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

Change-Id: I2a21f9cee0e00f7148142465a8fc131ef4ff6f44
This commit is contained in:
Tomasz Trębski 2017-01-12 13:42:37 +01:00
parent beb9497ebc
commit 04030115db
20 changed files with 165 additions and 249 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

@ -121,7 +121,8 @@ To run all the unit test cases, run the following command from the root
directory of this project:
```sh
tox -e py27 (or -e py26, -e py33)
tox -e py27
tox -e py35
```
### Coverage
@ -147,7 +148,7 @@ To generate documentation, run the following command from the root
directory of this project:
```sh
make html
tox -e docs
```
That will create documentation under build folder relative to root of the
@ -177,7 +178,7 @@ Requests flow through the following architectural layers from top to bottom:
# License
# Copyright 2015 kornicameister@gmail.com
# Copyright 2015 FUJITSU LIMITED
# Copyright 2015-2017 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain

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,12 @@ 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',
'oslo_config.sphinxconfiggen'
]
# Add any paths that contain templates here, relative to this directory.
@ -55,17 +54,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.3'
version = '1.3.0'
# The full version, including alpha/beta/rc tags.
release = 'stable/mitaka'
release = 'stable/ocata'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
@ -84,7 +83,7 @@ language = None
# directories to ignore when looking for source files.
exclude_patterns = [
'common',
'docs',
'doc',
'documentation',
'etc',
'java'
@ -99,17 +98,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 +121,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 +143,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 +160,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 +244,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 +288,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 +306,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,6 +20,14 @@ monasca_log_api.api.headers module
:undoc-members:
:show-inheritance:
monasca_log_api.api.healthcheck_api module
------------------------------------------
.. automodule:: monasca_log_api.api.healthcheck_api
:members:
:undoc-members:
:show-inheritance:
monasca_log_api.api.logs_api module
-----------------------------------

View File

@ -4,6 +4,13 @@ monasca_log_api.v2.common package
Submodules
----------
monasca_log_api.v2.common.error_handlers module
-----------------------------------------------
.. automodule:: monasca_log_api.reference.common.error_handlers
:members:
:undoc-members:
:show-inheritance:
monasca_log_api.v2.common.log_publisher module
----------------------------------------------

View File

@ -22,4 +22,3 @@ monasca_log_api.reference.v3 module
:undoc-members:
:show-inheritance:

View File

@ -66,7 +66,7 @@ by monasca-log-api
in given case. However two mentioned in this documentation are required.
All fields, apart from **creation_time** and **log**, are created from HTTP headers.
Description is available [here](/docs/monasca-log-api-spec.md).
Description is available [here](/documentation/monasca-log-api-spec.md).
## Truncating too large message
@ -127,7 +127,7 @@ There are only two relevant options:
* topics - comma delimited list of topics where data should be sent
* kafka_url - adress where kafka server is running
# Copyright 2016 FUJITSU LIMITED
# Copyright 2016-2017 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain

View File

@ -76,7 +76,7 @@ to recover from error situation
### monasca.log.out_logs_truncated_bytes
Metric is sent with the amount of bytes that log's message is shorten
by if necessary. To read more about truncation see [here](/docs/monasca-log-api-kafka.md).
by if necessary. To read more about truncation see [here](/documentation/monasca-log-api-kafka.md).
If truncation did not happen, which should be normal situation for most
of the time, metric is updated with value **0**.
@ -92,3 +92,17 @@ processing.
Total amount of time logs spent inside **Log-API**. Metric does not
include time needed to communicate with Keystone to authenticate request.
As far as possible it is meant to track **Log-API** itself
# Copyright 2016-2017 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -195,7 +195,7 @@ Cache-Control: no-cache
#### Response Body
This request does not return a response body.
# Copyright 2016 FUJITSU LIMITED
# Copyright 2016-2017 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain

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
@ -35,5 +38,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

@ -9,5 +9,9 @@ bandit>=1.1.0 # Apache-2.0
fixtures>=3.0.0 # Apache-2.0/BSD
coverage>=4.0 # Apache-2.0
mock>=2.0 # BSD
nose # LGPL
sphinx!=1.3b1,<1.4,>=1.2.1 # BSD
oslosphinx>=4.7.0 # Apache-2.0
oslotest>=1.10.0 # Apache-2.0
os-testr>=0.8.0 # Apache-2.0
simplejson>=2.2.0 # MIT
openstackdocstheme>=1.5.0 # Apache-2.0

91
tox.ini
View File

@ -1,46 +1,89 @@
[tox]
# TODO(trebskit) Add pypy to envlist ?
envlist = py27,py3,pep8
envlist = py27,pep8,cover
minversion = 2.1
skipsdist = True
[testenv]
usedevelop = True
setenv =
CLIENT_NAME=monasca-log-api
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}
whitelist_externals = find
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
commands =
find ./ -type f -name '*.pyc' -delete
nosetests monasca_log_api --verbose
find ./ -type f -name '*.pyc' -delete
[testenv:py27]
basepython = python2.7
commands =
{[testenv]commands}
ostestr {posargs}
[testenv:py35]
basepython = python3.5
commands =
{[testenv]commands}
ostestr {posargs}
[testenv:cover]
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:bashate]
deps = bashate
whitelist_externals = bashate
commands =
# Ignore too long lines error E006 from bashate and treat
# E005, E042 as errors.
bashate -v -iE006 -eE005,E042 devstack/plugin.sh
[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 =
bashate
{[testenv]deps}
whitelist_externals = bashate
{[testenv]deps}
{[testenv:bashate]deps}
commands =
flake8 monasca_log_api
# Ignore too long lines error E006 from bashate and treat
# E005, E042 as errors.
bashate -v -iE006 -eE005,E042 devstack/plugin.sh
# FIXME(dmllr); B101 needs to be fixed first
bandit -r monasca_log_api -n5 -s B101 -x monasca_log_api/tests
{[testenv:flake8]commands}
{[testenv:bandit]commands}
{[testenv:bashate]commands}
[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
[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]