blob: 65468760fc5385ad9ed16077ba9a0784b0b360f1 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# 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 Chen49950b92021-11-08 19:19:18 +08005
6# pylint: disable=protected-access
7
8from unittest import TestCase
9
10from data_models.data_model_parameters import ParameterName
11from device_config.enodeb_configuration import EnodebConfiguration
12from devices.experimental.cavium import CaviumTrDataModel
13
14
15class EnodebConfigurationTest(TestCase):
16 def setUp(self):
17 self.config = EnodebConfiguration(CaviumTrDataModel)
18
19 def tearDown(self):
20 self.config = None
21
22 def test_data_model(self) -> None:
23 data_model = self.config.data_model
24 expected = CaviumTrDataModel
25 self.assertEqual(data_model, expected, 'Data model fetch incorrect')
26
27 def test_get_has_set_parameter(self) -> None:
28 param = ParameterName.ADMIN_STATE
29 self.config.set_parameter(param, True)
30 self.assertTrue(
31 self.config.has_parameter(param),
32 'Expected to have parameter',
33 )
34 param_value = self.config.get_parameter(param)
35 expected = True
36 self.assertEqual(
37 param_value, expected,
38 'Parameter value does not match what was set',
39 )
40
41 def test_add_has_delete_object(self) -> None:
42 object_name = ParameterName.PLMN_N % 1
43 self.assertFalse(self.config.has_object(object_name))
44 self.config.add_object(object_name)
45 self.assertTrue(self.config.has_object(object_name))
46 self.config.delete_object(object_name)
47 self.assertFalse(self.config.has_object(object_name))
48
49 def test_get_parameter_names(self) -> None:
50 # Should start off as an empty list
51 names_list = self.config.get_parameter_names()
52 self.assertEqual(len(names_list), 0, 'Expected 0 names')
53
54 # Should grow as we set parameters
55 self.config.set_parameter(ParameterName.ADMIN_STATE, True)
56 names_list = self.config.get_parameter_names()
57 self.assertEqual(len(names_list), 1, 'Expected 1 name')
58
59 # Parameter names should not include objects
60 self.config.add_object(ParameterName.PLMN)
61 names_list = self.config.get_parameter_names()
62 self.assertEqual(len(names_list), 1, 'Expected 1 name')
63
64 def test_get_object_names(self) -> None:
65 # Should start off as an empty list
66 obj_list = self.config.get_object_names()
67 self.assertEqual(len(obj_list), 0, 'Expected 0 names')
68
69 # Should grow as we set parameters
70 self.config.add_object(ParameterName.PLMN)
71 obj_list = self.config.get_object_names()
72 self.assertEqual(len(obj_list), 1, 'Expected 1 names')
73
74 def test_get_set_parameter_for_object(self) -> None:
75 self.config.add_object(ParameterName.PLMN_N % 1)
76 self.config.set_parameter_for_object(
77 ParameterName.PLMN_N_CELL_RESERVED % 1, True,
78 ParameterName.PLMN_N % 1,
79 )
80 param_value = self.config.get_parameter_for_object(
81 ParameterName.PLMN_N_CELL_RESERVED % 1, ParameterName.PLMN_N % 1,
82 )
83 self.assertTrue(
84 param_value,
85 'Expected that the param for object was set correctly',
86 )
87
88 def test_get_parameter_names_for_object(self) -> None:
89 # Should start off empty
90 self.config.add_object(ParameterName.PLMN_N % 1)
91 param_list = self.config.get_parameter_names_for_object(
92 ParameterName.PLMN_N % 1,
93 )
94 self.assertEqual(len(param_list), 0, 'Should be an empty param list')
95
96 # Should increment as we set parameters
97 self.config.set_parameter_for_object(
98 ParameterName.PLMN_N_CELL_RESERVED % 1, True,
99 ParameterName.PLMN_N % 1,
100 )
101 param_list = self.config.get_parameter_names_for_object(
102 ParameterName.PLMN_N % 1,
103 )
104 self.assertEqual(len(param_list), 1, 'Should not be an empty list')