Merge lp:~mpontillo/maas/fix-recommission-lvm-virtio-bug-1585016 into lp:~maas-committers/maas/trunk

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 5116
Proposed branch: lp:~mpontillo/maas/fix-recommission-lvm-virtio-bug-1585016
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 45 lines (+22/-2)
2 files modified
src/metadataserver/models/commissioningscript.py (+4/-2)
src/metadataserver/models/tests/test_commissioningscript.py (+18/-0)
To merge this branch: bzr merge lp:~mpontillo/maas/fix-recommission-lvm-virtio-bug-1585016
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+297257@code.launchpad.net

Commit message

Use the path instead of the id_path when recommissioning virtual disks (when the serial number is blank). This prevents issues where the LVM id_path is used instead of a correct ID.

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/metadataserver/models/commissioningscript.py'
2--- src/metadataserver/models/commissioningscript.py 2016-06-10 02:29:21 +0000
3+++ src/metadataserver/models/commissioningscript.py 2016-06-14 15:22:18 +0000
4@@ -333,8 +333,10 @@
5 model = block_info.get("MODEL", "")
6 serial = block_info.get("SERIAL", "")
7 id_path = block_info.get("ID_PATH", "")
8- if not id_path:
9- # Fallback to the dev path if id_path missing.
10+ if not id_path or not serial:
11+ # Fallback to the dev path if id_path missing or there is no
12+ # serial number. (No serial number is a strong indicator that this
13+ # is a virtual disk, so it's unlikely that the ID_PATH would work.)
14 id_path = block_info["PATH"]
15 size = int(block_info["SIZE"])
16 block_size = int(block_info["BLOCK_SIZE"])
17
18=== modified file 'src/metadataserver/models/tests/test_commissioningscript.py'
19--- src/metadataserver/models/tests/test_commissioningscript.py 2016-06-11 00:59:08 +0000
20+++ src/metadataserver/models/tests/test_commissioningscript.py 2016-06-14 15:22:18 +0000
21@@ -603,6 +603,24 @@
22 name=name, id_path='/dev/%s' % name, size=size,
23 block_size=block_size, model=model, serial=serial))
24
25+ def test__creates_physical_block_device_with_path_for_missing_serial(self):
26+ name = factory.make_name('name')
27+ size = random.randint(MIN_BLOCK_DEVICE_SIZE, 1000 * 1000 * 1000)
28+ block_size = random.choice([512, 1024, 4096])
29+ model = factory.make_name('model')
30+ serial = ''
31+ device = self.make_block_device(
32+ name=name, size=size, block_size=block_size,
33+ model=model, serial=serial, id_path='bogus')
34+ node = factory.make_Node()
35+ json_output = json.dumps([device]).encode('utf-8')
36+ update_node_physical_block_devices(node, json_output, 0)
37+ self.assertThat(
38+ PhysicalBlockDevice.objects.filter(node=node).first(),
39+ MatchesStructure.byEquality(
40+ name=name, id_path='/dev/%s' % name, size=size,
41+ block_size=block_size, model=model, serial=serial))
42+
43 def test__creates_physical_block_device_only_for_node(self):
44 device = self.make_block_device()
45 node = factory.make_Node(with_boot_disk=False)