← Back to team overview

cloud-init-dev team mailing list archive

[Merge] lp:~daniel-thewatkins/cloud-init/lp-1311463 into lp:cloud-init

 

Dan Watkins has proposed merging lp:~daniel-thewatkins/cloud-init/lp-1311463 into lp:cloud-init.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1311463 in cloud-init: "disk-setup unable to partition disks"
  https://bugs.launchpad.net/cloud-init/+bug/1311463

For more details, see:
https://code.launchpad.net/~daniel-thewatkins/cloud-init/lp-1311463/+merge/253362
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~daniel-thewatkins/cloud-init/lp-1311463 into lp:cloud-init.
=== modified file 'cloudinit/config/cc_disk_setup.py'
--- cloudinit/config/cc_disk_setup.py	2015-02-13 21:04:03 +0000
+++ cloudinit/config/cc_disk_setup.py	2015-03-18 13:35:03 +0000
@@ -304,8 +304,7 @@
 
     # If the child count is higher 1, then there are child nodes
     # such as partition or device mapper nodes
-    use_count = [x for x in enumerate_disk(device)]
-    if len(use_count.splitlines()) > 1:
+    if len(list(enumerate_disk(device))) > 1:
         return True
 
     # If we see a file system, then its used

=== added file 'tests/unittests/test_handler/test_handler_disk_setup.py'
--- tests/unittests/test_handler/test_handler_disk_setup.py	1970-01-01 00:00:00 +0000
+++ tests/unittests/test_handler/test_handler_disk_setup.py	2015-03-18 13:35:03 +0000
@@ -0,0 +1,30 @@
+from cloudinit.config import cc_disk_setup
+from ..helpers import ExitStack, mock, TestCase
+
+
+class TestIsDiskUsed(TestCase):
+
+    def setUp(self):
+        super(TestIsDiskUsed, self).setUp()
+        self.patches = ExitStack()
+        mod_name = 'cloudinit.config.cc_disk_setup'
+        self.enumerate_disk = self.patches.enter_context(
+            mock.patch('{0}.enumerate_disk'.format(mod_name)))
+        self.check_fs = self.patches.enter_context(
+            mock.patch('{0}.check_fs'.format(mod_name)))
+
+    def test_multiple_child_nodes_returns_true(self):
+        self.enumerate_disk.return_value = (mock.MagicMock() for _ in range(2))
+        self.check_fs.return_value = (mock.MagicMock(), None, mock.MagicMock())
+        self.assertTrue(cc_disk_setup.is_disk_used(mock.MagicMock()))
+
+    def test_valid_filesystem_returns_true(self):
+        self.enumerate_disk.return_value = (mock.MagicMock() for _ in range(1))
+        self.check_fs.return_value = (
+            mock.MagicMock(), 'ext4', mock.MagicMock())
+        self.assertTrue(cc_disk_setup.is_disk_used(mock.MagicMock()))
+
+    def test_one_child_nodes_and_no_fs_returns_false(self):
+        self.enumerate_disk.return_value = (mock.MagicMock() for _ in range(1))
+        self.check_fs.return_value = (mock.MagicMock(), None, mock.MagicMock())
+        self.assertFalse(cc_disk_setup.is_disk_used(mock.MagicMock()))