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

openqa-load-templates: Slightly simplify #6004

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 33 additions & 39 deletions script/openqa-load-templates
Original file line number Diff line number Diff line change
Expand Up @@ -104,53 +104,49 @@
if (my $err = $res->error) {
if (my $json = $res->json) {
if (my $json_err = $json->{error}) {
die "$err->{message}: " . join("\n", @{$json_err})
if ref $json_err eq 'ARRAY';
die "$err->{message}: $json_err";
die "$err->{message}: " . (ref $json_err eq 'ARRAY' ? join("\n", @{$json_err}) : $json_err);
b10n1k marked this conversation as resolved.
Show resolved Hide resolved
}
}
die "ERROR: $err->{code} - $err->{message}" if $err->{code};
}
die "unknown error code - host $url->{host} unreachable?";
}

sub post_entry ($table, $entry) {
my %param;

if ($table eq 'JobGroups') {
# Create the group first
my $job_groups_url = $url->clone->path($options{apibase} . '/job_groups');
my $res = $client->post($job_groups_url, form => {name => $entry->{group_name}})->res;
print_error $res unless $res->is_success;
sub handle_job_groups ($entry) {
# Create the group first
my $job_groups_url = $url->clone->path($options{apibase} . '/job_groups');
my $res = $client->post($job_groups_url, form => {name => $entry->{group_name}})->res;
print_error $res unless $res->is_success;

# Post the job template YAML
my $job_templates_url = $url->clone->path($options{apibase} . '/job_templates_scheduling');
$res
= $client->post($job_templates_url,
form => {name => $entry->{group_name}, template => $entry->{template}, schema => 'JobTemplates-01.yaml'})
->res;
print_error $res unless $res->is_success;
return 1;
}
# Post the job template YAML
my $job_templates_url = $url->clone->path($options{apibase} . '/job_templates_scheduling');
$res
= $client->post($job_templates_url,
form => {name => $entry->{group_name}, template => $entry->{template}, schema => 'JobTemplates-01.yaml'})->res;
print_error $res unless $res->is_success;
return 1;
}

if ($table eq 'JobTemplates') {
unless (defined($entry->{prio})) {
# we have to migrate the prio from the TestSuite to the JobTemplate
for my $ts (@{$info->{TestSuites}}) {
if ($ts->{name} eq $entry->{test_suite}{name}) {
$entry->{prio} = $ts->{prio};
}
}
}
unless (defined($entry->{group_name})) {
# we have to create a group_name from the Product
my $gn = $entry->{product}{distri};
if ($entry->{product}{version} ne '*') {
$gn .= "-" . $entry->{product}{version};
}
$entry->{group_name} = $gn;
sub handle_job_templates ($entry) {
unless (defined($entry->{prio})) {

Check warning on line 131 in script/openqa-load-templates

View check run for this annotation

Codecov / codecov/patch

script/openqa-load-templates#L130-L131

Added lines #L130 - L131 were not covered by tests
# we have to migrate the prio from the TestSuite to the JobTemplate
for my $ts (@{$info->{TestSuites}}) {
$entry->{prio} = $ts->{prio} if $ts->{name} eq $entry->{test_suite}{name};

Check warning on line 134 in script/openqa-load-templates

View check run for this annotation

Codecov / codecov/patch

script/openqa-load-templates#L133-L134

Added lines #L133 - L134 were not covered by tests
}
}
unless (defined($entry->{group_name})) {

Check warning on line 137 in script/openqa-load-templates

View check run for this annotation

Codecov / codecov/patch

script/openqa-load-templates#L137

Added line #L137 was not covered by tests
# we have to create a group_name from the Product
my $gn = $entry->{product}{distri};
$gn .= "-" . $entry->{product}{version} if $entry->{product}{version} ne '*';
$entry->{group_name} = $gn;

Check warning on line 141 in script/openqa-load-templates

View check run for this annotation

Codecov / codecov/patch

script/openqa-load-templates#L139-L141

Added lines #L139 - L141 were not covered by tests
}
}

sub post_entry ($table, $entry) {
my %param;

return handle_job_groups($entry) if $table eq 'JobGroups';
handle_job_templates($entry) if $table eq 'JobTemplates';

for my $key (keys %{$entry}) {
if ($key eq 'machine' && defined $entry->{machine}{name}) {
Expand All @@ -167,9 +163,7 @@
}
elsif ($key eq 'settings' && ref($entry->{settings}) eq "ARRAY") {
$param{settings} = {};
for my $var (@{$entry->{settings}}) {
$param{settings}{$var->{key}} = $var->{value};
}
$param{settings}{$_->{key}} = $_->{value} for @{$entry->{settings}};
}
else {
$param{$key} = $entry->{$key};
Expand Down
Loading