From c772db86819771a3d577524c0f743dd5ac2b885a Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: May 04 2021 01:16:38 +0000 Subject: Jenkins unittests run in docker container Prepared dockerfiles for creating a testing environment in containers. Two containers are prepared. The first for normal Python3 and the second one runs in CentOS 7. A tox configuration is customized for supported versions of Python. Minor syntax changes were done to silence flake8 in Python2. JIRA: RHELCMP-4962 Signed-off-by: Ondrej Nosek --- diff --git a/Makefile b/Makefile index e8b8e3d..f0008b3 100644 --- a/Makefile +++ b/Makefile @@ -5,5 +5,5 @@ test: $(default_targets) tox: @python3 -m venv .env @.env/bin/pip install tox - @.env/bin/tox -e py27,py36,py37,flake8,flake8python2 --parallel=auto ${TOX_POSARGS} + @.env/bin/tox -e py27,py36,py39,flake8,flake8python2 --parallel=auto ${TOX_POSARGS} .PHONY: tox diff --git a/jenkins_test.dockerfile b/jenkins_test.dockerfile new file mode 100644 index 0000000..7005cbc --- /dev/null +++ b/jenkins_test.dockerfile @@ -0,0 +1,24 @@ +FROM fedora:33 +LABEL \ + name="fedpkg test" \ + description="Run tests using tox with Python 3" \ + vendor="fedpkg developers" \ + license="MIT" + +RUN dnf -y update && dnf -y install \ + python3-setuptools \ + rpm-build \ + python3-tox \ + gcc \ + libcurl-devel \ + krb5-devel \ + openssl-devel \ + make \ + git +RUN dnf clean all + +WORKDIR /src + +ENV PYTHONPATH "${PYTHONPATH}:./rpkg" + +CMD ["tox", "-e", "py36,py39,flake8"] diff --git a/jenkins_test_py2.dockerfile b/jenkins_test_py2.dockerfile new file mode 100644 index 0000000..75c2e22 --- /dev/null +++ b/jenkins_test_py2.dockerfile @@ -0,0 +1,32 @@ +FROM centos:7 +LABEL \ + name="fedpkg test for Python 2" \ + description="Run tests using tox with Python 2" \ + vendor="fedpkg developers" \ + license="MIT" + +RUN yum -y update && yum install -y epel-release +RUN yum -y install \ + pytest \ + python2-six \ + python2-mock \ + git \ + GitPython \ + python-requests \ + PyYAML \ + python2-cccolutils \ + python2-koji \ + python2-bugzilla \ + python2-freezegun \ + bodhi-client \ + python-flake8 \ + python2-fedora \ + python2-distro \ + rpm-build +RUN yum clean all + +WORKDIR /src + +ENV PYTHONPATH "${PYTHONPATH}:./rpkg" + +CMD ["python", "-m", "pytest" ,"test"] diff --git a/requirements.txt b/requirements.txt index c8dd6bc..9e4f07a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +bodhi-client openidc-client python-bugzilla rpkg diff --git a/test/test_cli.py b/test/test_cli.py index 4327990..4b832af 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -1831,8 +1831,7 @@ class TestBodhiOverrideExtend(CliTestCase): override_expiration_date = utcnow + timedelta(days=7) build_nvr = 'somepkg-1.54-2.fc28' build_override = { - 'expiration_date': - override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), + 'expiration_date': override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), 'nvr': build_nvr, 'notes': 'build for other package', 'build': {'nvr': build_nvr}, @@ -1886,8 +1885,7 @@ class TestBodhiOverrideExtend(CliTestCase): override_expiration_date = utcnow + timedelta(days=7) build_nvr = 'somepkg-1.54-2.fc28' build_override = { - 'expiration_date': - override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), + 'expiration_date': override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), 'nvr': build_nvr, 'notes': 'build for other package', 'build': {'nvr': build_nvr}, @@ -1946,8 +1944,7 @@ class TestBodhiOverrideExtend(CliTestCase): override_expiration_date = utcnow - timedelta(days=7) build_nvr = 'somepkg-1.54-2.fc28' build_override = { - 'expiration_date': - override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), + 'expiration_date': override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), 'nvr': build_nvr, 'notes': 'build for other package', 'build': {'nvr': build_nvr}, @@ -2008,8 +2005,7 @@ class TestBodhiOverrideExtend(CliTestCase): list_overrides.return_value = { 'total': 1, 'overrides': [{ - 'expiration_date': - override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), + 'expiration_date': override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), 'nvr': build_nvr, 'notes': 'build for other package', 'build': {'nvr': build_nvr}, @@ -2043,8 +2039,7 @@ class TestBodhiOverrideExtend(CliTestCase): build_nvr = 'somepkg-1.54-2.fc28' build_override = { - 'expiration_date': - override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), + 'expiration_date': override_expiration_date.strftime('%Y-%m-%d %H:%M:%S'), 'nvr': build_nvr, 'notes': 'build for other package', 'build': {'nvr': build_nvr}, @@ -2326,7 +2321,7 @@ class TestBuildFromStreamBranch(CliTestCase): return_value={ 'epel': ['el6', 'epel7'], 'fedora': ['f29', 'f28'] - }) + }) class TestReleasesInfo(CliTestCase): """Test command releases-info""" diff --git a/test/test_utils.py b/test/test_utils.py index 96ad3a1..2b6e5b0 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -273,11 +273,12 @@ class TestVerifySLS(unittest.TestCase): ] get.return_value = rv - utils.verify_sls('http://localhost/', - { - 'bug_fixes': '2018-06-01', - 'security_fixes': '2018-12-01' - }) + utils.verify_sls( + 'http://localhost/', + { + 'bug_fixes': '2018-06-01', + 'security_fixes': '2018-12-01' + }) @patch('requests.get') diff --git a/tox.ini b/tox.ini index 075538d..bb05d1a 100644 --- a/tox.ini +++ b/tox.ini @@ -1,13 +1,13 @@ [tox] -envlist = py27,py36,py37,flake8 +envlist = py27,py36,py39,flake8 [testenv] -sitepackages=False +sitepackages=false basepython= py27: {env:TOXPYTHON:python2.7} py36: {env:TOXPYTHON:python3.6} - py37: {env:TOXPYTHON:python3.7} - flake8: {env:TOXPYTHON:python3.7} + py39: {env:TOXPYTHON:python3.9} + flake8: {env:TOXPYTHON:python3.6} flake8python2: {env:TOXPYTHON:python2.7} deps = -r{toxinidir}/requirements.txt @@ -28,8 +28,5 @@ deps = flake8 commands = python -m flake8 fedpkg/ test/ [testenv:flake8python2] -deps = - -r{toxinidir}/requirements-py2.txt - -r{toxinidir}/tests-requirements.txt - flake8 +deps = flake8 commands = python -m flake8 fedpkg/ test/