-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
targetuserspacecreator: Refactor gathering of repositories #973
Open
vinzenz
wants to merge
1
commit into
oamg:main
Choose a base branch
from
vinzenz:repository-collection-refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
97 changes: 97 additions & 0 deletions
97
repos/system_upgrade/common/actors/targetuserspacecreator/libraries/repoinfo.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,97 @@ | ||
from collections import defaultdict | ||
|
||
from leapp.libraries.common import repofileutils | ||
from leapp.libraries.stdlib import api | ||
from leapp.models import TargetRepositories | ||
|
||
DEFAULT_RHSM_REPOFILE = '/etc/yum.repos.d/redhat.repo' | ||
|
||
REPO_KIND_RHUI = 'rhui' | ||
REPO_KIND_RHSM = 'rhsm' | ||
REPO_KIND_CUSTOM = 'custom' | ||
|
||
|
||
class _RequestedRepoIDs(object): | ||
def __init__(self): | ||
self.rhel_repos = set() | ||
self.custom_repos = set() | ||
|
||
@property | ||
def combined(self): | ||
return self.rhel_repos | self.custom_repos | ||
|
||
|
||
def _get_requested_repo_ids(): | ||
""" | ||
Get all requested target repositories. | ||
""" | ||
result = _RequestedRepoIDs() | ||
for msg in api.consume(TargetRepositories): | ||
result.rhel_repos.update({r.repoid for r in msg.rhel_repos}) | ||
result.custom_repos.update({r.repoid for r in msg.custom_repos}) | ||
return result | ||
|
||
|
||
class RepositoryInformation(object): | ||
def __init__(self, context, cloud_repo=None): | ||
self.repos = [] | ||
self.rfiles = [] | ||
self.mapped = defaultdict(list) | ||
self.repo_type_map = defaultdict(set) | ||
self._target_repo_ids = _get_requested_repo_ids() | ||
self._load_repofiles(context=context, cloud_repo=cloud_repo) | ||
|
||
def _load_repofiles(self, context, cloud_repo=None): | ||
for rfile in repofileutils.get_parsed_repofiles( | ||
context=context, | ||
kind_resolve=resolve_repo_file_kind(cloud_repo)): | ||
self.add_file(rfile) | ||
|
||
@property | ||
def rhsm_repoids(self): | ||
return self.repo_type_map[REPO_KIND_RHSM] | ||
|
||
@property | ||
def rhui_repoids(self): | ||
return self.repo_type_map[REPO_KIND_RHUI] | ||
|
||
@property | ||
def rhel_repoids(self): | ||
return self.rhsm_repoids | self.rhui_repoids | ||
|
||
@property | ||
def custom_repoids(self): | ||
return self.repo_type_map[REPO_KIND_CUSTOM] | ||
|
||
@property | ||
def missing_custom_repoids(self): | ||
return self._target_repo_ids.custom_repos - self.custom_repoids | ||
|
||
@property | ||
def target_repoids(self): | ||
return (self._target_repo_ids.custom_repos & self.custom_repoids) | ( | ||
self._target_repo_ids.rhel_repos & self.rhel_repoids) | ||
|
||
def add_file(self, rfile): | ||
self.rfiles.append(rfile) | ||
for repo in rfile.data: | ||
self.add(repo) | ||
|
||
def add(self, repo): | ||
self.repos.append(repo) | ||
self.mapped[repo.repoid].append(repo) | ||
self.repo_type_map[repo.kind].add(repo.repoid) | ||
|
||
@property | ||
def duplicated_repoids(self): | ||
return {k: v for k, v in self.mapped.items() if len(v) > 1} | ||
|
||
|
||
def resolve_repo_file_kind(cloud_repo): | ||
def resolver(path): | ||
if path == DEFAULT_RHSM_REPOFILE: | ||
return REPO_KIND_RHSM | ||
if cloud_repo and path == cloud_repo: | ||
return REPO_KIND_RHUI | ||
return REPO_KIND_CUSTOM | ||
return resolver |
34 changes: 34 additions & 0 deletions
34
repos/system_upgrade/common/actors/targetuserspacecreator/libraries/repos.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,34 @@ | ||
import os | ||
|
||
from leapp.libraries.actor import repoinfo | ||
from leapp.libraries.common import rhsm, rhui | ||
|
||
|
||
def _install_custom_repofiles(context, custom_repofiles): | ||
""" | ||
Install the required custom repository files into the container. | ||
|
||
The repository files are copied from the host into the /etc/yum.repos.d | ||
directory into the container. | ||
|
||
:param context: the container where the repofiles should be copied | ||
:type context: mounting.IsolatedActions class | ||
:param custom_repofiles: list of custom repo files | ||
:type custom_repofiles: List(CustomTargetRepositoryFile) | ||
""" | ||
for rfile in custom_repofiles: | ||
_dst_path = os.path.join('/etc/yum.repos.d', os.path.basename(rfile.file)) | ||
context.copy_to(rfile.file, _dst_path) | ||
|
||
|
||
def prepare_repository_collection(context, indata, prod_cert_path): | ||
rhsm.set_container_mode(context) | ||
rhsm.switch_certificate(context, indata.rhsm_info, prod_cert_path) | ||
if indata.rhui_info: | ||
rhui.copy_rhui_data(context, indata.rhui_info.provider) | ||
_install_custom_repofiles(context, indata.custom_repofiles) | ||
|
||
|
||
def collect_repositories(context, cloud_repo=None): | ||
info = repoinfo.RepositoryInformation(context, cloud_repo) | ||
return info |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The property name suggests that it contains a collection of repoids that are duplicated, whereas a dictionary is returned. Every use of this property access to the values of the property requests only its keys().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it is right now, the point is that you can now report which repo files do contain the duplications. But this would be a follow up improvement. And it is a collection, key = repoid, value = list of repos with the same repo id)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list of repos here means the list of repository files