From adb6139edf758b578224281efbbf2b90e342a439 Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Fri, 31 Jul 2026 21:53:24 +0000 Subject: [PATCH] fix(oci): raise ImageNotFoundError when daily image lookup has no match Previously, daily_image raised an unhelpful IndexError when no matching image was found after filtering out aarch64 and GPU images. It now raises the more descriptive ImageNotFoundError carrying the release. Also bumps VERSION to 1!11.1.3. --- VERSION | 2 +- pycloudlib/oci/cloud.py | 6 +++++- tests/unit_tests/oci/test_cloud.py | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 4dd7a042..a1015f6c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1!11.1.5 +1!11.1.6 diff --git a/pycloudlib/oci/cloud.py b/pycloudlib/oci/cloud.py index 4cf06856..e74d6012 100644 --- a/pycloudlib/oci/cloud.py +++ b/pycloudlib/oci/cloud.py @@ -14,6 +14,7 @@ from pycloudlib.config import ConfigFile from pycloudlib.errors import ( CloudSetupError, + ImageNotFoundError, InstanceNotFoundError, InvalidTagNameError, PycloudlibException, @@ -198,7 +199,10 @@ def daily_image( for i in image_response.data if "aarch64" not in i.display_name and "GPU" not in i.display_name ] - image_id = matching_image[0].id + try: + image_id = matching_image[0].id + except IndexError: + raise ImageNotFoundError(release=release) return image_id def image_serial(self, image_id): diff --git a/tests/unit_tests/oci/test_cloud.py b/tests/unit_tests/oci/test_cloud.py index d9c1cc7d..cff9f701 100644 --- a/tests/unit_tests/oci/test_cloud.py +++ b/tests/unit_tests/oci/test_cloud.py @@ -9,6 +9,7 @@ import toml from pycloudlib.errors import ( + ImageNotFoundError, InstanceNotFoundError, InvalidTagNameError, PycloudlibException, @@ -223,6 +224,23 @@ def test_invalid_release(self, oci_cloud): with pytest.raises(ValueError, match="Invalid release"): oci_cloud.daily_image("invalid-release") + def test_daily_image_not_found(self, oci_cloud): + """Test daily_image raises ImageNotFoundError when no matching image is found.""" + oci_cloud.compute_client.list_images.return_value = mock.Mock(data=[]) + with pytest.raises(ImageNotFoundError): + oci_cloud.daily_image("20.04") + + def test_daily_image_filters_aarch64_and_gpu(self, oci_cloud): + """Test daily_image filters out aarch64 and GPU images and picks the first match.""" + oci_cloud.compute_client.list_images.return_value = mock.Mock( + data=[ + mock.Mock(display_name="Canonical Ubuntu 20.04 aarch64", id="aarch64-id"), + mock.Mock(display_name="Canonical Ubuntu 20.04 GPU", id="gpu-id"), + mock.Mock(display_name="Canonical Ubuntu 20.04", id="image-id"), + ] + ) + assert oci_cloud.daily_image("20.04") == "image-id" + def test_image_serial_not_implemented(self, oci_cloud): """Test image_serial raises NotImplementedError.""" with pytest.raises(NotImplementedError):