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 support for getting test results as json on the job json api #1424

Merged

Conversation

foursixnine
Copy link
Member

@foursixnine foursixnine commented Aug 9, 2017

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

@foursixnine foursixnine changed the title Add support for getting test results as json Move read_test_modules to OpenQA::Utils Add support for getting test results as json on the job json api Aug 9, 2017
@codecov
Copy link

codecov bot commented Aug 9, 2017

Codecov Report

Merging #1424 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1424      +/-   ##
==========================================
+ Coverage   88.44%   88.44%   +<.01%     
==========================================
  Files         105      105              
  Lines        7951     7956       +5     
==========================================
+ Hits         7032     7037       +5     
  Misses        919      919
Impacted Files Coverage Δ
lib/OpenQA/WebAPI/Controller/Test.pm 98.17% <ø> (-0.11%) ⬇️
lib/OpenQA/Schema/Result/Jobs.pm 90.73% <100%> (+0.03%) ⬆️
lib/OpenQA/Utils.pm 91.12% <100%> (+0.47%) ⬆️
lib/OpenQA/WebAPI/Controller/API/V1/Job.pm 79.39% <100%> (+0.08%) ⬆️
lib/OpenQA/WebAPI.pm 92.28% <100%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 92f4fa1...b1d5b82. Read the comment docs.

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);
Copy link
Contributor

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

@foursixnine foursixnine force-pushed the feature/json_api/job_details branch 3 times, most recently from 0087d43 to 2e53269 Compare August 11, 2017 08:21
@@ -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};
Copy link
Member

@kraih kraih Aug 11, 2017

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?

@@ -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);
Copy link
Member

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

Copy link
Member

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);
);

Copy link
Member

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 :-)

Copy link
Member Author

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)
);

Copy link
Member

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 {
Copy link
Member

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?

Copy link
Member Author

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);
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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

@okurz
Copy link
Member

okurz commented Aug 28, 2017

LGTM

@foursixnine foursixnine force-pushed the feature/json_api/job_details branch 2 times, most recently from 76c3dd8 to c27f500 Compare September 18, 2017 11:19
$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"');
Copy link
Member Author

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

Copy link
Member

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
@foursixnine foursixnine merged commit b5f2b56 into os-autoinst:master Sep 27, 2017
coolo pushed a commit that referenced this pull request Sep 27, 2017
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
@AdamWill
Copy link
Contributor

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...

@coolo
Copy link
Contributor

coolo commented Oct 11, 2017

details*json as in all needle matches - the epic is https://progress.opensuse.org/issues/20526

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants