Merge ~r00ta/maas:MAASENG-2165-support-filter-by-ephemeral-deployment into maas:master

Proposed by Jacopo Rota
Status: Merged
Approved by: Jacopo Rota
Approved revision: be2448cae6c5f6a3878dab5eeb018b87a31bc099
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~r00ta/maas:MAASENG-2165-support-filter-by-ephemeral-deployment
Merge into: maas:master
Diff against target: 234 lines (+116/-0)
6 files modified
src/maasserver/enum.py (+10/-0)
src/maasserver/node_constraint_filter_forms.py (+40/-0)
src/maasserver/tests/test_node_constraint_filter_forms.py (+5/-0)
src/maasserver/websockets/handlers/node.py (+6/-0)
src/maasserver/websockets/handlers/tests/test_machine.py (+14/-0)
src/tests/maasserver/websockets/handlers/test_machine.py (+41/-0)
Reviewer Review Type Date Requested Status
MAAS Lander Approve
Björn Tillenius Approve
Review via email: mp+451358@code.launchpad.net

Commit message

support filter by ephemeral_deploy property in machine list websocket handler

Description of the change

This MP aims to implement the task https://warthogs.atlassian.net/browse/MAASENG-2165 .

In particular, the user can now filter by the `ephemeral_deploy` property.
If `ephemeral_deploy=True`, then all the machines that are ephemerally deployed will be included in the result.
If `ephemeral_deploy=False`, then all the machines that are ephemerally deployed are excluded from the result.

If nothing is specified, all the machines are included in the result.

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

UNIT TESTS
-b MAASENG-2165-support-filter-by-ephemeral-deployment lp:~r00ta/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/3551/console
COMMIT: d1d5232ab24fbc174ec1089a7ddb85fec1ab9927

review: Needs Fixing
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1

review: Approve
996f30e... by Jacopo Rota

use deployment_target instead of ephemeral_deploy in filters

0b8d227... by Jacopo Rota

refactoring

5a73f84... by Jacopo Rota

refactoring

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

UNIT TESTS
-b MAASENG-2165-support-filter-by-ephemeral-deployment lp:~r00ta/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/3553/console
COMMIT: 0b8d2277ff4e43dd6426f9ff475d1c0d4366e8ba

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

UNIT TESTS
-b MAASENG-2165-support-filter-by-ephemeral-deployment lp:~r00ta/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/3554/console
COMMIT: 5a73f84cdf3dfc61c28f55f341e5b02656a38f6d

review: Needs Fixing
Revision history for this message
Björn Tillenius (bjornt) wrote :

+1

review: Approve
d6bf4ca... by Jacopo Rota

add deployment_target in filter_groups response

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

UNIT TESTS
-b MAASENG-2165-support-filter-by-ephemeral-deployment lp:~r00ta/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/3557/console
COMMIT: d6bf4ca7567c36f8d5ab9ce68c43dd8ef1593095

review: Needs Fixing
Revision history for this message
Jacopo Rota (r00ta) wrote :

jenkins: !test

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

UNIT TESTS
-b MAASENG-2165-support-filter-by-ephemeral-deployment lp:~r00ta/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/3559/console
COMMIT: d6bf4ca7567c36f8d5ab9ce68c43dd8ef1593095

review: Needs Fixing
ff755a7... by Jacopo Rota

fix dynamic test

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

UNIT TESTS
-b MAASENG-2165-support-filter-by-ephemeral-deployment lp:~r00ta/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas-tester/3560/console
COMMIT: ff755a7195c105b87d124a5c36aa74dc85dd08b8

review: Needs Fixing
be2448c... by Jacopo Rota

fix dynamic test

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

UNIT TESTS
-b MAASENG-2165-support-filter-by-ephemeral-deployment lp:~r00ta/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: be2448cae6c5f6a3878dab5eeb018b87a31bc099

review: Approve

Update scan failed

At least one of the branches involved have failed to scan. You can manually schedule a rescan if required.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/enum.py b/src/maasserver/enum.py
2index e12bd46..6b98fb2 100644
3--- a/src/maasserver/enum.py
4+++ b/src/maasserver/enum.py
5@@ -411,6 +411,16 @@ class POWER_STATE:
6 POWER_STATE_CHOICES = enum_choices(POWER_STATE, transform=str.capitalize)
7
8
9+class DEPLOYMENT_TARGET:
10+ # A node has been deployed ephemerally
11+ MEMORY = "memory"
12+
13+ DISK = "disk"
14+
15+
16+DEPLOYMENT_TARGET_CHOICES = enum_choices(DEPLOYMENT_TARGET)
17+
18+
19 class BOOT_RESOURCE_TYPE:
20 """Possible types for `BootResource`."""
21
22diff --git a/src/maasserver/node_constraint_filter_forms.py b/src/maasserver/node_constraint_filter_forms.py
23index 41614e5..c76a668 100644
24--- a/src/maasserver/node_constraint_filter_forms.py
25+++ b/src/maasserver/node_constraint_filter_forms.py
26@@ -17,6 +17,8 @@ from django.forms.fields import Field
27 from netaddr import IPAddress
28
29 from maasserver.enum import (
30+ DEPLOYMENT_TARGET,
31+ DEPLOYMENT_TARGET_CHOICES,
32 NODE_STATUS,
33 NODE_STATUS_SHORT_LABEL_CHOICES,
34 POWER_STATE,
35@@ -633,6 +635,7 @@ STATIC_FILTER_FIELDS = (
36 "power_state",
37 "simple_status",
38 "status",
39+ "deployment_target",
40 )
41
42
43@@ -934,9 +937,24 @@ class FilterNodeForm(forms.Form):
44 clean_prefix="=",
45 )
46
47+ deployment_target = ConstrainedMultipleChoiceField(
48+ label="Deployment target",
49+ choices=DEPLOYMENT_TARGET_CHOICES,
50+ required=False,
51+ clean_prefix="=",
52+ )
53+
54+ not_deployment_target = ConstrainedMultipleChoiceField(
55+ label="Deployment target",
56+ choices=DEPLOYMENT_TARGET_CHOICES,
57+ required=False,
58+ clean_prefix="=",
59+ )
60+
61 ignore_unknown_constraints = False
62
63 NODE_FILTERS = {
64+ "deployment_target": ("ephemeral_deploy", _match_any),
65 "fabric_classes": (
66 "current_config__interface__vlan__fabric__class_type",
67 _match_any,
68@@ -965,6 +983,7 @@ class FilterNodeForm(forms.Form):
69 }
70
71 NODE_EXCLUDES = {
72+ "not_deployment_target": ("ephemeral_deploy", _match_any),
73 "not_fabric_classes": (
74 "current_config__interface__vlan__fabric__class_type",
75 _match_any,
76@@ -1147,6 +1166,27 @@ class FilterNodeForm(forms.Form):
77 values = self.cleaned_data["not_power_state"]
78 return [getattr(POWER_STATE, a.upper()) for a in values]
79
80+ def _convert_deployment_target_to_ephemeral_deploy(self, target):
81+ if target is None:
82+ return None
83+ if target == DEPLOYMENT_TARGET.MEMORY:
84+ return True
85+ return False
86+
87+ def clean_deployment_target(self):
88+ values = self.cleaned_data["deployment_target"]
89+ return [
90+ self._convert_deployment_target_to_ephemeral_deploy(a)
91+ for a in values
92+ ]
93+
94+ def clean_not_deployment_target(self):
95+ values = self.cleaned_data["not_deployment_target"]
96+ return [
97+ self._convert_deployment_target_to_ephemeral_deploy(a)
98+ for a in values
99+ ]
100+
101 def clean(self):
102 if not self.ignore_unknown_constraints:
103 unknown_constraints = set(self.data).difference(set(self.fields))
104diff --git a/src/maasserver/tests/test_node_constraint_filter_forms.py b/src/maasserver/tests/test_node_constraint_filter_forms.py
105index 2414112..6a4c0b7 100644
106--- a/src/maasserver/tests/test_node_constraint_filter_forms.py
107+++ b/src/maasserver/tests/test_node_constraint_filter_forms.py
108@@ -14,6 +14,7 @@ from testtools.matchers import (
109 )
110
111 from maasserver.enum import (
112+ DEPLOYMENT_TARGET,
113 FILESYSTEM_GROUP_TYPE,
114 FILESYSTEM_TYPE,
115 INTERFACE_TYPE,
116@@ -1555,6 +1556,8 @@ class TestFilterNodeForm(MAASServerTestCase, FilterConstraintsMixin):
117 "not_owner": factory.make_User().username,
118 "power_state": POWER_STATE.ON,
119 "not_power_state": POWER_STATE.OFF,
120+ "deployment_target": DEPLOYMENT_TARGET.MEMORY,
121+ "not_deployment_target": DEPLOYMENT_TARGET.DISK,
122 }
123 form = FilterNodeForm(data=constraints)
124 self.assertTrue(form.is_valid(), form.errors)
125@@ -2123,6 +2126,8 @@ class TestAcquireNodeForm(MAASServerTestCase, FilterConstraintsMixin):
126 "not_owner": factory.make_User().username,
127 "power_state": POWER_STATE.ON,
128 "not_power_state": POWER_STATE.OFF,
129+ "deployment_target": DEPLOYMENT_TARGET.MEMORY,
130+ "not_deployment_target": DEPLOYMENT_TARGET.DISK,
131 }
132 form = AcquireNodeForm(data=constraints)
133 self.assertTrue(form.is_valid(), form.errors)
134diff --git a/src/maasserver/websockets/handlers/node.py b/src/maasserver/websockets/handlers/node.py
135index 03baa03..f60d52c 100644
136--- a/src/maasserver/websockets/handlers/node.py
137+++ b/src/maasserver/websockets/handlers/node.py
138@@ -15,6 +15,7 @@ from django.db.models import Prefetch, Subquery
139 from lxml import etree
140
141 from maasserver.enum import (
142+ DEPLOYMENT_TARGET_CHOICES,
143 FILESYSTEM_FORMAT_TYPE_CHOICES,
144 FILESYSTEM_FORMAT_TYPE_CHOICES_DICT,
145 INTERFACE_TYPE,
146@@ -1601,6 +1602,11 @@ class NodeHandler(TimestampedModelHandler):
147 {"key": choice, "label": str(choice)}
148 for choice in (True, False)
149 ]
150+ elif key == "deployment_target":
151+ return [
152+ {"key": choice, "label": str(choice)}
153+ for choice in DEPLOYMENT_TARGET_CHOICES
154+ ]
155 else:
156 return self._get_dynamic_filter_options(key)
157
158diff --git a/src/maasserver/websockets/handlers/tests/test_machine.py b/src/maasserver/websockets/handlers/tests/test_machine.py
159index 5cc29bd..d8655bd 100644
160--- a/src/maasserver/websockets/handlers/tests/test_machine.py
161+++ b/src/maasserver/websockets/handlers/tests/test_machine.py
162@@ -5908,6 +5908,20 @@ class TestMachineHandlerNewSchema(MAASServerTestCase):
163 "for_grouping": False,
164 },
165 {
166+ "key": "deployment_target",
167+ "label": "Deployment target",
168+ "dynamic": False,
169+ "type": "list[str]",
170+ "for_grouping": False,
171+ },
172+ {
173+ "key": "not_deployment_target",
174+ "label": "Deployment target",
175+ "dynamic": True,
176+ "type": "list[str]",
177+ "for_grouping": False,
178+ },
179+ {
180 "key": "storage",
181 "label": "Storage",
182 "dynamic": True,
183diff --git a/src/tests/maasserver/websockets/handlers/test_machine.py b/src/tests/maasserver/websockets/handlers/test_machine.py
184index f073699..7f98d26 100644
185--- a/src/tests/maasserver/websockets/handlers/test_machine.py
186+++ b/src/tests/maasserver/websockets/handlers/test_machine.py
187@@ -339,6 +339,47 @@ class TestMachineHandlerNewSchema:
188 )
189 assert result["groups"][0]["count"] == 1
190
191+ def test_filter_deployment_target(self):
192+ user, session = factory.make_User_with_session()
193+ node_with_ephemeral_deployment = factory.make_Node(
194+ owner=user, status=NODE_STATUS.NEW, ephemeral_deploy=True
195+ )
196+ node_with_standard_deployment = factory.make_Node(
197+ owner=user, status=NODE_STATUS.NEW, ephemeral_deploy=False
198+ )
199+ handler = MachineHandler(
200+ user, {}, None, session_id=session.session_key
201+ )
202+
203+ result = handler.list_ids({})
204+ assert result["groups"][0]["count"] == 2
205+
206+ result = handler.list_ids(
207+ {
208+ "filter": {
209+ "deployment_target": ["=memory"],
210+ }
211+ }
212+ )
213+ assert result["groups"][0]["count"] == 1
214+ assert (
215+ result["groups"][0]["items"][0]["id"]
216+ == node_with_ephemeral_deployment.id
217+ )
218+
219+ result = handler.list_ids(
220+ {
221+ "filter": {
222+ "deployment_target": ["=disk"],
223+ }
224+ }
225+ )
226+ assert result["groups"][0]["count"] == 1
227+ assert (
228+ result["groups"][0]["items"][0]["id"]
229+ == node_with_standard_deployment.id
230+ )
231+
232 def test_filter_counters(self):
233 user, session = factory.make_User_with_session()
234 nodes = [factory.make_Machine(owner=user) for _ in range(2)]

Subscribers

People subscribed via source and target branches