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

Check for existing job groups during openqa-load-templates #6095

Merged
merged 1 commit into from
Jan 7, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions script/openqa-load-templates
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,29 @@ sub post_entry ($table, $entry) {
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;

my $existing_group_res = $client->get($job_groups_url, form => {name => $entry->{group_name}})->res;
print_error $existing_group_res unless $existing_group_res->is_success;
my $group_exists = 0;
for my $group (@{$existing_group_res->json}) {
next unless $group->{name} eq $entry->{group_name};
$group_exists = 1
if $options{update}
or die "Job group '$entry->{group_name}' already exists. Use --update to modify existing entries.";
}
unless ($group_exists) {
my $create_res = $client->post($job_groups_url, form => {name => $entry->{group_name}})->res;
print_error($create_res) unless $create_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;
my $yaml_res = $client->post(
$job_templates_url,
form => {
name => $entry->{group_name},
template => $entry->{template},
schema => 'JobTemplates-01.yaml'
})->res;
print_error($yaml_res) unless $yaml_res->is_success;
return 1;
}

Expand Down
4 changes: 3 additions & 1 deletion t/40-script_load_dump_templates.t
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ my $base_args = "--host $host --apikey $apikey --apisecret $apisecret";
$args = "$base_args $filename";
my $expected = qr/JobGroups.+=> \{ added => 1, of => 1 \}/;
test_once $args, $expected, 'Admin may load templates', 0, 'successfully loaded templates';
test_once $args, qr/group with existing name/, 'Duplicate job group', 255, 'failed on duplicate job group';
test_once $args, qr/Use --update to modify/, 'Duplicate job group', 255, 'failed on duplicate job group';
$args = "$base_args --update $filename";
test_once $args, $expected, 'Update with existing job group', 0, 'updated template with existing job group';

subtest 'test changing existing entries' => sub {
# delete job group so that we can load the template again without running into duplicate job group error
Expand Down
Loading