From 3039255e9604af3529c64db930f3cebf178a3dd0 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Fri, 9 Apr 2021 12:58:11 +0000 Subject: [PATCH] Implementation of deferred restarts Add deferred restart actions and config. Change-Id: I34ceac5b62e079259a25a11edcedc30f943888d7 --- src/actions.yaml | 27 +++++++++++++++++++ src/actions/restart-services | 26 ++++++++++++++++++ src/actions/run-deferred-hooks | 26 ++++++++++++++++++ src/actions/show-deferred-events | 26 ++++++++++++++++++ src/config.yaml | 7 +++++ src/lib/charm/openstack/ovn_chassis.py | 6 +++-- src/reactive/ovn_chassis_handlers.py | 7 +++++ src/tests/tests.yaml | 1 + .../test_reactive_ovn_chassis_handlers.py | 1 + 9 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 src/actions.yaml create mode 100755 src/actions/restart-services create mode 100755 src/actions/run-deferred-hooks create mode 100755 src/actions/show-deferred-events diff --git a/src/actions.yaml b/src/actions.yaml new file mode 100644 index 0000000..54c58d7 --- /dev/null +++ b/src/actions.yaml @@ -0,0 +1,27 @@ +restart-services: + description: | + Restarts services this charm manages. + params: + deferred-only: + type: boolean + default: false + description: | + Restart all deferred services. + services: + type: string + default: "" + description: | + List of services to restart. + run-hooks: + type: boolean + default: true + description: | + Run any hooks which have been deferred. +run-deferred-hooks: + description: | + Run deferable hooks and restart services. + . + NOTE: Service will be restarted as needed irrespective of enable-auto-restarts +show-deferred-events: + descrpition: | + Show the outstanding restarts diff --git a/src/actions/restart-services b/src/actions/restart-services new file mode 100755 index 0000000..09e534c --- /dev/null +++ b/src/actions/restart-services @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# Copyright 2021 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 sys + + +sys.path.append('actions') + + +import os_deferred_event_actions + + +if __name__ == "__main__": + sys.exit(os_deferred_event_actions.main(sys.argv)) diff --git a/src/actions/run-deferred-hooks b/src/actions/run-deferred-hooks new file mode 100755 index 0000000..09e534c --- /dev/null +++ b/src/actions/run-deferred-hooks @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# Copyright 2021 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 sys + + +sys.path.append('actions') + + +import os_deferred_event_actions + + +if __name__ == "__main__": + sys.exit(os_deferred_event_actions.main(sys.argv)) diff --git a/src/actions/show-deferred-events b/src/actions/show-deferred-events new file mode 100755 index 0000000..09e534c --- /dev/null +++ b/src/actions/show-deferred-events @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +# Copyright 2021 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 sys + + +sys.path.append('actions') + + +import os_deferred_event_actions + + +if __name__ == "__main__": + sys.exit(os_deferred_event_actions.main(sys.argv)) diff --git a/src/config.yaml b/src/config.yaml index fdc7e0e..9f2671c 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -14,3 +14,10 @@ options: a hypervisor hosts an instance in a subnet, so the volume should be relatively low. If you set this number too high you may put an unnecessary toll on the OVN Southbound database server. + enable-auto-restarts: + type: boolean + default: True + description: | + Allow the charm and packages to restart services automatically when + required. + diff --git a/src/lib/charm/openstack/ovn_chassis.py b/src/lib/charm/openstack/ovn_chassis.py index cfacbbb..91befb4 100644 --- a/src/lib/charm/openstack/ovn_chassis.py +++ b/src/lib/charm/openstack/ovn_chassis.py @@ -20,7 +20,8 @@ import charms.ovn_charm charm.use_defaults('charm.default-select-release') -class TrainOVNChassisCharm(charms.ovn_charm.BaseTrainOVNChassisCharm): +class TrainOVNChassisCharm(charms.ovn_charm.DeferredEventMixin, + charms.ovn_charm.BaseTrainOVNChassisCharm): # OpenvSwitch and OVN is distributed as part of the Ubuntu Cloud Archive # Pockets get their name from OpenStack releases release = 'train' @@ -31,7 +32,8 @@ class TrainOVNChassisCharm(charms.ovn_charm.BaseTrainOVNChassisCharm): source_config_key = '' -class UssuriOVNChassisCharm(charms.ovn_charm.BaseUssuriOVNChassisCharm): +class UssuriOVNChassisCharm(charms.ovn_charm.DeferredEventMixin, + charms.ovn_charm.BaseUssuriOVNChassisCharm): # OpenvSwitch and OVN is distributed as part of the Ubuntu Cloud Archive # Pockets get their name from OpenStack releases release = 'ussuri' diff --git a/src/reactive/ovn_chassis_handlers.py b/src/reactive/ovn_chassis_handlers.py index ed302ab..fca4503 100644 --- a/src/reactive/ovn_chassis_handlers.py +++ b/src/reactive/ovn_chassis_handlers.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import charms.reactive as reactive +import charms_openstack.charm as charm from . import ovn_chassis_charm_handlers @@ -20,3 +21,9 @@ from . import ovn_chassis_charm_handlers def enable_ovn_chassis_handlers(): reactive.set_flag( ovn_chassis_charm_handlers.OVN_CHASSIS_ENABLE_HANDLERS_FLAG) + + +@reactive.when_not('is-update-status-hook') +def configure_deferred_restarts(): + with charm.provide_charm_instance() as instance: + instance.configure_deferred_restarts() diff --git a/src/tests/tests.yaml b/src/tests/tests.yaml index 432ac70..47f69be 100644 --- a/src/tests/tests.yaml +++ b/src/tests/tests.yaml @@ -26,6 +26,7 @@ target_deploy_status: configure: - zaza.openstack.charm_tests.vault.setup.auto_initialize_no_validation tests: +- zaza.openstack.charm_tests.ovn.tests.OVNChassisDeferredRestartTest - zaza.openstack.charm_tests.ovn.tests.ChassisCharmOperationTest tests_options: force_deploy: diff --git a/unit_tests/test_reactive_ovn_chassis_handlers.py b/unit_tests/test_reactive_ovn_chassis_handlers.py index 0a4726d..3443be7 100644 --- a/unit_tests/test_reactive_ovn_chassis_handlers.py +++ b/unit_tests/test_reactive_ovn_chassis_handlers.py @@ -26,6 +26,7 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks): hook_set = { 'when_not': { 'enable_ovn_chassis_handlers': ('MOCKED_FLAG',), + 'configure_deferred_restarts': ('is-update-status-hook',), }, } # test that the hooks were registered via the