@@ -818,22 +818,22 @@ def is_shutoff():
818818 controllerVM .execute ('virsh domstate testvm | grep "shut off"' )[0 ] == 0
819819 )
820820
821- assert wait_until_succeed (is_shutoff )
821+ wait_until_succeed (is_shutoff )
822822
823823 controllerVM .fail ("find /run/libvirt/ch -name *.xml | grep ." )
824824
825825 controllerVM .succeed ("virsh start testvm" )
826826 wait_for_ssh (controllerVM )
827827
828828 controllerVM .succeed ("virsh shutdown testvm" )
829- assert wait_until_succeed (is_shutoff )
829+ wait_until_succeed (is_shutoff )
830830 controllerVM .fail ("find /run/libvirt/ch -name *.xml | grep ." )
831831
832832 controllerVM .succeed ("virsh start testvm" )
833833 wait_for_ssh (controllerVM )
834834
835835 controllerVM .succeed ("virsh destroy testvm" )
836- assert wait_until_succeed (is_shutoff )
836+ wait_until_succeed (is_shutoff )
837837 controllerVM .fail ("find /run/libvirt/ch -name *.xml | grep ." )
838838
839839 def test_libvirt_event_stop_failed (self ):
@@ -942,7 +942,7 @@ def prompt():
942942 )
943943 return status == 0
944944
945- assert wait_until_succeed (prompt )
945+ wait_until_succeed (prompt )
946946
947947 controllerVM .succeed (
948948 textwrap .dedent ("""
@@ -1055,7 +1055,7 @@ def migration_finished():
10551055 status , _ = controllerVM .execute ("screen -ls | grep migrate" )
10561056 return status != 0
10571057
1058- self . assertTrue ( wait_until_succeed (migration_finished ) )
1058+ wait_until_succeed (migration_finished )
10591059
10601060 computeVM .succeed ("virsh list | grep testvm | grep running" )
10611061
@@ -1353,11 +1353,8 @@ def check_virsh_list(vm):
13531353 status , _ = vm .execute ("virsh list | grep testvm > /dev/null" )
13541354 return status == 0
13551355
1356- status = wait_until_fail (lambda : check_virsh_list (controllerVM ))
1357- assert status
1358-
1359- status = wait_until_fail (lambda : check_virsh_list (computeVM ))
1360- assert status
1356+ wait_until_fail (lambda : check_virsh_list (controllerVM ))
1357+ wait_until_fail (lambda : check_virsh_list (computeVM ))
13611358
13621359 def test_live_migration_kill_chv_on_receiver_side (self ):
13631360 """
@@ -1391,11 +1388,9 @@ def check_virsh_list(vm):
13911388 status , _ = vm .execute ("virsh list | grep testvm > /dev/null" )
13921389 return status == 0
13931390
1394- status = wait_until_fail (lambda : check_virsh_list (computeVM ))
1395- assert status
1391+ wait_until_fail (lambda : check_virsh_list (computeVM ))
13961392
1397- status = wait_until_succeed (lambda : check_virsh_list (controllerVM ))
1398- assert status
1393+ wait_until_succeed (lambda : check_virsh_list (controllerVM ))
13991394
14001395 controllerVM .succeed ("virsh list | grep 'running'" )
14011396
@@ -1944,29 +1939,34 @@ def measure_ms(func):
19441939 return (time .time () - start ) * 1000
19451940
19461941
1947- def wait_until_succeed (func , retries = 600 ) -> bool :
1942+ def wait_until_succeed (func , retries = 600 ):
19481943 """
19491944 Waits for the command to succeed.
19501945 After each failure, it waits 100ms.
19511946
19521947 :param func: Function that is expected to succeed.
19531948 :param retries: Amount of retries.
1954- :return: whether the function succeeded eventually
19551949 """
19561950 for _i in range (retries ):
19571951 if func ():
1958- return True
1952+ return
19591953 time .sleep (0.1 )
1960- return False
1954+ raise RuntimeError ("function didn't succeed" )
1955+
19611956
1957+ def wait_until_fail (func , retries = 600 ):
1958+ """
1959+ Waits for the command to succeed.
1960+ After each failure, it waits 100ms.
19621961
1963- def wait_until_fail (func ):
1964- retries = 600
1962+ :param func: Function that is expected to succeed.
1963+ :param retries: Amount of retries.
1964+ """
19651965 for i in range (retries ):
19661966 if not func ():
1967- return True
1967+ return
19681968 time .sleep (0.1 )
1969- return False
1969+ raise RuntimeError ( "function didn't fail" )
19701970
19711971
19721972def wait_for_ssh (machine : Machine , user = "root" , password = "root" , ip = "192.168.1.2" ):
@@ -2158,10 +2158,7 @@ def wait_for_guest_pci_device_enumeration(machine: Machine, new_count: int):
21582158 :return:
21592159 """
21602160 # retries=20 => max 2s => we expect hotplug events to be relatively quick
2161- if not wait_until_succeed (lambda : number_of_devices (machine ) == new_count , 20 ):
2162- raise RuntimeError (
2163- f"guest did acknowledge PCI hotplug event: should be { new_count } but is { number_of_devices (machine )} "
2164- )
2161+ wait_until_succeed (lambda : number_of_devices (machine ) == new_count , 20 )
21652162
21662163
21672164runner = unittest .TextTestRunner ()
0 commit comments