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 3a8ec60..f6eb3ae 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -13,3 +13,9 @@ options: type: string description: | Comma separated list of nagios servicegroups for the service checks. + 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_dedicated_chassis.py b/src/lib/charm/openstack/ovn_dedicated_chassis.py index 2edab06..1a05a75 100644 --- a/src/lib/charm/openstack/ovn_dedicated_chassis.py +++ b/src/lib/charm/openstack/ovn_dedicated_chassis.py @@ -31,7 +31,8 @@ class OVNDedicatedChassisConfigurationAdapter( enable_hardware_offload = False -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 source_config_key = 'source' @@ -40,12 +41,13 @@ class TrainOVNChassisCharm(charms.ovn_charm.BaseTrainOVNChassisCharm): configuration_class = OVNDedicatedChassisConfigurationAdapter # NOTE(fnordahl): Add this to ``layer-ovn`` - def install(self): + def install(self, check_deferred_events=True): self.configure_source() - super().install() + super().install(check_deferred_events=check_deferred_events) -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 source_config_key = 'source' @@ -54,6 +56,6 @@ class UssuriOVNChassisCharm(charms.ovn_charm.BaseUssuriOVNChassisCharm): configuration_class = OVNDedicatedChassisConfigurationAdapter # NOTE(fnordahl): Add this to ``layer-ovn`` - def install(self): + def install(self, check_deferred_events=True): self.configure_source() - super().install() + super().install(check_deferred_events=check_deferred_events) diff --git a/src/reactive/ovn_dedicated_chassis_handlers.py b/src/reactive/ovn_dedicated_chassis_handlers.py index dc6600f..8c525c2 100644 --- a/src/reactive/ovn_dedicated_chassis_handlers.py +++ b/src/reactive/ovn_dedicated_chassis_handlers.py @@ -1,6 +1,7 @@ import charms.reactive as reactive from . import ovn_chassis_charm_handlers +import charms_openstack.charm as charm # NOTE: code shared among the chassis charms can be found in the 'ovn' layer. @@ -8,3 +9,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 693d467..41e58d1 100644 --- a/src/tests/tests.yaml +++ b/src/tests/tests.yaml @@ -23,6 +23,7 @@ target_deploy_status: configure: - zaza.openstack.charm_tests.vault.setup.auto_initialize_no_validation tests: +- zaza.openstack.charm_tests.ovn.tests.OVNDedicatedChassisDeferredRestartTest - zaza.openstack.charm_tests.ovn.tests.ChassisCharmOperationTest tests_options: force_deploy: diff --git a/unit_tests/test_reactive_ovn_dedicated_chassis_handlers.py b/unit_tests/test_reactive_ovn_dedicated_chassis_handlers.py index b8ec6c1..dc75317 100644 --- a/unit_tests/test_reactive_ovn_dedicated_chassis_handlers.py +++ b/unit_tests/test_reactive_ovn_dedicated_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