Merge "Add linters tests"

This commit is contained in:
Jenkins 2016-09-21 08:12:14 +00:00 committed by Gerrit Code Review
commit f6a1449985
4 changed files with 170 additions and 2 deletions

View File

@ -28,7 +28,7 @@ done
ip link set dev docker0 down
brctl delbr docker0
echo DOCKER_OPTS=\"-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock --bip=${FLANNEL_SUBNET} --mtu=${FLANNEL_MTU}\" > /etc/default/docker
echo DOCKER_OPTS=\"-H tcp://127.0.0.1:4243 -H unix:///var/run/docker.sock --bip="${FLANNEL_SUBNET}" --mtu="${FLANNEL_MTU}"\" > /etc/default/docker
echo post-up iptables -t nat -A POSTROUTING -s 10.200.0.0/16 ! -d 10.200.0.0/16 -j MASQUERADE >> /etc/network/interfaces.d/eth0.cfg
iptables -t nat -A POSTROUTING -s 10.200.0.0/16 ! -d 10.200.0.0/16 -j MASQUERADE

69
tools/jenkins/shellcheck.sh Executable file
View File

@ -0,0 +1,69 @@
#!/bin/bash
WORKSPACE="${WORKSPACE:-${1}}"
APP_DIRS="${APP_DIRS:-${2}}"
# SC2001: See if you can use ${variable//search/replace} instead.
# Occasionally a more complex sed substitution is required, so lets igone
# this warning
skip_list='SC2001'
function help_m() {
cat <<-EOF
***********************************************************************
Shellcheck script help message:
Scripts work with files under \${WORKSPACE}/\${APP_DIRS}
Please use env variable:
- Set directory for scan:
export WORKSPACE='/dir/with/sh/files/to/scan'
export APP_DIRS="Applications DockerInterfacesLibrary DockerStandaloneHost Kubernetes"
- or directly:
./shellcheck.sh "/dir/with/sh/files/to/scan" "Applications DockerInterfacesLibrary DockerStandaloneHost Kubernetes"
***********************************************************************
EOF
}
function run_check() {
local e_count=0
for w_dir in ${APP_DIRS}; do
cat <<-EOF
***********************************************************************
*
* Starting shellcheck against dir:"${WORKSPACE}/${w_dir}"
*
***********************************************************************
EOF
while read -d '' -r script; do
unset RESULT
shellcheck "${script}" -e "${skip_list}"
RESULT=$?
if [ ${RESULT} != 0 ]; then
((e_count++))
fi
done < <(find "${WORKSPACE}/${w_dir}" -name '*.sh' -print0)
done
cat <<-EOF
***********************************************************************
*
* shellcheck finished with ${e_count} errors.
*
***********************************************************************
EOF
if [ "${e_count}" -gt 0 ] ; then
exit 1
fi
}
### Body:
if [[ -z "${WORKSPACE}" ]]; then
echo 'ERROR: WORKSPACE variable is not set!'
help_m
exit 1
fi
if [[ -z "${APP_DIRS}" ]]; then
echo 'ERROR: APP_DIRS variable is not set!'
help_m
exit 1
fi
run_check

64
tools/jenkins/yamllint.sh Executable file
View File

@ -0,0 +1,64 @@
#!/bin/bash
WORKSPACE="${WORKSPACE:-${1}}"
APP_DIRS="${APP_DIRS:-${2}}"
function help_m() {
cat <<-EOF
***********************************************************************
Yamllint script help message:
Scripts work with files under \${WORKSPACE}/\${APP_DIRS}
Please use env variable:
- Set directory for scan:
export WORKSPACE='/dir/with/sh/files/to/scan'
export APP_DIRS="Applications DockerInterfacesLibrary DockerStandaloneHost Kubernetes"
- or directly:
./yamllint.sh "/dir/with/sh/files/to/scan" "Applications DockerInterfacesLibrary DockerStandaloneHost Kubernetes"
***********************************************************************
EOF
}
function run_check() {
local e_count=0
for w_dir in ${APP_DIRS}; do
cat <<-EOF
***********************************************************************
*
* Starting yamllint against dir:"${WORKSPACE}/${w_dir}"
*
***********************************************************************
EOF
while read -d '' -r y_file; do
unset RESULT
yamllint -d relaxed "${y_file}"
RESULT=$?
if [ ${RESULT} != 0 ]; then
((e_count++))
fi
done < <(find "${WORKSPACE}/${w_dir}" -name '*.yaml' -print0)
done
cat <<-EOF
***********************************************************************
*
* yamllint finished with ${e_count} errors.
*
***********************************************************************
EOF
if [ "${e_count}" -gt 0 ] ; then
exit 1
fi
}
### Body:
if [[ -z "${WORKSPACE}" ]]; then
echo 'ERROR: WORKSPACE variable is not set!'
help_m
exit 1
fi
if [[ -z "${APP_DIRS}" ]]; then
echo 'ERROR: APP_DIRS variable is not set!'
help_m
exit 1
fi
run_check

37
tox.ini
View File

@ -8,7 +8,9 @@ setenv = VIRTUAL_ENV={envdir}
LANG=en_US.UTF-8
LANGUAGE=en_US:en
LC_ALL=C
passenv = OS_* MURANO* *ENDPOINT*
# to be used in yamllint.sh and shellcheck.sh
APP_DIRS=Applications DockerInterfacesLibrary DockerStandaloneHost Kubernetes
passenv = OS_* MURANO* *ENDPOINT* APPS_DIRS
deps=
-r{toxinidir}/test-requirements.txt
distribute = false
@ -18,3 +20,36 @@ commands = {posargs:}
[testenv:deploy_scale_k8s]
commands = python -m unittest tests.test_k8s_app.MuranoK8sTest.test_deploy_scale_k8s
[testenv:shellcheck]
# 'shellcheck' is not an Python package, so it can be run w\o
# virtual env. But tox is a usable wrapper to run any kind of tests -
# let's use it for common test-run as well - for unification purposes.
whitelist_externals = shellcheck
commands = {toxinidir}/tools/jenkins/shellcheck.sh {toxinidir}
[testenv:yaml-syntaxcheck]
deps = yamllint
commands = {toxinidir}/tools/jenkins/yamllint.sh {toxinidir}
[testenv:linters]
# linters env - it's a combination of check's (usually syntax)
# for aggregate non-destructive run's. Used only in openstack-infra ci for
# decrease resource usage.
# Current duplicate list:
# shellcheck
# yaml-syntaxcheck
#
# We need to suppress exit code from 'command1', to be able run 'command2';
# Otherwise, if some command failed - exit code from tox itself will be 1
ignore_errors=True
deps = yamllint
murano-pkg-check
whitelist_externals = shellcheck
commands = {toxinidir}/tools/jenkins/shellcheck.sh {toxinidir}
{toxinidir}/tools/jenkins/yamllint.sh {toxinidir}
murano-pkg-check --verbose --debug --discover {toxinidir}
[testenv:murano-pkg-check]
deps = murano-pkg-check
commands = murano-pkg-check --verbose --debug --discover {toxinidir}