Fabian Deutsch has uploaded a new change for review. Change subject: storage: Fix NFSv4 Domain setting ......................................................................
storage: Fix NFSv4 Domain setting Previously removing the NFSv4 domain failed. This is now fixed by propperly updating the config file. Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=960833 Change-Id: I8f58418e4db31f67d4a1e859a736e37508c8322e Signed-off-by: Fabian Deutsch <[email protected]> --- M src/ovirt/node/config/defaults.py M src/ovirt/node/utils/storage.py 2 files changed, 27 insertions(+), 21 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/61/24761/1 diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py index 88eb26e..68e4496 100644 --- a/src/ovirt/node/config/defaults.py +++ b/src/ovirt/node/config/defaults.py @@ -1325,7 +1325,9 @@ def commit(self): nfsv4 = storage.NFSv4() - nfsv4.domain(domain) + + # Need to pass "" to disable Domain line + nfsv4.domain(domain or "") fs.Config().persist(nfsv4.configfilename) system.service("rpcidmapd", "restart") diff --git a/src/ovirt/node/utils/storage.py b/src/ovirt/node/utils/storage.py index 0137906..07e5700 100644 --- a/src/ovirt/node/utils/storage.py +++ b/src/ovirt/node/utils/storage.py @@ -40,40 +40,44 @@ class NFSv4(base.Base): """A class to deal some external NFSv4 related functionality + + >>> n = NFSv4() + >>> n.domain("") + >>> n.domain() + >>> n.domain("abc") + 'abc' + >>> n.domain() + 'abc' + >>> n.domain("bar") + 'bar' """ configfilename = "/etc/idmapd.conf" def domain(self, domain=None): + """Get or set the domain + Domain is None: Just retrieve the name + Domain is "": Comment out the Domain directive + (else): Set Domain to domain + """ if domain is not None: self.__set_domain(domain) return self.__get_domain() def __set_domain(self, domain): current_domain = self.__get_domain() - print(current_domain) - cmd = None - if current_domain.startswith("#"): - current_domain = ("#Domain = %s" % - current_domain.replace("# ", "")) - cmd = ['sed', '-i', '-c', 's/%s/Domain = %s/g' % - (current_domain, domain), self.configfilename] + cfg = File(self.configfilename) + + if domain: + # Uncomment Domain line and set new domain + cfg.sub(r"^[#]?Domain =.*", "Domain = %s" % domain) else: - if domain is "": - cmd = ['sed', '-i', '-c', '/^Domain/ s/.*/#Domain = empty/g' % - (current_domain, domain), self.configfilename] - else: - cmd = ['sed', '-i', '-c', '/^Domain/ s/%s/%s/g' % - (current_domain, domain), self.configfilename] - print(cmd) - process.check_call(cmd) + # Comment out Domain line + cfg.sub(r"^[#]?(Domain =.*)", r"#\1") def __get_domain(self): - domain = None nfs_config = File(self.configfilename) - for line in nfs_config: - if "Domain =" in line: - domain = line.replace("Domain =", "").strip() - return domain + matches = nfs_config.findall("^Domain = (.*)") + return matches[0] if matches else None class Devices(base.Base): -- To view, visit http://gerrit.ovirt.org/24761 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8f58418e4db31f67d4a1e859a736e37508c8322e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-node Gerrit-Branch: node-3.0 Gerrit-Owner: Fabian Deutsch <[email protected]> _______________________________________________ node-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/node-patches
