Skip to content

Commit

Permalink
Skip creating the yum.repos.d structure on debian based systems
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernhard committed Jan 12, 2024
1 parent ebe024d commit 7ffb3cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
22 changes: 13 additions & 9 deletions src/subscription_manager/repofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,16 @@ class RepoFileBase:
NAME: str = None
REPOFILE_HEADER: str = None

def __init__(self, path: Optional[str] = None, name: Optional[str] = None):
def __init__(self, path: Optional[str] = None, name: Optional[str] = None, options: List[str] = []):
# PATH gets expanded with chroot info, etc
path = path or self.PATH
name = name or self.NAME
self.path: str = Path.join(path, name)
self.repos_dir: str = Path.abs(path)
self.manage_repos: bool = manage_repos_enabled()
if self.manage_repos is True:
self.create()
if len(options) == 0 or "skip_creating_repo" not in options:
self.create()

# Easier than trying to mock/patch os.path.exists
def path_exists(self, path: str) -> bool:
Expand Down Expand Up @@ -413,8 +414,8 @@ class AptRepoFile(RepoFileBase):
#
"""

def __init__(self, path: Optional[str] = None, name: Optional[str] = None):
super(AptRepoFile, self).__init__(path, name)
def __init__(self, path: Optional[str] = None, name: Optional[str] = None, options: List[str] = []):
super(AptRepoFile, self).__init__(path, name, options)
self.repos822 = []

def read(self):
Expand Down Expand Up @@ -503,9 +504,9 @@ class YumRepoFile(RepoFileBase, ConfigParser):
#
"""

def __init__(self, path: Optional[str] = None, name: Optional[str] = None):
def __init__(self, path: Optional[str] = None, name: Optional[str] = None, options: List[str] = []):
ConfigParser.__init__(self)
RepoFileBase.__init__(self, path, name)
RepoFileBase.__init__(self, path, name, options)

def read(self) -> None:
ConfigParser.read(self, self.path)
Expand Down Expand Up @@ -582,8 +583,8 @@ class ZypperRepoFile(YumRepoFile):
#
"""

def __init__(self, path: Optional[str] = None, name: Optional[str] = None):
super(ZypperRepoFile, self).__init__(path, name)
def __init__(self, path: Optional[str] = None, name: Optional[str] = None, options: List[str] = []):
super(ZypperRepoFile, self).__init__(path, name, options)
self.gpgcheck: bool = False
self.repo_gpgcheck: bool = False
self.autorefresh: bool = False
Expand Down Expand Up @@ -693,9 +694,12 @@ def server_value_repo_file(cls) -> "ZypperRepoFile":


def init_repo_file_classes() -> List[Tuple[type(RepoFileBase), str]]:
repo_file_classes: List[type(RepoFileBase)] = [YumRepoFile, ZypperRepoFile]
repo_file_classes: List[type(RepoFileBase)] = []
if HAS_DEB822:
repo_file_classes.append(AptRepoFile)
else:
repo_file_classes.append(YumRepoFile)
repo_file_classes.append(ZypperRepoFile)
_repo_files: List[Tuple[type(RepoFileBase), type(RepoFileBase)]] = [
(RepoFile, RepoFile.server_value_repo_file) for RepoFile in repo_file_classes if RepoFile.installed()
]
Expand Down
8 changes: 6 additions & 2 deletions src/subscription_manager/repolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from subscription_manager.model import ent_cert
from subscription_manager.repofile import Repo, manage_repos_enabled, get_repo_file_classes
from subscription_manager.repofile import YumRepoFile
from subscription_manager.repofile import HAS_DEB822
from subscription_manager.utils import get_supported_resources

import rhsm.config
Expand Down Expand Up @@ -217,7 +218,10 @@ def get_repos(self, apply_overrides: bool = True) -> Set[Repo]:

current = set()
# Add the current repo data
yum_repo_file = YumRepoFile()
if HAS_DEB822:
yum_repo_file = YumRepoFile(options=["skip_creating_repo"])
else:
yum_repo_file = YumRepoFile()
yum_repo_file.read()
server_value_repo_file = YumRepoFile("var/lib/rhsm/repo_server_val/")
server_value_repo_file.read()
Expand All @@ -238,7 +242,7 @@ def get_repos(self, apply_overrides: bool = True) -> Set[Repo]:
return current

def get_repo_file(self) -> str:
yum_repo_file = YumRepoFile()
yum_repo_file = YumRepoFile(options=["skip_creating_repo"])
return yum_repo_file.path

@classmethod
Expand Down

0 comments on commit 7ffb3cf

Please sign in to comment.