Skip to content

Commit

Permalink
tests: Add ability to test commands
Browse files Browse the repository at this point in the history
Adding now commands/ to the test search places.
Additionally fixed the problems within commands found by pylint.

Signed-off-by: Vinzenz Feenstra <[email protected]>
  • Loading branch information
vinzenz authored and pirat89 committed Nov 23, 2021
1 parent eab3cf3 commit e3a7955
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 9 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}


Expand Down Expand Up @@ -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 \
Expand All @@ -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.." && \
Expand Down
2 changes: 1 addition & 1 deletion commands/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [],
Expand Down
Empty file added commands/tests/.gitkeep
Empty file.
6 changes: 3 additions & 3 deletions commands/upgrade/breadcrumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packaging/leapp-repository.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions utils/container-tests/Containerfile.ubi7
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 9 additions & 0 deletions utils/install_commands.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e3a7955

Please sign in to comment.