From 2b255edf33145a1ce2b2e2021aa1d2112e7a7688 Mon Sep 17 00:00:00 2001 From: Renan Rodrigo Date: Fri, 22 Sep 2023 19:46:13 -0300 Subject: [PATCH] test: capture errors when updating the esm cache It is more resilient now, but we can log success and failure using the AcquireProgress object Signed-off-by: Renan Rodrigo --- features/unattached_commands.feature | 2 +- uaclient/apt.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/features/unattached_commands.feature b/features/unattached_commands.feature index 618326382e..b09706963b 100644 --- a/features/unattached_commands.feature +++ b/features/unattached_commands.feature @@ -415,7 +415,7 @@ Feature: Command behaviour when unattached When I run `cat /var/log/ubuntu-advantage.log` with sudo Then stdout matches regexp: """ - Failed to fetch the ESM Apt Cache + Failed to fetch ESM Apt Cache item: """ Examples: ubuntu release diff --git a/uaclient/apt.py b/uaclient/apt.py index 3126ab7b99..8d8e37d538 100644 --- a/uaclient/apt.py +++ b/uaclient/apt.py @@ -805,7 +805,17 @@ def update_esm_caches(cfg) -> None: with PreserveAptCfg(get_esm_apt_pkg_cache) as cache: sources_list = apt_pkg.SourceList() sources_list.read_main_list() - fetch_progress = AcquireProgress() + + class EsmAcquireProgress(AcquireProgress): + def done(self, item: apt_pkg.AcquireItemDesc): + LOG.debug("Fetched ESM Apt Cache item: {}".format(item.uri)) + + def fail(self, item: apt_pkg.AcquireItemDesc): + LOG.warning( + "Failed to fetch ESM Apt Cache item: {}".format(item.uri) + ) + + fetch_progress = EsmAcquireProgress() try: cache.update(fetch_progress, sources_list, 0) except (apt_pkg.Error, SystemError) as e: