Skip to content

Commit

Permalink
Add "--migrate-level" for opm_migrate if opm>1.46
Browse files Browse the repository at this point in the history
This commit modifies the `opm_migrate` function to include the
`--migrate-level bundle-object-to-csv-metadata` arguments to the command
whenever the OPM version is greater than 1.46

Refers to CLOUDDST-25703
  • Loading branch information
JAVGan authored and lipoja committed Jan 30, 2025
1 parent 05b7824 commit 7de328b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions iib/workers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ class Config(object):
# Enable send events to the broker. This is needed for celery promethues exporter
worker_send_task_events: bool = True
task_send_sent_event: bool = True
# The minimal version of OPM which requires setting the --migrate-level flag for migrate
iib_opm_new_migrate_version = "v1.46.0"


class ProductionConfig(Config):
Expand Down
8 changes: 7 additions & 1 deletion iib/workers/tasks/opm_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,13 @@ def opm_migrate(
if os.path.exists(fbc_dir_path):
shutil.rmtree(fbc_dir_path)

cmd = [Opm.opm_version, 'migrate', index_db, fbc_dir_path]
migrate_args = []
opm_new_migrate_version = get_worker_config().get('iib_opm_new_migrate_version')
opm_version_number = Opm.get_opm_version_number()
if Version(opm_version_number) > Version(opm_new_migrate_version):
migrate_args = ['--migrate-level', 'bundle-object-to-csv-metadata']

cmd = [Opm.opm_version, 'migrate', *migrate_args, 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.")
Expand Down
16 changes: 14 additions & 2 deletions tests/test_workers/test_tasks/test_opm_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,18 +386,30 @@ def test_serve_cmd_at_port_delayed_initialize(
assert mock_run_cmd.call_count == 7


@pytest.mark.parametrize(
"opm_version,migrate_args",
[
("v1.26.8", []),
("v1.47.2", ['--migrate-level', 'bundle-object-to-csv-metadata']),
],
)
@mock.patch('iib.workers.tasks.opm_operations.opm_validate')
@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')
@mock.patch.object(opm_operations.Opm, 'opm_version', 'opm-v1.26.8')
def test_opm_migrate(
mock_run_cmd,
mock_gcl,
moch_srmtree,
mock_opmvalidate,
opm_version,
migrate_args,
monkeypatch,
tmpdir,
):
monkeypatch.setattr(opm_operations.Opm, 'opm_version', f'opm-{opm_version}')
monkeypatch.setattr(opm_operations.Opm, 'get_opm_version_number', lambda: opm_version)

index_db_file = os.path.join(tmpdir, 'database/index.db')

opm_operations.opm_migrate(index_db_file, tmpdir)
Expand All @@ -406,7 +418,7 @@ def test_opm_migrate(
fbc_dir = os.path.join(tmpdir, 'catalog')

mock_run_cmd.assert_called_once_with(
['opm-v1.26.8', 'migrate', index_db_file, fbc_dir],
[f'opm-{opm_version}', 'migrate', *migrate_args, index_db_file, fbc_dir],
{'cwd': tmpdir},
exc_msg='Failed to migrate index.db to file-based catalog',
)
Expand Down

0 comments on commit 7de328b

Please sign in to comment.