Skip to content

Commit ca699a8

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Fix kolla_set_configs --check with a directory" into stable/ussuri
2 parents 5a31aa0 + c191e6f commit ca699a8

File tree

3 files changed

+53
-5
lines changed

3 files changed

+53
-5
lines changed

docker/base/set_configs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ def _cmp_dir(self, source, dest):
204204
return False
205205
for file_ in files:
206206
full_path = os.path.join(root, file_)
207-
dest_full_path = os.path.join(dest, os.path.relpath(source,
208-
full_path))
207+
dest_full_path = os.path.join(dest, os.path.relpath(full_path,
208+
source))
209209
if not self._cmp_file(full_path, dest_full_path):
210210
return False
211211
return True
@@ -225,8 +225,9 @@ def check(self):
225225
# otherwise means copy the source to dest
226226
if dest.endswith(os.sep):
227227
dest = os.path.join(dest, os.path.basename(source))
228-
if os.path.isdir(source) and not self._cmp_dir(source, dest):
229-
bad_state_files.append(source)
228+
if os.path.isdir(source):
229+
if not self._cmp_dir(source, dest):
230+
bad_state_files.append(source)
230231
elif not self._cmp_file(source, dest):
231232
bad_state_files.append(source)
232233
if len(bad_state_files) != 0:
@@ -404,7 +405,7 @@ def execute_config_strategy(config):
404405

405406

406407
def execute_config_check(config):
407-
for data in config['config_files']:
408+
for data in config.get('config_files', []):
408409
config_file = ConfigFile(**data)
409410
config_file.check()
410411

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes an issue with the ``kolla_set_configs --check`` command when the
5+
source is a directory. `LP#1890567
6+
<https://bugs.launchpad.net/kolla/+bug/1890567>`__

tests/test_set_config.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,44 @@ def test_check_glob_source_file_no_equal(self, mock_glob, mock_isdir,
288288
'/foo/bar.conf'),
289289
mock.call('/var/lib/kolla/config_files/bar.yml',
290290
'/foo/bar.yml')])
291+
292+
@mock.patch.object(set_configs.ConfigFile, '_cmp_file')
293+
@mock.patch.object(set_configs.ConfigFile, '_cmp_dir')
294+
@mock.patch('os.path.isdir', return_value=False)
295+
@mock.patch('glob.glob')
296+
def test_check_source_dir(self, mock_glob, mock_isdir, mock_cmp_dir,
297+
mock_cmp_file):
298+
config_file = set_configs.ConfigFile(
299+
'/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644')
300+
301+
mock_glob.return_value = ['/var/lib/kolla/config_files/bar']
302+
mock_isdir.return_value = True
303+
mock_cmp_dir.return_value = True
304+
305+
config_file.check()
306+
307+
mock_isdir.assert_called_once_with('/var/lib/kolla/config_files/bar')
308+
mock_cmp_dir.assert_called_once_with(
309+
'/var/lib/kolla/config_files/bar', '/foo')
310+
mock_cmp_file.assert_not_called()
311+
312+
@mock.patch.object(set_configs.ConfigFile, '_cmp_file')
313+
@mock.patch.object(set_configs.ConfigFile, '_cmp_dir')
314+
@mock.patch('os.path.isdir', return_value=False)
315+
@mock.patch('glob.glob')
316+
def test_check_source_dir_no_equal(self, mock_glob, mock_isdir,
317+
mock_cmp_dir, mock_cmp_file):
318+
config_file = set_configs.ConfigFile(
319+
'/var/lib/kolla/config_files/bar', '/foo', 'user1', '0644')
320+
321+
mock_glob.return_value = ['/var/lib/kolla/config_files/bar']
322+
mock_isdir.return_value = True
323+
mock_cmp_dir.return_value = False
324+
325+
self.assertRaises(set_configs.ConfigFileBadState,
326+
config_file.check)
327+
328+
mock_isdir.assert_called_once_with('/var/lib/kolla/config_files/bar')
329+
mock_cmp_dir.assert_called_once_with(
330+
'/var/lib/kolla/config_files/bar', '/foo')
331+
mock_cmp_file.assert_not_called()

0 commit comments

Comments
 (0)