From 0a8fb7a8827b797aa18766b118fb2314d21027a4 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Fri, 20 Oct 2017 17:39:54 +0800 Subject: add develop guide for testapi Change-Id: Iaa9c15092aafda2024f08c467eea2f3ab9cddd96 Signed-off-by: SerenaFeng --- utils/test/testapi/.gitignore | 5 + utils/test/testapi/README.rst | 93 ------------ utils/test/testapi/docs/Makefile | 20 +++ utils/test/testapi/docs/conf.py | 165 +++++++++++++++++++++ utils/test/testapi/docs/developer/devguide/api.rst | 10 ++ .../testapi/docs/developer/devguide/framework.rst | 101 +++++++++++++ .../test/testapi/docs/developer/devguide/index.rst | 18 +++ .../testapi/docs/developer/devguide/overview.rst | 98 ++++++++++++ .../testapi/docs/developer/devguide/swagger-ui.rst | 10 ++ .../docs/developer/devguide/testapi-client.rst | 10 ++ .../testapi/docs/developer/devguide/web-portal.rst | 10 ++ utils/test/testapi/docs/index.rst | 20 +++ utils/test/testapi/setup.cfg | 2 - utils/test/testapi/tox.ini | 4 + 14 files changed, 471 insertions(+), 95 deletions(-) delete mode 100644 utils/test/testapi/README.rst create mode 100644 utils/test/testapi/docs/Makefile create mode 100644 utils/test/testapi/docs/conf.py create mode 100644 utils/test/testapi/docs/developer/devguide/api.rst create mode 100644 utils/test/testapi/docs/developer/devguide/framework.rst create mode 100644 utils/test/testapi/docs/developer/devguide/index.rst create mode 100644 utils/test/testapi/docs/developer/devguide/overview.rst create mode 100644 utils/test/testapi/docs/developer/devguide/swagger-ui.rst create mode 100644 utils/test/testapi/docs/developer/devguide/testapi-client.rst create mode 100644 utils/test/testapi/docs/developer/devguide/web-portal.rst create mode 100644 utils/test/testapi/docs/index.rst diff --git a/utils/test/testapi/.gitignore b/utils/test/testapi/.gitignore index a3d6e01ec..21bb264e4 100644 --- a/utils/test/testapi/.gitignore +++ b/utils/test/testapi/.gitignore @@ -6,3 +6,8 @@ build *.egg-info 3rd_party/static/static *.pyc +.cache +.eggs +.tox +.ven +docs/_build diff --git a/utils/test/testapi/README.rst b/utils/test/testapi/README.rst deleted file mode 100644 index 0d18b7e93..000000000 --- a/utils/test/testapi/README.rst +++ /dev/null @@ -1,93 +0,0 @@ -============= -opnfv-testapi -============= - -**Test Results Collector of OPNFV Test Projects**: - -This project aims to provide a common way of gathering all the test results for OPNFV -testing projects into a single place, and a unified way of getting those results for -testing analysis projects, such as Reporting/Bitergia Dashboard/Qtip. It exposes -Restful APIs for collecting results and pushing them into a MongoDB database. - -If you are interested in how TestAPI looks like, please visit OPNFV's official `TestAPI Server`__ - -.. __: http://testresults.opnfv.org/test - -Pre-requsites -============= - -TestAPI leverages MongoDB as the data warehouse, in order to let it work -successfully, a MongoDB must be provided, the official MongoDB version in OPNFV -TestAPI is 3.2.6. And the database is **test_results_collection**, the five -collections are *users/pods/projects/testcases/scenarioes/results*. And thanks to -MongoDB's very user-friendly property, they don't need to be created in advance. - -Running locally -=============== - -Requirements -^^^^^^^^^^^^ - -All requirements are listed in requirements.txt and should be -installed by 'pip install': - - *pip install -r requirements.txt* - -Installation -^^^^^^^^^^^^ - - *python setup.py install* - -After installation, configuration file etc/config.ini will be put under -/etc/opnfv_testapi/. And all the web relevant files under 3rd_party/static -will be in /user/local/share/opnfv_testapi as a totality. - -Start Server -^^^^^^^^^^^^ - - *opnfv-testapi [--config-file ]* - -If --config-file is provided, the specified configuration file will be employed -when starting the server, or else /etc/opnfv_testapi/config.ini will be utilized -by default. - -After executing the command successfully, a TestAPI server will be started on -port 8000, to visit web portal, please access http://hostname:8000 - -Regarding swagger-ui website, please visit http://hostname:8000/swagger/spec.html - -Running with container -====================== - -TestAPI has already containerized, the docker image is opnfv/testapi:latest. - -**Running the container not behind nginx:** - -.. code-block:: shell - - docker run -dti --name testapi -p expose_port:8000 - -e "mongodb_url=mongodb://mongodb_ip:27017/" - -e "base_url=http://host_name:expose_port" - opnfv/testapi:latest - -**Running the container behind nginx:** - -.. code-block:: shell - - docker run -dti --name testapi -p expose_port:8000 - -e "mongodb_url=mongodb://mongodb_ip:27017/" - -e "base_url=http://nginx_url" - opnfv/testapi:latest - -Unittest & pep8 -=============== - -All requirements for unit tests are outlined in test-requirements.txt, and in TestAPI project, tox is leveraged to drive the executing of unit tests and pep8 check - -**Running unit tests** - - *tox -e py27* - -**Running pep8 check** - - *tox -e pep8* diff --git a/utils/test/testapi/docs/Makefile b/utils/test/testapi/docs/Makefile new file mode 100644 index 000000000..11e9eb6d8 --- /dev/null +++ b/utils/test/testapi/docs/Makefile @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = OPNFVTestAPI +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file diff --git a/utils/test/testapi/docs/conf.py b/utils/test/testapi/docs/conf.py new file mode 100644 index 000000000..eaf15017d --- /dev/null +++ b/utils/test/testapi/docs/conf.py @@ -0,0 +1,165 @@ +# -*- coding: utf-8 -*- +# +# OPNFV TestAPI documentation build configuration file, created by +# sphinx-quickstart on Thu Oct 26 10:23:57 2017. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'OPNFV TestAPI' +copyright = u'2017, SerenaFeng' +author = u'SerenaFeng' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = u'v1.0' +# The full version, including alpha/beta/rc tags. +release = u'v1.0' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This patterns also effect to html_static_path and html_extra_path +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +# html_static_path = ['_static'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# This is required for the alabaster theme +# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars +html_sidebars = { + '**': [ + 'relations.html', # needs 'show_related': True theme option to display + 'searchbox.html', + ] +} + + +# -- Options for HTMLHelp output ------------------------------------------ + +# Output file base name for HTML help builder. +htmlhelp_basename = 'OPNFVTestAPIdoc' + + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'OPNFVTestAPI.tex', u'OPNFV TestAPI Documentation', + u'SerenaFeng', 'manual'), +] + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'opnfvtestapi', u'OPNFV TestAPI Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'OPNFVTestAPI', u'OPNFV TestAPI Documentation', + author, 'OPNFVTestAPI', 'One line description of project.', + 'Miscellaneous'), +] diff --git a/utils/test/testapi/docs/developer/devguide/api.rst b/utils/test/testapi/docs/developer/devguide/api.rst new file mode 100644 index 000000000..cd2ca27cf --- /dev/null +++ b/utils/test/testapi/docs/developer/devguide/api.rst @@ -0,0 +1,10 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. (c) 2017 ZTE Corp. + +============ +Restful APIs +============ + +.. toctree:: + :maxdepth: 2 diff --git a/utils/test/testapi/docs/developer/devguide/framework.rst b/utils/test/testapi/docs/developer/devguide/framework.rst new file mode 100644 index 000000000..f7a760531 --- /dev/null +++ b/utils/test/testapi/docs/developer/devguide/framework.rst @@ -0,0 +1,101 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. (c) 2017 ZTE Corp. + + +.. toctree:: + :maxdepth: 2 + +========= +Framework +========= + +**Test Results Collector of OPNFV Test Projects**: + +This project aims to provide a common way of gathering all the test results for OPNFV +testing projects into a single place, and a unified way of getting those results for +testing analysis projects, such as Reporting/Bitergia Dashboard/Qtip. It exposes +Restful APIs for collecting results and pushing them into a MongoDB database. + +If you are interested in how TestAPI looks like, please visit OPNFV's official `TestAPI Server`__ + +.. __: http://testresults.opnfv.org/test + +Pre-requsites +============= + +TestAPI leverages MongoDB as the data warehouse, in order to let it work +successfully, a MongoDB must be provided, the official MongoDB version in OPNFV +TestAPI is 3.2.6. And the database is **test_results_collection**, the five +collections are *users/pods/projects/testcases/scenarioes/results*. And thanks to +MongoDB's very user-friendly property, they don't need to be created in advance. + +Running locally +=============== + +Requirements +^^^^^^^^^^^^ + +All requirements are listed in requirements.txt and should be +installed by 'pip install': + + *pip install -r requirements.txt* + +Installation +^^^^^^^^^^^^ + + *python setup.py install* + +After installation, configuration file etc/config.ini will be put under +/etc/opnfv_testapi/. And all the web relevant files under 3rd_party/static +will be in /user/local/share/opnfv_testapi as a totality. + +Start Server +^^^^^^^^^^^^ + + *opnfv-testapi [--config-file ]* + +If --config-file is provided, the specified configuration file will be employed +when starting the server, or else /etc/opnfv_testapi/config.ini will be utilized +by default. + +After executing the command successfully, a TestAPI server will be started on +port 8000, to visit web portal, please access http://hostname:8000 + +Regarding swagger-ui website, please visit http://hostname:8000/swagger/spec.html + +Running with container +====================== + +TestAPI has already containerized, the docker image is opnfv/testapi:latest. + +**Running the container not behind nginx:** + +.. code-block:: shell + + docker run -dti --name testapi -p expose_port:8000 + -e "mongodb_url=mongodb://mongodb_ip:27017/" + -e "base_url=http://host_name:expose_port" + opnfv/testapi:latest + +**Running the container behind nginx:** + +.. code-block:: shell + + docker run -dti --name testapi -p expose_port:8000 + -e "mongodb_url=mongodb://mongodb_ip:27017/" + -e "base_url=http://nginx_url" + opnfv/testapi:latest + +Unittest & pep8 +=============== + +All requirements for unit tests are outlined in test-requirements.txt, and in TestAPI project, tox is leveraged to drive the executing of unit tests and pep8 check + +**Running unit tests** + + *tox -e py27* + +**Running pep8 check** + + *tox -e pep8* diff --git a/utils/test/testapi/docs/developer/devguide/index.rst b/utils/test/testapi/docs/developer/devguide/index.rst new file mode 100644 index 000000000..7afcd96fe --- /dev/null +++ b/utils/test/testapi/docs/developer/devguide/index.rst @@ -0,0 +1,18 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. (c) 2017 ZTE Corp. + + +*********************** +TestAPI Developer Guide +*********************** + +.. toctree:: + :maxdepth: 2 + + overview.rst + framework.rst + api.rst + swagger-ui.rst + web-portal.rst + testapi-client.rst diff --git a/utils/test/testapi/docs/developer/devguide/overview.rst b/utils/test/testapi/docs/developer/devguide/overview.rst new file mode 100644 index 000000000..b6475f30e --- /dev/null +++ b/utils/test/testapi/docs/developer/devguide/overview.rst @@ -0,0 +1,98 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. (c) 2017 ZTE Corporation + + +******** +Overview +******** + +TestAPI uses Python as primary programming language and build the framework from the following packages + +======== =============================================================================================================== +Module Package +======== =============================================================================================================== +api `Tornado-Motor`_ - API applications using Motor with tornado +swagger `tornado-swagger`_ - a wrapper for tornado which enables swagger-ui-v1.2 support +web `angular`_ - a superheroic JavaScript MVW framework, the version is AngularJS v1.3.15 +docs `sphinx`_ - a tool that makes it easy to create intelligent and beautiful documentation +testing `pytest`_ - a mature full-featured Python testing tool that helps you write better programs +======== =============================================================================================================== + + +Source Code +=========== + +The structure of repository is based on the recommended sample in `The Hitchhiker's Guide to Python`_ + +========================== ==================================================================================================== +Path Content +========================== ==================================================================================================== +``./3rd_party/`` third part included in TestAPI project +``./docker/`` configuration for building Docker image for TestAPI deployment +``./docs/`` user and developer documentation, design proposals +``./etc/`` configuration files used to install opnfv-testapi +``./opnfv_testapi/`` the actual package +``./opnfv_testapi/tests/`` package functional and unit tests +``./opts/`` optional components, e.g. one click deployment script +========================== ==================================================================================================== + + +Coding Style +============ + +TestAPI follows `OpenStack Style Guidelines`_ for source code and commit message. + +Specially, it is recommended to link each patch set with a JIRA issue. Put:: + + JIRA: RELENG-n + +in commit message to create an automatic link. + + +Testing +======= + +All testing related code are stored in ``./opnfv_testapi/tests/`` + +================== ==================================================================================================== +Path Content +================== ==================================================================================================== +``./tests/unit/`` unit test for each module, follow the same layout as ./opnfv_testapi/ +``./conftest.py`` pytest configuration in project scope +================== ==================================================================================================== + +`tox`_ is used to automate the testing tasks + +.. code-block:: shell + + cd + pip install tox + tox + +The test cases are written in `pytest`_. You may run it selectively with + +.. code-block:: shell + + pytest opnfv_testapi/tests/unit/common/test_config.py + + +Branching +========= + +Currently, no branching for TestAPI, only master branch + + +Releasing +========= + +Currently, TestAPI does not follow community's milestones and releases + +.. _Tornado-Motor: https://motor.readthedocs.io/en/stable/tutorial-tornado.html +.. _tornado-swagger: https://github.com/SerenaFeng/tornado-swagger +.. _angular: https://code.angularjs.org/1.3.15/docs/guide +.. _sphinx: http://www.sphinx-doc.org/en/stable/ +.. _pytest: http://doc.pytest.org/ +.. _OpenStack Style Guidelines: http://docs.openstack.org/developer/hacking/ +.. _The Hitchhiker's Guide to Python: http://python-guide-pt-br.readthedocs.io/en/latest/writing/structure/ +.. _tox: https://tox.readthedocs.io/ diff --git a/utils/test/testapi/docs/developer/devguide/swagger-ui.rst b/utils/test/testapi/docs/developer/devguide/swagger-ui.rst new file mode 100644 index 000000000..7f53047e5 --- /dev/null +++ b/utils/test/testapi/docs/developer/devguide/swagger-ui.rst @@ -0,0 +1,10 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. (c) 2017 ZTE Corp. + +============ +Swagger page +============ + +.. toctree:: + :maxdepth: 2 diff --git a/utils/test/testapi/docs/developer/devguide/testapi-client.rst b/utils/test/testapi/docs/developer/devguide/testapi-client.rst new file mode 100644 index 000000000..ab4c8e802 --- /dev/null +++ b/utils/test/testapi/docs/developer/devguide/testapi-client.rst @@ -0,0 +1,10 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. (c) 2017 ZTE Corp. + +============== +TestAPI client +============== + +.. toctree:: + :maxdepth: 2 diff --git a/utils/test/testapi/docs/developer/devguide/web-portal.rst b/utils/test/testapi/docs/developer/devguide/web-portal.rst new file mode 100644 index 000000000..62b2f1794 --- /dev/null +++ b/utils/test/testapi/docs/developer/devguide/web-portal.rst @@ -0,0 +1,10 @@ +.. This work is licensed under a Creative Commons Attribution 4.0 International License. +.. http://creativecommons.org/licenses/by/4.0 +.. (c) 2017 ZTE Corp. + +========== +Web portal +========== + +.. toctree:: + :maxdepth: 2 diff --git a/utils/test/testapi/docs/index.rst b/utils/test/testapi/docs/index.rst new file mode 100644 index 000000000..017282a74 --- /dev/null +++ b/utils/test/testapi/docs/index.rst @@ -0,0 +1,20 @@ +.. OPNFV TestAPI documentation master file, created by + sphinx-quickstart on Thu Oct 26 10:23:57 2017. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to OPNFV TestAPI's documentation! +========================================= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + +Developer Guide +=============== + +.. toctree:: + :maxdepth: 2 + + developer/devguide/index.rst diff --git a/utils/test/testapi/setup.cfg b/utils/test/testapi/setup.cfg index 23341e4b4..62a193c30 100644 --- a/utils/test/testapi/setup.cfg +++ b/utils/test/testapi/setup.cfg @@ -1,8 +1,6 @@ [metadata] name = opnfv_testapi summary = Test Result Collector -description-file = - README.rst author = SerenaFeng author-email = feng.xiaowei@zte.com.cn #home-page = http://www.opnfv.org/ diff --git a/utils/test/testapi/tox.ini b/utils/test/testapi/tox.ini index d300f1a61..13b197c63 100644 --- a/utils/test/testapi/tox.ini +++ b/utils/test/testapi/tox.ini @@ -25,6 +25,10 @@ setenv= HOME = {envtmpdir} PYTHONPATH = {toxinidir} +[testenv:docs] +basepython=python2.7 +commands = sphinx-build -W -b html docs/ docs/_build + [testenv:pep8] deps = flake8 commands = flake8 {toxinidir} -- cgit 1.2.3-korg