[tox]
minversion = 3.18.0
envlist = py39,pypy,pep8
skipsdist = True

[testenv]
usedevelop = True
setenv =
   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
deps = -c{env:TOX_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/upper/2023.1}
       -r{toxinidir}/requirements.txt
       -r{toxinidir}/test-requirements.txt
commands = stestr run {posargs}

# Common definitions shared between dsvm/non-dsvm jobs
[testenv:common]
setenv = OS_TEST_TIMEOUT=180

# Common definitions shared among dsvm jobs
[testenv:dsvm]
setenv = OS_FAIL_ON_MISSING_DEPS=1
         OS_LOG_PATH={env:OS_LOG_PATH:/opt/stack/logs}

[testenv:functional]
setenv = {[testenv]setenv}
         {[testenv:common]setenv}
         OS_TEST_PATH=./networking_bagpipe/tests/functional
         OS_LOG_PATH={env:OS_LOG_PATH:/opt/stack/logs}
deps =
  {[testenv]deps}
  -r{toxinidir}/networking_bagpipe/tests/functional/requirements.txt

[testenv:dsvm-functional]
setenv = {[testenv:functional]setenv}
         {[testenv:dsvm]setenv}
sitepackages = True
deps =
  {[testenv:functional]deps}
commands = stestr run {posargs}

[testenv:dsvm-fullstack]
setenv = {[testenv]setenv}
         {[testenv:common]setenv}
         {[testenv:dsvm]setenv}
         # workaround for DB teardown lock contention (bug/1541742)
         OS_TEST_TIMEOUT=600
         OS_TEST_PATH=./networking_bagpipe/tests/fullstack
deps =
  {[testenv:functional]deps}

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

[testenv:pep8]
commands =
    flake8
    pylint -E --rcfile=.pylintrc --output-format=colorized {posargs:networking_bagpipe}
    neutron-db-manage --subproject networking-bagpipe --database-connection sqlite:// check_migration
    {[testenv:genconfig]commands}
allowlist_externals =
    {toxinidir}/tools/generate_config_file_samples.sh

[testenv:venv]
commands = {posargs}

[testenv:cover]
setenv =
    PYTHON = coverage run --source networking_bagpipe --parallel-mode
commands =
    stestr run {posargs}
    coverage combine
    coverage html -d cover
    coverage xml -o cover/coverage.xml

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

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

[testenv:debug]
commands = oslo_debug_helper {posargs}

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

[flake8]
show-source = True
enable-extensions = H203,H904
builtins = _
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,.tmp,bagpipe-bgp/*

[flake8:local-plugins]
extension =
  # Checks from neutron-lib
  N521 = neutron_lib.hacking.checks:use_jsonutils
  N524 = neutron_lib.hacking.checks:check_no_contextlib_nested
  N529 = neutron_lib.hacking.checks:no_mutable_default_args
  N532 = neutron_lib.hacking.translation_checks:check_log_warn_deprecated
  N536 = neutron_lib.hacking.checks:assert_equal_none
  N537 = neutron_lib.hacking.translation_checks:no_translate_logs

[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/networking-bgpvpn#egg=networking_bgpvpn"
    pip install -q -e "git+https://opendev.org/openstack/networking-sfc#egg=networking_sfc"
    pip install -q -e "git+https://opendev.org/openstack/neutron#egg=neutron"

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

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