diff options
| author | Martin André <m.andre@redhat.com> | 2017-06-21 15:52:16 +0200 |
|---|---|---|
| committer | Martin André <m.andre@redhat.com> | 2017-06-27 08:44:41 +0200 |
| commit | e313c896219b3942d66a00d5388ba2cda6bcce87 (patch) | |
| tree | e5bddfb4b7744f911fa4845c5721c4b0e9c8bed5 /tests/test_set_config.py | |
| parent | 748a056b0964e2abf93ad66951957c834a32b81b (diff) | |
| download | kolla-e313c896219b3942d66a00d5388ba2cda6bcce87.tar.gz kolla-e313c896219b3942d66a00d5388ba2cda6bcce87.zip | |
Introduce merge and preserve_properties for config_files
The `merge` option will basically copy all the files recursively inside
the container without removing the existing files or directory, while
the `preserve_properties` option keeps the file attributes
(permissions, ownership, timestamps) in the container.
This is useful if you have extracted some config files from a container
and want to use them in another container based on the same image.
This makes TripleO usage of Kolla much more robust.
Change-Id: I78dcec741a941dc21adba33ba33a6dc6ff1d217c
Diffstat (limited to 'tests/test_set_config.py')
| -rw-r--r-- | tests/test_set_config.py | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/tests/test_set_config.py b/tests/test_set_config.py index fa8e45301..aff97b3bb 100644 --- a/tests/test_set_config.py +++ b/tests/test_set_config.py @@ -115,14 +115,34 @@ class ConfigFileTest(base.BaseTestCase): mock_isdir.assert_called_with(config_file.dest) mock_remove.assert_called_with(config_file.dest) + @mock.patch('shutil.copystat') + @mock.patch('os.stat') + @mock.patch('os.chown') + def test_set_properties_from_file(self, + mock_chown, + mock_stat, + mock_copystat): + + stat_result = mock.MagicMock() + mock_stat.return_value = stat_result + + config_file = copy.deepcopy(FAKE_CONFIG_FILE) + config_file._set_properties_from_file(config_file.source, + config_file.dest) + + mock_copystat.assert_called_with(config_file.source, config_file.dest) + mock_stat.assert_called_with(config_file.source) + mock_chown.assert_called_with(config_file.dest, stat_result.st_uid, + stat_result.st_gid) + @mock.patch('os.chmod') @mock.patch.object(set_configs, 'handle_permissions') - def test_set_permission(self, - mock_handle_permissions, - mock_chmod): + def test_set_properties_from_conf(self, + mock_handle_permissions, + mock_chmod): config_file = copy.deepcopy(FAKE_CONFIG_FILE) - config_file._set_permission(config_file.dest) + config_file._set_properties_from_conf(config_file.dest) mock_handle_permissions.assert_called_with({'owner': 'user1', 'path': config_file.dest, 'perm': '0644'}) @@ -167,14 +187,14 @@ class ConfigFileTest(base.BaseTestCase): mock_copy_file.assert_called_with(config_file.source, config_file.dest) - @mock.patch.object(set_configs.ConfigFile, '_copy_dir') + @mock.patch.object(set_configs.ConfigFile, '_merge_directories') @mock.patch('os.path.isdir', return_value=True) @mock.patch.object(set_configs.ConfigFile, '_create_parent_dirs') @mock.patch.object(set_configs.ConfigFile, '_delete_path') @mock.patch('glob.glob') def test_copy_one_source_dir(self, mock_glob, mock_delete_path, mock_create_parent_dirs, mock_isdir, - mock_copy_dir): + mock_merge_directories): config_file = copy.deepcopy(FAKE_CONFIG_FILE) mock_glob.return_value = [config_file.source] @@ -184,9 +204,8 @@ class ConfigFileTest(base.BaseTestCase): mock_glob.assert_called_with(config_file.source) mock_delete_path.assert_called_with(config_file.dest) mock_create_parent_dirs.assert_called_with(config_file.dest) - mock_isdir.assert_called_with(config_file.source) - mock_copy_dir.assert_called_with(config_file.source, - config_file.dest) + mock_merge_directories.assert_called_with(config_file.source, + config_file.dest) @mock.patch.object(set_configs.ConfigFile, '_copy_file') @mock.patch('os.path.isdir', return_value=False) |
