Merge lp:~andreserl/maas/lp1610397 into lp:~maas-committers/maas/trunk

Proposed by Andres Rodriguez
Status: Merged
Approved by: Andres Rodriguez
Approved revision: no longer in the source branch.
Merged at revision: 5231
Proposed branch: lp:~andreserl/maas/lp1610397
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 68 lines (+50/-0)
2 files modified
src/maasserver/forms.py (+8/-0)
src/maasserver/tests/test_forms_device.py (+42/-0)
To merge this branch: bzr merge lp:~andreserl/maas/lp1610397
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
LaMont Jones (community) Approve
Review via email: mp+302419@code.launchpad.net

Commit message

Ensure that containers with parents (typically, juju created containers), inherit the parent's domain name. If juju wishes to change the domain, they can do so by creating a device and specifying the domain.

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

Looks good

review: Approve
Revision history for this message
Blake Rouse (blake-rouse) :
review: Needs Information
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good. Thanks for the fixes.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :
Download full text (31.3 KiB)

The attempt to merge lp:~andreserl/maas/lp1610397 into lp:maas failed. Below is the output from the failed tests.

Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [94.5 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 [95.7 kB]
Hit:4 http://prodstack-zone-2.clouds.archive.ubuntu.com/ubuntu xenial-backports InRelease
Fetched 190 kB in 0s (465 kB/s)
Reading package lists...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y \
    --no-install-recommends install apache2 archdetect-deb authbind 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 libpq-dev make nodejs-legacy npm postgresql pxelinux python3-all python3-apt 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...
archdetect-deb is already the newest version (1.117ubuntu2).
authbind is already the newest version (2.1.1+nmu1).
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).
freeipmi-tools is already the newest version (1.4.11-1ubuntu1).
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).
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 is already the newest version (0.10.4-0.1build2).
python-ps...

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/forms.py'
2--- src/maasserver/forms.py 2016-07-28 09:10:51 +0000
3+++ src/maasserver/forms.py 2016-08-09 15:11:21 +0000
4@@ -788,6 +788,14 @@
5 if self.new_node:
6 # Set the owner: devices are owned by their creator.
7 device.owner = self.request.user
8+
9+ # If the device has a parent and no domain was provided,
10+ # inherit the parent's domain.
11+ if device.parent:
12+ if (not self.cleaned_data.get('domain', None) and
13+ device.parent.domain):
14+ device.domain = device.parent.domain
15+
16 device.save()
17 return device
18
19
20=== modified file 'src/maasserver/tests/test_forms_device.py'
21--- src/maasserver/tests/test_forms_device.py 2016-04-22 17:28:15 +0000
22+++ src/maasserver/tests/test_forms_device.py 2016-08-09 15:11:21 +0000
23@@ -101,3 +101,45 @@
24 self.assertThat(iface.node, Equals(device))
25 iface = get_one(Interface.objects.filter(mac_address=mac2))
26 self.assertThat(iface.node, Equals(device))
27+
28+ def test_creates_device_with_parent_inherits_parents_domain(self):
29+ parent = factory.make_Node()
30+ hostname = factory.make_name("device")
31+ mac1 = factory.make_mac_address()
32+ mac2 = factory.make_mac_address()
33+ form = DeviceWithMACsForm(data=get_QueryDict({
34+ "hostname": hostname,
35+ "mac_addresses": [mac1, mac2],
36+ "parent": parent.system_id,
37+ }), request=self.make_request())
38+ self.assertTrue(form.is_valid(), dict(form.errors))
39+ form.save()
40+ device = get_one(Device.objects.filter(hostname=hostname))
41+ self.assertThat(device.hostname, Equals(hostname))
42+ self.assertThat(device.domain, Equals(parent.domain))
43+ iface = get_one(Interface.objects.filter(mac_address=mac1))
44+ self.assertThat(iface.node, Equals(device))
45+ iface = get_one(Interface.objects.filter(mac_address=mac2))
46+ self.assertThat(iface.node, Equals(device))
47+
48+ def test_creates_device_with_domain_and_parent(self):
49+ parent = factory.make_Node()
50+ hostname = factory.make_name("device")
51+ mac1 = factory.make_mac_address()
52+ mac2 = factory.make_mac_address()
53+ domain = factory.make_Domain()
54+ form = DeviceWithMACsForm(data=get_QueryDict({
55+ "hostname": hostname,
56+ "mac_addresses": [mac1, mac2],
57+ "parent": parent.system_id,
58+ "domain": domain.name,
59+ }), request=self.make_request())
60+ self.assertTrue(form.is_valid(), dict(form.errors))
61+ form.save()
62+ device = get_one(Device.objects.filter(hostname=hostname))
63+ self.assertThat(device.hostname, Equals(hostname))
64+ self.assertThat(device.domain, Equals(domain))
65+ iface = get_one(Interface.objects.filter(mac_address=mac1))
66+ self.assertThat(iface.node, Equals(device))
67+ iface = get_one(Interface.objects.filter(mac_address=mac2))
68+ self.assertThat(iface.node, Equals(device))