Skip to content

Commit

Permalink
Add filter to exclude groupless jobs to API/V1
Browse files Browse the repository at this point in the history
  • Loading branch information
r-richardson committed Aug 9, 2024
1 parent 0b3a25e commit 8668e87
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/OpenQA/Schema/ResultSet/Jobs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,18 @@ sub _prepare_complex_query_search_args ($self, $args) {
push @conds, {'me.group_id' => {-in => $subquery}};
}

if (defined $args->{not_groupid}) {
my $id = $args->{not_groupid};
if ($id) {
push @conds, {-or => [
{'me.group_id' => {-not_in => $id}},
{'me.group_id' => undef},
]};
}
else {
push @conds, {'me.group_id' => {-not => undef}};
}
}
if ($args->{ids}) {
push @conds, {'me.id' => {-in => $args->{ids}}};
}
Expand Down
3 changes: 2 additions & 1 deletion lib/OpenQA/WebAPI/Controller/API/V1/Job.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ sub list ($self) {
$validation->optional('limit')->num;
$validation->optional('offset')->num;
$validation->optional('groupid')->num;
$validation->optional('not_groupid')->num;

my $limits = OpenQA::App->singleton->config->{misc_limits};
my $limit = min($limits->{generic_max_limit}, $validation->param('limit') // $limits->{generic_default_limit});
Expand All @@ -99,7 +100,7 @@ sub list ($self) {
$args{limit} = $limit + 1;
$args{offset} = $offset;
my @args = qw(build iso distri version flavor scope group groupid
before after arch hdd_1 test machine worker_class
not_groupid before after arch hdd_1 test machine worker_class
modules modules_result);
for my $arg (@args) {
next unless defined(my $value = $self->param($arg));
Expand Down
15 changes: 15 additions & 0 deletions t/api/04-jobs.t
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ subtest 'check job group' => sub {
is(scalar(@{$t->tx->res->json->{jobs}}), 0);
};

subtest 'exclude groupless jobs' => sub {
my %jobs = map { $_->{id} => $_ } @jobs;
is($jobs{99928}->{state}, 'scheduled', 'groupless job is listed');
$t->get_ok('/api/v1/jobs?not_groupid=0')->status_is(200);
@jobs = @{$t->tx->res->json->{jobs}};
is scalar @jobs, 15, 'groupless jobs are excluded';
};

subtest 'exclude specific group' => sub {
my %jobs = map { $_->{id} => $_ } @jobs;
$t->get_ok('/api/v1/jobs?not_groupid=1001')->status_is(200);
@jobs = @{$t->tx->res->json->{jobs}};
is scalar @jobs, 4, 'jobs of specified groups are excluded';
};

subtest 'restricted query' => sub {
$t->get_ok('/api/v1/jobs?iso=openSUSE-13.1-DVD-i586-Build0091-Media.iso');
is(scalar(@{$t->tx->res->json->{jobs}}), 6, 'query for existing jobs by iso');
Expand Down

0 comments on commit 8668e87

Please sign in to comment.