Merge ~newell-jensen/maas:2.2-lp1706196 into maas:2.2

Proposed by Newell Jensen
Status: Merged
Approved by: Newell Jensen
Approved revision: 3b2193b0246478a2e4600722fcc9109ec5e6bf14
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~newell-jensen/maas:2.2-lp1706196
Merge into: maas:2.2
Diff against target: 85 lines (+31/-5)
3 files modified
docs/changelog.rst (+2/-0)
src/maasserver/api/machines.py (+9/-5)
src/maasserver/api/tests/test_machines.py (+20/-0)
Reviewer Review Type Date Requested Status
Newell Jensen (community) Approve
Review via email: mp+328188@code.launchpad.net

Commit message

Backport 203936f14ba93a88ec95eb63f548af35adb226f7 from master.

LP: #1706196 - Don't allocate composed machine with tags.

Exclude pod machine composition during allocation if tags are supplied.

To post a comment you must log in.
Revision history for this message
Newell Jensen (newell-jensen) wrote :

Self approved backport.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/docs/changelog.rst b/docs/changelog.rst
index abea670..092bd1d 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -8,6 +8,8 @@ Changelog
8Bugs fixed in this release8Bugs fixed in this release
9--------------------------9--------------------------
1010
11LP: #1706196 Exclude pod machine composition during allocation if tags are supplied.
12
11LP: #1700802 Add missing networking constraint names.13LP: #1700802 Add missing networking constraint names.
1214
13LP: #1702690 Set the machine's min_hwe_kernel to the setting's default_min_hwe_kernel when commissioning.15LP: #1702690 Set the machine's min_hwe_kernel to the setting's default_min_hwe_kernel when commissioning.
diff --git a/src/maasserver/api/machines.py b/src/maasserver/api/machines.py
index f986d35..2bbc845 100644
--- a/src/maasserver/api/machines.py
+++ b/src/maasserver/api/machines.py
@@ -1405,11 +1405,11 @@ class MachinesHandler(NodesHandler, PowersMixin):
1405 # XXX AndresRodriguez 2016-10-27: If new params are added and are not1405 # XXX AndresRodriguez 2016-10-27: If new params are added and are not
1406 # constraints, these need to be added to IGNORED_FIELDS in1406 # constraints, these need to be added to IGNORED_FIELDS in
1407 # src/maasserver/node_constraint_filter_forms.py.1407 # src/maasserver/node_constraint_filter_forms.py.
1408 input_constraints = str([1408 input_constraints = [
1409 param for param in request.data.lists() if param[0] != 'op'])1409 param for param in request.data.lists() if param[0] != 'op']
1410 maaslog.info(1410 maaslog.info(
1411 "Request from user %s to acquire a machine with constraints: %s",1411 "Request from user %s to acquire a machine with constraints: %s",
1412 request.user.username, input_constraints)1412 request.user.username, str(input_constraints))
1413 agent_name, bridge_all, bridge_fd, bridge_stp, comment = (1413 agent_name, bridge_all, bridge_fd, bridge_stp, comment = (
1414 get_allocation_parameters(request))1414 get_allocation_parameters(request))
1415 verbose = get_optional_param(1415 verbose = get_optional_param(
@@ -1450,7 +1450,11 @@ class MachinesHandler(NodesHandler, PowersMixin):
1450 "storage": storage,1450 "storage": storage,
1451 }1451 }
1452 pods = Pod.objects.all()1452 pods = Pod.objects.all()
1453 if pods:1453 # We don't want to compose a machine from a pod if the
1454 # constraints contain tags.
1455 if pods and not any(
1456 'tags' in constraint
1457 for constraint in input_constraints):
1454 if form.cleaned_data.get('pod'):1458 if form.cleaned_data.get('pod'):
1455 pods = pods.filter(name=form.cleaned_data.get('pod'))1459 pods = pods.filter(name=form.cleaned_data.get('pod'))
1456 elif form.cleaned_data.get('pod_type'):1460 elif form.cleaned_data.get('pod_type'):
@@ -1477,7 +1481,7 @@ class MachinesHandler(NodesHandler, PowersMixin):
1477 message = (1481 message = (
1478 'No available machine matches constraints: %s '1482 'No available machine matches constraints: %s '
1479 '(resolved to "%s")' % (1483 '(resolved to "%s")' % (
1480 input_constraints, constraints))1484 str(input_constraints), constraints))
1481 raise NodesNotAvailable(message)1485 raise NodesNotAvailable(message)
1482 if not dry_run:1486 if not dry_run:
1483 machine.acquire(1487 machine.acquire(
diff --git a/src/maasserver/api/tests/test_machines.py b/src/maasserver/api/tests/test_machines.py
index 021a30a..943a40b 100644
--- a/src/maasserver/api/tests/test_machines.py
+++ b/src/maasserver/api/tests/test_machines.py
@@ -1055,6 +1055,26 @@ class TestMachinesAPI(APITestCase.ForUser):
1055 response.content.decode(settings.DEFAULT_CHARSET))1055 response.content.decode(settings.DEFAULT_CHARSET))
1056 self.assertItemsEqual(machine_tag_names, response_json['tag_names'])1056 self.assertItemsEqual(machine_tag_names, response_json['tag_names'])
10571057
1058 def test_POST_allocate_does_not_compose_machine_by_tags(self):
1059 pod = factory.make_Pod()
1060 pod.architectures = [random.choice([
1061 "amd64/generic", "i386/generic",
1062 "armhf/generic", "arm64/generic"
1063 ])]
1064 pod.save()
1065 mock_filter_nodes = self.patch(AcquireNodeForm, 'filter_nodes')
1066 mock_filter_nodes.return_value = [], {}, {}
1067 mock_compose = self.patch(ComposeMachineForPodsForm, 'compose')
1068 factory.make_Tag('fast')
1069 factory.make_Tag('stable')
1070 # Legacy call using comma-separated tags.
1071 response = self.client.post(reverse('machines_handler'), {
1072 'op': 'allocate',
1073 'tags': ['fast', 'stable'],
1074 })
1075 self.assertThat(response, HasStatusCode(http.client.CONFLICT))
1076 self.assertThat(mock_compose, MockNotCalled())
1077
1058 def test_POST_allocate_allocates_machine_by_negated_tags(self):1078 def test_POST_allocate_allocates_machine_by_negated_tags(self):
1059 tagged_machine = factory.make_Node(1079 tagged_machine = factory.make_Node(
1060 status=NODE_STATUS.READY, with_boot_disk=True)1080 status=NODE_STATUS.READY, with_boot_disk=True)

Subscribers

People subscribed via source and target branches