22Integration tests for the get_metrics plugin
33"""
44
5- import os
6-
75import pytest
86
97from linodecli .exit_codes import ExitCodes
@@ -20,154 +18,205 @@ def test_missing_required_args():
2018 """Test error handling for missing required arguments"""
2119 # Missing entity-ids
2220 exec_failing_test_command (
23- BASE_CMD + [
21+ BASE_CMD
22+ + [
2423 "nodebalancer" ,
25- "--metrics" , "cpu_usage:avg" ,
26- "--duration" , "15" ,
27- "--duration-unit" , "min"
24+ "--metrics" ,
25+ "cpu_usage:avg" ,
26+ "--duration" ,
27+ "15" ,
28+ "--duration-unit" ,
29+ "min" ,
2830 ],
29- expected_code = ExitCodes .REQUEST_FAILED
31+ expected_code = ExitCodes .REQUEST_FAILED ,
3032 )
3133
3234 # Missing metrics
3335 exec_failing_test_command (
34- BASE_CMD + [
36+ BASE_CMD
37+ + [
3538 "nodebalancer" ,
36- "--entity-ids" , "123" ,
37- "--duration" , "15" ,
38- "--duration-unit" , "min"
39+ "--entity-ids" ,
40+ "123" ,
41+ "--duration" ,
42+ "15" ,
43+ "--duration-unit" ,
44+ "min" ,
3945 ],
40- expected_code = ExitCodes .REQUEST_FAILED
46+ expected_code = ExitCodes .REQUEST_FAILED ,
4147 )
4248
4349 # Missing duration and time parameters
4450 exec_failing_test_command (
45- BASE_CMD + [
46- "nodebalancer" ,
47- "--entity-ids" , "123" ,
48- "--metrics" , "cpu_usage:avg"
49- ],
50- expected_code = ExitCodes .REQUEST_FAILED
51+ BASE_CMD
52+ + ["nodebalancer" , "--entity-ids" , "123" , "--metrics" , "cpu_usage:avg" ],
53+ expected_code = ExitCodes .REQUEST_FAILED ,
5154 )
5255
5356
5457def test_invalid_service ():
5558 """Test error handling for invalid service name"""
5659 exec_failing_test_command (
57- BASE_CMD + [
60+ BASE_CMD
61+ + [
5862 "invalid_service" ,
59- "--entity-ids" , "123" ,
60- "--metrics" , "cpu_usage:avg" ,
61- "--duration" , "15" ,
62- "--duration-unit" , "min"
63+ "--entity-ids" ,
64+ "123" ,
65+ "--metrics" ,
66+ "cpu_usage:avg" ,
67+ "--duration" ,
68+ "15" ,
69+ "--duration-unit" ,
70+ "min" ,
6371 ],
64- expected_code = ExitCodes .REQUEST_FAILED
72+ expected_code = ExitCodes .REQUEST_FAILED ,
6573 )
6674
6775
6876def test_invalid_aggregate_function ():
6977 """Test error handling for metrics without aggregate functions"""
7078 exec_failing_test_command (
71- BASE_CMD + [
79+ BASE_CMD
80+ + [
7281 "nodebalancer" ,
73- "--entity-ids" , "123" ,
74- "--metrics" , "cpu_usage" , # Missing :avg
75- "--duration" , "15" ,
76- "--duration-unit" , "min"
82+ "--entity-ids" ,
83+ "123" ,
84+ "--metrics" ,
85+ "cpu_usage" , # Missing :avg
86+ "--duration" ,
87+ "15" ,
88+ "--duration-unit" ,
89+ "min" ,
7790 ],
78- expected_code = ExitCodes .REQUEST_FAILED
91+ expected_code = ExitCodes .REQUEST_FAILED ,
7992 )
8093
8194
8295def test_invalid_duration_unit ():
8396 """Test handling of invalid duration unit"""
8497 exec_failing_test_command (
85- BASE_CMD + [
98+ BASE_CMD
99+ + [
86100 "nodebalancer" ,
87- "--entity-ids" , "123" ,
88- "--metrics" , "cpu_usage:avg" ,
89- "--duration" , "15" ,
90- "--duration-unit" , "invalid_unit"
101+ "--entity-ids" ,
102+ "123" ,
103+ "--metrics" ,
104+ "cpu_usage:avg" ,
105+ "--duration" ,
106+ "15" ,
107+ "--duration-unit" ,
108+ "invalid_unit" ,
91109 ],
92- expected_code = ExitCodes .REQUEST_FAILED
110+ expected_code = ExitCodes .REQUEST_FAILED ,
93111 )
94112
95113
96114def test_conflicting_time_params ():
97115 """Test handling of conflicting time parameters"""
98116 exec_failing_test_command (
99- BASE_CMD + [
117+ BASE_CMD
118+ + [
100119 "nodebalancer" ,
101- "--entity-ids" , "123" ,
102- "--metrics" , "cpu_usage:avg" ,
103- "--duration" , "15" ,
104- "--duration-unit" , "min" ,
105- "--start-time" , "2025-12-22T00:00:00Z" ,
106- "--end-time" , "2025-12-22T12:00:00Z"
120+ "--entity-ids" ,
121+ "123" ,
122+ "--metrics" ,
123+ "cpu_usage:avg" ,
124+ "--duration" ,
125+ "15" ,
126+ "--duration-unit" ,
127+ "min" ,
128+ "--start-time" ,
129+ "2025-12-22T00:00:00Z" ,
130+ "--end-time" ,
131+ "2025-12-22T12:00:00Z" ,
107132 ],
108- expected_code = ExitCodes .REQUEST_FAILED
133+ expected_code = ExitCodes .REQUEST_FAILED ,
109134 )
110135
111136
112137@pytest .mark .smoke
113138def test_objstorage_metrics_basic ():
114139 """Test get_metrics with objectstorage service (with authentication)"""
115140 # Use objectstorage service which doesn't require entity-ids
116- output = exec_test_command (BASE_CMD + [
117- "objectstorage" ,
118- "--metrics" , "obj_requests_num:sum" ,
119- "--duration" , "15" ,
120- "--duration-unit" , "min" ,
121- "--entity-region" , "us-east"
122- ])
141+ output = exec_test_command (
142+ BASE_CMD
143+ + [
144+ "objectstorage" ,
145+ "--metrics" ,
146+ "obj_requests_num:sum" ,
147+ "--duration" ,
148+ "15" ,
149+ "--duration-unit" ,
150+ "min" ,
151+ "--entity-region" ,
152+ "us-east" ,
153+ ]
154+ )
123155
124156 print (f"SUCCESS: { output } " )
125157 assert "Fetching metrics" in output or "data" in output .lower ()
126158
127159
128160def test_obj_metrics_with_filters ():
129161 """Test get_metrics with objectstorage service and filters"""
130- output = exec_test_command (BASE_CMD + [
131- "objectstorage" ,
132- "--metrics" , "obj_requests_num:sum" ,
133- "--duration" , "30" ,
134- "--duration-unit" , "min" ,
135- "--entity-region" , "us-west" ,
136- "--filters" , "request_type:eq:get"
137- ])
162+ output = exec_test_command (
163+ BASE_CMD
164+ + [
165+ "objectstorage" ,
166+ "--metrics" ,
167+ "obj_requests_num:sum" ,
168+ "--duration" ,
169+ "30" ,
170+ "--duration-unit" ,
171+ "min" ,
172+ "--entity-region" ,
173+ "us-west" ,
174+ "--filters" ,
175+ "request_type:eq:get" ,
176+ ]
177+ )
138178
139179 assert "Fetching metrics" in output or "data" in output .lower ()
140180
141181
142-
143182def test_absolute_time_metrics ():
144183 """Test get_metrics with objectstorage service and absolute time range"""
145- output = exec_test_command (BASE_CMD + [
146- "objectstorage" ,
147- "--metrics" , "obj_requests_num:sum" ,
148- "--start-time" , "2025-12-22T00:00:00Z" ,
149- "--end-time" , "2025-12-22T12:00:00Z" ,
150- "--entity-region" , "us-southeast" ,
151- "--granularity" , "5" ,
152- "--granularity-unit" , "min"
153- ])
184+ output = exec_test_command (
185+ BASE_CMD
186+ + [
187+ "objectstorage" ,
188+ "--metrics" ,
189+ "obj_requests_num:sum" ,
190+ "--start-time" ,
191+ "2025-12-22T00:00:00Z" ,
192+ "--end-time" ,
193+ "2025-12-22T12:00:00Z" ,
194+ "--entity-region" ,
195+ "us-southeast" ,
196+ "--granularity" ,
197+ "5" ,
198+ "--granularity-unit" ,
199+ "min" ,
200+ ]
201+ )
154202
155203 assert "Fetching metrics" in output or "data" in output .lower ()
156204
157205
158-
159206def test_malformed_filters ():
160207 """Test handling of malformed filter syntax"""
161208 exec_failing_test_command (
162- BASE_CMD + [
209+ BASE_CMD
210+ + [
163211 "objectstorage" ,
164- "--metrics" , "obj_requests_num:sum" ,
165- "--duration" , "15" ,
166- "--duration-unit" , "min" ,
167- "--filters" , "invalid_filter_format"
212+ "--metrics" ,
213+ "obj_requests_num:sum" ,
214+ "--duration" ,
215+ "15" ,
216+ "--duration-unit" ,
217+ "min" ,
218+ "--filters" ,
219+ "invalid_filter_format" ,
168220 ],
169- expected_code = ExitCodes .REQUEST_FAILED
221+ expected_code = ExitCodes .REQUEST_FAILED ,
170222 )
171-
172-
173-
0 commit comments