add JSON api for getting tempest run results
This commit is contained in:
64
stackviz/views/tempest/api.py
Normal file
64
stackviz/views/tempest/api.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from restless.views import Endpoint
|
||||
|
||||
from stackviz.parser.tempest_subunit import (get_repositories,
|
||||
convert_run,
|
||||
reorganize)
|
||||
|
||||
#: Cached results from loaded subunit logs indexed by their run number
|
||||
_cached_run = {}
|
||||
|
||||
#: Cached results converted into tree form
|
||||
_cached_tree = {}
|
||||
|
||||
|
||||
class NoRunDataException(Exception):
|
||||
pass
|
||||
|
||||
class RunNotFoundException(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def _load_run(run_id):
|
||||
if run_id in _cached_run:
|
||||
return _cached_run[run_id]
|
||||
|
||||
repos = get_repositories()
|
||||
if not repos:
|
||||
raise NoRunDataException()
|
||||
|
||||
try:
|
||||
# assume first repo for now
|
||||
run = repos[0].get_test_run(run_id)
|
||||
|
||||
# strip details for now
|
||||
# TODO: provide method for getting details on demand
|
||||
# (preferably for individual tests to avoid bloat)
|
||||
converted_run = convert_run(run, strip_details=True)
|
||||
_cached_run[run_id] = converted_run
|
||||
|
||||
return converted_run
|
||||
except KeyError:
|
||||
raise RunNotFoundException()
|
||||
|
||||
|
||||
def _load_tree(run_id):
|
||||
if run_id in _cached_tree:
|
||||
return _cached_tree[run_id]
|
||||
|
||||
run = _load_run(run_id)
|
||||
tree = reorganize(run)
|
||||
|
||||
_cached_tree[run_id] = tree
|
||||
return tree
|
||||
|
||||
|
||||
class TempestRunEndpoint(Endpoint):
|
||||
def get(self, request, run_id):
|
||||
return _load_tree(run_id)
|
||||
|
||||
|
||||
# TODO: run details
|
||||
# class TempestRunDetailsEndpoint(Endpoint):
|
||||
# def get(self, request, run_id, test_path):
|
||||
# ...
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
from django.conf.urls import patterns, include, url
|
||||
from django.contrib import admin
|
||||
|
||||
from stackviz.views.tempest.latest_results import LatestResultsView
|
||||
from .latest_results import LatestResultsView
|
||||
from .api import TempestRunEndpoint
|
||||
|
||||
|
||||
urlpatterns = patterns('',
|
||||
# Examples:
|
||||
# url(r'^$', 'stackviz.views.home', name='home'),
|
||||
# url(r'^blog/', include('blog.urls')),
|
||||
|
||||
url(r'^latest_results$', LatestResultsView.as_view()),
|
||||
|
||||
url(r'^api/(\d+)/$', TempestRunEndpoint.as_view())
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user