Skip to content

Commit 3bbd34a

Browse files
committed
Fix enqueueing of Minion jobs breaking PARALLEL_ONE_HOST_ONLY=1
When restarting openQA jobs, additional Minion jobs are enqueued (of `git_clone` task, this is happening especially often when `git_auto_clone` is enabled). So far this didn't happen in a transaction. So the scheduler might see the openQA jobs but not the Minion jobs they are blocked by. This is problematic because the scheduler might assign jobs too soon to a worker. This is especially problematic if it does not happen consistently across a parallel job cluster as it then breaks the `PARALLEL_ONE_HOST_ONLY=1` feature. Related ticket: https://progress.opensuse.org/issues/169342
1 parent 6edeaf9 commit 3bbd34a

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

lib/OpenQA/Resource/Jobs.pm

-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use Mojo::Base -strict, -signatures;
77

88
use OpenQA::Jobs::Constants;
99
use OpenQA::Schema;
10-
use OpenQA::Utils qw(create_git_clone_list);
1110
use Exporter 'import';
1211

1312
our @EXPORT_OK = qw(job_restart);
@@ -50,8 +49,6 @@ sub job_restart ($jobids, %args) {
5049
my $jobs_rs = $schema->resultset('Jobs');
5150
my $jobs = $jobs_rs->search({id => $jobids, state => {'not in' => [PRISTINE_STATES]}});
5251
$duplication_args{no_directly_chained_parent} = 1 unless $force;
53-
my %clones;
54-
my @clone_ids;
5552
while (my $job = $jobs->next) {
5653
my $job_id = $job->id;
5754
my $missing_assets = $job->missing_assets;
@@ -76,18 +73,15 @@ sub job_restart ($jobids, %args) {
7673

7774
my $cloned_job_or_error = $job->auto_duplicate(\%duplication_args);
7875
if (ref $cloned_job_or_error) {
79-
create_git_clone_list($job->settings_hash, \%clones);
8076
push @duplicates, $cloned_job_or_error->{cluster_cloned};
8177
push @comments, @{$cloned_job_or_error->{comments_created}};
82-
push @clone_ids, $cloned_job_or_error->{cluster_cloned}->{$job_id};
8378
}
8479
else {
8580
$res{enforceable} = 1 if index($cloned_job_or_error, 'Direct parent ') == 0;
8681
push @errors, ($cloned_job_or_error // "An internal error occurred when duplicating $job_id");
8782
}
8883
push @processed, $job_id;
8984
}
90-
OpenQA::App->singleton->gru->enqueue_git_clones(\%clones, \@clone_ids) if keys %clones;
9185

9286
# abort running jobs
9387
return \%res if $args{skip_aborting_jobs};

lib/OpenQA/Schema/Result/Jobs.pm

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use DateTime;
1111
use OpenQA::Constants qw(WORKER_COMMAND_ABORT WORKER_COMMAND_CANCEL);
1212
use OpenQA::Log qw(log_trace log_debug log_info log_warning log_error);
1313
use OpenQA::Utils (
14-
qw(parse_assets_from_settings locate_asset),
14+
qw(create_git_clone_list parse_assets_from_settings locate_asset),
1515
qw(resultdir assetdir read_test_modules find_bugref random_string),
1616
qw(run_cmd_with_log_return_error needledir testcasedir gitrepodir find_video_files)
1717
);
@@ -693,18 +693,25 @@ sub _create_clones ($self, $jobs, $comments, $comment_text, $comment_user_id, @c
693693
$res->register_assets_from_settings;
694694
}
695695

696+
my %git_clones;
697+
my @clone_ids;
696698
for my $original_job_id (@original_job_ids) {
697699
my $cloned_job = $clones{$original_job_id};
698700
# calculate blocked_by
699701
$cloned_job->calculate_blocked_by;
700702
# add a reference to the clone within $jobs
701-
$jobs->{$original_job_id}->{clone} = $cloned_job->id;
703+
push @clone_ids, $jobs->{$original_job_id}->{clone} = $cloned_job->id;
704+
# add Git repositories to clone
705+
create_git_clone_list($cloned_job->settings_hash, \%git_clones);
702706
}
703707

704708
# create comments on original jobs
705709
$result_source->schema->resultset('Comments')
706710
->create_for_jobs(\@original_job_ids, $comment_text, $comment_user_id, $comments)
707711
if defined $comment_text;
712+
713+
# enqueue Minion jobs to clone required Git repositories
714+
OpenQA::App->singleton->gru->enqueue_git_clones(\%clones, \@clone_ids);
708715
}
709716

710717
# internal (recursive) function for duplicate - returns hash of all jobs in the

lib/OpenQA/Shared/Plugin/Gru.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ sub enqueue_git_update_all ($self) {
249249
}
250250

251251
sub enqueue_git_clones ($self, $clones, $job_ids) {
252-
return unless %$clones;
252+
return unless keys %$clones;
253253
return unless OpenQA::App->singleton->config->{'scm git'}->{git_auto_clone} eq 'yes';
254254
# $clones is a hashref with paths as keys and git urls as values
255255
# $job_id is used to create entries in a related table (gru_dependencies)

t/api/04-jobs.t

+3-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ $ENV{MOJO_MAX_MESSAGE_SIZE} = 207741824;
6262

6363
my $t = client(Test::Mojo->new('OpenQA::WebAPI'));
6464
my $cfg = $t->app->config;
65+
$cfg->{'scm git'}->{git_auto_clone} = 'no';
6566
$cfg->{'scm git'}->{git_auto_update} = 'no';
6667
is $cfg->{audit}->{blocklist}, 'job_grab', 'blocklist updated';
6768

@@ -1614,7 +1615,7 @@ subtest 'handle FOO_URL' => sub {
16141615
};
16151616

16161617
subtest 'handle git_clone with CASEDIR' => sub {
1617-
OpenQA::App->singleton->config->{'scm git'}->{git_auto_clone} = 'yes';
1618+
$cfg->{'scm git'}->{git_auto_clone} = 'yes';
16181619
$testsuites->create(
16191620
{
16201621
name => 'handle_foo_casedir',
@@ -1645,7 +1646,7 @@ subtest 'handle git_clone with CASEDIR' => sub {
16451646
};
16461647

16471648
subtest 'handle git_clone without CASEDIR' => sub {
1648-
OpenQA::App->singleton->config->{'scm git'}->{git_auto_update} = 'yes';
1649+
$cfg->{'scm git'}->{git_auto_update} = 'yes';
16491650
$testsuites->create(
16501651
{
16511652
name => 'handle_git_clone',

0 commit comments

Comments
 (0)