Merge ~adam-collard/maas:machine-list-owner-data into maas:master

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: c77f87e1dc4ca4c39570ae5adde64346a56dbfd0
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas:machine-list-owner-data
Merge into: maas:master
Diff against target: 285 lines (+54/-43)
4 files modified
src/maasserver/websockets/handlers/controller.py (+1/-0)
src/maasserver/websockets/handlers/machine.py (+10/-7)
src/maasserver/websockets/handlers/tests/test_controller.py (+2/-2)
src/maasserver/websockets/handlers/tests/test_machine.py (+41/-34)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Alberto Donato Approve
Review via email: mp+395698@code.launchpad.net

Commit message

Add OwnerData to the machine list websocket handler

To post a comment you must log in.
c77f87e... by Adam Collard

Remove redundant owner_data from fields in machine list test

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

LGTM!

one tiny nit inline

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

UNIT TESTS
-b machine-list-owner-data lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8953/console
COMMIT: c77f87e1dc4ca4c39570ae5adde64346a56dbfd0

review: Needs Fixing
Revision history for this message
Adam Collard (adam-collard) wrote :

jenkins: !test

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

UNIT TESTS
-b machine-list-owner-data lp:~adam-collard/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: c77f87e1dc4ca4c39570ae5adde64346a56dbfd0

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/websockets/handlers/controller.py b/src/maasserver/websockets/handlers/controller.py
2index 965a766..b3881bd 100644
3--- a/src/maasserver/websockets/handlers/controller.py
4+++ b/src/maasserver/websockets/handlers/controller.py
5@@ -32,6 +32,7 @@ class ControllerHandler(MachineHandler):
6 .select_related("controllerinfo", "domain", "bmc")
7 .prefetch_related("service_set")
8 .prefetch_related("tags")
9+ .prefetch_related("ownerdata_set")
10 .annotate(
11 status_event_type_description=Subquery(
12 Event.objects.filter(
13diff --git a/src/maasserver/websockets/handlers/machine.py b/src/maasserver/websockets/handlers/machine.py
14index 469e072..0df469f 100644
15--- a/src/maasserver/websockets/handlers/machine.py
16+++ b/src/maasserver/websockets/handlers/machine.py
17@@ -133,6 +133,7 @@ class MachineHandler(NodeHandler):
18 .prefetch_related("boot_interface__vlan__fabric")
19 .prefetch_related("tags")
20 .prefetch_related("pool")
21+ .prefetch_related("ownerdata_set")
22 .annotate(
23 status_event_type_description=Subquery(
24 Event.objects.filter(
25@@ -199,8 +200,8 @@ class MachineHandler(NodeHandler):
26 "set_script_result_unsuppressed",
27 "get_suppressible_script_results",
28 "get_latest_failed_testing_script_results",
29- "get_owner_data",
30- "set_owner_data",
31+ "get_workload_annotations",
32+ "set_workload_annotations",
33 ]
34 form = AdminMachineWithMACAddressesForm
35 exclude = [
36@@ -361,6 +362,8 @@ class MachineHandler(NodeHandler):
37 node_script_results
38 )
39
40+ data["workload_annotations"] = OwnerData.objects.get_owner_data(obj)
41+
42 if not for_list:
43 # Add info specific to a machine.
44 data["show_os_info"] = self.dehydrate_show_os_info(obj)
45@@ -1121,21 +1124,21 @@ class MachineHandler(NodeHandler):
46 raise HandlerPermissionError()
47 return node
48
49- def get_owner_data(self, params):
50- """Get the owner data for a machine"""
51+ def get_workload_annotations(self, params):
52+ """Get the owner data for a machine, known as workload annotations."""
53 machine = self._get_node_or_permission_error(
54 params, permission=NodePermission.edit
55 )
56 return OwnerData.objects.get_owner_data(machine)
57
58- def set_owner_data(self, params):
59- """Set the owner data for a machine"""
60+ def set_workload_annotations(self, params):
61+ """Set the owner data for a machine, known as workload annotations."""
62 machine = self._get_node_or_permission_error(
63 params, permission=NodePermission.edit
64 )
65 owner_data = {
66 key: None if value == "" else value
67- for key, value in params["owner_data"].items()
68+ for key, value in params["workload_annotations"].items()
69 }
70 OwnerData.objects.set_owner_data(machine, owner_data)
71 return OwnerData.objects.get_owner_data(machine)
72diff --git a/src/maasserver/websockets/handlers/tests/test_controller.py b/src/maasserver/websockets/handlers/tests/test_controller.py
73index 84a157f..873fff1 100644
74--- a/src/maasserver/websockets/handlers/tests/test_controller.py
75+++ b/src/maasserver/websockets/handlers/tests/test_controller.py
76@@ -108,12 +108,12 @@ class TestControllerHandler(MAASServerTestCase):
77 # and slowing down the client waiting for the response.
78 self.assertEqual(
79 queries_one,
80- 4,
81+ 5,
82 "Number of queries has changed; make sure this is expected.",
83 )
84 self.assertEqual(
85 queries_total,
86- 4,
87+ 5,
88 "Number of queries has changed; make sure this is expected.",
89 )
90
91diff --git a/src/maasserver/websockets/handlers/tests/test_machine.py b/src/maasserver/websockets/handlers/tests/test_machine.py
92index 8f46f16..6ce5614 100644
93--- a/src/maasserver/websockets/handlers/tests/test_machine.py
94+++ b/src/maasserver/websockets/handlers/tests/test_machine.py
95@@ -61,6 +61,7 @@ from maasserver.models.nodeprobeddetails import (
96 get_single_probed_details,
97 script_output_nsmap,
98 )
99+from maasserver.models.ownerdata import OwnerData
100 from maasserver.models.partition import Partition, PARTITION_ALIGNMENT_SIZE
101 import maasserver.node_action as node_action_module
102 from maasserver.node_action import compile_node_actions
103@@ -125,6 +126,9 @@ wait_for_reactor = wait_for(30) # 30 seconds.
104
105
106 class TestMachineHandler(MAASServerTestCase):
107+
108+ maxDiff = None
109+
110 def get_blockdevice_status(self, handler, blockdevice):
111 blockdevice_script_results = [
112 script_result
113@@ -321,6 +325,7 @@ class TestMachineHandler(MAASServerTestCase):
114 "zone": handler.dehydrate_zone(node.zone),
115 "pool": handler.dehydrate_pool(node.pool),
116 "default_user": node.default_user,
117+ "workload_annotations": OwnerData.objects.get_owner_data(node),
118 }
119 if "module" in driver and "comment" in driver:
120 data["third_party_driver"] = {
121@@ -374,6 +379,7 @@ class TestMachineHandler(MAASServerTestCase):
122 "testing_script_count",
123 "testing_status",
124 "vlan",
125+ "workload_annotations",
126 ]
127 for key in list(data):
128 if key not in allowed_fields:
129@@ -577,14 +583,15 @@ class TestMachineHandler(MAASServerTestCase):
130 # It is important to keep this number as low as possible. A larger
131 # number means regiond has to do more work slowing down its process
132 # and slowing down the client waiting for the response.
133+ expected_query_count = 24
134 self.assertEqual(
135 queries_one,
136- 23,
137+ expected_query_count,
138 "Number of queries has changed; make sure this is expected.",
139 )
140 self.assertEqual(
141 queries_total,
142- 23,
143+ expected_query_count,
144 "Number of queries has changed; make sure this is expected.",
145 )
146
147@@ -629,7 +636,7 @@ class TestMachineHandler(MAASServerTestCase):
148 # It is important to keep this number as low as possible. A larger
149 # number means regiond has to do more work slowing down its process
150 # and slowing down the client waiting for the response.
151- expected_query_count = 23
152+ expected_query_count = 24
153 self.assertEqual(
154 queries_one,
155 expected_query_count,
156@@ -673,7 +680,7 @@ class TestMachineHandler(MAASServerTestCase):
157 # and slowing down the client waiting for the response.
158 self.assertEqual(
159 queries,
160- 51,
161+ 52,
162 "Number of queries has changed; make sure this is expected.",
163 )
164
165@@ -5274,90 +5281,90 @@ class TestMachineHandlerUpdateFilesystem(MAASServerTestCase):
166
167
168 class TestMachineHandlerOwnerData(MAASServerTestCase):
169- """Tests for MachineHandle methods set_owner_data and get_owner_data."""
170+ """Tests for MachineHandle methods set_workload_annotations and get_workload_annotations."""
171
172- def test_set_owner_data(self):
173+ def test_set_workload_annotations(self):
174 user = factory.make_User()
175 node = factory.make_Node(owner=user)
176 handler = MachineHandler(user, {}, None)
177- owner_data = {"data 1": "value 1"}
178+ workload_annotations = {"data 1": "value 1"}
179 self.assertEqual(
180- owner_data,
181- handler.set_owner_data(
182+ workload_annotations,
183+ handler.set_workload_annotations(
184 {
185 "system_id": node.system_id,
186- "owner_data": owner_data,
187+ "workload_annotations": workload_annotations,
188 }
189 ),
190 )
191
192- def test_set_owner_data_overwrite(self):
193+ def test_set_workload_annotations_overwrite(self):
194 user = factory.make_User()
195 node = factory.make_Node(owner=user)
196 handler = MachineHandler(user, {}, None)
197- owner_data = {"data 1": "value 1"}
198+ workload_annotations = {"data 1": "value 1"}
199 self.assertEqual(
200- owner_data,
201- handler.set_owner_data(
202+ workload_annotations,
203+ handler.set_workload_annotations(
204 {
205 "system_id": node.system_id,
206- "owner_data": owner_data,
207+ "workload_annotations": workload_annotations,
208 }
209 ),
210 )
211- owner_data = {"data 1": "value 2"}
212+ workload_annotations = {"data 1": "value 2"}
213 self.assertEqual(
214- owner_data,
215- handler.set_owner_data(
216+ workload_annotations,
217+ handler.set_workload_annotations(
218 {
219 "system_id": node.system_id,
220- "owner_data": owner_data,
221+ "workload_annotations": workload_annotations,
222 }
223 ),
224 )
225
226- def test_set_owner_data_empty(self):
227+ def test_set_workload_annotations_empty(self):
228 user = factory.make_User()
229 node = factory.make_Node(owner=user)
230 handler = MachineHandler(user, {}, None)
231- owner_data = {"data 1": "value 1"}
232+ workload_annotations = {"data 1": "value 1"}
233 self.assertEqual(
234- owner_data,
235- handler.set_owner_data(
236+ workload_annotations,
237+ handler.set_workload_annotations(
238 {
239 "system_id": node.system_id,
240- "owner_data": owner_data,
241+ "workload_annotations": workload_annotations,
242 }
243 ),
244 )
245- owner_data = {"data 1": ""}
246+ workload_annotations = {"data 1": ""}
247 self.assertEqual(
248 {},
249- handler.set_owner_data(
250+ handler.set_workload_annotations(
251 {
252 "system_id": node.system_id,
253- "owner_data": owner_data,
254+ "workload_annotations": workload_annotations,
255 }
256 ),
257 )
258
259- def test_get_ower_data(self):
260+ def test_get_workload_annotations(self):
261 user = factory.make_User()
262 node = factory.make_Node(owner=user)
263 handler = MachineHandler(user, {}, None)
264- owner_data = {"data 1": "value 1"}
265+ workload_annotations = {"data 1": "value 1"}
266 self.assertEqual(
267- owner_data,
268- handler.set_owner_data(
269+ workload_annotations,
270+ handler.set_workload_annotations(
271 {
272 "system_id": node.system_id,
273- "owner_data": owner_data,
274+ "workload_annotations": workload_annotations,
275 }
276 ),
277 )
278 self.assertEqual(
279- owner_data,
280- handler.get_owner_data(
281+ workload_annotations,
282+ handler.get_workload_annotations(
283 {
284 "system_id": node.system_id,
285 }

Subscribers

People subscribed via source and target branches