[ddellav,r=corey.bryant] Action-managed upgrade support

This commit is contained in:
Corey Bryant 2015-10-09 11:02:40 -04:00
commit 755227724d
8 changed files with 119 additions and 5 deletions

View File

@ -1,2 +1,4 @@
git-reinstall:
description: Reinstall nova-compute 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

32
actions/openstack_upgrade.py Executable file
View File

@ -0,0 +1,32 @@
#!/usr/bin/python
import sys
sys.path.append('hooks/')
from charmhelpers.contrib.openstack.utils import (
do_action_openstack_upgrade,
)
from nova_compute_utils import do_openstack_upgrade
from nova_compute_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('nova-common',
do_openstack_upgrade,
CONFIGS)):
config_changed()
if __name__ == '__main__':
openstack_upgrade()

View File

@ -281,3 +281,13 @@ options:
description: |
The pecentage of system memory to use for hugepages eg '10%' or the total
number of 2M hugepages - eg "1024".
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

@ -117,10 +117,10 @@ def config_changed():
if config_value_changed('openstack-origin-git'):
status_set('maintenance', 'Running Git install')
git_install(config('openstack-origin-git'))
else:
elif not config('action-managed-upgrade'):
if openstack_upgrade_available('nova-common'):
status_set('maintenance', 'Running openstack upgrade')
CONFIGS = do_openstack_upgrade()
do_openstack_upgrade(CONFIGS)
sysctl_dict = config('sysctl')
if sysctl_dict:

View File

@ -537,7 +537,7 @@ def import_authorized_keys(user='root', prefix=None):
_keys.write('{}\n'.format(authorized_keys[index]))
def do_openstack_upgrade():
def do_openstack_upgrade(configs):
# NOTE(jamespage) horrible hack to make utils forget a cached value
import charmhelpers.contrib.openstack.utils as utils
utils.os_rel = None
@ -557,10 +557,8 @@ def do_openstack_upgrade():
apt_install(determine_packages(), fatal=True)
# Regenerate configs in full for new release
configs = register_configs()
configs.write_all()
[service_restart(s) for s in services()]
return configs
def import_keystone_ca_cert():

View File

@ -0,0 +1,62 @@
from mock import patch
import os
os.environ['JUJU_UNIT_NAME'] = 'nova_compute'
with patch('charmhelpers.core.hookenv.config') as config:
config.return_value = 'nova'
import nova_compute_utils as utils # noqa
with patch('nova_compute_utils.restart_map'):
with patch('nova_compute_utils.register_configs'):
import openstack_upgrade
from test_utils import (
CharmTestCase
)
TO_PATCH = [
'config_changed',
'do_openstack_upgrade'
]
class TestNovaComputeUpgradeActions(CharmTestCase):
def setUp(self):
super(TestNovaComputeUpgradeActions, 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')
@patch('charmhelpers.contrib.openstack.utils.juju_log')
def test_openstack_upgrade_true(self, log, 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') # noqa
@patch('charmhelpers.contrib.openstack.utils.openstack_upgrade_available') # noqa
@patch('charmhelpers.contrib.openstack.utils.juju_log')
def test_openstack_upgrade_false(self, log, 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

@ -115,6 +115,15 @@ class NovaComputeRelationsTests(CharmTestCase):
hooks.config_changed()
self.assertTrue(self.do_openstack_upgrade.called)
@patch.object(hooks, 'git_install_requested')
def test_config_changed_with_openstack_upgrade_action(self, git_requested):
git_requested.return_value = False
self.openstack_upgrade_available.return_value = True
self.test_config.set('action-managed-upgrade', True)
hooks.config_changed()
self.assertFalse(self.do_openstack_upgrade.called)
@patch.object(hooks, 'compute_joined')
def test_config_changed_with_migration(self, compute_joined):
self.git_install_requested.return_value = False