← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~xnox/cloud-init/refactor-dev-root into lp:cloud-init

 

Dimitri John Ledkov has proposed merging lp:~xnox/cloud-init/refactor-dev-root into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~xnox/cloud-init/refactor-dev-root/+merge/260165

refactor rootdev_from_cmdline into util.py
fix it up, to work with multiple "root=" args specified
add tests for above
and use that in cc_growpart
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~xnox/cloud-init/refactor-dev-root into lp:cloud-init.
=== modified file 'cloudinit/config/cc_growpart.py'
--- cloudinit/config/cc_growpart.py	2014-02-05 15:36:47 +0000
+++ cloudinit/config/cc_growpart.py	2015-05-26 14:02:15 +0000
@@ -200,9 +200,12 @@
         return devent
     else:
         result = util.get_mount_info(devent)
+        result = result[0] if result else None
+        if result is '/dev/root':
+            result = util.rootdev_from_cmdline(util.get_cmdline())            
         if not result:
             raise ValueError("Could not determine device of '%s' % dev_ent")
-        return result[0]
+        return result
 
 
 def resize_devices(resizer, devices):

=== modified file 'cloudinit/config/cc_resizefs.py'
--- cloudinit/config/cc_resizefs.py	2014-09-16 00:13:07 +0000
+++ cloudinit/config/cc_resizefs.py	2015-05-26 14:02:15 +0000
@@ -56,25 +56,6 @@
 NOBLOCK = "noblock"
 
 
-def rootdev_from_cmdline(cmdline):
-    found = None
-    for tok in cmdline.split():
-        if tok.startswith("root="):
-            found = tok[5:]
-            break
-    if found is None:
-        return None
-
-    if found.startswith("/dev/"):
-        return found
-    if found.startswith("LABEL="):
-        return "/dev/disk/by-label/" + found[len("LABEL="):]
-    if found.startswith("UUID="):
-        return "/dev/disk/by-uuid/" + found[len("UUID="):]
-
-    return "/dev/" + found
-
-
 def handle(name, cfg, _cloud, log, args):
     if len(args) != 0:
         resize_root = args[0]
@@ -106,7 +87,7 @@
     # Ensure the path is a block device.
     if (devpth == "/dev/root" and not os.path.exists(devpth) and
             not container):
-        devpth = rootdev_from_cmdline(util.get_cmdline())
+        devpth = util.rootdev_from_cmdline(util.get_cmdline())
         if devpth is None:
             log.warn("Unable to find device '/dev/root'")
             return

=== modified file 'cloudinit/util.py'
--- cloudinit/util.py	2015-05-14 21:06:39 +0000
+++ cloudinit/util.py	2015-05-26 14:02:15 +0000
@@ -1851,6 +1851,23 @@
     return pkglist
 
 
+def rootdev_from_cmdline(cmdline):
+    index = cmdline.rfind("root=")
+    if index is -1:
+        return None
+
+    found = cmdline[index:].split()[0][5:]
+
+    if found.startswith("/dev/"):
+        return found
+    if found.startswith("LABEL="):
+        return "/dev/disk/by-label/" + found[len("LABEL="):]
+    if found.startswith("UUID="):
+        return "/dev/disk/by-uuid/" + found[len("UUID="):]
+
+    return "/dev/" + found
+
+
 def parse_mount_info(path, mountinfo_lines, log=LOG):
     """Return the mount information for PATH given the lines from
     /proc/$$/mountinfo."""

=== modified file 'tests/unittests/test_util.py'
--- tests/unittests/test_util.py	2015-05-14 21:06:39 +0000
+++ tests/unittests/test_util.py	2015-05-26 14:02:15 +0000
@@ -227,6 +227,18 @@
         self.assertEqual(os.environ['DEBUG_PROC_CMDLINE'], util.get_cmdline())
 
 
+class TestRootdevFromCmdline(helpers.TestCase):
+    def test_values(self):
+        test_expectations = [
+            ("", None),
+            ("root=/dev/dev1 root=/dev/dev2", "/dev/dev2"),
+            ("root=UUID=73efc7ae-0a35-4339-bd53-2d1a78a09738", "/dev/disk/by-uuid/73efc7ae-0a35-4339-bd53-2d1a78a09738"),
+            ("root=LABEL=foobar", "/dev/disk/by-label/foobar"),
+        ]
+        for cmdline,result in test_expectations:
+            self.assertEqual(result, util.rootdev_from_cmdline(cmdline))
+
+
 class TestLoadYaml(helpers.TestCase):
     mydefault = "7b03a8ebace993d806255121073fed52"
 


Follow ups