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: I52abfa8091673f20c8c5cc1fffd7ad5d17a60820
This commit is contained in:
parent
d3c003dfd1
commit
c9af173206
|
@ -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.
|
|
@ -0,0 +1,70 @@
|
|||
#!/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.reactive as reactive
|
||||
|
||||
import charms_openstack.charm
|
||||
|
||||
# import the trilio module to get the charm definitions created.
|
||||
import charm.openstack.dmapi # noqa
|
||||
|
||||
|
||||
def update_trilio(*args):
|
||||
"""Run setup after Trilio upgrade.
|
||||
"""
|
||||
with charms_openstack.charm.provide_charm_instance() as trilio_charm:
|
||||
interfaces = ["shared-db", "identity-service", "amqp"]
|
||||
endpoints = [
|
||||
reactive.relations.endpoint_from_flag("{}.available".format(i))
|
||||
for i in interfaces]
|
||||
trilio_charm.run_trilio_upgrade(endpoints)
|
||||
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))
|
|
@ -0,0 +1 @@
|
|||
actions.py
|
Loading…
Reference in New Issue