Skip to content

Commit

Permalink
Optimize the query to get the database path in the index image
Browse files Browse the repository at this point in the history
  • Loading branch information
mprahl authored and yashvardhannanavati committed Sep 18, 2020
1 parent 4f1cc88 commit f587675
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
6 changes: 2 additions & 4 deletions iib/workers/tasks/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,8 @@ def _get_index_database(from_index, base_dir):
:rtype: str
:raises IIBError: if any podman command fails.
"""
data = skopeo_inspect(f'docker://{from_index}')
try:
db_path = data['Labels']['operators.operatorframework.io.index.database.v1']
except KeyError:
db_path = get_image_label(from_index, 'operators.operatorframework.io.index.database.v1')
if not db_path:
raise IIBError('Index image doesn\'t have the label specifying its database location.')
_copy_files_from_image(from_index, db_path, base_dir)
local_path = os.path.join(base_dir, os.path.basename(db_path))
Expand Down
24 changes: 9 additions & 15 deletions tests/test_workers/test_tasks/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1577,13 +1577,11 @@ def test_get_missing_bundles_match_hash():
@mock.patch('subprocess.Popen')
@mock.patch('iib.workers.tasks.build.run_cmd')
@mock.patch('iib.workers.tasks.build._copy_files_from_image')
@mock.patch('iib.workers.tasks.build.skopeo_inspect')
def test_get_present_bundles(mock_si, mock_copy, mock_run_cmd, mock_popen, mock_sleep, tmpdir):
@mock.patch('iib.workers.tasks.build.get_image_label')
def test_get_present_bundles(mock_gil, mock_copy, mock_run_cmd, mock_popen, mock_sleep, tmpdir):
with open(tmpdir.join('cidfile.txt'), 'w+') as f:
f.write('container_id')
mock_si.return_value = {
'Labels': {'operators.operatorframework.io.index.database.v1': 'some-path'}
}
mock_gil.return_value = 'some-path'
mock_run_cmd.side_effect = [
'api.Registry.ListBundles',
'{"packageName": "package1", "version": "v1.0"\n}'
Expand All @@ -1606,17 +1604,15 @@ def test_get_present_bundles(mock_si, mock_copy, mock_run_cmd, mock_popen, mock_
@mock.patch('subprocess.Popen')
@mock.patch('iib.workers.tasks.build.run_cmd')
@mock.patch('iib.workers.tasks.build._copy_files_from_image')
@mock.patch('iib.workers.tasks.build.skopeo_inspect')
@mock.patch('iib.workers.tasks.build.get_image_label')
def test_get_present_bundles_grpc_not_initialize(
mock_si, mock_copy, mock_run_cmd, mock_popen, mock_sleep, mock_remove, mock_time, tmpdir,
mock_gil, mock_copy, mock_run_cmd, mock_popen, mock_sleep, mock_remove, mock_time, tmpdir,
):
with open(tmpdir.join('cidfile.txt'), 'w+') as f:
f.write('container_id')
mock_run_cmd.side_effect = ['', '', '', '', ''] * 4
mock_time.side_effect = list(range(1, 80))
mock_si.return_value = {
'Labels': {'operators.operatorframework.io.index.database.v1': 'some-path'}
}
mock_gil.return_value = 'some-path'
my_mock = mock.MagicMock()
mock_popen.return_value = my_mock
my_mock.poll.return_value = None
Expand All @@ -1631,16 +1627,14 @@ def test_get_present_bundles_grpc_not_initialize(
@mock.patch('subprocess.Popen')
@mock.patch('iib.workers.tasks.build.run_cmd')
@mock.patch('iib.workers.tasks.build._copy_files_from_image')
@mock.patch('iib.workers.tasks.build.skopeo_inspect')
@mock.patch('iib.workers.tasks.build.get_image_label')
def test_get_present_bundles_grpc_delayed_initialize(
mock_si, mock_copy, mock_run_cmd, mock_popen, mock_sleep, mock_remove, mock_time, tmpdir,
mock_gil, mock_copy, mock_run_cmd, mock_popen, mock_sleep, mock_remove, mock_time, tmpdir,
):
with open(tmpdir.join('cidfile.txt'), 'w+') as f:
f.write('container_id')
mock_time.side_effect = [i * 0.5 for i in range(1, 80)]
mock_si.return_value = {
'Labels': {'operators.operatorframework.io.index.database.v1': 'some-path'}
}
mock_gil.return_value = 'some-path'
mock_run_cmd.side_effect = [
'',
'',
Expand Down

0 comments on commit f587675

Please sign in to comment.