leapp/SOURCES/0004-testing-Start-using-GH...

532 lines
20 KiB
Diff

From 2869a3ba3dda450f05e0045849db7a32bbb1787c Mon Sep 17 00:00:00 2001
From: Vinzenz 'evilissimo' Feenstra <vfeenstr@redhat.com>
Date: Mon, 28 Mar 2022 11:21:04 +0200
Subject: [PATCH 4/9] testing: Start using GH Actions for unit tests (#719)
This patch applies all necessary changes to make tests run on
GitHub Actions.
As part of this patch we are transitioning like in leapp-repository
to ubi based containers running on podman. This will gives us the closest
resemblance to the target environments. Tests for fedora & others can be
eventually added as well. For now this patch focuses on our main targets
as the tests have not been working for some time.
Also as part of this patch some minor flake8 fixes have been applied,
and the answerstore test has been fixed.
Signed-off-by: Vinzenz Feenstra <vinzenz.feenstra@gmail.com>
---
.github/workflows/unit-tests.yml | 38 +++++++++++++++++++
Makefile | 6 ---
leapp/actors/__init__.py | 1 -
leapp/messaging/answerstore.py | 3 --
leapp/repository/manager.py | 1 -
requirements-tests.txt | 10 ++---
res/container-tests/Containerfile.ubi7 | 35 +++++++++++++++++
res/container-tests/Containerfile.ubi8 | 38 +++++++++++++++++++
res/container-tests/Containerfile.ubi9 | 36 ++++++++++++++++++
res/docker-tests/Dockerfile | 19 ----------
res/docker-tests/Dockerfile.centos7 | 19 ----------
res/docker-tests/Dockerfile.centos8 | 18 ---------
.../workflow-api-tests/apis/v1/__init__.py | 11 +++++-
.../workflow-api-tests/apis/v1/depcheck.py | 2 +-
.../workflow-api-tests/apis/v1/testapi.py | 2 +-
.../workflow-api-tests/apis/v2/__init__.py | 14 ++++++-
.../data/workflow-api-tests/apis/v2/newapi.py | 1 +
.../workflow-api-tests/apis/v2/testapi.py | 2 +-
.../workflow-api-tests/apis/v3/__init__.py | 12 +++++-
tests/scripts/test_answerstore.py | 4 ++
20 files changed, 192 insertions(+), 80 deletions(-)
create mode 100644 .github/workflows/unit-tests.yml
create mode 100644 res/container-tests/Containerfile.ubi7
create mode 100644 res/container-tests/Containerfile.ubi8
create mode 100644 res/container-tests/Containerfile.ubi9
delete mode 100644 res/docker-tests/Dockerfile
delete mode 100644 res/docker-tests/Dockerfile.centos7
delete mode 100644 res/docker-tests/Dockerfile.centos8
diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml
new file mode 100644
index 0000000..123a73e
--- /dev/null
+++ b/.github/workflows/unit-tests.yml
@@ -0,0 +1,38 @@
+name: Unit Tests
+on:
+ push:
+ branches:
+ - master
+ pull_request:
+ branches:
+ - master
+
+jobs:
+ test:
+ name: Run unit tests in containers
+ runs-on: ubuntu-latest
+ strategy:
+ fail-fast: false
+ matrix:
+ scenarios:
+ - name: Run unit tests with python3.9 on el8
+ python: python3.9
+ container: ubi8
+ - name: Run unit tests with python 3.6 on el8
+ python: python3.6
+ container: ubi8
+ - name: Run unit tests with python2.7 on el7
+ python: python2.7
+ container: ubi7
+
+ steps:
+ - name: Checkout code
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: '0'
+ - name: Set master to origin/master
+ if: github.ref != 'refs/heads/master'
+ run: |
+ git branch -f master origin/master
+ - name: ${{matrix.scenarios.name}}
+ run: script -e -c /bin/bash -c 'TERM=xterm podman build --security-opt=seccomp=unconfined -t leapp-tests -f res/container-tests/Containerfile.${{matrix.scenarios.container}} res/container-tests && PYTHON_VENV=${{matrix.scenarios.python}} REPOSITORIES=${{matrix.scenarios.repos}} podman run --security-opt=seccomp=unconfined --rm -ti -v ${PWD}:/payload --env=PYTHON_VENV --env=REPOSITORIES leapp-tests'
diff --git a/Makefile b/Makefile
index 4d500e9..611d255 100644
--- a/Makefile
+++ b/Makefile
@@ -123,10 +123,6 @@ install:
install -dm 0755 ${LIBDIR}
umask 177 && $(PYTHON_VENV) -c "import sqlite3; sqlite3.connect('${LIBDIR}/audit.db').executescript(open('res/audit-layout.sql', 'r').read())"
-install-container-test:
- docker pull registry.centos.org/${CONTAINER}
- docker build -t leapp-tests -f res/docker-tests/Dockerfile.$(subst :,,${CONTAINER}) res/docker-tests
-
install-test:
ifeq ($(shell id -u), 0)
pip install -r requirements-tests.txt
@@ -136,8 +132,6 @@ else
pip install -r requirements-tests.txt
endif
-container-test:
- docker run --rm -ti -v ${PWD}:/payload leapp-tests
test: lint
@ $(ENTER_VENV) \
diff --git a/leapp/actors/__init__.py b/leapp/actors/__init__.py
index 5c7e9df..c472b84 100644
--- a/leapp/actors/__init__.py
+++ b/leapp/actors/__init__.py
@@ -183,7 +183,6 @@ class Actor(object):
""" Returns all actor tools paths related to the actor and common actors tools paths. """
return self.actor_tools_paths + self.common_tools_paths
-
def get_folder_path(self, name):
"""
Finds the first matching folder path within :py:attr:`files_paths`.
diff --git a/leapp/messaging/answerstore.py b/leapp/messaging/answerstore.py
index c03317c..3e55e8a 100644
--- a/leapp/messaging/answerstore.py
+++ b/leapp/messaging/answerstore.py
@@ -40,7 +40,6 @@ class AnswerStore(object):
# So don't even bother updating this to some more 'pythonic' coding style
self._storage[scope] = dialog_scope
-
@classmethod
def _load_ini(cls, inifile):
"""
@@ -59,7 +58,6 @@ class AnswerStore(object):
raise CommandError('Failed to load answer file {inifile} with the following errors: {errors}'.format(
inifile=inifile, errors=exc.message))
-
def update(self, answer_file, allow_missing=False):
"""
Update answerfile with all answers from answerstore that have correspondent sections in the file.
@@ -81,7 +79,6 @@ class AnswerStore(object):
conf.write(afile)
return not_updated
-
def load(self, answer_file):
"""
Loads an answer file from the given location and updates the loaded data with it.
diff --git a/leapp/repository/manager.py b/leapp/repository/manager.py
index 10b7bba..7d6cb22 100644
--- a/leapp/repository/manager.py
+++ b/leapp/repository/manager.py
@@ -45,7 +45,6 @@ class RepositoryManager(object):
actors.append(actor)
return actors
-
def lookup_workflow(self, name):
"""
Find workflow in all loaded repositories
diff --git a/requirements-tests.txt b/requirements-tests.txt
index 97d6453..74c3955 100644
--- a/requirements-tests.txt
+++ b/requirements-tests.txt
@@ -1,10 +1,10 @@
-r requirements.txt
-e .
+flake8
+isort
jsonschema==3.2.0
mock
-pyrsistent==0.16.1
-pytest==3.6.4
-pytest-flake8
-pytest-cov==2.9.0
-pytest-pylint==0.14.1
+pylint
+pytest-cov
+pytest==4.6.11
diff --git a/res/container-tests/Containerfile.ubi7 b/res/container-tests/Containerfile.ubi7
new file mode 100644
index 0000000..bc434b9
--- /dev/null
+++ b/res/container-tests/Containerfile.ubi7
@@ -0,0 +1,35 @@
+FROM registry.access.redhat.com/ubi7/ubi:7.9
+
+VOLUME /payload
+
+RUN yum -y install python27-python-pip && \
+ scl enable python27 -- pip install -U --target /usr/lib/python2.7/site-packages/ pip==20.3.0 && \
+ python -m pip install --ignore-installed pip==20.3.4 virtualenv
+
+WORKDIR /payload
+ENTRYPOINT virtualenv testenv && \
+ source testenv/bin/activate && \
+ pip install -U setuptools && \
+ pip install -U funcsigs && \
+ pip install -U -r requirements-tests.txt && \
+ pip install -U . && \
+ export LINTABLES=$(find . -name '*.py' | grep -E -e '^\./leapp\/' -e '^\./tests/scripts/' | sort -u ) && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ echo '=============== Running pylint ===============' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ # echo $LINTABLES | xargs pylint --py3k && echo '===> pylint PASSED' && \
+ echo 'TEMPORARILY DISABLED' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ echo '=============== Running flake8 ===============' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ flake8 $LINTABLES && echo '===> flake8 PASSED' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ echo '=============== Running tests ===============' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ py.test -vv --cov-report term-missing --cov=leapp tests/scripts/*.py
diff --git a/res/container-tests/Containerfile.ubi8 b/res/container-tests/Containerfile.ubi8
new file mode 100644
index 0000000..2b8db2f
--- /dev/null
+++ b/res/container-tests/Containerfile.ubi8
@@ -0,0 +1,38 @@
+FROM registry.access.redhat.com/ubi8/ubi:latest
+
+VOLUME /payload
+
+ENV PYTHON_VENV "python3.6"
+
+RUN yum update -y && \
+ yum install python3 python39 python3-virtualenv make -y && \
+ yum -y install python3-pip && \
+ python3 -m pip install --upgrade pip==20.3.4
+
+WORKDIR /payload
+ENTRYPOINT virtualenv testenv -p "/usr/bin/$PYTHON_VENV" && \
+ source testenv/bin/activate && \
+ pip install -U setuptools && \
+ pip install -U funcsigs && \
+ pip install -U -r requirements-tests.txt && \
+ pip install -U . && \
+ export LINTABLES=$(find . -name '*.py' | grep -E -e '^\./leapp\/' -e '^\./tests/scripts/' | sort -u ) && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ echo '=============== Running pylint ===============' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ # echo $LINTABLES | xargs pylint && echo '===> pylint PASSED' && \
+ echo 'TEMPORARILY DISABLED' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ echo '=============== Running flake8 ===============' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ flake8 $LINTABLES && echo '===> flake8 PASSED' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ echo '=============== Running tests ===============' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ py.test -vv --cov-report term-missing --cov=leapp tests/scripts/*.py
diff --git a/res/container-tests/Containerfile.ubi9 b/res/container-tests/Containerfile.ubi9
new file mode 100644
index 0000000..4f31335
--- /dev/null
+++ b/res/container-tests/Containerfile.ubi9
@@ -0,0 +1,36 @@
+FROM registry.access.redhat.com/ubi8/ubi:latest
+
+VOLUME /payload
+
+RUN yum update -y && \
+ yum install python3 python39 python3-virtualenv make -y && \
+ yum -y install python3-pip && \
+ python3 -m pip install --upgrade pip==20.3.4
+
+WORKDIR /payload
+ENTRYPOINT virtualenv testenv -p "/usr/bin/$PYTHON_VENV" && \
+ source testenv/bin/activate && \
+ pip install -U setuptools && \
+ pip install -U funcsigs && \
+ pip install -U -r requirements-tests.txt && \
+ pip install -U . && \
+ export LINTABLES=$(find . -name '*.py' | grep -E -e '^\./leapp\/' -e '^\./tests/scripts/' | sort -u ) && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ echo '=============== Running pylint ===============' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ # echo $LINTABLES | xargs pylint && echo '===> pylint PASSED' && \
+ echo 'TEMPORARILY DISABLED' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ echo '=============== Running flake8 ===============' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ flake8 $LINTABLES && echo '===> flake8 PASSED' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ echo '=============== Running tests ===============' && \
+ echo '==================================================' && \
+ echo '==================================================' && \
+ py.test -vv --cov-report term-missing --cov=leapp tests/scripts/*.py
diff --git a/res/docker-tests/Dockerfile b/res/docker-tests/Dockerfile
deleted file mode 100644
index 18ce6cb..0000000
--- a/res/docker-tests/Dockerfile
+++ /dev/null
@@ -1,19 +0,0 @@
-FROM registry.centos.org/centos:7
-
-VOLUME /payload
-
-RUN yum update -y && \
- yum install python-virtualenv make -y && \
- yum -y install epel-release && \
- yum -y install python-pip python3-pip && \
- python2 -m pip install --upgrade pip==20.3.4 && \
- python3 -m pip install --upgrade pip==20.3.4
-
-WORKDIR /payload
-ENTRYPOINT virtualenv testenv && \
- source testenv/bin/activate && \
- pip install -U setuptools && \
- pip install -U funcsigs && \
- pip install -U -r requirements-tests.txt && \
- pip install -U . && \
- py.test tests/scripts
diff --git a/res/docker-tests/Dockerfile.centos7 b/res/docker-tests/Dockerfile.centos7
deleted file mode 100644
index 18ce6cb..0000000
--- a/res/docker-tests/Dockerfile.centos7
+++ /dev/null
@@ -1,19 +0,0 @@
-FROM registry.centos.org/centos:7
-
-VOLUME /payload
-
-RUN yum update -y && \
- yum install python-virtualenv make -y && \
- yum -y install epel-release && \
- yum -y install python-pip python3-pip && \
- python2 -m pip install --upgrade pip==20.3.4 && \
- python3 -m pip install --upgrade pip==20.3.4
-
-WORKDIR /payload
-ENTRYPOINT virtualenv testenv && \
- source testenv/bin/activate && \
- pip install -U setuptools && \
- pip install -U funcsigs && \
- pip install -U -r requirements-tests.txt && \
- pip install -U . && \
- py.test tests/scripts
diff --git a/res/docker-tests/Dockerfile.centos8 b/res/docker-tests/Dockerfile.centos8
deleted file mode 100644
index 8eadbca..0000000
--- a/res/docker-tests/Dockerfile.centos8
+++ /dev/null
@@ -1,18 +0,0 @@
-FROM registry.centos.org/centos:8
-
-VOLUME /payload
-
-RUN yum update -y && \
- yum install python3-virtualenv make -y && \
- yum -y install epel-release && \
- yum -y install python3-pip && \
- python3 -m pip install --upgrade pip==20.3.4
-
-WORKDIR /payload
-ENTRYPOINT virtualenv testenv && \
- source testenv/bin/activate && \
- pip install -U setuptools && \
- pip install -U funcsigs && \
- pip install -U -r requirements-tests.txt && \
- pip install -U . && \
- py.test tests/scripts
diff --git a/tests/data/workflow-api-tests/apis/v1/__init__.py b/tests/data/workflow-api-tests/apis/v1/__init__.py
index cf2cb98..ef59b4d 100644
--- a/tests/data/workflow-api-tests/apis/v1/__init__.py
+++ b/tests/data/workflow-api-tests/apis/v1/__init__.py
@@ -1,2 +1,11 @@
-from leapp.workflows.api.v1.testapi import TestAPI
from leapp.workflows.api.v1.depcheck import DepCheckAPI1, DepCheckAPI2, DepCheckAPI3, DepCheckAPI4
+from leapp.workflows.api.v1.testapi import TestAPI
+
+
+__all__ = (
+ DepCheckAPI1,
+ DepCheckAPI2,
+ DepCheckAPI3,
+ DepCheckAPI4,
+ TestAPI
+)
diff --git a/tests/data/workflow-api-tests/apis/v1/depcheck.py b/tests/data/workflow-api-tests/apis/v1/depcheck.py
index e76e1b0..4ef350f 100644
--- a/tests/data/workflow-api-tests/apis/v1/depcheck.py
+++ b/tests/data/workflow-api-tests/apis/v1/depcheck.py
@@ -17,8 +17,8 @@ DepCheckAPI4 Produces: DepCheck4 Inherits: Produces: DepCheck2, Consumes DepChec
"""
from leapp.libraries.stdlib import api
-from leapp.workflows.api import WorkflowAPI
from leapp.models import DepCheck1, DepCheck2, DepCheck3, DepCheck4
+from leapp.workflows.api import WorkflowAPI
class DepCheckAPI1(WorkflowAPI):
diff --git a/tests/data/workflow-api-tests/apis/v1/testapi.py b/tests/data/workflow-api-tests/apis/v1/testapi.py
index af6ea40..404e059 100644
--- a/tests/data/workflow-api-tests/apis/v1/testapi.py
+++ b/tests/data/workflow-api-tests/apis/v1/testapi.py
@@ -1,5 +1,5 @@
from leapp.workflows.api import WorkflowAPI
-from leapp.workflows.api import v2
+from leapp.workflows.api.v2 import testapi as v2
class TestAPI(WorkflowAPI):
diff --git a/tests/data/workflow-api-tests/apis/v2/__init__.py b/tests/data/workflow-api-tests/apis/v2/__init__.py
index c3c0946..a087be9 100644
--- a/tests/data/workflow-api-tests/apis/v2/__init__.py
+++ b/tests/data/workflow-api-tests/apis/v2/__init__.py
@@ -1,3 +1,13 @@
-from leapp.workflows.api.v2.testapi import TestAPI
from leapp.workflows.api.v1.depcheck import DepCheckAPI1, DepCheckAPI2, DepCheckAPI3, DepCheckAPI4
-from leapp.workflows.api.v2.newapi import NewAPI
\ No newline at end of file
+from leapp.workflows.api.v2.newapi import NewAPI
+from leapp.workflows.api.v2.testapi import TestAPI
+
+
+__all__ = (
+ DepCheckAPI1,
+ DepCheckAPI2,
+ DepCheckAPI3,
+ DepCheckAPI4,
+ TestAPI,
+ NewAPI
+)
diff --git a/tests/data/workflow-api-tests/apis/v2/newapi.py b/tests/data/workflow-api-tests/apis/v2/newapi.py
index 339aac7..b8180f0 100644
--- a/tests/data/workflow-api-tests/apis/v2/newapi.py
+++ b/tests/data/workflow-api-tests/apis/v2/newapi.py
@@ -1,5 +1,6 @@
from leapp.workflows.api import WorkflowAPI
+
class NewAPI(WorkflowAPI):
def fun(self):
return 'NewAPI.fun'
diff --git a/tests/data/workflow-api-tests/apis/v2/testapi.py b/tests/data/workflow-api-tests/apis/v2/testapi.py
index 93854dd..46e5c23 100644
--- a/tests/data/workflow-api-tests/apis/v2/testapi.py
+++ b/tests/data/workflow-api-tests/apis/v2/testapi.py
@@ -1,5 +1,5 @@
from leapp.workflows.api import WorkflowAPI
-from leapp.workflows.api import v3
+from leapp.workflows.api.v3 import testapi as v3
class TestAPI(WorkflowAPI):
diff --git a/tests/data/workflow-api-tests/apis/v3/__init__.py b/tests/data/workflow-api-tests/apis/v3/__init__.py
index 44c5794..23e5fe4 100644
--- a/tests/data/workflow-api-tests/apis/v3/__init__.py
+++ b/tests/data/workflow-api-tests/apis/v3/__init__.py
@@ -1,4 +1,12 @@
-from leapp.workflows.api.v3.testapi import TestAPI
-from leapp.workflows.api.v2.newapi import NewAPI
from leapp.workflows.api.v1.depcheck import DepCheckAPI1, DepCheckAPI2, DepCheckAPI3, DepCheckAPI4
+from leapp.workflows.api.v2.newapi import NewAPI
+from leapp.workflows.api.v3.testapi import TestAPI
+__all__ = (
+ DepCheckAPI1,
+ DepCheckAPI2,
+ DepCheckAPI3,
+ DepCheckAPI4,
+ TestAPI,
+ NewAPI
+)
diff --git a/tests/scripts/test_answerstore.py b/tests/scripts/test_answerstore.py
index 6562613..af5e8de 100644
--- a/tests/scripts/test_answerstore.py
+++ b/tests/scripts/test_answerstore.py
@@ -18,6 +18,7 @@ class MockComponentKey1(object):
key = 'key1'
label = 'label key1'
description = 'description key1'
+ reason = 'Unbelievable reason'
default = False
value = None
@@ -27,6 +28,7 @@ class MockComponentKey2(object):
key = 'key2'
label = 'label key2'
description = 'description key2'
+ reason = 'Cannot reason with this reason'
default = 'Default'
value = None
@@ -36,6 +38,7 @@ class MockComponentKey1Bool(object):
key = 'key1'
label = 'label bool key1'
description = 'description bool key1'
+ reason = 'Unreasonable Reason'
default = True
value = None
@@ -45,6 +48,7 @@ class MockComponentKey2Bool(object):
key = 'key2'
label = 'label bool key2'
description = 'description bool key2'
+ reason = 'Unbearable\nReason\nxxx'
default = False
value = None
--
2.35.3