← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~rvb/maas/write_dns_config-command into lp:maas

 

Raphaël Badin has proposed merging lp:~rvb/maas/write_dns_config-command into lp:maas with lp:~rvb/maas/bug-1067977-dns-conf as a prerequisite.

Commit message:
Add a command to write the full DNS config.  This will be called by the postinst script of maas-dns.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~rvb/maas/write_dns_config-command/+merge/131030

Add a command to write the full DNS config.  This will be called by the postinst script of maas-dns.

maas-dns will call:
- Call the command 'set_up_dns' (set up all the RNDC config)
- restart bind (at this stage MAAS still cannot restart bind itself as the rndc key is still not loaded)
- Call the command 'write_dns_config'

The main goal of this fix is to cover for the following workflow:
1. the user configures an interface to manage DNS
2. looking at the logs, he suddenly realizes that he forgot to install the maas-dns package
3. the users installs maas-dns
At this stage, it is important that maas-dns calls the command write_dns_config so that the confi done in 1. is applied to the DNS config.
-- 
https://code.launchpad.net/~rvb/maas/write_dns_config-command/+merge/131030
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/write_dns_config-command into lp:maas.
=== modified file 'src/maasserver/management/commands/set_up_dns.py'
--- src/maasserver/management/commands/set_up_dns.py	2012-08-13 11:04:44 +0000
+++ src/maasserver/management/commands/set_up_dns.py	2012-10-23 15:09:18 +0000
@@ -6,7 +6,7 @@
 This creates a basic, blank DNS configuration which will allow MAAS to
 reload its configuration once zone files will be written.
 
-The main purpose of this command is for it to be run when MAAS is
+The main purpose of this command is for it to be run when 'maas-dns' is
 installed.
 """
 

=== added file 'src/maasserver/management/commands/write_dns_config.py'
--- src/maasserver/management/commands/write_dns_config.py	1970-01-01 00:00:00 +0000
+++ src/maasserver/management/commands/write_dns_config.py	2012-10-23 15:09:18 +0000
@@ -0,0 +1,34 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Django command: write the MAAS named zone files.
+
+If any of the cluster controllers connected to this MAAS region controller
+is configured to manage DNS, write the DNS configuration.
+
+The main purpose of this command is for it to be run when 'maas-dns' is
+installed.
+"""
+
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
+__metaclass__ = type
+__all__ = [
+    'Command',
+    ]
+
+from django.core.management.base import BaseCommand
+from maasserver.dns import write_full_dns_config
+
+
+class Command(BaseCommand):
+    help = (
+        "Write the DNS configuration files and reload the DNS server if "
+        "this MAAS server has cluster controllers configured to manage DNS.")
+
+    def handle(self, *args, **options):
+        write_full_dns_config()

=== added file 'src/maasserver/tests/test_commands_write_dns_config.py'
--- src/maasserver/tests/test_commands_write_dns_config.py	1970-01-01 00:00:00 +0000
+++ src/maasserver/tests/test_commands_write_dns_config.py	2012-10-23 15:09:18 +0000
@@ -0,0 +1,52 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the write_dns_config command."""
+
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
+__metaclass__ = type
+__all__ = []
+
+
+import os
+
+from celery.conf import conf
+from django.core.management import call_command
+from maasserver.testing.testcase import TestCase
+from maasserver.testing.factory import factory
+from django.conf import settings
+from netaddr import (
+    IPNetwork,
+    )
+from maasserver.enum import (
+    NODEGROUP_STATUS,
+    NODEGROUPINTERFACE_MANAGEMENT,
+    )
+from provisioningserver import tasks
+from testtools.matchers import (
+    FileExists,
+    )
+
+
+class TestWriteDNSConfigCommand(TestCase):
+
+    def test_write_dns_config_writes_zone_file(self):
+        dns_conf_dir = self.make_dir()
+        self.patch(conf, 'DNS_CONFIG_DIR', dns_conf_dir)
+        self.patch(settings, 'DNS_CONNECT', True)
+        # Prevent rndc task dispatch.
+        self.patch(tasks, "rndc_command")
+        domain = factory.getRandomString()
+        factory.make_node_group(
+            name=domain,
+            network=IPNetwork('192.168.0.1/24'),
+            status=NODEGROUP_STATUS.ACCEPTED,
+            management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
+        call_command('write_dns_config')
+        zone_file = os.path.join(dns_conf_dir, 'zone.%s' % domain)
+        self.assertThat(zone_file, FileExists())