Require relation to nova-compute application

Without a relation to at least one nova-compute application a
cinder-ceph backend will not be functional as the libvirt
secrets will not have been created to allow access to the
ceph cluster from libvirt/qemu.

Add a simple context to check that the 'ceph-access' relation
is present.  This will result in a blocked status if the
relation is not detected - for example:

  Missing relations: nova-compute

Change-Id: Iedbf4aafc2348cbf6f14257417e86aa9aeb48a81
Closes-Bug: 1718051
This commit is contained in:
James Page 2020-05-28 06:46:39 +01:00
parent e1f2335358
commit f200d8dff5
8 changed files with 43 additions and 5 deletions

View File

@ -0,0 +1 @@
cinder_hooks.py

View File

@ -0,0 +1 @@
cinder_hooks.py

View File

@ -17,6 +17,8 @@ from charmhelpers.core.hookenv import (
service_name,
is_relation_made,
leader_get,
relation_ids,
related_units,
)
from charmhelpers.contrib.openstack.context import (
@ -35,6 +37,17 @@ def ceph_config_file():
return CHARM_CEPH_CONF.format(service_name())
class CephAccessContext(OSContextGenerator):
interfaces = ['ceph-access']
def __call__(self):
"""Simple check to validate that compute units are present"""
for r_id in relation_ids(self.interfaces[0]):
if related_units(r_id):
return {'complete': True}
return {}
class CephSubordinateContext(OSContextGenerator):
interfaces = ['ceph-cinder']

View File

@ -30,6 +30,8 @@ from charmhelpers.core.hookenv import (
)
from charmhelpers.core.host import mkdir
import cinder_contexts
PACKAGES = [
'ceph-common',
@ -39,6 +41,7 @@ VERSION_PACKAGE = 'cinder-common'
REQUIRED_INTERFACES = {
'ceph': ['ceph'],
'nova-compute': ['ceph-access'],
}
CHARM_CEPH_CONF = '/var/lib/charm/{}/ceph.conf'
@ -84,7 +87,8 @@ def register_configs():
install_alternative(os.path.basename(CEPH_CONF),
CEPH_CONF, ceph_config_file())
CONFIG_FILES[ceph_config_file()] = {
'hook_contexts': [context.CephContext()],
'hook_contexts': [context.CephContext(),
cinder_contexts.CephAccessContext()],
'services': ['cinder-volume'],
}
confs.append(ceph_config_file())

View File

@ -10,7 +10,7 @@
charm-tools>=2.4.4
requests>=2.18.4
mock>=1.2
flake8>=2.2.4,<=2.4.1
flake8>=2.2.4
stestr>=2.2.0
coverage>=4.5.2
pyudev # for ceph-* charm unit tests (need to fix the ceph-* charm unit tests/mocking)

View File

@ -26,6 +26,7 @@ def _add_path(path):
if path not in sys.path:
sys.path.insert(1, path)
_add_path(_actions)
_add_path(_hooks)
_add_path(_charmhelpers)

View File

@ -24,6 +24,8 @@ TO_PATCH = [
'service_name',
'get_os_codename_package',
'leader_get',
'relation_ids',
'related_units',
]
@ -140,3 +142,19 @@ class TestCinderContext(CharmTestCase):
}
}
}})
def test_ceph_access_incomplete(self):
self.relation_ids.return_value = ['ceph-access:1']
self.related_units.return_value = []
self.assertEqual(
contexts.CephAccessContext()(),
{}
)
def test_ceph_access_complete(self):
self.relation_ids.return_value = ['ceph-access:1']
self.related_units.return_value = ['nova-compute/0', 'nova-compute/1']
self.assertEqual(
contexts.CephAccessContext()(),
{'complete': True}
)

View File

@ -93,9 +93,9 @@ class TestConfig(object):
return self.config
def set(self, attr, value):
if attr not in self.config:
raise KeyError
self.config[attr] = value
if attr not in self.config:
raise KeyError
self.config[attr] = value
class TestRelation(object):