summaryrefslogtreecommitdiffstats
path: root/reporting/api
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-03-21 14:48:54 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-03-25 01:07:45 +0000
commit60b07c9cb49db8dd7db883058f2d25fc1b93efc6 (patch)
tree46c2413200057a0b4477ea11a2b735647d1d118e /reporting/api
parent3bda241da0264a6a46cbda51f61931dd4299db20 (diff)
Create Catalogue page
JIRA: RELENG-193 1.create a page to list all project. 2.This page can get test case list of certain project. 3.This page can show information of certain test case. Change-Id: I79e0d3aafa99c054865a0d2948b99918802f32a7 Signed-off-by: chenjiankun <chenjiankun1@huawei.com>
Diffstat (limited to 'reporting/api')
-rw-r--r--reporting/api/api/__init__.py (renamed from reporting/api/__init__.py)0
-rw-r--r--reporting/api/api/conf.py1
-rw-r--r--reporting/api/api/handlers/__init__.py19
-rw-r--r--reporting/api/api/handlers/landing.py (renamed from reporting/api/handlers/landing.py)14
-rw-r--r--reporting/api/api/handlers/projects.py27
-rw-r--r--reporting/api/api/handlers/testcases.py33
-rw-r--r--reporting/api/api/server.py (renamed from reporting/api/server.py)2
-rw-r--r--reporting/api/api/urls.py (renamed from reporting/api/urls.py)10
-rw-r--r--reporting/api/handlers/__init__.py0
-rwxr-xr-xreporting/api/install.sh3
-rw-r--r--reporting/api/requirements.txt3
-rw-r--r--reporting/api/setup.cfg32
-rw-r--r--reporting/api/setup.py9
13 files changed, 136 insertions, 17 deletions
diff --git a/reporting/api/__init__.py b/reporting/api/api/__init__.py
index e69de29..e69de29 100644
--- a/reporting/api/__init__.py
+++ b/reporting/api/api/__init__.py
diff --git a/reporting/api/api/conf.py b/reporting/api/api/conf.py
new file mode 100644
index 0000000..5897d4f
--- /dev/null
+++ b/reporting/api/api/conf.py
@@ -0,0 +1 @@
+base_url = 'http://testresults.opnfv.org/test/api/v1'
diff --git a/reporting/api/api/handlers/__init__.py b/reporting/api/api/handlers/__init__.py
new file mode 100644
index 0000000..bcda664
--- /dev/null
+++ b/reporting/api/api/handlers/__init__.py
@@ -0,0 +1,19 @@
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+from tornado.web import RequestHandler
+
+
+class BaseHandler(RequestHandler):
+ def _set_header(self):
+ self.set_header('Access-Control-Allow-Origin', '*')
+ self.set_header('Access-Control-Allow-Headers',
+ 'Content-Type, Content-Length, Authorization, \
+ Accept, X-Requested-With , PRIVATE-TOKEN')
+ self.set_header('Access-Control-Allow-Methods',
+ 'PUT, POST, GET, DELETE, OPTIONS')
diff --git a/reporting/api/handlers/landing.py b/reporting/api/api/handlers/landing.py
index ae1fd20..749916f 100644
--- a/reporting/api/handlers/landing.py
+++ b/reporting/api/api/handlers/landing.py
@@ -8,19 +8,11 @@
##############################################################################
import requests
-from tornado.web import RequestHandler
from tornado.escape import json_encode
from tornado.escape import json_decode
-
-class BaseHandler(RequestHandler):
- def _set_header(self):
- self.set_header('Access-Control-Allow-Origin', '*')
- self.set_header('Access-Control-Allow-Headers',
- 'Content-Type, Content-Length, Authorization, \
- Accept, X-Requested-With , PRIVATE-TOKEN')
- self.set_header('Access-Control-Allow-Methods',
- 'PUT, POST, GET, DELETE, OPTIONS')
+from api.handlers import BaseHandler
+from api import conf
class FiltersHandler(BaseHandler):
@@ -85,7 +77,7 @@ class ScenariosHandler(BaseHandler):
return atom
def _get_scenarios(self):
- url = 'http://testresults.opnfv.org/test/api/v1/scenarios'
+ url = '{}/scenarios'.format(conf.base_url)
resp = requests.get(url).json()
data = self._change_to_utf8(resp).get('scenarios', {})
return {a.get('name'): self._get_scenario(a.get('installers', [])
diff --git a/reporting/api/api/handlers/projects.py b/reporting/api/api/handlers/projects.py
new file mode 100644
index 0000000..02412cd
--- /dev/null
+++ b/reporting/api/api/handlers/projects.py
@@ -0,0 +1,27 @@
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apaiche.org/licenses/LICENSE-2.0
+##############################################################################
+import requests
+
+from tornado.escape import json_encode
+
+from api.handlers import BaseHandler
+from api import conf
+
+
+class Projects(BaseHandler):
+ def get(self):
+ self._set_header()
+
+ url = '{}/projects'.format(conf.base_url)
+ projects = requests.get(url).json().get('projects', {})
+
+ project_url = 'https://wiki.opnfv.org/display/{}'
+ data = {p['name']: project_url.format(p['name']) for p in projects}
+
+ return self.write(json_encode(data))
diff --git a/reporting/api/api/handlers/testcases.py b/reporting/api/api/handlers/testcases.py
new file mode 100644
index 0000000..110ac4c
--- /dev/null
+++ b/reporting/api/api/handlers/testcases.py
@@ -0,0 +1,33 @@
+##############################################################################
+# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+import requests
+
+from tornado.escape import json_encode
+
+from api.handlers import BaseHandler
+from api import conf
+
+
+class TestCases(BaseHandler):
+ def get(self, project):
+ self._set_header()
+
+ url = '{}/projects/{}/cases'.format(conf.base_url, project)
+ cases = requests.get(url).json().get('testcases', [])
+ data = [t['name'] for t in cases]
+ self.write(json_encode(data))
+
+
+class TestCase(BaseHandler):
+ def get(self, project, name):
+ self._set_header()
+
+ url = '{}/projects/{}/cases/{}'.format(conf.base_url, project, name)
+ data = requests.get(url).json()
+ self.write(json_encode(data))
diff --git a/reporting/api/server.py b/reporting/api/api/server.py
index 0b00e93..e340b01 100644
--- a/reporting/api/server.py
+++ b/reporting/api/api/server.py
@@ -11,7 +11,7 @@ import tornado.web
from tornado.options import define
from tornado.options import options
-from urls import mappings
+from api.urls import mappings
define("port", default=8000, help="run on the given port", type=int)
diff --git a/reporting/api/urls.py b/reporting/api/api/urls.py
index fcfb2d7..a5228b2 100644
--- a/reporting/api/urls.py
+++ b/reporting/api/api/urls.py
@@ -6,9 +6,15 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from handlers import landing
+from api.handlers import landing
+from api.handlers import projects
+from api.handlers import testcases
mappings = [
(r"/landing-page/filters", landing.FiltersHandler),
- (r"/landing-page/scenarios", landing.ScenariosHandler)
+ (r"/landing-page/scenarios", landing.ScenariosHandler),
+
+ (r"/projects-page/projects", projects.Projects),
+ (r"/projects/([^/]+)/cases", testcases.TestCases),
+ (r"/projects/([^/]+)/cases/([^/]+)", testcases.TestCase)
]
diff --git a/reporting/api/handlers/__init__.py b/reporting/api/handlers/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/reporting/api/handlers/__init__.py
+++ /dev/null
diff --git a/reporting/api/install.sh b/reporting/api/install.sh
deleted file mode 100755
index 55d6b77..0000000
--- a/reporting/api/install.sh
+++ /dev/null
@@ -1,3 +0,0 @@
-apt-get install -y python-pip
-pip install tornado
-pip install requests
diff --git a/reporting/api/requirements.txt b/reporting/api/requirements.txt
new file mode 100644
index 0000000..12ad688
--- /dev/null
+++ b/reporting/api/requirements.txt
@@ -0,0 +1,3 @@
+tornado==4.4.2
+requests==2.1.0
+
diff --git a/reporting/api/setup.cfg b/reporting/api/setup.cfg
new file mode 100644
index 0000000..53d1092
--- /dev/null
+++ b/reporting/api/setup.cfg
@@ -0,0 +1,32 @@
+[metadata]
+name = reporting
+
+author = JackChan
+author-email = chenjiankun1@huawei.com
+
+classifier =
+ Environment :: opnfv
+ Intended Audience :: Information Technology
+ Intended Audience :: System Administrators
+ License :: OSI Approved :: Apache Software License
+ Operating System :: POSIX :: Linux
+ Programming Language :: Python
+ Programming Language :: Python :: 2
+ Programming Language :: Python :: 2.7
+
+[global]
+setup-hooks =
+ pbr.hooks.setup_hook
+
+[files]
+packages =
+ api
+
+[entry_points]
+console_scripts =
+ api = api.server:main
+
+[egg_info]
+tag_build =
+tag_date = 0
+tag_svn_revision = 0
diff --git a/reporting/api/setup.py b/reporting/api/setup.py
new file mode 100644
index 0000000..d974816
--- /dev/null
+++ b/reporting/api/setup.py
@@ -0,0 +1,9 @@
+import setuptools
+
+
+__author__ = 'JackChan'
+
+
+setuptools.setup(
+ setup_requires=['pbr>=1.8'],
+ pbr=True)