diff --git a/lib/OpenQA/Script/CloneJob.pm b/lib/OpenQA/Script/CloneJob.pm index 1fd05807454..016a107db8c 100644 --- a/lib/OpenQA/Script/CloneJob.pm +++ b/lib/OpenQA/Script/CloneJob.pm @@ -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 '') { @@ -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; diff --git a/script/openqa-clone-job b/script/openqa-clone-job index 9cb149c7e3d..f11ae47b5f9 100755 --- a/script/openqa-clone-job +++ b/script/openqa-clone-job @@ -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. 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. diff --git a/t/35-script_clone_job.t b/t/35-script_clone_job.t index a6326a4cc1a..9f552fba3dd 100644 --- a/t/35-script_clone_job.t +++ b/t/35-script_clone_job.t @@ -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"; @@ -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', @@ -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 {