diff --git a/src/lib/charm/openstack/ovn_central.py b/src/lib/charm/openstack/ovn_central.py index 9976334..06bb3d0 100644 --- a/src/lib/charm/openstack/ovn_central.py +++ b/src/lib/charm/openstack/ovn_central.py @@ -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. diff --git a/unit_tests/test_lib_charms_ovn_central.py b/unit_tests/test_lib_charms_ovn_central.py index cf731f4..c41d15c 100644 --- a/unit_tests/test_lib_charms_ovn_central.py +++ b/unit_tests/test_lib_charms_ovn_central.py @@ -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')