From 7c0b5189b6f07208ed6cdb7cccd33e0760234731 Mon Sep 17 00:00:00 2001 From: Jonathan Gangi Date: Tue, 16 Apr 2024 14:25:26 -0300 Subject: [PATCH] Enforce and validate just the dest dir on merge This commit changes the `merge_catalog_dirs` to call the `enforce_json_config_dir` and `opm_validate` only once after merging all files into the destination dir. Refers to CLOUDDST-21432 --- iib/workers/tasks/fbc_utils.py | 4 ++-- .../test_workers/test_tasks/test_fbc_utils.py | 21 ++++--------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/iib/workers/tasks/fbc_utils.py b/iib/workers/tasks/fbc_utils.py index bbe99eebd..a0d669f88 100644 --- a/iib/workers/tasks/fbc_utils.py +++ b/iib/workers/tasks/fbc_utils.py @@ -93,11 +93,11 @@ def merge_catalogs_dirs(src_config: str, dest_config: str): msg = f"config directory does not exist: {conf_dir}" log.error(msg) raise IIBError(msg) - enforce_json_config_dir(conf_dir) - opm_validate(conf_dir) log.info("Merging config folders: %s to %s", src_config, dest_config) shutil.copytree(src_config, dest_config, dirs_exist_ok=True) + enforce_json_config_dir(conf_dir) + opm_validate(conf_dir) def extract_fbc_fragment(temp_dir: str, fbc_fragment: str) -> Tuple[str, str]: diff --git a/tests/test_workers/test_tasks/test_fbc_utils.py b/tests/test_workers/test_tasks/test_fbc_utils.py index 7e0912926..1c572b802 100644 --- a/tests/test_workers/test_tasks/test_fbc_utils.py +++ b/tests/test_workers/test_tasks/test_fbc_utils.py @@ -117,23 +117,10 @@ def test_merge_catalogs_dirs(mock_enforce_json, mock_rc, mock_opm, tmpdir): tempfile.NamedTemporaryFile(dir=operator_dir, delete=False) merge_catalogs_dirs(src_config=source_dir, dest_config=destination_dir) - mock_enforce_json.assert_has_calls( - [ - mock.call(source_dir), - mock.call(destination_dir), - ] - ) - mock_rc.assert_has_calls( - [ - mock.call( - [mock_opm.opm_version, 'validate', source_dir], - exc_msg=f'Failed to validate the content from config_dir {source_dir}', - ), - mock.call( - [mock_opm.opm_version, 'validate', destination_dir], - exc_msg=f'Failed to validate the content from config_dir {destination_dir}', - ), - ] + mock_enforce_json.assert_called_once_with(destination_dir) + mock_rc.called_once_with( + [mock_opm.opm_version, 'validate', destination_dir], + exc_msg=f'Failed to validate the content from config_dir {destination_dir}', ) for r, d, f in os.walk(source_dir):