Skip to content

Commit

Permalink
Make test discovery succeed
Browse files Browse the repository at this point in the history
  • Loading branch information
vinzenz committed Jun 16, 2021
1 parent 9a03b3c commit eb3750a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 47 deletions.
62 changes: 34 additions & 28 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,48 @@
import logging
import os

from leapp.repository.manager import RepositoryManager
from leapp.repository.scan import find_and_scan_repositories
from leapp.utils.repository import find_repository_basedir
from leapp.utils.repository import find_repository_basedir, get_repository_id

logger = logging.getLogger(__name__)
logging.getLogger("asyncio").setLevel(logging.INFO)
logging.getLogger("parso").setLevel(logging.INFO)


def _load_and_add_repo(manager, repo_path):
repo = find_and_scan_repositories(
repo_path,
include_locals=True
)
unloaded = set()
loaded = {r.repo_id for r in manager.repos}
if hasattr(repo, 'repos'):
for repo in repo.repos:
if not manager.repo_by_id(repo.repo_id):
manager.add_repo(repo)
unloaded.add(repo.repo_id)
else:
manager.add_repo(repo)
if not loaded:
manager.load(skip_actors_discovery=True)
else:
for repo_id in unloaded:
manager.repo_by_id(repo_id).load(skip_actors_discovery=True)


def pytest_collectstart(collector):
if collector.nodeid:
current_repo_basedir = find_repository_basedir(collector.nodeid)
# loading the current repo
if (
not hasattr(collector.session, "leapp_repository")
or current_repo_basedir != collector.session.repo_base_dir
):
repo = find_and_scan_repositories(
find_repository_basedir(collector.nodeid), include_locals=True
)
repo.load(skip_actors_discovery=True)
collector.session.leapp_repository = repo
current_repo_basedir = find_repository_basedir(str(collector.fspath))
if not hasattr(collector.session, "leapp_repository"):
collector.session.leapp_repository = RepositoryManager()
collector.session.repo_base_dir = current_repo_basedir
_load_and_add_repo(collector.session.leapp_repository, current_repo_basedir)
else:
if not collector.session.leapp_repository.repo_by_id(
get_repository_id(current_repo_basedir)
):
_load_and_add_repo(collector.session.leapp_repository, current_repo_basedir)

# we're forcing the actor context switch only when traversing new
# actor
Expand All @@ -32,29 +52,15 @@ def pytest_collectstart(collector):
not in str(collector.fspath)
):
actor = None
print()
print()
print()
#print('COLECTOR', collector.session.leapp_repository.actors)
print()
print()
for a in collector.session.leapp_repository.actors:
print('A', a)
print('BASEDIR', current_repo_basedir)
print('Afull', a.full_path)
print('Acollector', collector.fspath.dirpath().dirname)
if a.full_path == collector.fspath.dirpath().dirname:
print()
print()
print('HIT')
print()
print()
print()
actor = a
break

if not actor:
logger.info("No actor found, exiting collection...")
print('Node:', collector.nodeid)
print('Base:', current_repo_basedir)
return
# we need to tear down the context from the previous
# actor
Expand Down
5 changes: 5 additions & 0 deletions repos/common/topics/systeminfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from leapp.topics import Topic


class SystemInfoTopic(Topic):
name = 'system_info'
2 changes: 1 addition & 1 deletion repos/system_upgrade/common/.leapp/info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name": "common", "id": "644900a5-c347-43a3-bfab-f448f46d9647"}
{"name": "system_upgrade_common", "id": "644900a5-c347-43a3-bfab-f448f46d9647", "repos": ["efcf9016-f2d1-4609-9329-a298e6587b3c"]}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_setrelease(monkeypatch):
monkeypatch.setattr(mounting, 'NotIsolatedActions', klass)
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(dst_ver='8.0'))
monkeypatch.setattr(config, 'get_product_type', lambda dummy: 'ga')
enablerhsmreposonrhel8.set_rhsm_release()
enablerhsmtargetrepos.set_rhsm_release()
assert commands_called and len(commands_called) == 1
assert commands_called[0][0][-1] == '8.0'

Expand All @@ -68,7 +68,7 @@ def test_setrelease_submgr_throwing_error(monkeypatch):
else:
monkeypatch.setattr(rhsm, 'set_release', rhsm.set_release.__wrapped__.__wrapped__)
with pytest.raises(StopActorExecutionError):
enablerhsmreposonrhel8.set_rhsm_release()
enablerhsmtargetrepos.set_rhsm_release()


@pytest.mark.parametrize('product', ['beta', 'htb'])
Expand All @@ -79,7 +79,7 @@ def test_setrelease_skip_rhsm(monkeypatch, product):
monkeypatch.setattr(config, 'get_product_type', lambda dummy: product)
# To make this work we need to re-apply the decorator, so it respects the environment variable
monkeypatch.setattr(rhsm, 'set_release', rhsm.with_rhsm(rhsm.set_release))
enablerhsmreposonrhel8.set_rhsm_release()
enablerhsmtargetrepos.set_rhsm_release()
assert not commands_called


Expand All @@ -91,37 +91,37 @@ def construct_UTRepo_consume(repoids):
def test_get_unique_repoids(monkeypatch):
repoids = (['some-repo', 'some-repo', 'another-repo'])
monkeypatch.setattr(api, 'consume', construct_UTRepo_consume(repoids))
assert enablerhsmreposonrhel8.get_repos_to_enable() == {'some-repo', 'another-repo'}
assert enablerhsmtargetrepos.get_repos_to_enable() == {'some-repo', 'another-repo'}


def test_get_submgr_cmd():
assert enablerhsmreposonrhel8.get_submgr_cmd({'some-repo'}) == ['subscription-manager', 'repos', '--enable',
assert enablerhsmtargetrepos.get_submgr_cmd({'some-repo'}) == ['subscription-manager', 'repos', '--enable',
'some-repo']


def test_running_submgr_ok(monkeypatch):
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(dst_ver='8.0', envars={'LEAPP_NO_RHSM': '0'}), )
monkeypatch.setattr(enablerhsmreposonrhel8, 'get_repos_to_enable', lambda: {'some-repo'})
monkeypatch.setattr(enablerhsmreposonrhel8, 'run', run_mocked())
enablerhsmreposonrhel8.enable_rhsm_repos()
assert enablerhsmreposonrhel8.run.called
assert 'subscription-manager' in enablerhsmreposonrhel8.run.args[0][0]
monkeypatch.setattr(enablerhsmtargetrepos, 'get_repos_to_enable', lambda: {'some-repo'})
monkeypatch.setattr(enablerhsmtargetrepos, 'run', run_mocked())
enablerhsmtargetrepos.enable_rhsm_repos()
assert enablerhsmtargetrepos.run.called
assert 'subscription-manager' in enablerhsmtargetrepos.run.args[0][0]


def test_running_submgr_fail(monkeypatch):
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(dst_ver='8.0', envars={'LEAPP_NO_RHSM': '0'}), )
monkeypatch.setattr(enablerhsmreposonrhel8, 'get_repos_to_enable', lambda: {'some-repo'})
monkeypatch.setattr(enablerhsmreposonrhel8, 'run', run_mocked(raise_err=True))
monkeypatch.setattr(enablerhsmtargetrepos, 'get_repos_to_enable', lambda: {'some-repo'})
monkeypatch.setattr(enablerhsmtargetrepos, 'run', run_mocked(raise_err=True))
monkeypatch.setattr(api, 'current_logger', logger_mocked())
enablerhsmreposonrhel8.enable_rhsm_repos()
assert enablerhsmreposonrhel8.run.called
enablerhsmtargetrepos.enable_rhsm_repos()
assert enablerhsmtargetrepos.run.called
assert api.current_logger.warnmsg


def test_enable_repos_skip_rhsm(monkeypatch):
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(envars={'LEAPP_NO_RHSM': '1'}))
monkeypatch.setattr(enablerhsmreposonrhel8, 'run', run_mocked())
monkeypatch.setattr(enablerhsmtargetrepos, 'run', run_mocked())
monkeypatch.setattr(api, 'current_logger', logger_mocked())
enablerhsmreposonrhel8.enable_rhsm_repos()
assert not enablerhsmreposonrhel8.run.called
enablerhsmtargetrepos.enable_rhsm_repos()
assert not enablerhsmtargetrepos.run.called
assert api.current_logger.dbgmsg
2 changes: 1 addition & 1 deletion repos/system_upgrade/el7toel8/.leapp/info
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"repos": ["efcf9016-f2d1-4609-9329-a298e6587b3c", "644900a5-c347-43a3-bfab-f448f46d9647"], "messages": {}, "name": "system_upgrade_el7toel8", "id": "c47fbc3d-ae38-416e-9176-7163d67d94f6"}
{"repos": ["efcf9016-f2d1-4609-9329-a298e6587b3c", "644900a5-c347-43a3-bfab-f448f46d9647", "644900a5-c347-43a3-bfab-f448f46d9647"], "messages": {}, "name": "system_upgrade_el7toel8", "id": "c47fbc3d-ae38-416e-9176-7163d67d94f6"}

0 comments on commit eb3750a

Please sign in to comment.