~corey.bryant/charms/trusty/swift-storage/mitaka-ch-sync

« back to all changes in this revision

Viewing changes to charmhelpers/contrib/openstack/utils.py

  • Committer: james.page at ubuntu
  • Date: 2015-09-23 13:52:50 UTC
  • mfrom: (81.2.1 swift-storage)
  • Revision ID: james.page@ubuntu.com-20150923135250-92ifjs3on3zd6npp
[thedac,r=james-page] Add action to manage upgrades

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import re
26
26
 
27
27
import six
 
28
import traceback
28
29
import yaml
29
30
 
30
31
from charmhelpers.contrib.network import ip
34
35
)
35
36
 
36
37
from charmhelpers.core.hookenv import (
 
38
    action_fail,
 
39
    action_set,
37
40
    config,
38
41
    log as juju_log,
39
42
    charm_dir,
749
752
        return projects[key]
750
753
 
751
754
    return None
 
755
 
 
756
 
 
757
def do_action_openstack_upgrade(package, upgrade_callback, configs):
 
758
    """Perform action-managed OpenStack upgrade.
 
759
 
 
760
    Upgrades packages to the configured openstack-origin version and sets
 
761
    the corresponding action status as a result.
 
762
 
 
763
    If the charm was installed from source we cannot upgrade it.
 
764
    For backwards compatibility a config flag (action-managed-upgrade) must
 
765
    be set for this code to run, otherwise a full service level upgrade will
 
766
    fire on config-changed.
 
767
 
 
768
    @param package: package name for determining if upgrade available
 
769
    @param upgrade_callback: function callback to charm's upgrade function
 
770
    @param configs: templating object derived from OSConfigRenderer class
 
771
 
 
772
    @return: True if upgrade successful; False if upgrade failed or skipped
 
773
    """
 
774
    ret = False
 
775
 
 
776
    if git_install_requested():
 
777
        action_set({'outcome': 'installed from source, skipped upgrade.'})
 
778
    else:
 
779
        if openstack_upgrade_available(package):
 
780
            if config('action-managed-upgrade'):
 
781
                juju_log('Upgrading OpenStack release')
 
782
 
 
783
                try:
 
784
                    upgrade_callback(configs=configs)
 
785
                    action_set({'outcome': 'success, upgrade completed.'})
 
786
                    ret = True
 
787
                except:
 
788
                    action_set({'outcome': 'upgrade failed, see traceback.'})
 
789
                    action_set({'traceback': traceback.format_exc()})
 
790
                    action_fail('do_openstack_upgrade resulted in an '
 
791
                                'unexpected error')
 
792
            else:
 
793
                action_set({'outcome': 'action-managed-upgrade config is '
 
794
                                       'False, skipped upgrade.'})
 
795
        else:
 
796
            action_set({'outcome': 'no upgrade available.'})
 
797
 
 
798
    return ret