Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ycabled][active-active] Fix in gRPC channel callback logic by creating swsscommon table within the context #509

Merged
merged 7 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 39 additions & 17 deletions sonic-ycabled/tests/test_y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ def mock_get_asic_id(mock_logical_port_name):
patched_util.get_asic_id_for_logical_port.return_value = 0

rc = change_ports_status_for_y_cable_change_event(
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())
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())

assert(rc == None)

Expand Down Expand Up @@ -1787,7 +1787,7 @@ def mock_get_asic_id(mock_logical_port_name):

patched_util.get_asic_id_for_logical_port.return_value = 0
rc = change_ports_status_for_y_cable_change_event(
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())
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())

assert(rc == None)

Expand Down Expand Up @@ -1831,7 +1831,7 @@ def mock_get_asic_id(mock_logical_port_name):

patched_util.get_asic_id_for_logical_port.return_value = 0
rc = change_ports_status_for_y_cable_change_event(
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())
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())

assert(rc == None)

Expand Down Expand Up @@ -1878,7 +1878,7 @@ def mock_get_asic_id(mock_logical_port_name):

patched_util.get_asic_id_for_logical_port.return_value = 0
rc = change_ports_status_for_y_cable_change_event(
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())
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())

assert(rc == None)

Expand Down Expand Up @@ -1918,7 +1918,7 @@ def mock_get_asic_id(mock_logical_port_name):

patched_util.get_asic_id_for_logical_port.return_value = 0
rc = change_ports_status_for_y_cable_change_event(
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())
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())

assert(rc == None)

Expand Down Expand Up @@ -6496,7 +6496,7 @@ def test_retry_setup_grpc_channel_for_port_incorrect(self):
port_tbl[asic_index] = swsscommon.Table(
test_db[asic_index], "PORT_INFO_TABLE")
grpc_client , fwd_state_response_tbl = {}, {}
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client, fwd_state_response_tbl)
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0, port_tbl, grpc_client)
assert(rc == False)

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

def test_process_loopback_interface_and_get_read_side_rc(self):
Expand All @@ -6532,7 +6532,7 @@ def test_process_loopback_interface_and_get_read_side_rc(self):
port_tbl[asic_index] = swsscommon.Table(
test_db[asic_index], "PORT_INFO_TABLE")
grpc_client , fwd_state_response_tbl = {}, {}
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0 , port_tbl, grpc_client, fwd_state_response_tbl )
rc = retry_setup_grpc_channel_for_port("Ethernet0", 0 , port_tbl, grpc_client)
assert(rc == False)

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

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

def test_process_loopback_interface_and_get_read_side_rc(self):
Expand Down Expand Up @@ -6619,7 +6619,7 @@ def test_check_identifier_presence_and_setup_channel(self):
mux_tbl[asic_index] = swsscommon.Table(
test_db[asic_index], "MUX_INFO_TABLE")

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)
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)

assert(rc == None)

Expand Down Expand Up @@ -6655,7 +6655,7 @@ def test_check_identifier_presence_and_setup_channel_with_false_status(self):
mux_tbl[asic_index] = swsscommon.Table(
test_db[asic_index], "MUX_INFO_TABLE")

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)
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)

assert(rc == None)

Expand Down Expand Up @@ -6692,7 +6692,7 @@ def test_check_identifier_presence_and_setup_channel_with_mock(self):
mux_tbl[asic_index] = swsscommon.Table(
test_db[asic_index], "MUX_INFO_TABLE")

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)
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)
assert(rc == None)


Expand Down Expand Up @@ -6730,7 +6730,7 @@ def test_check_identifier_presence_and_setup_channel_with_mock_not_none(self):
mux_tbl[asic_index] = swsscommon.Table(
test_db[asic_index], "MUX_INFO_TABLE")

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)
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)

assert(rc == None)

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

patched_util.get_asic_id_for_logical_port.return_value = 0
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, fwd_state_response_tbl, False)
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, False)

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

patched_util.get_asic_id_for_logical_port.return_value = 0
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, fwd_state_response_tbl, False)
(channel, stub) = setup_grpc_channel_for_port("Ethernet0", "192.168.0.1", asic_index, grpc_client, False)

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

assert(rc == None)

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


def test_ycable_wait_for_state_change(self):

channel_conn = grpc.ChannelConnectivity.TRANSIENT_FAILURE
port = 'Ethernet0'
rc = wait_for_state_change(channel_conn, port)

assert (rc == None)

channel_conn = grpc.ChannelConnectivity.CONNECTING
rc = wait_for_state_change(channel_conn, port)

assert (rc == None)

channel_conn = grpc.ChannelConnectivity.READY
rc = wait_for_state_change(channel_conn, port)

assert (rc == None)

channel_conn = grpc.ChannelConnectivity.SHUTDOWN
rc = wait_for_state_change(channel_conn, port)

assert (rc == None)
2 changes: 1 addition & 1 deletion sonic-ycabled/ycable/ycable.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def handle_state_update_task(op, port, fvp_dict, y_cable_presence, port_tbl, por
port_dict[port] = SFP_STATUS_REMOVED

y_cable_helper.change_ports_status_for_y_cable_change_event(
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)
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)

#
# Helper classes ===============================================================
Expand Down
Loading
Loading