[Bug 2007311] Re: apt-check python script doesn't catch issues before outputting bad data

Kodiak Firesmith 2007311 at bugs.launchpad.net
Mon Mar 6 20:59:27 UTC 2023


One thing to note is that while this problem is present in jammy-updates
and focal-updates version of apt_check.py in /src, the version already
in the devel branch seems to fix the issue.

( This works:  https://git.launchpad.net/ubuntu/+source/update-notifier/tree/data/apt_check.py,
these don't:
 - https://git.launchpad.net/ubuntu/+source/update-notifier/tree/data/apt_check.py?h=ubuntu%2Ffocal-updates
 - https://git.launchpad.net/ubuntu/+source/update-notifier/tree/data/apt_check.py?h=ubuntu%2Fjammy-updates
)

Due to what was added in this commit:
update-notifier (3.192.63) lunar; urgency=medium

  * Isolate creation of the esm apt cache in apt-check (LP: #2008212)

 -- Renan Rodrigo Barbosa <renanrodrigo at canonical.com>  Mon, 27 Feb 2023
23:15:02 -0300

+def get_apt_pkg_esm_cache():
+    """Get an apt_pkg cache with the ubuntu-advantage-tools esm data.
+
+    Set the configuration to get the u-a-t cache, then set it back to an
+    empty configuration state and init again so other calls to Cache work as
+    expected.
+    """
+    for key in apt_pkg.config.keys():
+        if re.match(r"^Acquire", key) is None:
+            apt_pkg.config.clear(key)
+    apt_pkg.config.set("Dir", PRO_ESM_CACHE_DIR)
+    apt_pkg.init()
+    try:
+        esm_cache = apt_pkg.Cache(progress=None)
+    except apt_pkg.Error:
+        esm_cache = None
+
+    for key in apt_pkg.config.keys():
+        apt_pkg.config.clear(key)
+    apt_pkg.init()
+
+    return esm_cache
+
+
 def init():
     " init the system, be nice "
     # FIXME: do a ionice here too?
@@ -365,12 +390,7 @@ def run(options=None):
         sys.stderr.write("E: " + _("Error: Marking the upgrade (%s)") % e)
         sys.exit(-1)
 
-    try:
-        apt_pkg.config.set("Dir", "/var/lib/ubuntu-advantage/apt-esm/")
-        apt_pkg.init_system()
-        esm_cache = apt_pkg.Cache(progress=None)
-    except apt_pkg.Error:
-        esm_cache = None
+    esm_cache = get_apt_pkg_esm_cache()

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to update-notifier in Ubuntu.
https://bugs.launchpad.net/bugs/2007311

Title:
  apt-check python script doesn't catch issues before outputting bad
  data

Status in update-notifier package in Ubuntu:
  Confirmed

Bug description:
  This type of error should be caught.

   /usr/lib/update-notifier/apt-check
  E: Unknown Error: '<class 'KeyError'>' ("The cache has no package named 'libxmlb2:amd64'")

  /usr/lib/update-notifier/apt-check --human-readable
  E: Unknown Error: '<class 'KeyError'>' ("The cache has no package named 'libxmlb2:amd64'")

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/update-notifier/+bug/2007311/+subscriptions




More information about the foundations-bugs mailing list