Rework assess status to take action managed status into account
This commit is contained in:
parent
69478a8460
commit
ba7531c0ad
2
Makefile
2
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:
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#!/usr/bin/python
|
||||
import sys
|
||||
import uuid
|
||||
|
||||
sys.path.append('hooks/')
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
assess_status(CONFIGS)
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -13,7 +13,6 @@ from test_utils import (
|
|||
TO_PATCH = [
|
||||
'config_changed',
|
||||
'do_openstack_upgrade',
|
||||
'uuid'
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue