From cf3c65fef7c51b8f54c32bfa58574f58ad4071c8 Mon Sep 17 00:00:00 2001 From: Michal Arbet Date: Thu, 12 Jun 2025 13:29:43 +0200 Subject: 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 Change-Id: I6e0b4aaa5722990e3ac647578023f474db3d4381 --- tests/test_set_config.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'tests') diff --git a/tests/test_set_config.py b/tests/test_set_config.py index 3d4fc5a45..f29650504 100644 --- a/tests/test_set_config.py +++ b/tests/test_set_config.py @@ -892,3 +892,47 @@ class ConfigFileTest(base.BaseTestCase): # Verify that the updated state was saved mock_set_defaults_state.assert_called_once_with(expected_state) + + +class ExecuteConfigCheckStateMismatchTest(base.BaseTestCase): + + @mock.patch.object(set_configs, 'get_defaults_state') + def test_execute_config_check_raises_state_mismatch( + self, mock_get_defaults_state + ): + """Test execute_config_check() when state has extra config file. + + This test simulates the scenario where the state file contains + a destination that no longer exists in config.json. It verifies: + - get_defaults_state() returns a state with an extra entry. + - execute_config_check() raises StateMismatch when config.json + omits a tracked destination. + """ + config = { + "command": "/bin/true", + "config_files": [ + { + "source": "/etc/foo/foo.conf", + "dest": "/etc/foo/foo.conf", + "owner": "user1", + "perm": "0644" + } + ] + } + + mock_get_defaults_state.return_value = { + "/etc/foo/foo.conf": { + "source": "/etc/foo/foo.conf", + "preserve_properties": True, + "dest": "/etc/kolla/defaults/etc/foo/foo.conf" + }, + "/etc/old/obsolete.conf": { + "source": "/etc/old/obsolete.conf", + "preserve_properties": True, + "dest": "/etc/kolla/defaults/etc/old/obsolete.conf" + } + } + + self.assertRaises(set_configs.StateMismatch, + set_configs.execute_config_check, + config) -- cgit v1.2.3