838
842
subprocess.check_call(['update-rc.d', 'qemu-hugefsdir', 'defaults'])
841
def check_optional_relations(configs):
842
required_interfaces = {}
845
def get_optional_relations():
846
"""Return a dictionary of optional relations.
848
@returns {relation: relation_name}
850
optional_interfaces = {}
843
851
if relation_ids('ceph'):
844
required_interfaces['storage-backend'] = ['ceph']
852
optional_interfaces['storage-backend'] = ['ceph']
846
853
if relation_ids('neutron-plugin'):
847
required_interfaces['neutron-plugin'] = ['neutron-plugin']
854
optional_interfaces['neutron-plugin'] = ['neutron-plugin']
849
855
if relation_ids('shared-db') or relation_ids('pgsql-db'):
850
required_interfaces['database'] = ['shared-db', 'pgsql-db']
852
if required_interfaces:
853
set_os_workload_status(configs, required_interfaces)
856
return 'unknown', 'No optional relations'
856
optional_interfaces['database'] = ['shared-db', 'pgsql-db']
857
return optional_interfaces
860
def assess_status(configs):
861
"""Assess status of current unit
862
Decides what the state of the unit should be based on the current
864
SIDE EFFECT: calls set_os_workload_status(...) which sets the workload
866
Also calls status_set(...) directly if paused state isn't complete.
867
@param configs: a templating.OSConfigRenderer() object
868
@returns None - this function is executed for its side-effect
870
assess_status_func(configs)()
873
def assess_status_func(configs):
874
"""Helper function to create the function that will assess_status() for
876
Uses charmhelpers.contrib.openstack.utils.make_assess_status_func() to
877
create the appropriate status function and then returns it.
878
Used directly by assess_status() and also for pausing and resuming
881
NOTE(ajkavanagh) ports are not checked due to race hazards with services
882
that don't behave sychronously w.r.t their service scripts. e.g.
884
@param configs: a templating.OSConfigRenderer() object
885
@return f() -> None : a function that assesses the unit's workload status
887
required_interfaces = REQUIRED_INTERFACES.copy()
888
required_interfaces.update(get_optional_relations())
889
return make_assess_status_func(
890
configs, required_interfaces,
891
services=services(), ports=None)
894
def pause_unit_helper(configs):
895
"""Helper function to pause a unit, and then call assess_status(...) in
896
effect, so that the status is correctly updated.
897
Uses charmhelpers.contrib.openstack.utils.pause_unit() to do the work.
898
@param configs: a templating.OSConfigRenderer() object
899
@returns None - this function is executed for its side-effect
901
_pause_resume_helper(pause_unit, configs)
904
def resume_unit_helper(configs):
905
"""Helper function to resume a unit, and then call assess_status(...) in
906
effect, so that the status is correctly updated.
907
Uses charmhelpers.contrib.openstack.utils.resume_unit() to do the work.
908
@param configs: a templating.OSConfigRenderer() object
909
@returns None - this function is executed for its side-effect
911
_pause_resume_helper(resume_unit, configs)
914
def _pause_resume_helper(f, configs):
915
"""Helper function that uses the make_assess_status_func(...) from
916
charmhelpers.contrib.openstack.utils to create an assess_status(...)
917
function that can be used with the pause/resume of the unit
918
@param f: the function to be used with the assess_status(...) function
919
@returns None - this function is executed for its side-effect
921
# TODO(ajkavanagh) - ports= has been left off because of the race hazard
922
# that exists due to service_start()
923
f(assess_status_func(configs),