Don't mask OVN service during charm upgrade.

Closes-Bug: #2007847
Change-Id: Icdd8502fa4c176ffc8cc8a0446dd150048d78dd1
This commit is contained in:
Martin Kalcok 2023-07-12 17:31:08 +02:00
parent 11408f28f6
commit db9216084f
2 changed files with 40 additions and 9 deletions

View File

@ -1002,16 +1002,20 @@ class UssuriOVNCentralCharm(BaseOVNCentralCharm):
'ovn-ovsdb-server-sb',
]
def install(self):
def install(self, service_masks=None):
"""Override charm install method."""
# This is done to prevent extraneous standalone DB initialization and
# subsequent upgrade to clustered DB when configuration is rendered.
service_masks = [
'ovn-central.service',
'ovn-ovsdb-server-nb.service',
'ovn-ovsdb-server-sb.service',
]
service_masks = service_masks or []
if not reactive.is_flag_set('charm.installed'):
# This is done to prevent extraneous standalone DB initialization
# and subsequent upgrade to clustered DB when configuration is
# rendered during the initial installation.
# Masking of OVN services is skipped on subsequent calls to this
# handler.
service_masks.extend([
'ovn-central.service',
'ovn-ovsdb-server-nb.service',
'ovn-ovsdb-server-sb.service',
])
super().install(service_masks=service_masks)

View File

@ -128,6 +128,8 @@ class TestOVNCentralCharm(Helper):
self.patch_object(ovn_central.os, 'symlink')
self.patch_target('configure_sources')
self.patch_object(ovn_central.os, 'mkdir')
self.patch_object(ovn_central.reactive, 'is_flag_set')
self.is_flag_set.return_value = False
self.target.install()
calls = []
for service in (self.target.services[0],
@ -146,6 +148,31 @@ class TestOVNCentralCharm(Helper):
self.install.assert_called_once_with()
self.configure_sources.assert_called_once_with()
def test_install_during_upgrade(self):
"""Test that services are not masked during charm upgrade.
install() handler is also called during charm-upgrade handling
and in such case, services should not be masked. Otherwise, it
results in upgrade failures.
"""
self.patch_object(ovn_central.charms_openstack.charm.OpenStackCharm,
'install')
self.patch_object(ovn_central.os.path, 'islink')
self.islink.return_value = False
self.patch_object(ovn_central.os, 'symlink')
self.patch_target('configure_sources')
self.patch_object(ovn_central.os, 'mkdir')
self.patch_object(ovn_central.reactive, 'is_flag_set')
self.is_flag_set.return_value = True
self.target.install()
# Assert that services were not masked
self.islink.assert_not_called()
self.symlink.assert_not_called()
self.install.assert_called_once_with()
self.configure_sources.assert_called_once_with()
def test_configure_ovn_source(self):
self.patch_target('configure_source')
self.patch_object(ovn_central.ch_core.hookenv, 'config',