Skip to content

Commit

Permalink
Merge pull request #432 from nadvornik/hdd_names
Browse files Browse the repository at this point in the history
preprocess hdd image names
  • Loading branch information
Ondřej Holeček committed Sep 17, 2015
2 parents 54a0737 + 2ecd975 commit fa73930
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
19 changes: 19 additions & 0 deletions docs/GettingStarted.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,25 @@ Few important examples:
emulated USB stick.
** +SMP+ enables smp when set to 1, disables when set to 0.

Variable expansion
~~~~~~~~~~~~~~~~~~
Any variable defined in Test Suite, Machine or Product table can refer to another
variable using this syntax: %NAME%

For example this variable defined for Test Suite:

[source,sh]
--------------------------------------------------------------------------------
PUBLISH_HDD_1 = %DISTRI%-%VERSION%-%ARCH%-%DESKTOP%.qcow2
--------------------------------------------------------------------------------

is expanded to this job variable:

[source,sh]
--------------------------------------------------------------------------------
PUBLISH_HDD_1 = opensuse-13.1-i586-kde.qcow2
--------------------------------------------------------------------------------

Testing openSUSE
----------------
Expand Down
19 changes: 19 additions & 0 deletions lib/OpenQA/Scheduler/Scheduler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,25 @@ sub _generate_jobs {
$settings{PRIO} = $job_template->prio;
$settings{GROUP_ID} = $job_template->group_id;

# variable expansion
# replace %NAME% with $settings{NAME}
my $expanded;
do {
$expanded = 0;
for my $var (keys %settings) {
if ((my $val = $settings{$var}) =~ /(%\w+%)/) {
my $replace_var = $1;
$replace_var =~ s/^%(\w+)%$/$1/;
my $replace_val = $settings{$replace_var};
next unless defined $replace_val;
$replace_val = '' if $replace_var eq $var; #stop infinite recursion
$val =~ s/%${replace_var}%/$replace_val/g;
$settings{$var} = $val;
$expanded = 1;
}
}
} while ($expanded);

push @$ret, \%settings;
}
}
Expand Down
3 changes: 3 additions & 0 deletions t/api/02-iso.t
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ is_deeply($advanced_kde_64->{parents}, {Parallel => [], Chained => [$kde_64->{id
is($server_32->{group_id}, 1001, 'server_32 part of opensuse group');
is($server_64->{group_id}, 1001, 'server_64 part of opensuse group');

is($advanced_kde_32->{settings}->{PUBLISH_HDD_1}, 'opensuse-13.1-i586-kde-qemu32.qcow2', "variable expansion");
is($advanced_kde_64->{settings}->{PUBLISH_HDD_1}, 'opensuse-13.1-i586-kde-qemu64.qcow2', "variable expansion");

lj;

# check that the old tests are cancelled
Expand Down
4 changes: 4 additions & 0 deletions t/api/07-testsuites.t
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ is_deeply(
'key' => 'DESKTOP',
'value' => 'kde'
},
{
'key' => 'PUBLISH_HDD_1',
'value' => '%DISTRI%-%VERSION%-%ARCH%-%DESKTOP%-%QEMUCPU%.qcow2'
},
{
'key' => 'START_AFTER_TEST',
'value' => 'kde,textmode'
Expand Down
2 changes: 1 addition & 1 deletion t/fixtures/04-products.pl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
id => 1017,
name => "advanced_kde",
variables => '',
settings => [{ key => "DESKTOP", value => "kde" }, { key => "START_AFTER_TEST", value => "kde,textmode" }],
settings => [{ key => "DESKTOP", value => "kde" }, { key => "START_AFTER_TEST", value => "kde,textmode" }, { key => "PUBLISH_HDD_1", value => "%DISTRI%-%VERSION%-%ARCH%-%DESKTOP%-%QEMUCPU%.qcow2" }],
},
Products => {
name => '',
Expand Down

0 comments on commit fa73930

Please sign in to comment.