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
1diff --git a/src/provisioningserver/utils/services.py b/src/provisioningserver/utils/services.py
2index 2e00b66..8bcd452 100644
3--- a/src/provisioningserver/utils/services.py
4+++ b/src/provisioningserver/utils/services.py
5@@ -1149,7 +1149,11 @@ class NetworksMonitoringService(MultiService, metaclass=ABCMeta):
6 hints = self.beaconing_protocol.getJSONTopologyHints()
7 maas_url, system_id, credentials = yield self.getRefreshDetails()
8 yield self._run_refresh(
9- maas_url, system_id, credentials, interfaces
10+ maas_url,
11+ system_id,
12+ credentials,
13+ interfaces,
14+ hints,
15 )
16 yield maybeDeferred(self.recordInterfaces, interfaces, hints)
17 # Note: _interfacesRecorded() will reconfigure discovery after
18@@ -1169,7 +1173,9 @@ class NetworksMonitoringService(MultiService, metaclass=ABCMeta):
19 yield maybeDeferred(self._configureNetworkDiscovery, interfaces)
20
21 @inlineCallbacks
22- def _run_refresh(self, maas_url, system_id, credentials, interfaces):
23+ def _run_refresh(
24+ self, maas_url, system_id, credentials, interfaces, hints
25+ ):
26 yield deferToThread(
27 refresh,
28 system_id,
29@@ -1178,17 +1184,26 @@ class NetworksMonitoringService(MultiService, metaclass=ABCMeta):
30 credentials["token_secret"],
31 maas_url,
32 post_process_hook=functools.partial(
33- self._annotate_commissioning, interfaces
34+ self._annotate_commissioning, interfaces, hints
35 ),
36 )
37
38 def _annotate_commissioning(
39- self, interfaces, script_name, combined_path, stdout_path, stderr_path
40+ self,
41+ interfaces,
42+ hints,
43+ script_name,
44+ combined_path,
45+ stdout_path,
46+ stderr_path,
47 ):
48 if script_name != LXD_OUTPUT_NAME:
49 return
50 lxd_data = json.loads(Path(stdout_path).read_bytes())
51- lxd_data["network-hints"] = interfaces
52+ lxd_data["network-extra"] = {
53+ "interfaces": interfaces,
54+ "hints": hints,
55+ }
56 Path(stdout_path).write_text(json.dumps(lxd_data))
57
58 def _getInterfacesForBeaconing(self, interfaces: dict):
59diff --git a/src/provisioningserver/utils/tests/test_services.py b/src/provisioningserver/utils/tests/test_services.py
60index d794605..b0c1ad8 100644
61--- a/src/provisioningserver/utils/tests/test_services.py
62+++ b/src/provisioningserver/utils/tests/test_services.py
63@@ -318,7 +318,49 @@ class TestNetworksMonitoringService(MAASTestCase):
64 yield service.stopService()
65
66 @inlineCallbacks
67- def test_runs_refresh_and_annotates_commissioning(self):
68+ def test_runs_refresh_and_annotates_commissioning_with_hints(self):
69+ # Don't actually wait for beaconing to complete.
70+ self.patch(services, "pause")
71+ service = self.makeService(enable_beaconing=True)
72+ service.maas_url = "http://my.example.com/MAAS"
73+ service.system_id = "my-system"
74+ service.credentials = {
75+ "consumer_key": "my-consumer",
76+ "token_key": "my-key",
77+ "token_secret": "my-secret",
78+ }
79+ self.fake_refresher.credentials.update(service.credentials)
80+ base_lxd_data = {factory.make_string(): factory.make_string()}
81+ base_lxd_output = json.dumps(base_lxd_data)
82+ self.fake_refresher.stdout_content[
83+ LXD_OUTPUT_NAME
84+ ] = base_lxd_output.encode("utf-8")
85+ network_extra = {
86+ "interfaces": {"my-interface": "foo"},
87+ "hints": {"my-hint": "foo"},
88+ }
89+ self.all_interfaces_mock.return_value = network_extra["interfaces"]
90+ beaconing_mock = self.patch(services.BeaconingSocketProtocol)
91+ beaconing_mock.return_value.getJSONTopologyHints.return_value = (
92+ network_extra["hints"]
93+ )
94+
95+ yield service.startService()
96+ yield self.update_interfaces_deferred
97+ yield service.stopService()
98+
99+ metadata_url = service.maas_url + "/metadata/2012-03-01/"
100+ script_runs = self.fake_refresher.script_runs[metadata_url]
101+ self.assertEqual("finished", script_runs[LXD_OUTPUT_NAME].status)
102+ commissioning_data = json.loads(
103+ script_runs[LXD_OUTPUT_NAME].out.decode("utf-8")
104+ )
105+ expected_commisioning_data = base_lxd_data.copy()
106+ expected_commisioning_data.update({"network-extra": network_extra})
107+ self.assertEqual(expected_commisioning_data, commissioning_data)
108+
109+ @inlineCallbacks
110+ def test_runs_refresh_and_annotates_commissioning_without_hints(self):
111 service = self.makeService()
112 service.maas_url = "http://my.example.com/MAAS"
113 service.system_id = "my-system"
114@@ -333,8 +375,11 @@ class TestNetworksMonitoringService(MAASTestCase):
115 self.fake_refresher.stdout_content[
116 LXD_OUTPUT_NAME
117 ] = base_lxd_output.encode("utf-8")
118- interfaces_hints = {"my-interface": "foo"}
119- self.all_interfaces_mock.return_value = interfaces_hints
120+ network_extra = {
121+ "interfaces": {"my-interface": "foo"},
122+ "hints": None,
123+ }
124+ self.all_interfaces_mock.return_value = network_extra["interfaces"]
125
126 yield service.startService()
127 yield self.update_interfaces_deferred
128@@ -347,7 +392,7 @@ class TestNetworksMonitoringService(MAASTestCase):
129 script_runs[LXD_OUTPUT_NAME].out.decode("utf-8")
130 )
131 expected_commisioning_data = base_lxd_data.copy()
132- expected_commisioning_data.update({"network-hints": interfaces_hints})
133+ expected_commisioning_data.update({"network-extra": network_extra})
134 self.assertEqual(expected_commisioning_data, commissioning_data)
135
136 @inlineCallbacks

Subscribers

People subscribed via source and target branches