From 3163f3aa371c7ff5ac4fac4514c4b7623ae088dc Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Wed, 27 Mar 2024 13:53:27 +0100 Subject: [PATCH 1/2] 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..2e9a7200c8 100644 --- a/src/plugins/dnf/subscription_manager.py +++ b/src/plugins/dnf/subscription_manager.py @@ -32,11 +32,12 @@ 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 expired_warning = _( @@ -70,6 +71,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 +213,22 @@ 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() + 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: + # Skip the case, when release does not exist at all, or it was unset + # and it is empty string + if release_version: + msg = release_lock_warning.format(release_version=release_version) finally: if msg: logger.info(msg) From 9979053158e225c242d3b109122ad98ed6f6efd1 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Wed, 13 Mar 2024 15:24:34 +0100 Subject: [PATCH 2/2] fix: Change type hint according returned value. --- src/subscription_manager/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/subscription_manager/cache.py b/src/subscription_manager/cache.py index 6e24486eb2..64e3bd9c03 100644 --- a/src/subscription_manager/cache.py +++ b/src/subscription_manager/cache.py @@ -316,7 +316,7 @@ def _cache_exists(self) -> bool: def read_status( self, uep: connection.UEPConnection, uuid: str, on_date: Optional[datetime.datetime] = None - ) -> Optional[str]: + ) -> Optional[dict]: """ Return status, from cache if it exists, otherwise load_status and write cache and return it.