Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 1 | """ |
| 2 | Copyright 2020 The Magma Authors. |
| 3 | |
| 4 | This source code is licensed under the BSD-style license found in the |
| 5 | LICENSE file in the root directory of this source tree. |
| 6 | |
| 7 | Unless required by applicable law or agreed to in writing, software |
| 8 | distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | See the License for the specific language governing permissions and |
| 11 | limitations under the License. |
| 12 | """ |
| 13 | |
| 14 | # pylint: disable=protected-access |
| 15 | |
| 16 | from unittest import TestCase |
| 17 | |
| 18 | from data_models.data_model_parameters import ParameterName |
| 19 | from device_config.enodeb_configuration import EnodebConfiguration |
| 20 | from devices.experimental.cavium import CaviumTrDataModel |
| 21 | |
| 22 | |
| 23 | class EnodebConfigurationTest(TestCase): |
| 24 | def setUp(self): |
| 25 | self.config = EnodebConfiguration(CaviumTrDataModel) |
| 26 | |
| 27 | def tearDown(self): |
| 28 | self.config = None |
| 29 | |
| 30 | def test_data_model(self) -> None: |
| 31 | data_model = self.config.data_model |
| 32 | expected = CaviumTrDataModel |
| 33 | self.assertEqual(data_model, expected, 'Data model fetch incorrect') |
| 34 | |
| 35 | def test_get_has_set_parameter(self) -> None: |
| 36 | param = ParameterName.ADMIN_STATE |
| 37 | self.config.set_parameter(param, True) |
| 38 | self.assertTrue( |
| 39 | self.config.has_parameter(param), |
| 40 | 'Expected to have parameter', |
| 41 | ) |
| 42 | param_value = self.config.get_parameter(param) |
| 43 | expected = True |
| 44 | self.assertEqual( |
| 45 | param_value, expected, |
| 46 | 'Parameter value does not match what was set', |
| 47 | ) |
| 48 | |
| 49 | def test_add_has_delete_object(self) -> None: |
| 50 | object_name = ParameterName.PLMN_N % 1 |
| 51 | self.assertFalse(self.config.has_object(object_name)) |
| 52 | self.config.add_object(object_name) |
| 53 | self.assertTrue(self.config.has_object(object_name)) |
| 54 | self.config.delete_object(object_name) |
| 55 | self.assertFalse(self.config.has_object(object_name)) |
| 56 | |
| 57 | def test_get_parameter_names(self) -> None: |
| 58 | # Should start off as an empty list |
| 59 | names_list = self.config.get_parameter_names() |
| 60 | self.assertEqual(len(names_list), 0, 'Expected 0 names') |
| 61 | |
| 62 | # Should grow as we set parameters |
| 63 | self.config.set_parameter(ParameterName.ADMIN_STATE, True) |
| 64 | names_list = self.config.get_parameter_names() |
| 65 | self.assertEqual(len(names_list), 1, 'Expected 1 name') |
| 66 | |
| 67 | # Parameter names should not include objects |
| 68 | self.config.add_object(ParameterName.PLMN) |
| 69 | names_list = self.config.get_parameter_names() |
| 70 | self.assertEqual(len(names_list), 1, 'Expected 1 name') |
| 71 | |
| 72 | def test_get_object_names(self) -> None: |
| 73 | # Should start off as an empty list |
| 74 | obj_list = self.config.get_object_names() |
| 75 | self.assertEqual(len(obj_list), 0, 'Expected 0 names') |
| 76 | |
| 77 | # Should grow as we set parameters |
| 78 | self.config.add_object(ParameterName.PLMN) |
| 79 | obj_list = self.config.get_object_names() |
| 80 | self.assertEqual(len(obj_list), 1, 'Expected 1 names') |
| 81 | |
| 82 | def test_get_set_parameter_for_object(self) -> None: |
| 83 | self.config.add_object(ParameterName.PLMN_N % 1) |
| 84 | self.config.set_parameter_for_object( |
| 85 | ParameterName.PLMN_N_CELL_RESERVED % 1, True, |
| 86 | ParameterName.PLMN_N % 1, |
| 87 | ) |
| 88 | param_value = self.config.get_parameter_for_object( |
| 89 | ParameterName.PLMN_N_CELL_RESERVED % 1, ParameterName.PLMN_N % 1, |
| 90 | ) |
| 91 | self.assertTrue( |
| 92 | param_value, |
| 93 | 'Expected that the param for object was set correctly', |
| 94 | ) |
| 95 | |
| 96 | def test_get_parameter_names_for_object(self) -> None: |
| 97 | # Should start off empty |
| 98 | self.config.add_object(ParameterName.PLMN_N % 1) |
| 99 | param_list = self.config.get_parameter_names_for_object( |
| 100 | ParameterName.PLMN_N % 1, |
| 101 | ) |
| 102 | self.assertEqual(len(param_list), 0, 'Should be an empty param list') |
| 103 | |
| 104 | # Should increment as we set parameters |
| 105 | self.config.set_parameter_for_object( |
| 106 | ParameterName.PLMN_N_CELL_RESERVED % 1, True, |
| 107 | ParameterName.PLMN_N % 1, |
| 108 | ) |
| 109 | param_list = self.config.get_parameter_names_for_object( |
| 110 | ParameterName.PLMN_N % 1, |
| 111 | ) |
| 112 | self.assertEqual(len(param_list), 1, 'Should not be an empty list') |