make fetch-db-data
make get-template ID=1
perl generate-scenario.pl 1
-
-
Save perlpunk/f9022ce90f6dc1507a2b6afe61fcfbd7 to your computer and use it in GitHub Desktop.
openqa scenarios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use v5.10; | |
use YAML::PP; | |
use JSON::PP; | |
my $yp = YAML::PP->new; | |
use YAML::PP::Common qw/ :PRESERVE /; | |
my $yp_preserve = YAML::PP->new( | |
preserve => PRESERVE_ORDER | PRESERVE_SCALAR_STYLE | PRESERVE_FLOW_STYLE | PRESERVE_ALIAS, | |
indent => 2, | |
); | |
use Data::Dumper; | |
exit 1 unless @ARGV; | |
main(@ARGV); | |
sub main { | |
my ($group_id) = @_; | |
my $ts_list = $yp->load_file("testsuites.json")->{TestSuites}; | |
my $ma_list = $yp->load_file("machines.json")->{Machines}; | |
my $jg = $yp_preserve->load_file("job-group-$group_id.yaml"); | |
my $scenarios = $yp_preserve->preserved_mapping({}); | |
my $sc = $jg->{scenarios}; | |
my $all_defaults = $jg->{defaults}; | |
my $all_ts = {}; | |
for my $item (@$ts_list) { | |
delete $item->{id}; | |
delete $item->{description}; | |
my $settings_list = delete $item->{settings}; | |
my $name = delete $item->{name}; | |
my $settings = settings_list_to_hash($settings_list); | |
$item->{settings} = $settings; | |
$all_ts->{ $name } = $item; | |
} | |
my $all_ma = {}; | |
for my $machine (@$ma_list) { | |
$machine->{settings} = settings_list_to_hash($machine->{settings}); | |
my $name = delete $machine->{name}; | |
delete $machine->{id}; | |
$all_ma->{ $name } = $machine; | |
} | |
my %ts; | |
my %ma; | |
my $templates = $yp_preserve->preserved_mapping({}); | |
for my $arch (keys %$sc) { | |
$templates->{ $arch } = $yp_preserve->preserved_mapping({}); | |
warn __PACKAGE__.':'.__LINE__.": ===================== $arch\n"; | |
my $defaults = $all_defaults->{ $arch } || {}; | |
my $products = $sc->{ $arch }; | |
for my $pr (keys %$products) { | |
$templates->{ $arch }->{ $pr } = $yp_preserve->preserved_mapping({}); | |
warn __PACKAGE__.':'.__LINE__.": ========= $pr\n"; | |
my $tests = $products->{ $pr }; | |
for my $i (0..$#$tests) { | |
my $test = $tests->[$i]; | |
my $ref = ref $test; | |
my $machine = $defaults->{machine}; | |
my $testname; | |
my $suite; | |
my %template; | |
my $def = {}; | |
if (not ref $test eq 'HASH') { | |
$testname = $test; | |
$suite = $all_ts->{ $test }; | |
$ts{ $test } ||= $suite; | |
$ma{ $machine } ||= $all_ma->{ $machine }; | |
$templates->{ $arch }->{ $pr }->{ $testname } = {}; | |
} | |
elsif (ref $test eq 'HASH') { | |
(my $name, $def) = %$test; | |
if (my $merge = $def->{"<<"}) { | |
$machine = $merge->{machine} if $merge->{machine}; | |
$def->{testsuite} = $merge->{testsuite} if exists $merge->{testsuite}; | |
} | |
$machine = $def->{machine} if $def->{machine}; | |
my $test_machine = ref $machine eq 'ARRAY' ? '(' . join(',', @$machine) . ')' : $machine; | |
if (not exists $def->{testsuite}) { | |
$testname = "$name"; | |
$suite = $all_ts->{ $name }; | |
$ts{ $name } ||= $suite; | |
} | |
elsif ($def->{testsuite}) { | |
$testname = "\$$name"; | |
$suite = $all_ts->{ $def->{testsuite} }; | |
$ts{ $def->{testsuite} } ||= $suite; | |
} | |
else { | |
$testname = "\$$name"; | |
} | |
$testname .= '@' . $test_machine unless $test_machine eq $defaults->{machine}; | |
if (ref $machine eq 'ARRAY') { | |
$ma{ $_ } ||= $all_ma->{ $_ } for @$machine; | |
} | |
else { | |
$ma{ $machine } ||= $all_ma->{ $machine }; | |
} | |
$templates->{ $arch }->{ $pr }->{ $testname } = $def; | |
} | |
} | |
} | |
} | |
$yp->dump_file("testsuites-$group_id.yaml", { testsuites => \%ts }); | |
$yp->dump_file("machines-$group_id.yaml", { machines => \%ma }); | |
my $group_products = $jg->{products}; | |
my $pr_list = $yp->load_file("products.json")->{Products}; | |
my %products; | |
for my $product (@$pr_list) { | |
$product->{settings} = settings_list_to_hash($product->{settings}); | |
my $arch = $product->{arch} // '*'; | |
my $str = "$product->{distri}-$product->{version}-$product->{flavor}-$arch"; | |
next unless $group_products->{ $str }; | |
$products{ $str } = $product; | |
} | |
$yp->dump_file("products-$group_id.yaml", { products => \%products }); | |
# Remove keys not needed anymore | |
for my $arch (keys %$templates) { | |
my $products = $templates->{ $arch }; | |
for my $product (keys %$products) { | |
my $tests = $products->{ $product }; | |
for my $testname (sort keys %$tests) { | |
my $test = $tests->{ $testname }; | |
ref $test eq 'HASH' or next; | |
delete $test->{machine}; | |
delete $test->{testsuite} if exists $test->{testsuite} && not $test->{testsuite}; | |
} | |
} | |
} | |
$scenarios->{defaults} = $all_defaults; | |
$scenarios->{job_templates} = $templates; | |
my $yaml = $yp_preserve->dump_string($scenarios); | |
# Comment out for easier comparison to existing job group definition | |
# $yaml =~ s/^(?= +machine: )/# /mg; | |
# $yaml =~ s/^(?= +testsuite: null)/# /mg; | |
open my $fh, '>:encoding(UTF-8)', "scenario-$group_id.yaml"; | |
print $fh $yaml; | |
close $fh; | |
} | |
sub settings_list_to_hash { | |
my ($list) = @_; | |
my %settings; | |
for my $set (@$list) { | |
my $key = $set->{key}; | |
my $val = $set->{value}; | |
$settings{ $key } = $val; | |
} | |
return \%settings; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fetch-db-data: | |
openqa-cli api --o3 test_suites | jq . >testsuites.json | |
openqa-cli api --o3 products | jq . >products.json | |
openqa-cli api --o3 machines | jq . >machines.json | |
get-template: | |
openqa-cli api --o3 job_templates_scheduling/$$ID | jq . -r >job-group-$$ID.yaml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment