Skip to content

Commit 8a2dad9

Browse files
authored
[ycabled] fix no port/state returned by grpc server (sonic-net#308)
signed-off-by: vaibhav-dahiya [email protected] This PR fixes and issue when gRPC listener acknowledges the request from ycabled but sends no ports/states in the response Example for such responses : Oct 19 21:38:32.643397 DEV NOTICE pmon#ycable[128076]: Set admin state RPC received response port Ethernet44 port ids = [] curr_read_side 0 read_side 1 Oct 19 21:38:32.643515 DEV NOTICE pmon#ycable[128076]: Set admin state RPC received response port Ethernet44 state values = [] curr_read_side 0 read_side 1 ycabled will write appropriate unknown/failure in such a case
1 parent 4ea12cf commit 8a2dad9

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py

+37-28
Original file line numberDiff line numberDiff line change
@@ -3279,14 +3279,17 @@ def parse_grpc_response_hw_mux_cable_change_state(ret, response, portid, port):
32793279
state = 'unknown'
32803280
"return a list of states"
32813281
if ret is True:
3282-
if response.portid[0] == portid:
3283-
if response.state[0] == True:
3284-
state = 'active'
3285-
# No other values expected
3286-
elif response.state[0] == False:
3287-
state = 'standby'
3282+
if len(response.portid) > 0 and len(response.state) > 0:
3283+
if response.portid[0] == portid:
3284+
if response.state[0] == True:
3285+
state = 'active'
3286+
# No other values expected
3287+
elif response.state[0] == False:
3288+
state = 'standby'
3289+
else:
3290+
helper_logger.log_warning("recieved an error state while parsing response hw mux no response state for port".format(port))
32883291
else:
3289-
helper_logger.log_warning("recieved an error state while parsing response hw mux no response state for port".format(port))
3292+
helper_logger.log_warning("recieved an error portid while parsing response hw mux port list size 0 for port".format(port))
32903293
else:
32913294
helper_logger.log_warning("recieved an error portid while parsing response hw mux no portid for port".format(port))
32923295

@@ -3301,27 +3304,33 @@ def parse_grpc_response_forwarding_state(ret, response, read_side):
33013304
self_state = peer_state = 'unknown'
33023305

33033306
if ret is True and response is not None:
3304-
if int(read_side) == 0:
3305-
if response.state[0] == True:
3306-
self_state = 'active'
3307-
elif response.state[0] == False:
3308-
self_state = 'standby'
3309-
# No other values expected, should we raise exception/msg
3310-
# TODO handle other responses
3311-
if response.state[1] == True:
3312-
peer_state = 'active'
3313-
elif response.state[1] == False:
3314-
peer_state = 'standby'
3315-
3316-
elif int(read_side) == 1:
3317-
if response.state[1] == True:
3318-
self_state = 'active'
3319-
elif response.state[1] == False:
3320-
self_state = 'standby'
3321-
if response.state[0] == True:
3322-
peer_state = 'active'
3323-
elif response.state[0] == False:
3324-
peer_state = 'standby'
3307+
if len(response.portid) == 2 and len(response.state) == 2:
3308+
if int(read_side) == 0:
3309+
if response.state[0] == True:
3310+
self_state = 'active'
3311+
elif response.state[0] == False:
3312+
self_state = 'standby'
3313+
# No other values expected, should we raise exception/msg
3314+
# TODO handle other responses
3315+
if response.state[1] == True:
3316+
peer_state = 'active'
3317+
elif response.state[1] == False:
3318+
peer_state = 'standby'
3319+
3320+
elif int(read_side) == 1:
3321+
if response.state[1] == True:
3322+
self_state = 'active'
3323+
elif response.state[1] == False:
3324+
self_state = 'standby'
3325+
if response.state[0] == True:
3326+
peer_state = 'active'
3327+
elif response.state[0] == False:
3328+
peer_state = 'standby'
3329+
3330+
else:
3331+
helper_logger.log_warning("recieved an error port list while parsing response forwarding port state list size 0 {} {}".format(len(response.portid), len(response.state)))
3332+
self_state = 'unknown'
3333+
peer_state = 'unknown'
33253334
else:
33263335
self_state = 'unknown'
33273336
peer_state = 'unknown'

0 commit comments

Comments
 (0)