def test_repos_mapping(current_actor_context): repos_data = [ RepositoryData(repoid='rhel-7-server-rpms', name='RHEL 7 Server'), RepositoryData(repoid='rhel-7-blacklisted-rpms', name='RHEL 7 Blacklisted') ] repos_files = [ RepositoryFile(file='/etc/yum.repos.d/redhat.repo', data=repos_data) ] facts = RepositoriesFacts(repositories=repos_files) arch = stdlib.run(['uname', '-m'])['stdout'].strip() mapping = [ RepositoryMap(from_repoid='rhel-7-server-rpms', to_repoid='rhel-8-for-{}-baseos-htb-rpms'.format(arch), to_pes_repo='rhel8-baseos', from_minor_version='all', to_minor_version='all', arch=arch, repo_type='rpm'), RepositoryMap( from_repoid='rhel-7-server-rpms', to_repoid='rhel-8-for-{}-appstream-htb-rpms'.format(arch), to_pes_repo='rhel8-appstream', from_minor_version='all', to_minor_version='all', arch=arch, repo_type='rpm'), RepositoryMap(from_repoid='rhel-7-blacklist-rpms', to_repoid='rhel-8-blacklist-rpms', to_pes_repo='rhel8-blacklist', from_minor_version='all', to_minor_version='all', arch=arch, repo_type='rpm') ] repos_map = RepositoriesMap(repositories=mapping) repos_blacklisted = RepositoriesBlacklisted( repoids=['rhel-8-blacklisted-rpms']) current_actor_context.feed(facts) current_actor_context.feed(repos_map) current_actor_context.feed(repos_blacklisted) current_actor_context.run() assert current_actor_context.consume(TargetRepositories) rhel_repos = current_actor_context.consume( TargetRepositories)[0].rhel_repos assert len(rhel_repos) == 2 assert {repo.repoid for repo in rhel_repos} == { 'rhel-8-for-x86_64-baseos-htb-rpms', 'rhel-8-for-x86_64-appstream-htb-rpms' }
def test_repos_mapping(current_actor_context): repos_data = [ RepositoryData(repoid='rhel-7-server-rpms', name='RHEL 7 Server'), RepositoryData(repoid='rhel-7-blacklisted-rpms', name='RHEL 7 Blacklisted') ] repos_files = [ RepositoryFile(file='/etc/yum.repos.d/redhat.repo', data=repos_data) ] facts = RepositoriesFacts(repositories=repos_files) mapping = [ RepositoryMap(from_id='rhel-7-server-rpms', to_id='rhel-8-for-x86_64-baseos-htb-rpms', from_minor_version='all', to_minor_version='all', arch='x86_64', repo_type='rpm'), RepositoryMap(from_id='rhel-7-server-rpms', to_id='rhel-8-for-x86_64-appstream-htb-rpms', from_minor_version='all', to_minor_version='all', arch='x86_64', repo_type='rpm'), RepositoryMap(from_id='rhel-7-blacklist-rpms', to_id='rhel-8-blacklist-rpms', from_minor_version='all', to_minor_version='all', arch='x86_64', repo_type='rpm') ] repos_map = RepositoriesMap(repositories=mapping) repos_blacklisted = RepositoriesBlacklisted( repoids=['rhel-8-blacklisted-rpms']) current_actor_context.feed(facts) current_actor_context.feed(repos_map) current_actor_context.feed(repos_blacklisted) current_actor_context.run() assert current_actor_context.consume(TargetRepositories) rhel_repos = current_actor_context.consume( TargetRepositories)[0].rhel_repos assert len(rhel_repos) == 2 assert set([repo.repoid for repo in rhel_repos]) == set([ 'rhel-8-for-x86_64-baseos-htb-rpms', 'rhel-8-for-x86_64-appstream-htb-rpms' ])
def test_all_target_optionals_blacklisted_when_no_optional_on_source( monkeypatch, repomap_opts_only): """ Tests whether every target optional repository gets blacklisted if no optional repositories are used on the source system. """ repos_data = [ RepositoryData( repoid="rhel-7-server-rpms", name="RHEL 7 Server", enabled=True, ) ] repos_files = [ RepositoryFile(file="/etc/yum.repos.d/redhat.repo", data=repos_data) ] repo_facts = RepositoriesFacts(repositories=repos_files) monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(msgs=[repo_facts, repomap_opts_only])) monkeypatch.setattr(api, 'produce', produce_mocked()) monkeypatch.setattr(reporting, 'create_report', produce_mocked()) repositoriesblacklist.process() assert api.produce.called assert 'codeready-builder-for-rhel-8-x86_64-rpms' in api.produce.model_instances[ 0].repoids
def test_unit_localreposinhibit(current_actor_context, baseurl, mirrorlist, metalink, exp_msgs_len): """Ensure the Report is generated when local path is used as a baseurl. :type current_actor_context: ActorContext """ with pytest.deprecated_call(): current_actor_context.feed( TMPTargetRepositoriesFacts( repositories=[ RepositoryFile( file="the/path/to/some/file", data=[ RepositoryData( name="BASEOS", baseurl=( "http://example.com/path/to/repo/BaseOS/x86_64/os/" ), repoid="BASEOS", ), RepositoryData( name="APPSTREAM", baseurl=( "http://example.com/path/to/repo/AppStream/x86_64/os/" ), repoid="APPSTREAM", ), RepositoryData( name="CRB", repoid="CRB", baseurl=baseurl, mirrorlist=mirrorlist, metalink=metalink ), ], ) ] ) ) current_actor_context.feed( UsedTargetRepositories( repos=[ UsedTargetRepository(repoid="BASEOS"), UsedTargetRepository(repoid="CRB"), ] ) ) current_actor_context.run() assert len(current_actor_context.messages()) == exp_msgs_len
def repositories_mock(*model): repos_data = [ RepositoryData(repoid='rhel-7-optional-rpms', name='RHEL 7 Server') ] repos_files = [ RepositoryFile(file='/etc/yum.repos.d/redhat.repo', data=repos_data) ] yield RepositoriesFacts(repositories=repos_files)
def repofacts_opts_disabled(): repos_data = [ RepositoryData( repoid="rhel-7-server-optional-rpms", name="RHEL 7 Server", enabled=False, ) ] repos_files = [ RepositoryFile(file="/etc/yum.repos.d/redhat.repo", data=repos_data) ] return RepositoriesFacts(repositories=repos_files)
def _parse_repository(repoid, repo_data): def asbool(x): return x == '1' prepared = {'repoid': repoid, 'additional_fields': {}} for key in repo_data.keys(): if key in RepositoryData.fields: if isinstance(RepositoryData.fields[key], fields.Boolean): repo_data[key] = asbool(repo_data[key]) prepared[key] = repo_data[key] else: prepared['additional_fields'][key] = repo_data[key] prepared['additional_fields'] = json.dumps(prepared['additional_fields']) return RepositoryData(**prepared)
def _parse(r): with open(r, mode='r') as fp: cp = configparser.ConfigParser() cp.readfp(fp) for section in cp.sections(): prepared = {'repoid': section, 'additional_fields': {}} data = dict(cp.items(section)) for key in data.keys(): if key in RepositoryData.fields: if isinstance(RepositoryData.fields[key], fields.Boolean): data[key] = asbool(data[key]) prepared[key] = data[key] else: prepared['additional_fields'][key] = data[key] prepared['additional_fields'] = json.dumps(prepared['additional_fields']) yield RepositoryData(**prepared)
def test_enablerepo_option(monkeypatch, enabled_repo, exp_report_title, message_produced): repos_data = [ RepositoryData( repoid="rhel-7-server-optional-rpms", name="RHEL 7 Server", enabled=False, ) ] repos_files = [ RepositoryFile(file="/etc/yum.repos.d/redhat.repo", data=repos_data) ] msgs_to_feed = [ RepositoriesMap( repositories=( [ RepositoryMap( to_pes_repo="rhel-7-server-optional-rpms", from_repoid="rhel-7-server-optional-rpms", to_repoid="codeready-builder-for-rhel-8-x86_64-rpms", from_minor_version="all", to_minor_version="all", arch="x86_64", repo_type="rpm", ), ] ) ), RepositoriesFacts(repositories=repos_files), ] if enabled_repo: msgs_to_feed.append(CustomTargetRepository(repoid=enabled_repo)) monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=msgs_to_feed)) monkeypatch.setattr(api, 'produce', produce_mocked()) monkeypatch.setattr(reporting, 'create_report', create_report_mocked()) repositoriesblacklist.process() assert reporting.create_report.report_fields["title"] == exp_report_title if message_produced: assert isinstance(api.produce.model_instances[0], RepositoriesBlacklisted) else: assert not api.produce.model_instances
def _gen_repo(repoid): return RepositoryData(repoid=repoid, name='name {}'.format(repoid))
def get_repo_data(repoids, enabled=True): data = [] for repo in repoids: data.append(RepositoryData(repoid=repo, name=repo, enabled=enabled)) return data
def get_sample_repository(repoid, name): return RepositoryFile( file='/etc/yum.d/sample.repo', data=[RepositoryData(repoid=repoid, name=name, enabled=True)])
def test_repos_mapping(monkeypatch): """ Tests whether actor correctly determines what repositories should be enabled on target based on the information about what repositories are enabled on the source system using the RepositoriesMapping information. """ repos_data = [ RepositoryData(repoid='rhel-7-server-rpms', name='RHEL 7 Server'), RepositoryData(repoid='rhel-7-blacklisted-rpms', name='RHEL 7 Blacklisted') ] repos_files = [ RepositoryFile(file='/etc/yum.repos.d/redhat.repo', data=repos_data) ] facts = RepositoriesFacts(repositories=repos_files) repomap = RepositoriesMapping( mapping=[ RepoMapEntry( source='rhel7-base', target=['rhel8-baseos', 'rhel8-appstream', 'rhel8-blacklist']) ], repositories=[ PESIDRepositoryEntry(pesid='rhel7-base', repoid='rhel-7-server-rpms', major_version='7', arch='x86_64', repo_type='rpm', channel='ga', rhui=''), PESIDRepositoryEntry(pesid='rhel8-baseos', repoid='rhel-8-for-x86_64-baseos-htb-rpms', major_version='8', arch='x86_64', repo_type='rpm', channel='ga', rhui=''), PESIDRepositoryEntry(pesid='rhel8-appstream', repoid='rhel-8-for-x86_64-appstream-htb-rpms', major_version='8', arch='x86_64', repo_type='rpm', channel='ga', rhui=''), PESIDRepositoryEntry(pesid='rhel8-blacklist', repoid='rhel-8-blacklisted-rpms', major_version='8', arch='x86_64', repo_type='rpm', channel='ga', rhui=''), ]) repos_blacklisted = RepositoriesBlacklisted( repoids=['rhel-8-blacklisted-rpms']) msgs = [facts, repomap, repos_blacklisted] monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=msgs)) monkeypatch.setattr(api, 'produce', produce_mocked()) setuptargetrepos.process() assert api.produce.called rhel_repos = api.produce.model_instances[0].rhel_repos assert len(rhel_repos) == 2 produced_rhel_repoids = {repo.repoid for repo in rhel_repos} expected_rhel_repoids = { 'rhel-8-for-x86_64-baseos-htb-rpms', 'rhel-8-for-x86_64-appstream-htb-rpms' } assert produced_rhel_repoids == expected_rhel_repoids
import os from leapp.libraries.actor import scancustomrepofile from leapp.libraries.common import repofileutils from leapp.libraries.common.testutils import produce_mocked from leapp.libraries.stdlib import api from leapp.models import CustomTargetRepository, CustomTargetRepositoryFile, RepositoryData, RepositoryFile _REPODATA = [ RepositoryData(repoid="repo1", name="repo1name", baseurl="repo1url", enabled=True), RepositoryData(repoid="repo2", name="repo2name", baseurl="repo2url", enabled=False), RepositoryData(repoid="repo3", name="repo3name", enabled=True), RepositoryData(repoid="repo4", name="repo4name", mirrorlist="mirror4list", enabled=True), ] _CUSTOM_REPOS = [ CustomTargetRepository(repoid="repo1", name="repo1name", baseurl="repo1url", enabled=True), CustomTargetRepository(repoid="repo2", name="repo2name",