launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #12248
[Merge] lp:~rvb/maas/dns-nodegroup-status into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/dns-nodegroup-status into lp:maas.
Commit message:
Respect the settings on nodegroup ('status') and nodegroupinterface ('management') when generating DNS zone information.
Requested reviews:
MAAS Maintainers (maas-maintainers)
For more details, see:
https://code.launchpad.net/~rvb/maas/dns-nodegroup-status/+merge/125450
This branch makes the DNS machinery use nodegroup.status and nodegroup.get_managed_interface().management to determine if there is a DNS zone to be managed for a particular nodegroup. This change is required because we've change the way a user can configure whether or not the DNS server should be managed: from a global config option to an option set on each nodegroup/nodegroupinterface.
= Pre-imp =
This was discussed with Julian.
--
https://code.launchpad.net/~rvb/maas/dns-nodegroup-status/+merge/125450
Your team MAAS Maintainers is requested to review the proposed merge of lp:~rvb/maas/dns-nodegroup-status into lp:maas.
=== modified file 'src/maasserver/dns.py'
--- src/maasserver/dns.py 2012-09-18 16:36:51 +0000
+++ src/maasserver/dns.py 2012-09-20 10:28:20 +0000
@@ -14,6 +14,7 @@
'add_zone',
'change_dns_zones',
'is_dns_enabled',
+ 'is_dns_managed',
'next_zone_serial',
'write_full_dns_config',
]
@@ -24,6 +25,10 @@
import socket
from django.conf import settings
+from maasserver.enum import (
+ NODEGROUP_STATUS,
+ NODEGROUPINTERFACE_MANAGEMENT,
+ )
from maasserver.exceptions import MAASException
from maasserver.models import (
DHCPLease,
@@ -61,6 +66,15 @@
"""An error occured when setting up MAAS's DNS server."""
+def is_dns_managed(nodegroup):
+ """Does MAAS manage a DNS zone for this Nodegroup?"""
+ interface = nodegroup.get_managed_interface()
+ return (
+ nodegroup.status == NODEGROUP_STATUS.ACCEPTED and
+ interface is not None and
+ interface.management == NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
+
+
def warn_loopback(ip):
"""Warn if the given IP address is in the loopback network."""
if IPAddress(ip) in IPNetwork('127.0.0.1/8'):
@@ -103,9 +117,9 @@
This method also accepts a serial to reuse the same serial when
we are creating DNSZoneConfig objects in bulk.
"""
+ if not is_dns_managed(nodegroup):
+ return None
interface = nodegroup.get_managed_interface()
- if interface is None:
- return None
if serial is None:
serial = next_zone_serial()
=== modified file 'src/maasserver/tests/test_dns.py'
--- src/maasserver/tests/test_dns.py 2012-09-18 16:36:51 +0000
+++ src/maasserver/tests/test_dns.py 2012-09-20 10:28:20 +0000
@@ -24,6 +24,10 @@
dns,
server_address,
)
+from maasserver.enum import (
+ NODEGROUP_STATUS,
+ NODEGROUPINTERFACE_MANAGEMENT,
+ )
from maasserver.models.dhcplease import DHCPLease
from maasserver.testing.factory import factory
from maasserver.testing.testcase import TestCase
@@ -89,7 +93,9 @@
self.assertRaises(dns.DNSException, dns.get_dns_server_address)
def test_get_zone_creates_DNSZoneConfig(self):
- nodegroup = factory.make_node_group()
+ nodegroup = factory.make_node_group(
+ status=NODEGROUP_STATUS.ACCEPTED,
+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
interface = nodegroup.get_managed_interface()
serial = random.randint(1, 100)
zone = dns.get_zone(nodegroup, serial)
@@ -105,6 +111,30 @@
mapping=DHCPLease.objects.get_hostname_ip_mapping(nodegroup),
))
+ def test_is_dns_managed(self):
+ nodegroups_with_expected_results = {
+ factory.make_node_group(
+ status=NODEGROUP_STATUS.PENDING,
+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS): False,
+ factory.make_node_group(
+ status=NODEGROUP_STATUS.REJECTED,
+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS): False,
+ factory.make_node_group(
+ status=NODEGROUP_STATUS.ACCEPTED,
+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS): True,
+ factory.make_node_group(
+ status=NODEGROUP_STATUS.ACCEPTED,
+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP): False,
+ factory.make_node_group(
+ status=NODEGROUP_STATUS.ACCEPTED,
+ management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED): False,
+ }
+ results = {
+ nodegroup: dns.is_dns_managed(nodegroup)
+ for nodegroup, _ in nodegroups_with_expected_results.items()
+ }
+ self.assertEqual(nodegroups_with_expected_results, results)
+
class TestDNSConfigModifications(TestCase):
@@ -134,7 +164,9 @@
def create_nodegroup_with_lease(self, lease_number=1, nodegroup=None):
if nodegroup is None:
nodegroup = factory.make_node_group(
- network=IPNetwork('192.168.0.1/24'))
+ network=IPNetwork('192.168.0.1/24'),
+ status=NODEGROUP_STATUS.ACCEPTED,
+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
interface = nodegroup.get_managed_interface()
node = factory.make_node(
nodegroup=nodegroup, set_hostname=True)
@@ -257,14 +289,18 @@
self.patch(settings, "DNS_CONNECT", True)
network = IPNetwork('192.168.7.1/24')
ip = factory.getRandomIPInNetwork(network)
- nodegroup = factory.make_node_group(network=network)
+ nodegroup = factory.make_node_group(
+ network=network, status=NODEGROUP_STATUS.ACCEPTED,
+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
self.assertDNSMatches(generated_hostname(ip), nodegroup.name, ip)
def test_edit_nodegroupinterface_updates_DNS_zone(self):
self.patch(settings, "DNS_CONNECT", True)
old_network = IPNetwork('192.168.7.1/24')
old_ip = factory.getRandomIPInNetwork(old_network)
- nodegroup = factory.make_node_group(network=old_network)
+ nodegroup = factory.make_node_group(
+ network=old_network, status=NODEGROUP_STATUS.ACCEPTED,
+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
interface = nodegroup.get_managed_interface()
# Edit nodegroup's network information to '192.168.44.1/24'
interface.broadcast_ip = '192.168.44.255'
@@ -283,7 +319,9 @@
self.patch(settings, "DNS_CONNECT", True)
network = IPNetwork('192.168.7.1/24')
ip = factory.getRandomIPInNetwork(network)
- nodegroup = factory.make_node_group(network=network)
+ nodegroup = factory.make_node_group(
+ network=network, status=NODEGROUP_STATUS.ACCEPTED,
+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
nodegroup.delete()
self.assertEqual([''], self.dig_resolve(generated_hostname(ip)))
self.assertEqual([''], self.dig_reverse_resolve(ip))