1
1
from xcvrd .xcvrd_utilities .port_mapping import *
2
2
from xcvrd .xcvrd_utilities .sfp_status_helper import *
3
- from xcvrd .xcvrd_utilities .y_cable_helper import *
4
3
from xcvrd .xcvrd import *
5
4
import copy
6
5
import os
23
22
swsscommon .ProducerStateTable = MagicMock ()
24
23
swsscommon .SubscriberStateTable = MagicMock ()
25
24
swsscommon .SonicDBConfig = MagicMock ()
25
+ #swsscommon.Select = MagicMock()
26
26
27
27
test_path = os .path .dirname (os .path .abspath (__file__ ))
28
28
modules_path = os .path .dirname (test_path )
39
39
media_settings_with_comma_dict ['GLOBAL_MEDIA_SETTINGS' ]['1-5,6,7-20,21-32' ] = global_media_settings
40
40
41
41
class TestXcvrdScript (object ):
42
- def test_xcvrd_helper_class_run (self ):
43
- Y_cable_task = YCableTableUpdateTask (None )
44
42
45
43
@patch ('xcvrd.xcvrd._wrapper_get_sfp_type' )
46
44
@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):
569
567
def test_DomInfoUpdateTask_task_run_stop (self ):
570
568
port_mapping = PortMapping ()
571
569
task = DomInfoUpdateTask (port_mapping )
572
- task .task_run ([ False ] )
570
+ task .task_run ()
573
571
task .task_stop ()
574
572
assert not task .task_thread .is_alive ()
575
573
@@ -591,7 +589,7 @@ def test_DomInfoUpdateTask_task_worker(self, mock_select, mock_sub_table, mock_p
591
589
task = DomInfoUpdateTask (port_mapping )
592
590
task .task_stopping_event .wait = MagicMock (side_effect = [False , True ])
593
591
mock_detect_error .return_value = True
594
- task .task_worker ([ False ] )
592
+ task .task_worker ()
595
593
assert task .port_mapping .logical_port_list .count ('Ethernet0' )
596
594
assert task .port_mapping .get_asic_id_for_logical_port ('Ethernet0' ) == 0
597
595
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
600
598
assert mock_post_dom_info .call_count == 0
601
599
mock_detect_error .return_value = False
602
600
task .task_stopping_event .wait = MagicMock (side_effect = [False , True ])
603
- task .task_worker ([ False ] )
601
+ task .task_worker ()
604
602
assert mock_post_dom_th .call_count == 1
605
603
assert mock_post_dom_info .call_count == 1
606
604
@@ -619,7 +617,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_table_helper):
619
617
port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_ADD )
620
618
wait_time = 5
621
619
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 )
623
621
if task .port_mapping .logical_port_list :
624
622
break
625
623
wait_time -= 1
@@ -632,7 +630,7 @@ def test_SfpStateUpdateTask_handle_port_change_event(self, mock_table_helper):
632
630
port_change_event = PortChangeEvent ('Ethernet0' , 1 , 0 , PortChangeEvent .PORT_REMOVE )
633
631
wait_time = 5
634
632
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 )
636
634
if not task .port_mapping .logical_port_list :
637
635
break
638
636
wait_time -= 1
@@ -647,7 +645,7 @@ def test_SfpStateUpdateTask_task_run_stop(self):
647
645
retry_eeprom_set = set ()
648
646
task = SfpStateUpdateTask (port_mapping , retry_eeprom_set )
649
647
sfp_error_event = multiprocessing .Event ()
650
- task .task_run (sfp_error_event , [ False ] )
648
+ task .task_run (sfp_error_event )
651
649
assert wait_until (5 , 1 , task .task_process .is_alive )
652
650
task .task_stop ()
653
651
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_
718
716
mock_mapping_event .return_value = SYSTEM_NOT_READY
719
717
720
718
# 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 )
722
720
assert mock_os_kill .call_count == 1
723
721
assert sfp_error_event .is_set ()
724
722
725
723
mock_mapping_event .return_value = SYSTEM_FAIL
726
724
mock_os_kill .reset_mock ()
727
725
sfp_error_event .clear ()
728
726
# 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 )
730
728
assert mock_os_kill .call_count == 1
731
729
assert sfp_error_event .is_set ()
732
730
733
731
mock_mapping_event .side_effect = [SYSTEM_BECOME_READY , SYSTEM_NOT_READY ]
734
732
mock_os_kill .reset_mock ()
735
733
sfp_error_event .clear ()
736
734
# 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 )
738
736
assert mock_os_kill .call_count == 1
739
737
assert not sfp_error_event .is_set ()
740
738
@@ -744,7 +742,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
744
742
sfp_error_event .clear ()
745
743
# Test state machine: STATE_INIT + SYSTEM_BECOME_READY event => STATE_NORMAL + SYSTEM_FAIL event ... => STATE_INIT
746
744
# + SYSTEM_FAIL event ... => STATE_EXIT
747
- task .task_worker (stop_event , sfp_error_event , [ False ] )
745
+ task .task_worker (stop_event , sfp_error_event )
748
746
assert mock_os_kill .call_count == 1
749
747
assert sfp_error_event .is_set ()
750
748
@@ -755,7 +753,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
755
753
mock_post_sfp_info .return_value = SFP_EEPROM_NOT_READY
756
754
stop_event .is_set = MagicMock (side_effect = [False , True ])
757
755
# 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 )
759
757
assert mock_updata_status .call_count == 1
760
758
assert mock_post_sfp_info .call_count == 2 # first call and retry call
761
759
assert mock_post_dom_info .call_count == 0
@@ -769,7 +767,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
769
767
mock_updata_status .reset_mock ()
770
768
mock_post_sfp_info .reset_mock ()
771
769
# 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 )
773
771
assert mock_updata_status .call_count == 1
774
772
assert mock_post_sfp_info .call_count == 1
775
773
assert mock_post_dom_info .call_count == 1
@@ -780,7 +778,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
780
778
mock_change_event .return_value = (True , {1 : SFP_STATUS_REMOVED }, {})
781
779
mock_updata_status .reset_mock ()
782
780
# 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 )
784
782
assert mock_updata_status .call_count == 1
785
783
assert mock_del_dom .call_count == 1
786
784
@@ -790,7 +788,7 @@ def test_SfpStateUpdateTask_task_worker(self, mock_updata_status, mock_post_sfp_
790
788
mock_updata_status .reset_mock ()
791
789
mock_del_dom .reset_mock ()
792
790
# 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 )
794
792
assert mock_updata_status .call_count == 1
795
793
assert mock_del_dom .call_count == 1
796
794
0 commit comments