@@ -24,21 +24,51 @@ def test_parse_query_params(instance):
24
24
)
25
25
26
26
27
+ @patch ("openstackquery.runners.hypervisor_runner.json.loads" )
27
28
@patch ("openstackquery.runners.runner_utils.RunnerUtils.run_paginated_query" )
28
29
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 ,
30
34
):
31
35
"""
32
36
Tests that run_query method works expectedly with no server-side filters
33
37
"""
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
+
34
45
mock_hv_list = mock_run_paginated_query .return_value = [
35
- "hv1" ,
36
- "hv2" ,
37
- "hv3" ,
46
+ mock_hv1 ,
47
+ mock_hv2 ,
38
48
]
39
49
40
50
mock_connection = MagicMock ()
41
51
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
+
42
72
res = instance .run_query (
43
73
mock_connection ,
44
74
filter_kwargs = None ,
@@ -49,4 +79,18 @@ def test_run_query_no_server_filters(
49
79
mock_marker_prop_func ,
50
80
{"details" : True },
51
81
)
82
+
83
+ assert mock_json_loads .call_count == 2
84
+
52
85
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