blob: c1d82d295c98e1406f9769606fbc3afb1dda143a [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
14# pylint: disable=protected-access
15
16from unittest import TestCase
17
18from devices.device_utils import (
19 EnodebDeviceName,
20 _parse_sw_version,
21 get_device_name,
22)
23from exceptions import UnrecognizedEnodebError
24
25
26class EnodebConfigUtilsTest(TestCase):
27 def test_get_device_name(self) -> None:
28 # Baicells
29 oui = '34ED0B'
30 version = 'BaiStation_V100R001C00B110SPC003'
31 data_model = get_device_name(oui, version)
32 expected = EnodebDeviceName.BAICELLS
33 self.assertEqual(data_model, expected, 'Incorrect data model')
34
35 # Baicells before bug-fix
36 oui = '34ED0B'
37 version = 'BaiStation_V100R001C00B110SPC002'
38 data_model = get_device_name(oui, version)
39 expected = EnodebDeviceName.BAICELLS_OLD
40 self.assertEqual(data_model, expected, 'Incorrect data model')
41
42 # Baicells QAFB
43 oui = '48BF74'
44 version = 'BaiBS_QAFB_some_version'
45 data_model = get_device_name(oui, version)
46 expected = EnodebDeviceName.BAICELLS_QAFB
47 self.assertEqual(data_model, expected, 'Incorrect data model')
48
49 # Cavium
50 oui = '000FB7'
51 version = 'Some version of Cavium'
52 data_model = get_device_name(oui, version)
53 expected = EnodebDeviceName.CAVIUM
54 self.assertEqual(data_model, expected, 'Incorrect data model')
55
56 # Unsupported device OUI
57 oui = 'beepboopbeep'
58 version = 'boopboopboop'
59 with self.assertRaises(UnrecognizedEnodebError):
60 get_device_name(oui, version)
61
62 # Unsupported software version for Baicells
63 oui = '34ED0B'
64 version = 'blingblangblong'
65 with self.assertRaises(UnrecognizedEnodebError):
66 get_device_name(oui, version)
67
68 def test_parse_version(self):
69 """ Test that version string is parsed correctly """
70 self.assertEqual(
71 _parse_sw_version('BaiStation_V100R001C00B110SPC003'),
72 [100, 1, 0, 110, 3],
73 )
74 self.assertEqual(
75 _parse_sw_version('BaiStation_V100R001C00B060SPC012'),
76 [100, 1, 0, 60, 12],
77 )
78 self.assertEqual(
79 _parse_sw_version('BaiStation_V100R001C00B060SPC012_FB_3'),
80 [100, 1, 0, 60, 12],
81 )
82 # Incorrect number of digits
83 self.assertEqual(
84 _parse_sw_version('BaiStation_V10R001C00B060SPC012'),
85 None,
86 )
87 self.assertEqual(
88 _parse_sw_version('XYZ123'),
89 None,
90 )
91 self.assertEqual(
92 _parse_sw_version(''),
93 None,
94 )