-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The actor produce CustomTargetRepository messages for repoids obtained from the cmdline when user use the --enablerepo option. The values are stored inside LEAPP_ENABLE_REPOS envar now, which is stored inside the configuration of the actor.
- Loading branch information
Showing
3 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
repos/system_upgrade/el7toel8/actors/scanclienablerepo/actor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from leapp.actors import Actor | ||
from leapp.libraries.actor import library | ||
from leapp.models import CustomTargetRepository | ||
from leapp.tags import FactsPhaseTag, IPUWorkflowTag | ||
|
||
|
||
class ScanCLIenablrepo(Actor): | ||
""" | ||
Produce CustomTargetRepository based on the LEAPP_ENABLE_REPOS in config. | ||
""" | ||
|
||
name = 'scanclienablerepo' | ||
consumes = () | ||
produces = (CustomTargetRepository) | ||
tags = (FactsPhaseTag, IPUWorkflowTag) | ||
|
||
def process(self): | ||
library.process() |
11 changes: 11 additions & 0 deletions
11
repos/system_upgrade/el7toel8/actors/scanclienablerepo/libraries/library.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from leapp.libraries.stdlib import api | ||
from leapp.libraries.common import config | ||
from leapp.models import CustomTargetRepository | ||
|
||
|
||
def process(): | ||
if not config.get_env('LEAPP_ENABLE_REPOS'): | ||
return | ||
api.current_logger().info('The --enablerepo option has been used,') | ||
for repoid in config.get_env('LEAPP_ENABLE_REPOS').split(','): | ||
api.produce(CustomTargetRepository(repoid=repoid)) |
75 changes: 75 additions & 0 deletions
75
repos/system_upgrade/el7toel8/actors/scanclienablerepo/tests/test_unit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from collections import namedtuple | ||
import os | ||
|
||
import pytest | ||
|
||
from leapp.libraries.actor import library | ||
from leapp.libraries.common.config import architecture | ||
from leapp.libraries.common.testutils import produce_mocked | ||
from leapp.libraries.stdlib import api | ||
from leapp.models import CustomTargetRepository | ||
from leapp import models | ||
|
||
|
||
class CurrentActorMocked(object): | ||
def __init__(self, kernel='3.10.0-957.43.1.el7.x86_64', release_id='rhel', | ||
src_ver='7.6', dst_ver='8.1', arch=architecture.ARCH_X86_64, | ||
envars=None): | ||
|
||
if envars: | ||
envarsList = [models.EnvVar(name=key, value=value) for key, value in envars.items()] | ||
else: | ||
envarsList = [] | ||
|
||
version = namedtuple('Version', ['source', 'target'])(src_ver, dst_ver) | ||
os_release = namedtuple('OS_release', ['release_id', 'version_id'])(release_id, src_ver) | ||
args = (version, kernel, os_release, arch, envarsList) | ||
conf_fields = ['version', 'kernel', 'os_release', 'architecture', 'leapp_env_vars'] | ||
self.configuration = namedtuple('configuration', conf_fields)(*args) | ||
self._common_folder = '../../files' | ||
|
||
def __call__(self): | ||
return self | ||
|
||
def get_common_folder_path(self, folder): | ||
return os.path.join(self._common_folder, folder) | ||
|
||
|
||
class LoggerMocked(object): | ||
def __init__(self): | ||
self.infomsg = None | ||
self.debugmsg = None | ||
|
||
def info(self, msg): | ||
self.infomsg = msg | ||
|
||
def debug(self, msg): | ||
self.debugmsg = msg | ||
|
||
def __call__(self): | ||
return self | ||
|
||
|
||
def test_no_enabledrepos(monkeypatch): | ||
monkeypatch.setattr(api, 'produce', produce_mocked()) | ||
monkeypatch.setattr(api, 'current_logger', LoggerMocked()) | ||
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked()) | ||
library.process() | ||
assert not api.current_logger.infomsg | ||
assert not api.produce.called | ||
|
||
|
||
@pytest.mark.parametrize('envars,result', [ | ||
({'LEAPP_ENABLE_REPOS': 'repo1'}, [CustomTargetRepository(repoid='repo1')]), | ||
({'LEAPP_ENABLE_REPOS': 'repo1,repo2'}, [CustomTargetRepository(repoid='repo1'), | ||
CustomTargetRepository(repoid='repo2')]), | ||
]) | ||
def test_enabledrepos(monkeypatch, envars, result): | ||
monkeypatch.setattr(api, 'produce', produce_mocked()) | ||
monkeypatch.setattr(api, 'current_logger', LoggerMocked()) | ||
monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(envars=envars)) | ||
library.process() | ||
assert api.current_logger.infomsg | ||
assert api.produce.called == len(result) | ||
for i in result: | ||
assert i in api.produce.model_instances |