Update flake8 to verify patch scripts

To prevent the warning about a newer version of pip
available, the following env setting was added

  PIP_DISABLE_PIP_VERSION_CHECK=1

To prevent sub-calls to tox from using the default pip
cache location, rather than whatever a user may override
using xdg env variables, the following has been added:

  passenv =
      XDG_CACHE_HOME

The python patch scripts are now validated by flake8.
All flake8 tox targets are triggered from a single zuul job.

Story: 2004515
Task: 38581
Change-Id: I105512edbd3da15480355e30c0dd14933584a47b
Signed-off-by: albailey <Al.Bailey@windriver.com>
This commit is contained in:
albailey 2020-01-30 08:54:25 -06:00
parent da4662673c
commit e3be9a2776
9 changed files with 67 additions and 58 deletions

View File

@ -8,11 +8,10 @@
jobs:
- openstack-tox-linters
- py3-bandit
- patch-tox-flake8
- py3-flake8
- patch-tox-pylint
- patch-tox-py27
- patch-tox-py36
- patch-alarm-tox-flake8
- patch-alarm-tox-pylint
- patch-alarm-tox-py27
- patch-alarm-tox-py36
@ -20,11 +19,10 @@
jobs:
- openstack-tox-linters
- py3-bandit
- patch-tox-flake8
- py3-flake8
- patch-tox-pylint
- patch-tox-py27
- patch-tox-py36
- patch-alarm-tox-flake8
- patch-alarm-tox-pylint
- patch-alarm-tox-py27
- patch-alarm-tox-py36
@ -36,16 +34,13 @@
tox_envlist: bandit
- job:
name: patch-tox-flake8
name: py3-flake8
parent: tox
required-projects:
- starlingx/config
- starlingx/fault
files:
- cgcs-patch/cgcs-patch/*
vars:
tox_envlist: flake8
tox_extra_args: -c cgcs-patch/cgcs-patch/tox.ini
- job:
name: patch-tox-pylint
@ -83,18 +78,6 @@
tox_envlist: py36
tox_extra_args: -c cgcs-patch/cgcs-patch/tox.ini
- job:
name: patch-alarm-tox-flake8
parent: tox
required-projects:
- starlingx/config
- starlingx/fault
files:
- patch-alarm/patch-alarm/*
vars:
tox_envlist: flake8
tox_extra_args: -c patch-alarm/patch-alarm/tox.ini
- job:
name: patch-alarm-tox-pylint
parent: tox

View File

@ -23,8 +23,12 @@ setenv = VIRTUAL_ENV={envdir}
PYTHONDONTWRITEBYTECODE=1
PYTHONHASHSEED=0
PYTHONWARNINGS=default::DeprecationWarning
PIP_DISABLE_PIP_VERSION_CHECK=1
sitepackages = True
passenv =
XDG_CACHE_HOME
sitepackages = False
install_command = pip install \
-v -v -v \
-c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/openstack/requirements/raw/branch/stable/stein/upper-constraints.txt} \

View File

@ -23,8 +23,12 @@ setenv = VIRTUAL_ENV={envdir}
PYTHONDONTWRITEBYTECODE=1
PYTHONHASHSEED=0
PYTHONWARNINGS=default::DeprecationWarning
PIP_DISABLE_PIP_VERSION_CHECK=1
sitepackages = True
passenv =
XDG_CACHE_HOME
sitepackages = False
install_command = pip install \
-v -v -v \
-c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/openstack/requirements/raw/branch/stable/stein/upper-constraints.txt} \

View File

@ -6,7 +6,8 @@ SPDX-License-Identifier: Apache-2.0
"""
from kubernetes import client, config
from kubernetes import client
from kubernetes import config
from distutils.version import LooseVersion
@ -37,19 +38,19 @@ def get_kube_apiserver_versions():
def main():
running_versions = get_kube_apiserver_versions()
if len(running_versions) is 0:
if len(running_versions) == 0:
fatal_error("Could not determine kube-apiserver version")
# Running version must be at least v1.16.1
test_version = 'v1.16.1'
for running_version in running_versions:
if LooseVersion(running_version) < LooseVersion(test_version):
fatal_error("A kube-apiserver is running %s, but must be at least %s" %
(running_version, test_version))
fatal_error("A kube-apiserver is running %s, but must be"
" at least %s" % (running_version, test_version))
# Success
sys.exit(0)
if __name__ == '__main__':
main()

View File

@ -6,7 +6,8 @@ SPDX-License-Identifier: Apache-2.0
"""
from kubernetes import client, config
from kubernetes import client
from kubernetes import config
from distutils.version import LooseVersion
@ -37,20 +38,19 @@ def get_kube_apiserver_versions():
def main():
running_versions = get_kube_apiserver_versions()
if len(running_versions) is 0:
if len(running_versions) == 0:
fatal_error("Could not determine kube-apiserver version")
# Running version must be no higher than v1.16.1
test_version = 'v1.16.1'
for running_version in running_versions:
if LooseVersion(running_version) > LooseVersion(test_version):
fatal_error("A kube-apiserver is running %s, but must be no higher than %s" %
(running_version, test_version))
fatal_error("A kube-apiserver is running %s, but must be no higher"
" than %s" % (running_version, test_version))
# Success
sys.exit(0)
if __name__ == '__main__':
main()

View File

@ -6,7 +6,8 @@ SPDX-License-Identifier: Apache-2.0
"""
from kubernetes import client, config
from kubernetes import client
from kubernetes import config
from distutils.version import LooseVersion
@ -37,20 +38,19 @@ def get_kube_apiserver_versions():
def main():
running_versions = get_kube_apiserver_versions()
if len(running_versions) is 0:
if len(running_versions) == 0:
fatal_error("Could not determine kube-apiserver version")
# Running version must be at least v1.16.2
test_version = 'v1.16.2'
for running_version in running_versions:
if LooseVersion(running_version) < LooseVersion(test_version):
fatal_error("A kube-apiserver is running %s, but must be at least %s" %
(running_version, test_version))
fatal_error("A kube-apiserver is running %s, but must be"
" at least %s" % (running_version, test_version))
# Success
sys.exit(0)
if __name__ == '__main__':
main()

View File

@ -6,7 +6,8 @@ SPDX-License-Identifier: Apache-2.0
"""
from kubernetes import client, config
from kubernetes import client
from kubernetes import config
from distutils.version import LooseVersion
@ -37,21 +38,19 @@ def get_kube_apiserver_versions():
def main():
running_versions = get_kube_apiserver_versions()
if len(running_versions) is 0:
if len(running_versions) == 0:
fatal_error("Could not determine kube-apiserver version")
# Running version must be no higher than v1.16.2
test_version = 'v1.16.2'
for running_version in running_versions:
if LooseVersion(running_version) > LooseVersion(test_version):
fatal_error("A kube-apiserver is running %s, but must be no higher than %s" %
(running_version, test_version))
fatal_error("A kube-apiserver is running %s, but must be"
" no higher than %s" % (running_version, test_version))
# Success
sys.exit(0)
if __name__ == '__main__':
main()

View File

@ -1,7 +1,7 @@
hacking>=2.0<2.1
pycodestyle>=2.0.0 # MIT License
mock>=2.0.0 # BSD
bashate >= 0.2
PyYAML >= 3.1.0
yamllint >= 0.5.2
hacking!=0.13.0,<0.14,>=0.12.0
# The following are for py27 and py36
#mock # BSD
#nose # LGPL

34
tox.ini
View File

@ -14,28 +14,40 @@ minversion = 2.3
skipsdist = True
[testenv]
install_command = pip install -U {opts} {packages}
setenv = VIRTUAL_ENV={envdir}
OS_STDOUT_CAPTURE=1
OS_STDERR_CAPTURE=1
OS_TEST_TIMEOUT=60
PYTHONDONTWRITEBYTECODE=True
cgcs_patch_dir = {toxinidir}/cgcs-patch/cgcs-patch
cgcs_patch_src_dir = {[testenv]cgcs_patch_dir}/cgcs_patch
patch_alarm_dir = {toxinidir}/patch-alarm/patch-alarm
patch_alarm_src_dir = {[testenv]patch_alarm_dir}/patch_alarm
setenv =
VIRTUAL_ENV={envdir}
OS_STDOUT_CAPTURE=1
OS_STDERR_CAPTURE=1
OS_TEST_TIMEOUT=60
PYTHONDONTWRITEBYTECODE=True
PIP_DISABLE_PIP_VERSION_CHECK=1
passenv =
XDG_CACHE_HOME
commands = find {toxinidir} -type f -not -path '{toxinidir}/.tox/*' -not -path '*/__pycache__/*' -name '*.py[c|o]' -delete
install_command = pip install -U \
-c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/openstack/requirements/raw/branch/stable/stein/upper-constraints.txt} \
{opts} {packages}
deps = -r{toxinidir}/requirements.txt
-r{toxinidir}/test-requirements.txt
-e{[testenv]cgcs_patch_dir}
-e{[testenv]patch_alarm_dir}
whitelist_externals = find
[testenv:linters]
basepython = python3
whitelist_externals = bash
commands =
bash -c "find {toxinidir} \
bash -c "find {toxinidir} \
-not \( -type d -name .?\* -prune \) \
-type f \
-not -name \*~ \
@ -46,12 +58,17 @@ commands =
-wholename \*/devstack/\* \
\) \
-print0 | xargs -0 bashate -v -e 'E*' -iE006"
bash -c "find {toxinidir} \
bash -c "find {toxinidir} \
\( -name .tox -prune \) \
-o -type f -name '*.yaml' \
-print0 | xargs -0 yamllint"
[flake8]
filename=
*.preapply
*.preremove
[testenv:flake8]
basepython = python3
whitelist_externals = cp
find
@ -60,6 +77,7 @@ recreate = True
commands = {[testenv]commands}
tox -c cgcs-patch/cgcs-patch -e flake8
tox -c patch-alarm/patch-alarm -e flake8
flake8 {toxinidir}/patch-scripts/kube-upgrade
[testenv:venv]
basepython = python3