Skip to content

Commit

Permalink
test: capture errors when updating the esm cache
Browse files Browse the repository at this point in the history
It is more resilient now, but we can log success and failure using
the AcquireProgress object

Signed-off-by: Renan Rodrigo <[email protected]>
  • Loading branch information
renanrodrigo committed Sep 28, 2023
1 parent ca8fd40 commit 2b255ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion features/unattached_commands.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion uaclient/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2b255ed

Please sign in to comment.