Merge lp:~mpontillo/maas/dns-template-changes-1.7 into lp:maas/1.7

Proposed by Mike Pontillo
Status: Merged
Approved by: Mike Pontillo
Approved revision: no longer in the source branch.
Merged at revision: 3376
Proposed branch: lp:~mpontillo/maas/dns-template-changes-1.7
Merge into: lp:maas/1.7
Diff against target: 352 lines (+176/-7)
8 files modified
etc/maas/templates/dns/named.conf.options.inside.maas.template (+7/-1)
src/maasserver/management/commands/edit_named_options.py (+1/-1)
src/maasserver/tests/test_commands_edit_named_options.py (+2/-2)
src/provisioningserver/dns/config.py (+38/-0)
src/provisioningserver/dns/testing.py (+2/-0)
src/provisioningserver/dns/tests/test_config.py (+117/-0)
src/provisioningserver/utils/isc.py (+3/-1)
src/provisioningserver/utils/tests/test_isc.py (+6/-2)
To merge this branch: bzr merge lp:~mpontillo/maas/dns-template-changes-1.7
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Approve
Review via email: mp+264219@code.launchpad.net

Commit message

Allow users to define allow-* parameters in named.conf.options; prevent writing them to named.conf.options.inside.maas in that case. (Merge from trunk revision 4082)

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Self-approving backport.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'etc/maas/templates/dns/named.conf.options.inside.maas.template'
--- etc/maas/templates/dns/named.conf.options.inside.maas.template 2015-07-03 08:57:15 +0000
+++ etc/maas/templates/dns/named.conf.options.inside.maas.template 2015-07-09 23:21:59 +0000
@@ -6,7 +6,13 @@
6};6};
7{{endif}}7{{endif}}
88
9
10{{if not upstream_allow_query}}
9allow-query { any; };11allow-query { any; };
12{{endif}}
13{{if not upstream_allow_recursion}}
10allow-recursion { trusted; };14allow-recursion { trusted; };
15{{endif}}
16{{if not upstream_allow_query_cache}}
11allow-query-cache { trusted; };17allow-query-cache { trusted; };
1218{{endif}}
1319
=== modified file 'src/maasserver/management/commands/edit_named_options.py'
--- src/maasserver/management/commands/edit_named_options.py 2015-07-08 00:26:38 +0000
+++ src/maasserver/management/commands/edit_named_options.py 2015-07-09 23:21:59 +0000
@@ -33,7 +33,7 @@
33 CommandError,33 CommandError,
34 )34 )
35from maasserver.models import Config35from maasserver.models import Config
36from maasserver.utils.isc import (36from provisioningserver.utils.isc import (
37 ISCParseException,37 ISCParseException,
38 make_isc_string,38 make_isc_string,
39 parse_isc_string,39 parse_isc_string,
4040
=== modified file 'src/maasserver/tests/test_commands_edit_named_options.py'
--- src/maasserver/tests/test_commands_edit_named_options.py 2015-07-08 00:26:38 +0000
+++ src/maasserver/tests/test_commands_edit_named_options.py 2015-07-09 23:21:59 +0000
@@ -30,12 +30,12 @@
30from maasserver.testing.factory import factory30from maasserver.testing.factory import factory
31from maasserver.testing.testcase import MAASServerTestCase31from maasserver.testing.testcase import MAASServerTestCase
32from maasserver.utils import get_one32from maasserver.utils import get_one
33from maasserver.utils.isc import (33from provisioningserver.dns.config import MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME
34from provisioningserver.utils.isc import (
34 make_isc_string,35 make_isc_string,
35 parse_isc_string,36 parse_isc_string,
36 read_isc_file,37 read_isc_file,
37 )38 )
38from provisioningserver.dns.config import MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME
39from testtools.matchers import (39from testtools.matchers import (
40 Contains,40 Contains,
41 Equals,41 Equals,
4242
=== modified file 'src/provisioningserver/dns/config.py'
--- src/provisioningserver/dns/config.py 2014-11-17 11:02:09 +0000
+++ src/provisioningserver/dns/config.py 2015-07-09 23:21:59 +0000
@@ -31,10 +31,12 @@
3131
32from provisioningserver.utils import locate_config32from provisioningserver.utils import locate_config
33from provisioningserver.utils.fs import atomic_write33from provisioningserver.utils.fs import atomic_write
34from provisioningserver.utils.isc import read_isc_file
34from provisioningserver.utils.shell import call_and_check35from provisioningserver.utils.shell import call_and_check
35import tempita36import tempita
3637
3738
39NAMED_CONF_OPTIONS = 'named.conf.options'
38MAAS_NAMED_CONF_NAME = 'named.conf.maas'40MAAS_NAMED_CONF_NAME = 'named.conf.maas'
39MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME = 'named.conf.options.inside.maas'41MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME = 'named.conf.options.inside.maas'
40MAAS_NAMED_RNDC_CONF_NAME = 'named.conf.rndc.maas'42MAAS_NAMED_RNDC_CONF_NAME = 'named.conf.rndc.maas'
@@ -53,6 +55,18 @@
53 return setting55 return setting
5456
5557
58def get_bind_config_dir():
59 """Location of bind configuration files."""
60 setting = os.getenv(
61 "MAAS_BIND_CONFIG_DIR",
62 locate_config(os.path.pardir, "bind"))
63 if isinstance(setting, bytes):
64 fsenc = sys.getfilesystemencoding()
65 return setting.decode(fsenc)
66 else:
67 return setting
68
69
56def get_dns_rndc_port():70def get_dns_rndc_port():
57 """RNDC port to be configured by MAAS to communicate with BIND."""71 """RNDC port to be configured by MAAS to communicate with BIND."""
58 setting = os.getenv("MAAS_DNS_RNDC_PORT", "954")72 setting = os.getenv("MAAS_DNS_RNDC_PORT", "954")
@@ -192,6 +206,25 @@
192 # specify it. If it's not set, the substitution will fail with the default206 # specify it. If it's not set, the substitution will fail with the default
193 # template that uses this value.207 # template that uses this value.
194 kwargs.setdefault("upstream_dns")208 kwargs.setdefault("upstream_dns")
209
210 # Parse the options file and make sure MAAS doesn't define any options
211 # that the user has already customized.
212 allow_user_override_options = [
213 "allow-query",
214 "allow-recursion",
215 "allow-query-cache",
216 ]
217
218 try:
219 parsed_options = read_isc_file(
220 compose_bind_config_path(NAMED_CONF_OPTIONS))
221 except IOError:
222 parsed_options = {}
223
224 options = parsed_options.get('options', {})
225 for option in allow_user_override_options:
226 kwargs['upstream_' + option.replace('-', '_')] = option in options
227
195 try:228 try:
196 rendered = template.substitute(kwargs)229 rendered = template.substitute(kwargs)
197 except NameError as error:230 except NameError as error:
@@ -206,6 +239,11 @@
206 return os.path.join(get_dns_config_dir(), filename)239 return os.path.join(get_dns_config_dir(), filename)
207240
208241
242def compose_bind_config_path(filename):
243 """Return the full path for a DNS config or zone file."""
244 return os.path.join(get_bind_config_dir(), filename)
245
246
209def render_dns_template(template_name, *parameters):247def render_dns_template(template_name, *parameters):
210 """Generate contents for a DNS configuration or zone file.248 """Generate contents for a DNS configuration or zone file.
211249
212250
=== modified file 'src/provisioningserver/dns/testing.py'
--- src/provisioningserver/dns/testing.py 2014-09-24 09:32:18 +0000
+++ src/provisioningserver/dns/testing.py 2015-07-09 23:21:59 +0000
@@ -32,6 +32,8 @@
32 config_dir = config_dir.encode(fsenc)32 config_dir = config_dir.encode(fsenc)
33 testcase.useFixture(33 testcase.useFixture(
34 EnvironmentVariable(b"MAAS_DNS_CONFIG_DIR", config_dir))34 EnvironmentVariable(b"MAAS_DNS_CONFIG_DIR", config_dir))
35 testcase.useFixture(
36 EnvironmentVariable(b"MAAS_BIND_CONFIG_DIR", config_dir))
35 return config_dir.decode(fsenc)37 return config_dir.decode(fsenc)
3638
3739
3840
=== modified file 'src/provisioningserver/dns/tests/test_config.py'
--- src/provisioningserver/dns/tests/test_config.py 2015-07-03 09:30:27 +0000
+++ src/provisioningserver/dns/tests/test_config.py 2015-07-09 23:21:59 +0000
@@ -39,6 +39,7 @@
39 MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME,39 MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME,
40 MAAS_NAMED_RNDC_CONF_NAME,40 MAAS_NAMED_RNDC_CONF_NAME,
41 MAAS_RNDC_CONF_NAME,41 MAAS_RNDC_CONF_NAME,
42 NAMED_CONF_OPTIONS,
42 render_dns_template,43 render_dns_template,
43 report_missing_config_dir,44 report_missing_config_dir,
44 set_up_options_conf,45 set_up_options_conf,
@@ -54,12 +55,16 @@
54 DNSReverseZoneConfig,55 DNSReverseZoneConfig,
55 )56 )
56from provisioningserver.utils import locate_config57from provisioningserver.utils import locate_config
58from provisioningserver.utils.isc import read_isc_file
57from testtools.matchers import (59from testtools.matchers import (
60 AllMatch,
58 Contains,61 Contains,
59 ContainsAll,62 ContainsAll,
60 EndsWith,63 EndsWith,
64 Equals,
61 FileContains,65 FileContains,
62 FileExists,66 FileExists,
67 Is,
63 IsInstance,68 IsInstance,
64 MatchesAll,69 MatchesAll,
65 Not,70 Not,
@@ -70,6 +75,47 @@
70from twisted.python.filepath import FilePath75from twisted.python.filepath import FilePath
7176
7277
78NAMED_CONF_OPTIONS_CONTENTS = dedent("""\
79 options {
80 forwarders {
81 8.8.8.8;
82 8.8.4.4;
83 };
84 dnssec-validation auto;
85 allow-query { any; };
86 allow-recursion { trusted; };
87 allow-query-cache { trusted; };
88 auth-nxdomain no;
89 listen-on-v6 { any; };
90 };
91 """)
92
93NAMED_CONF_OPTIONS_WITH_ALLOW_QUERY_CONTENTS = dedent("""\
94 options {
95 forwarders {
96 8.8.8.8;
97 8.8.4.4;
98 };
99 dnssec-validation auto;
100 allow-query { any; };
101 auth-nxdomain no;
102 listen-on-v6 { any; };
103 };
104 """)
105
106NAMED_CONF_OPTIONS_NO_ALLOW_CONTENTS = dedent("""\
107 options {
108 forwarders {
109 8.8.8.8;
110 8.8.4.4;
111 };
112 dnssec-validation auto;
113 auth-nxdomain no;
114 listen-on-v6 { any; };
115 };
116 """)
117
118
73class TestHelpers(MAASTestCase):119class TestHelpers(MAASTestCase):
74120
75 def test_get_dns_config_dir_defaults_to_etc_bind_maas(self):121 def test_get_dns_config_dir_defaults_to_etc_bind_maas(self):
@@ -90,6 +136,24 @@
90 IsInstance(unicode),136 IsInstance(unicode),
91 ))137 ))
92138
139 def test_get_bind_config_dir_defaults_to_etc_bind_maas(self):
140 self.useFixture(EnvironmentVariable("MAAS_BIND_CONFIG_DIR"))
141 self.assertThat(
142 config.get_bind_config_dir(), MatchesAll(
143 SamePath(locate_config("../bind")),
144 IsInstance(unicode),
145 ))
146
147 def test_get_bind_config_dir_checks_environ_first(self):
148 directory = self.make_dir()
149 self.useFixture(EnvironmentVariable(
150 "MAAS_BIND_CONFIG_DIR", directory.encode("ascii")))
151 self.assertThat(
152 config.get_bind_config_dir(), MatchesAll(
153 SamePath(directory),
154 IsInstance(unicode),
155 ))
156
93 def test_get_dns_root_port_defaults_to_954(self):157 def test_get_dns_root_port_defaults_to_954(self):
94 self.useFixture(EnvironmentVariable("MAAS_DNS_RNDC_PORT"))158 self.useFixture(EnvironmentVariable("MAAS_DNS_RNDC_PORT"))
95 self.assertEqual(954, config.get_dns_rndc_port())159 self.assertEqual(954, config.get_dns_rndc_port())
@@ -145,6 +209,59 @@
145 ])209 ])
146 )210 )
147211
212 def test_set_up_options_conf_write_config_assumes_no_overrides(self):
213 dns_conf_dir = patch_dns_config_path(self)
214 set_up_options_conf()
215 target_file = os.path.join(
216 dns_conf_dir, MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
217 target = read_isc_file(target_file)
218 self.assertThat([
219 target['allow-query']['any'],
220 target['allow-recursion']['trusted'],
221 target['allow-query-cache']['trusted'],
222 ], AllMatch(Equals(True)))
223
224 def test_set_up_options_conf_write_config_allows_overrides(self):
225 dns_conf_dir = patch_dns_config_path(self)
226 factory.make_file(
227 location=dns_conf_dir, name=NAMED_CONF_OPTIONS,
228 contents=NAMED_CONF_OPTIONS_CONTENTS)
229 set_up_options_conf()
230 target_file = os.path.join(
231 dns_conf_dir, MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
232 target = read_isc_file(target_file)
233 self.assertThat([
234 target.get('allow-query'),
235 target.get('allow-recursion'),
236 target.get('allow-query-cache'),
237 ], AllMatch(Is(None)))
238
239 def test_set_up_options_conf_write_config_allows_zero_overrides(self):
240 dns_conf_dir = patch_dns_config_path(self)
241 factory.make_file(
242 location=dns_conf_dir, name=NAMED_CONF_OPTIONS,
243 contents=NAMED_CONF_OPTIONS_NO_ALLOW_CONTENTS)
244 set_up_options_conf()
245 target_file = os.path.join(
246 dns_conf_dir, MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
247 target = read_isc_file(target_file)
248 self.assertThat([
249 target['allow-query']['any'],
250 target['allow-recursion']['trusted'],
251 target['allow-query-cache']['trusted'],
252 ], AllMatch(Equals(True)))
253
254 def test_set_up_options_conf_write_config_allows_single_override(self):
255 dns_conf_dir = patch_dns_config_path(self)
256 factory.make_file(
257 location=dns_conf_dir, name=NAMED_CONF_OPTIONS,
258 contents=NAMED_CONF_OPTIONS_WITH_ALLOW_QUERY_CONTENTS)
259 set_up_options_conf()
260 target_file = os.path.join(
261 dns_conf_dir, MAAS_NAMED_CONF_OPTIONS_INSIDE_NAME)
262 target = read_isc_file(target_file)
263 self.assertIsNone(target.get('allow-query'))
264
148 def test_set_up_options_conf_handles_no_upstream_dns(self):265 def test_set_up_options_conf_handles_no_upstream_dns(self):
149 dns_conf_dir = patch_dns_config_path(self)266 dns_conf_dir = patch_dns_config_path(self)
150 set_up_options_conf()267 set_up_options_conf()
151268
=== renamed file 'src/maasserver/utils/isc.py' => 'src/provisioningserver/utils/isc.py'
--- src/maasserver/utils/isc.py 2015-07-08 00:26:38 +0000
+++ src/provisioningserver/utils/isc.py 2015-07-09 23:21:59 +0000
@@ -144,6 +144,8 @@
144 # If there are more than 1 'keywords' at new_char_list[index]144 # If there are more than 1 'keywords' at new_char_list[index]
145 # ex - "recursion no;"145 # ex - "recursion no;"
146 elif len(new_char_list[index].split()) >= 2:146 elif len(new_char_list[index].split()) >= 2:
147 if type(dictionary_fragment) == list:
148 raise ISCParseException("Syntax error")
147 dictionary_fragment[149 dictionary_fragment[
148 new_char_list[index].split()[0]] = (150 new_char_list[index].split()[0]] = (
149 ' '.join(new_char_list[index].split()[1:]))151 ' '.join(new_char_list[index].split()[1:]))
@@ -155,7 +157,7 @@
155 elif new_char_list[index] not in ['{', ';', '}']:157 elif new_char_list[index] not in ['{', ';', '}']:
156 key = new_char_list[index]158 key = new_char_list[index]
157 if type(dictionary_fragment) == list:159 if type(dictionary_fragment) == list:
158 raise ISCParseException("Dictionary expected; got a list")160 raise ISCParseException("Syntax error")
159 dictionary_fragment[key] = ''161 dictionary_fragment[key] = ''
160 index += 1162 index += 1
161 index += 1163 index += 1
162164
=== renamed file 'src/maasserver/utils/tests/test_isc.py' => 'src/provisioningserver/utils/tests/test_isc.py'
--- src/maasserver/utils/tests/test_isc.py 2015-07-08 00:26:38 +0000
+++ src/provisioningserver/utils/tests/test_isc.py 2015-07-09 23:21:59 +0000
@@ -18,13 +18,13 @@
18from collections import OrderedDict18from collections import OrderedDict
19from textwrap import dedent19from textwrap import dedent
2020
21from maasserver.utils.isc import (21from maastesting.testcase import MAASTestCase
22from provisioningserver.utils.isc import (
22 ISCParseException,23 ISCParseException,
23 make_isc_string,24 make_isc_string,
24 parse_isc_string,25 parse_isc_string,
25 read_isc_file,26 read_isc_file,
26 )27 )
27from maastesting.testcase import MAASTestCase
28from testtools import ExpectedException28from testtools import ExpectedException
2929
3030
@@ -220,6 +220,10 @@
220 with ExpectedException(ISCParseException):220 with ExpectedException(ISCParseException):
221 parse_isc_string("forwarders {{}a;;b}")221 parse_isc_string("forwarders {{}a;;b}")
222222
223 def test_parse_forgotten_semicolons_throw_iscparseexception(self):
224 with ExpectedException(ISCParseException):
225 parse_isc_string("a { b; } { c; } d e;")
226
223 def test_read_isc_file(self):227 def test_read_isc_file(self):
224 testdata = dedent("""\228 testdata = dedent("""\
225 acl canonical-int-ns { 91.189.90.151; 91.189.89.192; };229 acl canonical-int-ns { 91.189.90.151; 91.189.89.192; };

Subscribers

People subscribed via source and target branches

to all changes: