Skip to content

Commit 96337cc

Browse files
committed
Add "--migrate-level" for opm_migrate if opm>1.46
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
1 parent 05b7824 commit 96337cc

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

iib/workers/tasks/opm_operations.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,14 @@ def opm_migrate(
621621
if os.path.exists(fbc_dir_path):
622622
shutil.rmtree(fbc_dir_path)
623623

624-
cmd = [Opm.opm_version, 'migrate', index_db, fbc_dir_path]
624+
cmd = [Opm.opm_version, 'migrate']
625+
626+
migrate_args = []
627+
opm_version_number = Opm.get_opm_version_number()
628+
if Version(opm_version_number) > Version("v1.46.0"):
629+
migrate_args = ['--migrate-level', 'bundle-object-to-csv-metadata']
630+
631+
cmd = [Opm.opm_version, 'migrate', *migrate_args, index_db, fbc_dir_path]
625632

626633
run_cmd(cmd, {'cwd': base_dir}, exc_msg='Failed to migrate index.db to file-based catalog')
627634
log.info("Migration to file-based catalog was completed.")

tests/test_workers/test_tasks/test_opm_operations.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,18 +386,30 @@ def test_serve_cmd_at_port_delayed_initialize(
386386
assert mock_run_cmd.call_count == 7
387387

388388

389+
@pytest.mark.parametrize(
390+
"opm_version,migrate_args",
391+
[
392+
("v1.26.8", []),
393+
("v1.47.2", ['--migrate-level', 'bundle-object-to-csv-metadata']),
394+
],
395+
)
389396
@mock.patch('iib.workers.tasks.opm_operations.opm_validate')
390397
@mock.patch('iib.workers.tasks.opm_operations.shutil.rmtree')
391398
@mock.patch('iib.workers.tasks.opm_operations.generate_cache_locally')
392399
@mock.patch('iib.workers.tasks.utils.run_cmd')
393-
@mock.patch.object(opm_operations.Opm, 'opm_version', 'opm-v1.26.8')
394400
def test_opm_migrate(
395401
mock_run_cmd,
396402
mock_gcl,
397403
moch_srmtree,
398404
mock_opmvalidate,
405+
opm_version,
406+
migrate_args,
407+
monkeypatch,
399408
tmpdir,
400409
):
410+
monkeypatch.setattr(opm_operations.Opm, 'opm_version', f'opm-{opm_version}')
411+
monkeypatch.setattr(opm_operations.Opm, 'get_opm_version_number', lambda: opm_version)
412+
401413
index_db_file = os.path.join(tmpdir, 'database/index.db')
402414

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

408420
mock_run_cmd.assert_called_once_with(
409-
['opm-v1.26.8', 'migrate', index_db_file, fbc_dir],
421+
[f'opm-{opm_version}', 'migrate', *migrate_args, index_db_file, fbc_dir],
410422
{'cwd': tmpdir},
411423
exc_msg='Failed to migrate index.db to file-based catalog',
412424
)

0 commit comments

Comments
 (0)