Add final dot when missing in nameservers

The configuration option nameserver expects each value to have a dot (.)
at the end, currently when this dot is missing the servers creation
fail, the error doesn't bubble up. On the neutron-api charm adds the dot
automatically when it's missing in the dns-domain config option, this
change makes the Designate charm behave in the same way.

Change-Id: If335c9b5b1b2adca3e39fa4f1d182dfbe362f874
Closes-Bug: #1952656
This commit is contained in:
Felipe Reyes 2021-11-29 15:31:56 -03:00
parent 1e7035e2f0
commit 81c8cbf4a6
2 changed files with 10 additions and 3 deletions

View File

@ -543,7 +543,13 @@ class DesignateCharm(ch_plugins.PolicydOverridePlugin,
with cls.check_zone_ids(nova_domain_name, neutron_domain_name): with cls.check_zone_ids(nova_domain_name, neutron_domain_name):
if hookenv.config('nameservers'): if hookenv.config('nameservers'):
for ns in hookenv.config('nameservers').split(): for ns in hookenv.config('nameservers').split():
cls.create_server(ns) ns_ = ns
if not ns.endswith('.'):
ns_ = ns + '.'
hookenv.log(("Missing dot (.) at the end of '%s', "
"adding it automatically." % ns),
level=hookenv.WARNING)
cls.create_server(ns_)
else: else:
hookenv.log('No nameserver specified, skipping creation of' hookenv.log('No nameserver specified, skipping creation of'
'nova and neutron domains', 'nova and neutron domains',

View File

@ -311,7 +311,7 @@ class TestDesignateCharm(Helper):
def test_create_initial_servers_and_domains(self): def test_create_initial_servers_and_domains(self):
test_config = { test_config = {
'nameservers': 'dnsserverrec1', 'nameservers': 'dnsserverrec1. dnsserverrec2',
'nova-domain': 'novadomain', 'nova-domain': 'novadomain',
'nova-domain-email': 'novaemail', 'nova-domain-email': 'novaemail',
'neutron-domain': 'neutrondomain', 'neutron-domain': 'neutrondomain',
@ -333,7 +333,8 @@ class TestDesignateCharm(Helper):
with mock.patch.object(designate.hookenv, 'config', with mock.patch.object(designate.hookenv, 'config',
side_effect=FakeConfig(test_config)): side_effect=FakeConfig(test_config)):
designate.DesignateCharm.create_initial_servers_and_domains() designate.DesignateCharm.create_initial_servers_and_domains()
self.create_server.assert_called_once_with('dnsserverrec1') self.create_server.assert_has_calls([mock.call('dnsserverrec1.'),
mock.call('dnsserverrec2.')])
calls = [ calls = [
mock.call('novadomain', 'novaemail'), mock.call('novadomain', 'novaemail'),
mock.call('neutrondomain', 'neutronemail')] mock.call('neutrondomain', 'neutronemail')]