diff --git a/src/subscription_manager/repofile.py b/src/subscription_manager/repofile.py index cc98803493..6c41d74c61 100644 --- a/src/subscription_manager/repofile.py +++ b/src/subscription_manager/repofile.py @@ -338,7 +338,7 @@ 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 @@ -346,7 +346,8 @@ def __init__(self, path: Optional[str] = None, name: Optional[str] = None): 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: @@ -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): @@ -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) @@ -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 @@ -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() ] diff --git a/src/subscription_manager/repolib.py b/src/subscription_manager/repolib.py index 4e7c016b46..13d1c965db 100644 --- a/src/subscription_manager/repolib.py +++ b/src/subscription_manager/repolib.py @@ -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 @@ -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() @@ -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