With opendnssec 2, read the zone list from file

With OpenDNSSEC 1.4, the code was using the command
$ ods-ksmutil zonelist export
which printed the zonelist as XML in its output.
With OpenDNSSEC 2, the code is using the command
$ ods-enforcer zonelist export
which prints a message instead:
"Exported zonelist to /etc/opendnssec/zonelist.xml successfully"
The code needs to extract the zonelist file name and read the XML
from the file.

Related: https://pagure.io/freeipa/issue/8214
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
Reviewed-By: Christian Heimes <cheimes@redhat.com>
This commit is contained in:
Florence Blanc-Renaud
2020-03-12 21:48:25 +01:00
parent c2e355ae59
commit b857828180
+15 -1
View File
@@ -5,6 +5,7 @@
import logging
import dns.name
import re
try:
from xml.etree import cElementTree as etree
except ImportError:
@@ -140,7 +141,20 @@ class ODSMgr:
def get_ods_zonelist(self):
stdout = self.ksmutil(['zonelist', 'export'])
reader = ODSZoneListReader(stdout)
try:
reader = ODSZoneListReader(stdout)
except etree.ParseError:
# With OpenDNSSEC 2, the above command returns a message
# containing the zonelist filename instead of the XML text:
# "Exported zonelist to /etc/opendnssec/zonelist.xml successfully"
# extract the filename and read its content
pattern = re.compile(r'.* (/.*) .*')
matches = re.findall(pattern, stdout)
if matches:
with open(matches[0]) as f:
content = f.read()
reader = ODSZoneListReader(content)
return reader
def add_ods_zone(self, uuid, name):