From 5167a1e082f8ab5ee808cca388cf30f155abe68f Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Thu, 10 Apr 2025 10:07:50 -0400 Subject: [PATCH] commands: invalidate cached config when node is not ctdb leader When the `samba-container config-update --watch` command is run on a CTDB enabled server we avoid updating the local config unless the node is the ctdb leader. However, the update function was returning the current config which the watch loop assigned to the previous var, meaning that the current and previous config would be equal on future trips around the loop. Therefore once the node became the leader it would not update the config even if it differed from the config in samba. This is a problem on start up because the loop initially runs before ctdb is ready and the node leadership is not known. Change it so that when the node is not a leader it returns None and "unsets" the previous config. This could lead to extra unneeded updates but should avoid missing updates that are needed. Signed-off-by: John Mulligan --- sambacc/commands/config.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/sambacc/commands/config.py b/sambacc/commands/config.py index ef88a7d9..e714786d 100644 --- a/sambacc/commands/config.py +++ b/sambacc/commands/config.py @@ -79,12 +79,15 @@ def _read_config(ctx: Context) -> config.InstanceConfig: ).get(ctx.cli.identity) +UpdateResult = typing.Tuple[typing.Optional[config.InstanceConfig], bool] + + def _update_config( current: config.InstanceConfig, previous: typing.Optional[config.InstanceConfig], ensure_paths: bool = True, notify_server: bool = True, -) -> typing.Tuple[config.InstanceConfig, bool]: +) -> UpdateResult: """Compare the current and previous instance configurations. If they differ, ensure any new paths, update the samba config, and inform any running smbds of the new configuration. Return the current config and a @@ -117,8 +120,8 @@ def _update_config( def _exec_if_leader( ctx: Context, - cond_func: typing.Callable[..., typing.Tuple[config.InstanceConfig, bool]], -) -> typing.Callable[..., typing.Tuple[config.InstanceConfig, bool]]: + cond_func: typing.Callable[..., UpdateResult], +) -> typing.Callable[..., UpdateResult]: """Run the cond func only on "nodes" that are the cluster leader.""" # CTDB status and leader detection is not changeable at runtime. @@ -126,11 +129,11 @@ def _exec_if_leader( @functools.wraps(cond_func) def _call_if_leader( current: config.InstanceConfig, previous: config.InstanceConfig - ) -> typing.Tuple[config.InstanceConfig, bool]: + ) -> UpdateResult: with best_leader_locator(ctx.instance_config) as ll: if not ll.is_leader(): _logger.info("skipping config update. node not leader") - return previous, False + return None, False _logger.info("checking for update. node is leader") result = cond_func(current, previous) return result