aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMark Goddard <mark@stackhpc.com>2020-08-06 10:50:25 +0100
committerRadosław Piliszek <radoslaw.piliszek@gmail.com>2020-08-28 15:01:25 +0000
commitc5320eb22386c34d83435fa0b9aa03b178996b52 (patch)
tree7988cda9ff2df403adf84b7c327ed2fe04224619 /tests
parentb4dde581c528c2072e408768601b75a97551e5a8 (diff)
downloadkolla-c5320eb22386c34d83435fa0b9aa03b178996b52.tar.gz
kolla-c5320eb22386c34d83435fa0b9aa03b178996b52.zip
Fix kolla_set_configs --check with a directory
There are several issues with kolla_set_configs --check: 1. We calculate the destination path incorrectly when comparing a file in a directory, due to passing arguments to os.path.relpath in the wrong order 2. For directories that have not changed, we also attempt to compare them as files, which fails when they are open()ed. 3. If the config JSON does not have a config_files key, it fails with a KeyError. The first two issues affect the fluentd container, which specifies directories as the source, without using a glob. The third affects OVN containers. This patch fixes these issues. Closes-Bug: #1890567 Change-Id: I8921befe51da4282121443849177a7ca5ebe8822
Diffstat (limited to 'tests')
-rw-r--r--tests/test_set_config.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test_set_config.py b/tests/test_set_config.py
index 8af2e618d..3888a38cc 100644
--- a/tests/test_set_config.py
+++ b/tests/test_set_config.py
@@ -288,3 +288,44 @@ class ConfigFileTest(base.BaseTestCase):
'/foo/bar.conf'),
mock.call('/var/lib/kolla/config_files/bar.yml',
'/foo/bar.yml')])
+
+ @mock.patch.object(set_configs.ConfigFile, '_cmp_file')
+ @mock.patch.object(set_configs.ConfigFile, '_cmp_dir')
+ @mock.patch('os.path.isdir', return_value=False)
+ @mock.patch('glob.glob')
+ def test_check_source_dir(self, mock_glob, mock_isdir, mock_cmp_dir,
+ mock_cmp_file):
+ config_file = set_configs.ConfigFile(
+ '/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644')
+
+ mock_glob.return_value = ['/var/lib/kolla/config_files/bar']
+ mock_isdir.return_value = True
+ mock_cmp_dir.return_value = True
+
+ config_file.check()
+
+ mock_isdir.assert_called_once_with('/var/lib/kolla/config_files/bar')
+ mock_cmp_dir.assert_called_once_with(
+ '/var/lib/kolla/config_files/bar', '/foo')
+ mock_cmp_file.assert_not_called()
+
+ @mock.patch.object(set_configs.ConfigFile, '_cmp_file')
+ @mock.patch.object(set_configs.ConfigFile, '_cmp_dir')
+ @mock.patch('os.path.isdir', return_value=False)
+ @mock.patch('glob.glob')
+ def test_check_source_dir_no_equal(self, mock_glob, mock_isdir,
+ mock_cmp_dir, mock_cmp_file):
+ config_file = set_configs.ConfigFile(
+ '/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644')
+
+ mock_glob.return_value = ['/var/lib/kolla/config_files/bar']
+ mock_isdir.return_value = True
+ mock_cmp_dir.return_value = False
+
+ self.assertRaises(set_configs.ConfigFileBadState,
+ config_file.check)
+
+ mock_isdir.assert_called_once_with('/var/lib/kolla/config_files/bar')
+ mock_cmp_dir.assert_called_once_with(
+ '/var/lib/kolla/config_files/bar', '/foo')
+ mock_cmp_file.assert_not_called()