Skip to content

Commit 044f0e4

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 1c06ca9 commit 044f0e4

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
@@ -1753,7 +1753,7 @@ def mock_get_asic_id(mock_logical_port_name):
17531753
patched_util.get_asic_id_for_logical_port.return_value = 0
17541754

17551755
rc = change_ports_status_for_y_cable_change_event(
1756-
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())
1756+
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())
17571757

17581758
assert(rc == None)
17591759

@@ -1786,7 +1786,7 @@ def mock_get_asic_id(mock_logical_port_name):
17861786

17871787
patched_util.get_asic_id_for_logical_port.return_value = 0
17881788
rc = change_ports_status_for_y_cable_change_event(
1789-
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())
1789+
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())
17901790

17911791
assert(rc == None)
17921792

@@ -1830,7 +1830,7 @@ def mock_get_asic_id(mock_logical_port_name):
18301830

18311831
patched_util.get_asic_id_for_logical_port.return_value = 0
18321832
rc = change_ports_status_for_y_cable_change_event(
1833-
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())
1833+
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())
18341834

18351835
assert(rc == None)
18361836

@@ -1877,7 +1877,7 @@ def mock_get_asic_id(mock_logical_port_name):
18771877

18781878
patched_util.get_asic_id_for_logical_port.return_value = 0
18791879
rc = change_ports_status_for_y_cable_change_event(
1880-
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())
1880+
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())
18811881

18821882
assert(rc == None)
18831883

@@ -1917,7 +1917,7 @@ def mock_get_asic_id(mock_logical_port_name):
19171917

19181918
patched_util.get_asic_id_for_logical_port.return_value = 0
19191919
rc = change_ports_status_for_y_cable_change_event(
1920-
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())
1920+
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())
19211921

19221922
assert(rc == None)
19231923

@@ -6495,7 +6495,7 @@ def test_retry_setup_grpc_channel_for_port_incorrect(self):
64956495
port_tbl[asic_index] = swsscommon.Table(
64966496
test_db[asic_index], "PORT_INFO_TABLE")
64976497
grpc_client , fwd_state_response_tbl = {}, {}
6498-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client, fwd_state_response_tbl)
6498+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client)
64996499
assert(rc == False)
65006500

65016501
@patch('ycable.ycable_utilities.y_cable_helper.setup_grpc_channel_for_port', MagicMock(return_value=(None,None)))
@@ -6513,7 +6513,7 @@ def test_retry_setup_grpc_channel_for_port_correct_none_val(self):
65136513
port_tbl[asic_index] = swsscommon.Table(
65146514
test_db[asic_index], "PORT_INFO_TABLE")
65156515
grpc_client , fwd_state_response_tbl = {}, {}
6516-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client, fwd_state_response_tbl)
6516+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client)
65176517
assert(rc == False)
65186518

65196519
def test_process_loopback_interface_and_get_read_side_rc(self):
@@ -6531,7 +6531,7 @@ def test_process_loopback_interface_and_get_read_side_rc(self):
65316531
port_tbl[asic_index] = swsscommon.Table(
65326532
test_db[asic_index], "PORT_INFO_TABLE")
65336533
grpc_client , fwd_state_response_tbl = {}, {}
6534-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0 , port_tbl, grpc_client, fwd_state_response_tbl )
6534+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0 , port_tbl, grpc_client)
65356535
assert(rc == False)
65366536

65376537
@patch('ycable.ycable_utilities.y_cable_helper.setup_grpc_channel_for_port', MagicMock(return_value=(True,True)))
@@ -6549,7 +6549,7 @@ def test_retry_setup_grpc_channel_for_port_correct(self):
65496549
port_tbl[asic_index] = swsscommon.Table(
65506550
test_db[asic_index], "PORT_INFO_TABLE")
65516551
grpc_client , fwd_state_response_tbl = {}, {}
6552-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client, fwd_state_response_tbl)
6552+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client)
65536553
assert(rc == True)
65546554

65556555
@patch('ycable.ycable_utilities.y_cable_helper.setup_grpc_channel_for_port', MagicMock(return_value=(None,None)))
@@ -6567,7 +6567,7 @@ def test_retry_setup_grpc_channel_for_port_correct_none_val(self):
65676567
port_tbl[asic_index] = swsscommon.Table(
65686568
test_db[asic_index], "PORT_INFO_TABLE")
65696569
grpc_client , fwd_state_response_tbl = {}, {}
6570-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client, fwd_state_response_tbl)
6570+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client)
65716571
assert(rc == False)
65726572

65736573
def test_process_loopback_interface_and_get_read_side_rc(self):
@@ -6618,7 +6618,7 @@ def test_check_identifier_presence_and_setup_channel(self):
66186618
mux_tbl[asic_index] = swsscommon.Table(
66196619
test_db[asic_index], "MUX_INFO_TABLE")
66206620

6621-
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)
6621+
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)
66226622

66236623
assert(rc == None)
66246624

@@ -6654,7 +6654,7 @@ def test_check_identifier_presence_and_setup_channel_with_false_status(self):
66546654
mux_tbl[asic_index] = swsscommon.Table(
66556655
test_db[asic_index], "MUX_INFO_TABLE")
66566656

6657-
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)
6657+
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)
66586658

66596659
assert(rc == None)
66606660

@@ -6691,7 +6691,7 @@ def test_check_identifier_presence_and_setup_channel_with_mock(self):
66916691
mux_tbl[asic_index] = swsscommon.Table(
66926692
test_db[asic_index], "MUX_INFO_TABLE")
66936693

6694-
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)
6694+
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)
66956695
assert(rc == None)
66966696

66976697

@@ -6729,7 +6729,7 @@ def test_check_identifier_presence_and_setup_channel_with_mock_not_none(self):
67296729
mux_tbl[asic_index] = swsscommon.Table(
67306730
test_db[asic_index], "MUX_INFO_TABLE")
67316731

6732-
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)
6732+
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)
67336733

67346734
assert(rc == None)
67356735

@@ -6753,7 +6753,7 @@ def test_setup_grpc_channel_for_port(self):
67536753
with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util:
67546754

67556755
patched_util.get_asic_id_for_logical_port.return_value = 0
6756-
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, fwd_state_response_tbl, False)
6756+
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, False)
67576757

67586758
assert(stub == True)
67596759
assert(channel != None)
@@ -6778,7 +6778,7 @@ def test_setup_grpc_channel_for_port_get_false(self):
67786778
with patch('ycable.ycable_utilities.y_cable_helper.y_cable_platform_sfputil') as patched_util:
67796779

67806780
patched_util.get_asic_id_for_logical_port.return_value = 0
6781-
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, fwd_state_response_tbl, False)
6781+
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, False)
67826782

67836783
assert(stub == True)
67846784
assert(channel != None)
@@ -6802,7 +6802,7 @@ def test_setup_grpc_channels(self):
68026802
patched_util.logical.return_value = ['Ethernet0', 'Ethernet4']
68036803
patched_util.get_asic_id_for_logical_port.return_value = 0
68046804
loopback_keys, hw_mux_cable_tbl, hw_mux_cable_tbl_peer, port_tbl, loopback_tbl, port_table_keys, grpc_client, fwd_state_response_tbl = {}, {}, {}, {}, {}, {}, {}, {}
6805-
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)
6805+
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)
68066806

68076807
assert(rc == None)
68086808

@@ -7763,3 +7763,25 @@ def test_ycable_helper_table_worker_toggle_active_active(self, mock_select, mock
77637763
assert swsscommon.Select.select.call_count == 1
77647764

77657765

7766+
def test_ycable_wait_for_state_change(self):
7767+
7768+
channel_conn = grpc.ChannelConnectivity.TRANSIENT_FAILURE
7769+
port = 'Ethernet0'
7770+
rc = wait_for_state_change(channel_conn, port)
7771+
7772+
assert (rc == None)
7773+
7774+
channel_conn = grpc.ChannelConnectivity.CONNECTING
7775+
rc = wait_for_state_change(channel_conn, port)
7776+
7777+
assert (rc == None)
7778+
7779+
channel_conn = grpc.ChannelConnectivity.READY
7780+
rc = wait_for_state_change(channel_conn, port)
7781+
7782+
assert (rc == None)
7783+
7784+
channel_conn = grpc.ChannelConnectivity.SHUTDOWN
7785+
rc = wait_for_state_change(channel_conn, port)
7786+
7787+
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)