@@ -94,7 +94,7 @@ def test_pull_index_db_artifact_imagestream_enabled_cache_not_synced(
9494 mock_get_indexdb_artifact_pullspec .assert_called_once_with (from_index )
9595 mock_get_oras_artifact .assert_called_once_with (artifact_ref , temp_dir )
9696 mock_log .info .assert_any_call ('ImageStream cache is enabled. Checking cache sync status.' )
97- mock_log .info .assert_any_call ('Index.db cache is not synced. Refreshing and pulling from Quay .' )
97+ mock_log .info .assert_any_call ('Index.db cache is not synced. Refreshing cache .' )
9898
9999
100100@patch ('iib.workers.tasks.containerized_utils.get_worker_config' )
@@ -162,6 +162,126 @@ def test_pull_index_db_artifact_default_config_behaves_as_disabled(
162162 mock_get_oras_artifact .assert_called_once_with (artifact_ref , temp_dir )
163163
164164
165+ @patch ('iib.workers.tasks.containerized_utils.get_worker_config' )
166+ @patch ('iib.workers.tasks.containerized_utils.log' )
167+ @patch ('iib.workers.tasks.containerized_utils.refresh_indexdb_cache_for_image' )
168+ @patch ('iib.workers.tasks.containerized_utils.verify_indexdb_cache_for_image' )
169+ @patch ('iib.workers.tasks.containerized_utils.get_indexdb_artifact_pullspec' )
170+ @patch ('iib.workers.tasks.containerized_utils.get_imagestream_artifact_pullspec' )
171+ @patch ('iib.workers.tasks.containerized_utils.get_oras_artifact' )
172+ def test_pull_index_db_artifact_verify_cache_fails_falls_back_to_quay (
173+ mock_get_oras_artifact ,
174+ mock_get_imagestream_artifact_pullspec ,
175+ mock_get_indexdb_artifact_pullspec ,
176+ mock_verify_cache ,
177+ mock_refresh_cache ,
178+ mock_log ,
179+ mock_get_worker_config ,
180+ ):
181+ """When ImageStream verify raises IIBError, fall back to Quay."""
182+ mock_get_worker_config .return_value = {'iib_use_imagestream_cache' : True }
183+ error = IIBError ('imagestreams.image.openshift.io not found' )
184+ mock_verify_cache .side_effect = error
185+
186+ from_index = 'quay.io/ns/index-image@sha256:abc'
187+ temp_dir = '/tmp/some-dir'
188+ artifact_ref = 'quay.io/ns/index-image-indexdb:v4.19'
189+ artifact_dir = '/tmp/artifact-dir'
190+
191+ mock_get_indexdb_artifact_pullspec .return_value = artifact_ref
192+ mock_get_oras_artifact .return_value = artifact_dir
193+
194+ result = pull_index_db_artifact (from_index , temp_dir )
195+
196+ assert result == artifact_dir
197+ mock_verify_cache .assert_called_once_with (from_index )
198+ mock_get_indexdb_artifact_pullspec .assert_called_once_with (from_index )
199+ mock_get_oras_artifact .assert_called_once_with (artifact_ref , temp_dir )
200+ mock_log .warning .assert_called_once_with (
201+ 'ImageStream cache access failed, falling back to Quay: %s' , error
202+ )
203+
204+
205+ @patch ('iib.workers.tasks.containerized_utils.get_worker_config' )
206+ @patch ('iib.workers.tasks.containerized_utils.log' )
207+ @patch ('iib.workers.tasks.containerized_utils.refresh_indexdb_cache_for_image' )
208+ @patch ('iib.workers.tasks.containerized_utils.verify_indexdb_cache_for_image' )
209+ @patch ('iib.workers.tasks.containerized_utils.get_indexdb_artifact_pullspec' )
210+ @patch ('iib.workers.tasks.containerized_utils.get_imagestream_artifact_pullspec' )
211+ @patch ('iib.workers.tasks.containerized_utils.get_oras_artifact' )
212+ def test_pull_index_db_artifact_imagestream_pull_fails_falls_back_to_quay (
213+ mock_get_oras_artifact ,
214+ mock_get_imagestream_artifact_pullspec ,
215+ mock_get_indexdb_artifact_pullspec ,
216+ mock_verify_cache ,
217+ mock_refresh_cache ,
218+ mock_log ,
219+ mock_get_worker_config ,
220+ ):
221+ """When ImageStream pull raises IIBError, fall back to Quay."""
222+ mock_get_worker_config .return_value = {'iib_use_imagestream_cache' : True }
223+ mock_verify_cache .return_value = True
224+ mock_get_imagestream_artifact_pullspec .return_value = 'imagestream-ref'
225+ error = IIBError ('Failed to pull from ImageStream registry' )
226+ artifact_ref = 'quay.io/ns/index-image-indexdb:v4.19'
227+ artifact_dir = '/tmp/artifact-dir'
228+ mock_get_oras_artifact .side_effect = [error , artifact_dir ]
229+ mock_get_indexdb_artifact_pullspec .return_value = artifact_ref
230+
231+ from_index = 'quay.io/ns/index-image@sha256:abc'
232+ temp_dir = '/tmp/some-dir'
233+
234+ result = pull_index_db_artifact (from_index , temp_dir )
235+
236+ assert result == artifact_dir
237+ mock_get_oras_artifact .assert_any_call ('imagestream-ref' , temp_dir )
238+ mock_get_oras_artifact .assert_any_call (artifact_ref , temp_dir )
239+ mock_log .warning .assert_called_once_with (
240+ 'ImageStream cache access failed, falling back to Quay: %s' , error
241+ )
242+
243+
244+ @patch ('iib.workers.tasks.containerized_utils.get_worker_config' )
245+ @patch ('iib.workers.tasks.containerized_utils.log' )
246+ @patch ('iib.workers.tasks.containerized_utils.refresh_indexdb_cache_for_image' )
247+ @patch ('iib.workers.tasks.containerized_utils.verify_indexdb_cache_for_image' )
248+ @patch ('iib.workers.tasks.containerized_utils.get_indexdb_artifact_pullspec' )
249+ @patch ('iib.workers.tasks.containerized_utils.get_imagestream_artifact_pullspec' )
250+ @patch ('iib.workers.tasks.containerized_utils.get_oras_artifact' )
251+ def test_pull_index_db_artifact_refresh_cache_fails_falls_back_to_quay (
252+ mock_get_oras_artifact ,
253+ mock_get_imagestream_artifact_pullspec ,
254+ mock_get_indexdb_artifact_pullspec ,
255+ mock_verify_cache ,
256+ mock_refresh_cache ,
257+ mock_log ,
258+ mock_get_worker_config ,
259+ ):
260+ """When cache refresh raises IIBError, fall back to Quay."""
261+ mock_get_worker_config .return_value = {'iib_use_imagestream_cache' : True }
262+ mock_verify_cache .return_value = False
263+ error = IIBError ('oc import-image failed' )
264+ mock_refresh_cache .side_effect = error
265+
266+ from_index = 'quay.io/ns/index-image@sha256:abc'
267+ temp_dir = '/tmp/some-dir'
268+ artifact_ref = 'quay.io/ns/index-image-indexdb:v4.19'
269+ artifact_dir = '/tmp/artifact-dir'
270+
271+ mock_get_indexdb_artifact_pullspec .return_value = artifact_ref
272+ mock_get_oras_artifact .return_value = artifact_dir
273+
274+ result = pull_index_db_artifact (from_index , temp_dir )
275+
276+ assert result == artifact_dir
277+ mock_refresh_cache .assert_called_once_with (from_index )
278+ mock_get_indexdb_artifact_pullspec .assert_called_once_with (from_index )
279+ mock_get_oras_artifact .assert_called_once_with (artifact_ref , temp_dir )
280+ mock_log .warning .assert_called_once_with (
281+ 'ImageStream cache access failed, falling back to Quay: %s' , error
282+ )
283+
284+
165285@patch ('iib.workers.tasks.containerized_utils.log' )
166286def test_write_build_metadata_creates_expected_json (mock_log , tmp_path ):
167287 """write_build_metadata should create JSON file with expected content."""
0 commit comments