-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sysName]: Implement sysName OID (#185)
[sysName]: Add sysName OID implementation in snmpagent. sysName OID is currently supported by snmpd. Override this implementation to make sure the latest hostname is taken from config db. Add a new MIB class to support retrieving sysName from config_db Add unit-test to test sysName OID.
- Loading branch information
1 parent
8efb4bb
commit 4aad821
Showing
6 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import sys | ||
import importlib | ||
from unittest import TestCase | ||
|
||
from ax_interface import ValueType | ||
from ax_interface.pdu_implementations import GetPDU, GetNextPDU | ||
from ax_interface.encodings import ObjectIdentifier | ||
from ax_interface.constants import PduTypes | ||
from ax_interface.pdu import PDU, PDUHeader | ||
from ax_interface.mib import MIBTable | ||
from sonic_ax_impl.mibs.ietf import rfc1213 | ||
import tests.mock_tables.dbconnector | ||
|
||
class TestGetNextPDU(TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
tests.mock_tables.dbconnector.load_namespace_config() | ||
importlib.reload(rfc1213) | ||
cls.lut = MIBTable(rfc1213.SysNameMIB) | ||
for updater in cls.lut.updater_instances: | ||
updater.reinit_data() | ||
updater.update_data() | ||
|
||
def test_getpdu_sysname(self): | ||
oid = ObjectIdentifier(9, 0, 0, 0, (1, 3, 6, 1, 2, 1, 1, 5, 0)) | ||
get_pdu = GetPDU( | ||
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), | ||
oids=[oid] | ||
) | ||
|
||
encoded = get_pdu.encode() | ||
response = get_pdu.make_response(self.lut) | ||
print(response) | ||
|
||
n = len(response.values) | ||
value0 = response.values[0] | ||
self.assertEqual(value0.type_, ValueType.OCTET_STRING) | ||
self.assertEqual(str(value0.name), str(ObjectIdentifier(9, 0, 0, 0, (1, 3, 6, 1, 2, 1, 1, 5, 0)))) | ||
self.assertEqual(str(value0.data), 'namespace_hostname') | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
tests.mock_tables.dbconnector.clean_up_config() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os | ||
import sys | ||
from unittest import TestCase | ||
|
||
from unittest import TestCase | ||
|
||
from ax_interface import ValueType | ||
from ax_interface.pdu_implementations import GetPDU, GetNextPDU | ||
from ax_interface.encodings import ObjectIdentifier | ||
from ax_interface.constants import PduTypes | ||
from ax_interface.pdu import PDU, PDUHeader | ||
from ax_interface.mib import MIBTable | ||
from sonic_ax_impl.mibs.ietf import rfc1213 | ||
|
||
class TestGetNextPDU(TestCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
cls.lut = MIBTable(rfc1213.SysNameMIB) | ||
for updater in cls.lut.updater_instances: | ||
updater.reinit_data() | ||
updater.update_data() | ||
|
||
def test_getpdu_sysname(self): | ||
oid = ObjectIdentifier(9, 0, 0, 0, (1, 3, 6, 1, 2, 1, 1, 5, 0)) | ||
get_pdu = GetPDU( | ||
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0), | ||
oids=[oid] | ||
) | ||
|
||
encoded = get_pdu.encode() | ||
response = get_pdu.make_response(self.lut) | ||
print(response) | ||
|
||
n = len(response.values) | ||
value0 = response.values[0] | ||
self.assertEqual(value0.type_, ValueType.OCTET_STRING) | ||
self.assertEqual(str(value0.name), str(ObjectIdentifier(9, 0, 0, 0, (1, 3, 6, 1, 2, 1, 1, 5, 0)))) | ||
self.assertEqual(str(value0.data), 'test_hostname') |