blob: 7de7931868981b8c1b2d3a62faa6c9ac108f3839 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# SPDX-FileCopyrightText: 2020 The Magma Authors.
2# SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org>
3#
4# SPDX-License-Identifier: BSD-3-Clause
Wei-Yu Chen49950b92021-11-08 19:19:18 +08005
6# pylint: disable=protected-access
7from unittest import TestCase
8
9from lte.protos.enodebd_pb2 import SingleEnodebStatus
10from devices.device_utils import EnodebDeviceName
11from enodeb_status import (
12 get_all_enb_status,
13 get_enb_status,
14 get_service_status_old,
15 get_single_enb_status,
16)
17from state_machines.enb_acs_manager import StateMachineManager
18from tests.test_utils.enb_acs_builder import (
19 EnodebAcsStateMachineBuilder,
20)
21from tests.test_utils.spyne_builder import (
22 get_spyne_context_with_ip,
23)
24from tests.test_utils.tr069_msg_builder import Tr069MessageBuilder
25
26
27class EnodebStatusTests(TestCase):
28 def test_get_service_status_old(self):
29 manager = self._get_manager()
30 status = get_service_status_old(manager)
31 self.assertTrue(
32 status['enodeb_connected'] == '0',
33 'Should report no eNB connected',
34 )
35
36 ##### Start session for the first IP #####
37 ctx1 = get_spyne_context_with_ip("192.168.60.145")
38 # Send an Inform message, wait for an InformResponse
39 inform_msg = Tr069MessageBuilder.get_inform(
40 '48BF74',
41 'BaiBS_RTS_3.1.6',
42 '120200002618AGP0001',
43 )
44 manager.handle_tr069_message(ctx1, inform_msg)
45 status = get_service_status_old(manager)
46 self.assertTrue(
47 status['enodeb_connected'] == '1',
48 'Should report an eNB as conencted',
49 )
50 self.assertTrue(
51 status['enodeb_serial'] == '120200002618AGP0001',
52 'eNodeB serial should match the earlier Inform',
53 )
54
55 def test_get_enb_status(self):
56 acs_state_machine = \
57 EnodebAcsStateMachineBuilder\
58 .build_acs_state_machine(EnodebDeviceName.BAICELLS)
59 try:
60 get_enb_status(acs_state_machine)
61 except KeyError:
62 self.fail(
63 'Getting eNB status should succeed after constructor '
64 'runs.',
65 )
66
67 def test_get_single_enb_status(self):
68 manager = self._get_manager()
69 ctx1 = get_spyne_context_with_ip("192.168.60.145")
70 inform_msg = Tr069MessageBuilder.get_inform(
71 '48BF74',
72 'BaiBS_RTS_3.1.6',
73 '120200002618AGP0001',
74 )
75 manager.handle_tr069_message(ctx1, inform_msg)
76 status = get_single_enb_status('120200002618AGP0001', manager)
77 self.assertEquals(
78 status.connected,
79 SingleEnodebStatus.StatusProperty.Value('ON'),
80 'Status should be connected.',
81 )
82 self.assertEquals(
83 status.configured,
84 SingleEnodebStatus.StatusProperty.Value('OFF'),
85 'Status should be not configured.',
86 )
87
88 def test_get_enodeb_all_status(self):
89 manager = self._get_manager()
90
91 ##### Test Empty #####
92 enb_status_by_serial = get_all_enb_status(manager)
93 self.assertTrue(enb_status_by_serial == {}, "No eNB connected")
94
95 ##### Start session for the first IP #####
96 ctx1 = get_spyne_context_with_ip("192.168.60.145")
97 # Send an Inform message, wait for an InformResponse
98 inform_msg = Tr069MessageBuilder.get_inform(
99 '48BF74',
100 'BaiBS_RTS_3.1.6',
101 '120200002618AGP0001',
102 )
103 manager.handle_tr069_message(ctx1, inform_msg)
104 enb_status_by_serial = get_all_enb_status(manager)
105 enb_status = enb_status_by_serial.get('120200002618AGP0001')
106 self.assertEquals(
107 enb_status.enodeb_connected,
108 SingleEnodebStatus.StatusProperty.Value('ON'),
109 'Status should be connected.',
110 )
111
112 def _get_manager(self) -> StateMachineManager:
113 service = EnodebAcsStateMachineBuilder.build_magma_service()
114 return StateMachineManager(service)