Skip to content

Commit ce57caa

Browse files
vdahiya12mssonicbld
authored andcommitted
[ycabled][active-active] Fix in gRPC channel callback logic by creating swsscommon table within the context (sonic-net#509)
* [ycabled][active-active] Fix in gRPC channel callback logic by creating swsscommon table within the context Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com> * fix UT Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com> * add more tests Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com> * typo Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com> * add port Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com> * add logging Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com> * add tests Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com> --------- Signed-off-by: Vaibhav Dahiya <vdahiya@microsoft.com>
1 parent 52bcf14 commit ce57caa

File tree

4 files changed

+143
-83
lines changed

4 files changed

+143
-83
lines changed

sonic-ycabled/tests/test_y_cable_helper.py

+39-17
Original file line numberDiff line numberDiff line change
@@ -1749,7 +1749,7 @@ def mock_get_asic_id(mock_logical_port_name):
17491749
patched_util.get_asic_id_for_logical_port.return_value = 0
17501750

17511751
rc = change_ports_status_for_y_cable_change_event(
1752-
logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event())
1752+
logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, state_db, stop_event=threading.Event())
17531753

17541754
assert(rc == None)
17551755

@@ -1782,7 +1782,7 @@ def mock_get_asic_id(mock_logical_port_name):
17821782

17831783
patched_util.get_asic_id_for_logical_port.return_value = 0
17841784
rc = change_ports_status_for_y_cable_change_event(
1785-
logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event())
1785+
logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, state_db, stop_event=threading.Event())
17861786

17871787
assert(rc == None)
17881788

@@ -1826,7 +1826,7 @@ def mock_get_asic_id(mock_logical_port_name):
18261826

18271827
patched_util.get_asic_id_for_logical_port.return_value = 0
18281828
rc = change_ports_status_for_y_cable_change_event(
1829-
logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event())
1829+
logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, state_db, stop_event=threading.Event())
18301830

18311831
assert(rc == None)
18321832

@@ -1873,7 +1873,7 @@ def mock_get_asic_id(mock_logical_port_name):
18731873

18741874
patched_util.get_asic_id_for_logical_port.return_value = 0
18751875
rc = change_ports_status_for_y_cable_change_event(
1876-
logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event())
1876+
logical_port_dict, y_cable_presence, port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, state_db, stop_event=threading.Event())
18771877

18781878
assert(rc == None)
18791879

@@ -1913,7 +1913,7 @@ def mock_get_asic_id(mock_logical_port_name):
19131913

19141914
patched_util.get_asic_id_for_logical_port.return_value = 0
19151915
rc = change_ports_status_for_y_cable_change_event(
1916-
logical_port_dict, y_cable_presence,port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stop_event=threading.Event())
1916+
logical_port_dict, y_cable_presence,port_tbl, port_table_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, state_db, stop_event=threading.Event())
19171917

19181918
assert(rc == None)
19191919

@@ -6491,7 +6491,7 @@ def test_retry_setup_grpc_channel_for_port_incorrect(self):
64916491
port_tbl[asic_index] = swsscommon.Table(
64926492
test_db[asic_index], "PORT_INFO_TABLE")
64936493
grpc_client , fwd_state_response_tbl = {}, {}
6494-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client, fwd_state_response_tbl)
6494+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client)
64956495
assert(rc == False)
64966496

64976497
@patch('ycable.ycable_utilities.y_cable_helper.setup_grpc_channel_for_port', MagicMock(return_value=(None,None)))
@@ -6509,7 +6509,7 @@ def test_retry_setup_grpc_channel_for_port_correct_none_val(self):
65096509
port_tbl[asic_index] = swsscommon.Table(
65106510
test_db[asic_index], "PORT_INFO_TABLE")
65116511
grpc_client , fwd_state_response_tbl = {}, {}
6512-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client, fwd_state_response_tbl)
6512+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client)
65136513
assert(rc == False)
65146514

65156515
def test_process_loopback_interface_and_get_read_side_rc(self):
@@ -6527,7 +6527,7 @@ def test_process_loopback_interface_and_get_read_side_rc(self):
65276527
port_tbl[asic_index] = swsscommon.Table(
65286528
test_db[asic_index], "PORT_INFO_TABLE")
65296529
grpc_client , fwd_state_response_tbl = {}, {}
6530-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0 , port_tbl, grpc_client, fwd_state_response_tbl )
6530+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0 , port_tbl, grpc_client)
65316531
assert(rc == False)
65326532

65336533
@patch('ycable.ycable_utilities.y_cable_helper.setup_grpc_channel_for_port', MagicMock(return_value=(True,True)))
@@ -6545,7 +6545,7 @@ def test_retry_setup_grpc_channel_for_port_correct(self):
65456545
port_tbl[asic_index] = swsscommon.Table(
65466546
test_db[asic_index], "PORT_INFO_TABLE")
65476547
grpc_client , fwd_state_response_tbl = {}, {}
6548-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client, fwd_state_response_tbl)
6548+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client)
65496549
assert(rc == True)
65506550

65516551
@patch('ycable.ycable_utilities.y_cable_helper.setup_grpc_channel_for_port', MagicMock(return_value=(None,None)))
@@ -6563,7 +6563,7 @@ def test_retry_setup_grpc_channel_for_port_correct_none_val(self):
65636563
port_tbl[asic_index] = swsscommon.Table(
65646564
test_db[asic_index], "PORT_INFO_TABLE")
65656565
grpc_client , fwd_state_response_tbl = {}, {}
6566-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client, fwd_state_response_tbl)
6566+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client)
65676567
assert(rc == False)
65686568

65696569
def test_process_loopback_interface_and_get_read_side_rc(self):
@@ -6614,7 +6614,7 @@ def test_check_identifier_presence_and_setup_channel(self):
66146614
mux_tbl[asic_index] = swsscommon.Table(
66156615
test_db[asic_index], "MUX_INFO_TABLE")
66166616

6617-
rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl)
6617+
rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client)
66186618

66196619
assert(rc == None)
66206620

@@ -6650,7 +6650,7 @@ def test_check_identifier_presence_and_setup_channel_with_false_status(self):
66506650
mux_tbl[asic_index] = swsscommon.Table(
66516651
test_db[asic_index], "MUX_INFO_TABLE")
66526652

6653-
rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl)
6653+
rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client)
66546654

66556655
assert(rc == None)
66566656

@@ -6687,7 +6687,7 @@ def test_check_identifier_presence_and_setup_channel_with_mock(self):
66876687
mux_tbl[asic_index] = swsscommon.Table(
66886688
test_db[asic_index], "MUX_INFO_TABLE")
66896689

6690-
rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl)
6690+
rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client)
66916691
assert(rc == None)
66926692

66936693

@@ -6725,7 +6725,7 @@ def test_check_identifier_presence_and_setup_channel_with_mock_not_none(self):
67256725
mux_tbl[asic_index] = swsscommon.Table(
67266726
test_db[asic_index], "MUX_INFO_TABLE")
67276727

6728-
rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client, fwd_state_response_tbl)
6728+
rc = check_identifier_presence_and_setup_channel("Ethernet0", port_tbl, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, asic_index, read_side, mux_tbl, y_cable_presence, grpc_client)
67296729

67306730
assert(rc == None)
67316731

@@ -6749,7 +6749,7 @@ def test_setup_grpc_channel_for_port(self):
67496749
with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util:
67506750

67516751
patched_util.get_asic_id_for_logical_port.return_value = 0
6752-
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, fwd_state_response_tbl, False)
6752+
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, False)
67536753

67546754
assert(stub == True)
67556755
assert(channel != None)
@@ -6774,7 +6774,7 @@ def test_setup_grpc_channel_for_port_get_false(self):
67746774
with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util:
67756775

67766776
patched_util.get_asic_id_for_logical_port.return_value = 0
6777-
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, fwd_state_response_tbl, False)
6777+
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, False)
67786778

67796779
assert(stub == True)
67806780
assert(channel != None)
@@ -6798,7 +6798,7 @@ def test_setup_grpc_channels(self):
67986798
patched_util.logical.return_value = ['Ethernet0', 'Ethernet4']
67996799
patched_util.get_asic_id_for_logical_port.return_value = 0
68006800
loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, port_tbl, loopback_tbl, port_table_keys, grpc_client, fwd_state_response_tbl = {}, {}, {}, {}, {}, {}, {}, {}
6801-
rc = setup_grpc_channels(stop_event, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, port_tbl, loopback_tbl, port_table_keys, grpc_client, fwd_state_response_tbl)
6801+
rc = setup_grpc_channels(stop_event, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, port_tbl, loopback_tbl, port_table_keys, grpc_client)
68026802

68036803
assert(rc == None)
68046804

@@ -7759,3 +7759,25 @@ def test_ycable_helper_table_worker_toggle_active_active(self, mock_select, mock
77597759
assert swsscommon.Select.select.call_count == 1
77607760

77617761

7762+
def test_ycable_wait_for_state_change(self):
7763+
7764+
channel_conn = grpc.ChannelConnectivity.TRANSIENT_FAILURE
7765+
port = 'Ethernet0'
7766+
rc = wait_for_state_change(channel_conn, port)
7767+
7768+
assert (rc == None)
7769+
7770+
channel_conn = grpc.ChannelConnectivity.CONNECTING
7771+
rc = wait_for_state_change(channel_conn, port)
7772+
7773+
assert (rc == None)
7774+
7775+
channel_conn = grpc.ChannelConnectivity.READY
7776+
rc = wait_for_state_change(channel_conn, port)
7777+
7778+
assert (rc == None)
7779+
7780+
channel_conn = grpc.ChannelConnectivity.SHUTDOWN
7781+
rc = wait_for_state_change(channel_conn, port)
7782+
7783+
assert (rc == None)

sonic-ycabled/ycable/ycable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def handle_state_update_task(op, port, fvp_dict, y_cable_presence, port_tbl, por
113113
port_dict[port] = SFP_STATUS_REMOVED
114114

115115
y_cable_helper.change_ports_status_for_y_cable_change_event(
116-
port_dict, y_cable_presence, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, fwd_state_response_tbl, state_db, stopping_event)
116+
port_dict, y_cable_presence, port_tbl, port_tbl_keys, loopback_tbl, loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, y_cable_tbl, static_tbl, mux_tbl, grpc_client, state_db, stopping_event)
117117

118118
#
119119
# Helper classes ===============================================================

0 commit comments

Comments
 (0)