[node-patches] Change in ovirt-node[master]: Bootloader.Arguments doctests
rbarry at redhat.com
rbarry at redhat.com
Fri Jun 27 16:42:36 UTC 2014
Ryan Barry has uploaded a new change for review.
Change subject: Bootloader.Arguments doctests
......................................................................
Bootloader.Arguments doctests
Break out parsing, make it testable
Change-Id: I1c5689b235e3bbcd8882ec9519905fcc67777d01
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/utils/system.py
1 file changed, 30 insertions(+), 11 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/62/29362/1
diff --git a/src/ovirt/node/utils/system.py b/src/ovirt/node/utils/system.py
index 87bfab4..5ea7600 100644
--- a/src/ovirt/node/utils/system.py
+++ b/src/ovirt/node/utils/system.py
@@ -839,10 +839,11 @@
class Arguments(base.Base):
- def __init__(self):
- self.__handle = Bootloader.find_grub_cfg()
- self.__mount = Mount.find_by_path(self.__handle.filename)
- self.items = self.__get_arguments()
+ def __init__(self, dry=False):
+ if not dry:
+ self.__handle = Bootloader.find_grub_cfg()
+ self.__mount = Mount.find_by_path(self.__handle.filename)
+ self.items = self.__get_arguments()
def __str__(self):
return str(self.items)
@@ -906,12 +907,34 @@
return key in self.items
def update_args(self, arg, remove=False):
+ self.__mount.remount(rw=True)
+ grub_cfg = self._parse_config(self.__get_lines(), arg, remove)
+ File(self.__handle.filename).write(grub_cfg, "w")
+ self.__mount.remount(rw=False)
+
+ def remove_args(self, arg):
+ self.update_args(arg, remove=True)
+
+ def _parse_config(self, lines, arg, remove):
+ """Parses and modifies the passed grub config
+
+ >>> cfg = ["tail", " kernel /vmlinuz0 arg1 foo=bar arg2"]
+ >>> b = Bootloader.Arguments(dry=True)
+ >>> parsed_args = lambda arg, remove: sorted(filter(None,
+ ... b._parse_config(cfg, arg, remove).split('\\n')))
+ >>> parsed_args("foo=bar", True)
+ [' kernel /vmlinuz0 arg1 arg2', 'tail']
+ >>> parsed_args("foo=oof", False)
+ [' kernel /vmlinuz0 arg1 foo=oof arg2', 'tail']
+ >>> parsed_args("new", False)
+ [' kernel /vmlinuz0 arg1 foo=bar arg2 new', 'tail']
+ """
+
replacement = arg
# Check if it's parameterized
if '=' in arg:
arg = re.match(r'^(.*?)=.*', arg).groups()[0]
- self.__mount.remount(rw=True)
- lines = self.__get_lines()
+
grub_cfg = ""
for line in lines:
if re.match(r'.*?\s%s' % arg, line):
@@ -926,11 +949,7 @@
line = line.rstrip() + " %s\n" % replacement
line = line if line.endswith("\n") else "{0}\n".format(line)
grub_cfg += line
- File(self.__handle.filename).write(grub_cfg, "w")
- self.__mount.remount(rw=False)
-
- def remove_args(self, arg):
- self.update_args(arg, remove=True)
+ return grub_cfg
class LVM(base.Base):
--
To view, visit http://gerrit.ovirt.org/29362
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c5689b235e3bbcd8882ec9519905fcc67777d01
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>
More information about the node-patches
mailing list