Skip to content

Commit

Permalink
Merge pull request #2212 from os-autoinst/revert-2206-cmd_h_stop_at
Browse files Browse the repository at this point in the history
Revert "Move stop_autotest into CommandHandler"
  • Loading branch information
kalikiana committed Nov 21, 2022
2 parents 61d5b38 + eb6bf7c commit dee0e60
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
20 changes: 0 additions & 20 deletions OpenQA/Isotovideo/CommandHandler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package OpenQA::Isotovideo::CommandHandler;
use Mojo::Base 'Mojo::EventEmitter', -signatures;

use bmwqemu;
use autotest ();
use log qw(diag fctwarn);
use OpenQA::Isotovideo::Interface;
use OpenQA::Isotovideo::NeedleDownloader;
Expand All @@ -20,9 +19,6 @@ use constant AUTOINST_STATUSFILE => 'autoinst-status.json';
# io handles for sending data to command server and backend
has [qw(test_fd cmd_srv_fd backend_fd backend_out_fd answer_fd)] => undef;

# the running test process
has test_process => undef;

# the name of the current test (full name includes category prefix, eg. installation-)
has [qw(current_test_name current_test_full_name)];

Expand Down Expand Up @@ -68,10 +64,6 @@ has [qw(last_check_seconds last_check_microseconds)] => 0;
sub new ($class, @args) {
my $self = $class->SUPER::new(@args);
$self->_update_last_check;
my ($test_process, $test_fd) = autotest::start_process;
$test_process->once(collected => sub { $self->loop(0) if $self->loop });
$self->test_process($test_process);
$self->test_fd($test_fd);
return $self;
}

Expand All @@ -85,18 +77,9 @@ sub setup_signal_handler ($self) {
sub _signal_handler ($self, $sig) {
bmwqemu::serialize_state(component => 'isotovideo', msg => "isotovideo received signal $sig", log => 1);
return $self->loop(0) if $self->loop;
$self->stop_autotest;
$self->emit(signal => $sig);
}

sub stop_autotest ($self) {
my $test_process = $self->test_process or return;
diag('stopping autotest process ' . $test_process->pid);
$test_process->stop() if $test_process->is_running;
$self->test_process(undef);
diag('done with autotest process');
}

sub clear_tags_and_timeout ($self) {
$self->tags(undef);
$self->timeout(undef);
Expand Down Expand Up @@ -306,9 +289,6 @@ sub _handle_command_set_current_test ($self, $response, @) {
sub _handle_command_tests_done ($self, $response, @) {
$self->test_died($response->{died});
$self->test_completed($response->{completed});
CORE::close($self->test_fd);
$self->test_fd(undef);
$self->stop_autotest;
$self->emit(tests_done => $response);
$self->loop(0);
$self->current_test_name('');
Expand Down
30 changes: 26 additions & 4 deletions isotovideo
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ BEGIN {

use log qw(diag);
use needle;
use autotest ();
use commands;
use distribution;
use testapi ();
Expand Down Expand Up @@ -150,6 +151,7 @@ for my $arg (@ARGV) {

my $cmd_srv_process;
my $command_handler;
my $testprocess;
my $cmd_srv_fd;
my $cmd_srv_port;

Expand Down Expand Up @@ -186,6 +188,15 @@ sub stop_commands ($reason) {
diag('done with command server');
}

sub stop_autotest () {
return unless defined $testprocess;

diag('stopping autotest process ' . $testprocess->pid);
$testprocess->stop() if $testprocess->is_running;
$testprocess = undef;
diag('done with autotest process');
}

# make sure all commands coming from the backend will not be in the
# developers's locale - but a defined english one. This is SUSE's
# default locale
Expand Down Expand Up @@ -228,23 +239,34 @@ testapi::init();
needle::init();
bmwqemu::save_vars();

my $testfd;
($testprocess, $testfd) = autotest::start_process();

$backend = OpenQA::Isotovideo::Backend->new;

spawn_debuggers;

# stop main loop as soon as one of the child processes terminates
my $stop_loop = sub (@) { $command_handler->loop(0) if $command_handler->loop; };
$testprocess->once(collected => $stop_loop);
$backend->process->once(collected => $stop_loop);
$cmd_srv_process->once(collected => $stop_loop);

$command_handler = OpenQA::Isotovideo::CommandHandler->new(
cmd_srv_fd => $cmd_srv_fd,
test_fd => $testfd,
backend_fd => $backend->process->channel_in,
backend_out_fd => $backend->process->channel_out,
);
$command_handler->on(tests_done => sub (@) {
CORE::close($testfd);
$testfd = undef;
stop_autotest;
});
$command_handler->on(signal => sub ($event, $sig) {
$backend->stop if defined $backend; # uncoverable statement
stop_commands("received signal $sig"); # uncoverable statement
stop_autotest; # uncoverable statement
_exit(1); # uncoverable statement
});
$command_handler->setup_signal_handler;
Expand All @@ -257,10 +279,10 @@ $command_handler->run;
# terminate/kill the command server and let it inform its websocket clients before
stop_commands('test execution ended');

if ($command_handler->test_fd) {
if ($testfd) {
$return_code = 1; # unusual shutdown
CORE::close($command_handler->test_fd); # uncoverable statement
$command_handler->stop_autotest; # uncoverable statement
CORE::close $testfd;
stop_autotest;
}

diag 'isotovideo ' . ($return_code ? 'failed' : 'done');
Expand Down Expand Up @@ -291,7 +313,7 @@ $fatal_error = undef;
END {
$backend->stop if defined $backend;
stop_commands('test execution ended through exception');
$command_handler->stop_autotest if defined $command_handler;
stop_autotest;

# in case of early exit, e.g. help display
$return_code //= 0;
Expand Down
1 change: 1 addition & 0 deletions t/19-isotovideo-command-processing.t
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ subtest signalhandler => sub {
subtest 'No readable JSON' => sub {
# We need valid fd's so fileno works but they're never used
open(my $readable, "$Bin");
$command_handler->test_fd($readable);
$command_handler->cmd_srv_fd($readable);
stderr_like {
$command_handler->_read_response(undef, $readable);
Expand Down

0 comments on commit dee0e60

Please sign in to comment.