diff --git a/debian-stuff/80package-profile-upload b/debian-stuff/80package-profile-upload index a188da5d57..f64aecd377 100644 --- a/debian-stuff/80package-profile-upload +++ b/debian-stuff/80package-profile-upload @@ -1 +1 @@ -DPkg::Post-Invoke { /usr/lib/katello-client/bin/deb_package_profile_upload } +DPkg::Post-Invoke { /usr/bin/package-profile-upload } diff --git a/debian-stuff/deb_package_profile_upload b/debian-stuff/deb_package_profile_upload deleted file mode 100755 index b2acee8ffc..0000000000 --- a/debian-stuff/deb_package_profile_upload +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh - -set -eu - -exit_msg() { - echo $1 - exit -} - -[ -f /etc/rhsm/rhsm.conf ] || exit_msg "subscription-manager is not installed. Skipping." - -KATELLO_SERVER=$(sed -n -e 's/^hostname\s*=\s*\(.*\)$/\1/p' /etc/rhsm/rhsm.conf) - -[ "${KATELLO_SERVER}" ] || exit_msg "No Katello server is configured. Skipping." - -IDENTITY=$(LANG=C subscription-manager identity 2> /dev/null | sed -n 's/system identity: //p') - -[ "${IDENTITY}" ] || exit_msg "Host is not registered with Katello. Skipping." - -echo -n "Upload Package Profile" - -dpkg -l |\ - awk '$1 ~ /^ii/ { sub(/:.*$/, "", $2); printf("{\"name\": \"%s\", \"version\": \"%s\", \"architecture\": \"%s\"}\n", $2, $3, $4) }' |\ - jq -s '{"deb_package_profile": {"deb_packages": .}}' |\ - http --cert /etc/pki/consumer/cert.pem --cert-key /etc/pki/consumer/key.pem --verify /etc/rhsm/ca/katello-default-ca.pem PUT https://${KATELLO_SERVER}/rhsm/systems/${IDENTITY}/deb_package_profile/ > /dev/null || exit_msg "Something went wrong." - -echo . - -if [ -f /etc/apt/sources.list.d/rhsm.sources ] -then - echo -n "Update bound repositories" - sed -ne 's/^baseurl:\s*\(.*\)$/"\1"/p' < /etc/apt/sources.list.d/rhsm.sources | jq -s "{enabled_repos: {repos: map({baseurl: [.]})}}" |\ - http --cert /etc/pki/consumer/cert.pem --cert-key /etc/pki/consumer/key.pem --verify /etc/rhsm/ca/katello-default-ca.pem PUT https://${KATELLO_SERVER}/rhsm/systems/${IDENTITY}/enabled_repos/ > /dev/null || exit_msg "Something went wrong." - echo . -fi diff --git a/debian-stuff/katello b/debian-stuff/katello index 51f6ded754..b2abc67875 100755 --- a/debian-stuff/katello +++ b/debian-stuff/katello @@ -1,4 +1,4 @@ -#! /usr/bin/python -u +#! /usr/bin/python3 -u # # The katello Acquire Method # @@ -29,7 +29,7 @@ import re import hashlib import requests from urllib.parse import quote -from configparser import SafeConfigParser +from configparser import ConfigParser class pkg_acquire_method: @@ -138,7 +138,7 @@ class katello_method(pkg_acquire_method): Return the proxy server config from /etc/rhsm/rhsm.conf as dict Adapted from https://github.com/Katello/katello-client-bootstrap/blob/master/bootstrap.py """ - rhsmconfig = SafeConfigParser() + rhsmconfig = ConfigParser() rhsmconfig.read('/etc/rhsm/rhsm.conf') proxy_options = [option for option in rhsmconfig.options('server') if option.startswith('proxy')] diff --git a/src/plugins/zypper/services/rhsm b/src/plugins/zypper/services/rhsm index 6b43660fe8..1f5b665336 100755 --- a/src/plugins/zypper/services/rhsm +++ b/src/plugins/zypper/services/rhsm @@ -19,13 +19,13 @@ import os import sys from subscription_manager import injection as inj -from subscription_manager.repofile import ZypperRepoFile from subscription_manager.repolib import RepoActionInvoker from subscription_manager.entcertlib import EntCertActionInvoker from subscription_manager.certlib import Locker from subscription_manager.injectioninit import init_dep_injection from rhsm import connection, logutil from rhsm import config +from rhsm.repofile import ZypperRepoFile from configparser import ConfigParser diff --git a/src/rhsm/profile.py b/src/rhsm/profile.py index 374df83b52..b504cbd9bd 100644 --- a/src/rhsm/profile.py +++ b/src/rhsm/profile.py @@ -14,31 +14,38 @@ import importlib.util import rpm -import os.path -from typing import List, Union +import os +from typing import List, Optional, Union from rhsm import ourjson as json from rhsm.utils import suppress_output -from iniparse import SafeConfigParser, ConfigParser +from rhsm.repofile import get_repo_file_classes +from rhsm.repofile import YumRepoFile from cloud_what import provider try: - import dnf + from rhsm.repofile import dnf except ImportError: dnf = None try: - import libdnf + from rhsm.repofile import libdnf except ImportError: libdnf = None try: - import yum + from rhsm.repofile import yum except ImportError: yum = None +try: + from rhsm.repofile import apt +except ImportError: + apt = None + use_zypper: bool = importlib.util.find_spec("zypp_plugin") is not None + if use_zypper: REPOSITORY_PATH = "/etc/rhsm/zypper.repos.d/redhat.repo" else: @@ -86,7 +93,7 @@ def _uniquify(module_list: list) -> list: return list(ret.values()) @staticmethod - def fix_aws_rhui_repos(base: "dnf.Base") -> None: + def fix_aws_rhui_repos(base) -> None: """ Try to fix RHUI repos on AWS systems. When the system is running on AWS, then we have to fix repository URL. See: https://bugzilla.redhat.com/show_bug.cgi?id=1924126 @@ -191,111 +198,34 @@ def collect(self) -> List[dict]: return self.content -class EnabledRepos: - def __generate(self) -> List[dict]: - if not os.path.exists(self.repofile): - return [] - - # Unfortuantely, we can not use the SafeConfigParser for zypper repo - # files because the repository urls contains strings which the - # SafeConfigParser don't like. It would crash with - # ConfigParser.InterpolationSyntaxError: '%' must be followed by '%' or '(' - if use_zypper: - config = ConfigParser() - else: - config = SafeConfigParser() - config.read(self.repofile) - enabled_sections = [section for section in config.sections() if config.getboolean(section, "enabled")] - enabled_repos = [] - for section in enabled_sections: - try: - enabled_repos.append( - { - "repositoryid": section, - "baseurl": [self._format_baseurl(config.get(section, "baseurl"))], - } - ) - except ImportError: - break - return enabled_repos - - def __init__(self, repo_file: str) -> None: - """ - Initialize EnabledRepos - :param repo_file: A repo file path used to filter the report. - """ - if dnf is not None: - self.db = dnf.dnf.Base() - elif yum is not None: - self.yb = yum.YumBase() - - self.repofile: str = repo_file - self.content: List[dict] = self.__generate() - - def __str__(self) -> str: - return str(self.content) - - def _format_baseurl(self, repo_url: str) -> str: - """ - Returns a well formatted baseurl string - :param repo_url: a repo URL that you want to format - """ - if use_zypper: - return self._cut_question_mark(repo_url) - else: - mappings = self._obtain_mappings() - return repo_url.replace("$releasever", mappings["releasever"]).replace( - "$basearch", mappings["basearch"] - ) - - def _cut_question_mark(self, repo_url) -> str: - """ - Returns a string where everything after the first occurrence of '?' is truncated - :param repo_url: a repo URL that you want to modify - """ - return repo_url[: repo_url.find("?")] - - @suppress_output - def _obtain_mappings(self) -> dict: - """ - returns a hash with "basearch" and "releasever" set. This will try dnf first, and them yum if dnf is - not installed. - """ - if dnf is not None: - return self._obtain_mappings_dnf() - elif yum is not None: - return self._obtain_mappings_yum() - else: - log.error("Unable to load module for any supported package manager (dnf, yum).") - raise ImportError - - def _obtain_mappings_dnf(self) -> dict: - return { - "releasever": self.db.conf.substitutions["releasever"], - "basearch": self.db.conf.substitutions["basearch"], - } - - def _obtain_mappings_yum(self) -> dict: - return {"releasever": self.yb.conf.yumvar["releasever"], "basearch": self.yb.conf.yumvar["basearch"]} - - class EnabledReposProfile: """ Collect information about enabled repositories """ - def __init__(self, repo_file: str = REPOSITORY_PATH) -> None: - self._enabled_repos: EnabledRepos = EnabledRepos(repo_file) + def __init__(self, repo_file: Optional[str] = None) -> None: + self._content = [] + + if repo_file is not None: + yum_repo = YumRepoFile(os.path.dirname(repo_file), os.path.basename(repo_file)) + yum_repo.read() + self._content.extend(yum_repo.enabled_repos()) + else: + for repo_file_cls, _ in get_repo_file_classes(): + repo_file = repo_file_cls() + repo_file.read() + self._content.extend(repo_file.enabled_repos()) + self._content.sort(key=lambda x: x["baseurl"]) def __eq__(self, other: "EnabledReposProfile") -> bool: - return self._enabled_repos.content == other._enabled_repos.content + return self._content == other._content def collect(self) -> List[dict]: """ Gather list of enabled repositories :return: List of enabled repositories """ - return self._enabled_repos.content + return self._content class Package: @@ -444,7 +374,33 @@ def __eq__(self, other: "RPMProfile") -> bool: return True -def get_profile(profile_type: str) -> Union[RPMProfile, EnabledRepos, ModulesProfile]: +class DebProfile(object): + def __init__(self): + cache = apt.Cache() + self._deb_profile = [ + { + "name": package.name, + "version": package.installed.version, + "architecture": package.installed.architecture, + } + for package in cache + if package.installed is not None + ] + + def __eq__(self, other): + """ + Compare one profile to another to determine if anything has changed. + """ + if not isinstance(self, type(other)): + return False + + return self._deb_profile == other._deb_profile + + def collect(self): + return self._deb_profile + + +def get_profile(profile_type: str): """ Returns an instance of a Profile object @param profile_type: profile type @@ -458,7 +414,12 @@ def get_profile(profile_type: str) -> Union[RPMProfile, EnabledRepos, ModulesPro # Profile types we support: PROFILE_MAP: dict = { - "rpm": RPMProfile, "enabled_repos": EnabledReposProfile, - "modulemd": ModulesProfile, } + +if dnf is not None or yum is not None: + PROFILE_MAP["rpm"] = RPMProfile + PROFILE_MAP["modulemd"] = ModulesProfile + +if apt is not None: + PROFILE_MAP["deb"] = DebProfile diff --git a/src/subscription_manager/repofile.py b/src/rhsm/repofile.py similarity index 83% rename from src/subscription_manager/repofile.py rename to src/rhsm/repofile.py index c5bbee9ba4..7098690798 100644 --- a/src/subscription_manager/repofile.py +++ b/src/rhsm/repofile.py @@ -25,11 +25,30 @@ import sys try: + import apt from debian.deb822 import Deb822 +except ImportError: + apt = None - HAS_DEB822 = True +try: + import dnf +except ImportError: + dnf = None + +try: + import libdnf except ImportError: - HAS_DEB822 = False + libdnf = None + +try: + import yum +except ImportError: + yum = None + +try: + import zypp +except ImportError: + zypp = None from subscription_manager import utils from subscription_manager.certdirectory import Path @@ -77,7 +96,7 @@ class Repo(dict): def __init__(self, repo_id: str, existing_values: List = None): super().__init__() - if HAS_DEB822 is True: + if apt is not None: self.PROPERTIES["arches"] = (1, None) # existing_values is a list of 2-tuples @@ -139,7 +158,6 @@ def from_ent_cert_content( repoid_vars = [part[1:] for part in repo_parts if part.startswith("$")] if HAS_YUM and repoid_vars: repo["ui_repoid_vars"] = " ".join(repoid_vars) - # If no GPG key URL is specified, turn gpgcheck off: gpg_url = content.gpg if not gpg_url: @@ -383,6 +401,9 @@ def create(self) -> None: def fix_content(self, content: str) -> str: return content + def enabled_repos(self): + raise NotImplementedError("'enabled_repos' is not implemented for this repo_file.") + @classmethod def installed(cls) -> bool: return os.path.exists(Path.abs(cls.PATH)) @@ -392,7 +413,7 @@ def server_value_repo_file(cls) -> "RepoFileBase": return cls("var/lib/rhsm/repo_server_val/") -if HAS_DEB822: +if apt is not None: class AptRepoFile(RepoFileBase): PATH: str = "etc/apt/sources.list.d" @@ -461,7 +482,8 @@ def sections(self): def fix_content(self, content): # Luckily apt ignores all Fields it does not recognize - baseurl = content["baseurl"] + parsed_url = urlparse(content["baseurl"]) + baseurl = parsed_url._replace(query="").geturl() url_res = re.match(r"^https?://(?P.*)$", baseurl) ent_res = re.match(r"^/etc/pki/entitlement/(?P.*).pem$", content["sslclientcert"]) if url_res and ent_res: @@ -469,11 +491,19 @@ def fix_content(self, content): entitlement = ent_res.group("entitlement") baseurl = "katello://{}@{}".format(entitlement, location) + query = parse_qs(parsed_url.query) + if "rel" in query and "comp" in query: + suites = query["rel"][0].replace(",", " ") + components = query["comp"][0].replace(",", " ") + else: + suites = "default" + components = "all" + apt_cont = content.copy() apt_cont["Types"] = "deb" apt_cont["URIs"] = baseurl - apt_cont["Suites"] = "default" - apt_cont["Components"] = "all" + apt_cont["Suites"] = suites + apt_cont["Components"] = components apt_cont["Trusted"] = "yes" if apt_cont["arches"] is None or apt_cont["arches"] == ["ALL"]: @@ -483,8 +513,57 @@ def fix_content(self, content): apt_cont["arches"] = arches_str apt_cont["Architectures"] = arches_str + # 'Signed-By': look for pulp public-key in '/etc/apt/trusted.gpg.d/' + keypath = "/etc/apt/trusted.gpg.d/" + if os.path.exists(keypath) and os.path.isdir(keypath): + keyfiles = [ + os.path.join(keypath, f) + for f in os.listdir(keypath) + if os.path.isfile(os.path.join(keypath, f)) + and (f.startswith("orcharhino_") or f.startswith("pulp_") or f.startswith("client")) + and (f.endswith(".gpg") or f.endswith(".asc")) + ] + else: + keyfiles = [] + + orcharhino_keyfile = None + if len(keyfiles) > 1: + orcharhino_keyfile = keyfiles[0] + log.info(f"Found more than one pulp signing-key file; choosing '{orcharhino_keyfile}'") + elif len(keyfiles) == 1: + orcharhino_keyfile = keyfiles[0] + else: + log.warning(f"Could not find pulp signing-key in {keypath}") + if orcharhino_keyfile: + apt_cont["Signed-By"] = orcharhino_keyfile + else: + log.warning("No pulp signing-key file found!") + return apt_cont + def enabled_repos(self): + enabled_repos = [repo for repo in self.repos822 if self._getboolean(repo, "enabled")] + return [ + {"repositoryid": repo822["id"], "baseurl": [repo822["baseurl"]]} for repo822 in enabled_repos + ] + + _boolean_states = { + "1": True, + "yes": True, + "true": True, + "on": True, + "0": False, + "no": False, + "false": False, + "off": False, + } + + def _getboolean(self, repo, option): + v = repo.get(option) + if v.lower() not in self._boolean_states: + raise ValueError("Not a boolean: %s" % v) + return self._boolean_states[v.lower()] + class YumRepoFile(RepoFileBase, ConfigParser): PATH = "etc/yum.repos.d/" @@ -560,6 +639,54 @@ def section(self, section: str) -> "Repo": if self.has_section(section): return Repo(section, self.items(section)) + def enabled_repos(self): + result = [] + try: + enabled_sections = [section for section in self.sections() if self.getboolean(section, "enabled")] + for section in enabled_sections: + result.append( + {"repositoryid": section, "baseurl": [self._replace_vars(self.get(section, "baseurl"))]} + ) + except ImportError: + pass + return result + + def _replace_vars(self, repo_url): + """ + returns a string with "$basearch" and "$releasever" replaced. + + :param repo_url: a repo URL that you want to replace $basearch and $releasever in. + :type path: str + """ + mappings = self._obtain_mappings() + for key, value in mappings.items(): + repo_url = repo_url.replace(key, value) + return repo_url + + def _obtain_mappings(self): + """ + returns a hash with "basearch" and "releasever" set. This will try dnf first, and then yum if dnf is + not installed. + """ + if dnf is not None: + return self._obtain_mappings_dnf() + elif yum is not None: + return self._obtain_mappings_yum() + else: + log.error("Unable to load module for any supported package manager (dnf, yum).") + raise ImportError + + def _obtain_mappings_dnf(self): + db = dnf.dnf.Base() + return { + "$releasever": db.conf.substitutions["releasever"], + "$basearch": db.conf.substitutions["basearch"], + } + + def _obtain_mappings_yum(self): + yb = yum.YumBase() + return {"$releasever": yb.conf.yumvar["releasever"], "$basearch": yb.conf.yumvar["basearch"]} + class ZypperRepoFile(YumRepoFile): """ @@ -690,10 +817,14 @@ def fix_content(self, content: "Content") -> str: def server_value_repo_file(cls) -> "ZypperRepoFile": return cls("var/lib/rhsm/repo_server_val/", "zypper_{}".format(cls.NAME)) + def _obtain_mappings(self): + db = zypp.ZConfig.instance() + return {"$basearch": str(db.systemArchitecture())} + def init_repo_file_classes() -> List[Tuple[type(RepoFileBase), str]]: repo_file_classes: List[type(RepoFileBase)] = [YumRepoFile, ZypperRepoFile] - if HAS_DEB822: + if apt is not None: repo_file_classes.append(AptRepoFile) _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/cache.py b/src/subscription_manager/cache.py index 5fb2c4eb47..88b0a68b00 100644 --- a/src/subscription_manager/cache.py +++ b/src/subscription_manager/cache.py @@ -37,7 +37,7 @@ from rhsm.config import get_config_parser import rhsm.connection as connection -from rhsm.profile import get_profile +from rhsm.profile import get_profile, PROFILE_MAP import subscription_manager.injection as inj from subscription_manager.jsonwrapper import PoolWrapper from rhsm import ourjson as json @@ -503,13 +503,9 @@ def _assembly_profile(rpm_profile, enabled_repos_profile, module_profile) -> Dic @property def current_profile(self) -> Dict[str, List[Dict]]: if not self._current_profile: - rpm_profile: List[Dict] = get_profile("rpm").collect() - enabled_repos: List[Dict] = get_profile("enabled_repos").collect() - module_profile: List[Dict] = get_profile("modulemd").collect() - combined_profile: Dict[str, List[Dict]] = self._assembly_profile( - rpm_profile, enabled_repos, module_profile - ) - self._current_profile = combined_profile + self._current_profile: Dict[str, List[Dict]] = { + key: get_profile(key).collect() for key in PROFILE_MAP.keys() + } return self._current_profile @current_profile.setter @@ -562,9 +558,11 @@ def _sync_with_server( combined_profile: Dict = self.current_profile if uep.has_capability("combined_reporting"): _combined_profile: List[Dict] = [ - {"content_type": "rpm", "profile": combined_profile["rpm"]}, - {"content_type": "enabled_repos", "profile": combined_profile["enabled_repos"]}, - {"content_type": "modulemd", "profile": combined_profile["modulemd"]}, + { + "content_type": key, + "profile": value, + } + for key, value in combined_profile.items() ] uep.updateCombinedProfile(consumer_uuid, _combined_profile) else: diff --git a/src/subscription_manager/cli_command/override.py b/src/subscription_manager/cli_command/override.py index 85abb4b0e0..d17c7122ee 100644 --- a/src/subscription_manager/cli_command/override.py +++ b/src/subscription_manager/cli_command/override.py @@ -18,12 +18,12 @@ import rhsm.connection as connection +from rhsm.repofile import manage_repos_enabled from subscription_manager.cli import system_exit from subscription_manager.cli_command.cli import CliCommand from subscription_manager.i18n import ugettext as _ from subscription_manager.overrides import Overrides, Override from subscription_manager.printing_utils import columnize, echo_columnize_callback -from subscription_manager.repofile import manage_repos_enabled from subscription_manager.utils import get_supported_resources diff --git a/src/subscription_manager/cli_command/repos.py b/src/subscription_manager/cli_command/repos.py index fc87e5e0d0..8942540953 100644 --- a/src/subscription_manager/cli_command/repos.py +++ b/src/subscription_manager/cli_command/repos.py @@ -19,13 +19,13 @@ import logging import subscription_manager.injection as inj +from rhsm.repofile import manage_repos_enabled, YumRepoFile from subscription_manager.action_client import ProfileActionClient, ActionClient from subscription_manager.cli_command.cli import CliCommand from subscription_manager.cli_command.list import REPOS_LIST from subscription_manager.i18n import ugettext as _ from subscription_manager.packageprofilelib import PackageProfileActionInvoker from subscription_manager.printing_utils import columnize, echo_columnize_callback -from subscription_manager.repofile import manage_repos_enabled, YumRepoFile from subscription_manager.repolib import RepoActionInvoker from subscription_manager.utils import get_supported_resources diff --git a/src/subscription_manager/repolib.py b/src/subscription_manager/repolib.py index 6fdf375b1d..6ccd99fee1 100644 --- a/src/subscription_manager/repolib.py +++ b/src/subscription_manager/repolib.py @@ -22,10 +22,10 @@ from subscription_manager.cache import OverrideStatusCache, WrittenOverrideCache from subscription_manager import model 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.utils import get_supported_resources +from rhsm.repofile import Repo, manage_repos_enabled, get_repo_file_classes +from rhsm.repofile import YumRepoFile import rhsm.config import configparser from rhsmlib.facts.hwprobe import HardwareCollector diff --git a/src/subscription_manager/syspurposelib.py b/src/subscription_manager/syspurposelib.py index d26482fc05..e7753b7a2c 100644 --- a/src/subscription_manager/syspurposelib.py +++ b/src/subscription_manager/syspurposelib.py @@ -118,7 +118,7 @@ def write_syspurpose(values: dict) -> bool: else: # Simple backup in case the syspurpose tooling is not installed. try: - json.dump(values, open(USER_SYSPURPOSE), ensure_ascii=True, indent=2) + json.dump(values, open(USER_SYSPURPOSE, "w"), ensure_ascii=True, indent=2) except OSError: log.warning("Could not write syspurpose to %s" % USER_SYSPURPOSE) return False diff --git a/test/cli_command/test_repos.py b/test/cli_command/test_repos.py index 7d09dd0949..607952bad2 100644 --- a/test/cli_command/test_repos.py +++ b/test/cli_command/test_repos.py @@ -317,7 +317,7 @@ def test_set_repo_status_enable_all_disable_all(self, mock_repolib): self.cc.cp.setContentOverrides.assert_called_once_with("fake_id", match_dict_list) self.assertTrue(repolib_instance.update.called) - @patch("subscription_manager.repofile.RepoFileBase.path_exists") + @patch("rhsm.repofile.RepoFileBase.path_exists") @patch("subscription_manager.cli_command.repos.YumRepoFile") def test_set_repo_status_when_disconnected(self, mock_repofile, mock_path_exists): mock_path_exists.return_value = True diff --git a/test/test_repolib.py b/test/test_repolib.py index 102cfce0ac..cce8930c45 100644 --- a/test/test_repolib.py +++ b/test/test_repolib.py @@ -25,15 +25,17 @@ from iniparse import ConfigParser import rhsm.connection -from subscription_manager import repofile +from rhsm import repofile # repofile must be patched and reloaded to import AptRepofile, otherwise # the class is not defined in the first place deb_mock = MagicMock() deb_mock.Deb822 = dict -with patch.dict("subscription_manager.repofile.sys.modules", {"debian.deb822": deb_mock}): +apt_mock = MagicMock() +apt_mock.Cache = dict +with patch.dict("rhsm.repofile.sys.modules", {"debian.deb822": deb_mock, "apt": apt_mock}): reload(repofile) - from subscription_manager.repofile import AptRepoFile + from rhsm.repofile import AptRepoFile reload(repofile) from .stubs import ( @@ -52,7 +54,7 @@ YumReleaseverSource, YumPluginManager, ) -from subscription_manager.repofile import Repo, TidyWriter, YumRepoFile +from rhsm.repofile import Repo, TidyWriter, YumRepoFile from subscription_manager import injection as inj from rhsm.config import RhsmConfigParser from rhsmlib.services import config @@ -908,13 +910,13 @@ def test_releasever_the_string_none(self): class AptRepoFileTest(unittest.TestCase): def _helper_stub_repo(self, *args, **kwargs): - with patch("subscription_manager.repofile.HAS_DEB822", True): + with patch("rhsm.repofile.apt", dict): repo = Repo(*args, **kwargs) return repo def _helper_stub_repofile(self, *args, **kwargs): my_mock = MagicMock() - with patch("subscription_manager.repofile.RepoFileBase.create", my_mock): + with patch("rhsm.repofile.RepoFileBase.create", my_mock): repofile = AptRepoFile(*args, **kwargs) return repofile @@ -1092,8 +1094,8 @@ def test_fix_content_arches_multi(self, mock_file): class YumRepoFileTest(unittest.TestCase): - @patch("subscription_manager.repofile.YumRepoFile.create") - @patch("subscription_manager.repofile.TidyWriter") + @patch("rhsm.repofile.YumRepoFile.create") + @patch("rhsm.repofile.TidyWriter") def test_configparsers_equal(self, tidy_writer, stub_create): rf = YumRepoFile() other = RawConfigParser() @@ -1102,8 +1104,8 @@ def test_configparsers_equal(self, tidy_writer, stub_create): parser.set("test", "key", "val") self.assertTrue(rf._configparsers_equal(other)) - @patch("subscription_manager.repofile.YumRepoFile.create") - @patch("subscription_manager.repofile.TidyWriter") + @patch("rhsm.repofile.YumRepoFile.create") + @patch("rhsm.repofile.TidyWriter") def test_configparsers_diff_sections(self, tidy_writer, stub_create): rf = YumRepoFile() rf.add_section("new_section") @@ -1113,8 +1115,8 @@ def test_configparsers_diff_sections(self, tidy_writer, stub_create): parser.set("test", "key", "val") self.assertFalse(rf._configparsers_equal(other)) - @patch("subscription_manager.repofile.YumRepoFile.create") - @patch("subscription_manager.repofile.TidyWriter") + @patch("rhsm.repofile.YumRepoFile.create") + @patch("rhsm.repofile.TidyWriter") def test_configparsers_diff_item_val(self, tidy_writer, stub_create): rf = YumRepoFile() other = RawConfigParser() @@ -1124,8 +1126,8 @@ def test_configparsers_diff_item_val(self, tidy_writer, stub_create): rf.set("test", "key", "val2") self.assertFalse(rf._configparsers_equal(other)) - @patch("subscription_manager.repofile.YumRepoFile.create") - @patch("subscription_manager.repofile.TidyWriter") + @patch("rhsm.repofile.YumRepoFile.create") + @patch("rhsm.repofile.TidyWriter") def test_configparsers_diff_items(self, tidy_writer, stub_create): rf = YumRepoFile() other = RawConfigParser() @@ -1135,8 +1137,8 @@ def test_configparsers_diff_items(self, tidy_writer, stub_create): rf.set("test", "somekey", "val") self.assertFalse(rf._configparsers_equal(other)) - @patch("subscription_manager.repofile.YumRepoFile.create") - @patch("subscription_manager.repofile.TidyWriter") + @patch("rhsm.repofile.YumRepoFile.create") + @patch("rhsm.repofile.TidyWriter") def test_configparsers_equal_int(self, tidy_writer, stub_create): rf = YumRepoFile() other = RawConfigParser()