Added workload status

This commit is contained in:
Liam Young 2015-10-07 10:41:12 +00:00
parent 592e691b31
commit 32ec1cb6a6
4 changed files with 48 additions and 0 deletions

View File

@ -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()

View File

@ -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'

View File

@ -30,6 +30,7 @@ TO_PATCH = [
'ExternalPortContext',
'determine_dkms_package',
'headers_package',
'status_set',
]
head_pkg = 'linux-headers-3.15.0-5-generic'

View File

@ -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():
'''