blob: 3138fcf1ec65bc4592cc224c7f1892a28174ec68 [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001"""
2Copyright 2020 The Magma Authors.
3
4This source code is licensed under the BSD-style license found in the
5LICENSE file in the root directory of this source tree.
6
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12"""
13
14# pylint: disable=protected-access
15from unittest import TestCase
16
17from lte.protos.enodebd_pb2 import SingleEnodebStatus
18from devices.device_utils import EnodebDeviceName
19from enodeb_status import (
20 get_all_enb_status,
21 get_enb_status,
22 get_service_status_old,
23 get_single_enb_status,
24)
25from state_machines.enb_acs_manager import StateMachineManager
26from tests.test_utils.enb_acs_builder import (
27 EnodebAcsStateMachineBuilder,
28)
29from tests.test_utils.spyne_builder import (
30 get_spyne_context_with_ip,
31)
32from tests.test_utils.tr069_msg_builder import Tr069MessageBuilder
33
34
35class EnodebStatusTests(TestCase):
36 def test_get_service_status_old(self):
37 manager = self._get_manager()
38 status = get_service_status_old(manager)
39 self.assertTrue(
40 status['enodeb_connected'] == '0',
41 'Should report no eNB connected',
42 )
43
44 ##### Start session for the first IP #####
45 ctx1 = get_spyne_context_with_ip("192.168.60.145")
46 # Send an Inform message, wait for an InformResponse
47 inform_msg = Tr069MessageBuilder.get_inform(
48 '48BF74',
49 'BaiBS_RTS_3.1.6',
50 '120200002618AGP0001',
51 )
52 manager.handle_tr069_message(ctx1, inform_msg)
53 status = get_service_status_old(manager)
54 self.assertTrue(
55 status['enodeb_connected'] == '1',
56 'Should report an eNB as conencted',
57 )
58 self.assertTrue(
59 status['enodeb_serial'] == '120200002618AGP0001',
60 'eNodeB serial should match the earlier Inform',
61 )
62
63 def test_get_enb_status(self):
64 acs_state_machine = \
65 EnodebAcsStateMachineBuilder\
66 .build_acs_state_machine(EnodebDeviceName.BAICELLS)
67 try:
68 get_enb_status(acs_state_machine)
69 except KeyError:
70 self.fail(
71 'Getting eNB status should succeed after constructor '
72 'runs.',
73 )
74
75 def test_get_single_enb_status(self):
76 manager = self._get_manager()
77 ctx1 = get_spyne_context_with_ip("192.168.60.145")
78 inform_msg = Tr069MessageBuilder.get_inform(
79 '48BF74',
80 'BaiBS_RTS_3.1.6',
81 '120200002618AGP0001',
82 )
83 manager.handle_tr069_message(ctx1, inform_msg)
84 status = get_single_enb_status('120200002618AGP0001', manager)
85 self.assertEquals(
86 status.connected,
87 SingleEnodebStatus.StatusProperty.Value('ON'),
88 'Status should be connected.',
89 )
90 self.assertEquals(
91 status.configured,
92 SingleEnodebStatus.StatusProperty.Value('OFF'),
93 'Status should be not configured.',
94 )
95
96 def test_get_enodeb_all_status(self):
97 manager = self._get_manager()
98
99 ##### Test Empty #####
100 enb_status_by_serial = get_all_enb_status(manager)
101 self.assertTrue(enb_status_by_serial == {}, "No eNB connected")
102
103 ##### Start session for the first IP #####
104 ctx1 = get_spyne_context_with_ip("192.168.60.145")
105 # Send an Inform message, wait for an InformResponse
106 inform_msg = Tr069MessageBuilder.get_inform(
107 '48BF74',
108 'BaiBS_RTS_3.1.6',
109 '120200002618AGP0001',
110 )
111 manager.handle_tr069_message(ctx1, inform_msg)
112 enb_status_by_serial = get_all_enb_status(manager)
113 enb_status = enb_status_by_serial.get('120200002618AGP0001')
114 self.assertEquals(
115 enb_status.enodeb_connected,
116 SingleEnodebStatus.StatusProperty.Value('ON'),
117 'Status should be connected.',
118 )
119
120 def _get_manager(self) -> StateMachineManager:
121 service = EnodebAcsStateMachineBuilder.build_magma_service()
122 return StateMachineManager(service)