From f7b8f9b66e3eb20743728a792d6f5125c17132bd Mon Sep 17 00:00:00 2001 From: Liam Young Date: Mon, 16 Aug 2021 13:20:07 +0000 Subject: [PATCH] Add update-trilio action Add update-trilio action which can be run after a Trilio upgrade. Trilio sometimes updates packages in package repositiories that require DB migrations or config file changes. Since these package updates are not applied by the charm as they would be by changing the openstack-origin or triliovault-pkg-source the charm has no event to react to to automatically perform the post package upgrade actions. This change adds an action `update-trilio` which can be run to apply the changes. Change-Id: I60034c9a7b14307835776a30b753905aab87aa75 --- src/actions.yaml | 4 +++ src/actions/actions.py | 64 +++++++++++++++++++++++++++++++++++++++ src/actions/update-trilio | 1 + 3 files changed, 69 insertions(+) create mode 100644 src/actions.yaml create mode 100755 src/actions/actions.py create mode 120000 src/actions/update-trilio diff --git a/src/actions.yaml b/src/actions.yaml new file mode 100644 index 0000000..7576e22 --- /dev/null +++ b/src/actions.yaml @@ -0,0 +1,4 @@ +update-trilio: + description: | + Update the trilio packages and run post-update steps such as rerender + configuration files and run any upgrade tasks such as database migrations. diff --git a/src/actions/actions.py b/src/actions/actions.py new file mode 100755 index 0000000..553dd81 --- /dev/null +++ b/src/actions/actions.py @@ -0,0 +1,64 @@ +#!/usr/local/sbin/charm-env python3 +# Copyright 2018,2020 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() +basic.init_config_states() + +import charmhelpers.core.hookenv as hookenv + +import charms_openstack.charm + +# import the trilio module to get the charm definitions created. +import charm.openstack.trilio_horizon_plugin # noqa + + +def update_trilio(*args): + """Run setup after Trilio upgrade. + """ + with charms_openstack.charm.provide_charm_instance() as trilio_charm: + trilio_charm.run_trilio_upgrade([]) + trilio_charm._assess_status() + + +# Actions to function mapping, to allow for illegal python action names that +# can map to a python function. +ACTIONS = { + "update-trilio": update_trilio, +} + + +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.function_fail(str(e)) + + +if __name__ == "__main__": + sys.exit(main(sys.argv)) diff --git a/src/actions/update-trilio b/src/actions/update-trilio new file mode 120000 index 0000000..405a394 --- /dev/null +++ b/src/actions/update-trilio @@ -0,0 +1 @@ +actions.py \ No newline at end of file