Skip to content

Commit

Permalink
Add repeat parameter to clone a job multiple times
Browse files Browse the repository at this point in the history
to better support statistical investigation, we want to provide an
immediate way to clone a job multiple times. Till now it has been done
with a for loop similar to

for i in {01..50}; do openqa-clone-job … TEST+=-$i; done

But we can avoid the API overhead of copying the same parameters and
assets again and again from the original job, simply by cloning it once and
posting the new job(s) N times. TEST name is automatically numbered, so the
user is not forced to remember any shell syntax.

As the default is --repeat=1, the API remains compatible with any shell
script using the openqa-clone-job program.
  • Loading branch information
ilmanzo committed Oct 16, 2023
1 parent f46075b commit d4fddec
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
19 changes: 19 additions & 0 deletions docs/UsersGuide.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,25 @@ timeouts by performing the task in background.
This is recommended on big instances but means that the results (and
possible errors) need to be polled via `openqa-cli api isos/$scheduled_product_id`.


===== Statistical investigation =====
In case issues appear sporadically and are therefore hard to reproduce it can
help to trigger many more jobs on a production instance to gather more data
first, for example the failure ratio.

Example of triggering 50 jobs in a development group so that the result of
passed/failed jobs is counted by openQA itself on the corresponding overview page:
[source,sh]
--------------------------------------------------------------------------------
openqa-clone-job --skip-chained-deps --repeat=50 --within-instance \
https://openqa.opensuse.org 123456 BUILD=poo32242_investigation \
_GROUP="Test Development:openSUSE Tumbleweed"
--------------------------------------------------------------------------------

To get an overview about the fail ratio and confidence interval of sporadically
failing applications you can also use a script like
https://github.com/okurz/scripts/blob/master/count_fail_ratio[this].

[id="scenarios_yaml"]
===== Defining test scenarios in YAML =====
Instead of relying on the tables for machines, mediums/products, test suites and
Expand Down
25 changes: 23 additions & 2 deletions lib/OpenQA/Script/CloneJob.pm
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,32 @@ sub handle_tx ($tx, $url_handler, $options, $jobs) {
}
}

# append a formatted "-NN" to the TEST parameter
sub append_idx_to_test_name ($n, $post_params) {
my $number_suffix = sprintf("-%03d", $n);
foreach my $job_key (keys %$post_params) {
my $job = $post_params->{$job_key};
my $test_name = $job->{TEST};
if ($n == 1) {
$test_name .= $number_suffix; # just append at the first time

Check warning on line 236 in lib/OpenQA/Script/CloneJob.pm

View check run for this annotation

Codecov / codecov/patch

lib/OpenQA/Script/CloneJob.pm#L230-L236

Added lines #L230 - L236 were not covered by tests
}
else {
# from the second onwards, replace the suffix
substr($test_name, -length($number_suffix)) = $number_suffix;

Check warning on line 240 in lib/OpenQA/Script/CloneJob.pm

View check run for this annotation

Codecov / codecov/patch

lib/OpenQA/Script/CloneJob.pm#L240

Added line #L240 was not covered by tests
}
$job->{TEST} = $test_name;

Check warning on line 242 in lib/OpenQA/Script/CloneJob.pm

View check run for this annotation

Codecov / codecov/patch

lib/OpenQA/Script/CloneJob.pm#L242

Added line #L242 was not covered by tests
}
}

sub clone_jobs ($jobid, $options) {
my $url_handler = create_url_handler($options);
my $repeat = delete $options->{'repeat'} || 1;
clone_job($jobid, $url_handler, $options, my $post_params = {}, my $jobs = {});
my $tx = post_jobs($post_params, $url_handler, $options);
handle_tx($tx, $url_handler, $options, $jobs) if $tx;
for my $counter (1 .. $repeat) {
append_idx_to_test_name($counter, $post_params) if $repeat > 1;
my $tx = post_jobs($post_params, $url_handler, $options);
handle_tx($tx, $url_handler, $options, $jobs) if $tx;
}
}

sub clone_job ($jobid, $url_handler, $options, $post_params = {}, $jobs = {}, $depth = 1, $relation = '') {
Expand Down
8 changes: 7 additions & 1 deletion script/openqa-clone-job
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ are cloned. Use C<0> to denote infinity.
A shortcut for C<--skip-download --from HOST --host HOST> to clone a job within
a local or remote instance.
=item B<--repeat> N
Do the same operation N times. Allowed values are from 1 to 999
=item B<--show-progress>
Displays a progress bar when downloading assets.
Expand Down Expand Up @@ -190,7 +194,7 @@ sub parse_options () {
"apikey:s", "apisecret:s", "verbose|v", "json-output|j",
"skip-deps", "skip-chained-deps", "skip-download", "parental-inheritance",
"help|h", "show-progress", "within-instance|w=s", "clone-children",
"max-depth:i", "ignore-missing-assets", "export-command",
"max-depth:i", "repeat|r:i", "ignore-missing-assets", "export-command",
) or usage(1);
usage(0) if $options{help};
usage(1) if $options{help} || ($options{'within-instance'} && $options{from});
Expand All @@ -207,6 +211,8 @@ sub parse_options () {
die "missing job reference, see --help for usage\n" unless $jobid;
($options{'from'}, $jobid) = split_jobid($jobid) unless $options{'from'};
usage(1) unless ($jobid && $options{'from'});
$options{'repeat'} ||= 1;
die "invalid repeat count, should be between 1 and 999" if ($options{'repeat'} < 1 or $options{'repeat'} > 999);
$options{'dir'} ||= assetdir();
$options{'host'} ||= 'localhost';
$options{'args'} = \@ARGV;
Expand Down

0 comments on commit d4fddec

Please sign in to comment.