diff --git a/iib/workers/tasks/opm_operations.py b/iib/workers/tasks/opm_operations.py index 8138b1a28..52632969d 100644 --- a/iib/workers/tasks/opm_operations.py +++ b/iib/workers/tasks/opm_operations.py @@ -333,17 +333,23 @@ def opm_migrate(index_db: str, base_dir: str) -> str: from iib.workers.tasks.utils import run_cmd fbc_dir_path = os.path.join(base_dir, 'catalog') + local_cache_path = os.path.join(base_dir, 'cache') - # It may happen that we need to regenerate file-based catalog + # It may happen that we need to regenerate file-based catalog and cache # based on updated index.db therefore we have to remove the outdated catalog - # to be able to generate new one + # and cache to be able to generate new one if os.path.exists(fbc_dir_path): shutil.rmtree(fbc_dir_path) + if os.path.exists(local_cache_path): + shutil.rmtree(local_cache_path) cmd = ['opm', 'migrate', index_db, fbc_dir_path] run_cmd(cmd, {'cwd': base_dir}, exc_msg='Failed to migrate index.db to file-based catalog') log.info("Migration to file-based catalog was completed.") + + generate_cache_locally(base_dir, fbc_dir_path, local_cache_path) + return fbc_dir_path @@ -406,8 +412,6 @@ def opm_generate_dockerfile( log.info('Rewriting Dockerfile %s with newly generated by opm.', dockerfile_path) os.rename(dockerfile_path_opm_default, dockerfile_path) - local_cache_path = os.path.join(base_dir, 'cache') - generate_cache_locally(base_dir, fbc_dir, local_cache_path) insert_cache_into_dockerfile(dockerfile_path) db_path = get_worker_config()['hidden_index_db_path'] diff --git a/tests/test_workers/test_tasks/test_opm_operations.py b/tests/test_workers/test_tasks/test_opm_operations.py index 4b1020586..1bf9828d0 100644 --- a/tests/test_workers/test_tasks/test_opm_operations.py +++ b/tests/test_workers/test_tasks/test_opm_operations.py @@ -147,9 +147,11 @@ def test_serve_cmd_at_port_delayed_initialize( @mock.patch('iib.workers.tasks.opm_operations.shutil.rmtree') +@mock.patch('iib.workers.tasks.opm_operations.generate_cache_locally') @mock.patch('iib.workers.tasks.utils.run_cmd') def test_opm_migrate( mock_run_cmd, + mock_gcl, moch_srmtree, tmpdir, ): @@ -158,18 +160,21 @@ def test_opm_migrate( opm_operations.opm_migrate(index_db_file, tmpdir) moch_srmtree.assert_not_called() + fbc_dir = os.path.join(tmpdir, 'catalog') + mock_run_cmd.assert_called_once_with( - ['opm', 'migrate', index_db_file, os.path.join(tmpdir, 'catalog')], + ['opm', 'migrate', index_db_file, fbc_dir], {'cwd': tmpdir}, exc_msg='Failed to migrate index.db to file-based catalog', ) + mock_gcl.assert_called_once_with(tmpdir, fbc_dir, mock.ANY) + @pytest.mark.parametrize("dockerfile", (None, 'index.Dockerfile')) @mock.patch('iib.workers.tasks.utils.run_cmd') -@mock.patch('iib.workers.tasks.opm_operations.generate_cache_locally') @mock.patch('iib.workers.tasks.opm_operations.insert_cache_into_dockerfile') -def test_opm_generate_dockerfile(mock_icid, mock_gcl, mock_run_cmd, tmpdir, dockerfile): +def test_opm_generate_dockerfile(mock_icid, mock_run_cmd, tmpdir, dockerfile): index_db_file = os.path.join(tmpdir, 'database/index.db') fbc_dir = os.path.join(tmpdir, 'catalogs') @@ -196,7 +201,6 @@ def create_dockerfile(*args, **kwargs): assert any(line.find('/var/lib/iib/_hidden/do.not.edit.db') != -1 for line in f.readlines()) mock_icid.assert_called_once_with(df_path) - mock_gcl.assert_called_once_with(tmpdir, fbc_dir, mock.ANY) @pytest.mark.parametrize("set_index_db_file", (False, True))