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 f84cee2634)
(cherry picked from commit fd5b1bb1f0)
Signed-off-by: zhhuabj <joshua.zhang@canonical.com>
This commit is contained in:
Olivier Dufour-Cuvillier 2023-01-30 19:38:02 +09:00 committed by zhhuabj
parent 667642b4b2
commit b779fcb020
2 changed files with 14 additions and 1 deletions

View File

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

View File

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