Merge lp:~blake-rouse/maas/fix-1674788 into lp:~maas-committers/maas/trunk

Proposed by Blake Rouse
Status: Merged
Approved by: Blake Rouse
Approved revision: no longer in the source branch.
Merged at revision: 5832
Proposed branch: lp:~blake-rouse/maas/fix-1674788
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 61 lines (+38/-2)
2 files modified
src/maasserver/api/machines.py (+4/-2)
src/maasserver/api/tests/test_machines.py (+34/-0)
To merge this branch: bzr merge lp:~blake-rouse/maas/fix-1674788
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
LaMont Jones (community) Approve
Review via email: mp+320545@code.launchpad.net

Commit message

Fix allocate API to work with architecture wildcards.

To post a comment you must log in.
Revision history for this message
LaMont Jones (lamont) wrote :

LGTM

review: Approve
Revision history for this message
Gavin Panella (allenap) :
Revision history for this message
Gavin Panella (allenap) :
review: Approve
Revision history for this message
Blake Rouse (blake-rouse) :
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (1.8 MiB)

The attempt to merge lp:~blake-rouse/maas/fix-1674788 into lp:maas failed. Below is the output from the failed tests.

Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB]
Hit:2 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial InRelease
Get:3 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]
Get:4 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]
Fetched 306 kB in 0s (636 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind avahi-utils bash bind9 bind9utils build-essential bzr bzr-builddeb chromium-browser chromium-chromedriver curl daemontools debhelper dh-apport dh-systemd distro-info dnsutils firefox freeipmi-tools git gjs ipython isc-dhcp-common isc-dhcp-server libjs-angularjs libjs-jquery libjs-jquery-hotkeys libjs-yui3-full libjs-yui3-min libnss-wrapper libpq-dev make nodejs-legacy npm postgresql psmisc pxelinux python3-all python3-apt python3-attr python3-bson python3-convoy python3-crochet python3-cssselect python3-curtin python3-dev python3-distro-info python3-django python3-django-nose python3-django-piston3 python3-dnspython python3-docutils python3-formencode python3-hivex python3-httplib2 python3-jinja2 python3-jsonschema python3-lxml python3-netaddr python3-netifaces python3-novaclient python3-oauth python3-oauthlib python3-openssl python3-paramiko python3-petname python3-pexpect python3-psycopg2 python3-pyinotify python3-pyparsing python3-pyvmomi python3-requests python3-seamicroclient python3-setuptools python3-simplestreams python3-sphinx python3-tempita python3-twisted python3-txtftp python3-tz python3-yaml python3-zope.interface python-bson python-crochet python-django python-django-piston python-djorm-ext-pgarray python-formencode python-lxml python-netaddr python-netifaces python-pocket-lint python-psycopg2 python-simplejson python-tempita python-twisted python-yaml socat syslinux-common tgt ubuntu-cloudimage-keyring wget xvfb
Reading package lists...
Building dependency tree...
Reading state information...
authbind is already the newest version (2.1.1+nmu1).
avahi-utils is already the newest version (0.6.32~rc+dfsg-1ubuntu2).
build-essential is already the newest version (12.1ubuntu2).
debhelper is already the newest version (9.20160115ubuntu3).
distro-info is already the newest version (0.14build1).
git is already the newest version (1:2.7.4-0ubuntu1).
libjs-angularjs is already the newest version (1.2.28-1ubuntu2).
libjs-jquery is already the newest version (1.11.3+dfsg-4).
libjs-yui3-full is already the newest version (3.5.1-1ubuntu3).
libjs-yui3-min is already the newest version (3.5.1-1ubuntu3).
make is already the newest version (4.1-6).
postgresql is already the newest version (9.5+173).
psmisc is already the newest version (22.21-2.1build1).
pxelinux is already the newest version (3:6.03+dfsg-11ubuntu1).
python-formencode is already the newest version (1.3.0-0ubuntu5).
python-lxml is already the newest version (3.5.0-1build1).
python-netaddr is already the newest version (0.7.18-1).
python-netifaces i...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/machines.py'
2--- src/maasserver/api/machines.py 2017-03-09 16:14:58 +0000
3+++ src/maasserver/api/machines.py 2017-03-21 19:15:32 +0000
4@@ -1335,8 +1335,10 @@
5 memory = int(memory)
6 architecture = None
7 architectures = form.cleaned_data.get('arch')
8- if architectures is not None and len(architectures) == 1:
9- architecture = architectures[0]
10+ if architectures is not None:
11+ architecture = (
12+ None if len(architectures) == 0
13+ else min(architectures))
14 data = {
15 "cores": cores,
16 "memory": memory,
17
18=== modified file 'src/maasserver/api/tests/test_machines.py'
19--- src/maasserver/api/tests/test_machines.py 2017-03-09 18:53:37 +0000
20+++ src/maasserver/api/tests/test_machines.py 2017-03-21 19:15:32 +0000
21@@ -637,6 +637,40 @@
22 self.assertEqual(machine.system_id, parsed_result['system_id'])
23 self.assertThat(mock_compose, MockCalledOnceWith())
24
25+ def test_POST_allocate_returns_a_composed_machine_wildcard_arch(self):
26+ # The "allocate" operation returns a composed machine.
27+ available_status = NODE_STATUS.READY
28+ architectures = [
29+ "amd64/generic", "i386/generic",
30+ "armhf/generic", "arm64/generic"
31+ ]
32+ pod = factory.make_Pod(architectures=architectures)
33+ pod.hints.cores = random.randint(8, 16)
34+ pod.hints.memory = random.randint(4096, 8192)
35+ pod.hints.save()
36+ machine = factory.make_Node(
37+ status=available_status, owner=None, with_boot_disk=True)
38+ mock_list_all_usable_architectures = self.patch(
39+ forms_module, 'list_all_usable_architectures')
40+ mock_list_all_usable_architectures.return_value = sorted(
41+ pod.architectures)
42+ mock_filter_nodes = self.patch(AcquireNodeForm, 'filter_nodes')
43+ mock_filter_nodes.return_value = [], {}, {}
44+ mock_compose = self.patch(ComposeMachineForPodsForm, 'compose')
45+ mock_compose.return_value = machine
46+ response = self.client.post(
47+ reverse('machines_handler'), {
48+ 'op': 'allocate',
49+ 'cpu_count': pod.hints.cores,
50+ 'mem': pod.hints.memory,
51+ 'arch': 'amd64'
52+ })
53+ self.assertEqual(http.client.OK, response.status_code)
54+ parsed_result = json.loads(
55+ response.content.decode(settings.DEFAULT_CHARSET))
56+ self.assertEqual(machine.system_id, parsed_result['system_id'])
57+ self.assertThat(mock_compose, MockCalledOnceWith())
58+
59 def test_POST_allocate_allocates_machine(self):
60 # The "allocate" operation allocates the machine it returns.
61 available_status = NODE_STATUS.READY