Support action managed upgrades

Add action for running OpenStack upgrades. This enables a service
to be upgraded one unit at a time.

Depends-On: I33947c474b70c5cd4722688567ba55370b805f65
Change-Id: Ic290ac6fecff0eb9d0efd3fc8ac3f6ea923ee268
This commit is contained in:
Liam Young 2018-11-04 09:59:54 +00:00
parent 85c216c8a5
commit 9938f45e9f
4 changed files with 75 additions and 0 deletions

4
actions.yaml Normal file
View File

@ -0,0 +1,4 @@
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 @@
os_principle_actions.py

60
actions/os_principle_actions.py Executable file
View File

@ -0,0 +1,60 @@
#!/usr/bin/env python3
# Copyright 2016 Canonical Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import sys
# Load modules from $CHARM_DIR/lib
sys.path.append('lib')
from charms.layer import basic
basic.bootstrap_charm_deps()
import charmhelpers.core.hookenv as hookenv
import charms_openstack.bus
import charms_openstack.charm
charms_openstack.bus.discover()
def openstack_upgrade_action(*args):
"""Run the resume action."""
with charms_openstack.charm.provide_charm_instance() as charm_instance:
charm_instance.run_upgrade()
charm_instance._assess_status()
# Actions to function mapping, to allow for illegal python action names that
# can map to a python function.
ACTIONS = {
"openstack-upgrade": openstack_upgrade_action,
}
def main(args):
action_name = os.path.basename(args[0])
try:
action = ACTIONS[action_name]
except KeyError:
return "Action %s undefined" % action_name
else:
try:
action(args)
except Exception as e:
hookenv.action_fail(str(e))
if __name__ == "__main__":
sys.exit(main(sys.argv))

View File

@ -23,3 +23,13 @@ options:
Note that updating this setting to a source that is known to
provide a later version of OpenStack will trigger a software
upgrade.
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.