From d6910f01deb3fa41b2a7662d1d5eb4a7d1b5c50f Mon Sep 17 00:00:00 2001 From: Piotr Milewski Date: Thu, 26 Mar 2026 18:05:41 +0100 Subject: Add YAML support to kolla_set_configs engine Following the PTG agreement, this commit extends the container configuration engine (set_configs.py) to support YAML format while maintaining backward compatibility with JSON. - Integrated 'yaml' library as a universal parser for both JSON and YAML formats (YAML is a superset of JSON) - Updated 'load_config' to search for 'config.json', 'config.yaml' - Added 'python3-yaml' (Debian) and 'python3-pyyaml' (RHEL) as required base packages in Dockerfile.j2 This change improves configuration readability and allows for easier maintenance while ensuring no breakage for existing JSON-based deployments. Change-Id: Icfb52b8f94e1036d5952b160c5921348d1427fda Signed-off-by: Piotr Milewski --- tests/test_set_config.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'tests') diff --git a/tests/test_set_config.py b/tests/test_set_config.py index 6e3ddf5e3..89b71fca8 100644 --- a/tests/test_set_config.py +++ b/tests/test_set_config.py @@ -75,6 +75,67 @@ class LoadFromFile(base.BaseTestCase): self.assertEqual(calls, mo.mock_calls) + @mock.patch('os.path.exists', return_value=True) + def test_load_yaml_ok(self, mock_exists): + in_config = ( + 'command: /bin/true\n' + 'config_files: {}\n' + ) + + mo = mock.mock_open(read_data=in_config) + with mock.patch.object(set_configs, 'open', mo): + config = set_configs.load_config() + self.assertEqual(config['command'], '/bin/true') + + mock_exists.assert_called_with( + '/var/lib/kolla/config_files/config.yaml') + + @mock.patch('os.path.exists', return_value=True) + def test_load_yaml_invalid(self, mock_exists): + in_config = '{' + + mo = mock.mock_open(read_data=in_config) + with mock.patch.object(set_configs, 'open', mo): + self.assertRaises(set_configs.InvalidConfig, + set_configs.load_config) + + @mock.patch('os.path.exists', return_value=False) + def test_load_json_when_no_yaml(self, mock_exists): + in_config = json.dumps({'command': '/bin/true', + 'config_files': {}}) + + mo = mock.mock_open(read_data=in_config) + with mock.patch.object(set_configs, 'open', mo): + config = set_configs.load_config() + self.assertEqual(config['command'], '/bin/true') + + mock_exists.assert_called_with( + '/var/lib/kolla/config_files/config.yaml') + + @mock.patch('os.path.exists', return_value=True) + def test_load_yaml_full_config(self, mock_exists): + in_config = ( + 'command: kolla_toolbox\n' + 'config_files:\n' + '- dest: /etc/rabbitmq/rabbitmq-env.conf\n' + ' source: /var/lib/kolla/config_files/rabbitmq-env.conf\n' + ' owner: rabbitmq\n' + ' perm: \'0600\'\n' + 'permissions:\n' + '- path: /var/log/kolla/ansible.log\n' + ' owner: ansible:kolla\n' + ' perm: \'0664\'\n' + ) + + mo = mock.mock_open(read_data=in_config) + with mock.patch.object(set_configs, 'open', mo): + config = set_configs.load_config() + + self.assertEqual(config['command'], 'kolla_toolbox') + self.assertEqual(len(config['config_files']), 1) + self.assertEqual(config['config_files'][0]['owner'], 'rabbitmq') + self.assertEqual(config['permissions'][0]['perm'], '0664') + FAKE_CONFIG_FILES = [ set_configs.ConfigFile( -- cgit v1.2.3