[elbe-devel] [PATCH 1/1] elbepack: commands: fetch_initvm_pkgs.py: retries for package-fetching added

Eduard Krein eduard.krein at linutronix.de
Wed Sep 6 10:13:56 CEST 2023


From: Eduard Krein <eduard at linutronix.de>

Unstable internet connections may disrupt fetching debian packages.
A broken package download invalidates the whole ELBE build. Mitigate these
failures by adding download retries.

Signed-off-by: Eduard Krein <eduard at linutronix.de>
Reviewed-by: Benedikt Spranger <b.spranger at linutronix.de>
---
 elbepack/commands/fetch_initvm_pkgs.py | 70 +++++++++++++++++---------
 1 file changed, 47 insertions(+), 23 deletions(-)

diff --git a/elbepack/commands/fetch_initvm_pkgs.py b/elbepack/commands/fetch_initvm_pkgs.py
index a45bdb55..2dcef049 100644
--- a/elbepack/commands/fetch_initvm_pkgs.py
+++ b/elbepack/commands/fetch_initvm_pkgs.py
@@ -17,7 +17,7 @@ from elbepack.dump import get_initvm_pkglist
 from elbepack.aptprogress import ElbeAcquireProgress
 from elbepack.filesystem import hostfs
 from elbepack.log import elbe_logging
-from elbepack.shellhelper import do
+from elbepack.shellhelper import do, CommandError
 from elbepack.aptpkgutils import fetch_binary
 
 
@@ -110,20 +110,32 @@ def run_command(argv):
             cache.open()
             for pkg in pkglist:
                 pkg_id = f"{pkg.name}-{pkg.installed_version}"
-                try:
-                    p = cache[pkg.name]
-                    pkgver = p.installed
-                    deb = fetch_binary(pkgver,
+                retry = 1
+                while retry < 3:
+                      try:
+                          p = cache[pkg.name]
+                          pkgver = p.installed
+                          deb = fetch_binary(pkgver,
                                        opt.archive,
                                        ElbeAcquireProgress(cb=None))
-                    repo.includedeb(deb, 'main', prio=pkgver.priority)
-                except ValueError:
-                    logging.exception('No package "%s"', pkg_id)
-                except FetchError:
-                    logging.exception('Package "%s-%s" could not be downloaded',
+                          repo.includedeb(deb, 'main', prio=pkgver.priority)
+                          break
+                      except ValueError:
+                          logging.exception('No package "%s"', pkg_id)
+                          retry = 3
+                      except FetchError:
+                          logging.exception('Package "%s-%s" could not be downloaded',
                                       pkg.name, pkgver.version)
-                except TypeError:
-                    logging.exception('Package "%s" missing name or version', pkg_id)
+                          retry += 1
+                      except TypeError:
+                          logging.exception('Package "%s" missing name or version', pkg_id)
+                          retry = 3
+                      except CommandError:
+                          logging.exception('Package "%s-%s" could not be added to repo.',
+                                          pkg.name, pkgver.version)
+                          retry += 1
+                if retry >= 3:
+                    logging.error('Failed to get binary Package "%s"', pkg_id)
 
         repo.finalize()
 
@@ -142,19 +154,31 @@ def run_command(argv):
         if opt.build_sources:
             for pkg in pkglist:
                 pkg_id = f"{pkg.name}-{pkg.installed_version}"
-                try:
-                    p = cache[pkg.name]
-                    pkgver = p.installed
-                    dsc = pkgver.fetch_source(opt.srcarchive,
+                retry = 1
+                while retry < 3:
+                      try:
+                          p = cache[pkg.name]
+                          pkgver = p.installed
+                          dsc = pkgver.fetch_source(opt.srcarchive,
                                               ElbeAcquireProgress(cb=None),
                                               unpack=False)
-                    repo.include_init_dsc(dsc, 'initvm')
-                except ValueError:
-                    logging.exception('No package "%s"', pkg_id)
-                except FetchError:
-                    logging.exception('Package "%s-%s" could not be downloaded', pkg.name, pkgver.version)
-                except TypeError:
-                    logging.exception('Package "%s" missing name or version', pkg_id)
+                          repo.include_init_dsc(dsc, 'initvm')
+                          break
+                      except ValueError:
+                          logging.exception('No package "%s"', pkg_id)
+                          retry = 3
+                      except FetchError:
+                          logging.exception('Package "%s-%s" could not be downloaded', pkg.name, pkgver.version)
+                          retry += 1
+                      except TypeError:
+                          logging.exception('Package "%s" missing name or version', pkg_id)
+                          retry = 3
+                      except CommandError:
+                          logging.exception('Package "%s-%s" could not be added to repo.',
+                                          pkg.name, pkgver.version)
+                    retry += 1
+                if retry >= 3:
+                    logging.error('Failed to get source Package "%s"', pkg_id)
 
         repo.finalize()
 
-- 
2.30.2



More information about the elbe-devel mailing list