diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py index a9eba552..9acc2fdb 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py @@ -27,6 +27,10 @@ def is_aq_managed_image(vm_data: VmData) -> bool: is for an Aquilon VM. """ image = openstack_api.get_image(vm_data) + if not image: + logger.info("No image found for %s", vm_data.virtual_machine_id) + return False + if "AQ_OS" not in image.metadata: logger.debug("Skipping non-Aquilon image: %s", image.name) return False diff --git a/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py b/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py index 6e27094a..f582a5f7 100644 --- a/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py +++ b/OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py @@ -1,5 +1,5 @@ import logging -from typing import List +from typing import List, Optional import openstack from openstack.compute.v2.image import Image @@ -79,12 +79,15 @@ def get_server_metadata(vm_data: VmData) -> dict: return server.metadata -def get_image(vm_data: VmData) -> Image: +def get_image(vm_data: VmData) -> Optional[Image]: """ Gets the image name from Openstack for the virtual machine. """ server = get_server_details(vm_data) uuid = server.image.id + if not uuid: + return None + with OpenstackConnection() as conn: image = conn.compute.find_image(uuid) return image diff --git a/OpenStack-Rabbit-Consumer/test/test_message_consumer.py b/OpenStack-Rabbit-Consumer/test/test_message_consumer.py index 10e92501..409284ee 100644 --- a/OpenStack-Rabbit-Consumer/test/test_message_consumer.py +++ b/OpenStack-Rabbit-Consumer/test/test_message_consumer.py @@ -332,6 +332,17 @@ def test_is_aq_managed_image(openstack_api, vm_data): openstack_api.get_image.assert_called_once_with(vm_data) +@patch("rabbit_consumer.message_consumer.openstack_api") +def test_is_aq_managed_image_missing_image(openstack_api, vm_data): + """ + Test that the function returns False when the image is not AQ managed + """ + openstack_api.get_image.return_value = None + + assert not is_aq_managed_image(vm_data) + openstack_api.get_image.assert_called_once_with(vm_data) + + @patch("rabbit_consumer.message_consumer.VmData") @patch("rabbit_consumer.message_consumer.openstack_api") def test_is_aq_managed_image_missing_key(openstack_api, vm_data): diff --git a/OpenStack-Rabbit-Consumer/test/test_openstack_api.py b/OpenStack-Rabbit-Consumer/test/test_openstack_api.py index a150eee1..a6274f08 100644 --- a/OpenStack-Rabbit-Consumer/test/test_openstack_api.py +++ b/OpenStack-Rabbit-Consumer/test/test_openstack_api.py @@ -9,6 +9,7 @@ check_machine_exists, get_server_details, get_server_networks, + get_image, ) @@ -122,3 +123,16 @@ def test_get_server_networks_no_internal(server_details, vm_data): result = get_server_networks(vm_data) assert not result + + +@patch("rabbit_consumer.openstack_api.get_server_details") +def test_get_image_no_image_id(server_details, vm_data): + """ + Tests that get image handles an empty image UUID + usually when a volume was used instead of an image + """ + server_details.return_value = NonCallableMock() + server_details.return_value.image.id = None + + result = get_image(vm_data) + assert not result diff --git a/OpenStack-Rabbit-Consumer/version.txt b/OpenStack-Rabbit-Consumer/version.txt index 3f684d2d..cc6c9a49 100644 --- a/OpenStack-Rabbit-Consumer/version.txt +++ b/OpenStack-Rabbit-Consumer/version.txt @@ -1 +1 @@ -2.3.4 +2.3.5 diff --git a/charts/rabbit-consumer/Chart.yaml b/charts/rabbit-consumer/Chart.yaml index 214217c9..d214cab3 100644 --- a/charts/rabbit-consumer/Chart.yaml +++ b/charts/rabbit-consumer/Chart.yaml @@ -6,10 +6,10 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 1.5.0 +version: 1.6.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "v2.3.4" +appVersion: "v2.3.5"