Migrate testing to ostestr and adding docs

Following commits not only enables running
unit tests with ostestr, like other
OS projects, but also:
* enables covarage with testr
* enables building documentation with build_sphinx commands

Additionally:
* tox.ini was organized a bit
* (cherry picked commit 0db2f1cd2a)

Needed-By: Ie289f5ca3d82a3150a0d0f8b8284385efe6ae4b2
Change-Id: I818c66be11bc75358caf8809646ff9a9c35a2c91
(cherry picked from commit 04030115db)
This commit is contained in:
Tomasz Trębski 2017-01-12 13:42:37 +01:00
parent 1745e71957
commit 7e4df653fe
21 changed files with 213 additions and 250 deletions

7
.coveragerc Normal file
View File

@ -0,0 +1,7 @@
[run]
branch = True
source = monasca_log_api
omit = monasca_log_api/tests/*
[report]
ignore_errors = True

9
.testr.conf Normal file
View File

@ -0,0 +1,9 @@
[DEFAULT]
test_command=OS_STDOUT_CAPTURE=${OS_STDOUT_CAPTURE:-1} \
OS_STDERR_CAPTURE=${OS_STDERR_CAPTURE:-1} \
OS_TEST_TIMEOUT=${OS_TEST_TIMEOUT:-160} \
${PYTHON:-python} -m subunit.run discover -t ./ $OS_TEST_PATH $LISTOPT $IDOPTION
test_id_option=--load-list $IDFILE
test_list_option=--list
group_regex=monasca_log_api\.tests(?:\.|_)([^_]+)

192
Makefile
View File

@ -1,192 +0,0 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = build
# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
endif
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) documentation
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) documentation
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " applehelp to make an Apple Help Book"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " xml to make Docutils-native XML files"
@echo " pseudoxml to make pseudoxml-XML files for display purposes"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
@echo " coverage to run coverage check of the documentation (if enabled)"
clean:
rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/monasca-log-api.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/monasca-log-api.qhc"
applehelp:
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
@echo
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
@echo "N.B. You won't be able to view it unless you put it in" \
"~/Library/Documentation/Help or install it in your application" \
"bundle."
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/monasca-log-api"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/monasca-log-api"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
latexpdfja:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
coverage:
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
@echo "Testing of coverage in the sources finished, look at the " \
"results in $(BUILDDIR)/coverage/python.txt."
xml:
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."
pseudoxml:
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."

View File

@ -12,10 +12,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys
import os
import shlex
import sphinx_rtd_theme
import warnings
# 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
@ -32,11 +30,11 @@ import sphinx_rtd_theme
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.viewcode',
'sphinx.ext.graphviz',
'oslosphinx'
]
# Add any paths that contain templates here, relative to this directory.
@ -55,17 +53,17 @@ master_doc = 'index'
# General information about the project.
project = u'monasca-log-api'
copyright = u'2015, FUJITSU LIMITED'
author = u'Tomasz Trębski <tomasz.trebski@ts.fujitsu.com>,Lukasz Zajaczkowski <lukasz.zajaczkowski@ts.fujitsu.com>'
copyright = u'2015-present, OpenStack Foundation'
author = u'OpenStack'
# 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 = '0.0.1'
version = '0.0.3'
# The full version, including alpha/beta/rc tags.
release = '0.0.1'
release = 'stable/mitaka'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -84,7 +82,7 @@ language = None
# directories to ignore when looking for source files.
exclude_patterns = [
'common',
'docs',
'doc',
'documentation',
'etc',
'java'
@ -99,17 +97,17 @@ exclude_patterns = [
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
add_module_names = False
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
show_authors = True
show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
modindex_common_prefix = ['monasca.']
# If true, keep warnings as "system message" paragraphs in the built documents.
#keep_warnings = False
@ -122,17 +120,15 @@ todo_include_todos = True
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_rtd_theme'
# html_theme = 'sphinx_rtd_theme'
# 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 = {}
# html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
html_theme_path = [
sphinx_rtd_theme.get_html_theme_path()
]
# html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
@ -146,7 +142,7 @@ html_theme_path = [
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# doc. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
@ -163,6 +159,14 @@ html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
git_cmd = ["git", "log", "--pretty=format:'%ad, commit %h'", "--date=local",
"-n1"]
try:
html_last_updated_fmt = os.subprocess.Popen(
git_cmd, stdout=os.subprocess.PIPE).communicate()[0].decode()
except Exception:
warnings.warn('Cannot get last updated time from git repository. '
'Not setting "html_last_updated_fmt".')
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
@ -239,7 +243,7 @@ latex_elements = {
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'monasca-log-api.tex', u'monasca-log-api Documentation',
u'Tomasz Trębski \\textless{}tomasz.trebski@ts.fujitsu.com\\textgreater{}', 'manual'),
u'Openstack Foundation \\textless{}monasca@lists.launchpad.net\\textgreater{}', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
@ -283,7 +287,7 @@ man_pages = [
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'monasca-log-api', u'monasca-log-api Documentation',
author, 'monasca-log-api', 'One line description of project.',
author, 'monasca-log-api', 'Rest-API to collect logs from your cloud.',
'Miscellaneous'),
]
@ -301,4 +305,4 @@ texinfo_documents = [
# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {'https://docs.python.org/': None}
intersphinx_mapping = {'https://doc.python.org/': None}

View File

@ -9,7 +9,7 @@ Welcome to monasca-log-api's documentation!
Contents:
.. toctree::
:maxdepth: 2
:maxdepth: 1
monasca_log_api

View File

@ -20,18 +20,18 @@ monasca_log_api.api.headers module
:undoc-members:
:show-inheritance:
monasca_log_api.api.logs_api module
-----------------------------------
monasca_log_api.api.healthcheck_api module
------------------------------------------
.. automodule:: monasca_log_api.api.logs_api
.. automodule:: monasca_log_api.api.healthcheck_api
:members:
:undoc-members:
:show-inheritance:
monasca_log_api.api.rest_utils module
-------------------------------------
monasca_log_api.api.logs_api module
-----------------------------------
.. automodule:: monasca_log_api.api.rest_utils
.. automodule:: monasca_log_api.api.logs_api
:members:
:undoc-members:
:show-inheritance:

View File

@ -0,0 +1,30 @@
monasca_log_api.v2.reference package
====================================
Submodules
----------
monasca_log_api.v2.reference.logs module
----------------------------------------
.. automodule:: monasca_log_api.v2.reference.logs
:members:
:undoc-members:
:show-inheritance:
monasca_log_api.v2.reference.versions module
--------------------------------------------
.. automodule:: monasca_log_api.v2.reference.versions
:members:
:undoc-members:
:show-inheritance:
Module contents
---------------
.. automodule:: monasca_log_api.v2.reference
:members:
:undoc-members:
:show-inheritance:

View File

@ -0,0 +1,18 @@
monasca_log_api.v2 package
==========================
Subpackages
-----------
.. toctree::
monasca_log_api.v2.common
monasca_log_api.v2.reference
Module contents
---------------
.. automodule:: monasca_log_api.v2
:members:
:undoc-members:
:show-inheritance:

View File

@ -26,7 +26,7 @@ _DEPRECATED_INFO = ('%s has been deprecated. Please use %s.'
# TODO(idea) perhaps add it as pipeline call right before API, seems generic
def _before_logs_post(req, res, payload, params):
def _before_logs_post(req, res, kwargs):
cross_tenant_id = req.get_param('tenant_id')
tenant_id = req.get_header(*headers.X_TENANT_ID)

View File

@ -28,10 +28,7 @@ class TestHealthChecks(testing.TestBase):
def before(self):
self.conf = base.mock_config(self)
self.resource = healthchecks.HealthChecks()
self.api.add_route(
ENDPOINT,
self.resource
)
self.api.add_route(ENDPOINT, self.resource)
def test_should_return_200_for_head(self):
self.simulate_request(ENDPOINT, method='HEAD')

View File

@ -11,5 +11,5 @@ pastedeploy>=1.5.0
pbr>=1.6.0
six>=1.9.0
simport
monasca-common>=0.0.6
monasca-common>=0.0.6,<1.4.0
eventlet>=0.17.4,!=0.18.0

View File

@ -1,6 +1,5 @@
[metadata]
name = monasca-log-api
summary = Monasca API for sending log entries
description-file =
README.md
@ -17,6 +16,10 @@ classifier =
Programming Language :: Python :: 2
Programming Language :: Python :: 2.7
[global]
setup-hooks =
pbr.hooks.setup_hook
[files]
packages =
monasca_log_api
@ -34,5 +37,13 @@ console_scripts =
tempest.test_plugins =
monasca_log_api_tests = monasca_log_api_tempest.plugin:MonascaLogApiTempestPlugin
[build_sphinx]
all_files = 1
build-dir = doc/build
source-dir = doc/source
[wheel]
universal = 1
[pbr]
warnerrors = True

View File

@ -1,7 +1,17 @@
fixtures>=1.3.1
flake8>=2.2.4,<=2.4.1
coverage>=3.6
hacking>=0.10.2,<0.11
mock>=1.2
nose
simplejson
# The order of packages is significant, because pip processes them in the order
# of appearance. Changing the order has an impact on the overall integration
# process, which may cause wedges in the gate later.
# Install bounded pep8/pyflakes first, then let flake8 install
hacking>=0.10.2,<0.11 # Apache-2.0
bandit>=0.17.3 # Apache-2.0
fixtures>=1.3.1,<2.0 # Apache-2.0/BSD
coverage>=3.6 # Apache-2.0
mock>=1.2 # BSD
sphinx>=1.1.2,!=1.2.0,!=1.3b1,<1.3 # BSD
oslosphinx>=2.5.0,!=3.4.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0
os-testr>=0.4.1 # Apache-2.0
simplejson>=2.2.0 # MIT
openstackdocstheme>=1.0.3 # Apache-2.0

30
tools/tox_install.sh Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Client constraint file contains this client version pin that is in conflict
# with installing the client from source. We should remove the version pin in
# the constraints file before applying it for from-source installation.
CONSTRAINTS_FILE=$1
shift 1
set -e
# NOTE(tonyb): Place this in the tox enviroment's log dir so it will get
# published to logs.openstack.org for easy debugging.
localfile="$VIRTUAL_ENV/log/upper-constraints.txt"
if [[ $CONSTRAINTS_FILE != http* ]]; then
CONSTRAINTS_FILE=file://$CONSTRAINTS_FILE
fi
# NOTE(tonyb): need to add curl to bindep.txt if the project supports bindep
curl $CONSTRAINTS_FILE --insecure --progress-bar --output $localfile
pip install -c$localfile openstack-requirements
# This is the main purpose of the script: Allow local installation of
# the current repo. It is listed in constraints file and thus any
# install will be constrained and we need to unconstrain it.
edit-constraints $localfile -- $CLIENT_NAME
pip install -c$localfile -U $*
exit $?

69
tox.ini
View File

@ -1,34 +1,73 @@
[tox]
# TODO(trebskit) Add pypy to envlist ?
envlist = py27,py3,pep8
envlist = py27,pep8,cover
minversion = 2.1
skipsdist = True
[testenv]
usedevelop = True
install_command = pip install -U {opts} {packages}
whitelist_externals = find
setenv = VIRTUAL_ENV={envdir}
OS_TEST_PATH=monasca_log_api/tests
CLIENT_NAME=monasca-log-api
passenv = http_proxy
HTTP_PROXY
https_proxy
HTTPS_PROXY
no_proxy
NO_PROXY
whitelist_externals = bash
find
rm
install_command = {toxinidir}/tools/tox_install.sh {env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
find ./ -type f -name '*.pyc' -delete
nosetests -w monasca_log_api
find ./ -type f -name '*.pyc' -delete
[testenv:pep8]
commands = flake8 monasca_log_api
[testenv:py27]
basepython = python2.7
commands =
{[testenv]commands}
ostestr {posargs}
[testenv:cover]
setenv =
NOSE_WITH_COVERAGE=1
NOSE_COVER_PACKAGE=monasca_log_api
NOSE_COVER_HTML=1
NOSE_COVER_ERASE=1
NOSE_COVER_MIN_PERCENTAGE=95
basepython = python2.7
commands =
{[testenv]commands}
coverage erase
python setup.py test --coverage --testr-args='{posargs}' --coverage-package-name=monasca_log_api
coverage report
[testenv:debug]
commands =
{[testenv]commands}
oslo_debug_helper -t ./monasca_log_api/tests {posargs}
[testenv:bandit]
commands =
# FIXME(dmllr); B101 needs to be fixed first
bandit -r monasca_log_api -n5 -s B101 -x monasca_log_api/tests
[testenv:flake8]
commands =
flake8 monasca_log_api
[testenv:pep8]
deps =
{[testenv]deps}
commands =
{[testenv:flake8]commands}
{[testenv:bandit]commands}
[testenv:docs]
commands =
rm -rf doc/build
python setup.py build_sphinx
[testenv:venv]
commands = {posargs}
[flake8]
exclude = .git,.tox,dist,docs,*.egg,build
exclude = .git,.tox,dist,doc,documentation,*.egg,build
show-source = True
[hacking]