From daa782f50da27410adda5116fa168ad527b708b1 Mon Sep 17 00:00:00 2001 From: George Matthews Date: Wed, 11 Dec 2024 13:03:11 +0000 Subject: [PATCH] Change uptime property to uptime days Change hypervisor uptime property to return uptime in days instead of returning the entire uptime string --- docs/user_docs/query_docs/HYPERVISORS.md | 2 +- openstackquery/enums/props/hypervisor_properties.py | 8 +++++--- tests/enums/props/test_hypervisor_properties.py | 13 +++++++------ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/docs/user_docs/query_docs/HYPERVISORS.md b/docs/user_docs/query_docs/HYPERVISORS.md index 411e396..f04ee7d 100644 --- a/docs/user_docs/query_docs/HYPERVISORS.md +++ b/docs/user_docs/query_docs/HYPERVISORS.md @@ -43,7 +43,7 @@ from enums.query.props.hypervisor_properties import HypervisorProperties | HYPERVISOR_VCPUS | `int` | "vcpus" | The number of vCPUs on this hypervisor. | | HYPERVISOR_VCPUS_USED | `int` | "vcpus_used" | The number of vCPUs currently being used on this hypervisor. | | HYPERVISOR_DISABLED_REASON | `string` | "disabled_reason" | Comment of why the hypervisor is disabled, None if not disabled | -| HYPERVISOR_UPTIME | `string` | "uptime" | The total uptime of the hypervisor and info about average load | +| HYPERVISOR_UPTIME_DAYS | `int` | "uptime" | The number of days the hypervisor has been up | Any of these properties can be used for any of the API methods that takes a property - like `select`, `where`, `sort_by` etc diff --git a/openstackquery/enums/props/hypervisor_properties.py b/openstackquery/enums/props/hypervisor_properties.py index 0435def..8c1ac0f 100644 --- a/openstackquery/enums/props/hypervisor_properties.py +++ b/openstackquery/enums/props/hypervisor_properties.py @@ -28,7 +28,7 @@ class HypervisorProperties(PropEnum): HYPERVISOR_VCPUS = auto() HYPERVISOR_VCPUS_USED = auto() HYPERVISOR_DISABLED_REASON = auto() - HYPERVISOR_UPTIME = auto() + HYPERVISOR_UPTIME_DAYS = auto() @staticmethod def _get_aliases() -> Dict: @@ -64,7 +64,7 @@ def _get_aliases() -> Dict: HypervisorProperties.HYPERVISOR_VCPUS: ["vcpus"], HypervisorProperties.HYPERVISOR_VCPUS_USED: ["vcpus_used"], HypervisorProperties.HYPERVISOR_DISABLED_REASON: ["disabled_reason"], - HypervisorProperties.HYPERVISOR_UPTIME: ["uptime"], + HypervisorProperties.HYPERVISOR_UPTIME_DAYS: ["uptime"], } @staticmethod @@ -112,7 +112,9 @@ def get_prop_mapping(prop) -> Optional[PropFunc]: HypervisorProperties.HYPERVISOR_DISABLED_REASON: lambda a: a["service"][ "disabled_reason" ], - HypervisorProperties.HYPERVISOR_UPTIME: lambda a: a["uptime"], + HypervisorProperties.HYPERVISOR_UPTIME_DAYS: lambda a: int( + a["uptime"].strip().split(" ")[2] + ), } try: return mapping[prop] diff --git a/tests/enums/props/test_hypervisor_properties.py b/tests/enums/props/test_hypervisor_properties.py index 21597bc..7b16883 100644 --- a/tests/enums/props/test_hypervisor_properties.py +++ b/tests/enums/props/test_hypervisor_properties.py @@ -285,15 +285,16 @@ def test_hypervisor_disabled_reason_serialization(val): @pytest.mark.parametrize( "val", [ - "hypervisor_uptime", - "Hypervisor_Uptime", - "HyPeRvIsOr_UpTiMe", + "HYPERVISOR_UPTIME_DAYS", + "Hypervisor_Uptime_Days", + "HyPeRvIsOr_UpTiMe_DaYs", ], ) -def test_hypervisor_uptime_serialization(val): +def test_hypervisor_uptime_days_serialization(val): """ - Tests that variants of HYPERVISOR_UPTIME can be serialized + Tests that variants of HYPERVISOR_UPTIME_DAYS can be serialized """ assert ( - HypervisorProperties.from_string(val) is HypervisorProperties.HYPERVISOR_UPTIME + HypervisorProperties.from_string(val) + is HypervisorProperties.HYPERVISOR_UPTIME_DAYS )