From b779fcb020f2a31ac3ff274e85797534ee644e09 Mon Sep 17 00:00:00 2001 From: Olivier Dufour-Cuvillier Date: Mon, 30 Jan 2023 19:38:02 +0900 Subject: [PATCH] Prevent update-status to run unrequired handlers Before, the update-status hook would run many handlers that would have been normally done only during configuration changes. Consequently it creates an impact on the service and apply changes every time the hook is triggered, which is in most deployments every 5 minutes. This prevents the DNS zones managed by Designate to be updated constantly and potentially avoid race conditions within designate components. Conflicts: src/reactive/designate_handlers.py Closes-bug: #2003528 Change-Id: I0d4fea182da1316c0c30c143e64fcd2ca682afff (cherry picked from commit f84cee2634e6d9605fd154be40f2c04426eba01e) (cherry picked from commit fd5b1bb1f064a067873c395136e3d3c3614a699a) Signed-off-by: zhhuabj --- src/reactive/designate_handlers.py | 7 +++++++ unit_tests/test_designate_handlers.py | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/reactive/designate_handlers.py b/src/reactive/designate_handlers.py index 9bfe6a1..7c7d69e 100644 --- a/src/reactive/designate_handlers.py +++ b/src/reactive/designate_handlers.py @@ -59,6 +59,7 @@ def check_dns_slaves(): reactive.remove_state('dns-slaves-config-valid') +@reactive.when_not('is-update-status-hook') @reactive.when_any('dns-slaves-config-valid', 'dns-backend.available') def set_dns_config_available(*args): @@ -83,6 +84,7 @@ def install_packages(): reactive.remove_state('pool-manager-cache.synched') +@reactive.when_not('is-update-status-hook') @reactive.when('amqp.connected') def setup_amqp_req(amqp): """Send request for rabbit access and vhost""" @@ -105,6 +107,7 @@ def setup_database(database): reactive.set_state('shared-db.setup') +@reactive.when_not('is-update-status-hook') @reactive.when('identity-service.connected') def maybe_setup_endpoint(keystone): """When the keystone interface connects, register this unit in the keystone @@ -119,6 +122,7 @@ def maybe_setup_endpoint(keystone): keystone.register_endpoints(*args) +@reactive.when_not('is-update-status-hook') @reactive.when('cluster.connected') def expose_rndc_address(cluster): rndc_address = ip.get_relation_ip('dns-backend') @@ -162,6 +166,7 @@ def sync_pool_manager_cache(*args): reactive.set_state('pool-manager-cache.synched') +@reactive.when_not('is-update-status-hook') @reactive.when('db.synched') @reactive.when('pool-manager-cache.synched') @reactive.when(*COMPLETE_INTERFACE_STATES) @@ -204,6 +209,7 @@ def _render_sink_configs(instance, interfaces_list): instance.render_with_interfaces(interfaces_list, configs=configs) +@reactive.when_not('is-update-status-hook') @reactive.when('ha.connected') def cluster_connected(hacluster): """Configure HA resources in corosync""" @@ -211,6 +217,7 @@ def cluster_connected(hacluster): instance.configure_ha_resources(hacluster) +@reactive.when_not('is-update-status-hook') @reactive.when('dnsaas.connected') def expose_endpoint(endpoint): with charm.provide_charm_instance() as instance: diff --git a/unit_tests/test_designate_handlers.py b/unit_tests/test_designate_handlers.py index dda3052..b1c6cab 100644 --- a/unit_tests/test_designate_handlers.py +++ b/unit_tests/test_designate_handlers.py @@ -43,7 +43,7 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks): 'configure_nrpe': ('base-config.rendered', ), }, 'when_not': { - 'setup_amqp_req': ('amqp.requested-access', ), + 'setup_amqp_req': ('is-update-status-hook', ), 'setup_database': ('shared-db.setup', ), 'install_packages': ('installed', ), 'run_db_migration': ('db.synched', ), @@ -54,6 +54,12 @@ class TestRegisteredHooks(test_utils.TestRegisteredHooks): 'dont-set-assess-status', ), 'reset_shared_db': ('shared-db.connected', ), 'configure_nrpe': ('is-update-status-hook', ), + 'set_dns_config_available': ('is-update-status-hook', ), + 'maybe_setup_endpoint': ('is-update-status-hook', ), + 'expose_endpoint': ('is-update-status-hook', ), + 'configure_designate_full': ('is-update-status-hook', ), + 'expose_rndc_address': ('is-update-status-hook', ), + 'cluster_connected': ('is-update-status-hook', ), }, 'when_any': { 'set_dns_config_available': (