Skip to content

Commit 687b30a

Browse files
committed
Backup index.db to prevent opm bug consequence
1 parent 8026d8c commit 687b30a

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

iib/workers/tasks/opm_operations.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,18 @@ def _opm_registry_add(
574574
log.info('Using force to add bundle(s) to index')
575575
cmd.extend(['--overwrite-latest'])
576576

577-
run_cmd(cmd, {'cwd': base_dir}, exc_msg='Failed to add the bundles to the index image')
577+
# after commit 643fc9499222107f52b7ba3f9f3969fa36812940 index.db backup was added
578+
# due to the opm bug https://issues.redhat.com/browse/OCPBUGS-30214
579+
index_db_backup = index_db + ".backup"
580+
shutil.copyfile(index_db, index_db_backup)
581+
582+
try:
583+
run_cmd(cmd, {'cwd': base_dir}, exc_msg='Failed to add the bundles to the index image')
584+
except Exception as e:
585+
shutil.copyfile(index_db_backup, index_db)
586+
raise e
587+
finally:
588+
os.remove(index_db_backup)
578589

579590

580591
@retry(

tests/test_workers/test_tasks/test_opm_operations.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,17 @@ def test_opm_generate_dockerfile_exist(mock_run_cmd, tmpdir, dockerfile, set_ind
251251
@pytest.mark.parametrize('container_tool', (None, 'podwoman'))
252252
@mock.patch('iib.workers.tasks.utils.set_registry_token')
253253
@mock.patch('iib.workers.tasks.utils.run_cmd')
254+
@mock.patch('iib.workers.tasks.opm_operations.shutil.copyfile')
255+
@mock.patch('iib.workers.tasks.opm_operations.os.remove')
254256
def test_opm_registry_add(
255-
mock_run_cmd, mock_srt, from_index, bundles, overwrite_csv, container_tool
257+
mock_os_remove,
258+
mock_shutil_copyfile,
259+
mock_run_cmd,
260+
mock_srt,
261+
from_index,
262+
bundles,
263+
overwrite_csv,
264+
container_tool,
256265
):
257266
opm_operations._opm_registry_add(
258267
base_dir='/tmp/somedir',

0 commit comments

Comments
 (0)