From 5050885df955b9882fb0c249bb08688798a9f177 Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 31 Oct 2019 13:17:33 +0000 Subject: [PATCH] Do not rely on when_file_change for systemd reload Systemd was not relying being reloaded when the definition file for aodh-api changed. The reload was supposed to be triggered by the when_file_changed decorator. However, there are a number of issues with when_file_changed decorator (*1, *2, *3) and the decorator has now been deprecated *4. This change ensures the reload happens without relying on the decorator. *1 https://github.com/juju-solutions/charms.reactive/issues/25 *2 https://github.com/juju-solutions/charms.reactive/issues/44 *3 https://github.com/juju-solutions/charms.reactive/issues/49 *4 https://github.com/juju-solutions/charms.reactive/issues/44#issuecomment-438472843 Closes-Bug: #1850767 Change-Id: I7c528a53a4de8a4a85bf655fc242b0f38fd0754b --- src/lib/charm/openstack/aodh.py | 19 ++++++++++++++++++- src/reactive/aodh_handlers.py | 6 ------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/lib/charm/openstack/aodh.py b/src/lib/charm/openstack/aodh.py index 79f2ea1..17e91c6 100644 --- a/src/lib/charm/openstack/aodh.py +++ b/src/lib/charm/openstack/aodh.py @@ -85,7 +85,7 @@ class AodhCharm(charms_openstack.charm.HAOpenStackCharm): # file changes restart_map = { AODH_CONF: services, - AODH_API_SYSTEMD_CONF: 'aodh-api', + AODH_API_SYSTEMD_CONF: ['aodh-api'], } # Resource when in HA mode @@ -125,6 +125,23 @@ class AodhCharm(charms_openstack.charm.HAOpenStackCharm): ch_host.service_restart('aodh-api') +class AodhCharmNewton(AodhCharm): + """Newton uses the aodh-api standalone systemd. If the systemd definition + changes the a systemctl daemon-reload is needed. + """ + release = 'newton' + + def render_with_interfaces(self, interface_list): + if os.path.exists(AODH_API_SYSTEMD_CONF): + old_hash = ch_host.file_hash(AODH_API_SYSTEMD_CONF) + else: + old_hash = '' + super(AodhCharmNewton, self).render_with_interfaces(interface_list) + new_hash = ch_host.file_hash(AODH_API_SYSTEMD_CONF) + if old_hash != new_hash: + self.reload_and_restart() + + class AodhCharmOcata(AodhCharm): """From ocata onwards there is no aodh-api service, as this is handled via apache2 with a wsgi handler. Therefore, these specialisations are simple diff --git a/src/reactive/aodh_handlers.py b/src/reactive/aodh_handlers.py index 4a33945..0c62aa1 100644 --- a/src/reactive/aodh_handlers.py +++ b/src/reactive/aodh_handlers.py @@ -103,9 +103,3 @@ def run_db_migration(): @reactive.when('ha.connected') def cluster_connected(hacluster): aodh.configure_ha_resources(hacluster) - - -# TODO: drop once charm switches to apache+mod_wsgi -@reactive.when_file_changed(aodh.AODH_API_SYSTEMD_CONF) -def systemd_override_changed(): - aodh.reload_and_restart()