aboutsummaryrefslogtreecommitdiff
path: root/docker/base
diff options
context:
space:
mode:
authorMichal Arbet <michal.arbet@ultimum.io>2025-06-12 13:29:43 +0200
committerMichal Arbet <michal.arbet@ultimum.io>2025-06-19 14:23:35 +0200
commitcf3c65fef7c51b8f54c32bfa58574f58ad4071c8 (patch)
treede5a59ac86eeab0b42f232c665ba08def689ab67 /docker/base
parent2319d121451167c2519938c234de2c65e7d3a797 (diff)
downloadkolla-cf3c65fef7c51b8f54c32bfa58574f58ad4071c8.tar.gz
kolla-cf3c65fef7c51b8f54c32bfa58574f58ad4071c8.zip
Fix kolla-set-configs --check to detect state mismatch
If a configuration file is tracked in the state file but no longer appears in config.json, it should either be restored or removed. This patch introduces a new exception StateMismatch and updates execute_config_check() to detect such cases. If any destination path is present in the defaults state but missing from config.json, we now raise StateMismatch. A dedicated unit test has been added to verify this behavior. Closes-Bug: #2114173 Signed-off-by: Michal Arbet <michal.arbet@ultimum.io> Change-Id: I6e0b4aaa5722990e3ac647578023f474db3d4381
Diffstat (limited to 'docker/base')
-rw-r--r--docker/base/set_configs.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/docker/base/set_configs.py b/docker/base/set_configs.py
index ab5b8c68b..80c32e507 100644
--- a/docker/base/set_configs.py
+++ b/docker/base/set_configs.py
@@ -68,6 +68,10 @@ class ConfigFileCommandDiffers(ExitingException):
pass
+class StateMismatch(ExitingException):
+ pass
+
+
class ConfigFile(object):
def __init__(self, source, dest, owner=None, perm=None, optional=False,
@@ -583,6 +587,56 @@ def execute_command_check(config):
def execute_config_check(config):
+ """Check configuration state consistency and validate config file entries.
+
+ This function compares the current config file destinations from the
+ provided config dictionary with those stored in the defaults state file.
+ If any destinations are found in the state file but not in the config,
+ a StateMismatch exception is raised. These missing files would otherwise
+ be restored or removed depending on their backup state.
+
+ After validating consistency, the function performs standard checks on
+ each declared configuration file, including content, permissions, and
+ ownership validation.
+
+ Args:
+ config (dict): The configuration dictionary containing 'config_files'
+ entries as expected by Kolla.
+
+ Raises:
+ StateMismatch: If there are entries in the defaults state not present
+ in the provided config.
+ """
+ state = get_defaults_state()
+
+ # Build a set of all current destination paths from config.json
+ # If the destination is a directory, we append the
+ # basename of the source
+ current_dests = {
+ entry['dest'] if not entry['dest'].endswith('/') else
+ os.path.join(entry['dest'], os.path.basename(entry['source']))
+ for entry in config.get('config_files', [])
+ if entry.get('dest')
+ }
+
+ # Detect any paths that are present in the state file but
+ # missing from config.json.
+ # These would be either restored (if state[dest] has a backup)
+ # or removed (if dest is null)
+ removed_dests = [
+ path for path in state.keys()
+ if path not in current_dests
+ ]
+
+ if removed_dests:
+ raise StateMismatch(
+ f"The following config files are tracked in state but missing "
+ f"from config.json. "
+ f"They would be restored or removed: {sorted(removed_dests)}"
+ )
+
+ # Perform the regular content, permissions, and ownership
+ # checks on the declared files
for data in config.get('config_files', []):
config_file = ConfigFile(**data)
config_file.check()