[tox]
envlist = py36,py38,pep8
minversion = 3.1.1
skipsdist = True

[testenv]
setenv = VIRTUAL_ENV={envdir}
         OS_LOG_CAPTURE={env:OS_LOG_CAPTURE:true}
         OS_STDOUT_CAPTURE={env:OS_STDOUT_CAPTURE:true}
         OS_STDERR_CAPTURE={env:OS_STDERR_CAPTURE:true}
         PYTHONWARNINGS=default::DeprecationWarning
usedevelop = True
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/yoga}
       -r{toxinidir}/requirements.txt
       -r{toxinidir}/test-requirements.txt
whitelist_externals = sh
commands =
  stestr run {posargs}
# there is also secret magic in stestr which lets you run in a fail only
# mode. To do this define the TRACE_FAILONLY environmental variable.

[testenv:functional]
deps =
  {[testenv]deps}
  -r{toxinidir}/neutron_vpnaas/tests/functional/requirements.txt
setenv =
  OS_SUDO_TESTING=1
  OS_LOG_PATH={env:OS_LOG_PATH:/opt/stack/logs}
  OS_ROOTWRAP_CMD=sudo {envdir}/bin/neutron-rootwrap {envdir}/etc/neutron/rootwrap.conf
  OS_ROOTWRAP_DAEMON_CMD=sudo {envdir}/bin/neutron-rootwrap-daemon {envdir}/etc/neutron/rootwrap.conf
  OS_FAIL_ON_MISSING_DEPS=1
whitelist_externals =
  sh
  cp
  sudo

[testenv:dev]
# run locally (not in the gate) using editable mode
# https://pip.pypa.io/en/stable/reference/pip_install/#editable-installs
# note that order is important to ensure dependencies don't override
commands =
    pip install -q -e "git+https://opendev.org/openstack/neutron#egg=neutron"

[testenv:py-dev]
commands =
    {[testenv:dev]commands}
    {[testenv]commands}

[testenv:dsvm-functional]
setenv =
  OS_TEST_PATH=./neutron_vpnaas/tests/functional/openswan
  {[testenv:functional]setenv}
deps = {[testenv:functional]deps}
whitelist_externals = {[testenv:functional]whitelist_externals}
commands =
  {toxinidir}/tools/deploy_rootwrap.sh {toxinidir} {envdir}
  stestr run {posargs}

[testenv:dsvm-functional-sswan]
setenv =
  OS_TEST_PATH=./neutron_vpnaas/tests/functional/strongswan
  {[testenv:functional]setenv}
deps = {[testenv:functional]deps}
whitelist_externals = {[testenv:functional]whitelist_externals}
commands =
  {toxinidir}/tools/deploy_rootwrap.sh {toxinidir} {envdir}
  stestr run {posargs}

[testenv:releasenotes]
envdir = {toxworkdir}/docs
deps = {[testenv:docs]deps}
commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html

[testenv:pep8]
deps =
  {[testenv]deps}
  hacking>=4.0.0,<4.1 # Apache-2.0
  flake8-import-order==0.18.1 # LGPLv3
  pylint==2.3.0 # GPLv2
  isort==4.3.21 # MIT
commands =
  flake8
  pylint --rcfile=.pylintrc --output-format=colorized {posargs:neutron_vpnaas}
  {toxinidir}/tools/check_unit_test_structure.sh
  neutron-db-manage --subproject neutron-vpnaas --database-connection sqlite:// check_migration
  {[testenv:genconfig]commands}
  {[testenv:genpolicy]commands}
whitelist_externals = sh

[testenv:pep8-dev]
deps =
    {[testenv:pep8]deps}
commands =
    {[testenv:dev]commands}
    {[testenv:pep8]commands}

[testenv:i18n]
commands = python ./tools/check_i18n.py ./neutron-vpnaas ./tools/i18n_cfg.py

[testenv:cover]
setenv =
    {[testenv]setenv}
    PYTHON=coverage run --source neutron_vpnaas --parallel-mode
commands =
  stestr run --no-subunit-trace {posargs}
  coverage combine
  coverage report --skip-covered
  coverage html -d cover
  coverage xml -o cover/coverage.xml

[testenv:venv]
commands = {posargs}

[testenv:docs]
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/yoga}
       -r{toxinidir}/doc/requirements.txt
commands = sphinx-build -W -a -b html doc/source doc/build/html

[testenv:pdf-docs]
envdir = {toxworkdir}/docs
deps = {[testenv:docs]deps}
whitelist_externals =
  make
commands =
  sphinx-build -W -b latex doc/source doc/build/pdf
  make -C doc/build/pdf

[flake8]
# E125 continuation line does not distinguish itself from next logical line
# E126 continuation line over-indented for hanging indent
# E128 continuation line under-indented for visual indent
# E129 visually indented line with same indent as next logical line
# E265 block comment should start with ‘# ‘
# W504 line break after binary operator
# I202 Additional newline in a group of imports
# H404 multi line docstring should start with a summary
# H405 multi line docstring summary not separated with an empty line
# TODO(dougwig) -- uncomment this to test for remaining linkages
# N530 direct neutron imports not allowed
# N531 Log messages require translation hints
ignore = E125,E126,E128,E129,E265,W504,I202,H404,H405,N530,N531
# H106 Don't put vim configuration in source files
# H203 Use assertIs(Not)None to check for None
# H904 Delay string interpolations at logging calls
enable-extensions=H106,H203,H904
exclude = .venv,.git,.tox,dist,doc,.tmp,*lib/python*,*egg,build,tools,.ropeproject,rally-scenarios
import-order-style = pep8

[hacking]
import_exceptions = neutron_vpnaas._i18n
local-check-factory = neutron_lib.hacking.checks.factory

[testenv:genconfig]
commands = {toxinidir}/tools/generate_config_file_samples.sh

[testenv:genpolicy]
commands = oslopolicy-sample-generator --config-file=etc/oslo-policy-generator/policy.conf
