Comment 8 for bug 2007311

Revision history for this message
Kodiak Firesmith (kfiresmith-whoi) wrote :

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 <email address hidden> 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()