Handle deferred stops
The ovs package in kinetic+ (zed+) uses dh_installsystemd with --no-start for ovsdb-server, ovs-vswitchd, and ovs-record-hostname. this results in stop events rather than restart events. This change updates the restart-services actions for this charm to handle stop events. Closes-Bug: #2012553 Change-Id: If1dd5d0e5ca640a91893376366b23e78649d5772
This commit is contained in:
parent
fa3721f369
commit
bc15fdac16
@ -1,26 +0,0 @@
|
||||
#!/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))
|
1
src/actions/restart-services
Symbolic link
1
src/actions/restart-services
Symbolic link
@ -0,0 +1 @@
|
||||
restart_services.py
|
76
src/actions/restart_services.py
Executable file
76
src/actions/restart_services.py
Executable file
@ -0,0 +1,76 @@
|
||||
#!/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 datetime
|
||||
import sys
|
||||
|
||||
|
||||
sys.path.append('actions')
|
||||
sys.path.append('lib')
|
||||
|
||||
from charms.layer import basic
|
||||
basic.bootstrap_charm_deps()
|
||||
|
||||
import charmhelpers.contrib.openstack.deferred_events as deferred_events
|
||||
import charmhelpers.contrib.openstack.utils as os_utils
|
||||
import charmhelpers.core.hookenv as hookenv
|
||||
import charms_openstack.charm
|
||||
|
||||
import os_deferred_event_actions
|
||||
|
||||
charms_openstack.bus.discover()
|
||||
|
||||
|
||||
def restart_services(args):
|
||||
"""Restart services.
|
||||
|
||||
:param args: Unused
|
||||
:type args: List[str]
|
||||
"""
|
||||
deferred_only = hookenv.action_get("deferred-only")
|
||||
services = hookenv.action_get("services").split()
|
||||
os_deferred_event_actions.restart_services(args)
|
||||
# Clear deferred stops. If the services start time is after the
|
||||
# requested stop time we can infer the stop has happened. This is
|
||||
# to work around Bug #2012553
|
||||
deferred_stops = [
|
||||
e
|
||||
for e in deferred_events.get_deferred_events()
|
||||
if e.action == 'stop']
|
||||
for event in deferred_stops:
|
||||
start_time = deferred_events.get_service_start_time(event.service)
|
||||
deferred_stop_time = datetime.datetime.fromtimestamp(
|
||||
event.timestamp)
|
||||
if start_time > deferred_stop_time:
|
||||
deferred_events.clear_deferred_events([event.service], 'stop')
|
||||
else:
|
||||
if deferred_only or event.service in services:
|
||||
os_utils.restart_services_action([event.service])
|
||||
deferred_events.clear_deferred_events([event.service], 'stop')
|
||||
with charms_openstack.charm.provide_charm_instance() as charm_instance:
|
||||
charm_instance._assess_status()
|
||||
|
||||
|
||||
def main(args):
|
||||
hookenv._run_atstart()
|
||||
try:
|
||||
restart_services(args)
|
||||
except Exception as e:
|
||||
hookenv.action_fail(str(e))
|
||||
hookenv._run_atexit()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv))
|
Loading…
Reference in New Issue
Block a user