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

preprocess hdd image names #432

Merged
merged 4 commits into from Sep 17, 2015
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/GettingStarted.asciidoc
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
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
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
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
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