diff --git a/Makefile b/Makefile index 15069ff..f9f3c33 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ PYTHON := /usr/bin/env python lint: @flake8 --exclude hooks/charmhelpers,tests/charmhelpers \ - hooks unit_tests tests + hooks unit_tests tests actions @charm proof test: diff --git a/actions/actions.py b/actions/actions.py index 9b8b6aa..7912881 100755 --- a/actions/actions.py +++ b/actions/actions.py @@ -5,7 +5,9 @@ import sys from charmhelpers.core.host import service_pause, service_resume from charmhelpers.core.hookenv import action_fail, status_set -from ceilometer_utils import CEILOMETER_SERVICES +from charmhelpers.core.unitdata import kv +from ceilometer_utils import CEILOMETER_SERVICES, assess_status +from ceilometer_hooks import CONFIGS def pause(args): @@ -16,8 +18,15 @@ def pause(args): for service in CEILOMETER_SERVICES: if not service_pause(service): raise Exception("Failed to %s." % service) + + db = kv() + db.set('unit-paused', True) + db.update() + status_set( - "maintenance", "Paused. Use 'resume' action to resume normal service.") + "maintenance", + "Unit paused - use 'resume' action to resume normal service") + def resume(args): """Resume the Ceilometer services. @@ -26,7 +35,12 @@ def resume(args): for service in CEILOMETER_SERVICES: if not service_resume(service): raise Exception("Failed to resume %s." % service) - status_set("active", "") + + db = kv() + db.set('unit-paused', False) + db.update() + + assess_status(CONFIGS) # A dictionary of all the defined actions to callables (which take @@ -49,4 +63,3 @@ def main(args): if __name__ == "__main__": sys.exit(main(sys.argv)) - diff --git a/actions/openstack_upgrade.py b/actions/openstack_upgrade.py index 45c3e72..cb04493 100755 --- a/actions/openstack_upgrade.py +++ b/actions/openstack_upgrade.py @@ -1,6 +1,5 @@ #!/usr/bin/python import sys -import uuid sys.path.append('hooks/') diff --git a/ceilometer_utils.py b/ceilometer_utils.py index 4b82b73..ebe4cc3 100644 --- a/ceilometer_utils.py +++ b/ceilometer_utils.py @@ -17,9 +17,11 @@ from ceilometer_contexts import ( from charmhelpers.contrib.openstack.utils import ( get_os_codename_package, get_os_codename_install_source, - configure_installation_source + configure_installation_source, + set_os_workload_status, ) -from charmhelpers.core.hookenv import config, log +from charmhelpers.core.hookenv import config, log, status_set +from charmhelpers.core.unitdata import kv from charmhelpers.fetch import apt_update, apt_install, apt_upgrade from copy import deepcopy @@ -229,3 +231,22 @@ def set_shared_secret(secret): """ with open(SHARED_SECRET, 'w') as secret_file: secret_file.write(secret) + + +def is_paused(): + '''Determine if current unit is in a paused state''' + db = kv() + if db.get('unit-paused'): + return True + else: + return False + + +def assess_status(configs): + if is_paused(): + status_set("maintenance", + "Unit paused - use 'resume' action " + "to resume normal service") + return + + set_os_workload_status(configs, REQUIRED_INTERFACES) diff --git a/hooks/ceilometer_hooks.py b/hooks/ceilometer_hooks.py index 4e66486..9a13529 100755 --- a/hooks/ceilometer_hooks.py +++ b/hooks/ceilometer_hooks.py @@ -28,7 +28,6 @@ from charmhelpers.core.host import ( from charmhelpers.contrib.openstack.utils import ( configure_installation_source, openstack_upgrade_available, - set_os_workload_status, ) from ceilometer_utils import ( get_packages, @@ -42,7 +41,7 @@ from ceilometer_utils import ( get_shared_secret, do_openstack_upgrade, set_shared_secret, - REQUIRED_INTERFACES, + assess_status, ) from ceilometer_contexts import CEILOMETER_PORT from charmhelpers.contrib.openstack.ip import ( @@ -339,4 +338,4 @@ if __name__ == '__main__': hooks.execute(sys.argv) except UnregisteredHookError as e: log('Unknown hook {} - skipping.'.format(e)) - set_os_workload_status(CONFIGS, REQUIRED_INTERFACES) \ No newline at end of file + assess_status(CONFIGS) diff --git a/tests/basic_deployment.py b/tests/basic_deployment.py index 1caff7a..d132cb0 100644 --- a/tests/basic_deployment.py +++ b/tests/basic_deployment.py @@ -604,7 +604,7 @@ class CeilometerBasicDeployment(OpenStackAmuletDeployment): unit_name = "ceilometer/0" unit = self.d.sentry.unit[unit_name] - assert u.status_get(unit)[0] == "unknown" + assert u.status_get(unit)[0] == "active" action_id = self._run_action(unit_name, "pause") assert self._wait_on_action(action_id), "Pause action failed." diff --git a/unit_tests/test_actions_openstack_upgrade.py b/unit_tests/test_actions_openstack_upgrade.py index 44fc58d..e19acab 100644 --- a/unit_tests/test_actions_openstack_upgrade.py +++ b/unit_tests/test_actions_openstack_upgrade.py @@ -13,7 +13,6 @@ from test_utils import ( TO_PATCH = [ 'config_changed', 'do_openstack_upgrade', - 'uuid' ]