summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDawud M <dawud@stackhpc.com>2023-02-15 18:02:05 +0000
committerMichal Nasiadka <mnasiadka@gmail.com>2023-08-30 07:13:58 +0000
commit3684f67fee9026ff85771517af32f12d48e9c625 (patch)
tree7cc405538a60cfbcf795f56790f04c4e88702786 /tests
parent9b612fa231acf239926e4790165d6ae16074f99e (diff)
downloadkolla-3684f67fee9026ff85771517af32f12d48e9c625.tar.gz
kolla-3684f67fee9026ff85771517af32f12d48e9c625.zip
Add comprehensive checks for container restarts
When adding a dashboard to grafana the containers aren't restarted when they should be. This is due to a bug in Kolla where the logic to determine whether or the container needs to be restarted fails in the case where the file does not exist in the container. This patch adds more comprehensive checks for container restarts in the set_configs.py file. This patch also adds a test to ensure that the functions work as expected. Closes-Bug: #1997984 Co-Authored-By: Will Szumski <will@stackhpc.com> Change-Id: I67f5f12700d7b55f26bff81e9b54559303da6d83 (cherry picked from commit d9a6c5f3901e078a30d341397ac57d867d8191cc)
Diffstat (limited to 'tests')
-rw-r--r--tests/test_set_config.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/test_set_config.py b/tests/test_set_config.py
index e74376c60..a5e09084e 100644
--- a/tests/test_set_config.py
+++ b/tests/test_set_config.py
@@ -344,3 +344,74 @@ class ConfigFileTest(base.BaseTestCase):
self.assertEqual([mock.call('/fake/file1', 'rb'),
mock.call('/fake/file2', 'rb')],
mock_open.call_args_list)
+
+ @mock.patch('glob.glob')
+ def test_check_non_optional_src_file_not_exists(self,
+ mock_glob):
+ config_file = set_configs.ConfigFile(
+ '/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644')
+
+ mock_glob.return_value = []
+
+ self.assertRaises(set_configs.MissingRequiredSource,
+ config_file.check)
+
+ @mock.patch('glob.glob')
+ def test_check_optional_src_file_not_exists(self,
+ mock_glob):
+ config_file = set_configs.ConfigFile(
+ '/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644',
+ optional=True)
+ mock_glob.return_value = []
+
+ self.assertIsNone(config_file.check())
+
+ @mock.patch('glob.glob')
+ @mock.patch('os.path.isdir')
+ @mock.patch.object(set_configs.ConfigFile, '_cmp_file')
+ def test_check_raises_config_bad_state(self,
+ mock_cmp_file,
+ mock_isdir,
+ mock_glob):
+ config_file = set_configs.ConfigFile(
+ '/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644',
+ optional=True)
+ mock_cmp_file.return_value = False
+ mock_isdir.return_value = False
+ mock_glob.return_value = ['/var/lib/kolla/config_files/bar']
+
+ self.assertRaises(set_configs.ConfigFileBadState, config_file.check)
+
+ @mock.patch('os.path.exists', autospec=True)
+ def test_cmp_file_optional_src_exists_dest_no_exists(self, mock_os_exists):
+ config_file = set_configs.ConfigFile(
+ '/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644',
+ optional=True)
+
+ def fake_exists(path):
+ if path == '/var/lib/kolla/config_files/bar':
+ return True
+ return False
+
+ mock_os_exists.side_effect = fake_exists
+
+ self.assertIs(False,
+ config_file._cmp_file('/var/lib/kolla/config_files/bar',
+ '/foo'))
+
+ @mock.patch('os.path.exists', autospec=True)
+ def test_cmp_file_optional_src_no_exists_dest_exists(self, mock_os_exists):
+ config_file = set_configs.ConfigFile(
+ '/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644',
+ optional=True)
+
+ def fake_exists(path):
+ if path == '/var/lib/kolla/config_files/bar':
+ return False
+ return True
+
+ mock_os_exists.side_effect = fake_exists
+
+ self.assertIs(False,
+ config_file._cmp_file('/var/lib/kolla/config_files/bar',
+ '/foo'))