Skip to content

Commit

Permalink
sonic-snmpagent: fixed interface descriptions (sonic-net#74)
Browse files Browse the repository at this point in the history
* sonic-snmpagent: fixed interface descriptions
* ifAlias should retrun the interface description not the SONiC name
* unit tests
  • Loading branch information
MichelMoriniaux authored and qiluo-msft committed Aug 8, 2018
1 parent 9d113dc commit 8a9fd25
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
14 changes: 6 additions & 8 deletions src/sonic_ax_impl/mibs/ietf/rfc2863.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,16 @@ def interface_name(self, sub_id):

def interface_alias(self, sub_id):
"""
ifAlias specific - this is not the "Alias map". This simply returns the SONiC name.
ifAlias specific - this is not the "Alias map".
To be homogenous with what is available in the wild this should return the interface 'description'.
:param sub_id: The 1-based sub-identifier query.
:return: The SONiC name.
:return: The SONiC interface description, empty string if not defined.
"""
oid = self.get_oid(sub_id)
if not oid:
entry = self._get_if_entry(sub_id)
if not entry:
return

if oid in self.oid_lag_name_map:
return self.oid_lag_name_map[oid]

return self.oid_name_map[oid]
return entry.get(b"description", "")

def get_counter32(self, sub_id, table_name):
oid = self.get_oid(sub_id)
Expand Down
2 changes: 0 additions & 2 deletions tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,6 @@
"speed": 100000
},
"PORT_TABLE:Ethernet116": {
"description": "snowflake",
"speed": 1000
},
"PORT_TABLE:Ethernet120": {
Expand Down Expand Up @@ -698,7 +697,6 @@
"speed": 100000
},
"PORT_TABLE:Ethernet116": {
"description": "snowflake",
"speed": 1000
},
"PORT_TABLE:Ethernet120": {
Expand Down
24 changes: 20 additions & 4 deletions tests/test_hc_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def test_update(self):
updater.update_data()

def test_getnextpdu_firstifalias(self):
# oid.include = 1
oid = ObjectIdentifier(10, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18))
get_pdu = GetNextPDU(
header=PDUHeader(1, PduTypes.GET, 16, 0, 42, 0, 0, 0),
Expand All @@ -42,12 +41,10 @@ def test_getnextpdu_firstifalias(self):
response = get_pdu.make_response(self.lut)
print(response)

n = len(response.values)
# self.assertEqual(n, 7)
value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.OCTET_STRING)
self.assertEqual(str(value0.name), str(ObjectIdentifier(11, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 1))))
self.assertEqual(str(value0.data), 'Ethernet0')
self.assertEqual(str(value0.data), 'snowflake')

def test_get_next_alias(self):
if_alias = b'\x01\x06\x10\x00\x00\x00\x00o\x00\x01\xcc4\x00\x01\xcc5\x00\x00\x000\x07\x02\x00\x00\x00\x00\x00\x01\x00\x00\x00\x1f\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x11\x00\x00\x00}\x03\x02\x00\x00\x00\x00\x00\x01\x00\x00\x00\x1f\x00\x00\x00\x02'
Expand All @@ -73,6 +70,25 @@ def test_get_next3(self):
resp = pdu.make_response(self.lut)
print(resp)

def test_no_description(self):
"""
For a port with no description in the db the result should be ian empty string
"""
oid = ObjectIdentifier(12, 0, 0, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 113))
get_pdu = GetNextPDU(
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)

value0 = response.values[0]
self.assertEqual(value0.type_, ValueType.OCTET_STRING)
self.assertEqual(str(value0.name), str(ObjectIdentifier(12, 0, 1, 0, (1, 3, 6, 1, 2, 1, 31, 1, 1, 1, 18, 117))))
self.assertEqual(str(value0.data), '')

def test_low_speed(self):
"""
For an interface with a speed inside the 32 bit counter returns the speed of the interface in Mbps
Expand Down

0 comments on commit 8a9fd25

Please sign in to comment.