Merge ~bjornt/maas:hints-in-commissioning-output into maas:master

Proposed by Björn Tillenius
Status: Merged
Approved by: Björn Tillenius
Approved revision: ef4f1af34a6f1ad3b19d71f2663b9615e7f97788
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~bjornt/maas:hints-in-commissioning-output
Merge into: maas:master
Diff against target: 136 lines (+69/-9)
2 files modified
src/provisioningserver/utils/services.py (+20/-5)
src/provisioningserver/utils/tests/test_services.py (+49/-4)
Reviewer Review Type Date Requested Status
Alberto Donato (community) Approve
MAAS Lander Approve
Review via email: mp+399491@code.launchpad.net

Commit message

Send the beaconing hints in the commissioning data.

I forgot to include them when I initially added the information that the
networks interfaces monitoring service collects to the commissioning output.

As before, don't pay too much attention on the key names. The will most likely
change soon, as I make use of the data, and remove what's not needed.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b hints-in-commissioning-output lp:~bjornt/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: ef4f1af34a6f1ad3b19d71f2663b9615e7f97788

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

+1

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b hints-in-commissioning-output lp:~bjornt/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/9474/consoleText

Revision history for this message
MAAS Lander (maas-lander) wrote :

LANDING
-b hints-in-commissioning-output lp:~bjornt/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED BUILD
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/9478/consoleText

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/provisioningserver/utils/services.py b/src/provisioningserver/utils/services.py
index 2e00b66..8bcd452 100644
--- a/src/provisioningserver/utils/services.py
+++ b/src/provisioningserver/utils/services.py
@@ -1149,7 +1149,11 @@ class NetworksMonitoringService(MultiService, metaclass=ABCMeta):
1149 hints = self.beaconing_protocol.getJSONTopologyHints()1149 hints = self.beaconing_protocol.getJSONTopologyHints()
1150 maas_url, system_id, credentials = yield self.getRefreshDetails()1150 maas_url, system_id, credentials = yield self.getRefreshDetails()
1151 yield self._run_refresh(1151 yield self._run_refresh(
1152 maas_url, system_id, credentials, interfaces1152 maas_url,
1153 system_id,
1154 credentials,
1155 interfaces,
1156 hints,
1153 )1157 )
1154 yield maybeDeferred(self.recordInterfaces, interfaces, hints)1158 yield maybeDeferred(self.recordInterfaces, interfaces, hints)
1155 # Note: _interfacesRecorded() will reconfigure discovery after1159 # Note: _interfacesRecorded() will reconfigure discovery after
@@ -1169,7 +1173,9 @@ class NetworksMonitoringService(MultiService, metaclass=ABCMeta):
1169 yield maybeDeferred(self._configureNetworkDiscovery, interfaces)1173 yield maybeDeferred(self._configureNetworkDiscovery, interfaces)
11701174
1171 @inlineCallbacks1175 @inlineCallbacks
1172 def _run_refresh(self, maas_url, system_id, credentials, interfaces):1176 def _run_refresh(
1177 self, maas_url, system_id, credentials, interfaces, hints
1178 ):
1173 yield deferToThread(1179 yield deferToThread(
1174 refresh,1180 refresh,
1175 system_id,1181 system_id,
@@ -1178,17 +1184,26 @@ class NetworksMonitoringService(MultiService, metaclass=ABCMeta):
1178 credentials["token_secret"],1184 credentials["token_secret"],
1179 maas_url,1185 maas_url,
1180 post_process_hook=functools.partial(1186 post_process_hook=functools.partial(
1181 self._annotate_commissioning, interfaces1187 self._annotate_commissioning, interfaces, hints
1182 ),1188 ),
1183 )1189 )
11841190
1185 def _annotate_commissioning(1191 def _annotate_commissioning(
1186 self, interfaces, script_name, combined_path, stdout_path, stderr_path1192 self,
1193 interfaces,
1194 hints,
1195 script_name,
1196 combined_path,
1197 stdout_path,
1198 stderr_path,
1187 ):1199 ):
1188 if script_name != LXD_OUTPUT_NAME:1200 if script_name != LXD_OUTPUT_NAME:
1189 return1201 return
1190 lxd_data = json.loads(Path(stdout_path).read_bytes())1202 lxd_data = json.loads(Path(stdout_path).read_bytes())
1191 lxd_data["network-hints"] = interfaces1203 lxd_data["network-extra"] = {
1204 "interfaces": interfaces,
1205 "hints": hints,
1206 }
1192 Path(stdout_path).write_text(json.dumps(lxd_data))1207 Path(stdout_path).write_text(json.dumps(lxd_data))
11931208
1194 def _getInterfacesForBeaconing(self, interfaces: dict):1209 def _getInterfacesForBeaconing(self, interfaces: dict):
diff --git a/src/provisioningserver/utils/tests/test_services.py b/src/provisioningserver/utils/tests/test_services.py
index d794605..b0c1ad8 100644
--- a/src/provisioningserver/utils/tests/test_services.py
+++ b/src/provisioningserver/utils/tests/test_services.py
@@ -318,7 +318,49 @@ class TestNetworksMonitoringService(MAASTestCase):
318 yield service.stopService()318 yield service.stopService()
319319
320 @inlineCallbacks320 @inlineCallbacks
321 def test_runs_refresh_and_annotates_commissioning(self):321 def test_runs_refresh_and_annotates_commissioning_with_hints(self):
322 # Don't actually wait for beaconing to complete.
323 self.patch(services, "pause")
324 service = self.makeService(enable_beaconing=True)
325 service.maas_url = "http://my.example.com/MAAS"
326 service.system_id = "my-system"
327 service.credentials = {
328 "consumer_key": "my-consumer",
329 "token_key": "my-key",
330 "token_secret": "my-secret",
331 }
332 self.fake_refresher.credentials.update(service.credentials)
333 base_lxd_data = {factory.make_string(): factory.make_string()}
334 base_lxd_output = json.dumps(base_lxd_data)
335 self.fake_refresher.stdout_content[
336 LXD_OUTPUT_NAME
337 ] = base_lxd_output.encode("utf-8")
338 network_extra = {
339 "interfaces": {"my-interface": "foo"},
340 "hints": {"my-hint": "foo"},
341 }
342 self.all_interfaces_mock.return_value = network_extra["interfaces"]
343 beaconing_mock = self.patch(services.BeaconingSocketProtocol)
344 beaconing_mock.return_value.getJSONTopologyHints.return_value = (
345 network_extra["hints"]
346 )
347
348 yield service.startService()
349 yield self.update_interfaces_deferred
350 yield service.stopService()
351
352 metadata_url = service.maas_url + "/metadata/2012-03-01/"
353 script_runs = self.fake_refresher.script_runs[metadata_url]
354 self.assertEqual("finished", script_runs[LXD_OUTPUT_NAME].status)
355 commissioning_data = json.loads(
356 script_runs[LXD_OUTPUT_NAME].out.decode("utf-8")
357 )
358 expected_commisioning_data = base_lxd_data.copy()
359 expected_commisioning_data.update({"network-extra": network_extra})
360 self.assertEqual(expected_commisioning_data, commissioning_data)
361
362 @inlineCallbacks
363 def test_runs_refresh_and_annotates_commissioning_without_hints(self):
322 service = self.makeService()364 service = self.makeService()
323 service.maas_url = "http://my.example.com/MAAS"365 service.maas_url = "http://my.example.com/MAAS"
324 service.system_id = "my-system"366 service.system_id = "my-system"
@@ -333,8 +375,11 @@ class TestNetworksMonitoringService(MAASTestCase):
333 self.fake_refresher.stdout_content[375 self.fake_refresher.stdout_content[
334 LXD_OUTPUT_NAME376 LXD_OUTPUT_NAME
335 ] = base_lxd_output.encode("utf-8")377 ] = base_lxd_output.encode("utf-8")
336 interfaces_hints = {"my-interface": "foo"}378 network_extra = {
337 self.all_interfaces_mock.return_value = interfaces_hints379 "interfaces": {"my-interface": "foo"},
380 "hints": None,
381 }
382 self.all_interfaces_mock.return_value = network_extra["interfaces"]
338383
339 yield service.startService()384 yield service.startService()
340 yield self.update_interfaces_deferred385 yield self.update_interfaces_deferred
@@ -347,7 +392,7 @@ class TestNetworksMonitoringService(MAASTestCase):
347 script_runs[LXD_OUTPUT_NAME].out.decode("utf-8")392 script_runs[LXD_OUTPUT_NAME].out.decode("utf-8")
348 )393 )
349 expected_commisioning_data = base_lxd_data.copy()394 expected_commisioning_data = base_lxd_data.copy()
350 expected_commisioning_data.update({"network-hints": interfaces_hints})395 expected_commisioning_data.update({"network-extra": network_extra})
351 self.assertEqual(expected_commisioning_data, commissioning_data)396 self.assertEqual(expected_commisioning_data, commissioning_data)
352397
353 @inlineCallbacks398 @inlineCallbacks

Subscribers

People subscribed via source and target branches