Skip to content

Commit b38f3ce

Browse files
committed
Update hypervisor runner test
Update hypervisor runner test to include new resource usage calls
1 parent c387001 commit b38f3ce

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

tests/runners/test_hypervisor_runner.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,51 @@ def test_parse_query_params(instance):
2424
)
2525

2626

27+
@patch("openstackquery.runners.hypervisor_runner.json.loads")
2728
@patch("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query")
2829
def test_run_query_no_server_filters(
29-
mock_run_paginated_query, instance, mock_marker_prop_func
30+
mock_run_paginated_query,
31+
mock_json_loads,
32+
instance,
33+
mock_marker_prop_func,
3034
):
3135
"""
3236
Tests that run_query method works expectedly with no server-side filters
3337
"""
38+
39+
mock_hv1 = MagicMock()
40+
mock_hv2 = MagicMock()
41+
42+
mock_hv1.return_value = {"id": "1"}
43+
mock_hv2.return_value = {"id": "2"}
44+
3445
mock_hv_list = mock_run_paginated_query.return_value = [
35-
"hv1",
36-
"hv2",
37-
"hv3",
46+
mock_hv1,
47+
mock_hv2,
3848
]
3949

4050
mock_connection = MagicMock()
4151

52+
vcpu_resource_class = MagicMock()
53+
vcpu_resource_class.resource_class = "VCPU"
54+
vcpu_resource_class.total = 128
55+
memory_resource_class = MagicMock()
56+
memory_resource_class.resource_class = "MEMORY_MB"
57+
memory_resource_class.total = 515264
58+
disk_resource_class = MagicMock()
59+
disk_resource_class.resource_class = "DISK_GB"
60+
disk_resource_class.total = 3510
61+
62+
mock_connection.placement.resource_provider_inventories.return_value = (
63+
vcpu_resource_class,
64+
memory_resource_class,
65+
disk_resource_class,
66+
)
67+
68+
mock_json_loads.return_value = {
69+
"usages": {"VCPU": 4, "MEMORY_MB": 8192, "DISK_GB": 10}
70+
}
71+
4272
res = instance.run_query(
4373
mock_connection,
4474
filter_kwargs=None,
@@ -49,4 +79,18 @@ def test_run_query_no_server_filters(
4979
mock_marker_prop_func,
5080
{"details": True},
5181
)
82+
83+
assert mock_json_loads.call_count == 2
84+
5285
assert res == mock_hv_list
86+
87+
assert mock_hv1.resources == {
88+
"VCPU": {"total": 128, "usage": 4, "free": 124},
89+
"MEMORY_MB": {"total": 515264, "usage": 8192, "free": 507072},
90+
"DISK_GB": {"total": 3510, "usage": 10, "free": 3500},
91+
}
92+
assert mock_hv2.resources == {
93+
"VCPU": {"total": 128, "usage": 4, "free": 124},
94+
"MEMORY_MB": {"total": 515264, "usage": 8192, "free": 507072},
95+
"DISK_GB": {"total": 3510, "usage": 10, "free": 3500},
96+
}

0 commit comments

Comments
 (0)