4444import ptf .packet as scapy
4545import thread
4646import threading
47+ from multiprocessing .pool import ThreadPool , TimeoutError
4748import os
4849import signal
4950import random
@@ -407,6 +408,7 @@ def __init__(self):
407408 self .cli_info = {}
408409 self .logs_info = {}
409410 self .log_fp = open ('/tmp/reboot.log' , 'w' )
411+ self .log_lock = threading .RLock ()
410412 self .test_params = testutils .test_params_get ()
411413 self .check_param ('verbose' , False , required = False )
412414 self .check_param ('dut_username' , '' , required = True )
@@ -492,9 +494,10 @@ def random_port(self, ports):
492494
493495 def log (self , message , verbose = False ):
494496 current_time = datetime .datetime .now ().strftime ("%Y-%m-%d %H:%M:%S" )
495- if verbose and self .test_params ['verbose' ] or not verbose :
496- print "%s : %s" % (current_time , message )
497- self .log_fp .write ("%s : %s\n " % (current_time , message ))
497+ with self .log_lock :
498+ if verbose and self .test_params ['verbose' ] or not verbose :
499+ print "%s : %s" % (current_time , message )
500+ self .log_fp .write ("%s : %s\n " % (current_time , message ))
498501
499502 def timeout (self , seconds , message ):
500503 def timeout_exception (self , message ):
@@ -528,7 +531,7 @@ def setUp(self):
528531 #
529532 self .generate_from_t1 ()
530533 self .generate_from_vlan ()
531- self .generate_ping_dut_vlan_intf ()
534+ self .generate_ping_dut_lo ()
532535
533536 self .log ("Test params:" )
534537 self .log ("DUT ssh: %s" % self .dut_ssh )
@@ -658,13 +661,14 @@ def generate_from_vlan(self):
658661
659662 return
660663
661- def generate_ping_dut_vlan_intf (self ):
664+ def generate_ping_dut_lo (self ):
665+ dut_lo_ipv4 = self .test_params ['lo_prefix' ].split ('/' )[0 ]
662666 packet = simple_icmp_packet (eth_dst = self .dut_mac ,
663667 ip_src = self .from_server_src_addr ,
664- ip_dst = self . test_params [ 'dut_vlan_ip' ] )
668+ ip_dst = dut_lo_ipv4 )
665669
666670 exp_packet = simple_icmp_packet (eth_src = self .dut_mac ,
667- ip_src = self . test_params [ 'dut_vlan_ip' ] ,
671+ ip_src = dut_lo_ipv4 ,
668672 ip_dst = self .from_server_src_addr ,
669673 icmp_type = 'echo-reply' )
670674
@@ -708,9 +712,9 @@ def runTest(self):
708712 self .log ("Schedule to reboot the remote switch in %s sec" % self .reboot_delay )
709713 thr .start ()
710714
711- self .log ("Wait until VLAN and CPU port down" )
715+ self .log ("Wait until CPU port down" )
712716 self .timeout (self .task_timeout , "DUT hasn't shutdown in %d seconds" % self .task_timeout )
713- self .wait_until_vlan_cpu_port_down ()
717+ self .wait_until_cpu_port_down ()
714718 self .cancel_timeout ()
715719
716720 self .reboot_start = datetime .datetime .now ()
@@ -719,20 +723,32 @@ def runTest(self):
719723 self .log ("Check that device is still forwarding Data plane traffic" )
720724 self .assertTrue (self .check_alive (), 'DUT is not stable' )
721725
722- self .log ("Wait until VLAN and CPU port up" )
723- self .timeout (self .task_timeout , "DUT hasn't bootup in %d seconds" % self .task_timeout )
724- self .wait_until_vlan_cpu_port_up ()
725- self .cancel_timeout ()
726+ self .log ("Wait until CPU port up" )
727+ pool = ThreadPool (processes = 10 )
728+ async_cpu_up = pool .apply_async (self .wait_until_cpu_port_up )
726729
727730 self .log ("Wait until ASIC stops" )
728- self .timeout (self .task_timeout , "DUT hasn't stopped in %d seconds" % self .task_timeout )
729- no_routing_start , upper_replies = self .check_forwarding_stop ()
730- self .cancel_timeout ()
731-
732- self .log ("ASIC was stopped, Waiting until it's up. Stop time: %s" % str (no_routing_start ))
733- self .timeout (self .task_timeout , "DUT hasn't started to work for %d seconds" % self .task_timeout )
734- no_routing_stop , _ = self .check_forwarding_resume ()
735- self .cancel_timeout ()
731+ async_forward_stop = pool .apply_async (self .check_forwarding_stop )
732+
733+ try :
734+ async_cpu_up .get (timeout = self .task_timeout )
735+ except TimeoutError as e :
736+ self .log ("DUT hasn't bootup in %d seconds" % self .task_timeout )
737+ raise
738+
739+ try :
740+ no_routing_start , upper_replies = async_forward_stop .get (timeout = self .task_timeout )
741+ self .log ("ASIC was stopped, Waiting until it's up. Stop time: %s" % str (no_routing_start ))
742+ except TimeoutError :
743+ self .log ("ASIC never stop" )
744+ no_routing_start = datetime .min
745+
746+ if no_routing_start is not None :
747+ self .timeout (self .task_timeout , "DUT hasn't started to work for %d seconds" % self .task_timeout )
748+ no_routing_stop , _ = self .check_forwarding_resume ()
749+ self .cancel_timeout ()
750+ else :
751+ no_routing_stop = datetime .min
736752
737753 # wait until all bgp session are established
738754 self .log ("Wait until bgp routing is up on all devices" )
@@ -870,13 +886,13 @@ def peer_state_check(self, ip, queue):
870886 ssh = Arista (ip , queue , self .test_params )
871887 self .fails [ip ], self .info [ip ], self .cli_info [ip ], self .logs_info [ip ] = ssh .run ()
872888
873- def wait_until_vlan_cpu_port_down (self ):
889+ def wait_until_cpu_port_down (self ):
874890 while True :
875891 total_rcv_pkt_cnt = self .pingDut ()
876892 if total_rcv_pkt_cnt < self .ping_dut_pkts :
877893 break
878894
879- def wait_until_vlan_cpu_port_up (self ):
895+ def wait_until_cpu_port_up (self ):
880896 while True :
881897 total_rcv_pkt_cnt = self .pingDut ()
882898 if total_rcv_pkt_cnt >= self .ping_dut_pkts / 2 :
0 commit comments