diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index f9b66dcb..a33bce63 100644 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -25,7 +25,6 @@ from charmhelpers.core.hookenv import ( log, relation_ids, service_name, - status_get, ) @@ -61,7 +60,6 @@ from charmhelpers.contrib.openstack.utils import ( git_pip_venv_dir, configure_installation_source, os_release, - set_os_workload_status, is_unit_paused_set, make_assess_status_func, pause_unit, @@ -442,28 +440,45 @@ def git_post_install(projects_yaml): service_restart('glance-registry') -def check_optional_relations(configs): - required_interfaces = {} +def get_optional_interfaces(): + """Return the optional interfaces that should be checked if the relavent + relations have appeared. + + :returns: {general_interface: [specific_int1, specific_int2, ...], ...} + """ + optional_interfaces = {} + if relation_ids('ha'): + optional_interfaces['ha'] = ['cluster'] + + if relation_ids('ceph') or relation_ids('object-store'): + optional_interfaces['storage-backend'] = ['ceph', 'object-store'] + + if relation_ids('amqp'): + optional_interfaces['messaging'] = ['amqp'] + return optional_interfaces + + +def check_optional_relations(configs): + """Check that if we have a relation_id for high availability that we can + get the hacluster config. If we can't then we are blocked. + + This function is called from assess_status/set_os_workload_status as the + charm_func and needs to return either None, None if there is no problem or + the status, message if there is a problem. + + :param configs: an OSConfigRender() instance. + :return 2-tuple: (string, string) = (status, message) + """ if relation_ids('ha'): - required_interfaces['ha'] = ['cluster'] try: get_hacluster_config() except: return ('blocked', 'hacluster missing configuration: ' 'vip, vip_iface, vip_cidr') - - if relation_ids('ceph') or relation_ids('object-store'): - required_interfaces['storage-backend'] = ['ceph', 'object-store'] - - if relation_ids('amqp'): - required_interfaces['messaging'] = ['amqp'] - - if required_interfaces: - set_os_workload_status(configs, required_interfaces) - return status_get() - else: - return 'unknown', 'No optional relations' + # return 'unknown' as the lowest priority to not clobber an existing + # status. + return "unknown", "" def swift_temp_url_key(): @@ -529,14 +544,20 @@ def assess_status_func(configs): Used directly by assess_status() and also for pausing and resuming the unit. + NOTE: REQUIRED_INTERFACES is augmented with the optional interfaces + depending on the current config before being passed to the + make_assess_status_func() function. + NOTE(ajkavanagh) ports are not checked due to race hazards with services that don't behave sychronously w.r.t their service scripts. e.g. apache2. @param configs: a templating.OSConfigRenderer() object @return f() -> None : a function that assesses the unit's workload status """ + required_interfaces = REQUIRED_INTERFACES.copy() + required_interfaces.update(get_optional_interfaces()) return make_assess_status_func( - configs, REQUIRED_INTERFACES, + configs, required_interfaces, charm_func=check_optional_relations, services=services(), ports=None) diff --git a/unit_tests/test_glance_utils.py b/unit_tests/test_glance_utils.py index ff84aaa2..713ae953 100644 --- a/unit_tests/test_glance_utils.py +++ b/unit_tests/test_glance_utils.py @@ -295,18 +295,23 @@ class TestGlanceUtils(CharmTestCase): asf.assert_called_once_with('test-config') callee.assert_called_once_with() + @patch.object(utils, 'get_optional_interfaces') @patch.object(utils, 'REQUIRED_INTERFACES') @patch.object(utils, 'services') @patch.object(utils, 'make_assess_status_func') def test_assess_status_func(self, make_assess_status_func, services, - REQUIRED_INTERFACES): + REQUIRED_INTERFACES, + get_optional_interfaces): services.return_value = 's1' + REQUIRED_INTERFACES.copy.return_value = {'int': ['test 1']} + get_optional_interfaces.return_value = {'opt': ['test 2']} utils.assess_status_func('test-config') # ports=None whilst port checks are disabled. make_assess_status_func.assert_called_once_with( - 'test-config', REQUIRED_INTERFACES, + 'test-config', + {'int': ['test 1'], 'opt': ['test 2']}, charm_func=utils.check_optional_relations, services='s1', ports=None)