Skip to content

Commit 94fa239

Browse files
authored
[y_cable] refactor y_cable to a seperate logic and new daemon from xcvrd (sonic-net#219)
* [xcvrd] suuport for integrating y cable within xcvrd This PR separates the logic of Y-Cable from xcvrd. Before this change we were utilizing xcvrd daemon to control all aspects of Y-Cable right from initialization to processing requests from other entities like orch,linkmgr. Now we would have another daemon ycabled which will serve this purpose. Logically everything still remains the same from the perspective of other daemons. it also take care aspects like init/delete daemon from Y-Cable perspective. dependent-startup EXITED Jan 18 05:40 AM xcvrd RUNNING pid 33, uptime 20:02:58 ycabled RUNNING pid 218, uptime 0:22:12 Motivation and Context Required for separating the logic of Y-Cable from xcvrd. This is to ensure that the daemon always works and responds to linkmgr to address its requests How Has This Been Tested? Built an image with the changes and ran dualtor specific tests on the change on a 7050cx3 testbed. Signed-off-by: vaibhav-dahiya <[email protected]>
1 parent c4127c2 commit 94fa239

15 files changed

+4852
-2225
lines changed

azure-pipelines.yml

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ parameters:
5858
root_dir: sonic-xcvrd
5959
python2: true
6060
python3: true
61+
- name: ycabled
62+
root_dir: sonic-ycabled
63+
python3: true
6164
- name: artifactBranch
6265
type: string
6366
default: 'refs/heads/master'

sonic-xcvrd/tests/test_xcvrd.py

+15-17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from xcvrd.xcvrd_utilities.port_mapping import *
22
from xcvrd.xcvrd_utilities.sfp_status_helper import *
3-
from xcvrd.xcvrd_utilities.y_cable_helper import *
43
from xcvrd.xcvrd import *
54
import copy
65
import os
@@ -23,6 +22,7 @@
2322
swsscommon.ProducerStateTable = MagicMock()
2423
swsscommon.SubscriberStateTable = MagicMock()
2524
swsscommon.SonicDBConfig = MagicMock()
25+
#swsscommon.Select = MagicMock()
2626

2727
test_path = os.path.dirname(os.path.abspath(__file__))
2828
modules_path = os.path.dirname(test_path)
@@ -39,8 +39,6 @@
3939
media_settings_with_comma_dict['GLOBAL_MEDIA_SETTINGS']['1-5,6,7-20,21-32'] = global_media_settings
4040

4141
class TestXcvrdScript(object):
42-
def test_xcvrd_helper_class_run(self):
43-
Y_cable_task = YCableTableUpdateTask(None)
4442

4543
@patch('xcvrd.xcvrd._wrapper_get_sfp_type')
4644
@patch('xcvrd.xcvrd_utilities.port_mapping.PortMapping.logical_port_name_to_physical_port_list', MagicMock(return_value=[0]))
@@ -569,7 +567,7 @@ def test_DomInfoUpdateTask_handle_port_change_event(self):
569567
def test_DomInfoUpdateTask_task_run_stop(self):
570568
port_mapping = PortMapping()
571569
task = DomInfoUpdateTask(port_mapping)
572-
task.task_run([False])
570+
task.task_run()
573571
task.task_stop()
574572
assert not task.task_thread.is_alive()
575573

@@ -591,7 +589,7 @@ def test_DomInfoUpdateTask_task_worker(self, mock_select, mock_sub_table, mock_p
591589
task = DomInfoUpdateTask(port_mapping)
592590
task.task_stopping_event.wait = MagicMock(side_effect=[False, True])
593591
mock_detect_error.return_value = True
594-
task.task_worker([False])
592+
task.task_worker()
595593
assert task.port_mapping.logical_port_list.count('Ethernet0')
596594
assert task.port_mapping.get_asic_id_for_logical_port('Ethernet0') == 0
597595
assert task.port_mapping.get_physical_to_logical(1) == ['Ethernet0']
@@ -600,7 +598,7 @@ def test_DomInfoUpdateTask_task_worker(self, mock_select, mock_sub_table, mock_p
600598
assert mock_post_dom_info.call_count == 0
601599
mock_detect_error.return_value = False
602600
task.task_stopping_event.wait = MagicMock(side_effect=[False, True])
603-
task.task_worker([False])
601+
task.task_worker()
604602
assert mock_post_dom_th.call_count == 1
605603
assert mock_post_dom_info.call_count == 1
606604

@@ -619,7 +617,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_table_helper):
619617
port_change_event = PortChangeEvent('Ethernet0', 1, 0, PortChangeEvent.PORT_ADD)
620618
wait_time = 5
621619
while wait_time > 0:
622-
task.on_port_config_change(stopping_event, [False], port_change_event)
620+
task.on_port_config_change(port_change_event)
623621
if task.port_mapping.logical_port_list:
624622
break
625623
wait_time -= 1
@@ -632,7 +630,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_table_helper):
632630
port_change_event = PortChangeEvent('Ethernet0', 1, 0, PortChangeEvent.PORT_REMOVE)
633631
wait_time = 5
634632
while wait_time > 0:
635-
task.on_port_config_change(stopping_event, [False], port_change_event)
633+
task.on_port_config_change(port_change_event)
636634
if not task.port_mapping.logical_port_list:
637635
break
638636
wait_time -= 1
@@ -647,7 +645,7 @@ def test_SfpStateUpdateTask_task_run_stop(self):
647645
retry_eeprom_set = set()
648646
task = SfpStateUpdateTask(port_mapping, retry_eeprom_set)
649647
sfp_error_event = multiprocessing.Event()
650-
task.task_run(sfp_error_event, [False])
648+
task.task_run(sfp_error_event)
651649
assert wait_until(5, 1, task.task_process.is_alive)
652650
task.task_stop()
653651
assert wait_until(5, 1, lambda: task.task_process.is_alive() is False)
@@ -718,23 +716,23 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
718716
mock_mapping_event.return_value = SYSTEM_NOT_READY
719717

720718
# Test state machine: STATE_INIT + SYSTEM_NOT_READY event => STATE_INIT + SYSTEM_NOT_READY event ... => STATE_EXIT
721-
task.task_worker(stop_event, sfp_error_event, [False])
719+
task.task_worker(stop_event, sfp_error_event)
722720
assert mock_os_kill.call_count == 1
723721
assert sfp_error_event.is_set()
724722

725723
mock_mapping_event.return_value = SYSTEM_FAIL
726724
mock_os_kill.reset_mock()
727725
sfp_error_event.clear()
728726
# Test state machine: STATE_INIT + SYSTEM_FAIL event => STATE_INIT + SYSTEM_FAIL event ... => STATE_EXIT
729-
task.task_worker(stop_event, sfp_error_event, [False])
727+
task.task_worker(stop_event, sfp_error_event)
730728
assert mock_os_kill.call_count == 1
731729
assert sfp_error_event.is_set()
732730

733731
mock_mapping_event.side_effect = [SYSTEM_BECOME_READY, SYSTEM_NOT_READY]
734732
mock_os_kill.reset_mock()
735733
sfp_error_event.clear()
736734
# Test state machine: STATE_INIT + SYSTEM_BECOME_READY event => STATE_NORMAL + SYSTEM_NOT_READY event ... => STATE_EXIT
737-
task.task_worker(stop_event, sfp_error_event, [False])
735+
task.task_worker(stop_event, sfp_error_event)
738736
assert mock_os_kill.call_count == 1
739737
assert not sfp_error_event.is_set()
740738

@@ -744,7 +742,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
744742
sfp_error_event.clear()
745743
# Test state machine: STATE_INIT + SYSTEM_BECOME_READY event => STATE_NORMAL + SYSTEM_FAIL event ... => STATE_INIT
746744
# + SYSTEM_FAIL event ... => STATE_EXIT
747-
task.task_worker(stop_event, sfp_error_event, [False])
745+
task.task_worker(stop_event, sfp_error_event)
748746
assert mock_os_kill.call_count == 1
749747
assert sfp_error_event.is_set()
750748

@@ -755,7 +753,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
755753
mock_post_sfp_info.return_value = SFP_EEPROM_NOT_READY
756754
stop_event.is_set = MagicMock(side_effect=[False, True])
757755
# Test state machine: handle SFP insert event, but EEPROM read failure
758-
task.task_worker(stop_event, sfp_error_event, [False])
756+
task.task_worker(stop_event, sfp_error_event)
759757
assert mock_updata_status.call_count == 1
760758
assert mock_post_sfp_info.call_count == 2 # first call and retry call
761759
assert mock_post_dom_info.call_count == 0
@@ -769,7 +767,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
769767
mock_updata_status.reset_mock()
770768
mock_post_sfp_info.reset_mock()
771769
# Test state machine: handle SFP insert event, and EEPROM read success
772-
task.task_worker(stop_event, sfp_error_event, [False])
770+
task.task_worker(stop_event, sfp_error_event)
773771
assert mock_updata_status.call_count == 1
774772
assert mock_post_sfp_info.call_count == 1
775773
assert mock_post_dom_info.call_count == 1
@@ -780,7 +778,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
780778
mock_change_event.return_value = (True, {1: SFP_STATUS_REMOVED}, {})
781779
mock_updata_status.reset_mock()
782780
# Test state machine: handle SFP remove event
783-
task.task_worker(stop_event, sfp_error_event, [False])
781+
task.task_worker(stop_event, sfp_error_event)
784782
assert mock_updata_status.call_count == 1
785783
assert mock_del_dom.call_count == 1
786784

@@ -790,7 +788,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
790788
mock_updata_status.reset_mock()
791789
mock_del_dom.reset_mock()
792790
# Test state machine: handle SFP error event
793-
task.task_worker(stop_event, sfp_error_event, [False])
791+
task.task_worker(stop_event, sfp_error_event)
794792
assert mock_updata_status.call_count == 1
795793
assert mock_del_dom.call_count == 1
796794

0 commit comments

Comments
 (0)