[thedac,r=james-page] Add support for action managed upgrade of openstack.

This commit is contained in:
James Page 2015-09-24 17:22:09 +01:00
commit 091e3c89bf
9 changed files with 159 additions and 5 deletions

View File

@ -1,2 +1,4 @@
git-reinstall:
description: Reinstall quantum-gateway from the openstack-origin-git repositories.
openstack-upgrade:
description: Perform openstack upgrades. Config option action-managed-upgrade must be set to True.

1
actions/openstack-upgrade Symbolic link
View File

@ -0,0 +1 @@
openstack_upgrade.py

36
actions/openstack_upgrade.py Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/python
import sys
sys.path.append('hooks/')
from charmhelpers.contrib.openstack.utils import (
do_action_openstack_upgrade,
)
from neutron_utils import (
do_openstack_upgrade,
get_common_package,
)
from neutron_hooks import (
config_changed,
CONFIGS,
)
def openstack_upgrade():
"""Upgrade packages to config-set Openstack version.
If the charm was installed from source we cannot upgrade it.
For backwards compatibility a config flag must be set for this
code to run, otherwise a full service level upgrade will fire
on config-changed."""
if do_action_openstack_upgrade(get_common_package(),
do_openstack_upgrade,
CONFIGS):
config_changed()
if __name__ == '__main__':
openstack_upgrade()

View File

@ -216,3 +216,13 @@ options:
description: |
Default multicast port number that will be used to communicate between
HA Cluster nodes.
action-managed-upgrade:
type: boolean
default: False
description: |
If True enables openstack upgrades for this charm via juju actions.
You will still need to set openstack-origin to the new repository but
instead of an upgrade running automatically across all units, it will
wait for you to execute the openstack-upgrade action for this charm on
each unit. If False it will revert to existing behavior of upgrading
all units on config change.

View File

@ -25,6 +25,7 @@ import sys
import re
import six
import traceback
import yaml
from charmhelpers.contrib.network import ip
@ -34,6 +35,8 @@ from charmhelpers.core import (
)
from charmhelpers.core.hookenv import (
action_fail,
action_set,
config,
log as juju_log,
charm_dir,
@ -114,6 +117,7 @@ SWIFT_CODENAMES = OrderedDict([
('2.2.1', 'kilo'),
('2.2.2', 'kilo'),
('2.3.0', 'liberty'),
('2.4.0', 'liberty'),
])
# >= Liberty version->codename mapping
@ -142,6 +146,9 @@ PACKAGE_CODENAMES = {
'glance-common': OrderedDict([
('11.0.0', 'liberty'),
]),
'openstack-dashboard': OrderedDict([
('8.0.0', 'liberty'),
]),
}
DEFAULT_LOOPBACK_SIZE = '5G'
@ -745,3 +752,47 @@ def git_yaml_value(projects_yaml, key):
return projects[key]
return None
def do_action_openstack_upgrade(package, upgrade_callback, configs):
"""Perform action-managed OpenStack upgrade.
Upgrades packages to the configured openstack-origin version and sets
the corresponding action status as a result.
If the charm was installed from source we cannot upgrade it.
For backwards compatibility a config flag (action-managed-upgrade) must
be set for this code to run, otherwise a full service level upgrade will
fire on config-changed.
@param package: package name for determining if upgrade available
@param upgrade_callback: function callback to charm's upgrade function
@param configs: templating object derived from OSConfigRenderer class
@return: True if upgrade successful; False if upgrade failed or skipped
"""
ret = False
if git_install_requested():
action_set({'outcome': 'installed from source, skipped upgrade.'})
else:
if openstack_upgrade_available(package):
if config('action-managed-upgrade'):
juju_log('Upgrading OpenStack release')
try:
upgrade_callback(configs=configs)
action_set({'outcome': 'success, upgrade completed.'})
ret = True
except:
action_set({'outcome': 'upgrade failed, see traceback.'})
action_set({'traceback': traceback.format_exc()})
action_fail('do_openstack_upgrade resulted in an '
'unexpected error')
else:
action_set({'outcome': 'action-managed-upgrade config is '
'False, skipped upgrade.'})
else:
action_set({'outcome': 'no upgrade available.'})
return ret

View File

@ -102,10 +102,9 @@ def config_changed():
if config_value_changed('openstack-origin-git'):
git_install(config('openstack-origin-git'))
CONFIGS.write_all()
else:
elif not config('action-managed-upgrade'):
if openstack_upgrade_available(get_common_package()):
do_openstack_upgrade()
CONFIGS.write_all()
do_openstack_upgrade(CONFIGS)
update_nrpe_config()

View File

@ -652,7 +652,7 @@ def services():
return list(set(_services))
def do_openstack_upgrade():
def do_openstack_upgrade(configs):
"""
Perform an upgrade. Takes care of upgrading packages, rewriting
configs, database migrations and potentially any other post-upgrade
@ -672,6 +672,7 @@ def do_openstack_upgrade():
fatal=True, dist=True)
apt_install(get_early_packages(), fatal=True)
apt_install(get_packages(), fatal=True)
configs.write_all()
def configure_ovs():

View File

@ -0,0 +1,53 @@
from mock import patch
import os
os.environ['JUJU_UNIT_NAME'] = 'neutron-gateway'
with patch('neutron_utils.register_configs') as register_configs:
import openstack_upgrade
from test_utils import (
CharmTestCase
)
TO_PATCH = [
'do_openstack_upgrade',
'config_changed',
]
class TestNeutronGWUpgradeActions(CharmTestCase):
def setUp(self):
super(TestNeutronGWUpgradeActions, self).setUp(openstack_upgrade,
TO_PATCH)
@patch('charmhelpers.contrib.openstack.utils.config')
@patch('charmhelpers.contrib.openstack.utils.action_set')
@patch('charmhelpers.contrib.openstack.utils.git_install_requested')
@patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available')
def test_openstack_upgrade_true(self, upgrade_avail, git_requested,
action_set, config):
git_requested.return_value = False
upgrade_avail.return_value = True
config.return_value = True
openstack_upgrade.openstack_upgrade()
self.assertTrue(self.do_openstack_upgrade.called)
self.assertTrue(self.config_changed.called)
@patch('charmhelpers.contrib.openstack.utils.config')
@patch('charmhelpers.contrib.openstack.utils.action_set')
@patch('charmhelpers.contrib.openstack.utils.git_install_requested')
@patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available')
def test_openstack_upgrade_false(self, upgrade_avail, git_requested,
action_set, config):
git_requested.return_value = False
upgrade_avail.return_value = True
config.return_value = False
openstack_upgrade.openstack_upgrade()
self.assertFalse(self.do_openstack_upgrade.called)
self.assertFalse(self.config_changed.called)

View File

@ -244,7 +244,8 @@ class TestQuantumUtils(CharmTestCase):
self.test_config.set('openstack-origin', 'cloud:precise-havana')
self.test_config.set('plugin', 'ovs')
self.get_os_codename_install_source.return_value = 'havana'
neutron_utils.do_openstack_upgrade()
configs = neutron_utils.register_configs()
neutron_utils.do_openstack_upgrade(configs)
self.assertTrue(self.log.called)
self.apt_update.assert_called_with(fatal=True)
dpkg_opts = [