Merge lp:~rvb/maas/write_dns_config-command into lp:~maas-committers/maas/trunk

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: no longer in the source branch.
Merged at revision: 1303
Proposed branch: lp:~rvb/maas/write_dns_config-command
Merge into: lp:~maas-committers/maas/trunk
Prerequisite: lp:~rvb/maas/bug-1067977-dns-conf
Diff against target: 108 lines (+87/-1)
3 files modified
src/maasserver/management/commands/set_up_dns.py (+1/-1)
src/maasserver/management/commands/write_dns_config.py (+34/-0)
src/maasserver/tests/test_commands_write_dns_config.py (+52/-0)
To merge this branch: bzr merge lp:~rvb/maas/write_dns_config-command
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) Approve
Review via email: mp+131030@code.launchpad.net

Commit message

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

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

One small thing: in write_dns_config.py your help string uses the term “MAAS server.” I guess that should be “region controller” now. Or even just “region.”

Jeroen

review: Approve
Revision history for this message
Raphaël Badin (rvb) wrote :

> One small thing: in write_dns_config.py your help string uses the term “MAAS
> server.” I guess that should be “region controller” now. Or even just
> “region.”

Good point, done.

bzr grep "MAAS server" tells me we need to make that change in a few other places as well ;)

Revision history for this message
MAAS Lander (maas-lander) wrote :

No proposals found for merge of lp:~rvb/maas/bug-1067977-dns-conf into lp:maas.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/maasserver/management/commands/set_up_dns.py'
2--- src/maasserver/management/commands/set_up_dns.py 2012-08-13 11:04:44 +0000
3+++ src/maasserver/management/commands/set_up_dns.py 2012-10-25 10:49:19 +0000
4@@ -6,7 +6,7 @@
5 This creates a basic, blank DNS configuration which will allow MAAS to
6 reload its configuration once zone files will be written.
7
8-The main purpose of this command is for it to be run when MAAS is
9+The main purpose of this command is for it to be run when 'maas-dns' is
10 installed.
11 """
12
13
14=== added file 'src/maasserver/management/commands/write_dns_config.py'
15--- src/maasserver/management/commands/write_dns_config.py 1970-01-01 00:00:00 +0000
16+++ src/maasserver/management/commands/write_dns_config.py 2012-10-25 10:49:19 +0000
17@@ -0,0 +1,34 @@
18+# Copyright 2012 Canonical Ltd. This software is licensed under the
19+# GNU Affero General Public License version 3 (see the file LICENSE).
20+
21+"""Django command: write the MAAS named zone files.
22+
23+If any of the cluster controllers connected to this MAAS region controller
24+is configured to manage DNS, write the DNS configuration.
25+
26+The main purpose of this command is for it to be run when 'maas-dns' is
27+installed.
28+"""
29+
30+from __future__ import (
31+ absolute_import,
32+ print_function,
33+ unicode_literals,
34+ )
35+
36+__metaclass__ = type
37+__all__ = [
38+ 'Command',
39+ ]
40+
41+from django.core.management.base import BaseCommand
42+from maasserver.dns import write_full_dns_config
43+
44+
45+class Command(BaseCommand):
46+ help = (
47+ "Write the DNS configuration files and reload the DNS server if "
48+ "this region has cluster controllers configured to manage DNS.")
49+
50+ def handle(self, *args, **options):
51+ write_full_dns_config()
52
53=== added file 'src/maasserver/tests/test_commands_write_dns_config.py'
54--- src/maasserver/tests/test_commands_write_dns_config.py 1970-01-01 00:00:00 +0000
55+++ src/maasserver/tests/test_commands_write_dns_config.py 2012-10-25 10:49:19 +0000
56@@ -0,0 +1,52 @@
57+# Copyright 2012 Canonical Ltd. This software is licensed under the
58+# GNU Affero General Public License version 3 (see the file LICENSE).
59+
60+"""Tests for the write_dns_config command."""
61+
62+from __future__ import (
63+ absolute_import,
64+ print_function,
65+ unicode_literals,
66+ )
67+
68+__metaclass__ = type
69+__all__ = []
70+
71+
72+import os
73+
74+from celery.conf import conf
75+from django.core.management import call_command
76+from maasserver.testing.testcase import TestCase
77+from maasserver.testing.factory import factory
78+from django.conf import settings
79+from netaddr import (
80+ IPNetwork,
81+ )
82+from maasserver.enum import (
83+ NODEGROUP_STATUS,
84+ NODEGROUPINTERFACE_MANAGEMENT,
85+ )
86+from provisioningserver import tasks
87+from testtools.matchers import (
88+ FileExists,
89+ )
90+
91+
92+class TestWriteDNSConfigCommand(TestCase):
93+
94+ def test_write_dns_config_writes_zone_file(self):
95+ dns_conf_dir = self.make_dir()
96+ self.patch(conf, 'DNS_CONFIG_DIR', dns_conf_dir)
97+ self.patch(settings, 'DNS_CONNECT', True)
98+ # Prevent rndc task dispatch.
99+ self.patch(tasks, "rndc_command")
100+ domain = factory.getRandomString()
101+ factory.make_node_group(
102+ name=domain,
103+ network=IPNetwork('192.168.0.1/24'),
104+ status=NODEGROUP_STATUS.ACCEPTED,
105+ management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
106+ call_command('write_dns_config')
107+ zone_file = os.path.join(dns_conf_dir, 'zone.%s' % domain)
108+ self.assertThat(zone_file, FileExists())