diff --git a/lib/setupmanagers/qemuhck/exceptions.rb b/lib/setupmanagers/qemuhck/exceptions.rb index 528e0f1e..5eed1f67 100644 --- a/lib/setupmanagers/qemuhck/exceptions.rb +++ b/lib/setupmanagers/qemuhck/exceptions.rb @@ -6,4 +6,6 @@ module AutoHCK # A custom QemuHCKError error exception class QemuHCKError < SetupManagerError; end + + class QemuRunError < QemuHCKError; end end diff --git a/lib/setupmanagers/qemuhck/qemu_machine.rb b/lib/setupmanagers/qemuhck/qemu_machine.rb index 2dd9cfc6..e3f3d852 100644 --- a/lib/setupmanagers/qemuhck/qemu_machine.rb +++ b/lib/setupmanagers/qemuhck/qemu_machine.rb @@ -89,6 +89,20 @@ def run_qemu(scope) qemu end + def check_fails_too_quickly(status) + if status&.zero? + @first_fail_time = nil + false + end + + if @first_fail_time.nil? + @first_fail_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + false + else + (Process.clock_gettime(Process::CLOCK_MONOTONIC) - @first_fail_time) <= 10 + end + end + def run_vm @machine.dump_config @@ -99,7 +113,7 @@ def run_vm @machine.run_pre_start_commands qemu = run_qemu(scope) - qemu.wait_no_fail + @fails_quickly = check_fails_too_quickly(qemu.wait_no_fail&.exitstatus) qemu = nil ensure unless qemu.nil? @@ -109,6 +123,8 @@ def run_vm @machine.run_post_stop_commands end + raise QemuRunError, 'QEMU fails repeated too quickly' if @fails_quickly + break unless @keep_alive end end