From 4f7c0a6e376c68ad371523282f37a08e05d5e322 Mon Sep 17 00:00:00 2001 From: Tytus Kurek Date: Thu, 22 Mar 2018 15:56:23 +0100 Subject: [PATCH] Add "also-notifies" option This patchset adds "also-notifies" option which is an optional part of the "pools.yaml" configuration and should only be used to define DNS servers other than the backend servers which should receive notifications on zone changes. Change-Id: I10faa6ec4ea4fd1f1f17c7234662cd5c23624c1d Closes-Bug: 1758008 --- src/config.yaml | 7 +++++++ src/lib/charm/openstack/designate.py | 9 +++++++++ src/templates/mitaka/pools.yaml | 17 +++++++---------- .../test_lib_charm_openstack_designate.py | 14 ++++++++++++++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/src/config.yaml b/src/config.yaml index 49e7d0d..3f387ee 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -67,3 +67,10 @@ options: type: boolean default: false description: Enables host request headers. + also-notifies: + type: string + default: + description: | + Space delimited list of DNS servers which should be notified on every + zone change in addition to the backend servers. List is of the form + also_notify_ip:also_notify_port diff --git a/src/lib/charm/openstack/designate.py b/src/lib/charm/openstack/designate.py index 0288150..383da71 100644 --- a/src/lib/charm/openstack/designate.py +++ b/src/lib/charm/openstack/designate.py @@ -270,6 +270,15 @@ class DesignateConfigurationAdapter( """ return self.nameservers.split() + @property + def also_notifies_hosts(self): + also_notifies_hosts = [] + if hookenv.config('also-notifies'): + for entry in hookenv.config('also-notifies').split(): + address, port = entry.split(':') + also_notifies_hosts.append({'address': address, 'port': port}) + return also_notifies_hosts + class DesignateAdapters(openstack_adapters.OpenStackAPIRelationAdapters): """ diff --git a/src/templates/mitaka/pools.yaml b/src/templates/mitaka/pools.yaml index 72c60d1..12c37db 100644 --- a/src/templates/mitaka/pools.yaml +++ b/src/templates/mitaka/pools.yaml @@ -54,16 +54,13 @@ {% endfor %} {% endif %} +{% if options.also_notifies_hosts %} also_notifies: -{% if dns_backend and dns_backend.pool_config %} -{% for slave in dns_backend.pool_config %} - - host: {{ slave.address }} - port: 53 -{% endfor %} -{% endif %} -{% if options.pool_config %} -{% for slave in options.pool_config %} - - host: {{ slave.address }} - port: 53 +{% for also_notify_host in options.also_notifies_hosts %} + - host: {{ also_notify_host.address }} + port: {{ also_notify_host.port }} {% endfor %} +# Workaround for https://bugs.launchpad.net/designate/+bug/1758013 +{% else %} + also_notifies: [] {% endif %} diff --git a/unit_tests/test_lib_charm_openstack_designate.py b/unit_tests/test_lib_charm_openstack_designate.py index 324319d..303f646 100644 --- a/unit_tests/test_lib_charm_openstack_designate.py +++ b/unit_tests/test_lib_charm_openstack_designate.py @@ -194,6 +194,20 @@ class TestDesignateConfigurationAdapter(Helper): a = designate.DesignateConfigurationAdapter(relation) self.assertEqual(a.rndc_master_ip, 'intip') + def test_also_notifies_hosts(self): + relation = mock.MagicMock + test_config = { + 'also-notifies': '10.0.0.1:53 10.0.0.2:10053', + } + with mock.patch.object(designate.hookenv, 'config', + side_effect=FakeConfig(test_config)): + expect = [{'address': '10.0.0.1', + 'port': '53'}, + {'address': '10.0.0.2', + 'port': '10053'}] + a = designate.DesignateConfigurationAdapter(relation) + self.assertEqual(a.also_notifies_hosts, expect) + class TestDesignateCharm(Helper):