From: John Mulligan Date: Sat, 21 Oct 2023 16:05:43 +0000 (-0400) Subject: cephadm: move logic to build pull command to container engines X-Git-Tag: v19.0.0~145^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=1dc1a0d1481e7e5d1ca5a9830e809b4bfd2bfd73;p=ceph-ci.git cephadm: move logic to build pull command to container engines Move the logic needed to build a pull command to a function in the container_engines.py file. This continues the effort to improve the locality of items with regards to specific options for container engines. I had thought to move the whole pull function but the logging and retry code made me change my mind. We can always move it later if it makes sense. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 650e080843e..478de27f0b5 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -103,6 +103,7 @@ from cephadmlib.container_engines import ( Podman, check_container_engine, find_container_engine, + pull_command, registry_login, ) from cephadmlib.data_utils import ( @@ -3926,14 +3927,7 @@ def _pull_image(ctx, image, insecure=False): 'Digest did not match, expected', ] - cmd = [ctx.container_engine.path, 'pull', image] - if isinstance(ctx.container_engine, Podman): - if insecure: - cmd.append('--tls-verify=false') - - if os.path.exists('/etc/ceph/podman-auth.json'): - cmd.append('--authfile=/etc/ceph/podman-auth.json') - cmd_str = ' '.join(cmd) + cmd = pull_command(ctx, image, insecure=insecure) for sleep_secs in [1, 4, 25]: out, err, ret = call(ctx, cmd, verbosity=CallVerbosity.QUIET_UNLESS_ERROR) @@ -3943,6 +3937,7 @@ def _pull_image(ctx, image, insecure=False): if 'unauthorized' in err: raise UnauthorizedRegistryError() + cmd_str = ' '.join(cmd) if not any(pattern in err for pattern in ignorelist): raise Error('Failed command: %s' % cmd_str) diff --git a/src/cephadm/cephadmlib/container_engines.py b/src/cephadm/cephadmlib/container_engines.py index 98019fa820b..64ce7ae821a 100644 --- a/src/cephadm/cephadmlib/container_engines.py +++ b/src/cephadm/cephadmlib/container_engines.py @@ -175,3 +175,17 @@ def registry_login( 'Failed to login to custom registry @ %s as %s with given password' % (ctx.registry_url, ctx.registry_username) ) + + +def pull_command( + ctx: CephadmContext, image: str, insecure: bool = False +) -> List[str]: + """Return a command that can be run to pull an image.""" + cmd = [ctx.container_engine.path, 'pull', image] + if isinstance(ctx.container_engine, Podman): + if insecure: + cmd.append('--tls-verify=false') + + if os.path.exists('/etc/ceph/podman-auth.json'): + cmd.append('--authfile=/etc/ceph/podman-auth.json') + return cmd