def test_single_kernel_s390x(monkeypatch): monkeypatch.setattr(api, 'current_actor', CurrentActorMocked()) monkeypatch.setattr(api, 'current_logger', logger_mocked()) monkeypatch.setattr(api, 'consume', mocked_consume(s390x_pkgs_single)) monkeypatch.setattr(reporting, 'create_report', create_report_mocked()) checkinstalledkernels.process() assert not reporting.create_report.called monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(arch=architecture.ARCH_S390X)) monkeypatch.setattr(api, 'consume', mocked_consume(s390x_pkgs_single)) checkinstalledkernels.process() assert not reporting.create_report.called
def test_repositoriesblacklist_empty(monkeypatch): monkeypatch.setattr(repositoriesblacklist, "_get_repos_to_exclude", lambda: set()) # pylint:disable=W0108 monkeypatch.setattr(api, 'current_actor', CurrentActorMocked()) monkeypatch.setattr(api, "produce", produce_mocked()) repositoriesblacklist.process() assert api.produce.called == 0
def test_without_optionals(monkeypatch): def repositories_mock(*model): mapping = [ RepositoryMap( to_pes_repo='rhel-7-foobar-rpms', from_repoid='rhel-7-foobar-rpms', to_repoid='rhel-8-foobar-rpms', from_minor_version='all', to_minor_version='all', arch='x86_64', repo_type='rpm', ), RepositoryMap( to_pes_repo='rhel-7-blacklist-rpms', from_repoid='rhel-7-blacklist-rpms', to_repoid='rhel-8-blacklist-rpms', from_minor_version='all', to_minor_version='all', arch='x86_64', repo_type='rpm', ), ] yield RepositoriesMap(repositories=mapping) monkeypatch.setattr(api, "consume", repositories_mock) monkeypatch.setattr(api, 'current_actor', CurrentActorMocked()) assert not repositoriesblacklist._get_optional_repo_mapping()
def test_perform_ok(monkeypatch): repoids = ['repoidX', 'repoidY'] monkeypatch.setattr(userspacegen, '_InputData', mocked_consume_data) monkeypatch.setattr(userspacegen, '_get_product_certificate_path', lambda: _DEFAULT_CERT_PATH) monkeypatch.setattr(overlaygen, 'create_source_overlay', MockedMountingBase) monkeypatch.setattr(userspacegen, '_gather_target_repositories', lambda *x: repoids) monkeypatch.setattr(userspacegen, '_create_target_userspace', lambda *x: None) monkeypatch.setattr(userspacegen.api, 'current_actor', CurrentActorMocked()) monkeypatch.setattr(userspacegen.api, 'produce', produce_mocked()) monkeypatch.setattr(repofileutils, 'get_repodirs', lambda: ['/etc/yum.repos.d']) userspacegen.perform() msg_target_repos = models.UsedTargetRepositories( repos=[models.UsedTargetRepository(repoid=repo) for repo in repoids]) assert userspacegen.api.produce.called == 3 assert isinstance(userspacegen.api.produce.model_instances[0], models.TMPTargetRepositoriesFacts) assert userspacegen.api.produce.model_instances[1] == msg_target_repos # this one is full of contants, so it's safe to check just the instance assert isinstance(userspacegen.api.produce.model_instances[2], models.TargetUserSpaceInfo)
def test_no_enabledrepos(monkeypatch): monkeypatch.setattr(api, 'produce', produce_mocked()) monkeypatch.setattr(api, 'current_logger', LoggerMocked()) monkeypatch.setattr(api, 'current_actor', CurrentActorMocked()) scanclienablerepo.process() assert not api.current_logger.infomsg assert not api.produce.called
def test_basic_checkpcidrivers( monkeypatch, driver_name, pci_id, inhibit_upgrade, num_msgs, ): """Check the main actor function.""" pci_devices.devices[0].driver = driver_name pci_devices.devices[0].pci_id = pci_id monkeypatch.setattr( api, "current_actor", CurrentActorMocked(msgs=[pci_devices, restricted_pci_devices]), ) monkeypatch.setattr( reporting, "create_report", create_report_mocked(), ) monkeypatch.setattr( CurrentActorMocked, "produce", produce_mocked(), ) checkpcidrivers_main() if inhibit_upgrade: assert len(CurrentActorMocked.produce.model_instances) == 1 assert CurrentActorMocked.produce.model_instances[0].report[ "flags"] == ["inhibitor"] if num_msgs and not inhibit_upgrade: assert ("flags" not in CurrentActorMocked.produce.model_instances[0].report) assert len(CurrentActorMocked.produce.model_instances) == num_msgs
def test_no_network_renaming(monkeypatch): """ This should cover OAMG-4243. """ # this mock should be needed, as this function should be called, but just # for a check.. monkeypatch.setattr(persistentnetnamesconfig, 'generate_link_file', generate_link_file_mocked) interfaces = generate_interfaces(4) for i in range(4): interfaces[i].name = 'myinterface{}'.format(i) msgs = [PersistentNetNamesFacts(interfaces=interfaces)] interfaces[0].name = 'changedinterfacename0' msgs.append(PersistentNetNamesFactsInitramfs(interfaces=interfaces)) mocked_actor = CurrentActorMocked( msgs=msgs, envars={'LEAPP_NO_NETWORK_RENAMING': '1'}) monkeypatch.setattr(persistentnetnamesconfig.api, 'current_actor', mocked_actor) monkeypatch.setattr(persistentnetnamesconfig.api, 'current_logger', logger_mocked()) monkeypatch.setattr(persistentnetnamesconfig.api, 'produce', produce_mocked()) persistentnetnamesconfig.process() ilog = 'Skipping handling of possibly renamed network interfaces: leapp executed with LEAPP_NO_NETWORK_RENAMING=1' assert ilog in persistentnetnamesconfig.api.current_logger.infomsg assert not persistentnetnamesconfig.api.produce.called
def test_get_mapped_target_pesid_repos(monkeypatch, mapping_data_for_find_repository_equiv): """ Test for the RepoMapDataHandler.get_mapped_target_pesid_repos method. Verifies that the method correctly builds a map mapping the target pesid to the best candidate pesid repos. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) repositories = mapping_data_for_find_repository_equiv.repositories handler = RepoMapDataHandler(mapping_data_for_find_repository_equiv) # Both pesid2 and pesid3 have an equivalent for provided source pesid repository fail_description = ( 'The get_mapped_target_pesid_repos failed to build a map mapping the target pesid ' 'to the best pesid repository candidate.') target_pesid_repos_map = handler.get_mapped_target_pesid_repos( repositories[0]) expected_pesid_to_best_candidate_map = { 'pesid2': repositories[2], 'pesid3': repositories[8] } assert target_pesid_repos_map == expected_pesid_to_best_candidate_map, fail_description # The pesid3 does not have an equivalent for provided source pesid repository (due to not having any rhui repos) target_pesid_repos_map = handler.get_mapped_target_pesid_repos( repositories[1]) expected_pesid_to_best_candidate_map = { 'pesid2': repositories[6], 'pesid3': None } assert target_pesid_repos_map == expected_pesid_to_best_candidate_map, fail_description
def test_get_mapped_target_repoids(monkeypatch, mapping_data_for_find_repository_equiv): """ Test for the RepoMapDataHandler.get_mapped_target_repoids method. Verifies that the method returns a correct list of repoids that should be present on the target system. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) handler = RepoMapDataHandler(mapping_data_for_find_repository_equiv) repositories = mapping_data_for_find_repository_equiv.repositories fail_description = ( 'The get_mapped_target_repoids method failed to return the correct list of repoids ', 'to be enabled on the target system.') # Both pesid2 and pesid3 have an equivalent for provided source pesid repository actual_target_repoids = handler.get_mapped_target_repoids(repositories[0]) expected_target_repoids = {repositories[2].repoid, repositories[8].repoid} assert len(actual_target_repoids) == len( expected_target_repoids), fail_description assert set( actual_target_repoids) == expected_target_repoids, fail_description # The pesid3 does not have an equivalent for provided source pesid # repository -> only one repository should be in the produced list actual_target_repoids = handler.get_mapped_target_repoids(repositories[1]) assert len(actual_target_repoids) == 1 assert 'pesid2-repoid4.1' in actual_target_repoids, fail_description
def test_get_pesid_repos(monkeypatch, repomap_data_for_pesid_repo_retrieval): """ Test for the RepoMapDataHandler.get_pesid_repos method. Verifies that the method is able to collect all PESIDRepositoryEntry present in the repomap data that match the given OS major version and the given pesid. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) handler = RepoMapDataHandler(repomap_data_for_pesid_repo_retrieval) repositories = repomap_data_for_pesid_repo_retrieval.repositories actual_pesid_repos = handler.get_pesid_repos('pesid3', '8') expected_pesid_repos = [repositories[3], repositories[4], repositories[5]] fail_description = 'The get_pesid_repos failed to find pesid repos matching the given criteria.' assert len(expected_pesid_repos) == len( actual_pesid_repos), fail_description for actual_pesid_repo in actual_pesid_repos: assert actual_pesid_repo in expected_pesid_repos, fail_description actual_pesid_repos = handler.get_pesid_repos('pesid1', '7') expected_pesid_repos = [repositories[0], repositories[1]] assert len(expected_pesid_repos) == len( actual_pesid_repos), fail_description for actual_pesid_repo in actual_pesid_repos: assert actual_pesid_repo in expected_pesid_repos, fail_description fail_description = ( 'The get_pesid_repos found some pesid repositories matching criteria, but there are no such repositories.' ) assert [] == handler.get_pesid_repos('pesid3', '7'), fail_description assert [] == handler.get_pesid_repos('pesid1', '8'), fail_description assert [] == handler.get_pesid_repos('nonexisting_pesid', '7'), fail_description
def test_find_repository_target_equivalent_fallback_to_default( monkeypatch, mapping_data_for_find_repository_equiv): """ Test for the RepoMapDataHandler._find_repository_target_equivalent method. Verifies that the method will find a target equivalent with matchin some of the fallback channels if a target equivalent that matches the source pesid repository completely is not available in the repository mapping data. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) handler = RepoMapDataHandler(mapping_data_for_find_repository_equiv) repositories = mapping_data_for_find_repository_equiv.repositories fail_description = ( 'The _find_repository_target_equivalent failed to find repository with some of the fallback channels.' ) expected_target_equivalent = repositories[6] actual_target_equivalent = handler._find_repository_target_equivalent( repositories[1], 'pesid2') assert expected_target_equivalent == actual_target_equivalent, fail_description handler.set_default_channels(['eus', 'ga']) expected_target_equivalent = repositories[7] actual_target_equivalent = handler._find_repository_target_equivalent( repositories[1], 'pesid2') assert expected_target_equivalent == actual_target_equivalent, fail_description
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_actor_execution(monkeypatch, has_server): """ Parametrized helper function for test_actor_* functions. First generate list of RPM models based on set arguments. Then, run the actor feeded with our RPM list. Finally, assert Reports according to set arguments. Parameters: has_server (bool): postgresql-server installed """ # Couple of random packages rpms = [_generate_rpm_with_name('sed'), _generate_rpm_with_name('htop')] if has_server: # Add postgresql-server rpms += [_generate_rpm_with_name('postgresql-server')] curr_actor_mocked = CurrentActorMocked( msgs=[InstalledRedHatSignedRPM(items=rpms)]) monkeypatch.setattr(api, 'current_actor', curr_actor_mocked) monkeypatch.setattr(reporting, "create_report", create_report_mocked()) # Executed actor feeded with out fake RPMs report_installed_packages(_context=api) if has_server: # Assert for postgresql-server package installed assert reporting.create_report.called == 1 else: # Assert for no postgresql packages installed assert not reporting.create_report.called
def test_is_rhel_alt(monkeypatch, result, kernel, release_id, src_ver): monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(src_ver=src_ver, kernel=kernel, release_id=release_id)) assert version.is_rhel_alt() == result
def test_get_target_pesids(monkeypatch, repomap_data_for_pesid_repo_retrieval): """ Test for the RepoMapDataHandler.get_target_pesids method. Verifies that the method correctly tells what target pesids is the given source pesid mapped to. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) handler = RepoMapDataHandler(repomap_data_for_pesid_repo_retrieval) expected_target_pesids = ['pesid2', 'pesid3'] actual_target_pesids = handler.get_target_pesids('pesid1') fail_description = ( 'The get_target_pesids method did not correctly identify what is the given source pesid mapped to.' ) assert expected_target_pesids == actual_target_pesids, fail_description fail_description = ( 'The get_target_pesids method found target pesids even if the source repository is not mapped.' ) assert [] == handler.get_target_pesids('pesid2'), fail_description assert [] == handler.get_target_pesids( 'pesid_no_mapping'), fail_description
def test_get_expected_target_repoids_simple(monkeypatch): """ Test for the RepoMapDataHandler.get_expected_target_repoids method. Verifies that the method is able to produce a correct map that maps target pesid to the best candidate pesid repository when there is only one repoid enabled and the corresponding source pesid repository has exact match target equivalent. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) repositories_mapping = RepositoriesMapping( mapping=[RepoMapEntry(source='pesid1', target=['pesid2'])], repositories=[ make_pesid_repo('pesid1', '7', 'pesid1-repoid'), make_pesid_repo('pesid2', '8', 'pesid2-repoid') ]) fail_description = 'Failed to get_expected_target_repoids with only one repository enabled on the source system.' handler = RepoMapDataHandler(repositories_mapping) target_repoids = handler.get_expected_target_pesid_repos(['pesid1-repoid']) assert { 'pesid2': repositories_mapping.repositories[1] } == target_repoids, fail_description
def test_consume_data(monkeypatch, raised, no_rhsm, testdata): # do not write never into testdata inside the test !! xfs = testdata.xfs custom_repofiles = testdata.custom_repofiles _exp_pkgs = {'dnf', 'dnf-command(config-manager)'} _exp_files = [] def _get_pkgs(msg): if isinstance(msg, models.TargetUserSpacePreupgradeTasks): return msg.install_rpms return msg.packages def _get_files(msg): if isinstance(msg, models.TargetUserSpacePreupgradeTasks): return msg.copy_files return [] def _cfiles2set(cfiles): return {(i.src, i.dst) for i in cfiles} if isinstance(testdata.pkg_msgs, list): for msg in testdata.pkg_msgs: _exp_pkgs.update(_get_pkgs(msg)) _exp_files += _get_files(msg) else: _exp_pkgs.update(_get_pkgs(testdata.pkg_msgs)) _exp_files += _get_files(testdata.pkg_msgs) mocked_consume = MockedConsume(testdata.pkg_msgs, testdata.rhsm_info, testdata.rhui_info, xfs, testdata.storage, custom_repofiles) monkeypatch.setattr(userspacegen.api, 'consume', mocked_consume) monkeypatch.setattr(userspacegen.api, 'current_logger', logger_mocked()) monkeypatch.setattr(userspacegen.api, 'current_actor', CurrentActorMocked(envars={'LEAPP_NO_RHSM': no_rhsm})) if not xfs: xfs = models.XFSPresence() if not custom_repofiles: custom_repofiles = [] if not raised: result = userspacegen._InputData() assert result.packages == _exp_pkgs assert _cfiles2set(result.files) == _cfiles2set(_exp_files) assert result.rhsm_info == testdata.rhsm_info assert result.rhui_info == testdata.rhui_info assert result.xfs_info == xfs assert result.storage_info == testdata.storage assert result.custom_repofiles == custom_repofiles assert not userspacegen.api.current_logger.warnmsg assert not userspacegen.api.current_logger.errmsg else: with pytest.raises(raised[0]) as err: userspacegen._InputData() if isinstance(err.value, StopActorExecutionError): assert raised[1] in err.value.message else: assert userspacegen.api.current_logger.warnmsg assert any([ raised[1] in x for x in userspacegen.api.current_logger.warnmsg ])
def test_get_expected_target_repoids_best_candidate_produced(monkeypatch): """ Test for the RepoMapDataHandler.get_expected_target_repoids method. Verifies that the method is able to produce a correct map that maps target pesid to the best candidate pesid repository when there are two repositories with different priority channels belonging to the same pesid family enabled on the source system and both have target equivalents. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) repositories_mapping = RepositoriesMapping( mapping=[RepoMapEntry(source='pesid1', target=['pesid2'])], repositories=[ make_pesid_repo('pesid1', '7', 'pesid1-repoid-ga'), make_pesid_repo('pesid1', '7', 'pesid1-repoid-eus', channel='eus'), make_pesid_repo('pesid2', '8', 'pesid2-repoid-ga'), make_pesid_repo('pesid2', '8', 'pesid2-repoid-eus', channel='eus'), make_pesid_repo('pesid2', '8', 'pesid2-repoid-e4s', channel='e4s'), ]) handler = RepoMapDataHandler(repositories_mapping) target_repoids = handler.get_expected_target_pesid_repos( ['pesid1-repoid-eus']) fail_description = ( 'The get_expected_target_repoids failed to map target pesid to a pesid repository' 'with the highest priority channel.') assert { 'pesid2': repositories_mapping.repositories[3] } == target_repoids, fail_description
def test_checktargetrepos_no_rhsm(monkeypatch, enable_repos, custom_target_repos, custom_target_repofile): mocked_consume = MockedConsume(_TARGET_REPOS_CUSTOM if custom_target_repos else _TARGET_REPOS_NO_CUSTOM) if custom_target_repofile: mocked_consume._msgs.append(_CUSTOM_TARGET_REPOFILE) envars = {'LEAPP_ENABLE_REPOS': 'hill,spencer'} if enable_repos else {} monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(envars=envars)) monkeypatch.setattr(reporting, 'create_report', create_report_mocked()) monkeypatch.setattr(rhsm, 'skip_rhsm', lambda: True) monkeypatch.setattr(api, 'consume', mocked_consume) checktargetrepos.process() if not custom_target_repos: assert reporting.create_report.called == 1 assert 'inhibitor' in reporting.create_report.report_fields.get( 'flags', []) elif not enable_repos and custom_target_repos and not custom_target_repofile: assert reporting.create_report.called == 1 assert 'inhibitor' not in reporting.create_report.report_fields.get( 'flags', []) else: assert reporting.create_report.called == 0
def test_get_expected_target_repoids_fallback(monkeypatch): """ Test for the RepoMapDataHandler.get_expected_target_repoids method. Verifies that the RepoMapDataHandler.get_expected_target_repoids method is able to produce a correct map that maps target pesid to the best candidate pesid repository when there is a repository on the source system that does not have exact match equivalent and some other with a fallback channel must be found. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) repositories_mapping = RepositoriesMapping( mapping=[RepoMapEntry(source='pesid1', target=['pesid2'])], repositories=[ make_pesid_repo('pesid1', '7', 'pesid1-repoid-eus', channel='eus'), make_pesid_repo('pesid2', '8', 'pesid2-repoid-ga'), make_pesid_repo('pesid1', '8', 'pesid2-repoid-e4s', channel='e4s'), ]) fail_description = ( 'The get_expected_target_repoids failed to find repository with a failback channel ' 'since there were no exact target equivalents.') handler = RepoMapDataHandler(repositories_mapping) handler.set_default_channels(['ga']) target_repoids = handler.get_expected_target_pesid_repos( ['pesid1-repoid-eus']) assert { 'pesid2': repositories_mapping.repositories[1] } == target_repoids, fail_description
def test_gather_target_repositories_required_not_available(monkeypatch): # If the repos that Leapp identifies as required for the upgrade (based on the repo mapping and PES data) are not # available, an exception shall be raised monkeypatch.setattr(userspacegen.api, 'current_actor', CurrentActorMocked()) # The available RHSM repos monkeypatch.setattr(rhsm, 'get_available_repo_ids', lambda x: ['repoidA', 'repoidB', 'repoidC']) monkeypatch.setattr(rhsm, 'skip_rhsm', lambda: False) # The required RHEL repos based on the repo mapping and PES data + custom repos required by third party actors monkeypatch.setattr( userspacegen.api, 'consume', lambda x: iter([ models.TargetRepositories( rhel_repos=[ models.RHELTargetRepository(repoid='repoidX'), models.RHELTargetRepository(repoid='repoidY') ], custom_repos= [models.CustomTargetRepository(repoid='repoidCustom')]) ])) with pytest.raises(StopActorExecutionError) as err: userspacegen.gather_target_repositories(None) assert "Cannot find required basic RHEL 8 repositories" in str(err)
def test_get_expected_target_pesid_repos_multiple_repositories(monkeypatch): """ Test for the RepoMapDataHandler.get_expected_target_repoids method. Verifies that the RepoMapDataHandler.get_expected_target_repoids method is able to produce a correct map that maps target pesid to the best candidate pesid repository when one source pesid is mapped to multiple target pesids (every target pesid should have an entry in the returned map). """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) repositories_mapping = RepositoriesMapping( mapping=[RepoMapEntry(source='pesid1', target=['pesid2', 'pesid3'])], repositories=[ make_pesid_repo('pesid1', '7', 'pesid1-repoid-ga'), make_pesid_repo('pesid2', '8', 'pesid2-repoid-ga'), make_pesid_repo('pesid3', '8', 'pesid3-repoid-ga') ]) fail_description = 'Failed to get_expected_target_repoids when one source pesid is mapped to two target pesids.' handler = RepoMapDataHandler(repositories_mapping) target_repoids = handler.get_expected_target_pesid_repos( ['pesid1-repoid-ga']) assert { 'pesid2': repositories_mapping.repositories[1], 'pesid3': repositories_mapping.repositories[2] } == target_repoids, fail_description
def test_non_ibmz_arch(monkeypatch): monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(architecture.ARCH_X86_64)) monkeypatch.setattr(reporting, "create_report", testutils.create_report_mocked()) cpu.process() assert not reporting.create_report.called
def test_get_expected_target_pesid_repos_unmapped_repository(monkeypatch): """ Test for the RepoMapDataHandler.get_expected_target_repoids method. Verifies that the RepoMapDataHandler.get_expected_target_repoids method does not fail when there is a repository on the source system that is not mapped. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) repositories_mapping = RepositoriesMapping( mapping=[RepoMapEntry(source='pesid1', target=['pesid2'])], repositories=[ make_pesid_repo('pesid1', '7', 'pesid1-repoid-ga'), make_pesid_repo('pesid2', '8', 'pesid2-repoid-ga') ]) fail_description = 'Failed to get_expected_target_repoids when one of the source repoids is unmapped.' handler = RepoMapDataHandler(repositories_mapping) target_repoids = handler.get_expected_target_pesid_repos( ['pesid1-repoid-ga', 'unmapped-repoid']) assert { 'pesid2': repositories_mapping.repositories[1] } == target_repoids, fail_description
def test_repositoriesblacklist_empty(monkeypatch): monkeypatch.setattr(repositoriesblacklist, "_get_disabled_optional_repo", lambda: []) monkeypatch.setattr(api, 'current_actor', CurrentActorMocked()) monkeypatch.setattr(api, "produce", produce_mocked()) repositoriesblacklist.process() assert api.produce.called == 0
def test_get_pesid_repo_entry(monkeypatch, repomap_data_for_pesid_repo_retrieval): """ Test for the RepoMapDataHandler.get_pesid_repo_entry method. Verifies that the method correctly retrieves PESIDRepositoryEntry that are matching the OS major version and repoid. """ monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4')) repositories = repomap_data_for_pesid_repo_retrieval.repositories handler = RepoMapDataHandler(repomap_data_for_pesid_repo_retrieval) fail_description = ( 'get_pesid_repo_entry method failed to find correct pesid repository that matches given parameters.' ) for exp_repo in repositories: result_repo = handler.get_pesid_repo_entry(exp_repo.repoid, exp_repo.major_version) assert result_repo == exp_repo, fail_description fail_description = ( 'get_pesid_repo_entry method found a pesid repository, but no repository should match given parameters.' ) assert handler.get_pesid_repo_entry('pesid1-repoid', '6') is None, fail_description assert handler.get_pesid_repo_entry('pesid1-repoid', '8') is None, fail_description assert handler.get_pesid_repo_entry('pesid1-repoid', '9') is None, fail_description assert handler.get_pesid_repo_entry('nonexisting-repo', '7') is None, fail_description
def test_with_optionals(monkeypatch, valid_opt_repoid, product_type): all_opt_repoids = {'rhel-7-optional-rpms', 'rhel-7-optional-beta-rpms', 'rhel-7-optional-htb-rpms'} # set of repos that should not be marked as optionals non_opt_repoids = all_opt_repoids - {valid_opt_repoid} | {'rhel-7-blacklist-rpms'} def repositories_mock(*model): mapping = [ RepositoryMap( to_pes_repo='rhel-7-blacklist-rpms', from_repoid='rhel-7-blacklist-rpms', to_repoid='rhel-8-blacklist-rpms', from_minor_version='all', to_minor_version='all', arch='x86_64', repo_type='rpm', ), ] for repoid in all_opt_repoids: mapping.append(RepositoryMap( to_pes_repo='rhel-7-foobar-rpms', from_repoid=repoid, to_repoid='rhel-8-optional-rpms', from_minor_version='all', to_minor_version='all', arch='x86_64', repo_type='rpm', )) yield RepositoriesMap(repositories=mapping) monkeypatch.setattr(api, "consume", repositories_mock) monkeypatch.setattr(api, 'current_actor', CurrentActorMocked( envars={'LEAPP_DEVEL_SOURCE_PRODUCT_TYPE': product_type})) optionals = set(repositoriesblacklist._get_optional_repo_mapping()) assert {valid_opt_repoid} == optionals assert not non_opt_repoids & optionals
def test_find_repository_equivalent_with_priority_channel(monkeypatch): """ Tests whether the _find_repository_target_equivalent correctly respects the chosen preferred channel. """ envars = {'LEAPP_DEVEL_TARGET_PRODUCT_TYPE': 'eus'} monkeypatch.setattr( api, 'current_actor', CurrentActorMocked(arch='x86_64', src_ver='7.9', dst_ver='8.4', envars=envars)) repositories_mapping = RepositoriesMapping( mapping=[RepoMapEntry(source='pesid1', target=['pesid2'])], repositories=[ make_pesid_repo('pesid1', '7', 'pesid1-repoid-ga'), make_pesid_repo('pesid2', '8', 'pesid2-repoid-ga', channel='ga'), make_pesid_repo('pesid2', '8', 'pesid2-repoid-eus', channel='eus'), ]) handler = RepoMapDataHandler(repositories_mapping) handler.set_default_channels(['ga']) assert handler.prio_channel == 'eus' fail_description = '_find_repository_target_equivalent does not correcly respect preferred channel.' expected_target_equivalent = repositories_mapping.repositories[2] actual_target_equivalent = handler._find_repository_target_equivalent( repositories_mapping.repositories[0], 'pesid2') assert expected_target_equivalent == actual_target_equivalent, fail_description
def test_flawless(monkeypatch, msgs, files, modules): _msgs = msgs + [InstalledTargetKernelVersion(version=KERNEL_VERSION)] run_mocked = RunMocked() monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=_msgs)) monkeypatch.setattr(targetinitramfsgenerator, 'run', run_mocked) # FIXME monkeypatch.setattr(targetinitramfsgenerator, 'copy_dracut_modules', lambda dummy: None) targetinitramfsgenerator.process() assert run_mocked.called # check files if files: assert '--install' in run_mocked.args arg = run_mocked.args[run_mocked.args.index('--install') + 1] for f in files: assert f in arg else: assert '--install' not in run_mocked.args # check modules if modules: assert '--add' in run_mocked.args arg = run_mocked.args[run_mocked.args.index('--add') + 1] for m in modules: assert m[0] in arg else: assert '--add' not in run_mocked.args
def test_custom_repos(monkeypatch): """ Tests whether the CustomRepos provided to the actor are propagated to the TargetRepositories after blacklist filtering is applied on them. """ custom = CustomTargetRepository( repoid='rhel-8-server-rpms', name='RHEL 8 Server (RPMs)', baseurl='https://.../dist/rhel/server/8/os', enabled=True) blacklisted = CustomTargetRepository( repoid='rhel-8-blacklisted-rpms', name='RHEL 8 Blacklisted (RPMs)', baseurl='https://.../dist/rhel/blacklisted/8/os', enabled=True) repos_blacklisted = RepositoriesBlacklisted( repoids=['rhel-8-blacklisted-rpms']) repositories_mapping = RepositoriesMapping(mapping=[], repositories=[]) msgs = [custom, blacklisted, repos_blacklisted, repositories_mapping] monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=msgs)) monkeypatch.setattr(api, 'produce', produce_mocked()) setuptargetrepos.process() assert api.produce.called custom_repos = api.produce.model_instances[0].custom_repos assert len(custom_repos) == 1 assert custom_repos[0].repoid == 'rhel-8-server-rpms'