Skip to content

Commit 875831e

Browse files
mykolafqiluo-msft
authored andcommitted
[LLDP MIB] fix lldp loc mgmt ip logic (sonic-net#113)
* [LLDP MIB] fix lldp loc mgmt ip logic * make sure updater.man_addr does not throw * drop the mgmt_ip_str on reinit_data
1 parent 7b8b377 commit 875831e

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/sonic_ax_impl/mibs/ieee802_1ab.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,18 @@ def reinit_data(self):
296296
Subclass update data routine.
297297
"""
298298
self.man_addr_list = []
299+
self.mgmt_ip_str = None
299300

300301
# establish connection to application database.
301302
self.db_conn.connect(mibs.APPL_DB)
302303
mgmt_ip_bytes = self.db_conn.get(mibs.APPL_DB, mibs.LOC_CHASSIS_TABLE, b'lldp_loc_man_addr')
303304

304305
if not mgmt_ip_bytes:
305-
self.mgmt_ip_str = ''
306-
else:
307-
self.mgmt_ip_str = mgmt_ip_bytes.decode()
308-
logger.debug("Got mgmt ip from db : {}".format(self.mgmt_ip_str))
306+
logger.warning("Missing lldp_loc_man_addr from APPL DB")
307+
return
308+
309+
self.mgmt_ip_str = mgmt_ip_bytes.decode()
310+
logger.debug("Got mgmt ip from db : {}".format(self.mgmt_ip_str))
309311
try:
310312
addr_subtype_sub_oid = 4
311313
mgmt_ip_sub_oid = None
@@ -316,8 +318,7 @@ def reinit_data(self):
316318
except ValueError:
317319
logger.error("Invalid local mgmt IP {}".format(self.mgmt_ip_str))
318320
return
319-
if mgmt_ip_sub_oid == None:
320-
return
321+
321322
sub_oid = (ManAddrConst.man_addr_subtype_ipv4,
322323
*mgmt_ip_sub_oid)
323324
self.man_addr_list.append(sub_oid)
@@ -348,12 +349,13 @@ def man_addr(self, sub_id):
348349
:param sub_id:
349350
:return: MGMT IP in HEX
350351
"""
351-
hex_ip = ''
352-
for mgmt_ip in self.mgmt_ip_str.split(','):
353-
if '.' in mgmt_ip:
354-
hex_ip = " ".join([format(int(i), '02X') for i in mgmt_ip.split('.')])
355-
break
356-
return hex_ip
352+
if self.mgmt_ip_str:
353+
hex_ip = ''
354+
for mgmt_ip in self.mgmt_ip_str.split(','):
355+
if '.' in mgmt_ip:
356+
hex_ip = " ".join([format(int(i), '02X') for i in mgmt_ip.split('.')])
357+
break
358+
return hex_ip
357359

358360
@staticmethod
359361
def man_addr_len(sub_id): return ManAddrConst.man_addr_len

0 commit comments

Comments
 (0)