Add and run some linters via tox and pre-commit
[transportpce.git] / tox.ini
diff --git a/tox.ini b/tox.ini
index 325dc7d09b09b45d6367ff73dde58bc975dc4007..59e210daf700409038b7f3aa8f8270ffced5c5d5 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -3,63 +3,173 @@ minversion = 1.6
 envlist = py3
     docs
     docs-linkcheck
+    checkbashisms
+    pre-commit
+    gitlint
 skipsdist = true
 setupdir = tests/
 
 [testenv]
-passenv = USE_LIGHTY
+passenv = USE_LIGHTY http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
+setenv =
+    USE_LIGHTY = True
 usedevelop = True
 basepython = python3
 deps =
   -r{toxinidir}/tests/requirements.txt
   -r{toxinidir}/tests/test-requirements.txt
-whitelist_externals = bash
+whitelist_externals = sh
                       sudo
 changedir={toxinidir}/tests
 commands =
 #install maven and JDK11 on the Gate since they are not there by default
-  {py3,portmapping,topoPortMapping,rspn,topology,pce,olm,end2end,portmapping221,rspn221,otnrenderer,topology221,otntopology,olm221,end2end221,gnpy}: - bash -c "if [ ! `which mvn` ]; then ./installMavenCentOS.sh  ; fi"
-#build 1.2.1 sims
-  {py3,portmapping,topoPortMapping,rspn,topology,olm,end2end}: - bash -c "./buildHoneynode.sh"
+  {py3,portmapping,topoPortMapping,rspn,topology,pce,olm,end2end,portmapping221,rspn221,otnrenderer,otnshrenderer,topology221,otntopology,flexgrid,olm221,tapi221,otnend2end,end2end221,pce400g,gnpy,devicenotif}: - sh -c "which mvn >/dev/null || ./installMavenCentOS.sh"
+#install honeynode 1.2.1 simulators
+  {py3,portmapping,topoPortMapping,rspn,topology,pce,olm,end2end,devicenotif}: - sh -c "./install_honeynode.sh 1.2.1"
 #patch OLM constant to speed up tests, unnecessary for PCE
-  {py3,portmapping,topoPortMapping,rspn,topology,olm,end2end,portmapping221,rspn221,otnrenderer,topology221,otn-topology,olm221,end2end221}: - bash -c "sed -i' ' 's@=.*//#FUNCTESTVAL=@=@g' ../olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java"
+  {py3,portmapping,topoPortMapping,rspn,topology,olm,end2end,portmapping221,rspn221,otnrenderer,otnshrenderer,topology221,olm221,otnend2end,end2end221,tapi221,nbinotifications,devicenotif}: - sh -c "sed -i'_' 's@=.*//#FUNCTESTVAL=@=@g' ../olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java"
 #build controller, source JDK_JAVA_OPTIONS to remove illegal reflective acces warnings introduced by Java11
-  {py3,portmapping,topoPortMapping,rspn,topology,pce,olm,end2end,portmapping221,rspn221,otnrenderer,topology221,otntopology,olm221,end2end221,gnpy}: - bash -c ". reflectwarn.sh && cd .. && mvn clean install -s tests/odl_settings.xml -DskipTests -Dmaven.javadoc.skip=true -Dodlparent.spotbugs.skip -Dodlparent.checkstyle.skip"
+  {py3,portmapping,topoPortMapping,rspn,topology,pce,olm,end2end,portmapping221,rspn221,otnrenderer,otnshrenderer,topology221,otntopology,flexgrid,olm221,tapi221,otnend2end,end2end221,pce400g,gnpy,nbinotifications,devicenotif}: - sh -c ". $PWD/reflectwarn.sh && cd .. && mvn clean install -B -q -s tests/odl_settings.xml -DskipTests -Dmaven.javadoc.skip=true -Dodlparent.spotbugs.skip -Dodlparent.checkstyle.skip"
+  {py3,portmapping,topoPortMapping,rspn,topology,olm,end2end,portmapping221,rspn221,otnrenderer,otnshrenderer,topology221,olm221,otnend2end,end2end221,tapi221,nbinotifications,devicenotif}: - sh -c "mv  ../olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java_  ../olm/src/main/java/org/opendaylight/transportpce/olm/util/OlmUtils.java"
 #patch Karaf exec for the same reason at runtime
-  {py3,portmapping,topoPortMapping,rspn,topology,pce,olm,end2end,portmapping221,rspn221,otnrenderer,topology221,otntopology,olm221,end2end221,gnpy}: - bash -c "sed -i' ' 's@!/bin/sh@!/bin/sh\n. $(dirname $0)/../../../../tests/reflectwarn.sh@' ../karaf/target/assembly/bin/karaf"
+  {py3,portmapping,topoPortMapping,rspn,topology,pce,olm,end2end,portmapping221,rspn221,otnrenderer,otnshrenderer,topology221,otntopology,flexgrid,olm221,tapi221,otnend2end,end2end221,pce400g,gnpy,nbinotifications,devicenotif}: - sh -c "sed -i'_' 's@!/bin/sh@!/bin/sh\'$'\n. $(dirname $0)/../../../../tests/reflectwarn.sh@' ../karaf/target/assembly/bin/karaf"
+  # the following command would be the straight and right way to support both BSD and GNU sed versions
+  # sh -c "sed -i'_' '1 a\'$'\n. \$(dirname \$0)/\.\./\.\./\.\./\.\./tests/reflectwarn.sh\n' ../karaf/target/assembly/bin/karaf"
+  # but tox reinterprets the quotes as
+  # sh -c 'sed -i'"'"'_'"'"' '"'"'1 a\'"'"'$'"'"'\n. \$(dirname \$0)/\.\./\.\./\.\./\.\./tests/reflectwarn.sh\n'"'"' ../karaf/target/assembly/bin/karaf'
+  # ,what results in an unexpected different formating (with a $ on the second line and the dot on the third)
 #build Lighty if needed
-  {py3,portmapping,topoPortMapping,rspn,topology,pce,olm,end2end,portmapping221,rspn221,otnrenderer,topology221,otntopology,olm221,end2end221,gnpy}: - bash -c 'if [ "$USE_LIGHTY" == "True" ]; then (cd ../lighty && ./build.sh); fi'
+  {py3,portmapping,topoPortMapping,rspn,topology,pce,olm,end2end,portmapping221,rspn221,otnrenderer,otnshrenderer,topology221,otntopology,olm221,tapi221,otnend2end,end2end221,pce400g,gnpy,nbinotifications,devicenotif}: - sh -c 'if [ "$USE_LIGHTY" = "True" ]; then (cd ../lighty && ./build.sh); fi'
 #run 1.2.1 functional tests
   {py3,portmapping}: nosetests --with-xunit transportpce_tests/1.2.1/test_portmapping.py
-  {py3,topoPortMapping}: nosetests --with-xunit transportpce_tests/1.2.1/test_topoPortMapping.py
+  {py3,topoPortMapping}: nosetests --with-xunit transportpce_tests/1.2.1/test_topo_portmapping.py
   {py3,topology}: nosetests --with-xunit transportpce_tests/1.2.1/test_topology.py
   {py3,rspn}: nosetests --with-xunit transportpce_tests/1.2.1/test_renderer_service_path_nominal.py
   {py3,pce}: nosetests --with-xunit transportpce_tests/1.2.1/test_pce.py
   {py3,olm}: nosetests --with-xunit transportpce_tests/1.2.1/test_olm.py
-  {end2end}: nosetests --with-xunit transportpce_tests/1.2.1/test_end2end.py
-#build 2.2.1 sims
-  {py3,portmapping221,rspn221,otnrenderer,topology221,otntopology,olm221,end2end221}: - bash -c "./buildHoneynode.sh 2.2.1"
+  #E2E 1.2.1 moved at the end before 2.2.1 E2E
 #run 2.2.1 functional tests
+#install honeynode 2.2.1 simulators
+  {py3,portmapping221,rspn221,otnrenderer,otnshrenderer,topology221,otntopology,flexgrid,olm221,tapi221,otnend2end,end2end221,nbinotifications,devicenotif}: - sh -c "./install_honeynode.sh 2.2.1"
   {py3,portmapping221}: nosetests --with-xunit transportpce_tests/2.2.1/test_portmapping.py
   {py3,topology221}: nosetests --with-xunit transportpce_tests/2.2.1/test_topology.py
-  {otntopology}: nosetests --with-xunit transportpce_tests/2.2.1/test_otn_topology.py
+  {py3,otntopology}: nosetests --with-xunit transportpce_tests/2.2.1/test_otn_topology.py
+  {py3,flexgrid}: nosetests --with-xunit transportpce_tests/2.2.1/test_flex_grid.py
   {py3,rspn221}: nosetests --with-xunit transportpce_tests/2.2.1/test_renderer_service_path_nominal.py
   {py3,otnrenderer}: nosetests --with-xunit transportpce_tests/2.2.1/test_otn_renderer.py
+  {py3,otnshrenderer}: nosetests --with-xunit transportpce_tests/2.2.1/test_otn_sh_renderer.py
   {py3,olm221}: nosetests --with-xunit transportpce_tests/2.2.1/test_olm.py
-  {end2end221}: nosetests --with-xunit transportpce_tests/2.2.1/test_end2end.py
+  {py3,tapi221}: nosetests --with-xunit transportpce_tests/2.2.1/test_tapi.py
+  {py3,otnend2end}: nosetests --with-xunit transportpce_tests/2.2.1/test_otn_end2end.py
+#run 7.1 functional tests
+  {py3,pce400g}: nosetests --with-xunit transportpce_tests/7.1/test_pce_400G.py
+#install honeynode 7.1 simulators
+  {py3,portmapping71,devicenotif}: - sh -c "./install_honeynode.sh 7.1"
+  {py3,portmapping71}: nosetests --with-xunit transportpce_tests/7.1/test_portmapping.py
+#End-to-End
+  {py3,end2end}: nosetests --with-xunit transportpce_tests/1.2.1/test_end2end.py
+  {py3,end2end221}: nosetests --with-xunit transportpce_tests/2.2.1/test_end2end.py
   #{gnpy}: - sudo docker pull atriki/gnpyrest:v1.2
   {gnpy}: - sudo docker run -d -p 8008:5000 --name gnpy_tpce_rest1 atriki/gnpyrest:v1.2
   {gnpy}: nosetests --with-xunit transportpce_tests/1.2.1/test_gnpy.py
   {gnpy}: - sudo docker container rm -f gnpy_tpce_rest1
+  {nbinotifications}: - sudo docker-compose -f ./nbinotifications/docker-compose.yml up -d
+  {nbinotifications}: nosetests --with-xunit transportpce_tests/2.2.1/test_nbinotifications.py
+  {nbinotifications}: - sudo docker-compose -f ./nbinotifications/docker-compose.yml down --rmi all
+# Hybrid tests
+  {py3,devicenotif}: nosetests --with-xunit transportpce_tests/hybrid/test_device_change_notifications.py
 
 [testenv:docs]
+passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
 basepython = python3
 deps = -rdocs/requirements.txt
 commands =
-    sphinx-build -W -b html -n -d {envtmpdir}/doctrees ../docs/ {toxinidir}/docs/_build/html
+    sphinx-build -q -W -b html -n -d {envtmpdir}/doctrees ../docs/ {toxinidir}/docs/_build/html
 
 [testenv:docs-linkcheck]
+passenv = http_proxy HTTP_PROXY https_proxy HTTPS_PROXY no_proxy NO_PROXY
 basepython = python3
 deps = -rdocs/requirements.txt
-commands = sphinx-build -W -b linkcheck -d {envtmpdir}/doctrees ../docs/ {toxinidir}/docs/_build/linkcheck
+commands = sphinx-build -q -b linkcheck -d {envtmpdir}/doctrees ../docs/ {toxinidir}/docs/_build/linkcheck
+
+[testenv:checkbashisms]
+deps =
+whitelist_externals = sh
+                      checkbashisms
+                      sudo
+                      find
+commands =
+    sh -c 'command checkbashisms>/dev/null || sudo yum install devscripts-minimal || (echo "checkbashisms command not found - please install it (e.g. sudo apt-get install devscripts | yum install devscripts-minimal )" >&2 && exit 1)'
+    find . -not -path '*/\.*' -name *.sh -exec checkbashisms -f  \{\} +
+
+[testenv:spelling]
+basepython = python3
+deps =
+    -rdocs/requirements.txt
+    sphinxcontrib-spelling
+    PyEnchant
+commands = sphinx-build -b spelling  -d {envtmpdir}/doctrees ../docs/ {toxinidir}/docs/_build/spelling
+
+[testenv:autopep8]
+basepython = python3
+deps = autopep8
+commands =
+    autopep8 --max-line-length 120 --in-place --recursive transportpce_tests/
+
+[testenv:pylint]
+basepython = python3
+deps = pylint
+whitelist_externals = find
+commands =
+    find transportpce_tests/ -name *.py -exec pylint --max-line-length=120 --disable=missing-docstring --method-rgx="(([a-z_][a-zA-Z0-9_]{2,})|(_[a-z0-9_]*)|(__[a-zA-Z][a-zA-Z0-9_]+__))$" --variable-rgx="[a-zA-Z_][a-zA-Z0-9_]{1,30}$" --reports=y --score=y  --output-format=colorized  \{\} +
+
+[testenv:pyang]
+basepython = python3
+deps = pyang
+whitelist_externals = find
+commands =
+    pyang --version
+    find ../api/ -name target -prune -o -name *.yang -exec pyang --lint --canonical --max-line-length=120 -p../api/src/main/yang/:../ordmodels/common/src/main/yang/:../ordmodels/service/src/main/yang/:../tapimodels/src/main/yang/ \{\} +
+#find ../api/ ../ordmodels/ ../tapimodels/ -name target -prune -o -name *.yang -exec pyang --lint --canonical --max-line-length=120 -p../api/src/main/yang/:../ordmodels/common/src/main/yang/:../ordmodels/service/src/main/yang/:../tapimodels/src/main/yang/ \{\} +
+
+[testenv:pyangformat]
+basepython = python3
+deps = pyang
+whitelist_externals = sh
+commands =
+    pyang --version
+    sh -c 'find ../api/ -name target -prune -o -name *.yang -print | while read -r fname; do pyang -f yang --yang-canonical --yang-remove-unused-imports --max-line-length=120 --keep-comments -p../api/src/main/yang/:../ordmodels/common/src/main/yang/:../ordmodels/service/src/main/yang/:../tapimodels/src/main/yang/ "$fname"  -o /tmp/tmpfile.$$ && mv /tmp/tmpfile.$$ "$fname";done'
+
+[testenv:pre-commit-install]
+basepython = python3
+deps = pre-commit
+commands =
+    pre-commit install
+    pre-commit install --hook-type commit-msg
+
+[testenv:pre-commit-uninstall]
+basepython = python3
+deps = pre-commit
+commands =
+    pre-commit uninstall
+    pre-commit uninstall --hook-type commit-msg
+
+[testenv:pre-commit]
+basepython = python3
+deps = pre-commit
+passenv = HOME
+commands =
+    pre-commit run --all-files --show-diff-on-failure
+    pre-commit run gitlint --hook-stage commit-msg --commit-msg-filename .git/COMMIT_EDITMSG
+    # Gitlint only proposes a pre-commit configuration for the commit-msg stage but none for the commit stage.
+    # Its default arguments --passed and --msg-filename are different from CI recommandations.
+    # As a result, the line above is always skipped in jenkins CI since there cannot be a .git/COMMIT_EDITMSG file.
+    # A dedicated gitlint profile for CI is proposed below. Also to behave fine locally, this profile must have access
+    # to the HOME variable so that Gitlint can retrieve Git user settings.
+
+[testenv:gitlint]
+basepython = python3
+deps = gitlint
+commands =
+    gitlint