Skip to content

Commit 5a85dc6

Browse files
authored
Merge pull request #72 from stfc/Add_machine_name_to_metadata
Add machine name to metadata
2 parents 34a6e5f + abcf6c5 commit 5a85dc6

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def handle_create_machine(rabbit_message: RabbitMessage) -> None:
151151
aq_api.aq_manage(network_details, image_meta)
152152
aq_api.aq_make(network_details, image_meta)
153153

154-
add_hostname_to_metadata(vm_data, network_details)
154+
add_aq_details_to_metadata(vm_data, network_details)
155155

156156
logger.info(
157157
"=== Finished Aquilon creation hook for VM %s ===", vm_data.virtual_machine_id
@@ -188,7 +188,7 @@ def handle_machine_delete(rabbit_message: RabbitMessage) -> None:
188188
)
189189

190190

191-
def add_hostname_to_metadata(
191+
def add_aq_details_to_metadata(
192192
vm_data: VmData, network_details: List[OpenstackAddress]
193193
) -> None:
194194
"""
@@ -203,7 +203,11 @@ def add_hostname_to_metadata(
203203
return
204204

205205
hostnames = [i.hostname for i in network_details]
206-
metadata = {"HOSTNAMES": ",".join(hostnames), "AQ_STATUS": "SUCCESS"}
206+
metadata = {
207+
"HOSTNAMES": ",".join(hostnames),
208+
"AQ_STATUS": "SUCCESS",
209+
"AQ_MACHINE": aq_api.search_machine_by_serial(vm_data),
210+
}
207211
openstack_api.update_metadata(vm_data, metadata)
208212

209213

OpenStack-Rabbit-Consumer/test/test_message_consumer.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from rabbit_consumer.message_consumer import (
1616
on_message,
1717
initiate_consumer,
18-
add_hostname_to_metadata,
18+
add_aq_details_to_metadata,
1919
handle_create_machine,
2020
handle_machine_delete,
2121
SUPPORTED_MESSAGE_TYPES,
@@ -155,20 +155,26 @@ def test_initiate_consumer_actual_consumption(rabbitpy, message_mock, _):
155155

156156

157157
@patch("rabbit_consumer.message_consumer.openstack_api")
158-
def test_add_hostname_to_metadata_machine_exists(
159-
openstack_api, vm_data, openstack_address_list
158+
@patch("rabbit_consumer.message_consumer.aq_api")
159+
def test_add_aq_details_to_metadata(
160+
aq_api, openstack_api, vm_data, openstack_address_list
160161
):
161162
"""
162163
Test that the function adds the hostname to the metadata when the machine exists
163164
"""
164165
openstack_api.check_machine_exists.return_value = True
165-
add_hostname_to_metadata(vm_data, openstack_address_list)
166+
add_aq_details_to_metadata(vm_data, openstack_address_list)
166167

167-
openstack_api.check_machine_exists.assert_called_once_with(vm_data)
168168
hostnames = [i.hostname for i in openstack_address_list]
169-
openstack_api.update_metadata.assert_called_with(
170-
vm_data, {"HOSTNAMES": ",".join(hostnames), "AQ_STATUS": "SUCCESS"}
171-
)
169+
expected = {
170+
"HOSTNAMES": ",".join(hostnames),
171+
"AQ_STATUS": "SUCCESS",
172+
"AQ_MACHINE": aq_api.search_machine_by_serial.return_value,
173+
}
174+
175+
openstack_api.check_machine_exists.assert_called_once_with(vm_data)
176+
aq_api.search_machine_by_serial.assert_called_once_with(vm_data)
177+
openstack_api.update_metadata.assert_called_with(vm_data, expected)
172178

173179

174180
@patch("rabbit_consumer.message_consumer.openstack_api")
@@ -177,7 +183,7 @@ def test_add_hostname_to_metadata_machine_does_not_exist(openstack_api, vm_data)
177183
Test that the function does not add the hostname to the metadata when the machine does not exist
178184
"""
179185
openstack_api.check_machine_exists.return_value = False
180-
add_hostname_to_metadata(vm_data, [])
186+
add_aq_details_to_metadata(vm_data, [])
181187

182188
openstack_api.check_machine_exists.assert_called_once_with(vm_data)
183189
openstack_api.update_metadata.assert_not_called()
@@ -200,7 +206,7 @@ def test_handle_create_machine_skips_invalid(openstack_api, machine_valid):
200206

201207
@patch("rabbit_consumer.message_consumer.openstack_api")
202208
@patch("rabbit_consumer.message_consumer.aq_api")
203-
@patch("rabbit_consumer.message_consumer.add_hostname_to_metadata")
209+
@patch("rabbit_consumer.message_consumer.add_aq_details_to_metadata")
204210
# pylint: disable=too-many-arguments
205211
def test_consume_create_machine_hostnames_good_path(
206212
metadata, aq_api, openstack, rabbit_message, image_metadata
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.0
1+
2.2.0

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.2.0
9+
version: 1.3.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.1.0"
15+
appVersion: "v2.2.0"

0 commit comments

Comments
 (0)