aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPiotr Milewski <vurmil@gmail.com>2026-03-26 18:05:41 +0100
committerPiotr Milewski <vurmil@gmail.com>2026-06-17 18:32:01 +0200
commitd6910f01deb3fa41b2a7662d1d5eb4a7d1b5c50f (patch)
tree0243ff6cbdbdf03798cafb0e387ac48dcba92ee9 /tests
parentc2a33b186be3c5991c85fdc0fa5172f52e55900a (diff)
downloadkolla-d6910f01deb3fa41b2a7662d1d5eb4a7d1b5c50f.tar.gz
kolla-d6910f01deb3fa41b2a7662d1d5eb4a7d1b5c50f.zip
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 <vurmil@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_set_config.py61
1 files changed, 61 insertions, 0 deletions
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(