Skip to content

Commit

Permalink
[ycabled] Fix insert delete events for ycabled OIR by subscribing to …
Browse files Browse the repository at this point in the history
…TRANSCEIVER_INFO instead of TRANSCEIVER_STATUS table (sonic-net#442)

* [ycabled] Fix insert delete events for ycabled OIR by subscribing to
TRANSCEIVER_INFO


Signed-off-by: Vaibhav Dahiya <[email protected]>
  • Loading branch information
vdahiya12 authored Mar 13, 2024
1 parent 8a5ca2b commit 04b0f88
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 12 deletions.
43 changes: 42 additions & 1 deletion sonic-ycabled/tests/test_ycable.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,52 @@ def test_handle_state_update_task(self):
state_db = {}
y_cable_presence = False
stopping_event = None
op = swsscommon.SET_COMMAND
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 = {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}
rc = handle_state_update_task(port, fvp_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)
rc = handle_state_update_task(op, port, fvp_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)
assert(rc == None)


@patch('ycable.ycable_utilities.y_cable_helper.change_ports_status_for_y_cable_change_event', MagicMock(return_value=0))
def test_handle_state_update_task_with_delete(self):

port = "Ethernet0"
fvp_dict = {}
state_db = {}
y_cable_presence = False
stopping_event = None
op = swsscommon.DEL_COMMAND
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 = {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}
rc = handle_state_update_task(op, port, fvp_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)
assert(rc == None)

@patch('swsscommon.swsscommon.Select.addSelectable', MagicMock())
@patch('swsscommon.swsscommon.Select.TIMEOUT', MagicMock(return_value=None))
@patch('swsscommon.swsscommon.CastSelectableToRedisSelectObj', MagicMock())
@patch('swsscommon.swsscommon.SubscriberStateTable')
@patch('swsscommon.swsscommon.Select.select')
def test_ycable_helper_state_update_task(self, mock_select, mock_sub_table):

mock_selectable = MagicMock()
mock_selectable.pop = MagicMock(
side_effect=[('Ethernet0', swsscommon.SET_COMMAND, (('state', 'active'), )), (False, False, False), (False, False, False), (False, False, False), (False, False, False), (False, False, False), (False, False, False), (False, False, False), (False, False, False), (False, False, False), (False, False, False), (False, False, False), (False, False, False), (False, False, False)])
mock_select.return_value = (swsscommon.Select.OBJECT, mock_selectable)
mock_sub_table.return_value = mock_selectable

y_cable_presence = [True]
stopping_event = MagicMock()
sfp_error_event = MagicMock()
Y_cable_task = YcableStateUpdateTask(sfp_error_event, y_cable_presence)
Y_cable_task.task_stopping_event.is_set = MagicMock(side_effect=[False, True])
mock_table = MagicMock()
"""mock_table.getKeys = MagicMock(return_value=['Ethernet0', 'Ethernet4'])
mock_table.get = MagicMock(
side_effect=[(True, (('index', 1), )), (True, (('index', 2), ))])
mock_swsscommon_table.return_value = mock_table
"""
Y_cable_task.task_worker(stopping_event, sfp_error_event, y_cable_presence)
assert swsscommon.Select.select.call_count == 1


def wait_until(total_wait_time, interval, call_back, *args, **kwargs):
wait_time = 0
Expand Down
19 changes: 12 additions & 7 deletions sonic-ycabled/ycable/ycable.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
NOT_IMPLEMENTED_ERROR = 3
SFP_SYSTEM_ERROR = 4

SFP_STATUS_REMOVED = "0"
SFP_STATUS_INSERTED = "1"

# Global platform specific sfputil class instance
platform_sfputil = None
# Global chassis object based on new platform api
Expand Down Expand Up @@ -94,17 +97,20 @@ def detect_port_in_error_status(logical_port_name, status_tbl):
rec, fvp = status_tbl.get(logical_port_name)
if rec:
status_dict = dict(fvp)
if status_dict['status'] in errors_block_eeprom_reading:
if status_dict.get('status', None) in errors_block_eeprom_reading:
return True
else:
return False
else:
return False

def handle_state_update_task(port, fvp_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):
def handle_state_update_task(op, port, fvp_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 = {}
port_dict[port] = fvp_dict.get('status', None)
if op == swsscommon.SET_COMMAND:
port_dict[port] = SFP_STATUS_INSERTED
elif op == swsscommon.DEL_COMMAND:
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)
Expand Down Expand Up @@ -143,9 +149,8 @@ def task_worker(self, y_cable_presence):
logger.log_warning("Got invalid asic index for {}, ignored".format(logical_port_name))
continue

if not detect_port_in_error_status(logical_port_name, self.table_helper.get_status_tbl()[asic_index]):
if y_cable_presence[0] is True:
y_cable_helper.check_identifier_presence_and_update_mux_info_entry(self.table_helper.get_state_db(), self.table_helper.get_mux_tbl(), asic_index, logical_port_name, self.table_helper.get_y_cable_tbl(), self.table_helper.get_port_tbl())
if y_cable_presence[0] is True:
y_cable_helper.check_identifier_presence_and_update_mux_info_entry(self.table_helper.get_state_db(), self.table_helper.get_mux_tbl(), asic_index, logical_port_name, self.table_helper.get_y_cable_tbl(), self.table_helper.get_port_tbl())

helper_logger.log_info("Stop DOM monitoring loop")

Expand Down Expand Up @@ -230,7 +235,7 @@ def task_worker(self, stopping_event, sfp_error_event, y_cable_presence):
continue

# Check if all tables are created in table_helper
handle_state_update_task(port, fvp_dict, y_cable_presence, self.table_helper.get_port_tbl(), self.table_helper.port_table_keys, self.table_helper.get_loopback_tbl(), self.table_helper.loopback_keys, self.table_helper.get_hw_mux_cable_tbl(), self.table_helper.get_hw_mux_cable_tbl_peer(), self.table_helper.get_y_cable_tbl(), self.table_helper.get_static_tbl(), self.table_helper.get_mux_tbl(), self.table_helper.get_grpc_config_tbl(), self.table_helper.get_fwd_state_response_tbl(), self.table_helper.state_db, stopping_event)
handle_state_update_task(op, port, fvp_dict, y_cable_presence, self.table_helper.get_port_tbl(), self.table_helper.port_table_keys, self.table_helper.get_loopback_tbl(), self.table_helper.loopback_keys, self.table_helper.get_hw_mux_cable_tbl(), self.table_helper.get_hw_mux_cable_tbl_peer(), self.table_helper.get_y_cable_tbl(), self.table_helper.get_static_tbl(), self.table_helper.get_mux_tbl(), self.table_helper.get_grpc_config_tbl(), self.table_helper.get_fwd_state_response_tbl(), self.table_helper.state_db, stopping_event)

def run(self):
if self.task_stopping_event.is_set():
Expand Down
8 changes: 4 additions & 4 deletions sonic-ycabled/ycable/ycable_utilities/y_cable_table_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

MUX_CABLE_STATIC_INFO_TABLE = "MUX_CABLE_STATIC_INFO"
MUX_CABLE_INFO_TABLE = "MUX_CABLE_INFO"
TRANSCEIVER_STATUS_TABLE = 'TRANSCEIVER_STATUS'
TRANSCEIVER_INFO_TABLE = 'TRANSCEIVER_INFO'

class YcableInfoUpdateTableHelper(object):
def __init__(self):
Expand All @@ -29,7 +29,7 @@ def __init__(self):
self.state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace)
self.config_db[asic_id] = daemon_base.db_connect("CONFIG_DB", namespace)
self.port_tbl[asic_id] = swsscommon.Table(self.config_db[asic_id], "MUX_CABLE")
self.status_tbl[asic_id] = swsscommon.Table(self.state_db[asic_id], TRANSCEIVER_STATUS_TABLE)
self.status_tbl[asic_id] = swsscommon.Table(self.state_db[asic_id], TRANSCEIVER_INFO_TABLE)
self.y_cable_tbl[asic_id] = swsscommon.Table(
self.state_db[asic_id], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME)
self.mux_tbl[asic_id] = swsscommon.Table(
Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(self):
self.state_db[asic_id] = daemon_base.db_connect("STATE_DB", namespace)
self.appl_db[asic_id] = daemon_base.db_connect("APPL_DB", namespace)
self.sub_status_tbl[asic_id] = swsscommon.SubscriberStateTable(
self.state_db[asic_id], TRANSCEIVER_STATUS_TABLE)
self.state_db[asic_id], TRANSCEIVER_INFO_TABLE)
self.config_db[asic_id] = daemon_base.db_connect("CONFIG_DB", namespace)
self.port_tbl[asic_id] = swsscommon.Table(self.config_db[asic_id], "MUX_CABLE")
self.port_table_keys[asic_id] = self.port_tbl[asic_id].getKeys()
Expand Down Expand Up @@ -497,7 +497,7 @@ def __init__(self):
self.appl_db[asic_id] = daemon_base.db_connect("APPL_DB", namespace)
self.config_db[asic_id] = daemon_base.db_connect("CONFIG_DB", namespace)
self.port_tbl[asic_id] = swsscommon.Table(self.config_db[asic_id], "MUX_CABLE")
self.status_tbl[asic_id] = swsscommon.Table(self.state_db[asic_id], TRANSCEIVER_STATUS_TABLE)
self.status_tbl[asic_id] = swsscommon.Table(self.state_db[asic_id], TRANSCEIVER_INFO_TABLE)
self.y_cable_tbl[asic_id] = swsscommon.Table(
self.state_db[asic_id], swsscommon.STATE_HW_MUX_CABLE_TABLE_NAME)
self.mux_tbl[asic_id] = swsscommon.Table(
Expand Down

0 comments on commit 04b0f88

Please sign in to comment.