[thedac,r=gnuoy] Workload Status

This commit is contained in:
Liam Young 2015-09-29 16:52:10 +01:00
commit 024fb53afb
3 changed files with 89 additions and 1 deletions

View File

@ -27,6 +27,8 @@ from cinder_utils import (
setup_ipv6, setup_ipv6,
check_db_initialised, check_db_initialised,
filesystem_mounted, filesystem_mounted,
REQUIRED_INTERFACES,
check_optional_relations,
) )
from charmhelpers.core.hookenv import ( from charmhelpers.core.hookenv import (
@ -42,6 +44,7 @@ from charmhelpers.core.hookenv import (
unit_get, unit_get,
log, log,
ERROR, ERROR,
status_set,
) )
from charmhelpers.fetch import ( from charmhelpers.fetch import (
@ -63,6 +66,7 @@ from charmhelpers.contrib.openstack.utils import (
openstack_upgrade_available, openstack_upgrade_available,
sync_db_with_multi_ipv6_addresses, sync_db_with_multi_ipv6_addresses,
os_release, os_release,
os_workload_status,
) )
from charmhelpers.contrib.storage.linux.ceph import ( from charmhelpers.contrib.storage.linux.ceph import (
@ -100,7 +104,10 @@ CONFIGS = register_configs()
@hooks.hook('install.real') @hooks.hook('install.real')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def install(): def install():
status_set('maintenance', 'Executing pre-install')
execd_preinstall() execd_preinstall()
conf = config() conf = config()
src = conf['openstack-origin'] src = conf['openstack-origin']
@ -109,18 +116,23 @@ def install():
src = 'cloud:precise-folsom' src = 'cloud:precise-folsom'
configure_installation_source(src) configure_installation_source(src)
status_set('maintenance', 'Installing apt packages')
apt_update() apt_update()
apt_install(determine_packages(), fatal=True) apt_install(determine_packages(), fatal=True)
status_set('maintenance', 'Git install')
git_install(config('openstack-origin-git')) git_install(config('openstack-origin-git'))
@hooks.hook('config-changed') @hooks.hook('config-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map(), stopstart=True) @restart_on_change(restart_map(), stopstart=True)
def config_changed(): def config_changed():
conf = config() conf = config()
if conf['prefer-ipv6']: if conf['prefer-ipv6']:
status_set('maintenance', 'configuring ipv6')
setup_ipv6() setup_ipv6()
sync_db_with_multi_ipv6_addresses(config('database'), sync_db_with_multi_ipv6_addresses(config('database'),
config('database-user')) config('database-user'))
@ -131,6 +143,7 @@ def config_changed():
if (service_enabled('volume') and if (service_enabled('volume') and
conf['block-device'] not in [None, 'None', 'none']): conf['block-device'] not in [None, 'None', 'none']):
status_set('maintenance', 'Configuring lvm storage')
block_devices = conf['block-device'].split() block_devices = conf['block-device'].split()
configure_lvm_storage(block_devices, configure_lvm_storage(block_devices,
conf['volume-group'], conf['volume-group'],
@ -140,9 +153,11 @@ def config_changed():
if git_install_requested(): if git_install_requested():
if config_value_changed('openstack-origin-git'): if config_value_changed('openstack-origin-git'):
status_set('maintenance', 'Running Git install')
git_install(config('openstack-origin-git')) git_install(config('openstack-origin-git'))
elif not config('action-managed-upgrade'): elif not config('action-managed-upgrade'):
if openstack_upgrade_available('cinder-common'): if openstack_upgrade_available('cinder-common'):
status_set('maintenance', 'Running openstack upgrade')
do_openstack_upgrade(configs=CONFIGS) do_openstack_upgrade(configs=CONFIGS)
# NOTE(jamespage) tell any storage-backends we just upgraded # NOTE(jamespage) tell any storage-backends we just upgraded
for rid in relation_ids('storage-backend'): for rid in relation_ids('storage-backend'):
@ -164,6 +179,8 @@ def config_changed():
@hooks.hook('shared-db-relation-joined') @hooks.hook('shared-db-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def db_joined(): def db_joined():
if is_relation_made('pgsql-db'): if is_relation_made('pgsql-db'):
# error, postgresql is used # error, postgresql is used
@ -184,6 +201,8 @@ def db_joined():
@hooks.hook('pgsql-db-relation-joined') @hooks.hook('pgsql-db-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def pgsql_db_joined(): def pgsql_db_joined():
if is_relation_made('shared-db'): if is_relation_made('shared-db'):
# raise error # raise error
@ -197,6 +216,8 @@ def pgsql_db_joined():
@hooks.hook('shared-db-relation-changed') @hooks.hook('shared-db-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def db_changed(): def db_changed():
if 'shared-db' not in CONFIGS.complete_contexts(): if 'shared-db' not in CONFIGS.complete_contexts():
@ -217,6 +238,8 @@ def db_changed():
@hooks.hook('pgsql-db-relation-changed') @hooks.hook('pgsql-db-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def pgsql_db_changed(): def pgsql_db_changed():
if 'pgsql-db' not in CONFIGS.complete_contexts(): if 'pgsql-db' not in CONFIGS.complete_contexts():
@ -229,6 +252,8 @@ def pgsql_db_changed():
@hooks.hook('amqp-relation-joined') @hooks.hook('amqp-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def amqp_joined(relation_id=None): def amqp_joined(relation_id=None):
conf = config() conf = config()
relation_set(relation_id=relation_id, relation_set(relation_id=relation_id,
@ -236,6 +261,8 @@ def amqp_joined(relation_id=None):
@hooks.hook('amqp-relation-changed') @hooks.hook('amqp-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def amqp_changed(): def amqp_changed():
if 'amqp' not in CONFIGS.complete_contexts(): if 'amqp' not in CONFIGS.complete_contexts():
@ -245,6 +272,8 @@ def amqp_changed():
@hooks.hook('amqp-relation-departed') @hooks.hook('amqp-relation-departed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def amqp_departed(): def amqp_departed():
if 'amqp' not in CONFIGS.complete_contexts(): if 'amqp' not in CONFIGS.complete_contexts():
@ -254,6 +283,8 @@ def amqp_departed():
@hooks.hook('identity-service-relation-joined') @hooks.hook('identity-service-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def identity_joined(rid=None): def identity_joined(rid=None):
public_url = '{}:{}/v1/$(tenant_id)s'.format( public_url = '{}:{}/v1/$(tenant_id)s'.format(
canonical_url(CONFIGS, PUBLIC), canonical_url(CONFIGS, PUBLIC),
@ -304,6 +335,8 @@ def identity_joined(rid=None):
@hooks.hook('identity-service-relation-changed') @hooks.hook('identity-service-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def identity_changed(): def identity_changed():
if 'identity-service' not in CONFIGS.complete_contexts(): if 'identity-service' not in CONFIGS.complete_contexts():
@ -314,6 +347,8 @@ def identity_changed():
@hooks.hook('ceph-relation-joined') @hooks.hook('ceph-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def ceph_joined(): def ceph_joined():
if not os.path.isdir('/etc/ceph'): if not os.path.isdir('/etc/ceph'):
os.mkdir('/etc/ceph') os.mkdir('/etc/ceph')
@ -329,6 +364,8 @@ def get_ceph_request():
@hooks.hook('ceph-relation-changed') @hooks.hook('ceph-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def ceph_changed(relation_id=None): def ceph_changed(relation_id=None):
if 'ceph' not in CONFIGS.complete_contexts(): if 'ceph' not in CONFIGS.complete_contexts():
@ -354,6 +391,8 @@ def ceph_changed(relation_id=None):
@hooks.hook('ceph-relation-broken') @hooks.hook('ceph-relation-broken')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def ceph_broken(): def ceph_broken():
service = service_name() service = service_name()
delete_keyring(service=service) delete_keyring(service=service)
@ -391,6 +430,8 @@ def cluster_changed():
@hooks.hook('ha-relation-joined') @hooks.hook('ha-relation-joined')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def ha_joined(relation_id=None): def ha_joined(relation_id=None):
cluster_config = get_hacluster_config() cluster_config = get_hacluster_config()
@ -448,6 +489,8 @@ def ha_joined(relation_id=None):
@hooks.hook('ha-relation-changed') @hooks.hook('ha-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
def ha_changed(): def ha_changed():
clustered = relation_get('clustered') clustered = relation_get('clustered')
if not clustered or clustered in [None, 'None', '']: if not clustered or clustered in [None, 'None', '']:
@ -460,6 +503,8 @@ def ha_changed():
@hooks.hook('image-service-relation-changed') @hooks.hook('image-service-relation-changed')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def image_service_changed(): def image_service_changed():
CONFIGS.write(CINDER_CONF) CONFIGS.write(CINDER_CONF)
@ -470,6 +515,8 @@ def image_service_changed():
'image-service-relation-broken', 'image-service-relation-broken',
'shared-db-relation-broken', 'shared-db-relation-broken',
'pgsql-db-relation-broken') 'pgsql-db-relation-broken')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map(), stopstart=True) @restart_on_change(restart_map(), stopstart=True)
def relation_broken(): def relation_broken():
CONFIGS.write_all() CONFIGS.write_all()
@ -507,6 +554,8 @@ def upgrade_charm():
@hooks.hook('storage-backend-relation-changed') @hooks.hook('storage-backend-relation-changed')
@hooks.hook('storage-backend-relation-broken') @hooks.hook('storage-backend-relation-broken')
@os_workload_status(CONFIGS, REQUIRED_INTERFACES,
charm_func=check_optional_relations)
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def storage_backend(): def storage_backend():
CONFIGS.write(CINDER_CONF) CONFIGS.write(CINDER_CONF)

View File

@ -19,7 +19,8 @@ from charmhelpers.core.hookenv import (
relation_ids, relation_ids,
log, log,
DEBUG, DEBUG,
service_name service_name,
status_get,
) )
from charmhelpers.fetch import ( from charmhelpers.fetch import (
@ -46,6 +47,7 @@ from charmhelpers.core.host import (
from charmhelpers.contrib.openstack.alternatives import install_alternative from charmhelpers.contrib.openstack.alternatives import install_alternative
from charmhelpers.contrib.hahelpers.cluster import ( from charmhelpers.contrib.hahelpers.cluster import (
is_elected_leader, is_elected_leader,
get_hacluster_config,
) )
from charmhelpers.contrib.storage.linux.utils import ( from charmhelpers.contrib.storage.linux.utils import (
@ -81,6 +83,7 @@ from charmhelpers.contrib.openstack.utils import (
git_yaml_value, git_yaml_value,
git_pip_venv_dir, git_pip_venv_dir,
os_release, os_release,
set_os_workload_status,
) )
from charmhelpers.core.decorators import ( from charmhelpers.core.decorators import (
@ -155,6 +158,15 @@ APACHE_SITE_24_CONF = '/etc/apache2/sites-available/' \
TEMPLATES = 'templates/' TEMPLATES = 'templates/'
# The interface is said to be satisfied if anyone of the interfaces in
# the
# list has a complete context.
REQUIRED_INTERFACES = {
'database': ['shared-db', 'pgsql-db'],
'message': ['amqp'],
'identity': ['identity-service'],
}
def ceph_config_file(): def ceph_config_file():
return CHARM_CEPH_CONF.format(service_name()) return CHARM_CEPH_CONF.format(service_name())
@ -799,3 +811,27 @@ def git_post_install(projects_yaml):
def filesystem_mounted(fs): def filesystem_mounted(fs):
return subprocess.call(['grep', '-wqs', fs, '/proc/mounts']) == 0 return subprocess.call(['grep', '-wqs', fs, '/proc/mounts']) == 0
def check_optional_relations(configs):
required_interfaces = {}
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('storage-backend') or relation_ids('ceph'):
required_interfaces['storage-backend'] = ['storage-backend', 'ceph']
if relation_ids('image-service'):
required_interfaces['image'] = ['image-service']
if required_interfaces:
set_os_workload_status(configs, required_interfaces)
return status_get()
else:
return 'unknown', 'No optional relations'

View File

@ -18,6 +18,9 @@ RESTART_MAP = OrderedDict([
('/etc/apache2/sites-available/openstack_https_frontend.conf', ['apache2']) ('/etc/apache2/sites-available/openstack_https_frontend.conf', ['apache2'])
]) ])
patch('charmhelpers.contrib.openstack.utils.set_os_workload_status').start()
patch('charmhelpers.core.hookenv.status_set').start()
def load_config(): def load_config():
'''Walk backwords from __file__ looking for config.yaml, '''Walk backwords from __file__ looking for config.yaml,