Reload ovn-northd service on certificate data change

The `ovn-northd` daemon does not detect certificate data changes,
reload the service when certificate data changes.

Change-Id: I37c6ff2c90f94ea0e77b27a9b28dc9dd0770b97e
Closes-Bug: #1895303
This commit is contained in:
Frode Nordahl 2020-09-23 10:09:51 +02:00
parent 5b197067ae
commit 71dd75c4cd
No known key found for this signature in database
GPG Key ID: 6A5D59A3BA48373F
2 changed files with 27 additions and 13 deletions

View File

@ -310,20 +310,26 @@ class BaseOVNCentralCharm(charms_openstack.charm.OpenStackCharm):
tls_objects = self.get_certs_and_keys(
certificates_interface=certificates_interface)
for tls_object in tls_objects:
with open(
self.options.ovn_ca_cert, 'w') as crt:
chain = tls_object.get('chain')
if chain:
crt.write(tls_object['ca'] + os.linesep + chain)
else:
crt.write(tls_object['ca'])
with charms_openstack.charm.utils.is_data_changed(
'configure_tls.tls_objects', tls_objects) as changed:
for tls_object in tls_objects:
with open(
self.options.ovn_ca_cert, 'w') as crt:
chain = tls_object.get('chain')
if chain:
crt.write(tls_object['ca'] + os.linesep + chain)
else:
crt.write(tls_object['ca'])
self.configure_cert(self.ovn_sysconfdir(),
tls_object['cert'],
tls_object['key'],
cn='host')
break
self.configure_cert(self.ovn_sysconfdir(),
tls_object['cert'],
tls_object['key'],
cn='host')
if changed:
# The `ovn-northd` daemon will not detect changes to the
# certificate data and needs to be restarted. LP: #1895303
self.service_reload('ovn-northd')
break
def configure_ovn_listener(self, db, port_map):
"""Create or update OVN listener configuration.

View File

@ -226,6 +226,10 @@ class TestOVNCentralCharm(Helper):
'ca': 'fakeca',
'chain': 'fakechain',
}]
self.patch_target('service_reload')
self.patch('charms_openstack.charm.utils.is_data_changed',
name='is_data_changed')
self.is_data_changed().__enter__.return_value = False
with mock.patch('builtins.open', create=True) as mocked_open:
mocked_file = mock.MagicMock(spec=io.FileIO)
mocked_open.return_value = mocked_file
@ -240,6 +244,10 @@ class TestOVNCentralCharm(Helper):
'fakecert',
'fakekey',
cn='host')
self.assertFalse(self.service_reload.called)
self.is_data_changed().__enter__.return_value = True
self.target.configure_tls()
self.service_reload.assert_called_once_with('ovn-northd')
def test_configure_ovn_listener(self):
self.patch_object(ovn_central.ch_ovsdb, 'SimpleOVSDB')