Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: vaibhav-dahiya <[email protected]>
  • Loading branch information
vdahiya12 committed Jun 21, 2023
1 parent 0975c5b commit 9e5b009
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
42 changes: 32 additions & 10 deletions sonic-ycabled/tests/test_y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7157,7 +7157,7 @@ def test_ycable_helper_cli_worker(self, mock_select, mock_sub_table):

mock_selectable = MagicMock()
mock_selectable.pop = MagicMock(
side_effect=[(False, False, False), (False, False, False), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), (None, None, None), (None, None, None)])
side_effect=[('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), (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

Expand All @@ -7166,21 +7166,41 @@ def test_ycable_helper_cli_worker(self, mock_select, mock_sub_table):
asic_index = 0
Y_cable_cli_task = YCableCliUpdateTask()
Y_cable_cli_task.task_stopping_event.is_set = MagicMock(side_effect=[False, True])
Y_cable_cli_task.cli_table_helper.xcvrd_show_hwmode_dir_cmd_tbl[asic_index].return_value = mock_selectable

#Y_cable_cli_task.task_stopping_event.is_set = MagicMock(side_effect=False)

expected_exception_start = None
expected_exception_join = None
trace = None
try:
#Y_cable_cli_task.start()
Y_cable_cli_task.task_cli_worker()
time.sleep(5)
Y_cable_cli_task.task_stopping_event.clear()
except Exception as e1:
expected_exception_start = e1
trace = traceback.format_exc()
Y_cable_cli_task.task_cli_worker()
Y_cable_cli_task.task_stopping_event.clear()

assert swsscommon.Select.select.call_count == 1
#y_cable_helper.handle_show_hwmode_state_cmd_arg_tbl_notification.assert_called()
Y_cable_cli_task_n = YCableCliUpdateTask()
Y_cable_cli_task_n.task_stopping_event.is_set = MagicMock(side_effect=[False, True])

mock_selectable.pop = MagicMock(
side_effect=[(False, False, False), (False, False, False), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), (None, None, None), (None, None, None)])
mock_selectable.pop = MagicMock(
side_effect=[('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), (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)

Y_cable_cli_task_n.task_cli_worker()
assert swsscommon.Select.select.call_count == 2

"""
Y_cable_cli_task_a = YCableCliUpdateTask()
Y_cable_cli_task_a.task_stopping_event.is_set = MagicMock(side_effect=[False, True])
mock_selectable.pop = MagicMock(
side_effect=[(False, False, False), ('Ethernet0', swsscommon.SET_COMMAND, (('index', '1'), )), (None, None, None), (None, None, None)])
mock_select.return_value = (swsscommon.Select.OBJECT, mock_selectable)
Y_cable_cli_task_a.task_cli_worker()
assert swsscommon.Select.select.call_count == 3
"""


@patch('swsscommon.swsscommon.Select.addSelectable', MagicMock())
Expand Down Expand Up @@ -7209,6 +7229,7 @@ def test_ycable_helper_cli_worker_execution(self, mock_select, mock_sub_table):
expected_exception_start = None
expected_exception_join = None
trace = None
"""
try:
#Y_cable_cli_task.start()
Y_cable_cli_task.task_cli_worker()
Expand All @@ -7217,5 +7238,6 @@ def test_ycable_helper_cli_worker_execution(self, mock_select, mock_sub_table):
except Exception as e1:
expected_exception_start = e1
trace = traceback.format_exc()
"""


5 changes: 1 addition & 4 deletions sonic-ycabled/tests/test_ycable.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def test_ycable_info_helper_class_run(self, mocked_sleep):
except Exception as e:
pass

"""
@patch("swsscommon.swsscommon.Select", MagicMock())
@patch("swsscommon.swsscommon.Select.addSelectable", MagicMock())
@patch("swsscommon.swsscommon.Select.select", MagicMock())
Expand All @@ -83,7 +82,6 @@ def test_ycable_helper_class_run_loop(self):
Y_cable_cli_task.task_cli_worker()
Y_cable_cli_task.start()
Y_cable_cli_task.join()
"""


@patch("swsscommon.swsscommon.Select", MagicMock())
Expand Down Expand Up @@ -331,7 +329,7 @@ def wait_until(total_wait_time, interval, call_back, *args, **kwargs):
return False


"""class TestYcableScriptException(object):
class TestYcableScriptException(object):

@patch("swsscommon.swsscommon.Select", MagicMock(side_effect=NotImplementedError))
@patch("swsscommon.swsscommon.Select.addSelectable", MagicMock(side_effect=NotImplementedError))
Expand Down Expand Up @@ -362,7 +360,6 @@ def test_ycable_helper_class_run_loop_with_exception(self):
assert("NotImplementedError" in str(trace) and "effect" in str(trace))
assert("sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py" in str(trace))
assert("swsscommon.Select" in str(trace))
"""


class TestYcableAsyncScript(object):
Expand Down
4 changes: 1 addition & 3 deletions sonic-ycabled/ycable/ycable_utilities/y_cable_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3823,8 +3823,8 @@ def task_cli_worker(self):
# Use timeout to prevent ignoring the signals we want to handle
# in signal_handler() (e.g. SIGTERM for graceful shutdown)


(state, selectableObj) = sel.select(SELECT_TIMEOUT)
self.exc = None

if state == swsscommon.Select.TIMEOUT:
# Do not flood log when select times out
Expand Down Expand Up @@ -3991,8 +3991,6 @@ def task_cli_worker(self):
handle_show_ber_cmd_arg_tbl_notification(fvp, self.cli_table_helper.xcvrd_show_ber_cmd_arg_tbl, self.cli_table_helper.xcvrd_show_ber_rsp_tbl, self.cli_table_helper.xcvrd_show_ber_cmd_sts_tbl, self.cli_table_helper.xcvrd_show_ber_res_tbl, asic_index, port)

break
"""
"""

def run(self):
if self.task_stopping_event.is_set():
Expand Down

0 comments on commit 9e5b009

Please sign in to comment.