Skip to content

Commit

Permalink
Synced new version of charm-helpers from:
Browse files Browse the repository at this point in the history
lp:~ajkavanagh/charm-helpers/add-service-checks-lp1524388
Added call to services() and determined_ports() for the assess_status()
call.
  • Loading branch information
ajkavanagh committed Feb 12, 2016
1 parent 873d96b commit bb09ba2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
15 changes: 11 additions & 4 deletions charmhelpers/contrib/openstack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,21 @@ def set_os_workload_status(configs, required_interfaces, charm_func=None, servic
# if we're passed the dict() then just grab the values as a list.
if isinstance(services, dict):
services = services.values()
_s = [s['service'] for s in services]
# either extract the list of services from the dictionary, or if
# it is a simple string, use that. i.e. works with mixed lists.
_s = []
for s in services:
if isinstance(s, dict) and 'service' in s:
_s.append(s['service'])
if isinstance(s, str):
_s.append(s)
services_running = [service_running(s) for s in _s]
if not all(services_running):
not_running = [s for s, running in zip(_s, services_running)
if not running]
message = ("Services not running that should be: {}"
.format(", ".join(not_running)))
state = 'unknown'
state = 'blocked'
# also verify that the ports that should be open are open
# NB, that ServiceManager objects only OPTIONALLY have ports
port_map = OrderedDict([(s['service'], s['ports'])
Expand All @@ -965,7 +972,7 @@ def set_os_workload_status(configs, required_interfaces, charm_func=None, servic
service,
", ".join([str(v) for v in ports]))
for service, ports in map_not_open.items()])))
state = 'unknown'
state = 'blocked'

if ports is not None and state == 'active':
# and we can also check ports which we don't know the service for
Expand All @@ -975,7 +982,7 @@ def set_os_workload_status(configs, required_interfaces, charm_func=None, servic
"Ports which should be open, but are not: {}"
.format(", ".join([str(p) for p, v in zip(ports, ports_open)
if not v])))
state = 'unknown'
state = 'blocked'

# Set to active if all requirements have been met
if state == 'active':
Expand Down
3 changes: 2 additions & 1 deletion hooks/keystone_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1841,4 +1841,5 @@ def assess_status(configs):

# set the status according to the current state of the contexts
set_os_workload_status(
configs, REQUIRED_INTERFACES, charm_func=check_optional_relations)
configs, REQUIRED_INTERFACES, charm_func=check_optional_relations,
services=services(), ports=determine_ports())
4 changes: 3 additions & 1 deletion unit_tests/test_keystone_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,4 +762,6 @@ def test_assess_status(self, status_set, is_paused):
set_os_workload_status.assert_called_with(
"TEST CONFIG",
utils.REQUIRED_INTERFACES,
charm_func=utils.check_optional_relations)
charm_func=utils.check_optional_relations,
services=['haproxy', 'keystone', 'apache2'],
ports=[5000, 35357])

0 comments on commit bb09ba2

Please sign in to comment.