def test_repos_mapping(current_actor_context): repos_data = [ RepositoryData(repoid='rhel-7-server-rpms', name='RHEL 7 Server') ] 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') ] repos_map = RepositoriesMap(repositories=mapping) current_actor_context.feed(facts) current_actor_context.feed(repos_map) current_actor_context.run() assert current_actor_context.consume(TargetRepositories) assert len( current_actor_context.consume(TargetRepositories)[0].rhel_repos) == 2
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 scan_repositories(path): if not os.path.isfile(path): inhibit_upgrade('Repositories map file not found ({})'.format(path)) if os.path.getsize(path) == 0: inhibit_upgrade('Repositories map file is invalid ({})'.format(path)) repositories = [] with open(path) as f: data = csv.reader(f) next(data) # skip header for row in data: if len(row) != 6: continue from_id, to_id, from_minor_version, to_minor_version, arch, repo_type = row try: repositories.append( RepositoryMap(from_id=from_id, to_id=to_id, from_minor_version=from_minor_version, to_minor_version=to_minor_version, arch=arch, repo_type=repo_type)) except ModelViolationError as err: inhibit_upgrade( 'Repositories map file is invalid ({})'.format(err)) if len(repositories) == 0: inhibit_upgrade('Repositories map file is invalid ({})'.format(path)) api.produce(RepositoriesMap(repositories=repositories))
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)
def gen_RepositoriesMap(repomap_records): """Generate Repositories map from the given repomap records.""" repositories = [] for record in repomap_records: repositories.append( RepositoryMap(from_repoid=record[0], to_repoid=record[1], to_pes_repo=record[2], from_minor_version=record[3], to_minor_version=record[4], arch=record[5], repo_type=record[6])) return RepositoriesMap(repositories=repositories)
def scan_repositories(read_repofile_func=_read_repofile): """ Scan the repository mapping file and produce RepositoriesMap msg. See the description of the actor for more details. """ _exp_src_prod_type = config.get_product_type('source') _exp_dst_prod_type = config.get_product_type('target') repositories = [] line_num = 0 for line in read_repofile_func(REPOMAP_FILE)[1:]: line_num += 1 # skip empty lines and comments if not line or line.startswith('#'): continue try: (from_repoid, to_repoid, to_pes_repo, from_minor_version, to_minor_version, arch, repo_type, src_prod_type, dst_prod_type) = line.split(',') # filter out records irrelevant for this run if (arch != api.current_actor().configuration.architecture or _exp_src_prod_type != src_prod_type or _exp_dst_prod_type != dst_prod_type): continue repositories.append( RepositoryMap( from_repoid=from_repoid, to_repoid=to_repoid, to_pes_repo=to_pes_repo, from_minor_version=from_minor_version, to_minor_version=to_minor_version, arch=arch, repo_type=repo_type, )) except (ModelViolationError, ValueError) as err: _inhibit_upgrade( 'The repository mapping file is invalid, offending line number: {} ({}).' ' It is possible the file is out of date.'.format( line_num, err)) if not repositories: _inhibit_upgrade( 'The repository mapping file is invalid. Could not find any repository mapping record.' ) api.produce(RepositoriesMap(repositories=repositories))
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)
def scan_repositories(path): if not os.path.isfile(path): inhibit_upgrade('Repositories map file not found ({})'.format(path)) if os.path.getsize(path) == 0: inhibit_upgrade('Repositories map file is invalid ({})'.format(path)) repositories = [] with open(path) as f: data = csv.reader(f) next(data) # skip header for row in data: # skip empty lines and comments if not row or row[0].startswith('#'): continue try: from_repoid, to_repoid, to_pes_repo, from_minor_version, to_minor_version, arch, repo_type = row except ValueError as err: inhibit_upgrade('Repositories map file is invalid, offending line number: {} ({})'.format( data.line_num, err)) if arch != api.current_actor().configuration.architecture: continue try: repositories.append( RepositoryMap( from_repoid=from_repoid, to_repoid=to_repoid, to_pes_repo=to_pes_repo, from_minor_version=from_minor_version, to_minor_version=to_minor_version, arch=arch, repo_type=repo_type, ) ) except ModelViolationError as err: inhibit_upgrade('Repositories map file is invalid, offending line number: {} ({})'.format( data.line_num, err)) if not repositories: inhibit_upgrade('Repositories map file is invalid ({})'.format(path)) api.produce(RepositoriesMap(repositories=repositories))
def process(self): repos_maps = RepositoriesMap() with open(self.get_file_path('repomap.csv')) as f: data = csv.reader(f) next(data) # skip header for row in data: if len(row) != 6: continue from_id, to_id, from_minor_version, to_minor_version, arch, repo_type = row repos_maps.repositories.append( RepositoryMap(from_id=from_id, to_id=to_id, from_minor_version=from_minor_version, to_minor_version=to_minor_version, arch=arch, repo_type=repo_type)) self.produce(repos_maps)
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