From ffeb1e2afdd712c6aef7729f02602090481177d4 Mon Sep 17 00:00:00 2001 From: George Matthews Date: Tue, 10 Dec 2024 11:30:26 +0000 Subject: [PATCH] Change server prop hv id to hv name Server properties previously using host id as hypervisor id however this didn't match the hypervisor id --- docs/user_docs/query_docs/SERVERS.md | 4 ++-- openstackquery/enums/props/server_properties.py | 6 +++--- openstackquery/mappings/hypervisor_mapping.py | 2 +- openstackquery/mappings/server_mapping.py | 2 +- tests/enums/props/test_server_properties.py | 7 ++++--- tests/mappings/test_hypervisor_mapping.py | 2 +- tests/mappings/test_server_mapping.py | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/user_docs/query_docs/SERVERS.md b/docs/user_docs/query_docs/SERVERS.md index 61b2e1c..f15f986 100644 --- a/docs/user_docs/query_docs/SERVERS.md +++ b/docs/user_docs/query_docs/SERVERS.md @@ -30,7 +30,7 @@ from enums.query.props.server_properties import ServerProperties | Property Enum | Type | Aliases | Description | |--------------------------|--------------|-------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | FLAVOR_ID | `string` | `None` | The ID of the Flavor the Server is using | -| HYPERVISOR_ID | `string` | `None` | The ID of the Hypervisor the Server is being hosted on | +| HYPERVISOR_NAME | `string` | `None` | Name of the Hypervisor the Server is being hosted on | | IMAGE_ID | `string` | `None` | The ID of the Image the Server is using | | PROJECT_ID | `string` | `None` | The ID of the Project the Server is associated with | | SERVER_CREATION_DATE | `string` (x) | "created_at" | Timestamp of when the server was created. | @@ -69,7 +69,7 @@ The following shared-common properties are listed below (as well as the Query ob | ServerProperties.PROJECT_ID | ProjectProperties.PROJECT_ID | Many-to-One | `ServerQuery` to `ProjectQuery` | [PROJECTS.md](PROJECTS.md) | | ServerProperties.FLAVOR_ID | FlavorProperties.FLAVOR_ID | Many-to-One | `ServerQuery` to `FlavorQuery` | [FLAVORS.md](FLAVORS.md) | | ServerProperties.IMAGE_ID | ImageProperties.IMAGE_ID | Many-to-One | `ServerQuery` to `ImageQuery` | [IMAGES.md](IMAGES.md) | -| ServerProperties.HYPERVISOR_ID | HypervisorProperties.HYPERVISOR_ID | Many-to-One | `ServerQuery` to `HypervisorQuery` | [HYPERVISORS.md](HYPERVISORS.md) | +| ServerProperties.HYPERVISOR_NAME | HypervisorProperties.HYPERVISOR_NAME | Many-to-One | `ServerQuery` to `HypervisorQuery` | [HYPERVISORS.md](HYPERVISORS.md) | diff --git a/openstackquery/enums/props/server_properties.py b/openstackquery/enums/props/server_properties.py index b45a610..fac5623 100644 --- a/openstackquery/enums/props/server_properties.py +++ b/openstackquery/enums/props/server_properties.py @@ -11,7 +11,7 @@ class ServerProperties(PropEnum): """ FLAVOR_ID = auto() - HYPERVISOR_ID = auto() + HYPERVISOR_NAME = auto() IMAGE_ID = auto() PROJECT_ID = auto() SERVER_CREATION_DATE = auto() @@ -29,7 +29,7 @@ def _get_aliases(): A method that returns all valid string alias mappings """ return { - ServerProperties.HYPERVISOR_ID: ["host_id", "hv_id"], + ServerProperties.HYPERVISOR_NAME: ["hv_name", "hypervisor_name"], ServerProperties.SERVER_CREATION_DATE: ["created_at"], ServerProperties.SERVER_DESCRIPTION: [ "description", @@ -53,7 +53,7 @@ def get_prop_mapping(prop): """ mapping = { ServerProperties.USER_ID: lambda a: a["user_id"], - ServerProperties.HYPERVISOR_ID: lambda a: a["host_id"], + ServerProperties.HYPERVISOR_NAME: lambda a: a["hypervisor_hostname"], ServerProperties.SERVER_ID: lambda a: a["id"], ServerProperties.SERVER_NAME: lambda a: a["name"], ServerProperties.SERVER_DESCRIPTION: lambda a: a["description"], diff --git a/openstackquery/mappings/hypervisor_mapping.py b/openstackquery/mappings/hypervisor_mapping.py index daa556e..3e01f8e 100644 --- a/openstackquery/mappings/hypervisor_mapping.py +++ b/openstackquery/mappings/hypervisor_mapping.py @@ -35,7 +35,7 @@ def get_chain_mappings(): Should return a dictionary containing property pairs mapped to query mappings. This is used to define how to chain results from this query to other possible queries """ - return {HypervisorProperties.HYPERVISOR_ID: ServerProperties.HYPERVISOR_ID} + return {HypervisorProperties.HYPERVISOR_NAME: ServerProperties.HYPERVISOR_NAME} @staticmethod def get_runner_mapping() -> Type[RunnerWrapper]: diff --git a/openstackquery/mappings/server_mapping.py b/openstackquery/mappings/server_mapping.py index 3328cc4..0cc189b 100644 --- a/openstackquery/mappings/server_mapping.py +++ b/openstackquery/mappings/server_mapping.py @@ -47,7 +47,7 @@ def get_chain_mappings(): ServerProperties.PROJECT_ID: ProjectProperties.PROJECT_ID, ServerProperties.FLAVOR_ID: FlavorProperties.FLAVOR_ID, ServerProperties.IMAGE_ID: ImageProperties.IMAGE_ID, - ServerProperties.HYPERVISOR_ID: HypervisorProperties.HYPERVISOR_ID, + ServerProperties.HYPERVISOR_NAME: HypervisorProperties.HYPERVISOR_NAME, } @staticmethod diff --git a/tests/enums/props/test_server_properties.py b/tests/enums/props/test_server_properties.py index 9847a39..e4b3da8 100644 --- a/tests/enums/props/test_server_properties.py +++ b/tests/enums/props/test_server_properties.py @@ -45,13 +45,14 @@ def test_flavor_id_serialization(val): @pytest.mark.parametrize( - "val", ["hypervisor_id", "Hypervisor_ID", "HyPerVisor_ID", "host_id", "hv_id"] + "val", + ["hypervisor_name", "Hypervisor_NAME", "HyPerVisor_NamE", "hv_name", "HV_name"], ) def test_hypervisor_id_serialization(val): """ - Tests that variants of HYPERVISOR_ID can be serialized + Tests that variants of HYPERVISOR_NAME can be serialized """ - assert ServerProperties.from_string(val) is ServerProperties.HYPERVISOR_ID + assert ServerProperties.from_string(val) is ServerProperties.HYPERVISOR_NAME @pytest.mark.parametrize("val", ["image_id", "Image_ID", "ImaGe_iD"]) diff --git a/tests/mappings/test_hypervisor_mapping.py b/tests/mappings/test_hypervisor_mapping.py index 1efc0d0..6cf0a4c 100644 --- a/tests/mappings/test_hypervisor_mapping.py +++ b/tests/mappings/test_hypervisor_mapping.py @@ -102,7 +102,7 @@ def test_get_chain_mappings(): Tests get_chain_mapping outputs correctly """ expected_mappings = { - HypervisorProperties.HYPERVISOR_ID: ServerProperties.HYPERVISOR_ID, + HypervisorProperties.HYPERVISOR_NAME: ServerProperties.HYPERVISOR_NAME, } assert HypervisorMapping.get_chain_mappings() == expected_mappings diff --git a/tests/mappings/test_server_mapping.py b/tests/mappings/test_server_mapping.py index b1f0d28..6488202 100644 --- a/tests/mappings/test_server_mapping.py +++ b/tests/mappings/test_server_mapping.py @@ -210,7 +210,7 @@ def test_get_chain_mappings(): ServerProperties.PROJECT_ID: ProjectProperties.PROJECT_ID, ServerProperties.FLAVOR_ID: FlavorProperties.FLAVOR_ID, ServerProperties.IMAGE_ID: ImageProperties.IMAGE_ID, - ServerProperties.HYPERVISOR_ID: HypervisorProperties.HYPERVISOR_ID, + ServerProperties.HYPERVISOR_NAME: HypervisorProperties.HYPERVISOR_NAME, } assert ServerMapping.get_chain_mappings() == expected_mappings