← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Raphaël Badin has proposed merging lp:~rvb/maas/set_up_dns-command into lp:maas with lp:~rvb/maas/maas-dns3 as a prerequisite.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

This branch adds a new command set_up_dns which is destined to be run when the MAAS package is installed: it creates a zone-free named.conf.maas configuration file containing only the RNDC configuration needed to allow MAAS to reload BIND configuration later on when zones will be added.  Not that this command does not use tasks but calls the code directly because it might be called before the main worker is running.

= Pre-imp =

No real pre-imp for this but it is part of the plan Gavin, Jeroen and I devised for the whole DNS replacement work (see the DNS document on Google docs) .

= Notes =

Drive by fix:
- fix a test case name
- add 'Command' in get_named_conf.
-- 
https://code.launchpad.net/~rvb/maas/set_up_dns-command/+merge/115136
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/set_up_dns-command into lp:maas.
=== modified file 'src/maasserver/management/commands/get_named_conf.py'
--- src/maasserver/management/commands/get_named_conf.py	2012-07-11 15:35:04 +0000
+++ src/maasserver/management/commands/get_named_conf.py	2012-07-16 13:25:21 +0000
@@ -12,7 +12,9 @@
     )
 
 __metaclass__ = type
-__all__ = []
+__all__ = [
+    'Command',
+    ]
 
 
 from optparse import make_option

=== added file 'src/maasserver/management/commands/set_up_dns.py'
--- src/maasserver/management/commands/set_up_dns.py	1970-01-01 00:00:00 +0000
+++ src/maasserver/management/commands/set_up_dns.py	2012-07-16 13:25:21 +0000
@@ -0,0 +1,41 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Django command: set up the MAAS named configuration.
+
+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
+installed.
+"""
+
+from __future__ import (
+    absolute_import,
+    print_function,
+    unicode_literals,
+    )
+
+__metaclass__ = type
+__all__ = [
+    'Command',
+    ]
+
+
+from django.core.management.base import BaseCommand
+from provisioningserver.dns.config import (
+    DNSConfig,
+    setup_rndc,
+    )
+
+
+class Command(BaseCommand):
+    help = (
+        "Set up MAAS DNS configuration: a blank configuration and "
+        "all the RNDC configuration options allowing MAAS to reload "
+        "BIND once zones configuration files will be written.")
+
+    def handle(self, *args, **options):
+        setup_rndc()
+        config = DNSConfig()
+        config.write_config(zone_names=(), reverse_zone_names=())

=== modified file 'src/maasserver/tests/test_commands_get_named_conf.py'
--- src/maasserver/tests/test_commands_get_named_conf.py	2012-07-11 12:08:07 +0000
+++ src/maasserver/tests/test_commands_get_named_conf.py	2012-07-16 13:25:21 +0000
@@ -23,7 +23,7 @@
     )
 
 
-class TestGenerateEnlistmentPXE(TestCase):
+class TestGetNamedConfCommand(TestCase):
 
     def test_get_named_conf_returns_snippet(self):
         out = BytesIO()

=== added file 'src/maasserver/tests/test_commands_set_up_dns.py'
--- src/maasserver/tests/test_commands_set_up_dns.py	1970-01-01 00:00:00 +0000
+++ src/maasserver/tests/test_commands_set_up_dns.py	2012-07-16 13:25:21 +0000
@@ -0,0 +1,39 @@
+# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# GNU Affero General Public License version 3 (see the file LICENSE).
+
+"""Tests for the get_named_conf 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 provisioningserver.dns.config import (
+    MAAS_NAMED_CONF_NAME,
+    MAAS_RNDC_CONF_NAME,
+    )
+from testtools.matchers import (
+    AllMatch,
+    FileExists,
+    )
+
+
+class TestSetUpDNSCommand(TestCase):
+
+    def test_set_up_dns_writes_configuration(self):
+        dns_conf_dir = self.make_dir()
+        self.patch(conf, 'DNS_CONFIG_DIR', dns_conf_dir)
+        call_command('set_up_dns')
+        named_config = os.path.join(dns_conf_dir, MAAS_NAMED_CONF_NAME)
+        rndc_conf_path = os.path.join(dns_conf_dir, MAAS_RNDC_CONF_NAME)
+        self.assertThat([rndc_conf_path, named_config], AllMatch(FileExists()))

=== modified file 'src/maasserver/tests/test_dns.py'
--- src/maasserver/tests/test_dns.py	2012-07-16 13:25:21 +0000
+++ src/maasserver/tests/test_dns.py	2012-07-16 13:25:21 +0000
@@ -27,10 +27,6 @@
 from maastesting.celery import CeleryFixture
 from maastesting.tests.test_bindfixture import dig_call
 from provisioningserver.dns.config import conf
-from provisioningserver.tasks import (
-    setup_rndc_configuration,
-    write_dns_config,
-    )
 from testresources import FixtureResource
 from testtools.matchers import MatchesStructure
 
@@ -65,11 +61,16 @@
         self.bind = self.useFixture(BINDServer())
         self.patch(conf, 'DNS_CONFIG_DIR', self.bind.config.homedir)
 
+        # This simulates what should happen when the package is
+        # installed:
+        # Create MAAS-specific DNS configuration files.
+        call_command('set_up_dns')
+        # Register MAAS-specific DNS configuration files with the
+        # system's BIND instance.
         call_command(
             'get_named_conf', edit=True,
             config_path=self.bind.config.conf_file)
-        setup_rndc_configuration()
-        write_dns_config(inactive=True)
+        # Reload BIND.
         self.bind.runner.rndc('reload')
 
     def create_nodegroup_with_lease(self, nodegroup=None):