Skip to content

Commit ce88a38

Browse files
authored
Fix code issue when SonicV2Connector.get() return None. (sonic-net#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.
1 parent a5d7157 commit ce88a38

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

device/alphanetworks/x86_64-alphanetworks_snh60a0_320fv2-r0/plugins/led_control.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,15 @@ def _port_name_to_qsfp_index(self, port_name):
187187
lanes = swss.get(
188188
swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
189189

190+
# SonicV2Connector.get() will return None when key does not exist.
191+
if lanes:
192+
lanes_len = len(lanes.split(','))
193+
else:
194+
lanes_len = 0
195+
190196
# SONiC port nums are 0-based and increment by 4
191197
# Arista QSFP indices are 1-based and increment by 1
192-
return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(',')))
198+
return (((sonic_port_num/4) + 1), sonic_port_num % 4, lanes_len)
193199

194200
# Concrete implementation of port_link_state_change() method
195201

device/alphanetworks/x86_64-alphanetworks_snh60b0_640f-r0/plugins/led_control.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,16 @@ def _port_name_to_qsfp_index(self, port_name):
154154
lanes = swss.get(
155155
swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes')
156156

157+
# SonicV2Connector.get() will return None when key does not exist.
158+
if lanes:
159+
lanes_len = len(lanes.split(','))
160+
else:
161+
lanes_len = 0
162+
163+
157164
# SONiC port nums are 0-based and increment by 4
158165
# Arista QSFP indices are 1-based and increment by 1
159-
return (((sonic_port_num/4) + 1), sonic_port_num % 4, len(lanes.split(',')))
166+
return (((sonic_port_num/4) + 1), sonic_port_num % 4, lanes_len)
160167

161168
# Concrete implementation of port_link_state_change() method
162169

0 commit comments

Comments
 (0)