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

Add os product tag based on /etc/os-release #3188

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 22 additions & 2 deletions src/subscription_manager/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import logging

from rhsm.certificate2 import CONTENT_ACCESS_CERT_TYPE
from rhsmlib.facts.hwprobe import HardwareCollector

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -89,22 +90,28 @@ def __getitem__(self, key):
return self._entitlements[key]


def find_content(ent_source, content_type=None):
def find_content(ent_source, content_type=None, use_os_release_product=False):
"""
Scan all entitlements looking for content of the given type. (string)
Type will be compared case insensitive.
If use_os_release_product is enabled, generate a os-product-version tag and
add it ot the list of product_tags
Returns a list of model.Content.
"""
entitled_content = []
content_access_entitlement_content = {}
content_labels = set()
if use_os_release_product:
all_product_tags = add_os_product_tags(ent_source.product_tags)
else:
all_product_tags = ent_source.product_tags
log.debug("Searching for content of type: %s" % content_type)
for entitlement in ent_source:
for content in entitlement.contents:
# this is basically matching_content from repolib
if content.content_type.lower() == content_type.lower() and content_tag_match(
content.tags, ent_source.product_tags
content.tags, all_product_tags
):
if entitlement.entitlement_type == CONTENT_ACCESS_CERT_TYPE:
content_access_entitlement_content[content.label] = content
Expand All @@ -119,6 +126,19 @@ def find_content(ent_source, content_type=None):
return entitled_content


def add_os_product_tags(product_tags):
"""Add [os-id]-[os-version] tag to product tag list based on /etc/os-release
Returns the product_tags including the os-product tag
"""
all_tags = product_tags

dist_info = HardwareCollector().get_distribution()
os_product = "{name}-{version}".format(name=dist_info[4], version=dist_info[1])
all_tags.add(os_product)
return all_tags


def content_tag_match(content_tags, product_tags):
"""See if content required tags are provided by installed products.
Expand Down
20 changes: 19 additions & 1 deletion src/subscription_manager/repolib.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,13 +493,31 @@ def get_unique_content(self):
# assumes items in content_list are hashable
return set(content_list)

def use_os_release_product_enabled(self):
try:
use_os_release_product = conf["rhsm"].get_int("use_os_release_product")
except ValueError as e:
log.exception(e)
return False
except configparser.Error as e:
log.exception(e)
return False
else:
if use_os_release_product is None:
return False
return bool(use_os_release_product)

# Expose as public API for RepoActionInvoker.is_managed, since that
# is used by Openshift tooling.
# See https://bugzilla.redhat.com/show_bug.cgi?id=1223038
def matching_content(self):
content = []
for content_type in ALLOWED_CONTENT_TYPES:
content += model.find_content(self.ent_source, content_type=content_type)
content += model.find_content(
self.ent_source,
content_type=content_type,
use_os_release_product=self.use_os_release_product_enabled(),
)
return content

def get_all_content(self, baseurl, ca_cert):
Expand Down