Merge lp:~newell-jensen/maas/fix-1694767 into lp:~maas-committers/maas/trunk

Proposed by Newell Jensen
Status: Merged
Approved by: Newell Jensen
Approved revision: no longer in the source branch.
Merged at revision: 6078
Proposed branch: lp:~newell-jensen/maas/fix-1694767
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 115 lines (+35/-14)
2 files modified
src/provisioningserver/drivers/pod/rsd.py (+16/-8)
src/provisioningserver/drivers/pod/tests/test_rsd.py (+19/-6)
To merge this branch: bzr merge lp:~newell-jensen/maas/fix-1694767
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+325103@code.launchpad.net

Commit message

Fixes RSD pod driver conditional to check that the smallest available block size is larger than the requested block device size in get_pod_machine_local_storages. Adds tests to check for successful and unsuccessful mapping of block device tags.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

I'm not sure I fully understand this branch. It might be fine as-is, but I can't really tell given the lack of context.

I think it would be clearer if you add some unit tests showing more specific expected success and failure scenarios.

review: Needs Information
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Also, you'll need to set a commit message. ;-)

Revision history for this message
Mike Pontillo (mpontillo) wrote :

Thanks for updating the tests and making the code more robust. It makes a little more sense to me now. Unfortunately, the log message raised more questions. =) See comment below.

review: Needs Information
Revision history for this message
Newell Jensen (newell-jensen) wrote :

See inline response. I agree that the message should definitely be more descriptive in terms of what is going on and will update it to give the user more information. In particular see what I say about (3) below.

Revision history for this message
Mike Pontillo (mpontillo) wrote :

Looks good; thanks for the fixes!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/drivers/pod/rsd.py'
2--- src/provisioningserver/drivers/pod/rsd.py 2017-06-05 17:31:23 +0000
3+++ src/provisioningserver/drivers/pod/rsd.py 2017-06-07 00:15:32 +0000
4@@ -474,12 +474,13 @@
5 """Get pod machine local strorages."""
6 local_drives = node_data.get('Links', {}).get('LocalDrives', [])
7 for local_drive in local_drives:
8+ local_drive_endpoint = local_drive['@odata.id']
9 discovered_machine_block_device = (
10 DiscoveredMachineBlockDevice(
11 model='', serial='', size=0))
12 drive_data, _ = yield self.redfish_request(
13- b"GET", join(url, local_drive[
14- '@odata.id'].lstrip('/').encode('utf-8')), headers)
15+ b"GET", join(url, local_drive_endpoint.lstrip(
16+ '/').encode('utf-8')), headers)
17 discovered_machine_block_device.model = drive_data['Model']
18 discovered_machine_block_device.serial = drive_data['SerialNumber']
19 discovered_machine_block_device.size = float(
20@@ -489,26 +490,33 @@
21 # block devices. This ensures that the composed machine has the
22 # requested tags on the block device.
23 if request is not None:
24- # Iterate over all the request's block devices and pick first
25+ # Iterate over all the request's block devices and pick
26 # device that has 'local' flag set with smallest adequate size.
27 chosen_block_device = None
28 smallest_size = discovered_machine_block_device.size
29 for block_device in request.block_devices:
30 if ('local' in block_device.tags and
31- block_device.size >= smallest_size):
32+ smallest_size >= block_device.size):
33 smallest_size = block_device.size
34 chosen_block_device = block_device
35 if chosen_block_device is not None:
36 discovered_machine_block_device.tags = (
37 chosen_block_device.tags)
38 # Delete this from the request's block devices as it
39- # is not longer needed.
40+ # is no longer needed.
41 request.block_devices.remove(chosen_block_device)
42 else:
43 # Log the fact that we did not find a chosen block device
44- # to set the tags.
45- maaslog.info(
46- "Unable to set tags for local drive: %r" % local_drive)
47+ # to set the tags. If the RSD is performing the way it
48+ # should, the user should not be seeing this as the
49+ # allocation process for composition should have failed.
50+ # Warn the user of this.
51+ maaslog.warning(
52+ "Requested disk size is larger than %d GiB, which "
53+ "drive '%r' contains. RSD allocation should have "
54+ "failed. Please report this to your RSD Pod "
55+ "administrator." % (
56+ smallest_size / (1024 ** 3), local_drive_endpoint))
57
58 if 'local' not in discovered_machine_block_device.tags:
59 discovered_machine_block_device.tags.append('local')
60
61=== modified file 'src/provisioningserver/drivers/pod/tests/test_rsd.py'
62--- src/provisioningserver/drivers/pod/tests/test_rsd.py 2017-06-05 17:31:23 +0000
63+++ src/provisioningserver/drivers/pod/tests/test_rsd.py 2017-06-07 00:15:32 +0000
64@@ -1312,14 +1312,20 @@
65 headers = driver.make_auth_headers(**context)
66 request = make_requested_machine()
67 # Set the tags on the requested machine's block devices
68- # and the size.
69- for idx in range(3):
70- request.block_devices[idx].size = 200 * 1024 ** 3
71- request.block_devices[idx].tags = ['local', 'testing tags']
72+ # and the size. First device will be a device that has
73+ # its tags mapped, while the second one will be at a size
74+ # that is bigger than the available local disk size so its
75+ # tags will not be mapped.
76+ request.block_devices[0].size = 100 * 1024 ** 3
77+ request.block_devices[0].tags = ['local', 'tags mapped']
78+ request.block_devices[1].size = 200 * 1024 ** 3
79+ request.block_devices[1].tags = ['local', 'tags not mapped']
80+ local_drive = "/redfish/v1/Systems/1/Adapters/3/Devices/3"
81 node_data = SAMPLE_JSON_NODE
82 discovered_machine = make_discovered_machine(block_devices=[])
83 mock_redfish_request = self.patch(driver, 'redfish_request')
84 mock_redfish_request.return_value = (SAMPLE_JSON_DEVICE, None)
85+ self.patch_autospec(rsd_module.maaslog, 'warning')
86
87 yield driver.get_pod_machine_local_storages(
88 node_data, url, headers, discovered_machine, request)
89@@ -1330,7 +1336,7 @@
90 serial=Equals('CVLI310601PY120E'),
91 size=Equals(119999999999.99997),
92 block_size=Equals(512),
93- tags=Equals(['local', 'testing tags', 'ssd']),
94+ tags=Equals(['local', 'tags mapped', 'ssd']),
95 type=Equals(BlockDeviceType.PHYSICAL),
96 ),
97 MatchesStructure(
98@@ -1338,9 +1344,16 @@
99 serial=Equals('CVLI310601PY120E'),
100 size=Equals(119999999999.99997),
101 block_size=Equals(512),
102- tags=Equals(['local', 'testing tags', 'ssd']),
103+ tags=Equals(['local', 'ssd']),
104 type=Equals(BlockDeviceType.PHYSICAL),
105 )]))
106+ self.assertThat(rsd_module.maaslog.warning, MockCalledOnceWith(
107+ "Requested disk size is larger than %d GiB, which "
108+ "drive '%r' contains. RSD allocation should have "
109+ "failed. Please report this to your RSD Pod "
110+ "administrator." % (
111+ discovered_machine.block_devices[1].size / (1024 ** 3),
112+ local_drive)))
113
114 def test__get_pod_machine_remote_storages(self):
115 driver = RSDPodDriver()