Skip to content

Commit

Permalink
Merge pull request #72 from stfc/Add_machine_name_to_metadata
Browse files Browse the repository at this point in the history
Add machine name to metadata
  • Loading branch information
meoflynn authored Jun 9, 2023
2 parents 34a6e5f + abcf6c5 commit 5a85dc6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
10 changes: 7 additions & 3 deletions OpenStack-Rabbit-Consumer/rabbit_consumer/message_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def handle_create_machine(rabbit_message: RabbitMessage) -> None:
aq_api.aq_manage(network_details, image_meta)
aq_api.aq_make(network_details, image_meta)

add_hostname_to_metadata(vm_data, network_details)
add_aq_details_to_metadata(vm_data, network_details)

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


def add_hostname_to_metadata(
def add_aq_details_to_metadata(
vm_data: VmData, network_details: List[OpenstackAddress]
) -> None:
"""
Expand All @@ -203,7 +203,11 @@ def add_hostname_to_metadata(
return

hostnames = [i.hostname for i in network_details]
metadata = {"HOSTNAMES": ",".join(hostnames), "AQ_STATUS": "SUCCESS"}
metadata = {
"HOSTNAMES": ",".join(hostnames),
"AQ_STATUS": "SUCCESS",
"AQ_MACHINE": aq_api.search_machine_by_serial(vm_data),
}
openstack_api.update_metadata(vm_data, metadata)


Expand Down
26 changes: 16 additions & 10 deletions OpenStack-Rabbit-Consumer/test/test_message_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from rabbit_consumer.message_consumer import (
on_message,
initiate_consumer,
add_hostname_to_metadata,
add_aq_details_to_metadata,
handle_create_machine,
handle_machine_delete,
SUPPORTED_MESSAGE_TYPES,
Expand Down Expand Up @@ -155,20 +155,26 @@ def test_initiate_consumer_actual_consumption(rabbitpy, message_mock, _):


@patch("rabbit_consumer.message_consumer.openstack_api")
def test_add_hostname_to_metadata_machine_exists(
openstack_api, vm_data, openstack_address_list
@patch("rabbit_consumer.message_consumer.aq_api")
def test_add_aq_details_to_metadata(
aq_api, openstack_api, vm_data, openstack_address_list
):
"""
Test that the function adds the hostname to the metadata when the machine exists
"""
openstack_api.check_machine_exists.return_value = True
add_hostname_to_metadata(vm_data, openstack_address_list)
add_aq_details_to_metadata(vm_data, openstack_address_list)

openstack_api.check_machine_exists.assert_called_once_with(vm_data)
hostnames = [i.hostname for i in openstack_address_list]
openstack_api.update_metadata.assert_called_with(
vm_data, {"HOSTNAMES": ",".join(hostnames), "AQ_STATUS": "SUCCESS"}
)
expected = {
"HOSTNAMES": ",".join(hostnames),
"AQ_STATUS": "SUCCESS",
"AQ_MACHINE": aq_api.search_machine_by_serial.return_value,
}

openstack_api.check_machine_exists.assert_called_once_with(vm_data)
aq_api.search_machine_by_serial.assert_called_once_with(vm_data)
openstack_api.update_metadata.assert_called_with(vm_data, expected)


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

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

@patch("rabbit_consumer.message_consumer.openstack_api")
@patch("rabbit_consumer.message_consumer.aq_api")
@patch("rabbit_consumer.message_consumer.add_hostname_to_metadata")
@patch("rabbit_consumer.message_consumer.add_aq_details_to_metadata")
# pylint: disable=too-many-arguments
def test_consume_create_machine_hostnames_good_path(
metadata, aq_api, openstack, rabbit_message, image_metadata
Expand Down
2 changes: 1 addition & 1 deletion OpenStack-Rabbit-Consumer/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0
2.2.0
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.2.0
version: 1.3.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.1.0"
appVersion: "v2.2.0"

0 comments on commit 5a85dc6

Please sign in to comment.