Fix code issue when SonicV2Connector.get() return None. (#13250)
Fix code issue when SonicV2Connector.get() return None. #### Why I did it When database key does not exist, SonicV2Connector.get() will return None. Code will break if not check return value. #### How I did it Check SonicV2Connector.get() return value before use it. #### How to verify it Pass all E2E test case.
This commit is contained in:
parent
a5d71576db
commit
ce88a38185
@ -187,9 +187,15 @@ class LedControl(LedControlBase):
|
|||||||
lanes = swss.get(
|
lanes = swss.get(
|
||||||
swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
|
swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
|
||||||
|
|
||||||
|
# SonicV2Connector.get() will return None when key does not exist.
|
||||||
|
if lanes:
|
||||||
|
lanes_len = len(lanes.split(','))
|
||||||
|
else:
|
||||||
|
lanes_len = 0
|
||||||
|
|
||||||
# SONiC port nums are 0-based and increment by 4
|
# SONiC port nums are 0-based and increment by 4
|
||||||
# Arista QSFP indices are 1-based and increment by 1
|
# Arista QSFP indices are 1-based and increment by 1
|
||||||
return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(',')))
|
return (((sonic_port_num/4) + 1), sonic_port_num % 4, lanes_len)
|
||||||
|
|
||||||
# Concrete implementation of port_link_state_change() method
|
# Concrete implementation of port_link_state_change() method
|
||||||
|
|
||||||
|
@ -154,9 +154,16 @@ class LedControl(LedControlBase):
|
|||||||
lanes = swss.get(
|
lanes = swss.get(
|
||||||
swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
|
swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
|
||||||
|
|
||||||
|
# SonicV2Connector.get() will return None when key does not exist.
|
||||||
|
if lanes:
|
||||||
|
lanes_len = len(lanes.split(','))
|
||||||
|
else:
|
||||||
|
lanes_len = 0
|
||||||
|
|
||||||
|
|
||||||
# SONiC port nums are 0-based and increment by 4
|
# SONiC port nums are 0-based and increment by 4
|
||||||
# Arista QSFP indices are 1-based and increment by 1
|
# Arista QSFP indices are 1-based and increment by 1
|
||||||
return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(',')))
|
return (((sonic_port_num/4) + 1), sonic_port_num % 4, lanes_len)
|
||||||
|
|
||||||
# Concrete implementation of port_link_state_change() method
|
# Concrete implementation of port_link_state_change() method
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user