From e3a795528f6f4ae13254f00ad377580f5db5b930 Mon Sep 17 00:00:00 2001 From: Vinzenz Feenstra Date: Mon, 22 Nov 2021 15:01:59 +0100 Subject: [PATCH] tests: Add ability to test commands Adding now commands/ to the test search places. Additionally fixed the problems within commands found by pylint. Signed-off-by: Vinzenz Feenstra --- Makefile | 7 ++++--- commands/rerun/__init__.py | 2 +- commands/tests/.gitkeep | 0 commands/upgrade/breadcrumbs.py | 6 +++--- conftest.py | 3 +++ packaging/leapp-repository.spec | 1 + utils/container-tests/Containerfile.ubi7 | 4 ++-- utils/install_commands.sh | 9 +++++++++ 8 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 commands/tests/.gitkeep create mode 100755 utils/install_commands.sh diff --git a/Makefile b/Makefile index 21f3431174..9e03122964 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ space += comma := , REPOSITORIES ?= $(shell ls repos/system_upgrade/ | xargs echo | tr ' ' ',') SYSUPG_TEST_PATHS=repos/system_upgrade/$(subst $(comma),$(space)repos/system_upgrade/,$(REPOSITORIES)) -TEST_PATHS:=repos/common +TEST_PATHS:=commands repos/common TEST_PATHS += ${SYSUPG_TEST_PATHS} @@ -215,14 +215,14 @@ install-deps: . $(VENVNAME)/bin/activate; \ pip install -U pip; \ pip install --upgrade setuptools; \ - pip install --upgrade -r requirements.txt \ + pip install --upgrade -r requirements.txt; \ + ./utils/install_commands.sh $(_PYTHON_VENV); \ # In case the top commit Depends-On some yet unmerged framework patch - override master leapp with the proper version if [[ ! -z "$(REQ_LEAPP_PR)" ]] ; then \ echo "Leapp-repository depends on the yet unmerged pr of the framework #$(REQ_LEAPP_PR), installing it.." && \ $(VENVNAME)/bin/pip install -I "git+https://github.com/oamg/leapp.git@refs/pull/$(REQ_LEAPP_PR)/head"; \ fi $(_PYTHON_VENV) utils/install_actor_deps.py --actor=$(ACTOR) --repos="$(TEST_PATHS)" - install-deps-fedora: @# Check the necessary rpms are installed for py3 (and py2 below) if ! rpm -q git findutils python3-virtualenv gcc; then \ @@ -238,6 +238,7 @@ install-deps-fedora: pip install -U pip; \ pip install --upgrade setuptools; \ pip install --upgrade -r requirements.txt; \ + ./utils/install_commands.sh $(_PYTHON_VENV); \ # In case the top commit Depends-On some yet unmerged framework patch - override master leapp with the proper version if [[ ! -z "$(REQ_LEAPP_PR)" ]] ; then \ echo "Leapp-repository depends on the yet unmerged pr of the framework #$(REQ_LEAPP_PR), installing it.." && \ diff --git a/commands/rerun/__init__.py b/commands/rerun/__init__.py index 6fb15a685a..74a0da5635 100644 --- a/commands/rerun/__init__.py +++ b/commands/rerun/__init__.py @@ -60,7 +60,7 @@ def rerun(args): db.execute('''DELETE FROM message WHERE context = ? and type = 'ErrorModel';''', (context,)) util.archive_logfiles() - upgrade(Namespace( + upgrade(Namespace( # pylint: disable=no-value-for-parameter resume=True, resume_context=context, only_with_tags=args.only_actors_with_tag or [], diff --git a/commands/tests/.gitkeep b/commands/tests/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/commands/upgrade/breadcrumbs.py b/commands/upgrade/breadcrumbs.py index d500d7aa26..52935012bb 100644 --- a/commands/upgrade/breadcrumbs.py +++ b/commands/upgrade/breadcrumbs.py @@ -9,12 +9,12 @@ from leapp.utils.audit import get_messages try: - from json.decoder import JSONDecodeError + from json.decoder import JSONDecodeError # pylint: disable=ungrouped-imports except ImportError: JSONDecodeError = ValueError -class _BreadCrumbs: +class _BreadCrumbs(object): def __init__(self, activity): self._crumbs = { 'activity': activity, @@ -76,7 +76,7 @@ def produces_breadcrumbs(f): """ Ensures that `/etc/migration-results` gets produced on every invocation of `leapp upgrade` & `leapp preupgrade` - Every execution of the upgrade will have their own entry in the /etc/migration-results file. + Every execution of the upgrade will have their own entry in the /etc/migration-results file. For a user flow like: leapp preupgrade && leapp upgrade && reboot there should be 5 new entries in the file: 1. leapp preupgrade diff --git a/conftest.py b/conftest.py index f0db0c375c..dc86003ca2 100644 --- a/conftest.py +++ b/conftest.py @@ -34,6 +34,9 @@ def _load_and_add_repo(manager, repo_path): def pytest_collectstart(collector): if collector.nodeid: current_repo_basedir = find_repository_basedir(str(collector.fspath)) + if not current_repo_basedir: + # This is not a repository + return if not hasattr(collector.session, "leapp_repository"): collector.session.leapp_repository = RepositoryManager() collector.session.repo_base_dir = current_repo_basedir diff --git a/packaging/leapp-repository.spec b/packaging/leapp-repository.spec index 04302a9115..937e4bcc1f 100644 --- a/packaging/leapp-repository.spec +++ b/packaging/leapp-repository.spec @@ -186,6 +186,7 @@ install -m 0644 etc/leapp/transaction/* %{buildroot}%{_sysconfdir}/leapp/transac # install CLI commands for the leapp utility on the expected path install -m 0755 -d %{buildroot}%{leapp_python_sitelib}/leapp/cli/ cp -r commands %{buildroot}%{leapp_python_sitelib}/leapp/cli/ +rm -rf %{buildroot}%{leapp_python_sitelib}/leapp/cli/commands/tests # Remove irrelevant repositories - We don't want to ship them for the particular # RHEL version diff --git a/utils/container-tests/Containerfile.ubi7 b/utils/container-tests/Containerfile.ubi7 index a4abc3ece6..c38489e738 100644 --- a/utils/container-tests/Containerfile.ubi7 +++ b/utils/container-tests/Containerfile.ubi7 @@ -18,8 +18,8 @@ RUN yum update -y && \ # module of pip version 20.3.0 and then make it update to 20.3.4 resulting the 'pip' command to be available. # The --target approach doesn't add it, but at least we now have pip 20.3.4 installed ;-) RUN yum -y install python27-python-pip && \ - scl enable python27 -- pip install -U --target /usr/lib/python2.7/site-packages/ pip==20.3.0 virtualenv && \ - python -m pip install --ignore-installed pip==20.3.4 ipaddress + 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 ipaddress virtualenv WORKDIR /payload ENTRYPOINT make install-deps && make test diff --git a/utils/install_commands.sh b/utils/install_commands.sh new file mode 100755 index 0000000000..877b4c7249 --- /dev/null +++ b/utils/install_commands.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +LEAPP_CLI_COMMANDS_PATH=$($1 -c "import leapp.cli.commands; print(leapp.cli.commands.__path__[0])") +echo "Installing commands to \"$LEAPP_CLI_COMMANDS_PATH\"" +for folder in `ls -1 commands/`; do + if [[ $folder != "tests" ]]; then + cp -a commands/$folder $LEAPP_CLI_COMMANDS_PATH; + fi +done