def _assess_status(self):
"""Assess the status of the unit and set the status and a useful
message as appropriate.
The 3 checks are:
1. Check if the unit has been paused (using
os_utils.is_unit_paused_set().
2. Do a custom_assess_status_check() check.
3. Check if the interfaces are all present (using the states that are
set by each interface as it comes 'live'.
4. Check that services that should be running are running.
Each sub-function determins what checks are taking place.
If custom assess_status() functionality is required then the derived
class should override any of the 4 check functions to alter the
behaviour as required.
Note that if ports are NOT to be checked, then the derived class should
override :meth:`ports_to_check()` and return an empty list.
SIDE EFFECT: this function calls status_set(state, message) to set the
workload status in juju.
"""
# set the application version when we set the status (always)
# NOTE(tinwood) this is not, strictly speaking, good code organisation,
# as the 'application_version' property is in the classes.py file.
# However, as this is ALWAYS a mixin on that class, we can get away
# with this.
hookenv.application_version_set(self.application_version)
for f in [self.check_if_paused,
self.custom_assess_status_check,
self.check_interfaces,
self.check_services_running]:
state, message = f()
if state is not None:
hookenv.status_set(state, message)
return
# No state was particularly set, so assume the unit is active
hookenv.status_set('active', 'Unit is ready')
评论列表
文章目录