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