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
This commit is contained in:
Tytus Kurek 2018-03-22 15:56:23 +01:00
parent 293fc11bc0
commit 4f7c0a6e37
4 changed files with 37 additions and 10 deletions

View File

@ -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

View File

@ -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):
"""

View File

@ -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 %}

View File

@ -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):