From 32ec1cb6a69647bc963d65772991ca0fa4f2ee16 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Wed, 7 Oct 2015 10:41:12 +0000 Subject: [PATCH 1/2] Added workload status --- hooks/neutron_ovs_hooks.py | 17 +++++++++++++++++ hooks/neutron_ovs_utils.py | 27 +++++++++++++++++++++++++++ unit_tests/test_neutron_ovs_utils.py | 1 + unit_tests/test_utils.py | 3 +++ 4 files changed, 48 insertions(+) diff --git a/hooks/neutron_ovs_hooks.py b/hooks/neutron_ovs_hooks.py index 6f656368..53599536 100755 --- a/hooks/neutron_ovs_hooks.py +++ b/hooks/neutron_ovs_hooks.py @@ -22,6 +22,7 @@ from charmhelpers.core.host import ( from charmhelpers.contrib.openstack.utils import ( os_requires_version, + os_workload_status, ) from neutron_ovs_utils import ( @@ -38,6 +39,8 @@ from neutron_ovs_utils import ( enable_local_dhcp, install_packages, purge_packages, + REQUIRED_INTERFACES, + check_optional_relations, ) hooks = Hooks() @@ -52,6 +55,8 @@ def install(): @hooks.hook('neutron-plugin-relation-changed') @hooks.hook('config-changed') +@os_workload_status(CONFIGS, REQUIRED_INTERFACES, + charm_func=check_optional_relations) @restart_on_change(restart_map()) def config_changed(): install_packages() @@ -68,6 +73,8 @@ def config_changed(): @hooks.hook('neutron-plugin-api-relation-changed') +@os_workload_status(CONFIGS, REQUIRED_INTERFACES, + charm_func=check_optional_relations) @restart_on_change(restart_map()) def neutron_plugin_api_changed(): if use_dvr(): @@ -82,6 +89,8 @@ def neutron_plugin_api_changed(): @hooks.hook('neutron-plugin-relation-joined') +@os_workload_status(CONFIGS, REQUIRED_INTERFACES, + charm_func=check_optional_relations) def neutron_plugin_joined(relation_id=None): if enable_local_dhcp(): install_packages() @@ -95,6 +104,8 @@ def neutron_plugin_joined(relation_id=None): @hooks.hook('amqp-relation-joined') +@os_workload_status(CONFIGS, REQUIRED_INTERFACES, + charm_func=check_optional_relations) def amqp_joined(relation_id=None): relation_set(relation_id=relation_id, username=config('rabbit-user'), @@ -103,6 +114,8 @@ def amqp_joined(relation_id=None): @hooks.hook('amqp-relation-changed') @hooks.hook('amqp-relation-departed') +@os_workload_status(CONFIGS, REQUIRED_INTERFACES, + charm_func=check_optional_relations) @restart_on_change(restart_map()) def amqp_changed(): if 'amqp' not in CONFIGS.complete_contexts(): @@ -112,6 +125,8 @@ def amqp_changed(): @hooks.hook('zeromq-configuration-relation-joined') +@os_workload_status(CONFIGS, REQUIRED_INTERFACES, + charm_func=check_optional_relations) @os_requires_version('kilo', 'neutron-common') def zeromq_configuration_relation_joined(relid=None): relation_set(relation_id=relid, @@ -120,6 +135,8 @@ def zeromq_configuration_relation_joined(relid=None): @hooks.hook('zeromq-configuration-relation-changed') +@os_workload_status(CONFIGS, REQUIRED_INTERFACES, + charm_func=check_optional_relations) @restart_on_change(restart_map(), stopstart=True) def zeromq_configuration_relation_changed(): CONFIGS.write_all() diff --git a/hooks/neutron_ovs_utils.py b/hooks/neutron_ovs_utils.py index 347fd4b9..9f09987e 100644 --- a/hooks/neutron_ovs_utils.py +++ b/hooks/neutron_ovs_utils.py @@ -10,6 +10,7 @@ from charmhelpers.contrib.openstack.utils import ( git_clone_and_install, git_src_dir, git_pip_venv_dir, + set_os_workload_status, ) from collections import OrderedDict from charmhelpers.contrib.openstack.utils import ( @@ -23,6 +24,8 @@ from charmhelpers.contrib.network.ovs import ( ) from charmhelpers.core.hookenv import ( config, + status_set, + status_get, ) from charmhelpers.contrib.openstack.neutron import ( parse_bridge_mappings, @@ -52,6 +55,15 @@ from charmhelpers.fetch import ( filter_installed_packages, ) +# The interface is said to be satisfied if anyone of the interfaces in the +# list has a complete context. +# LY: Note the neutron-plugin is always present since that is the relation +# with the principle and no data currently flows down from the principle +# so there is no point in having it in REQUIRED_INTERFACES +REQUIRED_INTERFACES = { + 'messaging': ['amqp', 'zeromq-configuration'], +} + BASE_GIT_PACKAGES = [ 'libffi-dev', 'libssl-dev', @@ -140,6 +152,7 @@ DATA_BRIDGE = 'br-data' def install_packages(): + status_set('maintenance', 'Installing apt packages') apt_update() # NOTE(jamespage): ensure early install of dkms related # dependencies for kernels which need @@ -151,6 +164,7 @@ def install_packages(): def purge_packages(pkg_list): + status_set('maintenance', 'Purging unused apt packages') purge_pkgs = [] required_packages = determine_packages() for pkg in pkg_list: @@ -229,6 +243,7 @@ def get_topics(): def configure_ovs(): + status_set('maintenance', 'Configuring ovs') if not service_running('openvswitch-switch'): full_restart() add_bridge(INT_BRIDGE) @@ -275,6 +290,7 @@ def enable_local_dhcp(): def git_install(projects_yaml): """Perform setup, and install git repos specified in yaml parameter.""" + status_set('maintenance', 'running git install') if git_install_requested(): git_pre_install() git_clone_and_install(projects_yaml, core_project='neutron') @@ -364,3 +380,14 @@ def git_post_install(projects_yaml): neutron_ovs_cleanup_context, perms=0o644) service_restart('neutron-plugin-openvswitch-agent') + + +def check_optional_relations(configs): + required_interfaces = {} + if enable_nova_metadata(): + required_interfaces['neutron-plugin-api'] = ['neutron-plugin-api'] + if required_interfaces: + set_os_workload_status(configs, required_interfaces) + return status_get() + else: + return 'unknown', 'No optional relations' diff --git a/unit_tests/test_neutron_ovs_utils.py b/unit_tests/test_neutron_ovs_utils.py index a3b26b52..0125cffa 100644 --- a/unit_tests/test_neutron_ovs_utils.py +++ b/unit_tests/test_neutron_ovs_utils.py @@ -30,6 +30,7 @@ TO_PATCH = [ 'ExternalPortContext', 'determine_dkms_package', 'headers_package', + 'status_set', ] head_pkg = 'linux-headers-3.15.0-5-generic' diff --git a/unit_tests/test_utils.py b/unit_tests/test_utils.py index 86ee0f73..bbc71fb3 100644 --- a/unit_tests/test_utils.py +++ b/unit_tests/test_utils.py @@ -6,6 +6,9 @@ import yaml from contextlib import contextmanager from mock import patch, MagicMock +patch('charmhelpers.contrib.openstack.utils.set_os_workload_status').start() +patch('charmhelpers.core.hookenv.status_set').start() + def load_config(): ''' From 7deaffa7957363e6638453842ee09866e330d5a5 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 8 Oct 2015 14:25:23 +0100 Subject: [PATCH 2/2] Move from decorator to new format for workload status --- hooks/neutron_ovs_hooks.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/hooks/neutron_ovs_hooks.py b/hooks/neutron_ovs_hooks.py index 53599536..58e172fa 100755 --- a/hooks/neutron_ovs_hooks.py +++ b/hooks/neutron_ovs_hooks.py @@ -22,7 +22,7 @@ from charmhelpers.core.host import ( from charmhelpers.contrib.openstack.utils import ( os_requires_version, - os_workload_status, + set_os_workload_status, ) from neutron_ovs_utils import ( @@ -55,8 +55,6 @@ def install(): @hooks.hook('neutron-plugin-relation-changed') @hooks.hook('config-changed') -@os_workload_status(CONFIGS, REQUIRED_INTERFACES, - charm_func=check_optional_relations) @restart_on_change(restart_map()) def config_changed(): install_packages() @@ -73,8 +71,6 @@ def config_changed(): @hooks.hook('neutron-plugin-api-relation-changed') -@os_workload_status(CONFIGS, REQUIRED_INTERFACES, - charm_func=check_optional_relations) @restart_on_change(restart_map()) def neutron_plugin_api_changed(): if use_dvr(): @@ -89,8 +85,6 @@ def neutron_plugin_api_changed(): @hooks.hook('neutron-plugin-relation-joined') -@os_workload_status(CONFIGS, REQUIRED_INTERFACES, - charm_func=check_optional_relations) def neutron_plugin_joined(relation_id=None): if enable_local_dhcp(): install_packages() @@ -104,8 +98,6 @@ def neutron_plugin_joined(relation_id=None): @hooks.hook('amqp-relation-joined') -@os_workload_status(CONFIGS, REQUIRED_INTERFACES, - charm_func=check_optional_relations) def amqp_joined(relation_id=None): relation_set(relation_id=relation_id, username=config('rabbit-user'), @@ -114,8 +106,6 @@ def amqp_joined(relation_id=None): @hooks.hook('amqp-relation-changed') @hooks.hook('amqp-relation-departed') -@os_workload_status(CONFIGS, REQUIRED_INTERFACES, - charm_func=check_optional_relations) @restart_on_change(restart_map()) def amqp_changed(): if 'amqp' not in CONFIGS.complete_contexts(): @@ -125,8 +115,6 @@ def amqp_changed(): @hooks.hook('zeromq-configuration-relation-joined') -@os_workload_status(CONFIGS, REQUIRED_INTERFACES, - charm_func=check_optional_relations) @os_requires_version('kilo', 'neutron-common') def zeromq_configuration_relation_joined(relid=None): relation_set(relation_id=relid, @@ -135,8 +123,6 @@ def zeromq_configuration_relation_joined(relid=None): @hooks.hook('zeromq-configuration-relation-changed') -@os_workload_status(CONFIGS, REQUIRED_INTERFACES, - charm_func=check_optional_relations) @restart_on_change(restart_map(), stopstart=True) def zeromq_configuration_relation_changed(): CONFIGS.write_all() @@ -147,6 +133,8 @@ def main(): hooks.execute(sys.argv) except UnregisteredHookError as e: log('Unknown hook {} - skipping.'.format(e)) + set_os_workload_status(CONFIGS, REQUIRED_INTERFACES, + charm_func=check_optional_relations) if __name__ == '__main__':