-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sysName]: Implement sysName OID #185
Changes from 1 commit
4d5d900
6762a72
5ef3567
1258c9b
28a644d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -667,3 +667,33 @@ class InterfacesMIB(metaclass=MIBMeta, prefix='.1.3.6.1.2.1.2'): | |
# FIXME Placeholder | ||
ifSpecific = \ | ||
SubtreeMIBEntry('2.1.22', if_updater, ValueType.OBJECT_IDENTIFIER, lambda sub_id: ObjectIdentifier.null_oid()) | ||
|
||
class sysNameUpdater(MIBUpdater): | ||
def __init__(self): | ||
super().__init__() | ||
self.db_conn = mibs.init_db() | ||
|
||
def update_data(self): | ||
return | ||
|
||
def get_sys_name(self): | ||
""" | ||
Subclass update interface information | ||
""" | ||
self.db_conn.connect(mibs.CONFIG_DB) | ||
|
||
device_metadata = self.db_conn.get_all(self.db_conn.CONFIG_DB, "DEVICE_METADATA|localhost") | ||
|
||
if device_metadata is not None and 'hostname' in device_metadata: | ||
return str(device_metadata['hostname']) | ||
else: | ||
return None | ||
|
||
|
||
class SysNameMIB(metaclass=MIBMeta, prefix='.1.3.6.1.2.1.1.5'): | ||
""" | ||
|
||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the unused lines? or add some useful comment? #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed lines. |
||
updater = sysNameUpdater() | ||
|
||
sysName = MIBEntry('0', ValueType.OCTET_STRING, updater.get_sys_name) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,5 +14,9 @@ | |
"admin_status": "up", | ||
"alias": "mgmt2", | ||
"speed": 1000 | ||
}, | ||
"DEVICE_METADATA|localhost": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
wrong indentation. #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed indendation. |
||
"chassis_serial_number": "SAMPLETESTSN", | ||
"hostname" : "namespace_hostname" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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) | ||
|
||
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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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) | ||
|
||
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticePhysicalTableMIBUpdater.reinit_data()
fetchDEVICE_METADATA
periodically. Could you reuse that?For device name changing case, I think the latency is good enough. No need to query Redis on each query. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That data is coming from STATE_DB and not CONFIG_DB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified implementation to get hostname in reinit_data() function which gets invoked every minute.
Also, using hostname from system as default hostname during intialization.