← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~multani/cloud-init:fix-1634678 into cloud-init:master

 

Jonathan Ballet has proposed merging ~multani/cloud-init:fix-1634678 into cloud-init:master.

Requested reviews:
  cloud init development team (cloud-init-dev)
Related bugs:
  Bug #1634678 in cloud-init: "fs_setup always creates new filesystem with partition 'auto'"
  https://bugs.launchpad.net/cloud-init/+bug/1634678

For more details, see:
https://code.launchpad.net/~multani/cloud-init/+git/cloud-init/+merge/320815

Fix filesystem creation when using "partition: auto"
    
Accordingly to the documentation:
    
    The ``partition`` option may also be set to ``auto``, in which this
    module will search for the existance of a filesystem matching the
    ``label``, ``type`` and ``device`` of the ``fs_setup`` entry and
    will skip creating the filesystem if one is found.
    
However, using this "auto" flag always recreates the partition no matter
if it has been done before or not.
    
This commit fixes a bug in which the "partition" attribute was always
set to None although in some cases it should not.
    
LP: #1634678
-- 
Your team cloud init development team is requested to review the proposed merge of ~multani/cloud-init:fix-1634678 into cloud-init:master.
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index 38df13a..f39f081 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -201,7 +201,7 @@ def update_fs_setup_devices(disk_setup, tformer):
 
         if part and 'partition' in definition:
             definition['_partition'] = definition['partition']
-        definition['partition'] = part
+            definition['partition'] = part
 
 
 def value_splitter(values, start=None):
diff --git a/tests/unittests/test_handler/test_handler_disk_setup.py b/tests/unittests/test_handler/test_handler_disk_setup.py
index 227f049..afb2bea 100644
--- a/tests/unittests/test_handler/test_handler_disk_setup.py
+++ b/tests/unittests/test_handler/test_handler_disk_setup.py
@@ -103,4 +103,46 @@ class TestGetPartitionMbrLayout(TestCase):
             ',{0},83\n,,82'.format(expected_partition_size),
             cc_disk_setup.get_partition_mbr_layout(disk_size, [33, [66, 82]]))
 
+
+class TestUpdateFsSetupDevices(TestCase):
+    def test_regression_1634678(self):
+        # Cf. https://bugs.launchpad.net/cloud-init/+bug/1634678
+        fs_setup = {
+            'partition': 'auto',
+            'device': '/dev/xvdb1',
+            'overwrite': False,
+            'label': 'test',
+            'filesystem': 'ext4'
+        }
+
+        cc_disk_setup.update_fs_setup_devices([fs_setup], lambda device: device)
+
+        self.assertEqual({
+            '_origname': '/dev/xvdb1',
+            'partition': 'auto',
+            'device': '/dev/xvdb1',
+            'overwrite': False,
+            'label': 'test',
+            'filesystem': 'ext4'
+        }, fs_setup)
+
+    def test_dotted_devname(self):
+        fs_setup = {
+            'partition': 'auto',
+            'device': 'ephemeral0.0',
+            'label': 'test2',
+            'filesystem': 'xfs'
+        }
+
+        cc_disk_setup.update_fs_setup_devices([fs_setup], lambda device: device)
+
+        self.assertEqual({
+            '_origname': 'ephemeral0.0',
+            '_partition': 'auto',
+            'partition': '0',
+            'device': 'ephemeral0',
+            'label': 'test2',
+            'filesystem': 'xfs'
+        }, fs_setup)
+
 # vi: ts=4 expandtab

Follow ups