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

Proposed by Newell Jensen
Status: Merged
Approved by: Newell Jensen
Approved revision: 9b02c13f5825bd6b8d4c139be2f14135ffab30bf
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~newell-jensen/maas:lp1706196
Merge into: maas:master
Diff against target: 72 lines (+29/-5)
2 files modified
src/maasserver/api/machines.py (+9/-5)
src/maasserver/api/tests/test_machines.py (+20/-0)
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+328146@code.launchpad.net

Commit message

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
Blake Rouse (blake-rouse) wrote :

Looks good overall, but a question first.

review: Needs Information
Revision history for this message
Newell Jensen (newell-jensen) wrote :

Replied inline. Since input_constraints is a list of tuples, was searching to see if the key 'tags' was in one of the tuples.

~newell-jensen/maas:lp1706196 updated
fed8060... by Newell Jensen

Clean up code.

1737b4b... by Newell Jensen

Change logical statement for checking if 'tags' is part of the input_constraints.

Revision history for this message
Blake Rouse (blake-rouse) wrote :

Thanks for the fixes

review: Approve
~newell-jensen/maas:lp1706196 updated
9b02c13... by Newell Jensen

Delete print statement used for debugging.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/src/maasserver/api/machines.py b/src/maasserver/api/machines.py
index dfca107..b709e10 100644
--- a/src/maasserver/api/machines.py
+++ b/src/maasserver/api/machines.py
@@ -1412,11 +1412,11 @@ class MachinesHandler(NodesHandler, PowersMixin):
1412 # XXX AndresRodriguez 2016-10-27: If new params are added and are not1412 # XXX AndresRodriguez 2016-10-27: If new params are added and are not
1413 # constraints, these need to be added to IGNORED_FIELDS in1413 # constraints, these need to be added to IGNORED_FIELDS in
1414 # src/maasserver/node_constraint_filter_forms.py.1414 # src/maasserver/node_constraint_filter_forms.py.
1415 input_constraints = str([1415 input_constraints = [
1416 param for param in request.data.lists() if param[0] != 'op'])1416 param for param in request.data.lists() if param[0] != 'op']
1417 maaslog.info(1417 maaslog.info(
1418 "Request from user %s to acquire a machine with constraints: %s",1418 "Request from user %s to acquire a machine with constraints: %s",
1419 request.user.username, input_constraints)1419 request.user.username, str(input_constraints))
1420 agent_name, bridge_all, bridge_fd, bridge_stp, comment = (1420 agent_name, bridge_all, bridge_fd, bridge_stp, comment = (
1421 get_allocation_parameters(request))1421 get_allocation_parameters(request))
1422 verbose = get_optional_param(1422 verbose = get_optional_param(
@@ -1457,7 +1457,11 @@ class MachinesHandler(NodesHandler, PowersMixin):
1457 "storage": storage,1457 "storage": storage,
1458 }1458 }
1459 pods = Pod.objects.all()1459 pods = Pod.objects.all()
1460 if pods:1460 # We don't want to compose a machine from a pod if the
1461 # constraints contain tags.
1462 if pods and not any(
1463 'tags' in constraint
1464 for constraint in input_constraints):
1461 if form.cleaned_data.get('pod'):1465 if form.cleaned_data.get('pod'):
1462 pods = pods.filter(name=form.cleaned_data.get('pod'))1466 pods = pods.filter(name=form.cleaned_data.get('pod'))
1463 elif form.cleaned_data.get('pod_type'):1467 elif form.cleaned_data.get('pod_type'):
@@ -1484,7 +1488,7 @@ class MachinesHandler(NodesHandler, PowersMixin):
1484 message = (1488 message = (
1485 'No available machine matches constraints: %s '1489 'No available machine matches constraints: %s '
1486 '(resolved to "%s")' % (1490 '(resolved to "%s")' % (
1487 input_constraints, constraints))1491 str(input_constraints), constraints))
1488 raise NodesNotAvailable(message)1492 raise NodesNotAvailable(message)
1489 if not dry_run:1493 if not dry_run:
1490 machine.acquire(1494 machine.acquire(
diff --git a/src/maasserver/api/tests/test_machines.py b/src/maasserver/api/tests/test_machines.py
index c9d0c7e..f9d53e9 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