Skip to content

Commit 8c89f6b

Browse files
authored
[ycabled][active-active] Fix in gRPC channel callback logic by creating swsscommon table within the context (#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 bc936a4 commit 8c89f6b

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

17561756
rc = change_ports_status_for_y_cable_change_event(
1757-
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())
1757+
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())
17581758

17591759
assert(rc == None)
17601760

@@ -1787,7 +1787,7 @@ def mock_get_asic_id(mock_logical_port_name):
17871787

17881788
patched_util.get_asic_id_for_logical_port.return_value = 0
17891789
rc = change_ports_status_for_y_cable_change_event(
1790-
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())
1790+
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())
17911791

17921792
assert(rc == None)
17931793

@@ -1831,7 +1831,7 @@ def mock_get_asic_id(mock_logical_port_name):
18311831

18321832
patched_util.get_asic_id_for_logical_port.return_value = 0
18331833
rc = change_ports_status_for_y_cable_change_event(
1834-
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())
1834+
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())
18351835

18361836
assert(rc == None)
18371837

@@ -1878,7 +1878,7 @@ def mock_get_asic_id(mock_logical_port_name):
18781878

18791879
patched_util.get_asic_id_for_logical_port.return_value = 0
18801880
rc = change_ports_status_for_y_cable_change_event(
1881-
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())
1881+
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())
18821882

18831883
assert(rc == None)
18841884

@@ -1918,7 +1918,7 @@ def mock_get_asic_id(mock_logical_port_name):
19181918

19191919
patched_util.get_asic_id_for_logical_port.return_value = 0
19201920
rc = change_ports_status_for_y_cable_change_event(
1921-
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())
1921+
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())
19221922

19231923
assert(rc == None)
19241924

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

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

65206520
def test_process_loopback_interface_and_get_read_side_rc(self):
@@ -6532,7 +6532,7 @@ def test_process_loopback_interface_and_get_read_side_rc(self):
65326532
port_tbl[asic_index] = swsscommon.Table(
65336533
test_db[asic_index], "PORT_INFO_TABLE")
65346534
grpc_client , fwd_state_response_tbl = {}, {}
6535-
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0 , port_tbl, grpc_client, fwd_state_response_tbl )
6535+
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0 , port_tbl, grpc_client)
65366536
assert(rc == False)
65376537

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

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

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

6622-
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)
6622+
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)
66236623

66246624
assert(rc == None)
66256625

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

6658-
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)
6658+
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)
66596659

66606660
assert(rc == None)
66616661

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

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

66986698

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

6733-
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)
6733+
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)
67346734

67356735
assert(rc == None)
67366736

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

67566756
patched_util.get_asic_id_for_logical_port.return_value = 0
6757-
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, fwd_state_response_tbl, False)
6757+
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, False)
67586758

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

67816781
patched_util.get_asic_id_for_logical_port.return_value = 0
6782-
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, fwd_state_response_tbl, False)
6782+
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, False)
67836783

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

68086808
assert(rc == None)
68096809

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

77667766

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