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:
Hua Liu 2023-01-10 03:37:43 +08:00 committed by GitHub
parent a5d71576db
commit ce88a38185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -187,9 +187,15 @@ class LedControl(LedControlBase):
lanes = swss.get(
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
# 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

View File

@ -154,9 +154,16 @@ class LedControl(LedControlBase):
lanes = swss.get(
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
# 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