Skip to content

Commit

Permalink
feat: Add warning message about release version to dnf plugin
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
jirihnidek committed Mar 27, 2024
1 parent 4ad1403 commit a7af500
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/plugins/dnf/subscription_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = _(
Expand Down Expand Up @@ -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__)


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a7af500

Please sign in to comment.