|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import importlib |
| 4 | +from unittest import TestCase |
| 5 | + |
| 6 | +from ax_interface import ValueType |
| 7 | +from ax_interface.pdu_implementations import GetPDU, GetNextPDU |
| 8 | +from ax_interface.encodings import ObjectIdentifier |
| 9 | +from ax_interface.constants import PduTypes |
| 10 | +from ax_interface.pdu import PDU, PDUHeader |
| 11 | +from ax_interface.mib import MIBTable |
| 12 | +from sonic_ax_impl.mibs.ietf import rfc1213 |
| 13 | +import tests.mock_tables.dbconnector |
| 14 | + |
| 15 | +class TestGetNextPDU(TestCase): |
| 16 | + @classmethod |
| 17 | + def setUpClass(cls): |
| 18 | + tests.mock_tables.dbconnector.load_namespace_config() |
| 19 | + importlib.reload(rfc1213) |
| 20 | + cls.lut = MIBTable(rfc1213.SysNameMIB) |
| 21 | + for updater in cls.lut.updater_instances: |
| 22 | + updater.reinit_data() |
| 23 | + updater.update_data() |
| 24 | + |
| 25 | + def test_getpdu_sysname(self): |
| 26 | + oid = ObjectIdentifier(9, 0, 0, 0, (1, 3, 6, 1, 2, 1, 1, 5, 0)) |
| 27 | + get_pdu = GetPDU( |
| 28 | + header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), |
| 29 | + oids=[oid] |
| 30 | + ) |
| 31 | + |
| 32 | + encoded = get_pdu.encode() |
| 33 | + response = get_pdu.make_response(self.lut) |
| 34 | + print(response) |
| 35 | + |
| 36 | + n = len(response.values) |
| 37 | + value0 = response.values[0] |
| 38 | + self.assertEqual(value0.type_, ValueType.OCTET_STRING) |
| 39 | + self.assertEqual(str(value0.name), str(ObjectIdentifier(9, 0, 0, 0, (1, 3, 6, 1, 2, 1, 1, 5, 0)))) |
| 40 | + self.assertEqual(str(value0.data), 'namespace_hostname') |
| 41 | + |
| 42 | + @classmethod |
| 43 | + def tearDownClass(cls): |
| 44 | + tests.mock_tables.dbconnector.clean_up_config() |
0 commit comments