Restart nova-api-metadata on restart_nonce changes
The nova-cloud-controller presents a restart_nonce key on the quantum-network-service relation once db migration has been completed and the nova-conductor service is able to respond to RPC calls. Restart the nova-api-metadata when this data changes to ensure a running service post deployment. Change-Id: Iafc27fbb2a70e3195fc189e4056a1ca58ff6b663 Closes-Bug: 1547122
This commit is contained in:
parent
3f9fb284c1
commit
c287278881
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@ precise
|
||||
trusty
|
||||
wily
|
||||
xenial
|
||||
.unit-state.db
|
||||
|
@ -12,6 +12,8 @@ from charmhelpers.core.hookenv import (
|
||||
UnregisteredHookError,
|
||||
status_set,
|
||||
)
|
||||
from charmhelpers.core.host import service_restart
|
||||
from charmhelpers.core.unitdata import kv
|
||||
from charmhelpers.fetch import (
|
||||
apt_update,
|
||||
apt_install,
|
||||
@ -34,6 +36,7 @@ from charmhelpers.contrib.openstack.utils import (
|
||||
openstack_upgrade_available,
|
||||
os_requires_version,
|
||||
pausable_restart_on_change as restart_on_change,
|
||||
is_unit_paused_set,
|
||||
)
|
||||
from charmhelpers.payload.execd import execd_preinstall
|
||||
from charmhelpers.core.sysctl import create as create_sysctl
|
||||
@ -220,6 +223,20 @@ def nm_changed():
|
||||
if config('ha-legacy-mode'):
|
||||
cache_env_data()
|
||||
|
||||
# NOTE: nova-api-metadata needs to be restarted
|
||||
# once the nova-conductor is up and running
|
||||
# on the nova-cc units.
|
||||
restart_nonce = relation_get('restart_nonce')
|
||||
if restart_nonce is not None:
|
||||
db = kv()
|
||||
previous_nonce = db.get('restart_nonce',
|
||||
restart_nonce)
|
||||
if previous_nonce != restart_nonce:
|
||||
if not is_unit_paused_set():
|
||||
service_restart('nova-api-metadata')
|
||||
db.set('restart_nonce', restart_nonce)
|
||||
db.flush()
|
||||
|
||||
|
||||
@hooks.hook("cluster-relation-departed")
|
||||
@restart_on_change(restart_map())
|
||||
|
@ -54,6 +54,9 @@ TO_PATCH = [
|
||||
'cleanup_ovs_netns',
|
||||
'stop_neutron_ha_monitor_daemon',
|
||||
'use_l3ha',
|
||||
'kv',
|
||||
'service_restart',
|
||||
'is_unit_paused_set',
|
||||
]
|
||||
|
||||
|
||||
@ -277,11 +280,60 @@ class TestQuantumHooks(CharmTestCase):
|
||||
self.assertTrue(self.CONFIGS.write_all.called)
|
||||
|
||||
def test_nm_changed(self):
|
||||
self.relation_get.return_value = "cert"
|
||||
def _relation_get(key):
|
||||
data = {
|
||||
'ca_cert': 'cert',
|
||||
'restart_nonce': None,
|
||||
}
|
||||
return data.get(key)
|
||||
self.relation_get.side_effect = _relation_get
|
||||
self._call_hook('quantum-network-service-relation-changed')
|
||||
self.assertTrue(self.CONFIGS.write_all.called)
|
||||
self.install_ca_cert.assert_called_with('cert')
|
||||
|
||||
def test_nm_changed_restart_nonce_changed(self):
|
||||
def _relation_get(key):
|
||||
data = {
|
||||
'ca_cert': 'cert',
|
||||
'restart_nonce': '1111111222222333333',
|
||||
}
|
||||
return data.get(key)
|
||||
self.relation_get.side_effect = _relation_get
|
||||
self.is_unit_paused_set.return_value = False
|
||||
kv_mock = MagicMock()
|
||||
self.kv.return_value = kv_mock
|
||||
kv_mock.get.return_value = ('22222233333344444')
|
||||
self._call_hook('quantum-network-service-relation-changed')
|
||||
self.assertTrue(self.CONFIGS.write_all.called)
|
||||
self.install_ca_cert.assert_called_with('cert')
|
||||
self.service_restart.assert_called_with('nova-api-metadata')
|
||||
kv_mock.get.assert_called_with('restart_nonce',
|
||||
'1111111222222333333')
|
||||
kv_mock.set.assert_called_with('restart_nonce',
|
||||
'1111111222222333333')
|
||||
self.assertTrue(kv_mock.flush.called)
|
||||
|
||||
def test_nm_changed_restart_nonce_nochange(self):
|
||||
def _relation_get(key):
|
||||
data = {
|
||||
'ca_cert': 'cert',
|
||||
'restart_nonce': '1111111222222333333',
|
||||
}
|
||||
return data.get(key)
|
||||
self.relation_get.side_effect = _relation_get
|
||||
self.is_unit_paused_set.return_value = False
|
||||
kv_mock = MagicMock()
|
||||
self.kv.return_value = kv_mock
|
||||
kv_mock.get.return_value = ('1111111222222333333')
|
||||
self._call_hook('quantum-network-service-relation-changed')
|
||||
self.assertTrue(self.CONFIGS.write_all.called)
|
||||
self.install_ca_cert.assert_called_with('cert')
|
||||
self.assertFalse(self.service_restart.called)
|
||||
kv_mock.get.assert_called_with('restart_nonce',
|
||||
'1111111222222333333')
|
||||
self.assertFalse(kv_mock.set.called)
|
||||
self.assertFalse(kv_mock.flush.called)
|
||||
|
||||
def test_neutron_plugin_changed(self):
|
||||
self.use_l3ha.return_value = True
|
||||
self._call_hook('neutron-plugin-api-relation-changed')
|
||||
|
Loading…
Reference in New Issue
Block a user