Skip to content
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

Establish atix main #1

Open
wants to merge 24 commits into
base: atix-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
221d1f2
[ATIX] Add DebProfile to Profilemanager
Aug 1, 2019
5432dc2
[ATIX] Move repofile to rhsm subpackage
Aug 8, 2019
5abc786
[ATIX] Generate enabled_repos from repofile
Aug 8, 2019
90a4243
[ATIX] Fix report enabled deb-repositories only
m-bucher Oct 20, 2020
db6bcdc
[ATIX] Allow syspurpose file to be written
sbernhard Dec 7, 2021
4f6026d
[ATIX] Add handling of params in repository urls
hstct Jan 17, 2023
e86d256
[ATIX] Use repofile from rhsm subpackage
goarsna Jun 28, 2023
3f9ba06
[ATIX] Remove failing method annotations
goarsna Jun 28, 2023
2aed02b
[ATIX] Adjust katello script for Python3
goarsna Jun 28, 2023
850ccc8
[ATIX] Fix APT component selection
quba42 Jul 3, 2023
f408516
[ATIX] Fix failing profile upload with SCA enabled
m-bucher Feb 2, 2024
f79cf5f
[ATIX] Add deb repo-setting Signed-By
m-bucher May 24, 2024
8c8167a
WIP Fix setup.py style
sbernhard Jul 29, 2024
c871278
WIP Fix baseurl style in profile
sbernhard Jul 29, 2024
09c01db
WIP Fix debprofile style in profile
sbernhard Jul 29, 2024
1c6f311
WIP Fix repofile style
sbernhard Jul 29, 2024
ba92938
WIP Fix cache style
sbernhard Jul 29, 2024
7ca91fb
WIP Fix syspurpose style
sbernhard Jul 29, 2024
0f6741a
WIP - fix tests. repofile moved from sub-man to rhsm
sbernhard Aug 1, 2024
085b20e
WIP: fix repolib tests for apt. mock apt
sbernhard Aug 1, 2024
a15dad4
WIP: fix repofile.py - the /etc/apt/trusted.gpg.d dir may not exist
sbernhard Aug 2, 2024
752175a
WIP: setup.py package profile update packaged twice
sbernhard Aug 2, 2024
9273491
fix test
sbernhard Aug 8, 2024
214d088
WIP: fix repofile mappings.items() issue
sbernhard Aug 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion debian-stuff/80package-profile-upload
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DPkg::Post-Invoke { /usr/lib/katello-client/bin/deb_package_profile_upload }
DPkg::Post-Invoke { /usr/bin/package-profile-upload }
35 changes: 0 additions & 35 deletions debian-stuff/deb_package_profile_upload

This file was deleted.

6 changes: 3 additions & 3 deletions debian-stuff/katello
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/python -u
#! /usr/bin/python3 -u
#
# The katello Acquire Method
#
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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')]
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/zypper/services/rhsm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
165 changes: 63 additions & 102 deletions src/rhsm/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Loading
Loading