diff --git a/lib/auxiliary/closable_thread.rb b/lib/auxiliary/closable_thread.rb new file mode 100644 index 00000000..d4dbe347 --- /dev/null +++ b/lib/auxiliary/closable_thread.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require './lib/exceptions' + +module AutoHCK + # ClosableThread is a Thread with close method + class ClosableThread < Thread + def close + kill + join + end + end +end diff --git a/lib/setupmanagers/qemuhck/qemu_machine.rb b/lib/setupmanagers/qemuhck/qemu_machine.rb index c38ee038..cbf86a52 100644 --- a/lib/setupmanagers/qemuhck/qemu_machine.rb +++ b/lib/setupmanagers/qemuhck/qemu_machine.rb @@ -7,6 +7,7 @@ require_relative 'qmp' require_relative 'exceptions' +require_relative '../../auxiliary/closable_thread' require_relative '../../auxiliary/json_helper' require_relative '../../auxiliary/host_helper' require_relative '../../auxiliary/resource_scope' @@ -66,8 +67,10 @@ def initialize(scope, logger, machine, run_name, run_opts) @keep_alive = run_opts[:keep_alive] @delete_snapshot = run_opts[:create_snapshot] @machine.run_config_commands - run_vm + @machine.dump_config + @qemu_thread = run_vm scope << self + scope << @qemu_thread end def keep_snapshot @@ -91,16 +94,28 @@ def run_qemu(scope) qemu end - def run_vm - @machine.dump_config + def run_up + ClosableThread.new do + loop do + sleep 1 + try_with_qmp(&:up) + end + end + end - @qemu_thread = Thread.new do + def run_vm + ClosableThread.new do loop do qemu = nil ResourceScope.open do |scope| @machine.run_pre_start_commands qemu = run_qemu(scope) + + # The installer requires to press some key to start for UEFI + # systems. + scope << run_up + qemu.wait_no_fail qemu = nil ensure @@ -152,9 +167,6 @@ def vm_abort return if hard_abort @logger.info("#{@run_name} hard abort failed, force aborting...") - - @qemu_thread.kill - @qemu_thread.join end def close diff --git a/lib/setupmanagers/qemuhck/qmp.rb b/lib/setupmanagers/qemuhck/qmp.rb index bea0a055..40037b74 100644 --- a/lib/setupmanagers/qemuhck/qmp.rb +++ b/lib/setupmanagers/qemuhck/qmp.rb @@ -23,19 +23,39 @@ def initialize(scope, name, logger) def quit @logger.info("Sending quit signal to #{@name} via QMP") - run_cmd('quit') + run_cmd 'execute' => 'quit' end def powerdown @logger.info("Sending powerdown signal to #{@name} via QMP") - run_cmd('system_powerdown') + run_cmd 'execute' => 'system_powerdown' + end + + def up + run_cmd( + 'execute' => 'input-send-event', + 'arguments' => { + 'events' => [ + { + 'type' => 'key', + 'data' => { + 'down' => true, + 'key' => { + 'type' => 'qcode', + 'data' => 'up' + } + } + } + ] + } + ) end private def run_cmd(cmd) unless @negotiated - send_cmd 'qmp_capabilities' + send_cmd 'execute' => 'qmp_capabilities' @negotiated = true end @@ -43,7 +63,7 @@ def run_cmd(cmd) end def send_cmd(cmd) - @socket_internal.write JSON.dump({ 'execute' => cmd }) + @socket_internal.write JSON.dump(cmd) @socket_internal.flush loop do