Skip to content

Commit 757b8ad

Browse files
committed
podman: retry pulling the image Move podman_check_native_image_architecture() to the later stage, so we don't retry upon architecture mismatch. Relates: containers/podman#19770
1 parent ffa148a commit 757b8ad

File tree

6 files changed

+26
-6
lines changed

6 files changed

+26
-6
lines changed

mock/docs/site-defaults.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@
165165
# package manager (e.g. using dnf --installroot).
166166
#config_opts['bootstrap_image_fallback'] = True
167167

168+
# When 'use_bootstrap_image' is True, bootstrap image must be downloaded and it
169+
# may fail. Mock's logic is to retry downloads, using this option you can
170+
# configure how long should Mock keep trying (using exponential algorithm with
171+
# full jitter, see python-backoff docs for more info).
172+
#config_opts['bootstrap_image_keep_getting'] = 120 # seconds
173+
168174
# anything you specify with 'bootstrap_*' will be copied to bootstrap config
169175
# e.g. config_opts['bootstrap_system_yum_command'] = '/usr/bin/yum-deprecated' will become
170176
# config_opts['system_yum_command'] = '/usr/bin/yum-deprecated' for bootstrap config

mock/mock.spec

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Requires: python%{python3_pkgversion}-rpm
6060
Requires: python%{python3_pkgversion}-pyroute2
6161
Requires: python%{python3_pkgversion}-templated-dictionary
6262
Requires: python%{python3_pkgversion}-backoff
63+
BuildRequires: python%{python3_pkgversion}-backoff
6364
BuildRequires: python%{python3_pkgversion}-devel
6465
%if %{with lint}
6566
BuildRequires: python%{python3_pkgversion}-pylint

mock/py/mockbuild/buildroot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def _fallback(message):
234234
return
235235

236236
with _fallback("Can't initialize from bootstrap image"):
237-
podman.pull_image()
237+
podman.retry_image_pull(self.config["image_keep_getting"])
238238
podman.cp(self.make_chroot_path(), self.config["tar_binary"])
239239
file_util.unlink_if_exists(os.path.join(self.make_chroot_path(),
240240
"etc/rpm/macros.image-language-conf"))

mock/py/mockbuild/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def setup_default_config_opts():
8686
config_opts['bootstrap_image'] = 'fedora:latest'
8787
config_opts['bootstrap_image_ready'] = False
8888
config_opts['bootstrap_image_fallback'] = True
89+
config_opts['bootstrap_image_keep_getting'] = 120
8990

9091
config_opts['internal_dev_setup'] = True
9192

mock/py/mockbuild/podman.py

+16-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import subprocess
77
from contextlib import contextmanager
88

9+
import backoff
910
from mockbuild.trace_decorator import getLog, traceLog
1011
from mockbuild import util
1112
from mockbuild.exception import BootstrapError
@@ -59,18 +60,23 @@ def __init__(self, buildroot, image):
5960

6061
@traceLog()
6162
def pull_image(self):
62-
""" pull the latest image """
63+
""" pull the latest image, return True if successful """
6364
logger = getLog()
6465
logger.info("Pulling image: %s", self.image)
6566
cmd = [self.podman_binary, "pull", self.image]
6667
out, exit_status = util.do_with_status(cmd, env=self.buildroot.env,
6768
raiseExc=False, returnOutput=1)
6869
if exit_status:
6970
logger.error(out)
71+
return not exit_status
7072

71-
if not podman_check_native_image_architecture(self.image, logger):
72-
raise BootstrapError("Pulled image has invalid architecture")
73-
73+
def retry_image_pull(self, max_time):
74+
""" Try pulling the image multiple times """
75+
@backoff.on_predicate(backoff.expo, lambda x: not x,
76+
max_time=max_time, jitter=backoff.full_jitter)
77+
def _keep_trying():
78+
return self.pull_image()
79+
_keep_trying()
7480

7581
@contextmanager
7682
def mounted_image(self):
@@ -100,7 +106,12 @@ def mounted_image(self):
100106
@traceLog()
101107
def cp(self, destination, tar_cmd):
102108
""" copy content of container to destination directory """
103-
getLog().info("Copy content of container %s to %s", self.image, destination)
109+
logger = getLog()
110+
logger.info("Copy content of container %s to %s", self.image, destination)
111+
112+
if not podman_check_native_image_architecture(self.image, logger):
113+
raise BootstrapError("Pulled image has invalid architecture")
114+
104115
with self.mounted_image() as mount_path:
105116
# pipe-out the temporary mountpoint with the help of tar utility
106117
cmd_podman = [tar_cmd, "-C", mount_path, "-c", "."]

tox.ini

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ deps =
77
-rmock/requirements.txt
88
pytest
99
pytest-cov
10+
backoff
1011
setenv =
1112
PYTHONPATH = ./mock/py
1213
commands = python -m pytest -v {posargs} --cov-report term-missing --cov mock/py mock/tests

0 commit comments

Comments
 (0)