Skip to content

Commit

Permalink
Set the machine name before expanding specified variables
Browse files Browse the repository at this point in the history
When doing `isos post`, the machine name was added to the job settings
before expanding specified variables, so the %MACHINE% was not replaced
correctly.
  • Loading branch information
Amrysliu committed Apr 21, 2020
1 parent a990d8b commit e3d84d0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
29 changes: 29 additions & 0 deletions lib/OpenQA/JobSettings.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,35 @@ package OpenQA::JobSettings;
use strict;
use warnings;

sub generate_settings {
my ($params) = @_;
my $settings = $params->{settings};
my @worker_class;
for my $entity (qw (product machine test_suite job_template)) {
next unless $params->{$entity};
my @entity_settings = $params->{$entity}->settings;
for my $setting (@entity_settings) {
if ($setting->key eq 'WORKER_CLASS') {
push @worker_class, $setting->value;
next;
}
$settings->{$setting->key} = $setting->value;
}
}
$settings->{WORKER_CLASS} = join ',', sort @worker_class if @worker_class > 0;
if (my $input_args = $params->{input_args}) {
$settings->{uc $_} = $input_args->{$_} for keys %$input_args;
}

# Prevent the MACHINE was override by input args when doing isos post
if (my $machine = $params->{'machine'}) {
$settings->{BACKEND} = $machine->backend;
$settings->{MACHINE} = $machine->name;
}
handle_plus_in_settings($settings);
return expand_placeholders($settings);
}

# replace %NAME% with $settings{NAME}
sub expand_placeholders {
my ($settings) = @_;
Expand Down
2 changes: 0 additions & 2 deletions lib/OpenQA/Schema/Result/ScheduledProducts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,6 @@ sub _generate_jobs {

# add properties from dedicated database columns to settings
$settings{TEST} = $job_template->name || $job_template->test_suite->name;
$settings{MACHINE} = $job_template->machine->name;
$settings{BACKEND} = $job_template->machine->backend;
$settings{TEST_SUITE_NAME} = $job_template->test_suite->name;
$settings{JOB_DESCRIPTION} = $job_template->description if length $job_template->description;

Expand Down
26 changes: 24 additions & 2 deletions t/api/02-iso.t
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ use OpenQA::Client;
use OpenQA::Schema::Result::ScheduledProducts;
use Mojo::IOLoop;


OpenQA::Test::Case->new->init_data;

my $t = Test::Mojo->new('OpenQA::WebAPI');
Expand Down Expand Up @@ -470,7 +469,7 @@ sub add_opensuse_test {
my $not_add_test_suite = delete $settings{NOT_ADD_TESTSUITE};
my @mapped_settings;
for my $key (keys %settings) {
push(@mapped_settings, {key => $key, value => $settings{$key}});
push(@mapped_settings, {key => $key, value => $settings{$key}}) if $key ne 'MACHINE';
}
$t->app->schema->resultset('TestSuites')->create(
{
Expand Down Expand Up @@ -966,4 +965,27 @@ subtest 'PUBLISH and STORE variables cannot include slashes' => sub {
$schema->txn_rollback;
};

subtest 'Expand specified variables when scheduling iso' => sub {
$schema->txn_begin;
add_opensuse_test(
'test',
BUILD_HA => '%BUILD%',
BUILD_SDK => '%BUILD_HA%',
SHUTDOWN_NEEDS_AUTH => 1,
HDD_1 => '%DISTRI%-%VERSION%-%ARCH%-%BUILD_SDK%@%MACHINE%-minimal_with_sdk%BUILD_SDK%_installed.qcow2',
MACHINE => ['32bit', '64bit'],
);
my $res = schedule_iso({%iso, _GROUP_ID => '1002', TEST => 'test', BUILD => '176.6'}, 200);
is($res->json->{count}, 2, 'two job templates were scheduled');
$res = schedule_iso({%iso, _GROUP_ID => '1002', TEST => 'test', BUILD => '176.6', MACHINE => '64bit'}, 200);
is($res->json->{count}, 1, 'only the job template which machine is 64bit was scheduled');
my $result = $jobs->find($res->json->{ids}->[0])->settings_hash;
is(
$result->{HDD_1},
'opensuse-13.1-i586-176.6@64bit-minimal_with_sdk176.6_installed.qcow2',
'the specified variables were expanded correctly'
);
is($result->{BACKEND}, 'qemu', 'the BACKEND was added to settings correctly');
};

done_testing();

0 comments on commit e3d84d0

Please sign in to comment.