Skip to content

Commit 6dbda9b

Browse files
vdahiya12yxieca
authored andcommitted
[ycabled] fix no port/state returned by grpc server (#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 3d1228a commit 6dbda9b

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
@@ -3269,14 +3269,17 @@ def parse_grpc_response_hw_mux_cable_change_state(ret, response, portid, port):
32693269
state = 'unknown'
32703270
"return a list of states"
32713271
if ret is True:
3272-
if response.portid[0] == portid:
3273-
if response.state[0] == True:
3274-
state = 'active'
3275-
# No other values expected
3276-
elif response.state[0] == False:
3277-
state = 'standby'
3272+
if len(response.portid) > 0 and len(response.state) > 0:
3273+
if response.portid[0] == portid:
3274+
if response.state[0] == True:
3275+
state = 'active'
3276+
# No other values expected
3277+
elif response.state[0] == False:
3278+
state = 'standby'
3279+
else:
3280+
helper_logger.log_warning("recieved an error state while parsing response hw mux no response state for port".format(port))
32783281
else:
3279-
helper_logger.log_warning("recieved an error state while parsing response hw mux no response state for port".format(port))
3282+
helper_logger.log_warning("recieved an error portid while parsing response hw mux port list size 0 for port".format(port))
32803283
else:
32813284
helper_logger.log_warning("recieved an error portid while parsing response hw mux no portid for port".format(port))
32823285

@@ -3291,27 +3294,33 @@ def parse_grpc_response_forwarding_state(ret, response, read_side):
32913294
self_state = peer_state = 'unknown'
32923295

32933296
if ret is True and response is not None:
3294-
if int(read_side) == 0:
3295-
if response.state[0] == True:
3296-
self_state = 'active'
3297-
elif response.state[0] == False:
3298-
self_state = 'standby'
3299-
# No other values expected, should we raise exception/msg
3300-
# TODO handle other responses
3301-
if response.state[1] == True:
3302-
peer_state = 'active'
3303-
elif response.state[1] == False:
3304-
peer_state = 'standby'
3305-
3306-
elif int(read_side) == 1:
3307-
if response.state[1] == True:
3308-
self_state = 'active'
3309-
elif response.state[1] == False:
3310-
self_state = 'standby'
3311-
if response.state[0] == True:
3312-
peer_state = 'active'
3313-
elif response.state[0] == False:
3314-
peer_state = 'standby'
3297+
if len(response.portid) == 2 and len(response.state) == 2:
3298+
if int(read_side) == 0:
3299+
if response.state[0] == True:
3300+
self_state = 'active'
3301+
elif response.state[0] == False:
3302+
self_state = 'standby'
3303+
# No other values expected, should we raise exception/msg
3304+
# TODO handle other responses
3305+
if response.state[1] == True:
3306+
peer_state = 'active'
3307+
elif response.state[1] == False:
3308+
peer_state = 'standby'
3309+
3310+
elif int(read_side) == 1:
3311+
if response.state[1] == True:
3312+
self_state = 'active'
3313+
elif response.state[1] == False:
3314+
self_state = 'standby'
3315+
if response.state[0] == True:
3316+
peer_state = 'active'
3317+
elif response.state[0] == False:
3318+
peer_state = 'standby'
3319+
3320+
else:
3321+
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)))
3322+
self_state = 'unknown'
3323+
peer_state = 'unknown'
33153324
else:
33163325
self_state = 'unknown'
33173326
peer_state = 'unknown'

0 commit comments

Comments
 (0)