
This change introduces a testing framework for the dynamic_inventory.py script, which will be helpful in debugging any changes made to the script. Current testing is indirect, relying on the other, very high level gate tests, which may take longer to identify inventory generation issues. Currently, it does not do actual unit testing, instead opting to start by testing from 'outside', calling the script through a subprocess. In time, this should be replaced, but as a start it's easier to implement without making many changes. The 'tests/inventory' directory has the necessary pieces symlinked in; namely, env.d, openstack_environment.yml, and a sample openstack_user-config.yml (based on the AIO one already used in the gates). A new tox environment, 'inventory' was added rather than creating a new 'gate-check-inventory.sh' file. This should fit the general openstack-infra testing framework better. For the first test, I decided to add a loop that runs 100 times because of the nature of the script. Since the dynamic_inventory script does not assign IP addresses sequentially, the loop helps exercise a larger sample than just one run per test. On my local machine, this took approximately 2 seconds. Running it 1,000 times took about 30 seconds. Thus, the time spent right now is minimal in comparison to the rest of the gate jobs. As it stands, the test suite is by no means complete, but serves as a starting point. Change-Id: I7410360ecec919639a299f72f2f3cc818bce8e33
121 lines
3.6 KiB
INI
121 lines
3.6 KiB
INI
[tox]
|
|
minversion = 1.6
|
|
skipsdist = True
|
|
envlist = docs,linters,releasenotes,inventory
|
|
|
|
[testenv]
|
|
usedevelop = True
|
|
install_command = pip install -U {opts} {packages}
|
|
setenv = VIRTUAL_ENV={envdir}
|
|
deps = -r{toxinidir}/test-requirements.txt
|
|
|
|
[testenv:releasenotes]
|
|
commands = sphinx-build -a -E -W -d releasenotes/build/doctrees -b html releasenotes/source releasenotes/build/html
|
|
|
|
[testenv:docs]
|
|
commands=
|
|
python setup.py build_sphinx
|
|
|
|
# environment used by the -infra templated docs job
|
|
[testenv:venv]
|
|
deps = -r{toxinidir}/test-requirements.txt
|
|
commands = {posargs}
|
|
|
|
# Run hacking/flake8 check for all python files
|
|
[testenv:pep8]
|
|
deps = flake8
|
|
whitelist_externals = bash
|
|
commands =
|
|
bash -c "grep -Irl \
|
|
-e '!/usr/bin/env python' \
|
|
-e '!/bin/python' \
|
|
-e '!/usr/bin/python' \
|
|
--exclude-dir '.*' \
|
|
--exclude-dir 'doc' \
|
|
--exclude-dir '*.egg' \
|
|
--exclude-dir '*.egg-info' \
|
|
--exclude-dir '*templates' \
|
|
--exclude 'tox.ini' \
|
|
--exclude '*.sh' \
|
|
{toxinidir} | xargs flake8 --verbose"
|
|
|
|
|
|
[flake8]
|
|
# Ignores the following rules due to how ansible modules work in general
|
|
# F403 'from ansible.module_utils.basic import *' used;
|
|
# unable to detect undefined names
|
|
# H303 No wildcard (*) import.
|
|
ignore=F403,H303
|
|
|
|
[testenv:bashate]
|
|
deps =
|
|
bashate
|
|
whitelist_externals = bash
|
|
commands =
|
|
# Run bashate check for all bash scripts
|
|
# Ignores the following rules:
|
|
# E003: Indent not multiple of 4 (we prefer to use multiples of 2)
|
|
# E006: Line longer than 79 columns (as many scripts use jinja
|
|
# templating, this is very difficult)
|
|
# E040: Syntax error determined using `bash -n` (as many scripts
|
|
# use jinja templating, this will often fail and the syntax
|
|
# error will be discovered in execution anyway)
|
|
bash -c "grep --recursive --binary-files=without-match \
|
|
--files-with-match '^.!.*\(ba\)\?sh$' \
|
|
--exclude-dir .tox \
|
|
--exclude-dir .git \
|
|
{toxinidir} | xargs bashate --error . --verbose --ignore=E003,E006,E040"
|
|
|
|
[testenv:ansible-lint]
|
|
deps =
|
|
ansible>1.9,<2.0
|
|
ansible-lint
|
|
whitelist_externals = bash
|
|
commands =
|
|
# Perform an Ansible lint check
|
|
bash -c "ansible-lint {toxinidir}/playbooks/*.yml"
|
|
|
|
[testenv:ansible-syntax]
|
|
deps =
|
|
ansible>1.9,<2.0
|
|
whitelist_externals = bash
|
|
commands =
|
|
# Perform an Ansible syntax check
|
|
bash -c "mkdir -p {envtmpdir}/ansible; \
|
|
export ANSIBLE_CONFIG={envtmpdir}/ansible/ansible.cfg; \
|
|
export ANSIBLE_ROLES_PATH={envtmpdir}/ansible/roles; \
|
|
sed 's|/etc/ansible|{envtmpdir}/ansible|' \
|
|
{toxinidir}/tests/ansible.cfg | \
|
|
tee {envtmpdir}/ansible/ansible.cfg; \
|
|
sed 's|path: /etc/ansible|path: {envtmpdir}/ansible|' \
|
|
{toxinidir}/ansible-role-requirements.yml | \
|
|
tee {envtmpdir}/ansible/ansible-role-requirements.yml; \
|
|
ansible-galaxy install \
|
|
--role-file={envtmpdir}/ansible/ansible-role-requirements.yml \
|
|
--roles-path={envtmpdir}/ansible/roles \
|
|
--ignore-errors \
|
|
--force; \
|
|
ansible-playbook -i 'localhost ansible-connection=local,' \
|
|
--syntax-check \
|
|
--list-tasks \
|
|
{toxinidir}/playbooks/*.yml"
|
|
|
|
[testenv:linters]
|
|
deps =
|
|
{[testenv:pep8]deps}
|
|
{[testenv:bashate]deps}
|
|
{[testenv:ansible-lint]deps}
|
|
# note that the ansible-syntax deps are omitted on purpose as the
|
|
# ansible-lint env contains duplicate items in its dep list
|
|
whitelist_externals = bash
|
|
commands =
|
|
{[testenv:pep8]commands}
|
|
{[testenv:bashate]commands}
|
|
{[testenv:ansible-lint]commands}
|
|
{[testenv:ansible-syntax]commands}
|
|
|
|
[testenv:inventory]
|
|
changedir = {toxinidir}/tests
|
|
commands =
|
|
python test_inventory.py
|