def rhel8_crb_pesidrepo(): return PESIDRepositoryEntry( pesid='rhel8-CRB', major_version='8', repoid='codeready-builder-for-rhel-8-x86_64-rpms', rhui='', arch='x86_64', channel='ga', repo_type='rpm')
def test_get_repositories_mapping(monkeypatch): """ Tests whether the actor is able to correctly determine the dictionary that maps the target PES ids determined from the event processing to the actual target repository ids. (tests for the _get_repositories_mapping). """ make_pesid_repo = functools.partial(PESIDRepositoryEntry, arch='x86_64', repo_type='rpm', channel='ga', rhui='') repositories_mapping = RepositoriesMapping( mapping=[ RepoMapEntry(source='rhel7-base', target=['rhel8-BaseOS', 'rhel8-AppStream']), RepoMapEntry(source='rhel7-optional', target=['rhel8-CRB']), ], repositories=[ make_pesid_repo(pesid='rhel7-base', major_version='7', repoid='rhel7-base-repoid'), make_pesid_repo(pesid='rhel7-optional', major_version='7', repoid='rhel7-optional-repoid'), make_pesid_repo(pesid='rhel8-BaseOS', major_version='8', repoid='rhel8-baseos-repoid'), make_pesid_repo(pesid='rhel8-AppStream', major_version='8', repoid='rhel8-appstream-repoid'), make_pesid_repo(pesid='rhel8-CRB', major_version='8', repoid='rhel8-crb-repoid'), # Extra repositories to make sure the created map contains the correct repoids PESIDRepositoryEntry(pesid='rhel8-CRB', major_version='8', repoid='rhel8-crb-repoid-azure', arch='x86_64', repo_type='rpm', channel='ga', rhui='azure'), PESIDRepositoryEntry(pesid='rhel8-BaseOS', major_version='8', repoid='rhel8-baseos-repoid-eus', arch='x86_64', repo_type='rpm', channel='eus', rhui=''), PESIDRepositoryEntry(pesid='rhel8-BaseOS', major_version='8', repoid='rhel8-baseos-repoid-s390x', arch='s390x', repo_type='rpm', channel='ga', rhui=''), ]) monkeypatch.setattr(peseventsscanner, '_get_enabled_repoids', lambda: {'rhel7-base-repoid'}) monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=[repositories_mapping], src_ver='7.9', dst_ver='8.4')) target_pesids = {'rhel8-BaseOS', 'rhel8-AppStream', 'rhel8-CRB'} expected_pesid_to_target_repoids = { 'rhel8-BaseOS': 'rhel8-baseos-repoid', 'rhel8-AppStream': 'rhel8-appstream-repoid', 'rhel8-CRB': 'rhel8-crb-repoid' } actual_pesid_to_target_repoids = peseventsscanner._get_repositories_mapping(target_pesids) fail_description = 'Actor failed to determine what repoid to enable for given target pesids.' assert actual_pesid_to_target_repoids == expected_pesid_to_target_repoids, fail_description
def rhel7_optional_pesidrepo(): return PESIDRepositoryEntry( pesid='rhel7-optional', major_version='7', repoid='rhel-7-server-optional-rpms', rhui='', arch='x86_64', channel='ga', repo_type='rpm', )
def test_request_pesid_repo_not_mapped_by_default(monkeypatch, source_repoid, expected_target_repoid): """ Tests whether a target repository that is not mapped by default (e.g. CRB) is requested to be enabled on the target system if it results from the relevant events. Note: Since the resulting target repository is not mapped by default from the enabled repositories, the data handler should fail to get expected repoids for the given pesid as it works with enabled repositories. Therefor, this test tests whether the fallback lookup with representative repository works. """ repositories_mapping = RepositoriesMapping( mapping=[ RepoMapEntry(source='rhel7-base', target=['rhel8-BaseOS', 'rhel8-AppStream']), RepoMapEntry(source='rhel7-optional', target=['rhel8-CRB']), ], repositories=[ PESIDRepositoryEntry(pesid='rhel7-base', major_version='7', repoid='rhel7-base-repoid', arch='x86_64', repo_type='rpm', channel='ga', rhui=''), PESIDRepositoryEntry(pesid='rhel7-base', major_version='7', repoid='rhel7-base-repoid-eus', arch='x86_64', repo_type='rpm', channel='eus', rhui=''), PESIDRepositoryEntry(pesid='rhel7-optional', major_version='7', repoid='rhel7-optional-repoid', arch='x86_64', repo_type='rpm', channel='ga', rhui=''), PESIDRepositoryEntry(pesid='rhel8-BaseOS', major_version='8', repoid='rhel8-baseos-repoid', arch='x86_64', repo_type='rpm', channel='ga', rhui=''), PESIDRepositoryEntry(pesid='rhel8-BaseOS', major_version='8', repoid='rhel8-baseos-repoid-eus', arch='x86_64', repo_type='rpm', channel='eus', rhui=''), PESIDRepositoryEntry(pesid='rhel8-AppStream', major_version='8', repoid='rhel8-appstream-repoid', arch='x86_64', repo_type='rpm', channel='ga', rhui=''), PESIDRepositoryEntry(pesid='rhel8-CRB', major_version='8', repoid='rhel8-crb-repoid', arch='x86_64', repo_type='rpm', channel='ga', rhui=''), PESIDRepositoryEntry(pesid='rhel8-CRB', major_version='8', repoid='rhel8-crb-repoid-eus', arch='x86_64', repo_type='rpm', channel='eus', rhui=''), ]) monkeypatch.setattr(peseventsscanner, '_get_enabled_repoids', lambda: {source_repoid}) monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=[repositories_mapping], src_ver='7.9', dst_ver='8.4')) event = Event(1, Action.MOVED, {'test-pkg': 'rhel7-base'}, {'test-pkg': 'rhel8-CRB'}, (7, 9), (8, 0), []) installed_pkgs = {'test-pkg'} tasks = process_events([(8, 0)], [event], installed_pkgs) assert tasks[Task.KEEP] == {'test-pkg': expected_target_repoid}
def make_pesid_repo(pesid, major_version, repoid, arch='x86_64', repo_type='rpm', channel='ga', rhui=''): """ PESIDRepositoryEntry factory function allowing shorter data description in tests by providing default values. """ return PESIDRepositoryEntry(pesid=pesid, major_version=major_version, repoid=repoid, arch=arch, repo_type=repo_type, channel=channel, rhui=rhui)
def add_repository(self, data, pesid): """ Add new PESIDRepositoryEntry with given pesid from the provided dictionary. :param data: A dict containing the data of the added repository. The dictionary structure corresponds to the repositories entries in the repository mapping JSON schema. :type data: Dict[str, str] :param pesid: PES id of the repository family that the newly added repository belongs to. :type pesid: str """ self.repositories.append( PESIDRepositoryEntry(repoid=data['repoid'], channel=data['channel'], rhui=data.get('rhui', ''), repo_type=data['repo_type'], arch=data['arch'], major_version=data['major_version'], pesid=pesid))
def _get_repositories_mapping(target_pesids): """ Get all repositories mapped from repomap file and map repositories id with respective names. :param target_pesids: The set of expected needed target PES IDs :return: Dictionary with all repositories mapped. """ repositories_map_msgs = api.consume(RepositoriesMapping) repositories_map_msg = next(repositories_map_msgs, None) if list(repositories_map_msgs): api.current_logger().warning( 'Unexpectedly received more than one RepositoriesMapping message.') if not repositories_map_msg: raise StopActorExecutionError( 'Cannot parse RepositoriesMapping data properly', details={ 'Problem': 'Did not receive a message with mapped repositories' }) repomap = peseventsscanner_repomap.RepoMapDataHandler(repositories_map_msg) # NOTE: We have to calculate expected target repositories # like in the setuptargetrepos actor. It's planned to handle this in different # way in future... enabled_repoids = _get_enabled_repoids() default_channels = peseventsscanner_repomap.get_default_repository_channels( repomap, enabled_repoids) repomap.set_default_channels(default_channels) exp_pesid_repos = repomap.get_expected_target_pesid_repos(enabled_repoids) # FIXME: this is hack now. In case some packages will need a repository # with pesid that is not mapped by default regarding the enabled repos, # let's use this one representative repository (baseos/appstream) to get # data for a guess of the best repository from the requires target pesid.. # FIXME: this could now fail in case all repos are disabled... representative_repo = exp_pesid_repos.get( peseventsscanner_repomap.DEFAULT_PESID[get_target_major_version()], None) if not representative_repo: api.current_logger().warning( 'Cannot determine the representative target base repository.') api.current_logger().info( 'Fallback: Create an artificial representative PESIDRepositoryEntry for the repository mapping' ) representative_repo = PESIDRepositoryEntry( pesid=peseventsscanner_repomap.DEFAULT_PESID[ get_target_major_version()], arch=api.current_actor().configuration.architecture, major_version=get_target_major_version(), repoid='artificial-repoid', repo_type='rpm', channel='ga', rhui='', ) for pesid in target_pesids: if pesid in exp_pesid_repos: continue # some packages are moved to repos outside of default repomapping # try to find the best possible repo for them.. # FIXME: HACK NOW # good way is to modify class to search repo with specific criteria.. if not representative_repo: api.current_logger().warning( 'Cannot find suitable repository for PES ID: {}'.format(pesid)) continue pesid_repo = repomap._find_repository_target_equivalent( representative_repo, pesid) if not pesid_repo: api.current_logger().warning( 'Cannot find suitable repository for PES ID: {}'.format(pesid)) continue exp_pesid_repos[pesid] = pesid_repo # map just pesids with found repoids # {to_pesid: repoid} repositories_mapping = {} for pesid, repository in exp_pesid_repos.items(): if pesid not in target_pesids: # We can skip this repo as it was not identified as needed during the processing of PES events continue if not repository: # TODO continue repositories_mapping[pesid] = repository.repoid return repositories_mapping
def test_scan_existing_valid_data(monkeypatch, adjust_cwd): """ Tests whether an existing valid repomap file is loaded correctly. """ with open('files/repomap_example.json') as repomap_file: data = json.load(repomap_file) monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(src_ver='7.9', dst_ver='8.4')) monkeypatch.setattr(api, 'produce', produce_mocked()) repositoriesmapping.scan_repositories(lambda dummy: data) assert api.produce.called, 'Actor did not produce any message when deserializing valid repomap data.' fail_description = 'Actor produced multiple messages, but only one was expected.' assert len(api.produce.model_instances) == 1, fail_description repo_mapping = api.produce.model_instances[0] # Verify that the loaded JSON data is matching the repomap file content # 1. Verify src_pesid -> target_pesids mappings are loaded and filtered correctly fail_description = 'Actor produced more mappings than there are source system relevant mappings in the test file.' assert len(repo_mapping.mapping) == 1, fail_description fail_description = 'Actor failed to load IPU-relevant mapping data correctly.' assert repo_mapping.mapping[0].source == 'pesid1', fail_description assert set(repo_mapping.mapping[0].target) == {'pesid2', 'pesid3'}, fail_description # 2. Verify that only repositories valid for the current IPU are produced pesid_repos = repo_mapping.repositories fail_description = 'Actor produced incorrect number of IPU-relevant pesid repos.' assert len(pesid_repos) == 3, fail_description expected_pesid_repos = [ PESIDRepositoryEntry(pesid='pesid1', major_version='7', repoid='some-rhel-7-repoid', arch='x86_64', repo_type='rpm', channel='eus', rhui=''), PESIDRepositoryEntry(pesid='pesid2', major_version='8', repoid='some-rhel-8-repoid1', arch='x86_64', repo_type='rpm', channel='eus', rhui=''), PESIDRepositoryEntry(pesid='pesid3', major_version='8', repoid='some-rhel-8-repoid2', arch='x86_64', repo_type='rpm', channel='eus', rhui=''), ] fail_description = 'Expected pesid repo is not present in the deserialization output.' for expected_pesid_repo in expected_pesid_repos: assert expected_pesid_repo in pesid_repos, fail_description
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