blob: f2bf2a6a5748730340b83a4002d590f0b4b02459 [file] [log] [blame]
Andy Bavier614af142020-08-07 14:49:56 -07001#!/usr/bin/env python
2
3# Copyright 2020-present Open Networking Foundation
4#
Hyunsun Moon200eba52021-04-05 21:31:54 -07005# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
Andy Bavier614af142020-08-07 14:49:56 -07006
7import unittest
8import edge_monitoring_server as ems
9import datetime
10import pytz
Hyunsun Moon5f237ec2020-09-29 14:45:52 -070011import json
12import time
Andy Bavier2d60fc52021-05-04 16:13:39 -070013from copy import deepcopy
Hyunsun Moon5f237ec2020-09-29 14:45:52 -070014
15
16test_edge = {
Andy Baviere4591222021-07-07 12:44:19 -070017 'name': 'ace-menlo-rasp-pi',
Hyunsun Moon5f237ec2020-09-29 14:45:52 -070018 'status': {
19 'control_plane': 'connected',
20 'user_plane': 'connected'
21 },
Jeremy Ronquilloc45955a2021-11-09 12:04:57 -080022 'dongle_stats': {
23 'SuccessfulFetch': True,
24 'IMSI': '315021000000000',
25 'CellGlobalID': '315010001F800',
Jeremy Ronquillo1eaff6a2021-11-16 13:46:46 -080026 'PhyCellID': '101',
Jeremy Ronquilloc45955a2021-11-09 12:04:57 -080027 'PLMNStatus': 'Success'
28 },
Jeremy Ronquillof4200252021-02-13 16:11:04 -080029 'speedtest': {
30 'ping': {
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -070031 'dry_run': {
32 'transmitted': 3,
33 'received': 2,
34 'median': 5.0,
35 'min': 1.0,
36 'avg': 5.0,
37 'max': 9.0,
38 'stddev': 1.0
39 },
Jeremy Ronquillof4200252021-02-13 16:11:04 -080040 'dns': {
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -070041 'transmitted': 10,
42 'received': 9,
43 'median': 4.0,
Jeremy Ronquillof4200252021-02-13 16:11:04 -080044 'min': 2.0,
45 'avg': 4.0,
46 'max': 6.0,
47 'stddev': 1.0
Jeremy Ronquillo6e352b72021-06-08 10:33:25 -070048 },
49 'iperf_server': {
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -070050 'transmitted': 10,
51 'received': 10,
52 'median': 3.0,
Jeremy Ronquillo6e352b72021-06-08 10:33:25 -070053 'min': 1.0,
54 'avg': 3.0,
55 'max': 5.0,
56 'stddev': 1.0
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -070057 },
58 'management_server': {
59 'transmitted': 10,
60 'received': 8,
61 'median': 6.0,
62 'min': 2.0,
63 'avg': 6.0,
64 'max': 10.0,
65 'stddev': 1.0
Jeremy Ronquillof4200252021-02-13 16:11:04 -080066 }
Jeremy Ronquilloc7434622021-04-08 21:06:00 -070067 },
68 'iperf': {
69 'cluster': {
70 'downlink': 100.0,
71 'uplink': 10.0
72 }
Jeremy Ronquillof4200252021-02-13 16:11:04 -080073 }
74 },
Hyunsun Moon200eba52021-04-05 21:31:54 -070075 'signal_quality': {
76 'rsrq': 30,
77 'rsrp': 80
78 },
79 'last_update': time.time()
80}
81
82test_edge_status_only = {
Andy Baviere4591222021-07-07 12:44:19 -070083 'name': 'ace-menlo-rasp-pi',
Hyunsun Moon200eba52021-04-05 21:31:54 -070084 'status': {
85 'control_plane': 'connected',
86 'user_plane': 'connected'
87 },
Jeremy Ronquillof4200252021-02-13 16:11:04 -080088 'last_update': time.time()
89}
90
91test_edge_no_speedtest = {
Andy Baviere4591222021-07-07 12:44:19 -070092 'name': 'ace-menlo-rasp-pi',
Jeremy Ronquillof4200252021-02-13 16:11:04 -080093 'status': {
94 'control_plane': 'connected',
95 'user_plane': 'connected'
96 },
Hyunsun Moon200eba52021-04-05 21:31:54 -070097 'signal_quality': {
98 'rsrq': 30,
99 'rsrp': 80
100 },
101 'last_update': time.time()
102}
103
104test_edge_no_signal_quality = {
Andy Baviere4591222021-07-07 12:44:19 -0700105 'name': 'ace-menlo-rasp-pi',
Hyunsun Moon200eba52021-04-05 21:31:54 -0700106 'status': {
107 'control_plane': 'connected',
108 'user_plane': 'connected'
109 },
110 'speedtest': {
111 'ping': {
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700112 'dry_run': {
113 'transmitted': 3,
114 'received': 2,
115 'median': 5.0,
116 'min': 1.0,
117 'avg': 5.0,
118 'max': 9.0,
119 'stddev': 1.0
120 },
Hyunsun Moon200eba52021-04-05 21:31:54 -0700121 'dns': {
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700122 'transmitted': 10,
123 'received': 9,
124 'median': 4.0,
Hyunsun Moon200eba52021-04-05 21:31:54 -0700125 'min': 2.0,
126 'avg': 4.0,
127 'max': 6.0,
128 'stddev': 1.0
Jeremy Ronquillo6e352b72021-06-08 10:33:25 -0700129 },
130 'iperf_server': {
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700131 'transmitted': 10,
132 'received': 10,
133 'median': 3.0,
Jeremy Ronquillo6e352b72021-06-08 10:33:25 -0700134 'min': 1.0,
135 'avg': 3.0,
136 'max': 5.0,
137 'stddev': 1.0
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700138 },
139 'management_server': {
140 'transmitted': 10,
141 'received': 8,
142 'median': 6.0,
143 'min': 2.0,
144 'avg': 6.0,
145 'max': 10.0,
146 'stddev': 1.0
Hyunsun Moon200eba52021-04-05 21:31:54 -0700147 }
Jeremy Ronquilloc7434622021-04-08 21:06:00 -0700148 },
149 'iperf': {
150 'cluster': {
151 'downlink': 100.0,
152 'uplink': 10.0
153 }
Hyunsun Moon200eba52021-04-05 21:31:54 -0700154 }
155 },
Hyunsun Moon5f237ec2020-09-29 14:45:52 -0700156 'last_update': time.time()
157}
Andy Bavier614af142020-08-07 14:49:56 -0700158
Jeremy Ronquilloc7434622021-04-08 21:06:00 -0700159test_edge_no_iperf = {
Andy Baviere4591222021-07-07 12:44:19 -0700160 'name': 'ace-menlo-rasp-pi',
Jeremy Ronquilloc7434622021-04-08 21:06:00 -0700161 'status': {
162 'control_plane': 'connected',
163 'user_plane': 'connected'
164 },
165 'speedtest': {
166 'ping': {
167 'dns': {
168 'min': 2.0,
169 'avg': 4.0,
170 'max': 6.0,
171 'stddev': 1.0
172 }
173 }
174 },
175 'signal_quality': {
176 'rsrq': 30,
177 'rsrp': 80
178 },
179 'last_update': time.time()
180}
181
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700182test_edge_pre_0_7_0 = {
183 'name': 'ace-menlo-rasp-pi',
184 'status': {
185 'control_plane': 'connected',
186 'user_plane': 'connected'
187 },
188 'speedtest': {
189 'ping': {
190 'dns': {
191 'min': 2.0,
192 'avg': 4.0,
193 'max': 6.0,
194 'stddev': 1.0
195 },
196 'iperf_server': {
197 'min': 1.0,
198 'avg': 3.0,
199 'max': 5.0,
200 'stddev': 1.0
201 }
202 },
203 'iperf': {
204 'cluster': {
205 'downlink': 100.0,
206 'uplink': 10.0
207 }
208 }
209 },
210 'signal_quality': {
211 'rsrq': 30,
212 'rsrp': 80
213 },
214 'last_update': time.time()
215}
216
217test_edge_dns_iperf = {
218 'name': 'ace-menlo-rasp-pi',
219 'status': {
220 'control_plane': 'connected',
221 'user_plane': 'connected'
222 },
223 'speedtest': {
224 'ping': {
225 'dns': {
226 'transmitted': 10,
227 'received': 9,
228 'median': 4.0,
229 'min': 2.0,
230 'avg': 4.0,
231 'max': 6.0,
232 'stddev': 1.0
233 },
234 'iperf_server': {
235 'transmitted': 10,
236 'received': 10,
237 'median': 3.0,
238 'min': 1.0,
239 'avg': 3.0,
240 'max': 5.0,
241 'stddev': 1.0
242 }
243 },
244 'iperf': {
245 'cluster': {
246 'downlink': 100.0,
247 'uplink': 10.0
248 }
249 }
250 },
251 'signal_quality': {
252 'rsrq': 30,
253 'rsrp': 80
254 },
255 'last_update': time.time()
256}
257
258test_edge_basic_ping_stats = {
259 'name': 'ace-menlo-rasp-pi',
260 'status': {
261 'control_plane': 'connected',
262 'user_plane': 'connected'
263 },
264 'speedtest': {
265 'ping': {
266 'dry_run': {
267 'min': 1.0,
268 'avg': 5.0,
269 'max': 9.0,
270 'stddev': 1.0
271 },
272 'dns': {
273 'min': 2.0,
274 'avg': 4.0,
275 'max': 6.0,
276 'stddev': 1.0
277 },
278 'iperf_server': {
279 'min': 1.0,
280 'avg': 3.0,
281 'max': 5.0,
282 'stddev': 1.0
283 },
284 'management_server': {
285 'min': 2.0,
286 'avg': 6.0,
287 'max': 10.0,
288 'stddev': 1.0
289 }
290 },
291 'iperf': {
292 'cluster': {
293 'downlink': 100.0,
294 'uplink': 10.0
295 }
296 }
297 },
298 'signal_quality': {
299 'rsrq': 30,
300 'rsrp': 80
301 },
302 'last_update': time.time()
303}
Andy Bavier614af142020-08-07 14:49:56 -0700304
Jeremy Ronquilloc45955a2021-11-09 12:04:57 -0800305test_edge_no_dongle_stats = {
306 'name': 'ace-menlo-rasp-pi',
307 'status': {
308 'control_plane': 'connected',
309 'user_plane': 'connected'
310 },
311 'speedtest': {
312 'ping': {
313 'dry_run': {
314 'transmitted': 3,
315 'received': 2,
316 'median': 5.0,
317 'min': 1.0,
318 'avg': 5.0,
319 'max': 9.0,
320 'stddev': 1.0
321 },
322 'dns': {
323 'transmitted': 10,
324 'received': 9,
325 'median': 4.0,
326 'min': 2.0,
327 'avg': 4.0,
328 'max': 6.0,
329 'stddev': 1.0
330 },
331 'iperf_server': {
332 'transmitted': 10,
333 'received': 10,
334 'median': 3.0,
335 'min': 1.0,
336 'avg': 3.0,
337 'max': 5.0,
338 'stddev': 1.0
339 },
340 'management_server': {
341 'transmitted': 10,
342 'received': 8,
343 'median': 6.0,
344 'min': 2.0,
345 'avg': 6.0,
346 'max': 10.0,
347 'stddev': 1.0
348 }
349 },
350 'iperf': {
351 'cluster': {
352 'downlink': 100.0,
353 'uplink': 10.0
354 }
355 }
356 },
357 'signal_quality': {
358 'rsrq': 30,
359 'rsrp': 80
360 },
361 'last_update': time.time()
362}
363
Andy Bavier614af142020-08-07 14:49:56 -0700364class MyEvent:
Andy Bavierc41cf0c2020-09-02 14:49:21 -0700365 def __init__ (self, location = "", description = "", summary = "", start = None, end = None, all_day = False):
Andy Bavier614af142020-08-07 14:49:56 -0700366 self.location = location
367 self.description = description
368 self.summary = summary
369 self.start = start
370 self.end = end
Andy Bavierc41cf0c2020-09-02 14:49:21 -0700371 self.all_day = all_day
Andy Bavier614af142020-08-07 14:49:56 -0700372
373class MyEventNoLoc:
374 def __init__ (self, description = "", summary = ""):
375 self.description = description
376 self.summary = summary
377
378
379class TestEdgeMonitoringServer(unittest.TestCase):
Hyunsun Moon5f237ec2020-09-29 14:45:52 -0700380 def setUp(self):
381 self.app = ems.app.test_client()
Hyunsun Moon200eba52021-04-05 21:31:54 -0700382 self.emulated_time = time.mktime(time.strptime("2021-04-05 00:00:00", "%Y-%m-%d %H:%M:%S"))
383 self.time_method = time.time
384 time.time = self._get_time
385
386 def tearDown(self):
387 time.time = self.time_method
388
389 def _get_time(self):
390 return self.emulated_time
391
392 def _assert_status_metrics_exist(self, data):
Andy Baviere4591222021-07-07 12:44:19 -0700393 self.assertTrue('aetheredge_status_control_plane{name="ace-menlo-rasp-pi"} 2.0' in data)
394 self.assertTrue('aetheredge_status_user_plane{name="ace-menlo-rasp-pi"} 2.0' in data)
395 self.assertTrue('aetheredge_last_update{name="ace-menlo-rasp-pi"}' in data)
396 self.assertTrue('aetheredge_connect_test_ok{name="ace-menlo-rasp-pi"} 1.0' in data)
397 self.assertTrue('aetheredge_ping_test_ok{name="ace-menlo-rasp-pi"} 1.0' in data)
398 self.assertTrue('aetheredge_e2e_tests_ok{name="ace-menlo-rasp-pi"} 1.0' in data)
399 self.assertTrue('aetheredge_e2e_tests_down{name="ace-menlo-rasp-pi"} 0.0' in data)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700400
401 def _assert_speedtest_metrics_exist(self, data):
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700402 self.assertTrue('aetheredge_ping_dry_run_test_transmitted{name="ace-menlo-rasp-pi"} 3' in data)
403 self.assertTrue('aetheredge_ping_dry_run_test_received{name="ace-menlo-rasp-pi"} 2' in data)
404 self.assertTrue('aetheredge_ping_dry_run_test_median{name="ace-menlo-rasp-pi"} 5.0' in data)
405 self.assertTrue('aetheredge_ping_dry_run_test_min{name="ace-menlo-rasp-pi"} 1.0' in data)
406 self.assertTrue('aetheredge_ping_dry_run_test_avg{name="ace-menlo-rasp-pi"} 5.0' in data)
407 self.assertTrue('aetheredge_ping_dry_run_test_max{name="ace-menlo-rasp-pi"} 9.0' in data)
408 self.assertTrue('aetheredge_ping_dry_run_test_stddev{name="ace-menlo-rasp-pi"} 1.0' in data)
409
410 self.assertTrue('aetheredge_ping_dns_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
411 self.assertTrue('aetheredge_ping_dns_test_received{name="ace-menlo-rasp-pi"} 9' in data)
412 self.assertTrue('aetheredge_ping_dns_test_median{name="ace-menlo-rasp-pi"} 4.0' in data)
Andy Baviere4591222021-07-07 12:44:19 -0700413 self.assertTrue('aetheredge_ping_dns_test_min{name="ace-menlo-rasp-pi"} 2.0' in data)
414 self.assertTrue('aetheredge_ping_dns_test_avg{name="ace-menlo-rasp-pi"} 4.0' in data)
415 self.assertTrue('aetheredge_ping_dns_test_max{name="ace-menlo-rasp-pi"} 6.0' in data)
416 self.assertTrue('aetheredge_ping_dns_test_stddev{name="ace-menlo-rasp-pi"} 1.0' in data)
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700417
418 self.assertTrue('aetheredge_ping_iperf_server_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
419 self.assertTrue('aetheredge_ping_iperf_server_test_received{name="ace-menlo-rasp-pi"} 10' in data)
420 self.assertTrue('aetheredge_ping_iperf_server_test_median{name="ace-menlo-rasp-pi"} 3.0' in data)
Andy Baviere4591222021-07-07 12:44:19 -0700421 self.assertTrue('aetheredge_ping_iperf_server_test_min{name="ace-menlo-rasp-pi"} 1.0' in data)
422 self.assertTrue('aetheredge_ping_iperf_server_test_avg{name="ace-menlo-rasp-pi"} 3.0' in data)
423 self.assertTrue('aetheredge_ping_iperf_server_test_max{name="ace-menlo-rasp-pi"} 5.0' in data)
424 self.assertTrue('aetheredge_ping_iperf_server_test_stddev{name="ace-menlo-rasp-pi"} 1.0' in data)
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700425
426 self.assertTrue('aetheredge_ping_management_server_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
427 self.assertTrue('aetheredge_ping_management_server_test_received{name="ace-menlo-rasp-pi"} 8' in data)
428 self.assertTrue('aetheredge_ping_management_server_test_median{name="ace-menlo-rasp-pi"} 6.0' in data)
429 self.assertTrue('aetheredge_ping_management_server_test_min{name="ace-menlo-rasp-pi"} 2.0' in data)
430 self.assertTrue('aetheredge_ping_management_server_test_avg{name="ace-menlo-rasp-pi"} 6.0' in data)
431 self.assertTrue('aetheredge_ping_management_server_test_max{name="ace-menlo-rasp-pi"} 10.0' in data)
432 self.assertTrue('aetheredge_ping_management_server_test_stddev{name="ace-menlo-rasp-pi"} 1.0' in data)
433
Andy Baviere4591222021-07-07 12:44:19 -0700434 self.assertTrue('aetheredge_iperf_cluster_downlink_test{name="ace-menlo-rasp-pi"} 100.0' in data)
435 self.assertTrue('aetheredge_iperf_cluster_uplink_test{name="ace-menlo-rasp-pi"} 10.0' in data)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700436
437 def _assert_signal_quality_metrics_exist(self, data):
Andy Baviere4591222021-07-07 12:44:19 -0700438 self.assertTrue('aetheredge_signal_quality_rsrq{name="ace-menlo-rasp-pi"} 30' in data)
439 self.assertTrue('aetheredge_signal_quality_rsrp{name="ace-menlo-rasp-pi"} 80' in data)
Hyunsun Moon5f237ec2020-09-29 14:45:52 -0700440
Jeremy Ronquilloc45955a2021-11-09 12:04:57 -0800441 def _assert_dongle_stats_metrics_exist(self, data):
442 self.assertTrue('aetheredge_dongle_stats_imsi{name="ace-menlo-rasp-pi"}' in data)
Jeremy Ronquillo1eaff6a2021-11-16 13:46:46 -0800443 self.assertTrue('aetheredge_dongle_stats_cellglobalid{name="ace-menlo-rasp-pi"} 8.67518969411584e+014' in data)
444 self.assertTrue('aetheredge_dongle_stats_plmnstatus{name="ace-menlo-rasp-pi"} 3' in data)
445 self.assertTrue('aetheredge_dongle_stats_phycellid{name="ace-menlo-rasp-pi"} 101' in data)
446
Jeremy Ronquilloc45955a2021-11-09 12:04:57 -0800447
Andy Bavier614af142020-08-07 14:49:56 -0700448 def test_match_location(self):
Andy Baviere4591222021-07-07 12:44:19 -0700449 event = MyEvent(location = "ace-menlo-rasp-pi-production")
450 self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
Andy Bavier8a5c9872020-10-21 13:17:53 -0700451 event = MyEvent(location = "(Compute)-MP-1-Aether Production")
Andy Baviere4591222021-07-07 12:44:19 -0700452 self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
Andy Bavier614af142020-08-07 14:49:56 -0700453
454 def test_match_description(self):
Andy Baviere4591222021-07-07 12:44:19 -0700455 event = MyEvent(description = "ace-menlo-rasp-pi-production")
456 self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
Andy Bavier8a5c9872020-10-21 13:17:53 -0700457 event = MyEvent(description = "(Compute)-MP-1-Aether Production")
Andy Baviere4591222021-07-07 12:44:19 -0700458 self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
Andy Bavier614af142020-08-07 14:49:56 -0700459
460 def test_match_summary(self):
Andy Baviere4591222021-07-07 12:44:19 -0700461 event = MyEvent(summary = "ace-menlo-rasp-pi-production")
462 self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
Andy Bavier8a5c9872020-10-21 13:17:53 -0700463 event = MyEvent(summary = "(Compute)-MP-1-Aether Production")
Andy Baviere4591222021-07-07 12:44:19 -0700464 self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
Andy Bavier614af142020-08-07 14:49:56 -0700465
466 def test_no_match(self):
Andy Baviere4591222021-07-07 12:44:19 -0700467 event = MyEvent(summary = "ace-menlo-rasp-pi-production, (Compute)-MP-1-Aether Production")
Andy Bavier8a5c9872020-10-21 13:17:53 -0700468 self.assertFalse(ems.is_my_event(event, "ace-intel"))
Andy Bavier614af142020-08-07 14:49:56 -0700469 self.assertFalse(ems.is_my_event(event, "(Compute)-MP-1-Aether Staging"))
Andy Bavier8a5c9872020-10-21 13:17:53 -0700470 self.assertFalse(ems.is_my_event(event, "ace-menlo"))
Andy Bavier614af142020-08-07 14:49:56 -0700471
472 def test_missing_field(self):
Andy Bavier8a5c9872020-10-21 13:17:53 -0700473 event = MyEventNoLoc(description = "(Compute)-MP-1-Aether Production")
Andy Baviere4591222021-07-07 12:44:19 -0700474 self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
Andy Bavier614af142020-08-07 14:49:56 -0700475
476 def test_in_window(self):
477 events = []
478 now = datetime.datetime.now(pytz.utc)
479 events.append(MyEvent(location = "(Compute)-MP-1-Aether Production",
480 start = now - datetime.timedelta(hours=1),
481 end = now + datetime.timedelta(hours=1)))
Andy Baviere4591222021-07-07 12:44:19 -0700482 self.assertTrue(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
Andy Bavier8a5c9872020-10-21 13:17:53 -0700483 self.assertFalse(ems.in_maintenance_window(events, "ace-tucson", now))
Andy Bavier614af142020-08-07 14:49:56 -0700484
485 def test_not_in_window(self):
486 events = []
487 now = datetime.datetime.now(pytz.utc)
Andy Baviere4591222021-07-07 12:44:19 -0700488 events.append(MyEvent(location = "ace-menlo-rasp-pi-production",
Andy Bavier614af142020-08-07 14:49:56 -0700489 start = now + datetime.timedelta(hours=1),
490 end = now + datetime.timedelta(hours=2)))
Andy Baviere4591222021-07-07 12:44:19 -0700491 self.assertFalse(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
Andy Bavier614af142020-08-07 14:49:56 -0700492
493 def test_no_events(self):
494 events = []
495 now = datetime.datetime.now(pytz.utc)
Andy Baviere4591222021-07-07 12:44:19 -0700496 self.assertFalse(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
Andy Bavier614af142020-08-07 14:49:56 -0700497
Andy Bavierc41cf0c2020-09-02 14:49:21 -0700498 def test_all_day_events(self):
499 events = []
Andy Baviere4591222021-07-07 12:44:19 -0700500 events.append(MyEvent(location = "ace-menlo-rasp-pi-production",
Andy Bavierc41cf0c2020-09-02 14:49:21 -0700501 start = datetime.datetime(2020, 9, 2, 0, 0),
502 end = datetime.datetime(2020, 9, 3, 0, 0),
503 all_day = True))
504
505 ems.process_all_day_events(events)
506
507 now = datetime.datetime(2020, 9, 2, 12, 0, tzinfo=pytz.utc)
Andy Baviere4591222021-07-07 12:44:19 -0700508 self.assertTrue(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
Andy Bavierc41cf0c2020-09-02 14:49:21 -0700509
510 now = datetime.datetime(2020, 9, 3, 12, 0, tzinfo=pytz.utc)
Andy Baviere4591222021-07-07 12:44:19 -0700511 self.assertFalse(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
Andy Bavierc41cf0c2020-09-02 14:49:21 -0700512
Hyunsun Moon5f237ec2020-09-29 14:45:52 -0700513 def test_get_edges(self):
514 response = self.app.get('/edges')
515 data = json.loads(response.get_data(as_text=True))
516 self.assertEqual(len(data['edges']), 1)
Andy Bavier8a5c9872020-10-21 13:17:53 -0700517 self.assertEqual(data['edges'][0]['name'], 'ace-example')
Hyunsun Moon5f237ec2020-09-29 14:45:52 -0700518
Andy Bavierf872e9a2021-03-22 12:06:25 -0700519 def test_create_and_delete_edge_legacy(self):
Hyunsun Moon5f237ec2020-09-29 14:45:52 -0700520 response = self.app.post('/edges', json=test_edge)
521 data = json.loads(response.get_data(as_text=True))
Andy Baviere4591222021-07-07 12:44:19 -0700522 self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
Hyunsun Moon5f237ec2020-09-29 14:45:52 -0700523
524 response = self.app.get('/edges')
525 data = json.loads(response.get_data(as_text=True))
526 self.assertEqual(len(data['edges']), 2)
527
Andy Baviere47157d2020-12-11 14:13:12 -0700528 response = self.app.get('/edges/metrics')
529 data = response.get_data(as_text=True)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700530 # print(data)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700531
532 self._assert_status_metrics_exist(data)
533 self._assert_speedtest_metrics_exist(data)
534 self._assert_signal_quality_metrics_exist(data)
Andy Baviere47157d2020-12-11 14:13:12 -0700535
Andy Baviere4591222021-07-07 12:44:19 -0700536 response = self.app.delete('/edges/ace-menlo-rasp-pi')
Hyunsun Moon5f237ec2020-09-29 14:45:52 -0700537 data = json.loads(response.get_data(as_text=True))
538 self.assertEqual(data['result'], True)
Andy Baviere47157d2020-12-11 14:13:12 -0700539
540 response = self.app.get('/edges/metrics')
541 data = response.get_data(as_text=True)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700542 # print(data)
Andy Baviere4591222021-07-07 12:44:19 -0700543 self.assertFalse('ace-menlo-rasp-pi' in data)
Hyunsun Moon5f237ec2020-09-29 14:45:52 -0700544
545 response = self.app.get('/edges')
546 data = json.loads(response.get_data(as_text=True))
547 self.assertEqual(len(data['edges']), 1)
Andy Bavierc41cf0c2020-09-02 14:49:21 -0700548
Andy Bavierf872e9a2021-03-22 12:06:25 -0700549 def test_create_and_delete_edge(self):
550 response = self.app.post('/testresults', json=test_edge)
551 data = json.loads(response.get_data(as_text=True))
Andy Baviere4591222021-07-07 12:44:19 -0700552 self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
Andy Bavierf872e9a2021-03-22 12:06:25 -0700553
554 response = self.app.get('/edges')
555 data = json.loads(response.get_data(as_text=True))
556 self.assertEqual(len(data['edges']), 2)
557
558 response = self.app.get('/edges/metrics')
559 data = response.get_data(as_text=True)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700560 # print(data)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700561
562 self._assert_status_metrics_exist(data)
563 self._assert_speedtest_metrics_exist(data)
564 self._assert_signal_quality_metrics_exist(data)
Jeremy Ronquilloc45955a2021-11-09 12:04:57 -0800565 self._assert_dongle_stats_metrics_exist(data)
Andy Bavierf872e9a2021-03-22 12:06:25 -0700566
Andy Baviere4591222021-07-07 12:44:19 -0700567 response = self.app.delete('/testresults/ace-menlo-rasp-pi')
Andy Bavierf872e9a2021-03-22 12:06:25 -0700568 data = json.loads(response.get_data(as_text=True))
569 self.assertEqual(data['result'], True)
570
571 response = self.app.get('/edges/metrics')
572 data = response.get_data(as_text=True)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700573 # print(data)
Andy Baviere4591222021-07-07 12:44:19 -0700574 self.assertFalse('ace-menlo-rasp-pi' in data)
Andy Bavierf872e9a2021-03-22 12:06:25 -0700575
576 response = self.app.get('/edges')
577 data = json.loads(response.get_data(as_text=True))
578 self.assertEqual(len(data['edges']), 1)
Andy Bavier614af142020-08-07 14:49:56 -0700579
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800580 def test_create_and_delete_edge_speed_test(self):
581 response = self.app.post('/testresults', json=test_edge)
582 data = json.loads(response.get_data(as_text=True))
Andy Baviere4591222021-07-07 12:44:19 -0700583 self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800584
585 response = self.app.get('/edges/metrics')
586 data = response.get_data(as_text=True)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700587 # print(data)
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800588
Hyunsun Moon200eba52021-04-05 21:31:54 -0700589 self._assert_speedtest_metrics_exist(data)
590
Andy Baviere4591222021-07-07 12:44:19 -0700591 response = self.app.delete('/testresults/ace-menlo-rasp-pi')
Hyunsun Moon200eba52021-04-05 21:31:54 -0700592 data = json.loads(response.get_data(as_text=True))
593 self.assertEqual(data['result'], True)
594
595 def test_backwards_compatible_status_only(self):
596 response = self.app.post('/testresults', json=test_edge_status_only)
597 data = json.loads(response.get_data(as_text=True))
Andy Baviere4591222021-07-07 12:44:19 -0700598 self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
Hyunsun Moon200eba52021-04-05 21:31:54 -0700599
600 response = self.app.get('/edges/metrics')
601 data = response.get_data(as_text=True)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700602 # print(data)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700603
Andy Baviere4591222021-07-07 12:44:19 -0700604 self.assertFalse('aetheredge_signal_quality_rsrq{name="ace-menlo-rasp-pi"}' in data)
605 self.assertFalse('aetheredge_signal_quality_rsrp{name="ace-menlo-rasp-pi"}' in data)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700606
607 self._assert_status_metrics_exist(data)
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800608
Andy Baviere4591222021-07-07 12:44:19 -0700609 response = self.app.delete('/testresults/ace-menlo-rasp-pi')
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800610 data = json.loads(response.get_data(as_text=True))
611 self.assertEqual(data['result'], True)
612
613 def test_backwards_compatible_no_speedtest(self):
614 response = self.app.post('/testresults', json=test_edge_no_speedtest)
615 data = json.loads(response.get_data(as_text=True))
Andy Baviere4591222021-07-07 12:44:19 -0700616 self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800617
618 response = self.app.get('/edges/metrics')
619 data = response.get_data(as_text=True)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700620 # print(data)
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800621
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700622 self.assertFalse('aetheredge_ping_dry_run_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
623 self.assertFalse('aetheredge_ping_dry_run_test_received{name="ace-menlo-rasp-pi"}' in data)
624 self.assertFalse('aetheredge_ping_dry_run_test_median{name="ace-menlo-rasp-pi"}' in data)
625 self.assertFalse('aetheredge_ping_dry_run_test_min{name="ace-menlo-rasp-pi"}' in data)
626 self.assertFalse('aetheredge_ping_dry_run_test_avg{name="ace-menlo-rasp-pi"}' in data)
627 self.assertFalse('aetheredge_ping_dry_run_test_max{name="ace-menlo-rasp-pi"}' in data)
628 self.assertFalse('aetheredge_ping_dry_run_test_stddev{name="ace-menlo-rasp-pi"}' in data)
629
630 self.assertFalse('aetheredge_ping_dns_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
631 self.assertFalse('aetheredge_ping_dns_test_received{name="ace-menlo-rasp-pi"}' in data)
632 self.assertFalse('aetheredge_ping_dns_test_median{name="ace-menlo-rasp-pi"}' in data)
Andy Baviere4591222021-07-07 12:44:19 -0700633 self.assertFalse('aetheredge_ping_dns_test_min{name="ace-menlo-rasp-pi"}' in data)
634 self.assertFalse('aetheredge_ping_dns_test_avg{name="ace-menlo-rasp-pi"}' in data)
635 self.assertFalse('aetheredge_ping_dns_test_max{name="ace-menlo-rasp-pi"}' in data)
636 self.assertFalse('aetheredge_ping_dns_test_stddev{name="ace-menlo-rasp-pi"}' in data)
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700637
638 self.assertFalse('aetheredge_ping_iperf_server_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
639 self.assertFalse('aetheredge_ping_iperf_server_test_received{name="ace-menlo-rasp-pi"}' in data)
640 self.assertFalse('aetheredge_ping_iperf_server_test_median{name="ace-menlo-rasp-pi"}' in data)
Andy Baviere4591222021-07-07 12:44:19 -0700641 self.assertFalse('aetheredge_ping_iperf_server_test_min{name="ace-menlo-rasp-pi"}' in data)
642 self.assertFalse('aetheredge_ping_iperf_server_test_avg{name="ace-menlo-rasp-pi"}' in data)
643 self.assertFalse('aetheredge_ping_iperf_server_test_max{name="ace-menlo-rasp-pi"}' in data)
644 self.assertFalse('aetheredge_ping_iperf_server_test_stddev{name="ace-menlo-rasp-pi"}' in data)
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700645
646 self.assertFalse('aetheredge_ping_management_server_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
647 self.assertFalse('aetheredge_ping_management_server_test_received{name="ace-menlo-rasp-pi"}' in data)
648 self.assertFalse('aetheredge_ping_management_server_test_median{name="ace-menlo-rasp-pi"}' in data)
649 self.assertFalse('aetheredge_ping_management_server_test_min{name="ace-menlo-rasp-pi"}' in data)
650 self.assertFalse('aetheredge_ping_management_server_test_avg{name="ace-menlo-rasp-pi"}' in data)
651 self.assertFalse('aetheredge_ping_management_server_test_max{name="ace-menlo-rasp-pi"}' in data)
652 self.assertFalse('aetheredge_ping_management_server_test_stddev{name="ace-menlo-rasp-pi"}' in data)
653
Andy Baviere4591222021-07-07 12:44:19 -0700654 self.assertFalse('aetheredge_iperf_cluster_downlink_test{name="ace-menlo-rasp-pi"}' in data)
655 self.assertFalse('aetheredge_iperf_cluster_uplink_test{name="ace-menlo-rasp-pi"}' in data)
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800656
Hyunsun Moon200eba52021-04-05 21:31:54 -0700657 self._assert_status_metrics_exist(data)
658 self._assert_signal_quality_metrics_exist(data)
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800659
Andy Baviere4591222021-07-07 12:44:19 -0700660 response = self.app.delete('/testresults/ace-menlo-rasp-pi')
Jeremy Ronquillof4200252021-02-13 16:11:04 -0800661 data = json.loads(response.get_data(as_text=True))
662 self.assertEqual(data['result'], True)
663
Hyunsun Moon200eba52021-04-05 21:31:54 -0700664 def test_backwards_compatible_no_signal_quality(self):
665 response = self.app.post('/testresults', json=test_edge_no_signal_quality)
666 data = json.loads(response.get_data(as_text=True))
Andy Baviere4591222021-07-07 12:44:19 -0700667 self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
Hyunsun Moon200eba52021-04-05 21:31:54 -0700668
669 response = self.app.get('/edges/metrics')
670 data = response.get_data(as_text=True)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700671 # print(data)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700672
Andy Baviere4591222021-07-07 12:44:19 -0700673 self.assertFalse('aetheredge_signal_quality_rsrq{name="ace-menlo-rasp-pi"}' in data)
674 self.assertFalse('aetheredge_signal_quality_rsrp{name="ace-menlo-rasp-pi"}' in data)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700675
676 self._assert_status_metrics_exist(data)
677 self._assert_speedtest_metrics_exist(data)
678
Andy Baviere4591222021-07-07 12:44:19 -0700679 response = self.app.delete('/testresults/ace-menlo-rasp-pi')
Hyunsun Moon200eba52021-04-05 21:31:54 -0700680 data = json.loads(response.get_data(as_text=True))
681 self.assertEqual(data['result'], True)
682
683 def test_timeout_stale_result(self):
684 response = self.app.post('/testresults', json=test_edge)
685 data = json.loads(response.get_data(as_text=True))
Andy Bavier2d60fc52021-05-04 16:13:39 -0700686 # print(json.dumps(data, indent=2))
Hyunsun Moon200eba52021-04-05 21:31:54 -0700687
688 self.assertEqual(data['edge']['status']['control_plane'], 'connected')
689 self.assertEqual(data['edge']['status']['user_plane'], 'connected')
690 self.assertEqual(data['edge']['speedtest']['ping']['dns']['avg'], 4.0)
Jeremy Ronquillo6e352b72021-06-08 10:33:25 -0700691 self.assertEqual(data['edge']['speedtest']['ping']['iperf_server']['avg'], 3.0)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700692 self.assertTrue('signal_quality' in data['edge'])
693
694 self.emulated_time += (ems.NO_RESULT_THRESHOLD + 1)
695
Andy Baviere4591222021-07-07 12:44:19 -0700696 response = self.app.get('/edges/ace-menlo-rasp-pi')
Hyunsun Moon200eba52021-04-05 21:31:54 -0700697 data = json.loads(response.get_data(as_text=True))
Andy Bavier2d60fc52021-05-04 16:13:39 -0700698 # print(json.dumps(data, indent=2))
Hyunsun Moon200eba52021-04-05 21:31:54 -0700699
700 self.assertEqual(data['edge']['status']['control_plane'], 'no result')
701 self.assertEqual(data['edge']['status']['user_plane'], 'no result')
702 self.assertEqual(data['edge']['speedtest']['ping']['dns']['avg'], 0.0)
Jeremy Ronquillo6e352b72021-06-08 10:33:25 -0700703 self.assertEqual(data['edge']['speedtest']['ping']['iperf_server']['avg'], 0.0)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700704 self.assertFalse('signal_quality' in data['edge'])
705
Jeremy Ronquilloc7434622021-04-08 21:06:00 -0700706 def test_backwards_compatible_no_iperf(self):
707 response = self.app.post('/testresults', json=test_edge_no_iperf)
708 data = json.loads(response.get_data(as_text=True))
Andy Baviere4591222021-07-07 12:44:19 -0700709 self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
Jeremy Ronquilloc7434622021-04-08 21:06:00 -0700710
711 response = self.app.get('/edges/metrics')
712 data = response.get_data(as_text=True)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700713 # print(data)
Jeremy Ronquilloc7434622021-04-08 21:06:00 -0700714
Andy Baviere4591222021-07-07 12:44:19 -0700715 self.assertFalse('aetheredge_iperf_cluster_downlink{name="ace-menlo-rasp-pi"}' in data)
716 self.assertFalse('aetheredge_iperf_cluster_uplink{name="ace-menlo-rasp-pi"}' in data)
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700717 self.assertFalse('aetheredge_ping_iperf_server_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
718 self.assertFalse('aetheredge_ping_iperf_server_test_received{name="ace-menlo-rasp-pi"}' in data)
719 self.assertFalse('aetheredge_ping_iperf_server_test_median{name="ace-menlo-rasp-pi"}' in data)
Andy Baviere4591222021-07-07 12:44:19 -0700720 self.assertFalse('aetheredge_ping_iperf_server_test_min{name="ace-menlo-rasp-pi"}' in data)
721 self.assertFalse('aetheredge_ping_iperf_server_test_avg{name="ace-menlo-rasp-pi"}' in data)
722 self.assertFalse('aetheredge_ping_iperf_server_test_max{name="ace-menlo-rasp-pi"}' in data)
723 self.assertFalse('aetheredge_ping_iperf_server_test_stddev{name="ace-menlo-rasp-pi"}' in data)
Jeremy Ronquilloc7434622021-04-08 21:06:00 -0700724
Andy Baviere4591222021-07-07 12:44:19 -0700725 response = self.app.delete('/testresults/ace-menlo-rasp-pi')
Jeremy Ronquilloc7434622021-04-08 21:06:00 -0700726 data = json.loads(response.get_data(as_text=True))
727 self.assertEqual(data['result'], True)
728
Jeremy Ronquilloe0a8b422021-11-02 12:49:15 -0700729 def test_backwards_compatible_pre_0_7_0(self):
730 response = self.app.post('/testresults', json=test_edge_pre_0_7_0)
731 data = json.loads(response.get_data(as_text=True))
732 self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
733
734 response = self.app.get('/edges/metrics')
735 data = response.get_data(as_text=True)
736 # print(data)
737
738 self.assertFalse('aetheredge_ping_dry_run_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
739 self.assertFalse('aetheredge_ping_dry_run_test_received{name="ace-menlo-rasp-pi"}' in data)
740 self.assertFalse('aetheredge_ping_dry_run_test_median{name="ace-menlo-rasp-pi"}' in data)
741 self.assertFalse('aetheredge_ping_dry_run_test_min{name="ace-menlo-rasp-pi"}' in data)
742 self.assertFalse('aetheredge_ping_dry_run_test_avg{name="ace-menlo-rasp-pi"}' in data)
743 self.assertFalse('aetheredge_ping_dry_run_test_max{name="ace-menlo-rasp-pi"}' in data)
744 self.assertFalse('aetheredge_ping_dry_run_test_stddev{name="ace-menlo-rasp-pi"}' in data)
745
746 self.assertFalse('aetheredge_ping_management_server_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
747 self.assertFalse('aetheredge_ping_management_server_test_received{name="ace-menlo-rasp-pi"}' in data)
748 self.assertFalse('aetheredge_ping_management_server_test_median{name="ace-menlo-rasp-pi"}' in data)
749 self.assertFalse('aetheredge_ping_management_server_test_min{name="ace-menlo-rasp-pi"}' in data)
750 self.assertFalse('aetheredge_ping_management_server_test_avg{name="ace-menlo-rasp-pi"}' in data)
751 self.assertFalse('aetheredge_ping_management_server_test_max{name="ace-menlo-rasp-pi"}' in data)
752 self.assertFalse('aetheredge_ping_management_server_test_stddev{name="ace-menlo-rasp-pi"}' in data)
753
754 self.assertFalse('aetheredge_ping_dns_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
755 self.assertFalse('aetheredge_ping_dns_test_received{name="ace-menlo-rasp-pi"} 9' in data)
756 self.assertFalse('aetheredge_ping_dns_test_median{name="ace-menlo-rasp-pi"} 4.0' in data)
757
758 self.assertFalse('aetheredge_ping_iperf_server_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
759 self.assertFalse('aetheredge_ping_iperf_server_test_received{name="ace-menlo-rasp-pi"} 10' in data)
760 self.assertFalse('aetheredge_ping_iperf_server_test_median{name="ace-menlo-rasp-pi"} 3.0' in data)
761
762 response = self.app.delete('/testresults/ace-menlo-rasp-pi')
763 data = json.loads(response.get_data(as_text=True))
764 self.assertEqual(data['result'], True)
765
Jeremy Ronquilloc45955a2021-11-09 12:04:57 -0800766 def test_backwards_compatible_no_dongle_stats(self):
767 response = self.app.post('/testresults', json=test_edge_no_dongle_stats)
768 data = json.loads(response.get_data(as_text=True))
769 self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
770
771 response = self.app.get('/edges/metrics')
772 data = response.get_data(as_text=True)
773
Jeremy Ronquillocd711a22021-11-18 10:37:56 -0800774 self.assertFalse('aetheredge_dongle_stats_imsi{name="ace-menlo-rasp-pi"}' in data)
Jeremy Ronquillo1eaff6a2021-11-16 13:46:46 -0800775 self.assertFalse('aetheredge_dongle_stats_cellglobalid{name="ace-menlo-rasp-pi"}' in data)
776 self.assertFalse('aetheredge_dongle_stats_plmnstatus{name="ace-menlo-rasp-pi"}' in data)
777 self.assertFalse('aetheredge_dongle_stats_phycellid{name="ace-menlo-rasp-pi"}' in data)
Jeremy Ronquilloc45955a2021-11-09 12:04:57 -0800778
779 response = self.app.delete('/testresults/ace-menlo-rasp-pi')
780 data = json.loads(response.get_data(as_text=True))
781 self.assertEqual(data['result'], True)
782
Andy Bavier2d60fc52021-05-04 16:13:39 -0700783 def test_handle_invalid_schema(self):
784 response = self.app.post('/testresults', json="")
785 self.assertEqual(response.status_code, 400)
786
787 no_name = deepcopy(test_edge)
788 del no_name['name']
789 response = self.app.post('/testresults', json=no_name)
790 self.assertEqual(response.status_code, 400)
791 response = self.app.get('/edges/metrics')
792 data = response.get_data(as_text=True)
Andy Baviere4591222021-07-07 12:44:19 -0700793 self.assertFalse('ace-menlo-rasp-pi' in data)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700794
795 no_status = deepcopy(test_edge)
796 del no_status['status']
797 response = self.app.post('/testresults', json=no_status)
798 self.assertEqual(response.status_code, 400)
799 response = self.app.get('/edges/metrics')
800 data = response.get_data(as_text=True)
Andy Baviere4591222021-07-07 12:44:19 -0700801 self.assertFalse('ace-menlo-rasp-pi' in data)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700802
803 bad_status = deepcopy(test_edge)
804 bad_status['status']['control_plane'] = 1
805 response = self.app.post('/testresults', json=bad_status)
806 self.assertEqual(response.status_code, 400)
807 response = self.app.get('/edges/metrics')
808 data = response.get_data(as_text=True)
Andy Baviere4591222021-07-07 12:44:19 -0700809 self.assertFalse('ace-menlo-rasp-pi' in data)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700810
811 bad_ping_result = deepcopy(test_edge)
812 bad_ping_result['speedtest']['ping']['dns']['min'] = "foo"
813 response = self.app.post('/testresults', json=bad_ping_result)
814 self.assertEqual(response.status_code, 400)
815 response = self.app.get('/edges/metrics')
816 data = response.get_data(as_text=True)
Andy Baviere4591222021-07-07 12:44:19 -0700817 self.assertFalse('ace-menlo-rasp-pi' in data)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700818
819 bad_iperf_result = deepcopy(test_edge)
820 bad_iperf_result['speedtest']['iperf']['cluster']['uplink'] = "foo"
821 response = self.app.post('/testresults', json=bad_iperf_result)
822 self.assertEqual(response.status_code, 400)
823 response = self.app.get('/edges/metrics')
824 data = response.get_data(as_text=True)
Andy Baviere4591222021-07-07 12:44:19 -0700825 self.assertFalse('ace-menlo-rasp-pi' in data)
Andy Bavier2d60fc52021-05-04 16:13:39 -0700826
827 bad_signal_quality = deepcopy(test_edge)
828 del bad_signal_quality['signal_quality']['rsrq']
829 response = self.app.post('/testresults', json=bad_signal_quality)
830 self.assertEqual(response.status_code, 400)
831 response = self.app.get('/edges/metrics')
832 data = response.get_data(as_text=True)
Andy Baviere4591222021-07-07 12:44:19 -0700833 self.assertFalse('ace-menlo-rasp-pi' in data)
Hyunsun Moon200eba52021-04-05 21:31:54 -0700834
Andy Bavier614af142020-08-07 14:49:56 -0700835if __name__ == '__main__':
Andy Bavier55dc5872021-05-05 11:31:42 -0700836 import xmlrunner
837 with open('results.xml', 'wb') as output:
Jeremy Ronquillo6e352b72021-06-08 10:33:25 -0700838 unittest.main(testRunner=xmlrunner.XMLTestRunner(verbosity=2, output=output))