~openstack-charmers-next/charms/precise/nova-compute/trunk

« back to all changes in this revision

Viewing changes to hooks/nova_compute_utils.py

  • Committer: Gerrit Code Review
  • Author(s): Jenkins
  • Date: 2016-04-06 06:43:55 UTC
  • mfrom: (211.1.1 trunk)
  • Revision ID: review@openstack.org-20160406064355-hhfnwzmint2jmju2
Merge "Enhanced pause/resume for maintenance mode"

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
    relation_get,
38
38
    DEBUG,
39
39
    INFO,
40
 
    status_get,
41
40
)
42
41
 
43
42
from charmhelpers.core.templating import render
55
54
    git_pip_venv_dir,
56
55
    git_yaml_value,
57
56
    os_release,
58
 
    set_os_workload_status,
 
57
    is_unit_paused_set,
 
58
    make_assess_status_func,
 
59
    pause_unit,
 
60
    resume_unit,
59
61
)
60
62
 
61
63
from charmhelpers.contrib.python.packages import (
539
541
 
540
542
    configs.set_release(openstack_release=new_os_rel)
541
543
    configs.write_all()
542
 
    [service_restart(s) for s in services()]
 
544
    if not is_unit_paused_set():
 
545
        for s in services():
 
546
            service_restart(s)
543
547
 
544
548
 
545
549
def import_keystone_ca_cert():
838
842
        subprocess.check_call(['update-rc.d', 'qemu-hugefsdir', 'defaults'])
839
843
 
840
844
 
841
 
def check_optional_relations(configs):
842
 
    required_interfaces = {}
 
845
def get_optional_relations():
 
846
    """Return a dictionary of optional relations.
 
847
 
 
848
    @returns {relation: relation_name}
 
849
    """
 
850
    optional_interfaces = {}
843
851
    if relation_ids('ceph'):
844
 
        required_interfaces['storage-backend'] = ['ceph']
845
 
 
 
852
        optional_interfaces['storage-backend'] = ['ceph']
846
853
    if relation_ids('neutron-plugin'):
847
 
        required_interfaces['neutron-plugin'] = ['neutron-plugin']
848
 
 
 
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']
851
 
 
852
 
    if required_interfaces:
853
 
        set_os_workload_status(configs, required_interfaces)
854
 
        return status_get()
855
 
    else:
856
 
        return 'unknown', 'No optional relations'
 
856
        optional_interfaces['database'] = ['shared-db', 'pgsql-db']
 
857
    return optional_interfaces
 
858
 
 
859
 
 
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
 
863
    configuration.
 
864
    SIDE EFFECT: calls set_os_workload_status(...) which sets the workload
 
865
    status of the unit.
 
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
 
869
    """
 
870
    assess_status_func(configs)()
 
871
 
 
872
 
 
873
def assess_status_func(configs):
 
874
    """Helper function to create the function that will assess_status() for
 
875
    the unit.
 
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
 
879
    the unit.
 
880
 
 
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.
 
883
    apache2.
 
884
    @param configs: a templating.OSConfigRenderer() object
 
885
    @return f() -> None : a function that assesses the unit's workload status
 
886
    """
 
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)
 
892
 
 
893
 
 
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
 
900
    """
 
901
    _pause_resume_helper(pause_unit, configs)
 
902
 
 
903
 
 
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
 
910
    """
 
911
    _pause_resume_helper(resume_unit, configs)
 
912
 
 
913
 
 
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
 
920
    """
 
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),
 
924
      services=services(),
 
925
      ports=None)