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