Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "--migrate-level" for opm_migrate if opm>1.46 #795

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading