Update hook to remove old ceph.conf alternatives

When adding ceph-mon relation to cinder, the charm installs ceph.conf
with the update-alternatives via cinder_utils.resource_map().
However when the relation is removed, the alternative isn't cleaned up.
This can cause issues if installing a cinder-ceph subordinate charm.
The cinder-ceph charm also installs a ceph.conf alternative that will
point to the leftover ceph.conf installed by the ceph-mon charm.

Added remove_alternative() in ceph-relation-broken hook to ensure
that leftover ceph.conf alternatives is removed upon relation removal.

Change-Id: I308e62a626f31eb8ef690a09035fe3908920ccc9
Closes-Bug: 1778084
This commit is contained in:
Syed Mohammad Adnan Karim 2018-11-26 15:40:21 +00:00
parent 50eec67129
commit 18cbf7f6e1
3 changed files with 16 additions and 2 deletions

View File

@ -26,8 +26,12 @@ from cinder_utils import (
PACKAGES,
REQUIRED_INTERFACES,
VERSION_PACKAGE,
CEPH_CONF,
)
from cinder_contexts import (
CephSubordinateContext,
ceph_config_file,
)
from cinder_contexts import CephSubordinateContext
from charmhelpers.contrib.openstack.context import CephContext
from charmhelpers.core.hookenv import (
@ -48,6 +52,7 @@ from charmhelpers.core.host import (
restart_on_change,
service_restart,
)
from charmhelpers.contrib.openstack.alternatives import remove_alternative
from charmhelpers.contrib.storage.linux.ceph import (
send_request_if_needed,
is_request_complete,
@ -142,6 +147,7 @@ def ceph_broken():
service = service_name()
delete_keyring(service=service)
CONFIGS.write_all()
remove_alternative(os.path.basename(CEPH_CONF), ceph_config_file())
@hooks.hook('config-changed')

View File

@ -24,6 +24,7 @@ from tempfile import NamedTemporaryFile
from charmhelpers.core.hookenv import (
relation_ids,
service_name,
hook_name,
)
from charmhelpers.contrib.openstack import (
@ -78,7 +79,7 @@ def register_configs():
confs = []
if relation_ids('ceph'):
if relation_ids('ceph') and hook_name() != 'ceph-relation-broken':
# Add charm ceph configuration to resources and
# ensure directory actually exists
mkdir(os.path.dirname(ceph_config_file()))

View File

@ -13,6 +13,7 @@
# limitations under the License.
from mock import MagicMock, patch, call, ANY
import os
import json
import cinder_utils as utils
@ -35,6 +36,8 @@ TO_PATCH = [
'is_request_complete',
'send_request_if_needed',
'CONFIGS',
'CEPH_CONF',
'ceph_config_file',
# charmhelpers.core.hookenv
'config',
'relation_ids',
@ -52,6 +55,7 @@ TO_PATCH = [
'execd_preinstall',
'CephSubordinateContext',
'delete_keyring',
'remove_alternative',
'status_set',
'os_application_version_set',
]
@ -168,6 +172,9 @@ class TestCinderHooks(CharmTestCase):
hooks.hooks.execute(['hooks/ceph-relation-broken'])
self.delete_keyring.assert_called_with(service='cinder-ceph')
self.assertTrue(self.CONFIGS.write_all.called)
self.remove_alternative.assert_called_with(
os.path.basename(self.CEPH_CONF),
self.ceph_config_file())
@patch('charmhelpers.core.hookenv.config')
@patch.object(hooks, 'storage_backend')