Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import List
from typing import List, Optional

import openstack
from openstack.compute.v2.image import Image
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions OpenStack-Rabbit-Consumer/test/test_message_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 14 additions & 0 deletions OpenStack-Rabbit-Consumer/test/test_openstack_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
check_machine_exists,
get_server_details,
get_server_networks,
get_image,
)


Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion OpenStack-Rabbit-Consumer/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.4
2.3.5
4 changes: 2 additions & 2 deletions charts/rabbit-consumer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"