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

Add filter to exclude groupless jobs to API/V1 #5837

Merged
merged 1 commit into from
Aug 12, 2024
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
9 changes: 9 additions & 0 deletions lib/OpenQA/Schema/ResultSet/Jobs.pm
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@ 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');
perlpunk marked this conversation as resolved.
Show resolved Hide resolved
$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
Loading