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

Proposed by Jonathan Ballet
Status: Merged
Merged at revision: 4a2b2f87ec48c227eb8fb2091dba604457cf8de8
Proposed branch: ~multani/cloud-init:fix-1634678
Merge into: cloud-init:master
Diff against target: 64 lines (+43/-1)
2 files modified
cloudinit/config/cc_disk_setup.py (+1/-1)
tests/unittests/test_handler/test_handler_disk_setup.py (+42/-0)
Reviewer Review Type Date Requested Status
cloud-init Commiters Pending
Review via email: mp+320815@code.launchpad.net

Description of the change

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

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

Jonathan,
Thanks for this. It looks great.

In order to accept the change I need you to sign the contributors agreement.
HACKING.rst in the code base has more info.

http://www.canonical.com/contributors

Please feel free to ping me in irc or email if you have any questions.

Other than that, it looks good.
Thanks.
Scott

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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):
201201
202 if part and 'partition' in definition:202 if part and 'partition' in definition:
203 definition['_partition'] = definition['partition']203 definition['_partition'] = definition['partition']
204 definition['partition'] = part204 definition['partition'] = part
205205
206206
207def value_splitter(values, start=None):207def 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):
103 ',{0},83\n,,82'.format(expected_partition_size),103 ',{0},83\n,,82'.format(expected_partition_size),
104 cc_disk_setup.get_partition_mbr_layout(disk_size, [33, [66, 82]]))104 cc_disk_setup.get_partition_mbr_layout(disk_size, [33, [66, 82]]))
105105
106
107class TestUpdateFsSetupDevices(TestCase):
108 def test_regression_1634678(self):
109 # Cf. https://bugs.launchpad.net/cloud-init/+bug/1634678
110 fs_setup = {
111 'partition': 'auto',
112 'device': '/dev/xvdb1',
113 'overwrite': False,
114 'label': 'test',
115 'filesystem': 'ext4'
116 }
117
118 cc_disk_setup.update_fs_setup_devices([fs_setup], lambda device: device)
119
120 self.assertEqual({
121 '_origname': '/dev/xvdb1',
122 'partition': 'auto',
123 'device': '/dev/xvdb1',
124 'overwrite': False,
125 'label': 'test',
126 'filesystem': 'ext4'
127 }, fs_setup)
128
129 def test_dotted_devname(self):
130 fs_setup = {
131 'partition': 'auto',
132 'device': 'ephemeral0.0',
133 'label': 'test2',
134 'filesystem': 'xfs'
135 }
136
137 cc_disk_setup.update_fs_setup_devices([fs_setup], lambda device: device)
138
139 self.assertEqual({
140 '_origname': 'ephemeral0.0',
141 '_partition': 'auto',
142 'partition': '0',
143 'device': 'ephemeral0',
144 'label': 'test2',
145 'filesystem': 'xfs'
146 }, fs_setup)
147
106# vi: ts=4 expandtab148# vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches