Clean up stale ceph keyring

[cbjchen,r=]
Clean up the keyring after ceph relation is broken. So when next
time ceph relation is joined, ensure_ceph_keyring will not ignore
the new key because of the existance of the old one.
This commit is contained in:
Liang Chen liang.chen@canonical.com 2015-02-04 14:24:05 -05:00
parent 5ae1ca0b8e
commit 26a67b7013
2 changed files with 20 additions and 3 deletions

View File

@ -30,6 +30,7 @@ from charmhelpers.contrib.storage.linux.ceph import (
ensure_ceph_keyring,
CephBrokerRq,
CephBrokerRsp,
delete_keyring,
)
from charmhelpers.payload.execd import execd_preinstall
@ -88,8 +89,14 @@ def ceph_changed():
log("Request(s) sent to Ceph broker (rid=%s)" % (rid))
@hooks.hook('ceph-relation-broken',
'config-changed')
@hooks.hook('ceph-relation-broken')
def ceph_broken():
service = service_name()
delete_keyring(service=service)
CONFIGS.write_all()
@hooks.hook('config-changed')
@restart_on_change(restart_map())
def write_and_restart():
CONFIGS.write_all()

View File

@ -31,7 +31,8 @@ TO_PATCH = [
'apt_update',
# charmhelpers.contrib.hahelpers.cluster_utils
'execd_preinstall',
'CephSubordinateContext'
'CephSubordinateContext',
'delete_keyring'
]
@ -91,6 +92,15 @@ class TestCinderHooks(CharmTestCase):
self.assertTrue(self.log.called)
self.assertFalse(self.CONFIGS.write_all.called)
@patch('charmhelpers.core.hookenv.config')
def test_ceph_broken(self, mock_config):
self.CONFIGS.complete_contexts.return_value = ['ceph']
self.service_name.return_value = 'cinder-ceph'
hooks.hooks.execute(['hooks/ceph-relation-changed'])
hooks.hooks.execute(['hooks/ceph-relation-broken'])
self.delete_keyring.assert_called_with(service='cinder-ceph')
self.assertTrue(self.CONFIGS.write_all.called)
@patch('charmhelpers.core.hookenv.config')
@patch.object(hooks, 'storage_backend')
def test_upgrade_charm_related(self, _storage_backend, mock_config):