Merge lp:~lamont/maas/bug-1614584-2.1 into lp:maas/2.1

Proposed by LaMont Jones
Status: Merged
Approved by: LaMont Jones
Approved revision: no longer in the source branch.
Merged at revision: 5562
Proposed branch: lp:~lamont/maas/bug-1614584-2.1
Merge into: lp:maas/2.1
Diff against target: 86 lines (+27/-7)
4 files modified
docs/changelog.rst (+2/-0)
src/maasserver/models/node.py (+13/-1)
src/maasserver/models/tests/test_node.py (+6/-1)
src/maasserver/models/tests/test_staticipaddress.py (+6/-5)
To merge this branch: bzr merge lp:~lamont/maas/bug-1614584-2.1
Reviewer Review Type Date Requested Status
LaMont Jones (community) Approve
Review via email: mp+312651@code.launchpad.net

Commit message

Handle the case where gethostname() returns an FQDN.

Description of the change

Handle the case where gethostname() returns an FQDN.

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

Self-approval of trivial backport.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'docs/changelog.rst'
2--- docs/changelog.rst 2016-12-06 13:20:47 +0000
3+++ docs/changelog.rst 2016-12-07 12:55:26 +0000
4@@ -9,6 +9,8 @@
5 --------------------------
6
7
8+LP: #1614584 MAAS fails to start when gethostname returns an FQDN.
9+
10 LP: #1582323 Select MAAS datasource specifically to ensure commissioning doesn't fail when competing cloud metadata resides on disk
11
12 LP: #1646163 [2.1] Icon need to be improved
13
14=== modified file 'src/maasserver/models/node.py'
15--- src/maasserver/models/node.py 2016-10-31 21:41:45 +0000
16+++ src/maasserver/models/node.py 2016-12-07 12:55:26 +0000
17@@ -755,7 +755,19 @@
18 regiond has run on it. Create a region controller only; it can be
19 upgraded to a region+rack controller later if necessary.
20 """
21- return self.create(owner=get_worker_user(), hostname=gethostname())
22+ hostname = gethostname()
23+ # Bug#1614584: it is possible that gethostname() reurns the FQDN.
24+ # Split it up, and get the appropriate domain. If we wind up creating
25+ # one for it, we are not authoritative.
26+ # Just in case the default domain has not been created, let's create it
27+ # here, even if we subsequently overwrite it inside the if statement.
28+ domain = Domain.objects.get_default_domain()
29+ if hostname.find('.') > 0:
30+ hostname, domainname = hostname.split('.', 1)
31+ (domain, _) = Domain.objects.get_or_create(
32+ name=domainname, defaults={'authoritative': False})
33+ return self.create(
34+ owner=get_worker_user(), hostname=hostname, domain=domain)
35
36
37 def get_default_domain():
38
39=== modified file 'src/maasserver/models/tests/test_node.py'
40--- src/maasserver/models/tests/test_node.py 2016-10-31 20:37:57 +0000
41+++ src/maasserver/models/tests/test_node.py 2016-12-07 12:55:26 +0000
42@@ -595,7 +595,12 @@
43 super().setUp()
44 # Patch out gethostname and get_mac_addresses.
45 self.patch_autospec(node_module, "gethostname")
46- node_module.gethostname.return_value = factory.make_name("host")
47+ hostname = factory.make_name('host')
48+ # Bug#1614584: make sure that we handle the case where gethostname()
49+ # returns an FQDN, instead of a domainless hostname.
50+ if factory.pick_bool():
51+ hostname += ".%s" % factory.make_name('domain')
52+ node_module.gethostname.return_value = hostname
53 self.patch_autospec(node_module, "get_mac_addresses")
54 node_module.get_mac_addresses.return_value = []
55
56
57=== modified file 'src/maasserver/models/tests/test_staticipaddress.py'
58--- src/maasserver/models/tests/test_staticipaddress.py 2016-10-18 08:00:37 +0000
59+++ src/maasserver/models/tests/test_staticipaddress.py 2016-12-07 12:55:26 +0000
60@@ -397,20 +397,21 @@
61 alloc_type=IPADDRESS_TYPE.STICKY,
62 ip=factory.pick_ip_in_Subnet(subnet),
63 subnet=subnet, interface=boot_interface)
64- ifaces = node.interface_set.exclude(interface=boot_interface)
65+ iface2 = node.interface_set.exclude(id=boot_interface.id).first()
66 sip2 = factory.make_StaticIPAddress(
67 alloc_type=IPADDRESS_TYPE.STICKY,
68 ip=factory.pick_ip_in_Subnet(subnet),
69- subnet=subnet, interface=ifaces[0])
70+ subnet=subnet, interface=iface2)
71 mapping = StaticIPAddress.objects.get_hostname_ip_mapping(subnet)
72- self.assertEqual({
73+ expected = {
74 full_hostname:
75 HostnameIPMapping(
76 node.system_id, 30, {staticip.ip}, node.node_type),
77- "%s.%s" % (ifaces[0].name, full_hostname):
78+ "%s.%s" % (iface2.name, full_hostname):
79 HostnameIPMapping(
80 node.system_id, 30, {sip2.ip}, node.node_type),
81- }, mapping)
82+ }
83+ self.assertEqual(expected, mapping)
84
85 def make_mapping(self, node, raw_ttl=False):
86 if raw_ttl or node.address_ttl is not None:

Subscribers

People subscribed via source and target branches

to all changes: