Skip to content

Commit

Permalink
Merge pull request #3726 from os-autoinst/k/mojo_9
Browse files Browse the repository at this point in the history
  • Loading branch information
okurz committed Feb 17, 2021
2 parents fa28c15 + 20d219d commit 91dd770
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .circleci/ci-packages.txt
Expand Up @@ -140,7 +140,7 @@ perl-Module-Pluggable-5.2
perl-Module-Runtime-0.016
perl-Module-Runtime-Conflicts-0.003
perl-Mojo-IOLoop-ReadWriteProcess-0.28
perl-Mojolicious-8.73
perl-Mojolicious-9.01
perl-Mojolicious-Plugin-AssetPack-2.10
perl-Mojolicious-Plugin-OAuth2-1.58
perl-Mojo-Pg-4.24
Expand Down
27 changes: 7 additions & 20 deletions lib/OpenQA/Log.pm
Expand Up @@ -44,9 +44,6 @@ our @EXPORT_OK = qw(
my %CHANNELS;
my %LOG_DEFAULTS = (LOG_TO_STANDARD_CHANNEL => 1, CHANNELS => []);

my $log_module = "Mojo::Log";
eval 'use Mojo::Log::Colored; $log_module = "Mojo::Log::Colored"';

# logging helpers - _log_msg wrappers

# log_debug("message"[, param1=>val1, param2=>val2]);
Expand Down Expand Up @@ -170,7 +167,7 @@ sub add_log_channel {
}
delete $options{default};
}
$CHANNELS{$channel} = $log_module->new(%options);
$CHANNELS{$channel} = Mojo::Log->new(%options);
$CHANNELS{$channel}->format(\&log_format_callback);
}

Expand All @@ -181,7 +178,7 @@ sub log_format_callback {
$time = gettimeofday;
return
sprintf(strftime("[%FT%T.%%04d %Z] [$level] ", localtime($time)), 1000 * ($time - int($time)))
. join("\n", @lines, '');
. join(' ', @lines) . "\n";
}

# Removes a channel from defaults.
Expand Down Expand Up @@ -219,32 +216,22 @@ sub setup_log {
$level //= $app->config->{logging}->{level} // 'info';
$logfile = $ENV{OPENQA_LOGFILE} || $app->config->{logging}->{file};

# select a color selection that is compatible with reverse video terminals
# as well as standard
my %settings = (
level => $level,
colors => {
debug => "white",
info => "yellow",
warn => "red",
error => "magenta",
fatal => "yellow on_red",
});
my %settings = (level => $level);

if ($logfile || $logdir) {
$logfile = catfile($logdir, $logfile) if $logfile && $logdir;
# So each worker from each host get its own log (as the folder can be shared).
# Hopefully the machine hostname is already sanitized. Otherwise we need to check
$logfile //= catfile($logdir, hostname() . (defined $app->instance ? "-${\$app->instance}" : '') . ".log");
$log = $log_module->new(%settings, handle => path($logfile)->open('>>'));
$log = Mojo::Log->new(%settings, handle => path($logfile)->open('>>'));
$log->format(\&log_format_callback);
}
else {
$log = $log_module->new(%settings, handle => \*STDOUT);
$log = Mojo::Log->new(%settings, handle => \*STDOUT);
$log->format(
sub {
my ($time, $level, @lines) = @_;
return "[$level] " . join "\n", @lines, '';
my ($time, $level, @parts) = @_;
return "[$level] " . join(' ', @parts) . "\n";
});
}

Expand Down
4 changes: 2 additions & 2 deletions lib/OpenQA/WebAPI.pm
Expand Up @@ -128,7 +128,7 @@ sub startup ($self) {
$apik_auth->post('/')->to('api_key#create');
$apik_auth->delete('/:apikeyid')->name('api_key')->to('api_key#destroy');

$r->get('/search')->name('search')->to('search#search');
$r->get('/search')->name('search')->to(template => 'search/search');

$r->get('/tests')->name('tests')->to('test#list');
$r->get('/tests/overview')->name('tests_overview')->to('test#overview');
Expand Down Expand Up @@ -358,7 +358,7 @@ sub startup ($self) {
# api/v1/mm
my $mm_api = $api_r_job->any('/mm');
push @api_routes, $mm_api;
$mm_api->get('/children/:status' => [status => [qw(running scheduled done)]])->name('apiv1_mm_running_children')
$mm_api->get('/children/:state' => [state => [qw(running scheduled done)]])->name('apiv1_mm_running_children')
->to('mm#get_children_status');
$mm_api->get('/children')->name('apiv1_mm_children')->to('mm#get_children');
$mm_api->get('/parents')->name('apiv1_mm_parents')->to('mm#get_parents');
Expand Down
14 changes: 7 additions & 7 deletions lib/OpenQA/WebAPI/Controller/API/V1/Mm.pm
Expand Up @@ -52,20 +52,20 @@ JSON block with the list.
# IMHO it should be replaced with get_children and removed
sub get_children_status {
my ($self) = @_;
my $status = $self->stash('status');
if ($status eq 'running') {
$status = OpenQA::Jobs::Constants::RUNNING;
my $state = $self->stash('state');
if ($state eq 'running') {
$state = OpenQA::Jobs::Constants::RUNNING;
}
elsif ($status eq 'scheduled') {
$status = OpenQA::Jobs::Constants::SCHEDULED;
elsif ($state eq 'scheduled') {
$state = OpenQA::Jobs::Constants::SCHEDULED;
}
else {
$status = OpenQA::Jobs::Constants::DONE;
$state = OpenQA::Jobs::Constants::DONE;
}
my $jobid = $self->stash('job_id');

my @res = $self->schema->resultset('Jobs')
->search({'parents.parent_job_id' => $jobid, state => $status}, {columns => ['id'], join => 'parents'});
->search({'parents.parent_job_id' => $jobid, state => $state}, {columns => ['id'], join => 'parents'});
my @res_ids = map { $_->id } @res;
return $self->render(json => {jobs => \@res_ids}, status => 200);
}
Expand Down
12 changes: 6 additions & 6 deletions t/26-controllerrunning.t
Expand Up @@ -26,6 +26,7 @@ use OpenQA::Jobs::Constants;
use Mojolicious;
use Mojo::File 'path';
use Mojo::IOLoop;
use Mojo::Promise;

my $log_messages = '';

Expand All @@ -41,17 +42,16 @@ subtest streamtext => sub {
$buffer .= $chunk; # uncoverable statement
});
});
my $port = Mojo::IOLoop->acceptor($id)->port;
my $delay = Mojo::IOLoop->delay;
my $end = $delay->begin;
my $handle = undef;
my $port = Mojo::IOLoop->acceptor($id)->port;
my $promise = Mojo::Promise->new;
my $handle = undef;
Mojo::IOLoop->client(
{port => $port} => sub {
my ($loop, $err, $stream) = @_;
$handle = $stream->steal_handle;
$end->();
$promise->resolve;
});
$delay->wait;
$promise->wait;

my $stream = Mojo::IOLoop::Stream->new($handle);
$id = Mojo::IOLoop->stream($stream);
Expand Down
17 changes: 10 additions & 7 deletions t/ui/27-plugin_obs_rsync_status_details.t
Expand Up @@ -134,13 +134,14 @@ sub _wait_helper {
sleep .1; # uncoverable statement
}
# sometimes gru is not fast enough, so let's refresh the page and see if that helped
if($refresh) { # uncoverable statement
if ($refresh) { # uncoverable statement
$refresh->(); # uncoverable statement
} else {
}
else {
$driver->refresh(); # uncoverable statement
}
}
return $driver->find_element($element)->get_text(); # uncoverable statement
return $driver->find_element($element)->get_text(); # uncoverable statement
}

foreach my $proj (sort keys %params) {
Expand Down Expand Up @@ -176,12 +177,14 @@ foreach my $proj (sort keys %params) {
$builds_text = ($builds_text ? $builds_text : 'No data');
# now request fetching builds from obs
$driver->find_element("tr#folder_$ident .obsbuildsupdate")->click();
my $obsbuilds = _wait_helper("tr#folder_$ident .obsbuilds", sub {
my $obsbuilds = _wait_helper(
"tr#folder_$ident .obsbuilds",
sub {
shift eq $builds_text;
}, sub {
},
sub {
$driver->find_element("tr#folder_$ident .obsbuildsupdate")->click();
}
);
});
is($obsbuilds, $builds_text, "$proj obs builds");

if ($dt ne 'no data') {
Expand Down

0 comments on commit 91dd770

Please sign in to comment.