-
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
[sysName]: Implement sysName OID #185
Conversation
sysName OID is currently supported by snmpd. Override this implementation to make sure the latest hostname is taken from config db. Signed-off-by: Suvarna Meenakshi <[email protected]>
""" | ||
self.db_conn.connect(mibs.CONFIG_DB) | ||
|
||
device_metadata = self.db_conn.get_all(self.db_conn.CONFIG_DB, "DEVICE_METADATA|localhost") |
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.
device_metadata [](start = 8, length = 15)
I notice PhysicalTableMIBUpdater.reinit_data()
fetch DEVICE_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.
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.
As comments
in reinit_data. Update unit-test cases accordingly. Signed-off-by: Suvarna Meenakshi <[email protected]>
there is an error when reading from config_db the system hostname is used. Signed-off-by: Suvarna Meenakshi <[email protected]>
|
||
def reinit_data(self): | ||
self.db_conn.connect(self.db_conn.CONFIG_DB) | ||
device_metadata = self.db_conn.get_all(self.db_conn.CONFIG_DB, "DEVICE_METADATA|localhost") |
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.
get_all [](start = 39, length = 7)
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 of device_metadata is not None
below. #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.
Alternatively, you can use get
function to get hostname
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.
device_metadata = db_conn.get_all(db_conn.CONFIG_DB, "DEVICE_METADATA|loca")
print(device_metadata)
None
device_metadata = db_conn.get_all(db_conn.CONFIG_DB, "DEVICE_METADAT")
print(device_metadata)
None
...
hostname=device_metadata.get(b'hos')
print(hostname)
None
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:
>>> from sonic_ax_impl import mibs
db_conn.connect(db_conn.CONFIG_DB)
>>> device_metadata = db_conn.get_all(db_conn.CONFIG_DB, "DEVICE_METADATA|loca")
>>> print(device_metadata)
<swsscommon.swsscommon.FieldValueMap; proxy of <Swig Object of type 'swss::TableMap *' at 0x7f291e85a450> >
If DEVICE_METADATA exists, but key within DEVICE_METADATA table does not exist:
>>> device_metadata = db_conn.get_all(db_conn.CONFIG_DB, "DEVICE_METADATA|localhost")
>>> print(device_metadata)
<swsscommon.swsscommon.FieldValueMap; proxy of <Swig Object of type 'swss::TableMap *' at 0x7f291e85ab70> >
>>> print(device_metadata.get('foo'))
None
Signed-off-by: Suvarna Meenakshi <[email protected]>
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Removed lines.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
[](start = 0, length = 1)
wrong indentation. #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.
Fixed indendation.
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.
Notice minor issues.
Signed-off-by: Suvarna Meenakshi <[email protected]>
[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.
Signed-off-by: Suvarna Meenakshi [email protected]
- What I did
Add sysName OID implementation in snmpagent as mentioned in #170
- How I did it
- How to verify it
Bring up snmp docker with the changes.
Configure a new hostname using "config hostname <>" command.
Execute SNMP query to get 1.3.6.1.2.1.1.5.0, ensure new configured hostname is retrieved.
- Description for the changelog