Skip to content

Commit

Permalink
Backup index.db to prevent opm bug consequence
Browse files Browse the repository at this point in the history
  • Loading branch information
xDaile committed Mar 8, 2024
1 parent 8026d8c commit 687b30a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
13 changes: 12 additions & 1 deletion iib/workers/tasks/opm_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,18 @@ def _opm_registry_add(
log.info('Using force to add bundle(s) to index')
cmd.extend(['--overwrite-latest'])

run_cmd(cmd, {'cwd': base_dir}, exc_msg='Failed to add the bundles to the index image')
# after commit 643fc9499222107f52b7ba3f9f3969fa36812940 index.db backup was added
# due to the opm bug https://issues.redhat.com/browse/OCPBUGS-30214
index_db_backup = index_db + ".backup"
shutil.copyfile(index_db, index_db_backup)

try:
run_cmd(cmd, {'cwd': base_dir}, exc_msg='Failed to add the bundles to the index image')
except Exception as e:
shutil.copyfile(index_db_backup, index_db)
raise e
finally:
os.remove(index_db_backup)


@retry(
Expand Down
11 changes: 10 additions & 1 deletion tests/test_workers/test_tasks/test_opm_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,17 @@ def test_opm_generate_dockerfile_exist(mock_run_cmd, tmpdir, dockerfile, set_ind
@pytest.mark.parametrize('container_tool', (None, 'podwoman'))
@mock.patch('iib.workers.tasks.utils.set_registry_token')
@mock.patch('iib.workers.tasks.utils.run_cmd')
@mock.patch('iib.workers.tasks.opm_operations.shutil.copyfile')
@mock.patch('iib.workers.tasks.opm_operations.os.remove')
def test_opm_registry_add(
mock_run_cmd, mock_srt, from_index, bundles, overwrite_csv, container_tool
mock_os_remove,
mock_shutil_copyfile,
mock_run_cmd,
mock_srt,
from_index,
bundles,
overwrite_csv,
container_tool,
):
opm_operations._opm_registry_add(
base_dir='/tmp/somedir',
Expand Down

0 comments on commit 687b30a

Please sign in to comment.