blob: f2bf2a6a5748730340b83a4002d590f0b4b02459 [file] [log] [blame]
#!/usr/bin/env python
# Copyright 2020-present Open Networking Foundation
#
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
import unittest
import edge_monitoring_server as ems
import datetime
import pytz
import json
import time
from copy import deepcopy
test_edge = {
'name': 'ace-menlo-rasp-pi',
'status': {
'control_plane': 'connected',
'user_plane': 'connected'
},
'dongle_stats': {
'SuccessfulFetch': True,
'IMSI': '315021000000000',
'CellGlobalID': '315010001F800',
'PhyCellID': '101',
'PLMNStatus': 'Success'
},
'speedtest': {
'ping': {
'dry_run': {
'transmitted': 3,
'received': 2,
'median': 5.0,
'min': 1.0,
'avg': 5.0,
'max': 9.0,
'stddev': 1.0
},
'dns': {
'transmitted': 10,
'received': 9,
'median': 4.0,
'min': 2.0,
'avg': 4.0,
'max': 6.0,
'stddev': 1.0
},
'iperf_server': {
'transmitted': 10,
'received': 10,
'median': 3.0,
'min': 1.0,
'avg': 3.0,
'max': 5.0,
'stddev': 1.0
},
'management_server': {
'transmitted': 10,
'received': 8,
'median': 6.0,
'min': 2.0,
'avg': 6.0,
'max': 10.0,
'stddev': 1.0
}
},
'iperf': {
'cluster': {
'downlink': 100.0,
'uplink': 10.0
}
}
},
'signal_quality': {
'rsrq': 30,
'rsrp': 80
},
'last_update': time.time()
}
test_edge_status_only = {
'name': 'ace-menlo-rasp-pi',
'status': {
'control_plane': 'connected',
'user_plane': 'connected'
},
'last_update': time.time()
}
test_edge_no_speedtest = {
'name': 'ace-menlo-rasp-pi',
'status': {
'control_plane': 'connected',
'user_plane': 'connected'
},
'signal_quality': {
'rsrq': 30,
'rsrp': 80
},
'last_update': time.time()
}
test_edge_no_signal_quality = {
'name': 'ace-menlo-rasp-pi',
'status': {
'control_plane': 'connected',
'user_plane': 'connected'
},
'speedtest': {
'ping': {
'dry_run': {
'transmitted': 3,
'received': 2,
'median': 5.0,
'min': 1.0,
'avg': 5.0,
'max': 9.0,
'stddev': 1.0
},
'dns': {
'transmitted': 10,
'received': 9,
'median': 4.0,
'min': 2.0,
'avg': 4.0,
'max': 6.0,
'stddev': 1.0
},
'iperf_server': {
'transmitted': 10,
'received': 10,
'median': 3.0,
'min': 1.0,
'avg': 3.0,
'max': 5.0,
'stddev': 1.0
},
'management_server': {
'transmitted': 10,
'received': 8,
'median': 6.0,
'min': 2.0,
'avg': 6.0,
'max': 10.0,
'stddev': 1.0
}
},
'iperf': {
'cluster': {
'downlink': 100.0,
'uplink': 10.0
}
}
},
'last_update': time.time()
}
test_edge_no_iperf = {
'name': 'ace-menlo-rasp-pi',
'status': {
'control_plane': 'connected',
'user_plane': 'connected'
},
'speedtest': {
'ping': {
'dns': {
'min': 2.0,
'avg': 4.0,
'max': 6.0,
'stddev': 1.0
}
}
},
'signal_quality': {
'rsrq': 30,
'rsrp': 80
},
'last_update': time.time()
}
test_edge_pre_0_7_0 = {
'name': 'ace-menlo-rasp-pi',
'status': {
'control_plane': 'connected',
'user_plane': 'connected'
},
'speedtest': {
'ping': {
'dns': {
'min': 2.0,
'avg': 4.0,
'max': 6.0,
'stddev': 1.0
},
'iperf_server': {
'min': 1.0,
'avg': 3.0,
'max': 5.0,
'stddev': 1.0
}
},
'iperf': {
'cluster': {
'downlink': 100.0,
'uplink': 10.0
}
}
},
'signal_quality': {
'rsrq': 30,
'rsrp': 80
},
'last_update': time.time()
}
test_edge_dns_iperf = {
'name': 'ace-menlo-rasp-pi',
'status': {
'control_plane': 'connected',
'user_plane': 'connected'
},
'speedtest': {
'ping': {
'dns': {
'transmitted': 10,
'received': 9,
'median': 4.0,
'min': 2.0,
'avg': 4.0,
'max': 6.0,
'stddev': 1.0
},
'iperf_server': {
'transmitted': 10,
'received': 10,
'median': 3.0,
'min': 1.0,
'avg': 3.0,
'max': 5.0,
'stddev': 1.0
}
},
'iperf': {
'cluster': {
'downlink': 100.0,
'uplink': 10.0
}
}
},
'signal_quality': {
'rsrq': 30,
'rsrp': 80
},
'last_update': time.time()
}
test_edge_basic_ping_stats = {
'name': 'ace-menlo-rasp-pi',
'status': {
'control_plane': 'connected',
'user_plane': 'connected'
},
'speedtest': {
'ping': {
'dry_run': {
'min': 1.0,
'avg': 5.0,
'max': 9.0,
'stddev': 1.0
},
'dns': {
'min': 2.0,
'avg': 4.0,
'max': 6.0,
'stddev': 1.0
},
'iperf_server': {
'min': 1.0,
'avg': 3.0,
'max': 5.0,
'stddev': 1.0
},
'management_server': {
'min': 2.0,
'avg': 6.0,
'max': 10.0,
'stddev': 1.0
}
},
'iperf': {
'cluster': {
'downlink': 100.0,
'uplink': 10.0
}
}
},
'signal_quality': {
'rsrq': 30,
'rsrp': 80
},
'last_update': time.time()
}
test_edge_no_dongle_stats = {
'name': 'ace-menlo-rasp-pi',
'status': {
'control_plane': 'connected',
'user_plane': 'connected'
},
'speedtest': {
'ping': {
'dry_run': {
'transmitted': 3,
'received': 2,
'median': 5.0,
'min': 1.0,
'avg': 5.0,
'max': 9.0,
'stddev': 1.0
},
'dns': {
'transmitted': 10,
'received': 9,
'median': 4.0,
'min': 2.0,
'avg': 4.0,
'max': 6.0,
'stddev': 1.0
},
'iperf_server': {
'transmitted': 10,
'received': 10,
'median': 3.0,
'min': 1.0,
'avg': 3.0,
'max': 5.0,
'stddev': 1.0
},
'management_server': {
'transmitted': 10,
'received': 8,
'median': 6.0,
'min': 2.0,
'avg': 6.0,
'max': 10.0,
'stddev': 1.0
}
},
'iperf': {
'cluster': {
'downlink': 100.0,
'uplink': 10.0
}
}
},
'signal_quality': {
'rsrq': 30,
'rsrp': 80
},
'last_update': time.time()
}
class MyEvent:
def __init__ (self, location = "", description = "", summary = "", start = None, end = None, all_day = False):
self.location = location
self.description = description
self.summary = summary
self.start = start
self.end = end
self.all_day = all_day
class MyEventNoLoc:
def __init__ (self, description = "", summary = ""):
self.description = description
self.summary = summary
class TestEdgeMonitoringServer(unittest.TestCase):
def setUp(self):
self.app = ems.app.test_client()
self.emulated_time = time.mktime(time.strptime("2021-04-05 00:00:00", "%Y-%m-%d %H:%M:%S"))
self.time_method = time.time
time.time = self._get_time
def tearDown(self):
time.time = self.time_method
def _get_time(self):
return self.emulated_time
def _assert_status_metrics_exist(self, data):
self.assertTrue('aetheredge_status_control_plane{name="ace-menlo-rasp-pi"} 2.0' in data)
self.assertTrue('aetheredge_status_user_plane{name="ace-menlo-rasp-pi"} 2.0' in data)
self.assertTrue('aetheredge_last_update{name="ace-menlo-rasp-pi"}' in data)
self.assertTrue('aetheredge_connect_test_ok{name="ace-menlo-rasp-pi"} 1.0' in data)
self.assertTrue('aetheredge_ping_test_ok{name="ace-menlo-rasp-pi"} 1.0' in data)
self.assertTrue('aetheredge_e2e_tests_ok{name="ace-menlo-rasp-pi"} 1.0' in data)
self.assertTrue('aetheredge_e2e_tests_down{name="ace-menlo-rasp-pi"} 0.0' in data)
def _assert_speedtest_metrics_exist(self, data):
self.assertTrue('aetheredge_ping_dry_run_test_transmitted{name="ace-menlo-rasp-pi"} 3' in data)
self.assertTrue('aetheredge_ping_dry_run_test_received{name="ace-menlo-rasp-pi"} 2' in data)
self.assertTrue('aetheredge_ping_dry_run_test_median{name="ace-menlo-rasp-pi"} 5.0' in data)
self.assertTrue('aetheredge_ping_dry_run_test_min{name="ace-menlo-rasp-pi"} 1.0' in data)
self.assertTrue('aetheredge_ping_dry_run_test_avg{name="ace-menlo-rasp-pi"} 5.0' in data)
self.assertTrue('aetheredge_ping_dry_run_test_max{name="ace-menlo-rasp-pi"} 9.0' in data)
self.assertTrue('aetheredge_ping_dry_run_test_stddev{name="ace-menlo-rasp-pi"} 1.0' in data)
self.assertTrue('aetheredge_ping_dns_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
self.assertTrue('aetheredge_ping_dns_test_received{name="ace-menlo-rasp-pi"} 9' in data)
self.assertTrue('aetheredge_ping_dns_test_median{name="ace-menlo-rasp-pi"} 4.0' in data)
self.assertTrue('aetheredge_ping_dns_test_min{name="ace-menlo-rasp-pi"} 2.0' in data)
self.assertTrue('aetheredge_ping_dns_test_avg{name="ace-menlo-rasp-pi"} 4.0' in data)
self.assertTrue('aetheredge_ping_dns_test_max{name="ace-menlo-rasp-pi"} 6.0' in data)
self.assertTrue('aetheredge_ping_dns_test_stddev{name="ace-menlo-rasp-pi"} 1.0' in data)
self.assertTrue('aetheredge_ping_iperf_server_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
self.assertTrue('aetheredge_ping_iperf_server_test_received{name="ace-menlo-rasp-pi"} 10' in data)
self.assertTrue('aetheredge_ping_iperf_server_test_median{name="ace-menlo-rasp-pi"} 3.0' in data)
self.assertTrue('aetheredge_ping_iperf_server_test_min{name="ace-menlo-rasp-pi"} 1.0' in data)
self.assertTrue('aetheredge_ping_iperf_server_test_avg{name="ace-menlo-rasp-pi"} 3.0' in data)
self.assertTrue('aetheredge_ping_iperf_server_test_max{name="ace-menlo-rasp-pi"} 5.0' in data)
self.assertTrue('aetheredge_ping_iperf_server_test_stddev{name="ace-menlo-rasp-pi"} 1.0' in data)
self.assertTrue('aetheredge_ping_management_server_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
self.assertTrue('aetheredge_ping_management_server_test_received{name="ace-menlo-rasp-pi"} 8' in data)
self.assertTrue('aetheredge_ping_management_server_test_median{name="ace-menlo-rasp-pi"} 6.0' in data)
self.assertTrue('aetheredge_ping_management_server_test_min{name="ace-menlo-rasp-pi"} 2.0' in data)
self.assertTrue('aetheredge_ping_management_server_test_avg{name="ace-menlo-rasp-pi"} 6.0' in data)
self.assertTrue('aetheredge_ping_management_server_test_max{name="ace-menlo-rasp-pi"} 10.0' in data)
self.assertTrue('aetheredge_ping_management_server_test_stddev{name="ace-menlo-rasp-pi"} 1.0' in data)
self.assertTrue('aetheredge_iperf_cluster_downlink_test{name="ace-menlo-rasp-pi"} 100.0' in data)
self.assertTrue('aetheredge_iperf_cluster_uplink_test{name="ace-menlo-rasp-pi"} 10.0' in data)
def _assert_signal_quality_metrics_exist(self, data):
self.assertTrue('aetheredge_signal_quality_rsrq{name="ace-menlo-rasp-pi"} 30' in data)
self.assertTrue('aetheredge_signal_quality_rsrp{name="ace-menlo-rasp-pi"} 80' in data)
def _assert_dongle_stats_metrics_exist(self, data):
self.assertTrue('aetheredge_dongle_stats_imsi{name="ace-menlo-rasp-pi"}' in data)
self.assertTrue('aetheredge_dongle_stats_cellglobalid{name="ace-menlo-rasp-pi"} 8.67518969411584e+014' in data)
self.assertTrue('aetheredge_dongle_stats_plmnstatus{name="ace-menlo-rasp-pi"} 3' in data)
self.assertTrue('aetheredge_dongle_stats_phycellid{name="ace-menlo-rasp-pi"} 101' in data)
def test_match_location(self):
event = MyEvent(location = "ace-menlo-rasp-pi-production")
self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
event = MyEvent(location = "(Compute)-MP-1-Aether Production")
self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
def test_match_description(self):
event = MyEvent(description = "ace-menlo-rasp-pi-production")
self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
event = MyEvent(description = "(Compute)-MP-1-Aether Production")
self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
def test_match_summary(self):
event = MyEvent(summary = "ace-menlo-rasp-pi-production")
self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
event = MyEvent(summary = "(Compute)-MP-1-Aether Production")
self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
def test_no_match(self):
event = MyEvent(summary = "ace-menlo-rasp-pi-production, (Compute)-MP-1-Aether Production")
self.assertFalse(ems.is_my_event(event, "ace-intel"))
self.assertFalse(ems.is_my_event(event, "(Compute)-MP-1-Aether Staging"))
self.assertFalse(ems.is_my_event(event, "ace-menlo"))
def test_missing_field(self):
event = MyEventNoLoc(description = "(Compute)-MP-1-Aether Production")
self.assertTrue(ems.is_my_event(event, "ace-menlo-rasp-pi"))
def test_in_window(self):
events = []
now = datetime.datetime.now(pytz.utc)
events.append(MyEvent(location = "(Compute)-MP-1-Aether Production",
start = now - datetime.timedelta(hours=1),
end = now + datetime.timedelta(hours=1)))
self.assertTrue(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
self.assertFalse(ems.in_maintenance_window(events, "ace-tucson", now))
def test_not_in_window(self):
events = []
now = datetime.datetime.now(pytz.utc)
events.append(MyEvent(location = "ace-menlo-rasp-pi-production",
start = now + datetime.timedelta(hours=1),
end = now + datetime.timedelta(hours=2)))
self.assertFalse(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
def test_no_events(self):
events = []
now = datetime.datetime.now(pytz.utc)
self.assertFalse(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
def test_all_day_events(self):
events = []
events.append(MyEvent(location = "ace-menlo-rasp-pi-production",
start = datetime.datetime(2020, 9, 2, 0, 0),
end = datetime.datetime(2020, 9, 3, 0, 0),
all_day = True))
ems.process_all_day_events(events)
now = datetime.datetime(2020, 9, 2, 12, 0, tzinfo=pytz.utc)
self.assertTrue(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
now = datetime.datetime(2020, 9, 3, 12, 0, tzinfo=pytz.utc)
self.assertFalse(ems.in_maintenance_window(events, "ace-menlo-rasp-pi", now))
def test_get_edges(self):
response = self.app.get('/edges')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(len(data['edges']), 1)
self.assertEqual(data['edges'][0]['name'], 'ace-example')
def test_create_and_delete_edge_legacy(self):
response = self.app.post('/edges', json=test_edge)
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
response = self.app.get('/edges')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(len(data['edges']), 2)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self._assert_status_metrics_exist(data)
self._assert_speedtest_metrics_exist(data)
self._assert_signal_quality_metrics_exist(data)
response = self.app.delete('/edges/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['result'], True)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self.assertFalse('ace-menlo-rasp-pi' in data)
response = self.app.get('/edges')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(len(data['edges']), 1)
def test_create_and_delete_edge(self):
response = self.app.post('/testresults', json=test_edge)
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
response = self.app.get('/edges')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(len(data['edges']), 2)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self._assert_status_metrics_exist(data)
self._assert_speedtest_metrics_exist(data)
self._assert_signal_quality_metrics_exist(data)
self._assert_dongle_stats_metrics_exist(data)
response = self.app.delete('/testresults/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['result'], True)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self.assertFalse('ace-menlo-rasp-pi' in data)
response = self.app.get('/edges')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(len(data['edges']), 1)
def test_create_and_delete_edge_speed_test(self):
response = self.app.post('/testresults', json=test_edge)
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self._assert_speedtest_metrics_exist(data)
response = self.app.delete('/testresults/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['result'], True)
def test_backwards_compatible_status_only(self):
response = self.app.post('/testresults', json=test_edge_status_only)
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self.assertFalse('aetheredge_signal_quality_rsrq{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_signal_quality_rsrp{name="ace-menlo-rasp-pi"}' in data)
self._assert_status_metrics_exist(data)
response = self.app.delete('/testresults/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['result'], True)
def test_backwards_compatible_no_speedtest(self):
response = self.app.post('/testresults', json=test_edge_no_speedtest)
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self.assertFalse('aetheredge_ping_dry_run_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_received{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_median{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_min{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_avg{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_max{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_stddev{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dns_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dns_test_received{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dns_test_median{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dns_test_min{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dns_test_avg{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dns_test_max{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dns_test_stddev{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_received{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_median{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_min{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_avg{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_max{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_stddev{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_received{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_median{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_min{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_avg{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_max{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_stddev{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_iperf_cluster_downlink_test{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_iperf_cluster_uplink_test{name="ace-menlo-rasp-pi"}' in data)
self._assert_status_metrics_exist(data)
self._assert_signal_quality_metrics_exist(data)
response = self.app.delete('/testresults/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['result'], True)
def test_backwards_compatible_no_signal_quality(self):
response = self.app.post('/testresults', json=test_edge_no_signal_quality)
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self.assertFalse('aetheredge_signal_quality_rsrq{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_signal_quality_rsrp{name="ace-menlo-rasp-pi"}' in data)
self._assert_status_metrics_exist(data)
self._assert_speedtest_metrics_exist(data)
response = self.app.delete('/testresults/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['result'], True)
def test_timeout_stale_result(self):
response = self.app.post('/testresults', json=test_edge)
data = json.loads(response.get_data(as_text=True))
# print(json.dumps(data, indent=2))
self.assertEqual(data['edge']['status']['control_plane'], 'connected')
self.assertEqual(data['edge']['status']['user_plane'], 'connected')
self.assertEqual(data['edge']['speedtest']['ping']['dns']['avg'], 4.0)
self.assertEqual(data['edge']['speedtest']['ping']['iperf_server']['avg'], 3.0)
self.assertTrue('signal_quality' in data['edge'])
self.emulated_time += (ems.NO_RESULT_THRESHOLD + 1)
response = self.app.get('/edges/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
# print(json.dumps(data, indent=2))
self.assertEqual(data['edge']['status']['control_plane'], 'no result')
self.assertEqual(data['edge']['status']['user_plane'], 'no result')
self.assertEqual(data['edge']['speedtest']['ping']['dns']['avg'], 0.0)
self.assertEqual(data['edge']['speedtest']['ping']['iperf_server']['avg'], 0.0)
self.assertFalse('signal_quality' in data['edge'])
def test_backwards_compatible_no_iperf(self):
response = self.app.post('/testresults', json=test_edge_no_iperf)
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self.assertFalse('aetheredge_iperf_cluster_downlink{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_iperf_cluster_uplink{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_received{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_median{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_min{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_avg{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_max{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_stddev{name="ace-menlo-rasp-pi"}' in data)
response = self.app.delete('/testresults/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['result'], True)
def test_backwards_compatible_pre_0_7_0(self):
response = self.app.post('/testresults', json=test_edge_pre_0_7_0)
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
# print(data)
self.assertFalse('aetheredge_ping_dry_run_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_received{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_median{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_min{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_avg{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_max{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dry_run_test_stddev{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_transmitted{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_received{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_median{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_min{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_avg{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_max{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_management_server_test_stddev{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_ping_dns_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
self.assertFalse('aetheredge_ping_dns_test_received{name="ace-menlo-rasp-pi"} 9' in data)
self.assertFalse('aetheredge_ping_dns_test_median{name="ace-menlo-rasp-pi"} 4.0' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_transmitted{name="ace-menlo-rasp-pi"} 10' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_received{name="ace-menlo-rasp-pi"} 10' in data)
self.assertFalse('aetheredge_ping_iperf_server_test_median{name="ace-menlo-rasp-pi"} 3.0' in data)
response = self.app.delete('/testresults/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['result'], True)
def test_backwards_compatible_no_dongle_stats(self):
response = self.app.post('/testresults', json=test_edge_no_dongle_stats)
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['edge']['name'], 'ace-menlo-rasp-pi')
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
self.assertFalse('aetheredge_dongle_stats_imsi{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_dongle_stats_cellglobalid{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_dongle_stats_plmnstatus{name="ace-menlo-rasp-pi"}' in data)
self.assertFalse('aetheredge_dongle_stats_phycellid{name="ace-menlo-rasp-pi"}' in data)
response = self.app.delete('/testresults/ace-menlo-rasp-pi')
data = json.loads(response.get_data(as_text=True))
self.assertEqual(data['result'], True)
def test_handle_invalid_schema(self):
response = self.app.post('/testresults', json="")
self.assertEqual(response.status_code, 400)
no_name = deepcopy(test_edge)
del no_name['name']
response = self.app.post('/testresults', json=no_name)
self.assertEqual(response.status_code, 400)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
self.assertFalse('ace-menlo-rasp-pi' in data)
no_status = deepcopy(test_edge)
del no_status['status']
response = self.app.post('/testresults', json=no_status)
self.assertEqual(response.status_code, 400)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
self.assertFalse('ace-menlo-rasp-pi' in data)
bad_status = deepcopy(test_edge)
bad_status['status']['control_plane'] = 1
response = self.app.post('/testresults', json=bad_status)
self.assertEqual(response.status_code, 400)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
self.assertFalse('ace-menlo-rasp-pi' in data)
bad_ping_result = deepcopy(test_edge)
bad_ping_result['speedtest']['ping']['dns']['min'] = "foo"
response = self.app.post('/testresults', json=bad_ping_result)
self.assertEqual(response.status_code, 400)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
self.assertFalse('ace-menlo-rasp-pi' in data)
bad_iperf_result = deepcopy(test_edge)
bad_iperf_result['speedtest']['iperf']['cluster']['uplink'] = "foo"
response = self.app.post('/testresults', json=bad_iperf_result)
self.assertEqual(response.status_code, 400)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
self.assertFalse('ace-menlo-rasp-pi' in data)
bad_signal_quality = deepcopy(test_edge)
del bad_signal_quality['signal_quality']['rsrq']
response = self.app.post('/testresults', json=bad_signal_quality)
self.assertEqual(response.status_code, 400)
response = self.app.get('/edges/metrics')
data = response.get_data(as_text=True)
self.assertFalse('ace-menlo-rasp-pi' in data)
if __name__ == '__main__':
import xmlrunner
with open('results.xml', 'wb') as output:
unittest.main(testRunner=xmlrunner.XMLTestRunner(verbosity=2, output=output))