Merge ~cgrabowski/maas:add_field_type_to_filter_groups into maas:master

Proposed by Christian Grabowski
Status: Merged
Approved by: Christian Grabowski
Approved revision: 157a7a834c74f8d6d0d6f54da0d9e1bccbf766db
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~cgrabowski/maas:add_field_type_to_filter_groups
Merge into: maas:master
Diff against target: 344 lines (+89/-0)
4 files modified
src/maasserver/node_constraint_filter_forms.py (+19/-0)
src/maasserver/tests/test_node_constraint_filter_forms.py (+35/-0)
src/maasserver/websockets/handlers/node.py (+2/-0)
src/maasserver/websockets/handlers/tests/test_machine.py (+33/-0)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Alexsander de Souza Approve
Review via email: mp+426582@code.launchpad.net

Commit message

expand complex types

add type field to filter_groups endpoint

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

UNIT TESTS
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/2/consoleText
COMMIT: 094eb6d1ead7d3a289bb589c189b0f805078119e

review: Needs Fixing
Revision history for this message
Alexsander de Souza (alexsander-souza) wrote :

comments inline

review: Needs Fixing
Revision history for this message
Christian Grabowski (cgrabowski) :
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/3/consoleText
COMMIT: 48f2a45649e4a7315554ab8e10731e36adf8080f

review: Needs Fixing
Revision history for this message
Alexsander de Souza (alexsander-souza) :
Revision history for this message
Christian Grabowski (cgrabowski) :
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/4/consoleText
COMMIT: b650b20349dad973bdf1aac50ed25fe3cd48d4cf

review: Needs Fixing
Revision history for this message
Alexsander de Souza (alexsander-souza) wrote :

+1

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

UNIT TESTS
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/5/consoleText
COMMIT: bfc406c0102bd0cb22d7f4562a485488e54a9096

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

UNIT TESTS
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/6/consoleText
COMMIT: 1663f37f3e390e33389d3d6e554c0c8a453c623b

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

UNIT TESTS
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/7/consoleText
COMMIT: a05feb41c74786930633a828a522d69719782be5

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

UNIT TESTS
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/8/consoleText
COMMIT: 659ff302c1d501551a4dbab7de6454f86d06984f

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

UNIT TESTS
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/10/consoleText
COMMIT: 157a7a834c74f8d6d0d6f54da0d9e1bccbf766db

review: Needs Fixing
Revision history for this message
Christian Grabowski (cgrabowski) wrote :

jenkins: !test

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

UNIT TESTS
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 157a7a834c74f8d6d0d6f54da0d9e1bccbf766db

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

LANDING
-b add_field_type_to_filter_groups lp:~cgrabowski/maas/+git/maas into -b master lp:~maas-committers/maas

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/node_constraint_filter_forms.py b/src/maasserver/node_constraint_filter_forms.py
2index 1a4a765..71cf351 100644
3--- a/src/maasserver/node_constraint_filter_forms.py
4+++ b/src/maasserver/node_constraint_filter_forms.py
5@@ -679,6 +679,25 @@ GROUPABLE_FIELDS = (
6 )
7
8
9+ARGUMENT_TYPES_BY_FIELD_TYPE = {
10+ "int": (forms.IntegerField, forms.ChoiceField),
11+ "float": (forms.FloatField,),
12+ "string": (forms.CharField,),
13+ "list": (ValidatorMultipleChoiceField, UnconstrainedMultipleChoiceField),
14+ "dict[string,string]": (LabeledConstraintMapField,),
15+}
16+
17+
18+def get_field_argument_type(field):
19+ for arg_type, field_types in ARGUMENT_TYPES_BY_FIELD_TYPE.items():
20+ if type(field) in field_types:
21+ if arg_type == "list":
22+ # currently all multichoice fields take strings, this will need to be expanded if that changes
23+ return "list[string]"
24+ return arg_type
25+ return "unknown"
26+
27+
28 class FilterNodeForm(RenamableFieldsForm):
29 """A form for filtering nodes."""
30
31diff --git a/src/maasserver/tests/test_node_constraint_filter_forms.py b/src/maasserver/tests/test_node_constraint_filter_forms.py
32index df67c69..e980944 100644
33--- a/src/maasserver/tests/test_node_constraint_filter_forms.py
34+++ b/src/maasserver/tests/test_node_constraint_filter_forms.py
35@@ -24,6 +24,10 @@ from maasserver.enum import (
36 NODE_STATUS,
37 POWER_STATE,
38 )
39+from maasserver.forms import (
40+ UnconstrainedMultipleChoiceField,
41+ ValidatorMultipleChoiceField,
42+)
43 from maasserver.models import Domain, Machine, NodeDevice, Tag, Zone
44 from maasserver.node_constraint_filter_forms import (
45 AcquireNodeForm,
46@@ -32,6 +36,7 @@ from maasserver.node_constraint_filter_forms import (
47 FreeTextFilterNodeForm,
48 generate_architecture_wildcards,
49 get_architecture_wildcards,
50+ get_field_argument_type,
51 get_storage_constraints_from_string,
52 JUJU_ACQUIRE_FORM_FIELDS_MAPPING,
53 nodes_by_interface,
54@@ -2209,3 +2214,33 @@ class TestReadNodesForm(MAASServerTestCase, FilterConstraintsMixin):
55 node3 = factory.make_Node(status=NODE_STATUS.NEW)
56 self.assertConstrainedNodes([node1, node3], {"status": "new"})
57 self.assertConstrainedNodes([node2], {"status": "deploying"})
58+
59+
60+class TestGetFieldArgumentType(MAASServerTestCase):
61+ def test_get_IntegerField_type(self):
62+ field = forms.IntegerField()
63+ self.assertEqual(get_field_argument_type(field), "int")
64+
65+ def test_get_ChoiceField_type(self):
66+ field = forms.ChoiceField()
67+ self.assertEqual(get_field_argument_type(field), "int")
68+
69+ def test_get_FloatField_type(self):
70+ field = forms.FloatField()
71+ self.assertEqual(get_field_argument_type(field), "float")
72+
73+ def test_get_CharField_type(self):
74+ field = forms.CharField()
75+ self.assertEqual(get_field_argument_type(field), "string")
76+
77+ def test_get_ValidatorMultipleChoiceField_type(self):
78+ field = ValidatorMultipleChoiceField(validator=lambda x: True)
79+ self.assertEqual(get_field_argument_type(field), "list[string]")
80+
81+ def test_get_UnconstrainedMultipleChoiceField_type(self):
82+ field = UnconstrainedMultipleChoiceField()
83+ self.assertEqual(get_field_argument_type(field), "list[string]")
84+
85+ def test_get_unknown_type(self):
86+ field = forms.Field()
87+ self.assertEqual(get_field_argument_type(field), "unknown")
88diff --git a/src/maasserver/websockets/handlers/node.py b/src/maasserver/websockets/handlers/node.py
89index 7a9fc53..2c0d469 100644
90--- a/src/maasserver/websockets/handlers/node.py
91+++ b/src/maasserver/websockets/handlers/node.py
92@@ -46,6 +46,7 @@ from maasserver.models.nodeprobeddetails import script_output_nsmap
93 from maasserver.node_action import compile_node_actions
94 from maasserver.node_constraint_filter_forms import (
95 FreeTextFilterNodeForm,
96+ get_field_argument_type,
97 GROUPABLE_FIELDS,
98 STATIC_FILTER_FIELDS,
99 )
100@@ -1212,6 +1213,7 @@ class NodeHandler(TimestampedModelHandler):
101 {
102 "key": name,
103 "label": field.label,
104+ "type": get_field_argument_type(field),
105 "dynamic": name not in STATIC_FILTER_FIELDS,
106 "for_grouping": name in GROUPABLE_FIELDS,
107 }
108diff --git a/src/maasserver/websockets/handlers/tests/test_machine.py b/src/maasserver/websockets/handlers/tests/test_machine.py
109index dae1058..352d4ea 100644
110--- a/src/maasserver/websockets/handlers/tests/test_machine.py
111+++ b/src/maasserver/websockets/handlers/tests/test_machine.py
112@@ -5903,186 +5903,217 @@ class TestMachineHandlerFilter(MAASServerTestCase):
113 "key": "id",
114 "label": "System IDs to filter on",
115 "dynamic": True,
116+ "type": "list[string]",
117 "for_grouping": False,
118 },
119 {
120 "key": "arch",
121 "label": "Architecture",
122 "dynamic": False,
123+ "type": "string",
124 "for_grouping": True,
125 },
126 {
127 "key": "tags",
128 "label": "Tags",
129 "dynamic": True,
130+ "type": "list[string]",
131 "for_grouping": True,
132 },
133 {
134 "key": "not_tags",
135 "label": "Not having tags",
136 "dynamic": True,
137+ "type": "list[string]",
138 "for_grouping": False,
139 },
140 {
141 "key": "fabrics",
142 "label": "Attached to fabrics",
143 "dynamic": True,
144+ "type": "list[string]",
145 "for_grouping": True,
146 },
147 {
148 "key": "not_fabrics",
149 "label": "Not attached to fabrics",
150 "dynamic": True,
151+ "type": "list[string]",
152 "for_grouping": False,
153 },
154 {
155 "key": "fabric_classes",
156 "label": "Attached to fabric with specified classes",
157 "dynamic": True,
158+ "type": "list[string]",
159 "for_grouping": True,
160 },
161 {
162 "key": "not_fabric_classes",
163 "label": "Not attached to fabric with specified classes",
164 "dynamic": True,
165+ "type": "list[string]",
166 "for_grouping": False,
167 },
168 {
169 "key": "subnets",
170 "label": "Attached to subnets",
171 "dynamic": True,
172+ "type": "list[string]",
173 "for_grouping": True,
174 },
175 {
176 "key": "not_subnets",
177 "label": "Not attached to subnets",
178 "dynamic": True,
179+ "type": "list[string]",
180 "for_grouping": False,
181 },
182 {
183 "key": "link_speed",
184 "label": "Link speed",
185 "dynamic": True,
186+ "type": "float",
187 "for_grouping": False,
188 },
189 {
190 "key": "vlans",
191 "label": "Attached to VLANs",
192 "dynamic": True,
193+ "type": "list[string]",
194 "for_grouping": True,
195 },
196 {
197 "key": "not_vlans",
198 "label": "Not attached to VLANs",
199 "dynamic": True,
200+ "type": "list[string]",
201 "for_grouping": False,
202 },
203 {
204 "key": "zone",
205 "label": "Physical zone",
206 "dynamic": True,
207+ "type": "string",
208 "for_grouping": True,
209 },
210 {
211 "key": "not_in_zone",
212 "label": "Not in zone",
213 "dynamic": True,
214+ "type": "list[string]",
215 "for_grouping": False,
216 },
217 {
218 "key": "pool",
219 "label": "Resource pool",
220 "dynamic": True,
221+ "type": "string",
222 "for_grouping": True,
223 },
224 {
225 "key": "not_in_pool",
226 "label": "Not in resource pool",
227 "dynamic": True,
228+ "type": "list[string]",
229 "for_grouping": False,
230 },
231 {
232 "key": "storage",
233 "label": "Storage",
234 "dynamic": True,
235+ "type": "string",
236 "for_grouping": False,
237 },
238 {
239 "key": "interfaces",
240 "label": "Interfaces",
241 "dynamic": True,
242+ "type": "dict[string,string]",
243 "for_grouping": False,
244 },
245 {
246 "key": "devices",
247 "label": "Devices",
248 "dynamic": True,
249+ "type": "string",
250 "for_grouping": False,
251 },
252 {
253 "key": "cpu_count",
254 "label": "CPU count",
255 "dynamic": True,
256+ "type": "float",
257 "for_grouping": False,
258 },
259 {
260 "key": "mem",
261 "label": "Memory",
262 "dynamic": True,
263+ "type": "float",
264 "for_grouping": False,
265 },
266 {
267 "key": "pod",
268 "label": "The name of the desired pod",
269 "dynamic": True,
270+ "type": "string",
271 "for_grouping": True,
272 },
273 {
274 "key": "not_pod",
275 "label": "The name of the undesired pod",
276 "dynamic": True,
277+ "type": "string",
278 "for_grouping": False,
279 },
280 {
281 "key": "pod_type",
282 "label": "The power_type of the desired pod",
283 "dynamic": False,
284+ "type": "string",
285 "for_grouping": True,
286 },
287 {
288 "key": "not_pod_type",
289 "label": "The power_type of the undesired pod",
290 "dynamic": False,
291+ "type": "string",
292 "for_grouping": False,
293 },
294 {
295 "key": "hostname",
296 "label": "Hostnames to filter on",
297 "dynamic": True,
298+ "type": "list[string]",
299 "for_grouping": False,
300 },
301 {
302 "key": "mac_address",
303 "label": "MAC addresses to filter on",
304 "dynamic": True,
305+ "type": "list[string]",
306 "for_grouping": False,
307 },
308 {
309 "key": "domain",
310 "label": "Domain names to filter on",
311 "dynamic": True,
312+ "type": "list[string]",
313 "for_grouping": True,
314 },
315 {
316 "key": "agent_name",
317 "label": "Only include nodes with events matching the agent name",
318 "dynamic": True,
319+ "type": "string",
320 "for_grouping": False,
321 },
322 {
323 "key": "status",
324 "label": "Only includes nodes with the specified status",
325 "dynamic": False,
326+ "type": "int",
327 "for_grouping": True,
328 },
329 {
330@@ -6090,12 +6121,14 @@ class TestMachineHandlerFilter(MAASServerTestCase):
331 "label": "Owner",
332 "dynamic": True,
333 "for_grouping": True,
334+ "type": "string",
335 },
336 {
337 "key": "power_state",
338 "label": "Power State",
339 "dynamic": False,
340 "for_grouping": True,
341+ "type": "int",
342 },
343 ],
344 handler.filter_groups({}),

Subscribers

People subscribed via source and target branches