Skip to content
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
merged 5 commits into from
Dec 30, 2020

Conversation

SuvarnaMeenakshi
Copy link
Contributor

@SuvarnaMeenakshi SuvarnaMeenakshi commented Dec 17, 2020

[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

  • Add a new MIB class to support retrieving sysName from config_db
  • Add unit-test to test sysName OID.

- 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.

Testing result on sonic-vs platform:

admin@vlab-01:~$ sudo config hostname test
Running command: service hostname-config restart
Reloading Monit configuration ...
Reinitializing monit daemon
Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.
admin@vlab-01:~$ date
Thu 24 Dec 2020 02:30:04 AM UTC

admin@vlab-01:~$ docker exec -it snmp snmpwalk -v2c -c public 127.0.0.1 1.3.6.1.2.1.1.5.0
iso.3.6.1.2.1.1.5.0 = STRING: "vlab-01"
admin@vlab-01:~$ docker exec -it snmp snmpwalk -v2c -c public 127.0.0.1 1.3.6.1.2.1.1.5.0
iso.3.6.1.2.1.1.5.0 = STRING: "test"
admin@vlab-01:~$ date
Thu 24 Dec 2020 02:30:48 AM UTC

- Description for the changelog

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")
Copy link
Contributor

@qiluo-msft qiluo-msft Dec 18, 2020

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@qiluo-msft qiluo-msft left a 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")
Copy link
Contributor

@qiluo-msft qiluo-msft Dec 23, 2020

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

Copy link
Contributor

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)

Copy link
Contributor Author

@SuvarnaMeenakshi SuvarnaMeenakshi Dec 24, 2020

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

Copy link
Contributor

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)

Copy link
Contributor Author

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

Copy link
Contributor Author

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

qiluo-msft
qiluo-msft previously approved these changes Dec 24, 2020
@sonic-net sonic-net deleted a comment from svc-acs Dec 26, 2020
class SysNameMIB(metaclass=MIBMeta, prefix='.1.3.6.1.2.1.1.5'):
"""

"""
Copy link
Contributor

@qiluo-msft qiluo-msft Dec 30, 2020

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

Copy link
Contributor Author

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": {
Copy link
Contributor

@qiluo-msft qiluo-msft Dec 30, 2020

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed indendation.

Copy link
Contributor

@qiluo-msft qiluo-msft left a 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]>
@SuvarnaMeenakshi SuvarnaMeenakshi merged commit 4aad821 into sonic-net:master Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants