Skip to content

Commit

Permalink
add support to execute new ycable API's, add datetime field to mux_in…
Browse files Browse the repository at this point in the history
…fo (#297)

This PR does two main things

It adds the capability for SONiC CLI to call few API's like operationtime, healthcheck, queue_info, reset cause for it to be displayed via CLI
It adds a datetime field inside MUX_CABLE_INFO helpful for tracking last update, and it removes some of the toggle synchronization logic for SONiC telemetry, since SONiC telemetry table MUX_CABLE_INFO is anyways disabled/enabled using CLI
config muxcable telemetry enable/disable, it is redundant to have this logic embedded in ycabled and port_instance helper objects, which could be unneccessary
Description
Motivation and Context
How Has This Been Tested?
Putting the changes on Arista testbed and UT
  • Loading branch information
vdahiya12 authored Sep 23, 2022
1 parent 6522c46 commit 143422b
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 47 deletions.
141 changes: 141 additions & 0 deletions sonic-ycabled/tests/test_y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def test_y_cable_wrapper_get_presence_with_platform_chassis_raise_exception(self
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
@patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self',
'time_post': '2022-Sep-23 00:09:16.968812',
'mux_direction': 'self',
'manual_switch_count': '7',
'auto_switch_count': '71',
Expand Down Expand Up @@ -3478,6 +3479,146 @@ def test_handle_get_fec_cmd_arg_tbl_notification_get_alive_status(self, port_ins
fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port)
assert(rc == None)

@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances')
@patch('swsscommon.swsscommon.Table')
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port')
@patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "health_check", {"modex": "0",
"lane_mask": "0",
"direction": "0"})))
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0)))
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0]))
def test_handle_get_fec_cmd_arg_tbl_notification_get_cable_health(self, port_instance, mock_swsscommon_table, port_instance_helper):

mock_table = MagicMock()
mock_swsscommon_table.return_value = mock_table

xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table
xcvrd_show_ber_rsp_tbl = mock_swsscommon_table
xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table
xcvrd_show_ber_res_tbl = mock_swsscommon_table
port_instance = MagicMock()
port_instance.health_check.return_value = True

asic_index = 0
port = "Ethernet0"
fvp = {"get_ber": True}

rc = handle_show_ber_cmd_arg_tbl_notification(
fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port)
assert(rc == None)

@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances')
@patch('swsscommon.swsscommon.Table')
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port')
@patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "health_check", {"modex": "0",
"lane_mask": "0",
"direction": "0"})))
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0)))
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0]))
def test_handle_get_fec_cmd_arg_tbl_notification_get_cable_health(self, port_instance, mock_swsscommon_table, port_instance_helper):

mock_table = MagicMock()
mock_swsscommon_table.return_value = mock_table

xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table
xcvrd_show_ber_rsp_tbl = mock_swsscommon_table
xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table
xcvrd_show_ber_res_tbl = mock_swsscommon_table
port_instance = MagicMock()
port_instance.health_check.return_value = True

asic_index = 0
port = "Ethernet0"
fvp = {"get_ber": True}

rc = handle_show_ber_cmd_arg_tbl_notification(
fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port)
assert(rc == None)

@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances')
@patch('swsscommon.swsscommon.Table')
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port')
@patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "reset_cause", {"modex": "0",
"lane_mask": "0",
"direction": "0"})))
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0)))
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0]))
def test_handle_get_fec_cmd_arg_tbl_notification_get_reset_cause(self, port_instance, mock_swsscommon_table, port_instance_helper):

mock_table = MagicMock()
mock_swsscommon_table.return_value = mock_table

xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table
xcvrd_show_ber_rsp_tbl = mock_swsscommon_table
xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table
xcvrd_show_ber_res_tbl = mock_swsscommon_table
port_instance = MagicMock()
port_instance.health_check.return_value = 0

asic_index = 0
port = "Ethernet0"
fvp = {"get_ber": True}

rc = handle_show_ber_cmd_arg_tbl_notification(
fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port)
assert(rc == None)

@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances')
@patch('swsscommon.swsscommon.Table')
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port')
@patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "operation_time", {"modex": "0",
"lane_mask": "0",
"direction": "0"})))
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0)))
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0]))
def test_handle_get_fec_cmd_arg_tbl_notification_get_reset_cause(self, port_instance, mock_swsscommon_table, port_instance_helper):

mock_table = MagicMock()
mock_swsscommon_table.return_value = mock_table

xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table
xcvrd_show_ber_rsp_tbl = mock_swsscommon_table
xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table
xcvrd_show_ber_res_tbl = mock_swsscommon_table
port_instance = MagicMock()
port_instance.oporation_time.return_value = 0

asic_index = 0
port = "Ethernet0"
fvp = {"get_ber": True}

rc = handle_show_ber_cmd_arg_tbl_notification(
fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port)
assert(rc == None)

@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances')
@patch('swsscommon.swsscommon.Table')
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port')
@patch('ycable.ycable_utilities.y_cable_helper.gather_arg_from_db_and_check_for_type', MagicMock(return_value=(0, "queue_info", {"modex": "0",
"lane_mask": "0",
"direction": "0"})))
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_physical_port_from_logical_port', MagicMock(return_value=(0)))
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_locks', MagicMock(return_value=[0]))
def test_handle_get_fec_cmd_arg_tbl_notification_get_queue_info(self, port_instance, mock_swsscommon_table, port_instance_helper):

mock_table = MagicMock()
mock_swsscommon_table.return_value = mock_table

xcvrd_show_ber_cmd_arg_tbl = mock_swsscommon_table
xcvrd_show_ber_rsp_tbl = mock_swsscommon_table
xcvrd_show_ber_cmd_sts_tbl = mock_swsscommon_table
xcvrd_show_ber_res_tbl = mock_swsscommon_table
port_instance = MagicMock()
port_instance.queue_info.return_value = 0

asic_index = 0
port = "Ethernet0"
fvp = {"get_ber": True}

rc = handle_show_ber_cmd_arg_tbl_notification(
fvp, xcvrd_show_ber_cmd_arg_tbl, xcvrd_show_ber_rsp_tbl, xcvrd_show_ber_cmd_sts_tbl, xcvrd_show_ber_res_tbl, asic_index, port)
assert(rc == None)

@patch('ycable.ycable_utilities.y_cable_helper.y_cable_port_instances')
@patch('swsscommon.swsscommon.Table')
@patch('ycable.ycable_utilities.y_cable_helper.get_ycable_port_instance_from_logical_port')
Expand Down
1 change: 1 addition & 0 deletions sonic-ycabled/tests/test_ycable.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ def test_put_all_values_from_dict_to_db(self):
@patch('ycable.ycable_utilities.y_cable_helper.y_cable_wrapper_get_presence', MagicMock(return_value=True))
@patch('ycable.ycable_utilities.y_cable_helper.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@patch('ycable.ycable_utilities.y_cable_helper.get_muxcable_info', MagicMock(return_value={'tor_active': 'self',
'time_post': '2022-Sep-23 00:09:16.968812',
'mux_direction': 'self',
'manual_switch_count': '7',
'auto_switch_count': '71',
Expand Down
Loading

0 comments on commit 143422b

Please sign in to comment.