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 | # pylint: disable=protected-access |
| 7 | from devices.device_utils import EnodebDeviceName |
| 8 | from tests.test_utils.enb_acs_builder import ( |
| 9 | EnodebAcsStateMachineBuilder, |
| 10 | ) |
| 11 | from tests.test_utils.enodeb_handler import EnodebHandlerTestCase |
| 12 | from tests.test_utils.tr069_msg_builder import Tr069MessageBuilder |
| 13 | from tr069 import models |
| 14 | |
| 15 | |
| 16 | class BaicellsQAFBHandlerTests(EnodebHandlerTestCase): |
| 17 | def test_manual_reboot(self) -> None: |
| 18 | """ |
| 19 | Test a scenario where a Magma user goes through the enodebd CLI to |
| 20 | reboot the Baicells eNodeB. |
| 21 | |
| 22 | This checks the scenario where the command is not sent in the middle |
| 23 | of a TR-069 provisioning session. |
| 24 | """ |
| 25 | acs_state_machine = \ |
| 26 | EnodebAcsStateMachineBuilder \ |
| 27 | .build_acs_state_machine(EnodebDeviceName.BAICELLS_QAFB) |
| 28 | |
| 29 | # User uses the CLI tool to get eNodeB to reboot |
| 30 | acs_state_machine.reboot_asap() |
| 31 | |
| 32 | # And now the Inform message arrives from the eNodeB |
| 33 | inform_msg = \ |
| 34 | Tr069MessageBuilder.get_qafb_inform( |
| 35 | '48BF74', |
| 36 | 'BaiBS_QAFBv123', |
| 37 | '1202000181186TB0006', |
| 38 | ['2 PERIODIC'], |
| 39 | ) |
| 40 | resp = acs_state_machine.handle_tr069_message(inform_msg) |
| 41 | self.assertTrue( |
| 42 | isinstance(resp, models.InformResponse), |
| 43 | 'In reboot sequence, state machine should still ' |
| 44 | 'respond to an Inform with InformResponse.', |
| 45 | ) |
| 46 | req = models.DummyInput() |
| 47 | resp = acs_state_machine.handle_tr069_message(req) |
| 48 | self.assertTrue( |
| 49 | isinstance(resp, models.Reboot), |
| 50 | 'In reboot sequence, state machine should send a ' |
| 51 | 'Reboot message.', |
| 52 | ) |
| 53 | req = Tr069MessageBuilder.get_reboot_response() |
| 54 | resp = acs_state_machine.handle_tr069_message(req) |
| 55 | self.assertTrue( |
| 56 | isinstance(resp, models.DummyInput), |
| 57 | 'State machine should end TR-069 session after ' |
| 58 | 'receiving a RebootResponse', |
| 59 | ) |
| 60 | |
| 61 | def test_manual_reboot_during_provisioning(self) -> None: |
| 62 | """ |
| 63 | Test a scenario where a Magma user goes through the enodebd CLI to |
| 64 | reboot the Baicells eNodeB. |
| 65 | |
| 66 | This checks the scenario where the command is sent in the middle |
| 67 | of a TR-069 provisioning session. |
| 68 | """ |
| 69 | acs_state_machine = \ |
| 70 | EnodebAcsStateMachineBuilder \ |
| 71 | .build_acs_state_machine(EnodebDeviceName.BAICELLS_QAFB) |
| 72 | |
| 73 | # Send an Inform message, wait for an InformResponse |
| 74 | inform_msg = \ |
| 75 | Tr069MessageBuilder.get_qafb_inform( |
| 76 | '48BF74', |
| 77 | 'BaiBS_QAFBv123', |
| 78 | '1202000181186TB0006', |
| 79 | ['2 PERIODIC'], |
| 80 | ) |
| 81 | resp = acs_state_machine.handle_tr069_message(inform_msg) |
| 82 | self.assertTrue( |
| 83 | isinstance(resp, models.InformResponse), |
| 84 | 'Should respond with an InformResponse', |
| 85 | ) |
| 86 | |
| 87 | # Send an empty http request to kick off the rest of provisioning |
| 88 | req = models.DummyInput() |
| 89 | resp = acs_state_machine.handle_tr069_message(req) |
| 90 | |
| 91 | # Expect a request for an optional parameter, three times |
| 92 | self.assertTrue( |
| 93 | isinstance(resp, models.GetParameterValues), |
| 94 | 'State machine should be requesting param values', |
| 95 | ) |
| 96 | req = Tr069MessageBuilder.get_fault() |
| 97 | |
| 98 | # User uses the CLI tool to get eNodeB to reboot |
| 99 | acs_state_machine.reboot_asap() |
| 100 | |
| 101 | resp = acs_state_machine.handle_tr069_message(req) |
| 102 | self.assertTrue( |
| 103 | isinstance(resp, models.Reboot), |
| 104 | 'In reboot sequence, state machine should send a ' |
| 105 | 'Reboot message.', |
| 106 | ) |
| 107 | req = Tr069MessageBuilder.get_reboot_response() |
| 108 | resp = acs_state_machine.handle_tr069_message(req) |
| 109 | self.assertTrue( |
| 110 | isinstance(resp, models.DummyInput), |
| 111 | 'State machine should end TR-069 session after ' |
| 112 | 'receiving a RebootResponse', |
| 113 | ) |
| 114 | |
| 115 | def test_provision(self) -> None: |
| 116 | acs_state_machine = \ |
| 117 | EnodebAcsStateMachineBuilder \ |
| 118 | .build_acs_state_machine(EnodebDeviceName.BAICELLS_QAFB) |
| 119 | |
| 120 | # Send an Inform message, wait for an InformResponse |
| 121 | inform_msg = \ |
| 122 | Tr069MessageBuilder.get_qafb_inform( |
| 123 | '48BF74', |
| 124 | 'BaiBS_QAFBv123', |
| 125 | '1202000181186TB0006', |
| 126 | ['2 PERIODIC'], |
| 127 | ) |
| 128 | resp = acs_state_machine.handle_tr069_message(inform_msg) |
| 129 | self.assertTrue( |
| 130 | isinstance(resp, models.InformResponse), |
| 131 | 'Should respond with an InformResponse', |
| 132 | ) |
| 133 | |
| 134 | # Send an empty http request to kick off the rest of provisioning |
| 135 | req = models.DummyInput() |
| 136 | resp = acs_state_machine.handle_tr069_message(req) |
| 137 | |
| 138 | # Expect a request for read-only params |
| 139 | self.assertTrue( |
| 140 | isinstance(resp, models.GetParameterValues), |
| 141 | 'State machine should be requesting param values', |
| 142 | ) |
| 143 | req = Tr069MessageBuilder.get_qafb_read_only_param_values_response() |
| 144 | |
| 145 | # Send back some typical values |
| 146 | # And then SM should request regular parameter values |
| 147 | resp = acs_state_machine.handle_tr069_message(req) |
| 148 | self.assertTrue( |
| 149 | isinstance(resp, models.GetParameterValues), |
| 150 | 'State machine should be requesting param values', |
| 151 | ) |
| 152 | |
| 153 | # Send back typical values for the regular parameters |
| 154 | req = Tr069MessageBuilder.\ |
| 155 | get_qafb_regular_param_values_response( |
| 156 | admin_state=False, |
| 157 | earfcndl=39150, |
| 158 | ) |
| 159 | resp = acs_state_machine.handle_tr069_message(req) |
| 160 | |
| 161 | # SM will be requesting object parameter values |
| 162 | self.assertTrue( |
| 163 | isinstance(resp, models.GetParameterValues), |
| 164 | 'State machine should be requesting object param vals', |
| 165 | ) |
| 166 | |
| 167 | # Send back some typical values for object parameters |
| 168 | req = Tr069MessageBuilder.get_qafb_object_param_values_response() |
| 169 | resp = acs_state_machine.handle_tr069_message(req) |
| 170 | |
| 171 | self.assertTrue( |
| 172 | isinstance(resp, models.AddObject), |
| 173 | 'State machine should be adding objects', |
| 174 | ) |
| 175 | |
| 176 | def test_get_rpc_methods_cold(self) -> None: |
| 177 | """ |
| 178 | Test the scenario where: |
| 179 | - enodeB just booted |
| 180 | - enodeB is cold and has no state of ACS RPCMethods |
| 181 | - Simulate the enodeB performing the initial Inform and |
| 182 | the call for the GetRPCMethods, and the subsequent Empty |
| 183 | response for provisioning |
| 184 | finishing on the Baicells eNodeB |
| 185 | |
| 186 | Verifies that the ACS will continue into provisioning |
| 187 | """ |
| 188 | acs_state_machine = \ |
| 189 | EnodebAcsStateMachineBuilder\ |
| 190 | .build_acs_state_machine(EnodebDeviceName.BAICELLS_QAFB) |
| 191 | |
| 192 | # Send an Inform message, wait for an InformResponse |
| 193 | inform_msg = \ |
| 194 | Tr069MessageBuilder.get_inform( |
| 195 | '48BF74', |
| 196 | 'BaiBS_QAFBv123', |
| 197 | '120200002618AGP0003', |
| 198 | ['1 BOOT'], |
| 199 | ) |
| 200 | resp = acs_state_machine.handle_tr069_message(inform_msg) |
| 201 | self.assertTrue( |
| 202 | isinstance(resp, models.InformResponse), |
| 203 | 'Should respond with an InformResponse', |
| 204 | ) |
| 205 | |
| 206 | # Send GetRPCMethods |
| 207 | req = models.GetRPCMethods() |
| 208 | resp = acs_state_machine.handle_tr069_message(req) |
| 209 | self.assertTrue( |
| 210 | isinstance(resp, models.GetRPCMethodsResponse), |
| 211 | 'State machine should be sending RPC methods', |
| 212 | ) |
| 213 | |
| 214 | # Send an empty http request to kick off the rest of provisioning |
| 215 | req = models.DummyInput() |
| 216 | resp = acs_state_machine.handle_tr069_message(req) |
| 217 | |
| 218 | # Expect a request for an optional parameter |
| 219 | self.assertTrue( |
| 220 | isinstance(resp, models.GetParameterValues), |
| 221 | 'State machine should be requesting param values', |
| 222 | ) |