Merge lp:~lamont/maas/bug-1602482 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: 5483
Proposed branch: lp:~lamont/maas/bug-1602482
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 102 lines (+21/-18)
2 files modified
src/maasserver/models/staticipaddress.py (+18/-9)
src/maasserver/models/tests/test_staticipaddress.py (+3/-9)
To merge this branch: bzr merge lp:~lamont/maas/bug-1602482
Reviewer Review Type Date Requested Status
Blake Rouse (community) Approve
Review via email: mp+308517@code.launchpad.net

Commit message

If there are any assigned (not DISCOVERED) IP addresses on a host, then do not add any DISCOVERED addresses to the DNS.

Description of the change

If there are any assigned (not DISCOVERED) IP addresses on a host, then do not add any DISCOVERED addresses to the DNS.

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

Looks good. Makes since, surprised we where not doing this already.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/maasserver/models/staticipaddress.py'
--- src/maasserver/models/staticipaddress.py 2016-10-12 16:19:16 +0000
+++ src/maasserver/models/staticipaddress.py 2016-10-14 14:24:16 +0000
@@ -420,7 +420,8 @@
420 node.node_type,420 node.node_type,
421 """ + ttl_clause + """ AS ttl,421 """ + ttl_clause + """ AS ttl,
422 staticip.ip,422 staticip.ip,
423 interface.name423 interface.name,
424 alloc_type != 6 /* DISCOVERED */ AS assigned
424 FROM425 FROM
425 maasserver_interface AS interface426 maasserver_interface AS interface
426 JOIN maasserver_node AS node ON427 JOIN maasserver_node AS node ON
@@ -457,6 +458,7 @@
457 host(staticip.ip) != ''458 host(staticip.ip) != ''
458 ORDER BY459 ORDER BY
459 node.hostname,460 node.hostname,
461 assigned DESC, /* Return all assigned IPs for a node first. */
460 interface.id462 interface.id
461 """463 """
462 # We get user reserved et al mappings first, so that we can overwrite464 # We get user reserved et al mappings first, so that we can overwrite
@@ -467,6 +469,7 @@
467 iface_is_boot = defaultdict(bool, {469 iface_is_boot = defaultdict(bool, {
468 hostname: True for hostname in mapping.keys()470 hostname: True for hostname in mapping.keys()
469 })471 })
472 assigned_ips = defaultdict(bool)
470 cursor.execute(sql_query, query_parms)473 cursor.execute(sql_query, query_parms)
471 # The records from the query provide, for each hostname (after474 # The records from the query provide, for each hostname (after
472 # stripping domain), the boot and non-boot interface ip address in ipv4475 # stripping domain), the boot and non-boot interface ip address in ipv4
@@ -485,16 +488,22 @@
485 if is_boot == iface_is_boot[fqdn]:488 if is_boot == iface_is_boot[fqdn]:
486 mapping[fqdn].ips.add(ip)489 mapping[fqdn].ips.add(ip)
487 # Next, get all the addresses, on all the interfaces, and add the ones490 # Next, get all the addresses, on all the interfaces, and add the ones
488 # that are not already present on the FQDN as $IFACE.$FQDN.491 # that are not already present on the FQDN as $IFACE.$FQDN. Exclude
492 # any discovered addresses once there are any non-discovered addresses.
489 cursor.execute(iface_sql_query, (domain_or_subnet.id,))493 cursor.execute(iface_sql_query, (domain_or_subnet.id,))
490 for (fqdn, system_id, node_type, ttl,494 for (fqdn, system_id, node_type, ttl,
491 ip, iface_name) in cursor.fetchall():495 ip, iface_name, assigned) in cursor.fetchall():
492 if ip not in mapping[fqdn].ips:496 if assigned:
493 name = "%s.%s" % (iface_name, fqdn)497 assigned_ips[fqdn] = True
494 mapping[name].node_type = node_type498 # If this is an assigned IP, or there are NO assigned IPs on the
495 mapping[name].system_id = system_id499 # node, then consider adding the IP.
496 mapping[name].ttl = ttl500 if assigned or not assigned_ips[fqdn]:
497 mapping[name].ips.add(ip)501 if ip not in mapping[fqdn].ips:
502 name = "%s.%s" % (iface_name, fqdn)
503 mapping[name].node_type = node_type
504 mapping[name].system_id = system_id
505 mapping[name].ttl = ttl
506 mapping[name].ips.add(ip)
498 return mapping507 return mapping
499508
500 def filter_by_ip_family(self, family):509 def filter_by_ip_family(self, family):
501510
=== modified file 'src/maasserver/models/tests/test_staticipaddress.py'
--- src/maasserver/models/tests/test_staticipaddress.py 2016-10-12 17:34:30 +0000
+++ src/maasserver/models/tests/test_staticipaddress.py 2016-10-14 14:24:16 +0000
@@ -600,16 +600,14 @@
600 staticip = factory.make_StaticIPAddress(600 staticip = factory.make_StaticIPAddress(
601 alloc_type=IPADDRESS_TYPE.AUTO, interface=iface,601 alloc_type=IPADDRESS_TYPE.AUTO, interface=iface,
602 subnet=subnet)602 subnet=subnet)
603 discovered = factory.make_StaticIPAddress(603 factory.make_StaticIPAddress(
604 alloc_type=IPADDRESS_TYPE.DISCOVERED, interface=iface,604 alloc_type=IPADDRESS_TYPE.DISCOVERED, interface=iface,
605 subnet=subnet)605 subnet=subnet)
606 mapping = StaticIPAddress.objects.get_hostname_ip_mapping(606 mapping = StaticIPAddress.objects.get_hostname_ip_mapping(
607 node.domain)607 node.domain)
608 expected_mapping = {608 expected_mapping = {
609 node.fqdn: HostnameIPMapping(609 node.fqdn: HostnameIPMapping(
610 node.system_id, 30, {staticip.ip}, node.node_type),610 node.system_id, 30, {staticip.ip}, node.node_type)}
611 "%s.%s" % (iface.name, node.fqdn): HostnameIPMapping(
612 node.system_id, 30, {discovered.ip}, node.node_type)}
613 self.assertEqual(expected_mapping, mapping)611 self.assertEqual(expected_mapping, mapping)
614612
615 def test_get_hostname_ip_mapping_prefers_bond_with_no_boot_interface(self):613 def test_get_hostname_ip_mapping_prefers_bond_with_no_boot_interface(self):
@@ -828,9 +826,7 @@
828 mapping = StaticIPAddress.objects.get_hostname_ip_mapping(domain)826 mapping = StaticIPAddress.objects.get_hostname_ip_mapping(domain)
829 expected_mapping = {827 expected_mapping = {
830 node.fqdn: HostnameIPMapping(828 node.fqdn: HostnameIPMapping(
831 node.system_id, 30, {sip0.ip}, node.node_type),829 node.system_id, 30, {sip0.ip}, node.node_type)}
832 "%s.%s" % (iface1.name, node.fqdn): HostnameIPMapping(
833 node.system_id, 30, {sip1.ip}, node.node_type)}
834 self.assertEqual(expected_mapping, mapping)830 self.assertEqual(expected_mapping, mapping)
835831
836 def test_get_hostname_ip_mapping_returns_correct_bond_ip(self):832 def test_get_hostname_ip_mapping_returns_correct_bond_ip(self):
@@ -877,8 +873,6 @@
877 expected_mapping = {873 expected_mapping = {
878 node.fqdn: HostnameIPMapping(874 node.fqdn: HostnameIPMapping(
879 node.system_id, 30, {bond_sip.ip}, node.node_type),875 node.system_id, 30, {bond_sip.ip}, node.node_type),
880 "%s.%s" % (iface1.name, node.fqdn): HostnameIPMapping(
881 node.system_id, 30, {sip1.ip}, node.node_type),
882 }876 }
883 self.assertEqual(expected_mapping, mapping)877 self.assertEqual(expected_mapping, mapping)
884878