Refactored tox jobs

- assure we test triple-jobs-gerrit.py file
- fix division by zero bug with above file
- simplified tox.ini file
- prevent accidental regression on CI by checking number of passed tests
- removed test_molecule.py file which was the precursor of what later
  become pytest-molecule

Change-Id: Id6ffb9df88a376bcd3c8a0d77b2d378fca8da115
This commit is contained in:
Sorin Sbarnea 2019-02-01 16:48:45 +00:00
parent cfc3ad20a8
commit e5217e01a4
7 changed files with 41 additions and 85 deletions

View File

@ -193,18 +193,22 @@ def gen_html(data, html_file, table_file, stats_hours, job_names, options):
fp.write("Limit: " + options.l)
total = passed_jobs + partial_jobs + failed_jobs
if total:
passed_percent = float(passed_jobs) / float(total) * 100
partial_percent = float(partial_jobs) / float(total) * 100
failed_percent = float(failed_jobs) / float(total) * 100
else:
passed_percent = 0
partial_percent = 0
failed_percent = 0
fp.write("<p>Overall</p>")
fp.write("Passed: %d/%d (%d %%)<br/>" % (passed_jobs, total, passed_percent))
fp.write(
"Passed: %d/%d (%d %%)<br/>"
% (passed_jobs, total, float(passed_jobs) / float(total) * 100)
"Partial Failures: %d/%d (%d %%)<br/>" % (partial_jobs, total, partial_percent)
)
fp.write(
"Partial Failures: %d/%d (%d %%)<br/>"
% (partial_jobs, total, float(partial_jobs) / float(total) * 100)
)
fp.write(
"Complete Failures: %d/%d (%d %%)<br/>"
% (failed_jobs, total, float(failed_jobs) / float(total) * 100)
"Complete Failures: %d/%d (%d %%)<br/>" % (failed_jobs, total, failed_percent)
)
fp.close()

View File

@ -31,7 +31,7 @@ universal = 1
warnerrors = False
[tool:pytest]
norecursedirs = .git .tox dist
norecursedirs = .git .tox dist .eggs
log_cli = true
[flake8]

View File

@ -1,10 +1,15 @@
PyYAML
ansi2html # GPL (soft-dependency of pytest-html)
docker>=3.7 # Apache
mock
molecule>=3.0.2 # MIT
paramiko>=2.5.0 # LGPL (soft-dependency of docker that enables ssh protocol)
pprint
pre-commit>=1.10 # MIT License
pytest # MIT
pytest-cov # MIT
pytest-html # MPL 2.0
pytest-molecule # MIT
pytest-plus # MIT
pytest-xdist # MIT
mock
requests
pprint
pre-commit>=1.10 # MIT License
PyYAML

View File

@ -0,0 +1,7 @@
import os
def test_jobs_gerrit():
f = os.path.join(os.path.dirname(__file__), "../scripts/tripleo-jobs-gerrit.py")
result = os.system(f)
assert result == 0

View File

@ -1,53 +0,0 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import pytest
import subprocess
# detect if we have a working docker setup and skip with warning if not
docker_skip = False
docker_reason = ''
try:
import docker
client = docker.from_env(timeout=5)
if not client.ping():
raise Exception("Failed to ping docker server.")
except Exception as e:
docker_reason = "Skipping molecule tests due: %s" % e
docker_skip = True
def pytest_generate_tests(metafunc):
# detects all molecule scenarios inside the project
matches = []
if 'testdata' in metafunc.fixturenames:
for role in os.listdir("./roles"):
role_path = os.path.abspath('./roles/%s' % role)
for _, dirnames, _ in os.walk(role_path + '/molecule'):
for scenario in dirnames:
if os.path.isfile(
'%s/molecule/%s/molecule.yml' % (role_path, scenario)
):
matches.append([role_path, scenario])
metafunc.parametrize('testdata', matches)
@pytest.mark.skipif(docker_skip, reason=docker_reason)
def test_molecule(testdata):
cwd, scenario = testdata
cmd = ['python', '-m', 'molecule', 'test', '-s', scenario]
print("running: %s (from %s)" % (" ".join(cmd), cwd))
r = subprocess.call(cmd, cwd=cwd)
assert r == 0

22
tox.ini
View File

@ -1,6 +1,6 @@
[tox]
# keep py3 before py2 to assure they are preffered for envs like linters:
envlist = linters,py{37,36,35,27}
envlist = linters,py{37,36,35,27},molecule
minversion = 3.4.0
ignore_basepython_conflict = True
skip_missing_interpreters = True
@ -18,6 +18,8 @@ setenv =
# Avoid 2020-01-01 warnings: https://github.com/pypa/pip/issues/6207
PYTHONWARNINGS=ignore:DEPRECATION::pip._internal.cli.base_command
PIP_DISABLE_PIP_VERSION_CHECK=1
TEST_PARAMS=--cov=emit_releases_file -k "not molecule"
molecule: TEST_PARAMS=-ra -k molecule
passenv =
ANSIBLE_*
CURL_CA_BUNDLE
@ -35,7 +37,7 @@ commands_pre =
pip install -q bindep
bindep test
commands =
python -m pytest --html={envlogdir}/reports.html --self-contained-html --cov=emit_releases_file {posargs:scripts}
python -m pytest --html={envlogdir}/reports.html --self-contained-html {tty:-s} {env:TEST_PARAMS} {posargs}
[testenv:venv]
commands = {posargs}
@ -45,19 +47,3 @@ deps =
pre-commit>=1.20.0
commands =
python -m pre_commit run -a
[testenv:cireport]
commands = python scripts/tripleo-jobs-gerrit.py {posargs}
[testenv:molecule]
deps =
ansi2html # GPL (soft-dependency of pytest-html)
docker>=3.7 # Apache
molecule==3.0a9 # MIT
paramiko>=2.5.0 # LGPL (soft-dependency of docker that enables ssh protocol)
pytest # MIT
pytest-cov # MIT
pytest-html # MPL 2.0
pytest-xdist # MIT
commands =
python -m pytest -ra --html={envlogdir}/reports.html --self-contained-html {tty:-s} {posargs} tests

View File

@ -17,7 +17,10 @@
check:
jobs:
- openstack-tox-linters
- tripleo-tox-molecule
- tripleo-tox-molecule:
vars:
tox_environment:
PYTEST_REQPASS: 1
- openstack-tox-py35:
success-url: "tox/reports.html"
failure-url: "tox/reports.html"
@ -28,6 +31,10 @@
- ^setup.cfg$
- ^setup.py$
- ^tox.ini$
vars:
tox_environment:
PYTEST_REQPASS: 84
- tripleo-buildimage-overcloud-full-centos-8:
files: &build_images_files
- ^playbooks/tripleo-buildimages/.*$