diff --git a/src/subscription_manager/model/__init__.py b/src/subscription_manager/model/__init__.py index b0ca06ed1d..e5f9dae4c9 100644 --- a/src/subscription_manager/model/__init__.py +++ b/src/subscription_manager/model/__init__.py @@ -15,6 +15,7 @@ import logging from rhsm.certificate2 import CONTENT_ACCESS_CERT_TYPE +from rhsmlib.facts.hwprobe import HardwareCollector log = logging.getLogger(__name__) @@ -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 @@ -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. diff --git a/src/subscription_manager/repolib.py b/src/subscription_manager/repolib.py index dc649ea65d..6bf4f04650 100644 --- a/src/subscription_manager/repolib.py +++ b/src/subscription_manager/repolib.py @@ -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):