[Mellanox] [platform API] Fix “local variable 'label_port' referenced before assignment” error (#6419)

In rare case can see that xcvrd failed due to "UnboundLocalError: local variable 'label_port' referenced before assignment"

Init "label_port" as None at the beginning of the function, to avoid the case that "label_port" not assigned.
This commit is contained in:
Kebo Liu 2021-01-13 02:43:57 +08:00 committed by Abhishek Dosi
parent ce6cc3821f
commit 5ec164b694

View File

@ -278,6 +278,7 @@ class sfp_event:
port_cnt_p = new_uint32_t_p()
uint32_t_p_assign(port_cnt_p,64)
label_port_list = []
label_port = None
module_state = 0
rc = sx_lib_host_ifc_recv(fd_p, pkt, pkt_size_p, recv_info_p)
@ -309,9 +310,11 @@ class sfp_event:
for i in xrange(port_cnt):
port_attributes = sx_port_attributes_t_arr_getitem(port_attributes_list,i)
if port_attributes.log_port == logical_port:
lable_port = port_attributes.port_mapping.module_port
label_port = port_attributes.port_mapping.module_port
break
label_port_list.append(lable_port)
if label_port is not None:
label_port_list.append(label_port)
delete_uint32_t_p(pkt_size_p)
delete_uint8_t_arr(pkt)