Skip to content

Commit 2883279

Browse files
committed
Skip creating the yum.repos.d structure on debian based systems
1 parent ebe024d commit 2883279

2 files changed

Lines changed: 148 additions & 121 deletions

File tree

src/subscription_manager/repofile.py

Lines changed: 127 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import re
2424
import string
2525
import sys
26+
from importlib import util as importlib_util
2627

2728
try:
2829
from debian.deb822 import Deb822
@@ -31,6 +32,11 @@
3132
except ImportError:
3233
HAS_DEB822 = False
3334

35+
if importlib_util.find_spec("zypp_plugin") is not None:
36+
HAS_ZYPP = True
37+
else:
38+
HAS_ZYPP = False
39+
3440
from subscription_manager import utils
3541
from subscription_manager.certdirectory import Path
3642
import configparser
@@ -562,15 +568,17 @@ def section(self, section: str) -> "Repo":
562568
return Repo(section, self.items(section))
563569

564570

565-
class ZypperRepoFile(YumRepoFile):
566-
"""
567-
Class for manipulation of repo file on systems using Zypper (SuSE, OpenSuse).
568-
"""
571+
if HAS_ZYPP:
569572

570-
ZYPP_RHSM_PLUGIN_CONFIG_FILE = "/etc/rhsm/zypper.conf"
571-
PATH = "etc/rhsm/zypper.repos.d"
572-
NAME = "redhat.repo"
573-
REPOFILE_HEADER = """#
573+
class ZypperRepoFile(YumRepoFile):
574+
"""
575+
Class for manipulation of repo file on systems using Zypper (SuSE, OpenSuse).
576+
"""
577+
578+
ZYPP_RHSM_PLUGIN_CONFIG_FILE = "/etc/rhsm/zypper.conf"
579+
PATH = "etc/rhsm/zypper.repos.d"
580+
NAME = "redhat.repo"
581+
REPOFILE_HEADER = """#
574582
# Certificate-Based Repositories
575583
# Managed by (rhsm) subscription-manager
576584
#
@@ -582,120 +590,124 @@ class ZypperRepoFile(YumRepoFile):
582590
#
583591
"""
584592

585-
def __init__(self, path: Optional[str] = None, name: Optional[str] = None):
586-
super(ZypperRepoFile, self).__init__(path, name)
587-
self.gpgcheck: bool = False
588-
self.repo_gpgcheck: bool = False
589-
self.autorefresh: bool = False
590-
# According to
591-
# https://github.com/openSUSE/libzypp/blob/67f55b474d67f77c1868955da8542a7acfa70a9f/zypp/media/MediaManager.h#L394
592-
# the following values are valid: "yes", "no", "host", "peer"
593-
self.gpgkey_ssl_verify: Optional[str] = None
594-
self.repo_ssl_verify: Optional[str] = None
595-
596-
def read_zypp_conf(self):
597-
"""
598-
Read configuration file for zypper plugin
599-
:return: None
600-
"""
601-
zypp_cfg = configparser.ConfigParser()
602-
zypp_cfg.read(self.ZYPP_RHSM_PLUGIN_CONFIG_FILE)
603-
if zypp_cfg.has_option("rhsm-plugin", "gpgcheck"):
604-
self.gpgcheck = zypp_cfg.getboolean("rhsm-plugin", "gpgcheck")
605-
if zypp_cfg.has_option("rhsm-plugin", "repo_gpgcheck"):
606-
self.repo_gpgcheck = zypp_cfg.getboolean("rhsm-plugin", "repo_gpgcheck")
607-
if zypp_cfg.has_option("rhsm-plugin", "autorefresh"):
608-
self.autorefresh = zypp_cfg.getboolean("rhsm-plugin", "autorefresh")
609-
if zypp_cfg.has_option("rhsm-plugin", "gpgkey-ssl-verify"):
610-
self.gpgkey_ssl_verify = zypp_cfg.get("rhsm-plugin", "gpgkey-ssl-verify")
611-
if zypp_cfg.has_option("rhsm-plugin", "repo-ssl-verify"):
612-
self.repo_ssl_verify = zypp_cfg.get("rhsm-plugin", "repo-ssl-verify")
613-
614-
def fix_content(self, content: "Content") -> str:
615-
self.read_zypp_conf()
616-
zypper_cont = content.copy()
617-
sslverify = zypper_cont["sslverify"]
618-
sslcacert = zypper_cont["sslcacert"]
619-
sslclientkey = zypper_cont["sslclientkey"]
620-
sslclientcert = zypper_cont["sslclientcert"]
621-
proxy = zypper_cont["proxy"]
622-
proxy_username = zypper_cont["proxy_username"]
623-
proxy_password = zypper_cont["proxy_password"]
624-
625-
del zypper_cont["sslverify"]
626-
del zypper_cont["sslcacert"]
627-
del zypper_cont["sslclientkey"]
628-
del zypper_cont["sslclientcert"]
629-
del zypper_cont["proxy"]
630-
del zypper_cont["proxy_username"]
631-
del zypper_cont["proxy_password"]
632-
# NOTE looks like metadata_expire and ui_repoid_vars are ignored by zypper
633-
634-
# clean up data for zypper
635-
if zypper_cont["gpgkey"] in ["https://", "http://"]:
636-
del zypper_cont["gpgkey"]
637-
638-
# make sure gpg key download doesn't fail because of private certs
639-
if zypper_cont["gpgkey"] and self.gpgkey_ssl_verify:
640-
zypper_cont["gpgkey"] += "?ssl_verify=%s" % self.gpgkey_ssl_verify
641-
642-
# See BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1764265
643-
if self.gpgcheck is False:
644-
zypper_cont["gpgcheck"] = "0"
645-
646-
# See BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1858231
647-
if self.repo_gpgcheck is True:
648-
zypper_cont["repo_gpgcheck"] = "1"
649-
else:
650-
zypper_cont["repo_gpgcheck"] = "0"
651-
652-
# See BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1797386
653-
if self.autorefresh is True:
654-
zypper_cont["autorefresh"] = "1"
655-
else:
656-
zypper_cont["autorefresh"] = "0"
657-
658-
baseurl = zypper_cont["baseurl"]
659-
parsed = urlparse(baseurl)
660-
zypper_query_args: Dict[str, str] = parse_qs(parsed.query)
593+
def __init__(self, path: Optional[str] = None, name: Optional[str] = None):
594+
super(ZypperRepoFile, self).__init__(path, name)
595+
self.gpgcheck: bool = False
596+
self.repo_gpgcheck: bool = False
597+
self.autorefresh: bool = False
598+
# According to
599+
# https://github.com/openSUSE/libzypp/blob/67f55b474d67f77c1868955da8542a7acfa70a9f/zypp/media/MediaManager.h#L394
600+
# the following values are valid: "yes", "no", "host", "peer"
601+
self.gpgkey_ssl_verify: Optional[str] = None
602+
self.repo_ssl_verify: Optional[str] = None
603+
604+
def read_zypp_conf(self):
605+
"""
606+
Read configuration file for zypper plugin
607+
:return: None
608+
"""
609+
zypp_cfg = configparser.ConfigParser()
610+
zypp_cfg.read(self.ZYPP_RHSM_PLUGIN_CONFIG_FILE)
611+
if zypp_cfg.has_option("rhsm-plugin", "gpgcheck"):
612+
self.gpgcheck = zypp_cfg.getboolean("rhsm-plugin", "gpgcheck")
613+
if zypp_cfg.has_option("rhsm-plugin", "repo_gpgcheck"):
614+
self.repo_gpgcheck = zypp_cfg.getboolean("rhsm-plugin", "repo_gpgcheck")
615+
if zypp_cfg.has_option("rhsm-plugin", "autorefresh"):
616+
self.autorefresh = zypp_cfg.getboolean("rhsm-plugin", "autorefresh")
617+
if zypp_cfg.has_option("rhsm-plugin", "gpgkey-ssl-verify"):
618+
self.gpgkey_ssl_verify = zypp_cfg.get("rhsm-plugin", "gpgkey-ssl-verify")
619+
if zypp_cfg.has_option("rhsm-plugin", "repo-ssl-verify"):
620+
self.repo_ssl_verify = zypp_cfg.get("rhsm-plugin", "repo-ssl-verify")
621+
622+
def fix_content(self, content: "Content") -> str:
623+
self.read_zypp_conf()
624+
zypper_cont = content.copy()
625+
sslverify = zypper_cont["sslverify"]
626+
sslcacert = zypper_cont["sslcacert"]
627+
sslclientkey = zypper_cont["sslclientkey"]
628+
sslclientcert = zypper_cont["sslclientcert"]
629+
proxy = zypper_cont["proxy"]
630+
proxy_username = zypper_cont["proxy_username"]
631+
proxy_password = zypper_cont["proxy_password"]
632+
633+
del zypper_cont["sslverify"]
634+
del zypper_cont["sslcacert"]
635+
del zypper_cont["sslclientkey"]
636+
del zypper_cont["sslclientcert"]
637+
del zypper_cont["proxy"]
638+
del zypper_cont["proxy_username"]
639+
del zypper_cont["proxy_password"]
640+
# NOTE looks like metadata_expire and ui_repoid_vars are ignored by zypper
641+
642+
# clean up data for zypper
643+
if zypper_cont["gpgkey"] in ["https://", "http://"]:
644+
del zypper_cont["gpgkey"]
645+
646+
# make sure gpg key download doesn't fail because of private certs
647+
if zypper_cont["gpgkey"] and self.gpgkey_ssl_verify:
648+
zypper_cont["gpgkey"] += "?ssl_verify=%s" % self.gpgkey_ssl_verify
649+
650+
# See BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1764265
651+
if self.gpgcheck is False:
652+
zypper_cont["gpgcheck"] = "0"
653+
654+
# See BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1858231
655+
if self.repo_gpgcheck is True:
656+
zypper_cont["repo_gpgcheck"] = "1"
657+
else:
658+
zypper_cont["repo_gpgcheck"] = "0"
661659

662-
if sslverify and sslverify in ["1"]:
663-
if self.repo_ssl_verify:
664-
zypper_query_args["ssl_verify"] = self.repo_ssl_verify
660+
# See BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1797386
661+
if self.autorefresh is True:
662+
zypper_cont["autorefresh"] = "1"
665663
else:
666-
zypper_query_args["ssl_verify"] = "host"
667-
668-
if sslcacert:
669-
zypper_query_args["ssl_capath"] = os.path.dirname(sslcacert)
670-
if sslclientkey:
671-
zypper_query_args["ssl_clientkey"] = sslclientkey
672-
if sslclientcert:
673-
zypper_query_args["ssl_clientcert"] = sslclientcert
674-
if proxy:
675-
zypper_query_args["proxy"] = proxy
676-
if proxy_username:
677-
zypper_query_args["proxyuser"] = proxy_username
678-
if proxy_password:
679-
zypper_query_args["proxypass"] = proxy_password
680-
zypper_query = urlencode(zypper_query_args)
681-
682-
new_url = urlunparse(
683-
(parsed.scheme, parsed.netloc, parsed.path, parsed.params, zypper_query, parsed.fragment)
684-
)
685-
zypper_cont["baseurl"] = new_url
686-
687-
return zypper_cont
688-
689-
# We need to overwrite this, to avoid name clashes with yum's server_val_repo_file
690-
@classmethod
691-
def server_value_repo_file(cls) -> "ZypperRepoFile":
692-
return cls("var/lib/rhsm/repo_server_val/", "zypper_{}".format(cls.NAME))
664+
zypper_cont["autorefresh"] = "0"
665+
666+
baseurl = zypper_cont["baseurl"]
667+
parsed = urlparse(baseurl)
668+
zypper_query_args: Dict[str, str] = parse_qs(parsed.query)
669+
670+
if sslverify and sslverify in ["1"]:
671+
if self.repo_ssl_verify:
672+
zypper_query_args["ssl_verify"] = self.repo_ssl_verify
673+
else:
674+
zypper_query_args["ssl_verify"] = "host"
675+
676+
if sslcacert:
677+
zypper_query_args["ssl_capath"] = os.path.dirname(sslcacert)
678+
if sslclientkey:
679+
zypper_query_args["ssl_clientkey"] = sslclientkey
680+
if sslclientcert:
681+
zypper_query_args["ssl_clientcert"] = sslclientcert
682+
if proxy:
683+
zypper_query_args["proxy"] = proxy
684+
if proxy_username:
685+
zypper_query_args["proxyuser"] = proxy_username
686+
if proxy_password:
687+
zypper_query_args["proxypass"] = proxy_password
688+
zypper_query = urlencode(zypper_query_args)
689+
690+
new_url = urlunparse(
691+
(parsed.scheme, parsed.netloc, parsed.path, parsed.params, zypper_query, parsed.fragment)
692+
)
693+
zypper_cont["baseurl"] = new_url
694+
695+
return zypper_cont
696+
697+
# We need to overwrite this, to avoid name clashes with yum's server_val_repo_file
698+
@classmethod
699+
def server_value_repo_file(cls) -> "ZypperRepoFile":
700+
return cls("var/lib/rhsm/repo_server_val/", "zypper_{}".format(cls.NAME))
693701

694702

695703
def init_repo_file_classes() -> List[Tuple[type(RepoFileBase), str]]:
696-
repo_file_classes: List[type(RepoFileBase)] = [YumRepoFile, ZypperRepoFile]
704+
repo_file_classes: List[type(RepoFileBase)] = []
697705
if HAS_DEB822:
698706
repo_file_classes.append(AptRepoFile)
707+
elif HAS_ZYPP:
708+
repo_file_classes.append(ZypperRepoFile)
709+
else:
710+
repo_file_classes.append(YumRepoFile)
699711
_repo_files: List[Tuple[type(RepoFileBase), type(RepoFileBase)]] = [
700712
(RepoFile, RepoFile.server_value_repo_file) for RepoFile in repo_file_classes if RepoFile.installed()
701713
]

src/subscription_manager/repolib.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,19 @@
2323
from subscription_manager import model
2424
from subscription_manager.model import ent_cert
2525
from subscription_manager.repofile import Repo, manage_repos_enabled, get_repo_file_classes
26-
from subscription_manager.repofile import YumRepoFile
26+
from subscription_manager.repofile import YumRepoFile, RepoFileBase
27+
from subscription_manager.repofile import HAS_DEB822, HAS_ZYPP
2728
from subscription_manager.utils import get_supported_resources
2829

2930
import rhsm.config
3031
import configparser
3132
from rhsmlib.facts.hwprobe import HardwareCollector
3233

34+
if HAS_DEB822:
35+
from rhsm.repofile import AptRepoFile
36+
if HAS_ZYPP:
37+
from rhsm.repofile import ZypperRepoFile
38+
3339
# FIXME: local imports
3440

3541
from subscription_manager.certlib import ActionReport, BaseActionInvoker
@@ -217,12 +223,12 @@ def get_repos(self, apply_overrides: bool = True) -> Set[Repo]:
217223

218224
current = set()
219225
# Add the current repo data
220-
yum_repo_file = YumRepoFile()
221-
yum_repo_file.read()
226+
repo_file = self.get_system_repo_file()
227+
repo_file.read()
222228
server_value_repo_file = YumRepoFile("var/lib/rhsm/repo_server_val/")
223229
server_value_repo_file.read()
224230
for repo in repos:
225-
existing = yum_repo_file.section(repo.id)
231+
existing = repo_file.section(repo.id)
226232
server_value_repo = server_value_repo_file.section(repo.id)
227233
# we need a repo in the server val file to match any in
228234
# the main repo definition file
@@ -237,9 +243,18 @@ def get_repos(self, apply_overrides: bool = True) -> Set[Repo]:
237243

238244
return current
239245

246+
def get_system_repo_file(self) -> "RepoFileBase":
247+
if HAS_DEB822:
248+
repo = AptRepoFile()
249+
elif HAS_ZYPP:
250+
repo = ZypperRepoFile()
251+
else:
252+
repo = YumRepoFile()
253+
return repo
254+
240255
def get_repo_file(self) -> str:
241-
yum_repo_file = YumRepoFile()
242-
return yum_repo_file.path
256+
repo_file = self.get_system_repo_file()
257+
return repo_file.path
243258

244259
@classmethod
245260
def delete_repo_file(cls) -> None:

0 commit comments

Comments
 (0)