Skip to content

Commit 853b877

Browse files
authored
Merge pull request #92 from stfc/Skip_volumes_in_consumers
BUG: Skip VMs booted from volumes
2 parents a54746d + f99b8e5 commit 853b877

File tree

6 files changed

+37
-5
lines changed

6 files changed

+37
-5
lines changed

OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ def is_aq_managed_image(vm_data: VmData) -> bool:
2727
is for an Aquilon VM.
2828
"""
2929
image = openstack_api.get_image(vm_data)
30+
if not image:
31+
logger.info("No image found for %s", vm_data.virtual_machine_id)
32+
return False
33+
3034
if "AQ_OS" not in image.metadata:
3135
logger.debug("Skipping non-Aquilon image: %s", image.name)
3236
return False

OpenStack-Rabbit-Consumer/rabbit_consumer/openstack_api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import logging
2-
from typing import List
2+
from typing import List, Optional
33

44
import openstack
55
from openstack.compute.v2.image import Image
@@ -79,12 +79,15 @@ def get_server_metadata(vm_data: VmData) -> dict:
7979
return server.metadata
8080

8181

82-
def get_image(vm_data: VmData) -> Image:
82+
def get_image(vm_data: VmData) -> Optional[Image]:
8383
"""
8484
Gets the image name from Openstack for the virtual machine.
8585
"""
8686
server = get_server_details(vm_data)
8787
uuid = server.image.id
88+
if not uuid:
89+
return None
90+
8891
with OpenstackConnection() as conn:
8992
image = conn.compute.find_image(uuid)
9093
return image

OpenStack-Rabbit-Consumer/test/test_message_consumer.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ def test_is_aq_managed_image(openstack_api, vm_data):
332332
openstack_api.get_image.assert_called_once_with(vm_data)
333333

334334

335+
@patch("rabbit_consumer.message_consumer.openstack_api")
336+
def test_is_aq_managed_image_missing_image(openstack_api, vm_data):
337+
"""
338+
Test that the function returns False when the image is not AQ managed
339+
"""
340+
openstack_api.get_image.return_value = None
341+
342+
assert not is_aq_managed_image(vm_data)
343+
openstack_api.get_image.assert_called_once_with(vm_data)
344+
345+
335346
@patch("rabbit_consumer.message_consumer.VmData")
336347
@patch("rabbit_consumer.message_consumer.openstack_api")
337348
def test_is_aq_managed_image_missing_key(openstack_api, vm_data):

OpenStack-Rabbit-Consumer/test/test_openstack_api.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
check_machine_exists,
1010
get_server_details,
1111
get_server_networks,
12+
get_image,
1213
)
1314

1415

@@ -122,3 +123,16 @@ def test_get_server_networks_no_internal(server_details, vm_data):
122123

123124
result = get_server_networks(vm_data)
124125
assert not result
126+
127+
128+
@patch("rabbit_consumer.openstack_api.get_server_details")
129+
def test_get_image_no_image_id(server_details, vm_data):
130+
"""
131+
Tests that get image handles an empty image UUID
132+
usually when a volume was used instead of an image
133+
"""
134+
server_details.return_value = NonCallableMock()
135+
server_details.return_value.image.id = None
136+
137+
result = get_image(vm_data)
138+
assert not result
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.4
1+
2.3.5

charts/rabbit-consumer/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ type: application
66
# This is the chart version. This version number should be incremented each time you make changes
77
# to the chart and its templates, including the app version.
88
# Versions are expected to follow Semantic Versioning (https://semver.org/)
9-
version: 1.5.0
9+
version: 1.6.0
1010

1111
# This is the version number of the application being deployed. This version number should be
1212
# incremented each time you make changes to the application. Versions are not expected to
1313
# follow Semantic Versioning. They should reflect the version the application is using.
1414
# It is recommended to use it with quotes.
15-
appVersion: "v2.3.4"
15+
appVersion: "v2.3.5"

0 commit comments

Comments
 (0)