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
=== modified file 'docs/changelog.rst'
--- docs/changelog.rst 2016-12-06 13:20:47 +0000
+++ docs/changelog.rst 2016-12-07 12:55:26 +0000
@@ -9,6 +9,8 @@
9--------------------------9--------------------------
1010
1111
12LP: #1614584 MAAS fails to start when gethostname returns an FQDN.
13
12LP: #1582323 Select MAAS datasource specifically to ensure commissioning doesn't fail when competing cloud metadata resides on disk14LP: #1582323 Select MAAS datasource specifically to ensure commissioning doesn't fail when competing cloud metadata resides on disk
1315
14LP: #1646163 [2.1] Icon need to be improved16LP: #1646163 [2.1] Icon need to be improved
1517
=== modified file 'src/maasserver/models/node.py'
--- src/maasserver/models/node.py 2016-10-31 21:41:45 +0000
+++ src/maasserver/models/node.py 2016-12-07 12:55:26 +0000
@@ -755,7 +755,19 @@
755 regiond has run on it. Create a region controller only; it can be755 regiond has run on it. Create a region controller only; it can be
756 upgraded to a region+rack controller later if necessary.756 upgraded to a region+rack controller later if necessary.
757 """757 """
758 return self.create(owner=get_worker_user(), hostname=gethostname())758 hostname = gethostname()
759 # Bug#1614584: it is possible that gethostname() reurns the FQDN.
760 # Split it up, and get the appropriate domain. If we wind up creating
761 # one for it, we are not authoritative.
762 # Just in case the default domain has not been created, let's create it
763 # here, even if we subsequently overwrite it inside the if statement.
764 domain = Domain.objects.get_default_domain()
765 if hostname.find('.') > 0:
766 hostname, domainname = hostname.split('.', 1)
767 (domain, _) = Domain.objects.get_or_create(
768 name=domainname, defaults={'authoritative': False})
769 return self.create(
770 owner=get_worker_user(), hostname=hostname, domain=domain)
759771
760772
761def get_default_domain():773def get_default_domain():
762774
=== modified file 'src/maasserver/models/tests/test_node.py'
--- src/maasserver/models/tests/test_node.py 2016-10-31 20:37:57 +0000
+++ src/maasserver/models/tests/test_node.py 2016-12-07 12:55:26 +0000
@@ -595,7 +595,12 @@
595 super().setUp()595 super().setUp()
596 # Patch out gethostname and get_mac_addresses.596 # Patch out gethostname and get_mac_addresses.
597 self.patch_autospec(node_module, "gethostname")597 self.patch_autospec(node_module, "gethostname")
598 node_module.gethostname.return_value = factory.make_name("host")598 hostname = factory.make_name('host')
599 # Bug#1614584: make sure that we handle the case where gethostname()
600 # returns an FQDN, instead of a domainless hostname.
601 if factory.pick_bool():
602 hostname += ".%s" % factory.make_name('domain')
603 node_module.gethostname.return_value = hostname
599 self.patch_autospec(node_module, "get_mac_addresses")604 self.patch_autospec(node_module, "get_mac_addresses")
600 node_module.get_mac_addresses.return_value = []605 node_module.get_mac_addresses.return_value = []
601606
602607
=== modified file 'src/maasserver/models/tests/test_staticipaddress.py'
--- src/maasserver/models/tests/test_staticipaddress.py 2016-10-18 08:00:37 +0000
+++ src/maasserver/models/tests/test_staticipaddress.py 2016-12-07 12:55:26 +0000
@@ -397,20 +397,21 @@
397 alloc_type=IPADDRESS_TYPE.STICKY,397 alloc_type=IPADDRESS_TYPE.STICKY,
398 ip=factory.pick_ip_in_Subnet(subnet),398 ip=factory.pick_ip_in_Subnet(subnet),
399 subnet=subnet, interface=boot_interface)399 subnet=subnet, interface=boot_interface)
400 ifaces = node.interface_set.exclude(interface=boot_interface)400 iface2 = node.interface_set.exclude(id=boot_interface.id).first()
401 sip2 = factory.make_StaticIPAddress(401 sip2 = factory.make_StaticIPAddress(
402 alloc_type=IPADDRESS_TYPE.STICKY,402 alloc_type=IPADDRESS_TYPE.STICKY,
403 ip=factory.pick_ip_in_Subnet(subnet),403 ip=factory.pick_ip_in_Subnet(subnet),
404 subnet=subnet, interface=ifaces[0])404 subnet=subnet, interface=iface2)
405 mapping = StaticIPAddress.objects.get_hostname_ip_mapping(subnet)405 mapping = StaticIPAddress.objects.get_hostname_ip_mapping(subnet)
406 self.assertEqual({406 expected = {
407 full_hostname:407 full_hostname:
408 HostnameIPMapping(408 HostnameIPMapping(
409 node.system_id, 30, {staticip.ip}, node.node_type),409 node.system_id, 30, {staticip.ip}, node.node_type),
410 "%s.%s" % (ifaces[0].name, full_hostname):410 "%s.%s" % (iface2.name, full_hostname):
411 HostnameIPMapping(411 HostnameIPMapping(
412 node.system_id, 30, {sip2.ip}, node.node_type),412 node.system_id, 30, {sip2.ip}, node.node_type),
413 }, mapping)413 }
414 self.assertEqual(expected, mapping)
414415
415 def make_mapping(self, node, raw_ttl=False):416 def make_mapping(self, node, raw_ttl=False):
416 if raw_ttl or node.address_ttl is not None:417 if raw_ttl or node.address_ttl is not None:

Subscribers

People subscribed via source and target branches

to all changes: