From 33337c27cb38ca1f16ee6d6912456772e87d1ef0 Mon Sep 17 00:00:00 2001 From: Oliver Kurz Date: Thu, 14 Mar 2024 09:46:36 +0100 Subject: [PATCH 1/5] Use signatures in Resource::Jobs --- lib/OpenQA/Resource/Jobs.pm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/OpenQA/Resource/Jobs.pm b/lib/OpenQA/Resource/Jobs.pm index fe97ef9b76a..e5bebf396bf 100644 --- a/lib/OpenQA/Resource/Jobs.pm +++ b/lib/OpenQA/Resource/Jobs.pm @@ -1,10 +1,9 @@ -# Copyright 2017-2020 SUSE LLC +# Copyright SUSE LLC # SPDX-License-Identifier: GPL-2.0-or-later package OpenQA::Resource::Jobs; -use strict; -use warnings; +use Mojo::Base -strict, -signatures; use OpenQA::Jobs::Constants; use OpenQA::Schema; @@ -26,8 +25,7 @@ Handle job restart by user (using API or WebUI). Job is only restarted when eith or done. Scheduled jobs can't be restarted. =cut -sub job_restart { - my ($jobids, %args) = @_; +sub job_restart ($jobids, %args) { my (@duplicates, @processed, @errors, @warnings); my %res = (duplicates => \@duplicates, errors => \@errors, warnings => \@warnings, enforceable => 0); unless (ref $jobids eq 'ARRAY' && @$jobids) { From 0bd2cde0cf040863ec0a6f4e1a5833335bd318c2 Mon Sep 17 00:00:00 2001 From: Oliver Kurz Date: Thu, 14 Mar 2024 09:46:50 +0100 Subject: [PATCH 2/5] Use signatures in WebAPI::ServerSideDataTable --- lib/OpenQA/WebAPI/ServerSideDataTable.pm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/OpenQA/WebAPI/ServerSideDataTable.pm b/lib/OpenQA/WebAPI/ServerSideDataTable.pm index c331d22e356..81de21d1d3f 100644 --- a/lib/OpenQA/WebAPI/ServerSideDataTable.pm +++ b/lib/OpenQA/WebAPI/ServerSideDataTable.pm @@ -3,11 +3,9 @@ package OpenQA::WebAPI::ServerSideDataTable; -use strict; -use warnings; +use Mojo::Base -strict, -signatures; -sub render_response { - my (%args) = @_; +sub render_response (%args) { # mandatory parameter my $controller = $args{controller}; my $resultset_name = $args{resultset}; From 334e3887499eeb94a410a17108ce3c9ec950ac57 Mon Sep 17 00:00:00 2001 From: Oliver Kurz Date: Thu, 14 Mar 2024 09:47:01 +0100 Subject: [PATCH 3/5] Slightly simplify script/openqa-validate-yaml --- script/openqa-validate-yaml | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/script/openqa-validate-yaml b/script/openqa-validate-yaml index 047a87b733b..f3cf7355217 100755 --- a/script/openqa-validate-yaml +++ b/script/openqa-validate-yaml @@ -43,18 +43,11 @@ EOM print($usage->text), exit if $opt->help; -my @files = @ARGV; +my @files = @ARGV or pass 'Nothing to do'; my $default_schema = "$RealBin/../public/schema/JobTemplates-01.yaml"; my $schema = $opt->schema_file // $default_schema; - -unless (@files) { - pass "Nothing to do"; -} - -if ($opt->validate_schema) { - diag 'Validating schema, too'; -} +diag 'Validating schema, too' if $opt->validate_schema; for my $file (@files) { my $data; if ($file eq '-') { From 454385eceb585b9d991001dbaf461092b3661333 Mon Sep 17 00:00:00 2001 From: Oliver Kurz Date: Thu, 14 Mar 2024 09:47:34 +0100 Subject: [PATCH 4/5] Use signatures in Resource::Locks --- lib/OpenQA/Resource/Locks.pm | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/OpenQA/Resource/Locks.pm b/lib/OpenQA/Resource/Locks.pm index 254935240b3..6160bfe3799 100644 --- a/lib/OpenQA/Resource/Locks.pm +++ b/lib/OpenQA/Resource/Locks.pm @@ -1,10 +1,9 @@ -# Copyright 2015-2019 SUSE LLC +# Copyright SUSE LLC # SPDX-License-Identifier: GPL-2.0-or-later package OpenQA::Resource::Locks; -use strict; -use warnings; +use Mojo::Base -strict, -signatures; use OpenQA::Jobs::Constants; use OpenQA::Schema; @@ -21,8 +20,7 @@ my %final_states = map { $_ => 1 } OpenQA::Jobs::Constants::NOT_OK_RESULTS(); # So we have to specify, which child job is supposed to create the lock # and watch it's state. # -sub _get_lock { - my ($name, $jobid, $where) = @_; +sub _get_lock ($name = undef, $jobid = undef, $where = undef) { return 0 unless defined $name && defined $jobid; my $schema = OpenQA::Schema->singleton; my $job = $schema->resultset('Jobs')->single({id => $jobid}); @@ -45,9 +43,7 @@ sub _get_lock { } # returns -1 on unrecoverable error, 1 on have lock, 0 on try later (lock unavailable) -sub lock { - my ($name, $jobid, $where) = @_; - +sub lock ($name, $jobid, $where) { my $lock = _get_lock($name, $jobid, $where); if (!$lock and $where =~ /^\d+$/) { @@ -70,8 +66,7 @@ sub lock { return 0; } -sub unlock { - my ($name, $jobid, $where) = @_; +sub unlock ($name, $jobid, $where = undef) { my $lock = _get_lock($name, $jobid, $where // 'all'); return 0 unless $lock; # return if not locked @@ -82,8 +77,7 @@ sub unlock { return 0; } -sub create { - my ($name, $jobid) = @_; +sub create ($name, $jobid) { my $lock = _get_lock($name, $jobid, 'all'); # nothing if lock already exist return 0 if $lock; @@ -99,8 +93,7 @@ sub create { ## Barriers # barriers are created with number of expected jobs. Then wait call waits until the expected number of jobs is waiting -sub barrier_create { - my ($name, $jobid, $expected_jobs) = @_; +sub barrier_create ($name = undef, $jobid = undef, $expected_jobs = undef) { return 0 unless $name && $jobid && $expected_jobs; my $barrier = _get_lock($name, $jobid, 'all'); return 0 if $barrier; @@ -111,9 +104,7 @@ sub barrier_create { return $barrier; } -sub barrier_wait { - my ($name, $jobid, $where, $check_dead_job) = @_; - +sub barrier_wait ($name = undef, $jobid = undef, $where = undef, $check_dead_job = 0) { return -1 unless $name && $jobid; return -1 unless my $barrier = _get_lock($name, $jobid, $where); @@ -142,8 +133,7 @@ sub barrier_wait { return 0; } -sub barrier_destroy { - my ($name, $jobid, $where) = @_; +sub barrier_destroy ($name = undef, $jobid = undef, $where = undef) { return 0 unless $name && $jobid; my $barrier = _get_lock($name, $jobid, $where); return 0 unless $barrier; From b295d477ee368d80cc81d18e26cef938f22e2d09 Mon Sep 17 00:00:00 2001 From: Oliver Kurz Date: Thu, 14 Mar 2024 09:47:52 +0100 Subject: [PATCH 5/5] Simplify Resource::Locks with direct return of booleans --- lib/OpenQA/Resource/Locks.pm | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/OpenQA/Resource/Locks.pm b/lib/OpenQA/Resource/Locks.pm index 6160bfe3799..afc0c2d7593 100644 --- a/lib/OpenQA/Resource/Locks.pm +++ b/lib/OpenQA/Resource/Locks.pm @@ -121,16 +121,12 @@ sub barrier_wait ($name = undef, $jobid = undef, $where = undef, $check_dead_job } } - if (grep { $_ eq $jobid } @jobs) { - return 1 if @jobs == $barrier->count; - return 0; - } + return @jobs == $barrier->count if grep { $_ eq $jobid } @jobs; push @jobs, $jobid; $barrier->update({locked_by => join(',', @jobs)}); - return 1 if @jobs == $barrier->count; - return 0; + return @jobs == $barrier->count; } sub barrier_destroy ($name = undef, $jobid = undef, $where = undef) {