Skip to content

Commit

Permalink
feat: DNF plugin: Read release only from cache file
Browse files Browse the repository at this point in the history
* 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 be uneccessary slow
  down of DNF.
  • Loading branch information
jirihnidek committed Mar 13, 2024
1 parent cca00d3 commit 36f2e97
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/plugins/dnf/subscription_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from subscription_manager.utils import chroot, is_simple_content_access
from subscription_manager.injectioninit import init_dep_injection
from subscription_manager.i18n import ungettext, ugettext as _
from subscription_manager.release import get_consumer_release
from rhsm import logutil
from rhsm import config

Expand All @@ -33,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 @@ -214,9 +215,22 @@ def _warn_or_give_usage_message():
elif len(ent_dir.list_valid()) == 0 and not is_simple_content_access(identity=identity):
msg = no_subs_warning
else:
release_version = get_consumer_release(identity=identity)
if release_version is not None:
msg = release_lock_waring.format(release_version=release_version)
# 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)
if release_cache.exists():
release_version: Optional[str] = None
cp_provider: CPProvider = inj.require(inj.CP_PROVIDER)
cp = cp_provider.get_consumer_auth_cp()
release_version_dict: Optional[dict] = release_cache.read_status(cp, identity.uuid)
if release_version_dict is not None:
try:
release_version = release_version_dict["releaseVer"]
except KeyError:
log.warning("The 'releaseVer' not included in the release version document")
if release_version is not None:
msg = release_lock_waring.format(release_version=release_version)
finally:
if msg:
logger.info(msg)
Expand Down

0 comments on commit 36f2e97

Please sign in to comment.