Init commit for standalone enodebd
Change-Id: I88eeef5135dd7ba8551ddd9fb6a0695f5325337b
diff --git a/tests/device_utils_tests.py b/tests/device_utils_tests.py
new file mode 100644
index 0000000..c1d82d2
--- /dev/null
+++ b/tests/device_utils_tests.py
@@ -0,0 +1,94 @@
+"""
+Copyright 2020 The Magma Authors.
+
+This source code is licensed under the BSD-style license found in the
+LICENSE file in the root directory of this source tree.
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+"""
+
+# pylint: disable=protected-access
+
+from unittest import TestCase
+
+from devices.device_utils import (
+ EnodebDeviceName,
+ _parse_sw_version,
+ get_device_name,
+)
+from exceptions import UnrecognizedEnodebError
+
+
+class EnodebConfigUtilsTest(TestCase):
+ def test_get_device_name(self) -> None:
+ # Baicells
+ oui = '34ED0B'
+ version = 'BaiStation_V100R001C00B110SPC003'
+ data_model = get_device_name(oui, version)
+ expected = EnodebDeviceName.BAICELLS
+ self.assertEqual(data_model, expected, 'Incorrect data model')
+
+ # Baicells before bug-fix
+ oui = '34ED0B'
+ version = 'BaiStation_V100R001C00B110SPC002'
+ data_model = get_device_name(oui, version)
+ expected = EnodebDeviceName.BAICELLS_OLD
+ self.assertEqual(data_model, expected, 'Incorrect data model')
+
+ # Baicells QAFB
+ oui = '48BF74'
+ version = 'BaiBS_QAFB_some_version'
+ data_model = get_device_name(oui, version)
+ expected = EnodebDeviceName.BAICELLS_QAFB
+ self.assertEqual(data_model, expected, 'Incorrect data model')
+
+ # Cavium
+ oui = '000FB7'
+ version = 'Some version of Cavium'
+ data_model = get_device_name(oui, version)
+ expected = EnodebDeviceName.CAVIUM
+ self.assertEqual(data_model, expected, 'Incorrect data model')
+
+ # Unsupported device OUI
+ oui = 'beepboopbeep'
+ version = 'boopboopboop'
+ with self.assertRaises(UnrecognizedEnodebError):
+ get_device_name(oui, version)
+
+ # Unsupported software version for Baicells
+ oui = '34ED0B'
+ version = 'blingblangblong'
+ with self.assertRaises(UnrecognizedEnodebError):
+ get_device_name(oui, version)
+
+ def test_parse_version(self):
+ """ Test that version string is parsed correctly """
+ self.assertEqual(
+ _parse_sw_version('BaiStation_V100R001C00B110SPC003'),
+ [100, 1, 0, 110, 3],
+ )
+ self.assertEqual(
+ _parse_sw_version('BaiStation_V100R001C00B060SPC012'),
+ [100, 1, 0, 60, 12],
+ )
+ self.assertEqual(
+ _parse_sw_version('BaiStation_V100R001C00B060SPC012_FB_3'),
+ [100, 1, 0, 60, 12],
+ )
+ # Incorrect number of digits
+ self.assertEqual(
+ _parse_sw_version('BaiStation_V10R001C00B060SPC012'),
+ None,
+ )
+ self.assertEqual(
+ _parse_sw_version('XYZ123'),
+ None,
+ )
+ self.assertEqual(
+ _parse_sw_version(''),
+ None,
+ )