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
1diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
2index 38df13a..f39f081 100644
3--- a/cloudinit/config/cc_disk_setup.py
4+++ b/cloudinit/config/cc_disk_setup.py
5@@ -201,7 +201,7 @@ def update_fs_setup_devices(disk_setup, tformer):
6
7 if part and 'partition' in definition:
8 definition['_partition'] = definition['partition']
9- definition['partition'] = part
10+ definition['partition'] = part
11
12
13 def value_splitter(values, start=None):
14diff --git a/tests/unittests/test_handler/test_handler_disk_setup.py b/tests/unittests/test_handler/test_handler_disk_setup.py
15index 227f049..afb2bea 100644
16--- a/tests/unittests/test_handler/test_handler_disk_setup.py
17+++ b/tests/unittests/test_handler/test_handler_disk_setup.py
18@@ -103,4 +103,46 @@ class TestGetPartitionMbrLayout(TestCase):
19 ',{0},83\n,,82'.format(expected_partition_size),
20 cc_disk_setup.get_partition_mbr_layout(disk_size, [33, [66, 82]]))
21
22+
23+class TestUpdateFsSetupDevices(TestCase):
24+ def test_regression_1634678(self):
25+ # Cf. https://bugs.launchpad.net/cloud-init/+bug/1634678
26+ fs_setup = {
27+ 'partition': 'auto',
28+ 'device': '/dev/xvdb1',
29+ 'overwrite': False,
30+ 'label': 'test',
31+ 'filesystem': 'ext4'
32+ }
33+
34+ cc_disk_setup.update_fs_setup_devices([fs_setup], lambda device: device)
35+
36+ self.assertEqual({
37+ '_origname': '/dev/xvdb1',
38+ 'partition': 'auto',
39+ 'device': '/dev/xvdb1',
40+ 'overwrite': False,
41+ 'label': 'test',
42+ 'filesystem': 'ext4'
43+ }, fs_setup)
44+
45+ def test_dotted_devname(self):
46+ fs_setup = {
47+ 'partition': 'auto',
48+ 'device': 'ephemeral0.0',
49+ 'label': 'test2',
50+ 'filesystem': 'xfs'
51+ }
52+
53+ cc_disk_setup.update_fs_setup_devices([fs_setup], lambda device: device)
54+
55+ self.assertEqual({
56+ '_origname': 'ephemeral0.0',
57+ '_partition': 'auto',
58+ 'partition': '0',
59+ 'device': 'ephemeral0',
60+ 'label': 'test2',
61+ 'filesystem': 'xfs'
62+ }, fs_setup)
63+
64 # vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches