From d8552bacd7940461f98aa25b20dd2eb71d7f7f4a Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Tue, 18 Apr 2023 09:58:25 -0400 Subject: [PATCH] Prevent update-status to run unrequired handlers Before the update-status hook would run handlers that are expected to run when the configuration changes or relations added/removed. The update-status hook doesn't hold the machine lock which makes concurrent hook executions possible and seen in the gate where for example multiple "apt-get" executions trying to acquire dpkg's lock. Closes-Bug: #2016893 Change-Id: I63bfd9903057cbea2db8de4f1b612601aacb568d --- src/reactive/placement_handlers.py | 3 +++ unit_tests/test_placement_handlers.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/reactive/placement_handlers.py b/src/reactive/placement_handlers.py index e3814af..682602f 100644 --- a/src/reactive/placement_handlers.py +++ b/src/reactive/placement_handlers.py @@ -34,6 +34,7 @@ charms_openstack.charm.use_defaults( ) +@reactive.when_not('is-update-status-hook') @reactive.when('shared-db.available') @reactive.when('identity-service.available') def render_config(*args): @@ -60,6 +61,7 @@ def render_config(*args): reactive.set_state('config.rendered') +@reactive.when_not('is-update-status-hook') @reactive.when('config.rendered') @reactive.when('placement.available') @reactive.when_not('db.synced') @@ -77,6 +79,7 @@ def init_db(): reactive.set_state('db.synced') +@reactive.when_not('is-update-status-hook') @reactive.when('ha.connected') def cluster_connected(hacluster): """Configure HA resources in corosync""" diff --git a/unit_tests/test_placement_handlers.py b/unit_tests/test_placement_handlers.py index 7aad4b4..8771739 100644 --- a/unit_tests/test_placement_handlers.py +++ b/unit_tests/test_placement_handlers.py @@ -40,7 +40,9 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks): 'cluster_connected': ('ha.connected',), }, 'when_not': { - 'init_db': ('db.synced',), + 'init_db': ('db.synced', 'is-update-status-hook'), + 'render_config': ('is-update-status-hook', ), + 'cluster_connected': ('is-update-status-hook', ), }, } # test that the hooks were registered via the