Merge lp:~lamont/maas/bug-1590021 into lp:~maas-committers/maas/trunk

Proposed by LaMont Jones
Status: Merged
Approved by: LaMont Jones
Approved revision: no longer in the source branch.
Merged at revision: 5086
Proposed branch: lp:~lamont/maas/bug-1590021
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 61 lines (+31/-2)
2 files modified
src/maasserver/api/ip_addresses.py (+1/-1)
src/maasserver/api/tests/test_ipaddresses.py (+30/-1)
To merge this branch: bzr merge lp:~lamont/maas/bug-1590021
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+296684@code.launchpad.net

Commit message

Fix typo in the handling of api "ipaddresses reserve hostname=".

Description of the change

Fix typo in the handling of api "ipaddresses reserve hostname=".

To post a comment you must log in.
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good. Does this affect 1.9?

review: Approve
Revision history for this message
LaMont Jones (lamont) wrote :

> Looks good. Does this affect 1.9?

This was not a thing in 1.9 (DNSResource wasn't there.)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/api/ip_addresses.py'
2--- src/maasserver/api/ip_addresses.py 2016-03-31 23:34:55 +0000
3+++ src/maasserver/api/ip_addresses.py 2016-06-07 14:57:13 +0000
4@@ -116,7 +116,7 @@
5 alloc_type=IPADDRESS_TYPE.USER_RESERVED,
6 user=user)
7 if hostname is not None and hostname != '':
8- dnsrr = DNSResource.objects.get_or_create(
9+ dnsrr, _ = DNSResource.objects.get_or_create(
10 name=hostname, domain=domain)
11 dnsrr.ip_addresses.add(sip)
12 maaslog.info(
13
14=== modified file 'src/maasserver/api/tests/test_ipaddresses.py'
15--- src/maasserver/api/tests/test_ipaddresses.py 2016-05-24 22:05:45 +0000
16+++ src/maasserver/api/tests/test_ipaddresses.py 2016-06-07 14:57:13 +0000
17@@ -15,7 +15,10 @@
18 INTERFACE_TYPE,
19 IPADDRESS_TYPE,
20 )
21-from maasserver.models import StaticIPAddress
22+from maasserver.models import (
23+ DNSResource,
24+ StaticIPAddress,
25+)
26 from maasserver.testing.api import APITestCase
27 from maasserver.testing.factory import factory
28 from maasserver.utils.converters import json_load_bytes
29@@ -85,6 +88,32 @@
30 IPADDRESS_TYPE.USER_RESERVED, staticipaddress.alloc_type)
31 self.assertEqual(self.user, staticipaddress.user)
32
33+ def test_POST_reserve_creates_dnsresource(self):
34+ # The api doesn't autocreate the domain, so create one now.
35+ domain = factory.make_Domain()
36+ hostname = factory.make_name("host")
37+ fqdn = "%s.%s" % (hostname, domain.name)
38+ subnet = factory.make_Subnet()
39+ response = self.post_reservation_request(subnet, hostname=fqdn)
40+ self.assertEqual(http.client.OK, response.status_code)
41+ returned_address = json_load_bytes(response.content)
42+ [staticipaddress] = StaticIPAddress.objects.all()
43+ # We don't need to test the value of the 'created' datetime
44+ # field. By removing it, we also test for its presence.
45+ del returned_address['created']
46+ del returned_address['subnet']
47+ expected = dict(
48+ alloc_type=staticipaddress.alloc_type,
49+ ip=staticipaddress.ip,
50+ resource_uri=reverse('ipaddresses_handler'),
51+ )
52+ self.assertEqual(expected, returned_address)
53+ self.assertEqual(
54+ IPADDRESS_TYPE.USER_RESERVED, staticipaddress.alloc_type)
55+ self.assertEqual(self.user, staticipaddress.user)
56+ dnsrr = DNSResource.objects.get(name=hostname, domain=domain)
57+ self.assertItemsEqual(dnsrr.ip_addresses.all(), [staticipaddress])
58+
59 def test_POST_reserve_with_MAC_links_MAC_to_ip_address(self):
60 subnet = factory.make_Subnet()
61 mac = factory.make_mac_address()