It sets “restart-trigger” key on neutron-plugin relation on upgrade-charm event.
When neutron-api-plugin-ovn charm is upgraded (juju refresh ...) some configuration parameters in ml2_conf.ini may have also updated. It was observed that sometime those changes are not taken in to account by neutron service because it was not restarted after file content modification. This change introduces rising of “restart-trigger” key on neutron-plugin relation databag when upgrade-charm event is generated. With every new “charm-upgrade” event value for “restart-trigger” is updated: f.e. “restart-trigger cf2697c8-f5f0-44b5-8dae-32d893fb209c”. Principal charm “neutron-api” has implemented logic which triggers neutron service restart as soon as “restart-trigger” key value is changed. Closes-Bug: #2019798 Change-Id: Ia1f48d86330d6e357ae3b35ce28bbb036788ac4a
This commit is contained in:
parent
26287e88fd
commit
84ec4ada23
|
@ -16,6 +16,7 @@ import os
|
|||
|
||||
import charms_openstack.adapters
|
||||
import charms_openstack.charm
|
||||
import charms.reactive as reactive
|
||||
|
||||
|
||||
CERT_RELATION = 'certificates'
|
||||
|
@ -228,6 +229,16 @@ class BaseNeutronAPIPluginCharm(charms_openstack.charm.OpenStackCharm):
|
|||
for network_type in neutron_tenant_network_types.split(',')
|
||||
]
|
||||
|
||||
def upgrade_charm(self):
|
||||
""" It rises 'restart-needed' flag as a part of "upgrade-charm" hook.
|
||||
|
||||
Flag is risen to trigger corresponding handler invocation.
|
||||
:param None
|
||||
:returns: None
|
||||
"""
|
||||
super().upgrade_charm()
|
||||
reactive.set_flag('restart-needed')
|
||||
|
||||
|
||||
class TrainNeutronAPIPluginCharm(BaseNeutronAPIPluginCharm):
|
||||
"""The Train incarnation of the charm."""
|
||||
|
|
|
@ -126,3 +126,11 @@ def configure_neutron():
|
|||
},
|
||||
)
|
||||
instance.assess_status()
|
||||
|
||||
|
||||
@reactive.when('restart-needed')
|
||||
def restart_neutron():
|
||||
ch_core.hookenv.log('DEBUG: Executing neutron restart')
|
||||
neutron = reactive.endpoint_from_flag('neutron-plugin.connected')
|
||||
neutron.request_restart()
|
||||
reactive.clear_flag('restart-needed')
|
||||
|
|
|
@ -17,9 +17,11 @@ import io
|
|||
import os
|
||||
import unittest.mock as mock
|
||||
|
||||
|
||||
import charms_openstack.test_utils as test_utils
|
||||
|
||||
import charm.openstack.neutron_api_plugin_ovn as neutron_api_plugin_ovn
|
||||
# import charms.reactive as reactive
|
||||
|
||||
|
||||
class TestNeutronAPIPluginOvnConfigProperties(test_utils.PatchHelper):
|
||||
|
@ -140,3 +142,15 @@ class TestNeutronAPIPluginOvnCharm(Helper):
|
|||
network_types = 'gre,vlan,flat,local'
|
||||
expect = ['geneve', 'gre', 'vlan', 'flat', 'local']
|
||||
self.assertEquals(c.tenant_network_types(network_types), expect)
|
||||
|
||||
@mock.patch.object(
|
||||
neutron_api_plugin_ovn.charms_openstack.charm.OpenStackCharm,
|
||||
'upgrade_charm')
|
||||
@mock.patch.object(neutron_api_plugin_ovn.reactive, 'set_flag')
|
||||
def test_upgrade_charm(self, set_flag, upgrade_charm):
|
||||
c = neutron_api_plugin_ovn.UssuriNeutronAPIPluginCharm()
|
||||
c.upgrade_charm()
|
||||
set_flag.assert_called_once()
|
||||
set_flag.assert_called_with('restart-needed')
|
||||
upgrade_charm.assert_called_once()
|
||||
upgrade_charm.assert_called_with()
|
||||
|
|
|
@ -46,6 +46,7 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks):
|
|||
'ovsdb-cms.available',),
|
||||
'assess_status': ('neutron-plugin.available',),
|
||||
'poke_ovsdb': ('ovsdb-cms.available',),
|
||||
'restart_neutron': ('restart-needed',),
|
||||
},
|
||||
}
|
||||
# test that the hooks were registered via the
|
||||
|
@ -168,3 +169,14 @@ class TestOvnHandlers(test_utils.PatchHelper):
|
|||
},
|
||||
},
|
||||
)
|
||||
|
||||
@mock.patch.object(handlers.reactive, 'endpoint_from_flag')
|
||||
@mock.patch.object(handlers.reactive, 'clear_flag')
|
||||
def test_restart_neutron(self, clear_flag, endpoint_from_flag):
|
||||
neutron_plugin = mock.MagicMock()
|
||||
endpoint_from_flag.return_value = neutron_plugin
|
||||
handlers.restart_neutron()
|
||||
neutron_plugin.request_restart.assert_called_once()
|
||||
neutron_plugin.request_restart.assert_called_once_with()
|
||||
clear_flag.assert_called_once()
|
||||
clear_flag.assert_called_once_with('restart-needed')
|
||||
|
|
Loading…
Reference in New Issue