leapp-repository/SOURCES/0053-Makefile-Partially-fix-ACTOR-tests-and-enable-them-i.patch
2025-12-01 09:14:24 +00:00

179 lines
7.0 KiB
Diff

From 60a1fa88d3a8c93063eb67b9604ac030ed7f1c3a Mon Sep 17 00:00:00 2001
From: Matej Matuska <mmatuska@redhat.com>
Date: Mon, 11 Aug 2025 14:32:40 +0200
Subject: [PATCH 53/55] Makefile: Partially fix ACTOR tests and enable them in
containers
The ACTOR variable for running tests of a single actor has long been
unusable, git bisect led me to dc3abf6 as the commit where
it was (first?) broken due to the same model module being defined in
both el7toel8 and el8toel9 repos.
This patch unfortunately doesn't fix that, but works around it by
enabling the utils/actor_path.py script to search in specific
repositories. These are passed from the Makefile via REPOSITORIES
variable.
As the Makefile rules for containerized tests already use repositories,
the ACTOR variable is just passed along.
NOTE: the code in actor_path.py is ugly and uses private APIs, however
that's nothing new :).
---
Makefile | 44 +++++++++++++++++++++++++++++++-------------
utils/actor_path.py | 35 ++++++++++++++++++++++++++---------
2 files changed, 57 insertions(+), 22 deletions(-)
diff --git a/Makefile b/Makefile
index b1d807e1..59671f06 100644
--- a/Makefile
+++ b/Makefile
@@ -12,24 +12,29 @@ REPOS_PATH=repos
_SYSUPG_REPOS="$(REPOS_PATH)/system_upgrade"
LIBRARY_PATH=
REPORT_ARG=
-REPOSITORIES ?= $(shell ls $(_SYSUPG_REPOS) | xargs echo | tr " " ",")
-SYSUPG_TEST_PATHS=$(shell echo $(REPOSITORIES) | sed -r "s|(,\\|^)| $(_SYSUPG_REPOS)/|g")
-TEST_PATHS:=commands repos/common $(SYSUPG_TEST_PATHS)
-
-# Several commands can take arbitrary user supplied arguments from environment
-# variables as well:
-PYTEST_ARGS ?=
-PYLINT_ARGS ?=
-FLAKE8_ARGS ?=
# python version to run test with
_PYTHON_VENV=$${PYTHON_VENV:-python3.6}
ifdef ACTOR
- TEST_PATHS=`$(_PYTHON_VENV) utils/actor_path.py $(ACTOR)`
+ # If REPOSITORIES is set, the utils/actor_path.py script searches for the
+ # actor only in the specified repositories.
+ # if REPOSITORIES is not set i.e. it's empty, all repositories are searched
+ # - this is broken due to name collisions in repositories (FIXME)
+ TEST_PATHS=$(shell . $(VENVNAME)/bin/activate && $(_PYTHON_VENV) utils/actor_path.py $(ACTOR) $(REPOSITORIES))
APPROX_TEST_PATHS=$(shell $(_PYTHON_VENV) utils/find_actors.py -C repos $(ACTOR)) # Dev only
+else
+ REPOSITORIES ?= $(shell ls $(_SYSUPG_REPOS) | xargs echo | tr " " ",")
+ SYSUPG_TEST_PATHS=$(shell echo $(REPOSITORIES) | sed -r "s|(,\\|^)| $(_SYSUPG_REPOS)/|g")
+ TEST_PATHS:=commands repos/common $(SYSUPG_TEST_PATHS)
endif
+# Several commands can take arbitrary user supplied arguments from environment
+# variables as well:
+PYTEST_ARGS ?=
+PYLINT_ARGS ?=
+FLAKE8_ARGS ?=
+
ifeq ($(TEST_LIBS),y)
LIBRARY_PATH=`python utils/library_path.py`
endif
@@ -371,12 +376,24 @@ lint_fix:
echo "--- isort inplace fixing done. ---;"
test_no_lint:
- @. $(VENVNAME)/bin/activate; \
+ @if [ -z "$(REPOSITORIES)" -a -n "$(ACTOR)" ]; then \
+ printf "\033[0;31mWARNING\033[0m: Running tests with ACTOR without"; \
+ printf " specifying REPOSITORIES is currently broken.\n" 2>&1; \
+ printf " Specify REPOSITORIES with only one elXtoelY repository"; \
+ printf " (e.g. REPOSITORIES=common,el8toel9).\n" 2>&1; \
+ exit 1; \
+ fi
+
+ @echo "============= snactor sanity-check ipu ===============" 2>&1
+ . $(VENVNAME)/bin/activate; \
snactor repo find --path repos/; \
for dir in $$(echo $(REPOSITORIES) | tr "," " "); do \
echo "Running sanity-check in $(_SYSUPG_REPOS)/$$dir"; \
(cd $(_SYSUPG_REPOS)/$$dir && snactor workflow sanity-check ipu); \
- done; \
+ done
+
+ @echo "==================== unit tests ======================" 2>&1
+ . $(VENVNAME)/bin/activate; \
$(_PYTHON_VENV) -m pytest $(REPORT_ARG) $(TEST_PATHS) $(LIBRARY_PATH) $(PYTEST_ARGS)
test: lint test_no_lint
@@ -407,7 +424,7 @@ _test_container_ipu:
;; \
esac && \
$(_CONTAINER_TOOL) exec -w /repocopy $$_CONT_NAME make clean && \
- $(_CONTAINER_TOOL) exec -w /repocopy -e REPOSITORIES $$_CONT_NAME make $${_TEST_CONT_TARGET:-test}
+ $(_CONTAINER_TOOL) exec -w /repocopy -e ACTOR -e REPOSITORIES $$_CONT_NAME make $${_TEST_CONT_TARGET:-test}
# Runs lint in a container
@@ -449,6 +466,7 @@ test_container:
$(_CONTAINER_TOOL) run -di --name $$_CONT_NAME -v "$$PWD":/repo:Z -e PYTHON_VENV=$$_VENV $$TEST_IMAGE && \
$(_CONTAINER_TOOL) exec $$_CONT_NAME rsync -aur --delete --exclude 'tut/' --exclude 'docs/' --exclude '**/__pycache__/' --exclude 'packaging/' --exclude '.git/' /repo/ /repocopy && \
$(_CONTAINER_TOOL) exec $$_CONT_NAME rsync -aur --delete --exclude '**/__pycache__/' /repo/commands/ /repocopy/tut/lib/$$_VENV/site-packages/leapp/cli/commands/ && \
+ $(_CONTAINER_TOOL) exec -w /repocopy $$_CONT_NAME bash -c '. $(VENVNAME)/bin/activate && snactor repo find --path repos' && \
export res=0; \
case $$_VENV in \
python3.6) \
diff --git a/utils/actor_path.py b/utils/actor_path.py
index 5c53a16a..3c61ce79 100755
--- a/utils/actor_path.py
+++ b/utils/actor_path.py
@@ -1,7 +1,10 @@
import logging
+import os
import sys
-from leapp.repository.scan import find_and_scan_repositories
+from leapp.repository.manager import RepositoryManager
+from leapp.repository.scan import _resolve_repository_links, find_and_scan_repositories, scan_repo
+
def err_exit():
# We want to be sure that `make test` (test_no_lint) will stop when expected
@@ -10,22 +13,36 @@ def err_exit():
sys.stdout.write('ERROR:__read_error_messages_above_this_one_on_stderr__')
sys.exit(1)
+
def main():
logging.basicConfig(level=logging.INFO, filename='/dev/null')
logger = logging.getLogger('run_pytest.py')
BASE_REPO = 'repos'
- repos = find_and_scan_repositories(BASE_REPO, include_locals=True)
- repos.load()
- if len(sys.argv) > 1:
- actors = repos._lookup_actors(sys.argv[1])
- if not actors:
- sys.stderr.write('ERROR: No actor found for search "{}"\n'.format(sys.argv[1]))
- err_exit()
- print(' '.join([actor.full_path for actor in actors]))
+ SYSUPG_REPO = os.path.join(BASE_REPO, 'system_upgrade')
+
+ if len(sys.argv) == 2:
+ manager = find_and_scan_repositories(BASE_REPO, include_locals=True)
+ manager.load()
+ elif len(sys.argv) == 3:
+ repos = sys.argv[2].split(',')
+ # TODO: it would be nicer to have some function in the framework for
+ # the scanning and resolving done below
+ manager = RepositoryManager()
+ for repo in repos:
+ manager.add_repo(scan_repo(os.path.join(SYSUPG_REPO, repo)))
+ _resolve_repository_links(manager=manager, include_locals=True)
+ manager.load()
else:
sys.stderr.write('ERROR: Missing commandline argument\n')
+ sys.stderr.write('Usage: actor_path.py <actor_name> [repositories]\n')
+ err_exit()
+
+ actors = manager._lookup_actors(sys.argv[1])
+ if not actors:
+ sys.stderr.write('ERROR: No actor found for search "{}"\n'.format(sys.argv[1]))
err_exit()
+ print(' '.join([actor.full_path for actor in actors]))
if __name__ == '__main__':
--
2.51.1