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

Proposed by Newell Jensen on 2017-07-27
Status: Merged
Approved by: Newell Jensen on 2017-07-27
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 Approve on 2017-07-27
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.
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
1diff --git a/docs/changelog.rst b/docs/changelog.rst
2index abea670..092bd1d 100644
3--- a/docs/changelog.rst
4+++ b/docs/changelog.rst
5@@ -8,6 +8,8 @@ Changelog
6 Bugs fixed in this release
7 --------------------------
8
9+LP: #1706196 Exclude pod machine composition during allocation if tags are supplied.
10+
11 LP: #1700802 Add missing networking constraint names.
12
13 LP: #1702690 Set the machine's min_hwe_kernel to the setting's default_min_hwe_kernel when commissioning.
14diff --git a/src/maasserver/api/machines.py b/src/maasserver/api/machines.py
15index f986d35..2bbc845 100644
16--- a/src/maasserver/api/machines.py
17+++ b/src/maasserver/api/machines.py
18@@ -1405,11 +1405,11 @@ class MachinesHandler(NodesHandler, PowersMixin):
19 # XXX AndresRodriguez 2016-10-27: If new params are added and are not
20 # constraints, these need to be added to IGNORED_FIELDS in
21 # src/maasserver/node_constraint_filter_forms.py.
22- input_constraints = str([
23- param for param in request.data.lists() if param[0] != 'op'])
24+ input_constraints = [
25+ param for param in request.data.lists() if param[0] != 'op']
26 maaslog.info(
27 "Request from user %s to acquire a machine with constraints: %s",
28- request.user.username, input_constraints)
29+ request.user.username, str(input_constraints))
30 agent_name, bridge_all, bridge_fd, bridge_stp, comment = (
31 get_allocation_parameters(request))
32 verbose = get_optional_param(
33@@ -1450,7 +1450,11 @@ class MachinesHandler(NodesHandler, PowersMixin):
34 "storage": storage,
35 }
36 pods = Pod.objects.all()
37- if pods:
38+ # We don't want to compose a machine from a pod if the
39+ # constraints contain tags.
40+ if pods and not any(
41+ 'tags' in constraint
42+ for constraint in input_constraints):
43 if form.cleaned_data.get('pod'):
44 pods = pods.filter(name=form.cleaned_data.get('pod'))
45 elif form.cleaned_data.get('pod_type'):
46@@ -1477,7 +1481,7 @@ class MachinesHandler(NodesHandler, PowersMixin):
47 message = (
48 'No available machine matches constraints: %s '
49 '(resolved to "%s")' % (
50- input_constraints, constraints))
51+ str(input_constraints), constraints))
52 raise NodesNotAvailable(message)
53 if not dry_run:
54 machine.acquire(
55diff --git a/src/maasserver/api/tests/test_machines.py b/src/maasserver/api/tests/test_machines.py
56index 021a30a..943a40b 100644
57--- a/src/maasserver/api/tests/test_machines.py
58+++ b/src/maasserver/api/tests/test_machines.py
59@@ -1055,6 +1055,26 @@ class TestMachinesAPI(APITestCase.ForUser):
60 response.content.decode(settings.DEFAULT_CHARSET))
61 self.assertItemsEqual(machine_tag_names, response_json['tag_names'])
62
63+ def test_POST_allocate_does_not_compose_machine_by_tags(self):
64+ pod = factory.make_Pod()
65+ pod.architectures = [random.choice([
66+ "amd64/generic", "i386/generic",
67+ "armhf/generic", "arm64/generic"
68+ ])]
69+ pod.save()
70+ mock_filter_nodes = self.patch(AcquireNodeForm, 'filter_nodes')
71+ mock_filter_nodes.return_value = [], {}, {}
72+ mock_compose = self.patch(ComposeMachineForPodsForm, 'compose')
73+ factory.make_Tag('fast')
74+ factory.make_Tag('stable')
75+ # Legacy call using comma-separated tags.
76+ response = self.client.post(reverse('machines_handler'), {
77+ 'op': 'allocate',
78+ 'tags': ['fast', 'stable'],
79+ })
80+ self.assertThat(response, HasStatusCode(http.client.CONFLICT))
81+ self.assertThat(mock_compose, MockNotCalled())
82+
83 def test_POST_allocate_allocates_machine_by_negated_tags(self):
84 tagged_machine = factory.make_Node(
85 status=NODE_STATUS.READY, with_boot_disk=True)

Subscribers

People subscribed via source and target branches

to all changes: