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
diff --git a/src/maasserver/node_constraint_filter_forms.py b/src/maasserver/node_constraint_filter_forms.py
index 1a4a765..71cf351 100644
--- a/src/maasserver/node_constraint_filter_forms.py
+++ b/src/maasserver/node_constraint_filter_forms.py
@@ -679,6 +679,25 @@ GROUPABLE_FIELDS = (
679)679)
680680
681681
682ARGUMENT_TYPES_BY_FIELD_TYPE = {
683 "int": (forms.IntegerField, forms.ChoiceField),
684 "float": (forms.FloatField,),
685 "string": (forms.CharField,),
686 "list": (ValidatorMultipleChoiceField, UnconstrainedMultipleChoiceField),
687 "dict[string,string]": (LabeledConstraintMapField,),
688}
689
690
691def get_field_argument_type(field):
692 for arg_type, field_types in ARGUMENT_TYPES_BY_FIELD_TYPE.items():
693 if type(field) in field_types:
694 if arg_type == "list":
695 # currently all multichoice fields take strings, this will need to be expanded if that changes
696 return "list[string]"
697 return arg_type
698 return "unknown"
699
700
682class FilterNodeForm(RenamableFieldsForm):701class FilterNodeForm(RenamableFieldsForm):
683 """A form for filtering nodes."""702 """A form for filtering nodes."""
684703
diff --git a/src/maasserver/tests/test_node_constraint_filter_forms.py b/src/maasserver/tests/test_node_constraint_filter_forms.py
index df67c69..e980944 100644
--- a/src/maasserver/tests/test_node_constraint_filter_forms.py
+++ b/src/maasserver/tests/test_node_constraint_filter_forms.py
@@ -24,6 +24,10 @@ from maasserver.enum import (
24 NODE_STATUS,24 NODE_STATUS,
25 POWER_STATE,25 POWER_STATE,
26)26)
27from maasserver.forms import (
28 UnconstrainedMultipleChoiceField,
29 ValidatorMultipleChoiceField,
30)
27from maasserver.models import Domain, Machine, NodeDevice, Tag, Zone31from maasserver.models import Domain, Machine, NodeDevice, Tag, Zone
28from maasserver.node_constraint_filter_forms import (32from maasserver.node_constraint_filter_forms import (
29 AcquireNodeForm,33 AcquireNodeForm,
@@ -32,6 +36,7 @@ from maasserver.node_constraint_filter_forms import (
32 FreeTextFilterNodeForm,36 FreeTextFilterNodeForm,
33 generate_architecture_wildcards,37 generate_architecture_wildcards,
34 get_architecture_wildcards,38 get_architecture_wildcards,
39 get_field_argument_type,
35 get_storage_constraints_from_string,40 get_storage_constraints_from_string,
36 JUJU_ACQUIRE_FORM_FIELDS_MAPPING,41 JUJU_ACQUIRE_FORM_FIELDS_MAPPING,
37 nodes_by_interface,42 nodes_by_interface,
@@ -2209,3 +2214,33 @@ class TestReadNodesForm(MAASServerTestCase, FilterConstraintsMixin):
2209 node3 = factory.make_Node(status=NODE_STATUS.NEW)2214 node3 = factory.make_Node(status=NODE_STATUS.NEW)
2210 self.assertConstrainedNodes([node1, node3], {"status": "new"})2215 self.assertConstrainedNodes([node1, node3], {"status": "new"})
2211 self.assertConstrainedNodes([node2], {"status": "deploying"})2216 self.assertConstrainedNodes([node2], {"status": "deploying"})
2217
2218
2219class TestGetFieldArgumentType(MAASServerTestCase):
2220 def test_get_IntegerField_type(self):
2221 field = forms.IntegerField()
2222 self.assertEqual(get_field_argument_type(field), "int")
2223
2224 def test_get_ChoiceField_type(self):
2225 field = forms.ChoiceField()
2226 self.assertEqual(get_field_argument_type(field), "int")
2227
2228 def test_get_FloatField_type(self):
2229 field = forms.FloatField()
2230 self.assertEqual(get_field_argument_type(field), "float")
2231
2232 def test_get_CharField_type(self):
2233 field = forms.CharField()
2234 self.assertEqual(get_field_argument_type(field), "string")
2235
2236 def test_get_ValidatorMultipleChoiceField_type(self):
2237 field = ValidatorMultipleChoiceField(validator=lambda x: True)
2238 self.assertEqual(get_field_argument_type(field), "list[string]")
2239
2240 def test_get_UnconstrainedMultipleChoiceField_type(self):
2241 field = UnconstrainedMultipleChoiceField()
2242 self.assertEqual(get_field_argument_type(field), "list[string]")
2243
2244 def test_get_unknown_type(self):
2245 field = forms.Field()
2246 self.assertEqual(get_field_argument_type(field), "unknown")
diff --git a/src/maasserver/websockets/handlers/node.py b/src/maasserver/websockets/handlers/node.py
index 7a9fc53..2c0d469 100644
--- a/src/maasserver/websockets/handlers/node.py
+++ b/src/maasserver/websockets/handlers/node.py
@@ -46,6 +46,7 @@ from maasserver.models.nodeprobeddetails import script_output_nsmap
46from maasserver.node_action import compile_node_actions46from maasserver.node_action import compile_node_actions
47from maasserver.node_constraint_filter_forms import (47from maasserver.node_constraint_filter_forms import (
48 FreeTextFilterNodeForm,48 FreeTextFilterNodeForm,
49 get_field_argument_type,
49 GROUPABLE_FIELDS,50 GROUPABLE_FIELDS,
50 STATIC_FILTER_FIELDS,51 STATIC_FILTER_FIELDS,
51)52)
@@ -1212,6 +1213,7 @@ class NodeHandler(TimestampedModelHandler):
1212 {1213 {
1213 "key": name,1214 "key": name,
1214 "label": field.label,1215 "label": field.label,
1216 "type": get_field_argument_type(field),
1215 "dynamic": name not in STATIC_FILTER_FIELDS,1217 "dynamic": name not in STATIC_FILTER_FIELDS,
1216 "for_grouping": name in GROUPABLE_FIELDS,1218 "for_grouping": name in GROUPABLE_FIELDS,
1217 }1219 }
diff --git a/src/maasserver/websockets/handlers/tests/test_machine.py b/src/maasserver/websockets/handlers/tests/test_machine.py
index dae1058..352d4ea 100644
--- a/src/maasserver/websockets/handlers/tests/test_machine.py
+++ b/src/maasserver/websockets/handlers/tests/test_machine.py
@@ -5903,186 +5903,217 @@ class TestMachineHandlerFilter(MAASServerTestCase):
5903 "key": "id",5903 "key": "id",
5904 "label": "System IDs to filter on",5904 "label": "System IDs to filter on",
5905 "dynamic": True,5905 "dynamic": True,
5906 "type": "list[string]",
5906 "for_grouping": False,5907 "for_grouping": False,
5907 },5908 },
5908 {5909 {
5909 "key": "arch",5910 "key": "arch",
5910 "label": "Architecture",5911 "label": "Architecture",
5911 "dynamic": False,5912 "dynamic": False,
5913 "type": "string",
5912 "for_grouping": True,5914 "for_grouping": True,
5913 },5915 },
5914 {5916 {
5915 "key": "tags",5917 "key": "tags",
5916 "label": "Tags",5918 "label": "Tags",
5917 "dynamic": True,5919 "dynamic": True,
5920 "type": "list[string]",
5918 "for_grouping": True,5921 "for_grouping": True,
5919 },5922 },
5920 {5923 {
5921 "key": "not_tags",5924 "key": "not_tags",
5922 "label": "Not having tags",5925 "label": "Not having tags",
5923 "dynamic": True,5926 "dynamic": True,
5927 "type": "list[string]",
5924 "for_grouping": False,5928 "for_grouping": False,
5925 },5929 },
5926 {5930 {
5927 "key": "fabrics",5931 "key": "fabrics",
5928 "label": "Attached to fabrics",5932 "label": "Attached to fabrics",
5929 "dynamic": True,5933 "dynamic": True,
5934 "type": "list[string]",
5930 "for_grouping": True,5935 "for_grouping": True,
5931 },5936 },
5932 {5937 {
5933 "key": "not_fabrics",5938 "key": "not_fabrics",
5934 "label": "Not attached to fabrics",5939 "label": "Not attached to fabrics",
5935 "dynamic": True,5940 "dynamic": True,
5941 "type": "list[string]",
5936 "for_grouping": False,5942 "for_grouping": False,
5937 },5943 },
5938 {5944 {
5939 "key": "fabric_classes",5945 "key": "fabric_classes",
5940 "label": "Attached to fabric with specified classes",5946 "label": "Attached to fabric with specified classes",
5941 "dynamic": True,5947 "dynamic": True,
5948 "type": "list[string]",
5942 "for_grouping": True,5949 "for_grouping": True,
5943 },5950 },
5944 {5951 {
5945 "key": "not_fabric_classes",5952 "key": "not_fabric_classes",
5946 "label": "Not attached to fabric with specified classes",5953 "label": "Not attached to fabric with specified classes",
5947 "dynamic": True,5954 "dynamic": True,
5955 "type": "list[string]",
5948 "for_grouping": False,5956 "for_grouping": False,
5949 },5957 },
5950 {5958 {
5951 "key": "subnets",5959 "key": "subnets",
5952 "label": "Attached to subnets",5960 "label": "Attached to subnets",
5953 "dynamic": True,5961 "dynamic": True,
5962 "type": "list[string]",
5954 "for_grouping": True,5963 "for_grouping": True,
5955 },5964 },
5956 {5965 {
5957 "key": "not_subnets",5966 "key": "not_subnets",
5958 "label": "Not attached to subnets",5967 "label": "Not attached to subnets",
5959 "dynamic": True,5968 "dynamic": True,
5969 "type": "list[string]",
5960 "for_grouping": False,5970 "for_grouping": False,
5961 },5971 },
5962 {5972 {
5963 "key": "link_speed",5973 "key": "link_speed",
5964 "label": "Link speed",5974 "label": "Link speed",
5965 "dynamic": True,5975 "dynamic": True,
5976 "type": "float",
5966 "for_grouping": False,5977 "for_grouping": False,
5967 },5978 },
5968 {5979 {
5969 "key": "vlans",5980 "key": "vlans",
5970 "label": "Attached to VLANs",5981 "label": "Attached to VLANs",
5971 "dynamic": True,5982 "dynamic": True,
5983 "type": "list[string]",
5972 "for_grouping": True,5984 "for_grouping": True,
5973 },5985 },
5974 {5986 {
5975 "key": "not_vlans",5987 "key": "not_vlans",
5976 "label": "Not attached to VLANs",5988 "label": "Not attached to VLANs",
5977 "dynamic": True,5989 "dynamic": True,
5990 "type": "list[string]",
5978 "for_grouping": False,5991 "for_grouping": False,
5979 },5992 },
5980 {5993 {
5981 "key": "zone",5994 "key": "zone",
5982 "label": "Physical zone",5995 "label": "Physical zone",
5983 "dynamic": True,5996 "dynamic": True,
5997 "type": "string",
5984 "for_grouping": True,5998 "for_grouping": True,
5985 },5999 },
5986 {6000 {
5987 "key": "not_in_zone",6001 "key": "not_in_zone",
5988 "label": "Not in zone",6002 "label": "Not in zone",
5989 "dynamic": True,6003 "dynamic": True,
6004 "type": "list[string]",
5990 "for_grouping": False,6005 "for_grouping": False,
5991 },6006 },
5992 {6007 {
5993 "key": "pool",6008 "key": "pool",
5994 "label": "Resource pool",6009 "label": "Resource pool",
5995 "dynamic": True,6010 "dynamic": True,
6011 "type": "string",
5996 "for_grouping": True,6012 "for_grouping": True,
5997 },6013 },
5998 {6014 {
5999 "key": "not_in_pool",6015 "key": "not_in_pool",
6000 "label": "Not in resource pool",6016 "label": "Not in resource pool",
6001 "dynamic": True,6017 "dynamic": True,
6018 "type": "list[string]",
6002 "for_grouping": False,6019 "for_grouping": False,
6003 },6020 },
6004 {6021 {
6005 "key": "storage",6022 "key": "storage",
6006 "label": "Storage",6023 "label": "Storage",
6007 "dynamic": True,6024 "dynamic": True,
6025 "type": "string",
6008 "for_grouping": False,6026 "for_grouping": False,
6009 },6027 },
6010 {6028 {
6011 "key": "interfaces",6029 "key": "interfaces",
6012 "label": "Interfaces",6030 "label": "Interfaces",
6013 "dynamic": True,6031 "dynamic": True,
6032 "type": "dict[string,string]",
6014 "for_grouping": False,6033 "for_grouping": False,
6015 },6034 },
6016 {6035 {
6017 "key": "devices",6036 "key": "devices",
6018 "label": "Devices",6037 "label": "Devices",
6019 "dynamic": True,6038 "dynamic": True,
6039 "type": "string",
6020 "for_grouping": False,6040 "for_grouping": False,
6021 },6041 },
6022 {6042 {
6023 "key": "cpu_count",6043 "key": "cpu_count",
6024 "label": "CPU count",6044 "label": "CPU count",
6025 "dynamic": True,6045 "dynamic": True,
6046 "type": "float",
6026 "for_grouping": False,6047 "for_grouping": False,
6027 },6048 },
6028 {6049 {
6029 "key": "mem",6050 "key": "mem",
6030 "label": "Memory",6051 "label": "Memory",
6031 "dynamic": True,6052 "dynamic": True,
6053 "type": "float",
6032 "for_grouping": False,6054 "for_grouping": False,
6033 },6055 },
6034 {6056 {
6035 "key": "pod",6057 "key": "pod",
6036 "label": "The name of the desired pod",6058 "label": "The name of the desired pod",
6037 "dynamic": True,6059 "dynamic": True,
6060 "type": "string",
6038 "for_grouping": True,6061 "for_grouping": True,
6039 },6062 },
6040 {6063 {
6041 "key": "not_pod",6064 "key": "not_pod",
6042 "label": "The name of the undesired pod",6065 "label": "The name of the undesired pod",
6043 "dynamic": True,6066 "dynamic": True,
6067 "type": "string",
6044 "for_grouping": False,6068 "for_grouping": False,
6045 },6069 },
6046 {6070 {
6047 "key": "pod_type",6071 "key": "pod_type",
6048 "label": "The power_type of the desired pod",6072 "label": "The power_type of the desired pod",
6049 "dynamic": False,6073 "dynamic": False,
6074 "type": "string",
6050 "for_grouping": True,6075 "for_grouping": True,
6051 },6076 },
6052 {6077 {
6053 "key": "not_pod_type",6078 "key": "not_pod_type",
6054 "label": "The power_type of the undesired pod",6079 "label": "The power_type of the undesired pod",
6055 "dynamic": False,6080 "dynamic": False,
6081 "type": "string",
6056 "for_grouping": False,6082 "for_grouping": False,
6057 },6083 },
6058 {6084 {
6059 "key": "hostname",6085 "key": "hostname",
6060 "label": "Hostnames to filter on",6086 "label": "Hostnames to filter on",
6061 "dynamic": True,6087 "dynamic": True,
6088 "type": "list[string]",
6062 "for_grouping": False,6089 "for_grouping": False,
6063 },6090 },
6064 {6091 {
6065 "key": "mac_address",6092 "key": "mac_address",
6066 "label": "MAC addresses to filter on",6093 "label": "MAC addresses to filter on",
6067 "dynamic": True,6094 "dynamic": True,
6095 "type": "list[string]",
6068 "for_grouping": False,6096 "for_grouping": False,
6069 },6097 },
6070 {6098 {
6071 "key": "domain",6099 "key": "domain",
6072 "label": "Domain names to filter on",6100 "label": "Domain names to filter on",
6073 "dynamic": True,6101 "dynamic": True,
6102 "type": "list[string]",
6074 "for_grouping": True,6103 "for_grouping": True,
6075 },6104 },
6076 {6105 {
6077 "key": "agent_name",6106 "key": "agent_name",
6078 "label": "Only include nodes with events matching the agent name",6107 "label": "Only include nodes with events matching the agent name",
6079 "dynamic": True,6108 "dynamic": True,
6109 "type": "string",
6080 "for_grouping": False,6110 "for_grouping": False,
6081 },6111 },
6082 {6112 {
6083 "key": "status",6113 "key": "status",
6084 "label": "Only includes nodes with the specified status",6114 "label": "Only includes nodes with the specified status",
6085 "dynamic": False,6115 "dynamic": False,
6116 "type": "int",
6086 "for_grouping": True,6117 "for_grouping": True,
6087 },6118 },
6088 {6119 {
@@ -6090,12 +6121,14 @@ class TestMachineHandlerFilter(MAASServerTestCase):
6090 "label": "Owner",6121 "label": "Owner",
6091 "dynamic": True,6122 "dynamic": True,
6092 "for_grouping": True,6123 "for_grouping": True,
6124 "type": "string",
6093 },6125 },
6094 {6126 {
6095 "key": "power_state",6127 "key": "power_state",
6096 "label": "Power State",6128 "label": "Power State",
6097 "dynamic": False,6129 "dynamic": False,
6098 "for_grouping": True,6130 "for_grouping": True,
6131 "type": "int",
6099 },6132 },
6100 ],6133 ],
6101 handler.filter_groups({}),6134 handler.filter_groups({}),

Subscribers

People subscribed via source and target branches