Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ jobs:
fail-fast: false
matrix:
scenarios:
- name: Run unit tests with python3.9 on el8
- name: Run unit tests with python3.12 on el9
python: python3.12
container: ubi10
- name: Run unit tests with python3.9 on el9
python: python3.9
container: ubi8
container: ubi9
- name: Run unit tests with python 3.6 on el8
python: python3.6
container: ubi8
Expand Down
2 changes: 2 additions & 0 deletions .packit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
targets:
- epel-7-x86_64
- epel-8-x86_64
- epel-9-x86_64
- fedora-all-aarch64
- fedora-all-x86_64
actions:
Expand All @@ -32,6 +33,7 @@ jobs:
targets:
- epel-7-x86_64
- epel-8-x86_64
- epel-9-x86_64
- fedora-all-aarch64
- fedora-all-x86_64
actions:
Expand Down
29 changes: 18 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _TEST_CONTAINER=$${TEST_CONTAINER:-rhel8}
# someone will call copr_build without additional parameters
MASTER_BRANCH=master

# In case the PR or MR is defined or in case build is not comming from the
# In case the PR or MR is defined or in case build is not coming from the
# MATER_BRANCH branch, N_REL=0; (so build is not update of the approved
# upstream solution). For upstream builds N_REL=100;
N_REL=`_NR=$${PR:+0}; if test "$${_NR:-100}" == "100"; then _NR=$${MR:+0}; fi; git rev-parse --abbrev-ref HEAD | grep -q "^$(MASTER_BRANCH)$$" || _NR=0; echo $${_NR:-100}`
Expand Down Expand Up @@ -76,13 +76,13 @@ help:
@echo " test_container runs linter and unit tests in a container"
@echo " - by default rhel8 container is used"
@echo " - can be changed by setting TEST_CONTAINER env variable"
@echo " - available containers are: rhel7, rhel8, rhel9"
@echo " - available containers are:" rhel{7..10}
@echo " test_container_all runs linter and tests in all available containers"
@echo " lint runs just the linter"
@echo " build create the RPM"
@echo " build_container create the RPM in container"
@echo " - set BUILD_CONTAINER to select the container"
@echo " - available containers are: el7, el8, f35, f36, rawhide"
@echo " - available containers are:" el{7..9} f{35..40} rawhide
@echo " - this can't be used to build in parallel,"
@echo " as build containers operate on the same files"
@echo " clean_containers clean container images used for building"
Expand Down Expand Up @@ -154,10 +154,10 @@ build_container:
el7) \
_CONT_FILE="Containerfile.centos7"; \
;; \
el8) \
_CONT_FILE="Containerfile.ubi8"; \
el[8-9]) \
_CONT_FILE="Containerfile.ubi"$${BUILD_CONTAINER: -1}; \
;; \
f3[56]|rawhide) \
f3[5-9]|f40|rawhide) \
[ $$BUILD_CONTAINER = rawhide ] && VERSION=latest || VERSION=$${BUILD_CONTAINER: -2}; \
_CONT_FILE=".Containerfile.$${BUILD_CONTAINER}"; \
cp res/container-builds/Containerfile.fedora_generic res/container-builds/$$_CONT_FILE && \
Expand All @@ -168,7 +168,7 @@ build_container:
exit 1; \
;; \
*) \
echo "Available containers are el7, el8, f35, f36, rawhide"; \
echo "Available containers are: el{7..9} f{35..40} rawhide"; \
exit 1; \
;; \
esac && \
Expand All @@ -182,6 +182,7 @@ print_release:
@echo $(RELEASE)

install-deps:
@ $(ENTER_VENV) \
pip install -r requirements.txt

install:
Expand All @@ -200,10 +201,11 @@ else
pip install -r requirements-tests.txt
endif

test: lint
test: lint
@ $(ENTER_VENV) \
pytest -vv --cov-report term-missing --cov=leapp tests/scripts

# TODO(pstodulk): create ticket to add rhel10 for testing.... py: 3.12
test_container:
@case $(_TEST_CONTAINER) in \
rhel7) \
Expand All @@ -218,8 +220,13 @@ test_container:
export _VENV=python3.9; \
export _CONT_FILE="res/container-tests/Containerfile.ubi9"; \
;; \
# TODO the container is currently built on top of RHEL 9 UBI with python3.12 virtualenv \
rhel10) \
export _VENV=python3.12; \
export _CONT_FILE="res/container-tests/Containerfile.ubi10"; \
;; \
*) \
echo "Available test containers are rhel7, rhel8, rhel9"; \
echo "Available test containers are: rhel{7..10}"; \
exit 1; \
;; \
esac; \
Expand All @@ -229,12 +236,12 @@ test_container:
$(_CONTAINER_TOOL) run --rm -v $${PWD}:/payload:Z -e PYTHON_VENV=$$_VENV $$TEST_IMAGE

test_container_all:
@for container in "rhel"{7,8,9}; do \
@for container in "rhel"{7..10}; do \
TEST_CONTAINER=$$container $(MAKE) test_container; \
done

clean_containers:
@for i in "leapp-build-"{el7,el8,f35,f36,rawhide} "leapp-tests-rhel"{7,8,9}; do \
@for i in "leapp-build-"{el7,el8,el9,f35,f36,rawhide} "leapp-tests-rhel"{7..10}; do \
[ -z $$($(_CONTAINER_TOOL) images -q "$$i") ] || \
$(_CONTAINER_TOOL) rmi "$$i" > /dev/null 2>&1 || :; \
done
Expand Down
7 changes: 6 additions & 1 deletion leapp/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib
import os
import pkgutil
import socket
Expand All @@ -24,7 +25,11 @@ def _load_commands(base_command):
if os.path.isdir(entry_path) and os.path.isfile(os.path.join(entry_path, '__init__.py')):
# We found a package - We will import it and get the `register` symbol and check if it is callable.
package_name = 'leapp.cli.commands.{}'.format(entry)
package = pkgutil.get_loader(package_name).load_module(package_name)
if sys.version_info < (3, 12):
# get_loader and load_module are deprecated since 3.12
package = pkgutil.get_loader(package_name).load_module(package_name) # noqa: E501, pylint: disable=deprecated-method
else:
package = importlib.import_module(package_name)
register = getattr(package, 'register', None)
if callable(register):
register(base_command)
Expand Down
19 changes: 19 additions & 0 deletions leapp/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gettext # noqa: F401; pylint: disable=unused-import
import importlib
import locale
import sys

Expand Down Expand Up @@ -66,3 +67,21 @@ def raise_with_traceback(exc, tb):
:return: Nothing
"""
raise exc.with_traceback(tb)


def load_module(importer, name):
"""
Loads a module using the given importer and module name

:param importer: A finder implementation (returned by e.g. pkgutils.iter_modules)
:param name: Module name
:return: The loaded module
"""
if sys.version_info < (3, 4):
return importer.find_module(name).load_module(name)

spec = importer.find_spec(name)
module = importlib.util.module_from_spec(spec)
sys.modules[name] = module
spec.loader.exec_module(module)
return module
2 changes: 1 addition & 1 deletion leapp/libraries/stdlib/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# (pstodulk): find_executable() is from the distutils module which was
# removed in Python 3.12. We can get rid of this fallback when we drop
# support for Python 2. https://peps.python.org/pep-0632/
from distutils.spawn import find_executable as which
from distutils.spawn import find_executable as which # pylint: disable=deprecated-module

from leapp.compat import string_types
from leapp.libraries.stdlib.eventloop import POLL_HUP, POLL_IN, POLL_OUT, POLL_PRI, EventLoop
Expand Down
9 changes: 7 additions & 2 deletions leapp/messaging/answerstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import six
from six.moves import configparser
try:
from six.moves.configparser import SafeConfigParser as ConfigParser
except ImportError:
from six.moves.configparser import ConfigParser

from leapp.exceptions import CommandError
from leapp.utils.audit import create_audit_entry
Expand Down Expand Up @@ -46,10 +50,11 @@ def _load_ini(cls, inifile):
Loads an ini config file from the given location.

:param inifile: Path to the answer file to load.
:return: configparser.SafeConfigParser object
:return: configparser.ConfigParser object
:raises CommandError if any of the values are not in key=value format
"""
conf = configparser.SafeConfigParser(allow_no_value=False)
conf = ConfigParser(allow_no_value=False)

try:
conf.read(inifile)
return conf
Expand Down
3 changes: 2 additions & 1 deletion leapp/repository/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pkgutil
import sys

from leapp.compat import load_module
from leapp.exceptions import RepoItemPathDoesNotExistError, UnsupportedDefinitionKindError
from leapp.models import get_models, resolve_model_references
import leapp.libraries.common # noqa # pylint: disable=unused-import
Expand Down Expand Up @@ -166,7 +167,7 @@ def _load_modules(self, modules, prefix):
directories = [os.path.join(self._repo_dir, os.path.dirname(module)) for module in modules]
prefix = prefix + '.' if not prefix.endswith('.') else prefix
for importer, name, ispkg in pkgutil.iter_modules(directories, prefix=prefix):
importer.find_module(name).load_module(name)
load_module(importer, name)

def serialize(self):
"""
Expand Down
3 changes: 2 additions & 1 deletion leapp/repository/actor_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import leapp.libraries.actor # noqa # pylint: disable=unused-import
from leapp.actors import get_actor_metadata, get_actors
from leapp.compat import load_module
from leapp.exceptions import (ActorInspectionFailedError, LeappRuntimeError, MultipleActorsError,
UnsupportedDefinitionKindError)
from leapp.repository.definition import DefinitionKind
Expand Down Expand Up @@ -193,7 +194,7 @@ def load(self):
path = os.path.abspath(os.path.join(self._repo_dir, self.directory))
for importer, name, is_pkg in pkgutil.iter_modules((path,)):
if not is_pkg:
self._module = importer.find_module(name).load_module(name)
self._module = load_module(importer, name)
break

def discover(self):
Expand Down
3 changes: 2 additions & 1 deletion leapp/snactor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pkgutil
import socket

from leapp.compat import load_module
from leapp.utils.i18n import _ # noqa; pylint: disable=redefined-builtin
from leapp.snactor import commands
from leapp.snactor.commands import workflow
Expand Down Expand Up @@ -30,7 +31,7 @@ def _load_commands_from(path):
for importer, name, is_pkg in pkgutil.iter_modules([pkg_path]):
if is_pkg:
continue
mod = importer.find_module(name).load_module(name)
mod = load_module(importer, name)
if hasattr(mod.cli, 'command'):
if not mod.cli.command.parent:
cli.command.add_sub(mod.cli.command)
Expand Down
12 changes: 12 additions & 0 deletions res/container-builds/Containerfile.ubi9
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM registry.access.redhat.com/ubi9/ubi:latest

VOLUME /payload

ENV DIST_VERSION 9

RUN dnf update -y && \
dnf install -y python3 make git rpm-build python3-devel
#yum install -y python3-pip && \ python3 -m pip install --upgrade pip==20.3.4

WORKDIR /payload
ENTRYPOINT make build
41 changes: 41 additions & 0 deletions res/container-tests/Containerfile.ubi10
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM registry.access.redhat.com/ubi9/ubi:latest

VOLUME /payload

RUN dnf update -y && \
dnf install python3 python312 python3-pip make -y && \
python3 -m pip install --upgrade pip==20.3.4

RUN pip install virtualenv

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 && \
# NOTE(mmatuska): The pytest ver defined in requirements-tests is too old \
# for Python 3.12 (missing imp module), there do an update here until we \
# bump that. Similarly for six. \
pip install -U pytest && \
pip install -U six && \
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 '==================================================' && \
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
9 changes: 5 additions & 4 deletions res/container-tests/Containerfile.ubi9
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM registry.access.redhat.com/ubi8/ubi:latest
FROM registry.access.redhat.com/ubi9/ubi:latest

VOLUME /payload

RUN yum update -y && \
yum install python3 python39 python3-virtualenv make -y && \
yum -y install python3-pip && \
RUN dnf update -y && \
dnf install python3 python39 make python3-pip -y && \
python3 -m pip install --upgrade pip==20.3.4

RUN pip install virtualenv

WORKDIR /payload
ENTRYPOINT virtualenv testenv -p "/usr/bin/$PYTHON_VENV" && \
source testenv/bin/activate && \
Expand Down
6 changes: 6 additions & 0 deletions tests/scripts/test_audit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import sqlite3
import uuid

import pytest

from leapp.utils.audit import get_connection, Execution, Host, MessageData, \
DataSource, Message, Audit, get_messages, checkpoint, get_checkpoints, create_audit_entry, get_audit_entry
from leapp.config import get_config
Expand Down Expand Up @@ -95,10 +97,14 @@ def setup_module():
get_config().set('database', 'path', '/tmp/leapp-test.db')


@pytest.fixture(autouse=True)
def setup():
path = get_config().get('database', 'path')
if os.path.isfile(path):
os.unlink(path)
yield
if os.path.isfile(path):
os.unlink(path)


def test_migrations_are_applied():
Expand Down
4 changes: 4 additions & 0 deletions tests/scripts/test_exit_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ def setup_module():
get_config().set('database', 'path', '/tmp/leapp-test.db')


@pytest.fixture(autouse=True)
def setup():
path = get_config().get('database', 'path')
if os.path.isfile(path):
os.unlink(path)
yield
if os.path.isfile(path):
os.unlink(path)


@pytest.mark.parametrize('error, code', [(None, 0), ('StopActorExecution', 0), ('StopActorExecutionError', 0),
Expand Down