blob: 75f55befe6c1d9522a515b5982815239edfdbcf1 [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
14import asyncio
15from typing import Dict
16from unittest import mock
17
18from lte.protos.mconfig import mconfigs_pb2
19from common.service import MagmaService
20from devices.device_map import get_device_handler_from_name
21from devices.device_utils import EnodebDeviceName
22from state_machines.enb_acs import EnodebAcsStateMachine
23from state_machines.enb_acs_manager import StateMachineManager
24from tests.test_utils.config_builder import EnodebConfigBuilder
25
26
27class EnodebAcsStateMachineBuilder:
28 @classmethod
29 def build_acs_manager(
30 cls,
31 device: EnodebDeviceName = EnodebDeviceName.BAICELLS,
32 ) -> StateMachineManager:
33 service = cls.build_magma_service(device)
34 return StateMachineManager(service)
35
36 @classmethod
37 def build_multi_enb_acs_manager(
38 cls,
39 ) -> StateMachineManager:
40 service = cls.build_multi_enb_magma_service()
41 return StateMachineManager(service)
42
43 @classmethod
44 def build_multi_enb_acs_state_machine(
45 cls,
46 device: EnodebDeviceName = EnodebDeviceName.BAICELLS,
47 ) -> EnodebAcsStateMachine:
48 # Build the state_machine
49 service = cls.build_multi_enb_magma_service()
50 handler_class = get_device_handler_from_name(device)
51 acs_state_machine = handler_class(service)
52 return acs_state_machine
53
54 @classmethod
55 def build_acs_state_machine(
56 cls,
57 device: EnodebDeviceName = EnodebDeviceName.BAICELLS,
58 ) -> EnodebAcsStateMachine:
59 # Build the state_machine
60 service = cls.build_magma_service(device)
61 handler_class = get_device_handler_from_name(device)
62 acs_state_machine = handler_class(service)
63 return acs_state_machine
64
65 @classmethod
66 def build_magma_service(
67 cls,
68 device: EnodebDeviceName = EnodebDeviceName.BAICELLS,
69 mconfig: mconfigs_pb2.EnodebD = None,
70 service_config: Dict = None,
71 ) -> MagmaService:
72 event_loop = asyncio.get_event_loop()
73 if not mconfig:
74 mconfig = EnodebConfigBuilder.get_mconfig(device)
75 if not service_config:
76 service_config = EnodebConfigBuilder.get_service_config()
77 with mock.patch('magma.common.service.MagmaService') as MockService:
78 MockService.config = service_config
79 MockService.mconfig = mconfig
80 MockService.loop = event_loop
81 return MockService
82
83 @classmethod
84 def build_multi_enb_magma_service(cls) -> MagmaService:
85 event_loop = asyncio.get_event_loop()
86 mconfig = EnodebConfigBuilder.get_multi_enb_mconfig()
87 service_config = EnodebConfigBuilder.get_service_config()
88 with mock.patch('magma.common.service.MagmaService') as MockService:
89 MockService.config = service_config
90 MockService.mconfig = mconfig
91 MockService.loop = event_loop
92 return MockService