[node-patches] Change in ovirt-node[master]: storage: Fix NFSv4 Domain setting
fabiand at fedoraproject.org
fabiand at fedoraproject.org
Wed Feb 19 14:13:59 UTC 2014
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 <fabiand at redhat.com>
---
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/47/24747/1
diff --git a/src/ovirt/node/config/defaults.py b/src/ovirt/node/config/defaults.py
index 70b95af..d977a70 100644
--- a/src/ovirt/node/config/defaults.py
+++ b/src/ovirt/node/config/defaults.py
@@ -1368,7 +1368,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/24747
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f58418e4db31f67d4a1e859a736e37508c8322e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Fabian Deutsch <fabiand at fedoraproject.org>
More information about the node-patches
mailing list