Implementation of deferred restarts

Add deferred restart actions and config.

Change-Id: I06bea08c19c4aef40c2aae1ad5e8e21d2ef66579
This commit is contained in:
Liam Young 2021-04-09 13:13:02 +00:00
parent 78710b50d2
commit 66edeaaea3
9 changed files with 128 additions and 6 deletions

27
src/actions.yaml Normal file
View File

@ -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

26
src/actions/restart-services Executable file
View File

@ -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))

26
src/actions/run-deferred-hooks Executable file
View File

@ -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))

View File

@ -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))

View File

@ -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.

View File

@ -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)

View File

@ -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()

View File

@ -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:

View File

@ -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