Skip to content

Commit

Permalink
Generate catalog cache right after opm migrate
Browse files Browse the repository at this point in the history
[CLOUDDST-17016]
  • Loading branch information
lipoja committed Jan 5, 2023
1 parent 83d3d5d commit 6c53113
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions iib/workers/tasks/opm_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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']
Expand Down
12 changes: 8 additions & 4 deletions tests/test_workers/test_tasks/test_opm_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
):
Expand All @@ -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')

Expand All @@ -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))
Expand Down

0 comments on commit 6c53113

Please sign in to comment.