Commit c6d231c3 authored by ale's avatar ale

Allow setting update-policy on generated named.conf

Controlled via the --update-policy command-line flag.
parent cb6415ce
......@@ -25,6 +25,9 @@ def main():
parser.add_option(
'-n', '--dry-run', dest='dry_run', action='store_true',
help='Do not actually write zone files')
parser.add_option(
'--update-policy', dest='update_policies', action='append',
help='Set the update-policy for all zones (specify more than once for multiple policies)')
dnssec_g = parser.add_option_group('DNSSEC Options')
dnssec_g.add_option(
......@@ -68,7 +71,8 @@ def main():
zw = zone.ZoneWriter(opts.output_dir,
opts.named_conf,
delete=opts.delete,
dry_run=opts.dry_run)
dry_run=opts.dry_run,
update_policies=opts.update_policies)
changed, removed = zw.write(zp.render(), postproc=pproc)
sys.exit(0)
......
......@@ -209,11 +209,13 @@ def readyaml(filenames):
class ZoneWriter(object):
def __init__(self, output_dir, named_conf, delete=False, dry_run=False):
def __init__(self, output_dir, named_conf, delete=False, dry_run=False,
update_policies=None):
self.output_dir = output_dir
self.named_conf = named_conf
self.dry_run = dry_run
self.delete_old_files = delete
self.update_policies = update_policies
def write_if_changed(self, data, dst):
if os.path.exists(dst):
......@@ -226,13 +228,17 @@ class ZoneWriter(object):
return True
def config_snippet(self, zone_name, zone_file):
return '''
s = '''
zone "%s" {
type master;
file "%s";
allow-query { any; };
};
''' % (zone_name, zone_file)
if self.update_policies:
for p in self.update_policies:
s += ' update-policy { %s; };\n' % (p,)
s += '};\n'
return s
def write(self, zones, postproc=None):
# Compare the current contents of 'output_dir' with the
......
......@@ -181,6 +181,40 @@ class ZoneWriterTest(ZoneWriterTestBase):
self.assertEquals(set(['inventati.org']), changed)
self.assertEquals(set(['autistici.org']), removed)
def test_config(self):
self.zp.load(_loadyaml(TEST_DATA))
self.zw.write(self.zp.render())
with open(os.path.join(self.tmpdir, 'named.conf')) as fd:
named_conf = fd.read()
self.assertEquals(named_conf, '''
zone "autistici.org" {
type master;
file "%s/zones/autistici.org";
allow-query { any; };
};
''' % (self.tmpdir,))
def test_config_with_update_policies(self):
self.zp.load(_loadyaml(TEST_DATA))
self.zw.update_policies = [
'grant testkey zonesub',
'grant acme zonesub TXT',
]
self.zw.write(self.zp.render())
with open(os.path.join(self.tmpdir, 'named.conf')) as fd:
named_conf = fd.read()
self.assertEquals(named_conf, '''
zone "autistici.org" {
type master;
file "%s/zones/autistici.org";
allow-query { any; };
update-policy { grant testkey zonesub; };
update-policy { grant acme zonesub TXT; };
};
''' % (self.tmpdir,))
class DNSSECTest(ZoneWriterTestBase):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment