From a7af500a0f0b80509dd9107a234cc1393298daf9 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Wed, 27 Mar 2024 13:53:27 +0100 Subject: [PATCH] feat: Add warning message about release version to dnf plugin * Card ID: CCT-171 * New feature: when a release is set by subscription-manager, then dnf plugin "subscription-manager" prints warning about this release * Information about release is read only from cache file. When there is cache file containing information about current release, then only this information is used for printing warning about release lock. Gathering such information from candlepin would unnecessarily slow down DNF. --- src/plugins/dnf/subscription_manager.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/plugins/dnf/subscription_manager.py b/src/plugins/dnf/subscription_manager.py index 199bb1db05..0086c191b3 100644 --- a/src/plugins/dnf/subscription_manager.py +++ b/src/plugins/dnf/subscription_manager.py @@ -32,11 +32,13 @@ from configparser import ConfigParser -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Optional if TYPE_CHECKING: from subscription_manager.certdirectory import EntitlementDirectory from subscription_manager.identity import Identity + from subscription_manager.cache import ReleaseStatusCache + from subscription_manager.cp_provider import CPProvider expired_warning = _( @@ -70,6 +72,12 @@ """ ) +release_lock_warning = _( + """ +This system has release set to {release_version} and it receives updates only for this release. +""" +) + log = logging.getLogger("rhsm-app." + __name__) @@ -206,6 +214,21 @@ def _warn_or_give_usage_message(): msg = not_registered_warning elif len(ent_dir.list_valid()) == 0 and not is_simple_content_access(identity=identity): msg = no_subs_warning + else: + # Try to read release version ONLY from cache document. + # When cache document does not exist, then do not try to get this information + # from candlepin server and slow down DNF plugin! + release_cache: ReleaseStatusCache = inj.require(inj.RELEASE_STATUS_CACHE) + release_version_dict: Optional[dict] = release_cache.read_cache_only() + # Skip the case, when release does not exist at all, or it was unset + # and it is empty string + if release_version_dict: + try: + release_version: str = release_version_dict["releaseVer"] + except KeyError: + log.warning("The 'releaseVer' not included in the release version document") + else: + msg = release_lock_warning.format(release_version=release_version) finally: if msg: logger.info(msg)