Skip to content

Commit

Permalink
testing: Start using GH Actions for unit tests (oamg#719)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
vinzenz authored Mar 28, 2022
1 parent 8e74673 commit 2869a3b
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 80 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) \
Expand Down
1 change: 0 additions & 1 deletion leapp/actors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ def tools_paths(self):
""" 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`.
Expand Down
3 changes: 0 additions & 3 deletions leapp/messaging/answerstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def answer(self, scope, key, value):
# So don't even bother updating this to some more 'pythonic' coding style
self._storage[scope] = dialog_scope


@classmethod
def _load_ini(cls, inifile):
"""
Expand All @@ -59,7 +58,6 @@ def _load_ini(cls, inifile):
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.
Expand All @@ -81,7 +79,6 @@ def update(self, answer_file, allow_missing=False):
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.
Expand Down
1 change: 0 additions & 1 deletion leapp/repository/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def _lookup_actors(self, name):
actors.append(actor)
return actors


def lookup_workflow(self, name):
"""
Find workflow in all loaded repositories
Expand Down
10 changes: 5 additions & 5 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions res/container-tests/Containerfile.ubi7
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions res/container-tests/Containerfile.ubi8
Original file line number Diff line number Diff line change
@@ -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
36 changes: 36 additions & 0 deletions res/container-tests/Containerfile.ubi9
Original file line number Diff line number Diff line change
@@ -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
19 changes: 0 additions & 19 deletions res/docker-tests/Dockerfile

This file was deleted.

19 changes: 0 additions & 19 deletions res/docker-tests/Dockerfile.centos7

This file was deleted.

18 changes: 0 additions & 18 deletions res/docker-tests/Dockerfile.centos8

This file was deleted.

11 changes: 10 additions & 1 deletion tests/data/workflow-api-tests/apis/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion tests/data/workflow-api-tests/apis/v1/depcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"""

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):
Expand Down
2 changes: 1 addition & 1 deletion tests/data/workflow-api-tests/apis/v1/testapi.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
14 changes: 12 additions & 2 deletions tests/data/workflow-api-tests/apis/v2/__init__.py
Original file line number Diff line number Diff line change
@@ -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
from leapp.workflows.api.v2.newapi import NewAPI
from leapp.workflows.api.v2.testapi import TestAPI


__all__ = (
DepCheckAPI1,
DepCheckAPI2,
DepCheckAPI3,
DepCheckAPI4,
TestAPI,
NewAPI
)
1 change: 1 addition & 0 deletions tests/data/workflow-api-tests/apis/v2/newapi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from leapp.workflows.api import WorkflowAPI


class NewAPI(WorkflowAPI):
def fun(self):
return 'NewAPI.fun'
2 changes: 1 addition & 1 deletion tests/data/workflow-api-tests/apis/v2/testapi.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
12 changes: 10 additions & 2 deletions tests/data/workflow-api-tests/apis/v3/__init__.py
Original file line number Diff line number Diff line change
@@ -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
)
4 changes: 4 additions & 0 deletions tests/scripts/test_answerstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class MockComponentKey1(object):
key = 'key1'
label = 'label key1'
description = 'description key1'
reason = 'Unbelievable reason'
default = False
value = None

Expand All @@ -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

Expand All @@ -36,6 +38,7 @@ class MockComponentKey1Bool(object):
key = 'key1'
label = 'label bool key1'
description = 'description bool key1'
reason = 'Unreasonable Reason'
default = True
value = None

Expand All @@ -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

Expand Down

0 comments on commit 2869a3b

Please sign in to comment.