-
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
Merged
SuvarnaMeenakshi
merged 5 commits into
sonic-net:master
from
SuvarnaMeenakshi:sysNameMIB
Dec 30, 2020
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4d5d900
[sysName]: Add sysName OID implementation in snmpagent.
SuvarnaMeenakshi 6762a72
Update sysNameMIB implementation to get hostname periodically
SuvarnaMeenakshi 5ef3567
Set default hostname to system hostname so that in case
SuvarnaMeenakshi 1258c9b
Minor comments as per review comments.
SuvarnaMeenakshi 28a644d
Minor fix as per review comment.
SuvarnaMeenakshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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') |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Did you test the empty table on DUT? I think device_metadata will be an empty dict instead of None.
Suggest check
device_metadata
instead ofdevice_metadata is not None
below. #ClosedThere 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.
Alternatively, you can use
get
function to gethostname
directly.In reply to: 548318135 [](ancestors = 548318135)
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.
If DEVICE_METADATA table is not present, then get_all returns None.
Updated code as per suggestion and tested on sonic-vs image.
#Resolved
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 am okay with the code. However I am confused by your comment "If DEVICE_METADATA table is not present, then get_all returns None".
Could you double check?
In reply to: 548356652 [](ancestors = 548356652)
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.
On a device, to check this behavior, I tried the below commands; here "DEVICE_METADATA" exists, without DEVICE_METADATA in config_db, hwsku will not be known so dockers will not come up. So instead of checking directly for "DEVICE_METADATA", I checked for some modified fields that will not exist.
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.
The above comment does not hold good for SNMP docker with master branch with latest changes.
If a specific key does not exist in the table, A SWIG object is returned and None is not returned.
If key does not exist:
If DEVICE_METADATA exists, but key within DEVICE_METADATA table does not exist: