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 support for getting test results as json on the job json api #1424
Add support for getting test results as json on the job json api #1424
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1424 +/- ##
==========================================
+ Coverage 88.44% 88.44% +<.01%
==========================================
Files 105 105
Lines 7951 7956 +5
==========================================
+ Hits 7032 7037 +5
Misses 919 919
Continue to review full report at Codecov.
|
t/api/04-jobs.t
Outdated
$t->get_ok('/api/v1/jobs/99926')->status_is(200); | ||
$t->json_is('/job/testresults' => undef, 'Test details are not present'); | ||
|
||
$t->get_ok('/api/v1/jobs/99926?details=1')->status_is(200); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that this is a param. This should be a documented route as in jobs/99926/details
0087d43
to
2e53269
Compare
lib/OpenQA/Schema/Result/Jobs.pm
Outdated
@@ -582,6 +583,10 @@ sub to_hash { | |||
if ($args{deps}) { | |||
$j = {%$j, %{$job->deps_hash}}; | |||
} | |||
if ($args{details}) { | |||
my $testresults = read_test_modules($job); | |||
$j = {%$j, testresults => $testresults}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't $j->{testresults} = $testresults;
or $j->{testresults} = read_test_modules($job);
work just as well?
lib/OpenQA/Schema/Result/Jobs.pm
Outdated
@@ -23,7 +23,8 @@ use JSON; | |||
use Fcntl; | |||
use DateTime; | |||
use db_helpers; | |||
use OpenQA::Utils qw(log_debug log_info log_warning parse_assets_from_settings locate_asset send_job_to_worker); | |||
use OpenQA::Utils | |||
qw(log_debug log_info log_warning parse_assets_from_settings locate_asset send_job_to_worker read_test_modules); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess a line break within the 'qw()' part would look nicer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to use this syntax.
use OpenQA::Utils (
qw(log_debug log_info log_warning parse_assets_from_settings locate_asset),
qw(send_job_to_worker read_test_modules);
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, could work as well :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually we could also just use tags too, as right now we are exporting 40 of the 42 routines in the OpenQA::Utils, having :test_handling
or :logging
or :scheduling
etc to group a bit might come handy... or simply start extracting from Utils as proposed by @okurz below
I'm going with @kraih's proposal
use OpenQA::Utils (
qw(log_debug log_info log_warning),
qw(parse_assets_from_settings locate_asset),
qw(send_job_to_worker read_test_modules)
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Export tags seem like a good idea.
@@ -649,6 +650,48 @@ sub find_job { | |||
return $job; | |||
} | |||
|
|||
sub read_test_modules { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not so sure if the "utils" file is really the right one for such route specific implementation. Also the file "Utils.pm" is getting a bit big. Anyone has an idea for a better location for a function used both in the webUI route as well as the API one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made more sense to have it in the Utils module, pretty much like find_job does. But I agree that Utils is growing up a bit.
@@ -343,7 +343,8 @@ sub startup { | |||
$api_ro->post('/jobs/restart')->name('apiv1_restart_jobs')->to('job#restart'); | |||
|
|||
my $job_r = $api_ro->route('/jobs/:jobid', jobid => qr/\d+/); | |||
$api_public_r->route('/jobs/:jobid', jobid => qr/\d+/)->get('/')->name('apiv1_job')->to('job#show'); | |||
$api_public_r->route('/jobs/:jobid', jobid => qr/\d+/)->name('apiv1_job')->to('job#show'); | |||
$api_public_r->route('/jobs/:jobid/details', jobid => qr/\d+/)->name('apiv1_job')->to('job#show', details => 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't our idea to use the .json render route instead of an explicit API route? Or maybe even better to add the same to both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already had the API route, I just added the details part. Adding support to render it at /tests/:jobid/details
would have been only redundant when what we actually want is the pure json data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I get it but nevermind
2e53269
to
60f7586
Compare
LGTM |
60f7586
to
4f4e66b
Compare
76c3dd8
to
c27f500
Compare
c27f500
to
405b00f
Compare
$t->get_ok('/api/v1/jobs/99963/details')->status_is(200); | ||
$t->json_has('/job/testresults/0', 'Test details are there'); | ||
$t->json_is('/job/assets/hdd/0', => 'hdd_image.qcow2', 'Job has hdd_image.qcow2 as asset'); | ||
$t->json_is('/job/testresults/0/category', => 'installation', 'Job category is "installation"'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mudler You will be pleased :) Actually it made sense to add the test, just in case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect :)
This allows to be able to use the json api to get not only a job information but also the details if there are any Add tests to get test results from the job json api
405b00f
to
b1d5b82
Compare
commit b5f2b56 Merge: 92f4fa1 b1d5b82 Author: Santiago Zarate <santiago@zarate.net.ve> AuthorDate: Wed Sep 27 21:49:56 2017 +0200 Commit: GitHub <noreply@github.com> CommitDate: Wed Sep 27 21:49:56 2017 +0200 Merge pull request #1424 from foursixnine/feature/json_api/job_details Add support for getting test results as json on the job json api
note, I've been using e.g.: instead of: because the former includes individual module results but the latter doesn't. How does this compare with that? I can't quite grok precisely what 'details' this shows... |
details*json as in all needle matches - the epic is https://progress.opensuse.org/issues/20526 |
This allows to be able to use the json api to get not only a job information but also the details if there are any