Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing settings only for specific test when cloning jobs #5385

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/OpenQA/Script/CloneJob.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ sub clone_job_apply_settings ($argv, $depth, $settings, $options) {

for my $arg (@$argv) {
# split arg into key and value
unless ($arg =~ /([A-Z0-9_]+\+?)=(.*)/) {
warn "arg '$arg' does not match";
unless ($arg =~ /([A-Z0-9_]+)(:(\w+))?(\+)?=(.*)/) {
warn "command-line argument '$arg' is no valid setting and will be ignored\n";
next;
}
my ($key, $value) = ($1, $2);

next unless is_global_setting($key) || $depth <= 1 || $options->{'parental-inheritance'};
my ($key, $scope, $plus, $value) = ($1, $3, $4, $5);
next if defined $scope && ($settings->{TEST} // '') ne $scope;
next if !defined $scope && !is_global_setting($key) && $depth > 1 && !$options->{'parental-inheritance'};

# delete key if value empty
if (!defined $value || $value eq '') {
Expand All @@ -54,10 +54,7 @@ sub clone_job_apply_settings ($argv, $depth, $settings, $options) {
}

# allow appending via `+=`
if (substr($key, -1) eq '+') {
$key = substr $key, 0, -1;
$value = ($settings->{$key} // '') . $value;
}
$value = ($settings->{$key} // '') . $value if $plus;

# assign value to key, delete overrides
$settings->{$key} = $value;
Expand Down
10 changes: 8 additions & 2 deletions script/openqa-clone-job
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,14 @@ this:
Any parent jobs (chained or parallel) are also cloned unless C<--skip-deps> or
C<--skip-chained-deps> is specified. If C<--skip-chained-deps> is specified
published assets generated by parent jobs are downloaded to be directly used
instead of generated. Keep in mind that by default any additionally specified
job settings are NOT added to the also cloned parent jobs.
instead of generated.

Keep in mind that by default any additionally specified job settings are NOT
added to the also cloned parent jobs. Specify C<--parental-inheritance> if this
is wanted. It is also possible to specify the job a setting should be added to
explicitly, e.g. C<WORKER_CLASS:create_hpc=special-worker>. In this example the
setting "WORKER_CLASS" will only be set to the specified value for jobs where
the setting "TEST" equals "create_hpc".

Note that the child job is the one which has the "START_AFTER_TEST" or
"PARALLEL_WITH" setting and the parent job is the one mentioned by that setting.
Expand Down
9 changes: 6 additions & 3 deletions t/35-script_clone_job.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later

use Test::Most;
use Test::Warnings ':report_warnings';
use Test::Warnings qw(:report_warnings warning);

use FindBin;
use lib "$FindBin::Bin/lib", "$FindBin::Bin/../external/os-autoinst-common/lib";
Expand Down Expand Up @@ -41,7 +41,7 @@ use Mojo::Transaction;
}
}

my @argv = qw(WORKER_CLASS=local HDD_1=new.qcow2 HDDSIZEGB=40);
my @argv = qw(WORKER_CLASS=local HDD_1=new.qcow2 HDDSIZEGB=40 WORKER_CLASS:create_hpc+=-parent);
my %options = ('parental-inheritance' => '');
my %child_settings = (
NAME => '00000810-sle-15-Installer-DVD-x86_64-Build665.2-hpc_test@64bit',
Expand All @@ -68,10 +68,13 @@ subtest 'clone job apply settings tests' => sub {
is_deeply(\%child_settings, \%test_settings, 'cloned child job with correct global setting and new settings');

%test_settings = %parent_settings;
$test_settings{WORKER_CLASS} = 'local';
$test_settings{WORKER_CLASS} = 'local-parent';
delete $test_settings{NAME};
clone_job_apply_settings(\@argv, 2, \%parent_settings, \%options);
is_deeply(\%parent_settings, \%test_settings, 'cloned parent job only take global setting');

like warning { clone_job_apply_settings(['foo'], 1, \%child_settings, \%options) },
qr/no valid setting/, 'warning when argument is no valid setting';
};

subtest '_GROUP and _GROUP_ID override each other' => sub {
Expand Down
Loading