qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v2 1/5] docker.py: add podman support


From: Alex Bennée
Subject: Re: [Qemu-devel] [PATCH v2 1/5] docker.py: add podman support
Date: Thu, 11 Jul 2019 16:52:56 +0100
User-agent: mu4e 1.3.2; emacs 26.1

Marc-André Lureau <address@hidden> writes:

> Add a --engine option to select either docker, podman or auto.
>
> Among other advantages, podman allows to run rootless & daemonless
> containers, fortunately sharing compatible CLI with docker.
>
> Signed-off-by: Marc-André Lureau <address@hidden>

Acked-by: Alex Bennée <address@hidden>

podman doesn't seem to be widely packaged as of yet so I can't test it
on any of my systems.

> ---
>  tests/docker/docker.py | 43 +++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 38 insertions(+), 5 deletions(-)
>
> diff --git a/tests/docker/docker.py b/tests/docker/docker.py
> index 53a8c9c801..1f59a78b10 100755
> --- a/tests/docker/docker.py
> +++ b/tests/docker/docker.py
> @@ -20,6 +20,7 @@ import hashlib
>  import atexit
>  import uuid
>  import argparse
> +import enum
>  import tempfile
>  import re
>  import signal
> @@ -38,6 +39,26 @@ FILTERED_ENV_NAMES = ['ftp_proxy', 'http_proxy', 
> 'https_proxy']
>
>  DEVNULL = open(os.devnull, 'wb')
>
> +class EngineEnum(enum.IntEnum):
> +    AUTO = 1
> +    DOCKER = 2
> +    PODMAN = 3
> +
> +    def __str__(self):
> +        return self.name.lower()
> +
> +    def __repr__(self):
> +        return str(self)
> +
> +    @staticmethod
> +    def argparse(s):
> +        try:
> +            return EngineEnum[s.upper()]
> +        except KeyError:
> +            return s
> +
> +
> +USE_ENGINE = EngineEnum.AUTO
>
>  def _text_checksum(text):
>      """Calculate a digest string unique to the text content"""
> @@ -48,9 +69,14 @@ def _file_checksum(filename):
>      return _text_checksum(open(filename, 'rb').read())
>
>
> -def _guess_docker_command():
> -    """ Guess a working docker command or raise exception if not found"""
> -    commands = [["docker"], ["sudo", "-n", "docker"]]
> +def _guess_engine_command():
> +    """ Guess a working engine command or raise exception if not found"""
> +    commands = []
> +
> +    if USE_ENGINE in [EngineEnum.AUTO, EngineEnum.PODMAN]:
> +        commands += [["podman"]]
> +    if USE_ENGINE in [EngineEnum.AUTO, EngineEnum.DOCKER]:
> +        commands += [["docker"], ["sudo", "-n", "docker"]]
>      for cmd in commands:
>          try:
>              # docker version will return the client details in stdout
> @@ -61,7 +87,7 @@ def _guess_docker_command():
>          except OSError:
>              pass
>      commands_txt = "\n".join(["  " + " ".join(x) for x in commands])
> -    raise Exception("Cannot find working docker command. Tried:\n%s" %
> +    raise Exception("Cannot find working engine command. Tried:\n%s" %
>                      commands_txt)
>
>
> @@ -190,7 +216,7 @@ def _dockerfile_preprocess(df):
>  class Docker(object):
>      """ Running Docker commands """
>      def __init__(self):
> -        self._command = _guess_docker_command()
> +        self._command = _guess_engine_command()
>          self._instances = []
>          atexit.register(self._kill_instances)
>          signal.signal(signal.SIGTERM, self._kill_instances)
> @@ -502,6 +528,8 @@ class ProbeCommand(SubCommand):
>                  print("yes")
>              elif docker._command[0] == "sudo":
>                  print("sudo")
> +            elif docker._command[0] == "podman":
> +                print("podman")
>          except Exception:
>              print("no")
>
> @@ -597,9 +625,13 @@ class CheckCommand(SubCommand):
>
>
>  def main():
> +    global USE_ENGINE
> +
>      parser = argparse.ArgumentParser(description="A Docker helper",
>                                       usage="%s <subcommand> ..." %
>                                       os.path.basename(sys.argv[0]))
> +    parser.add_argument("--engine", type=EngineEnum.argparse, 
> choices=list(EngineEnum),
> +                        help="specify which container engine to use")
>      subparsers = parser.add_subparsers(title="subcommands", help=None)
>      for cls in SubCommand.__subclasses__():
>          cmd = cls()
> @@ -608,6 +640,7 @@ def main():
>          cmd.args(subp)
>          subp.set_defaults(cmdobj=cmd)
>      args, argv = parser.parse_known_args()
> +    USE_ENGINE = args.engine
>      return args.cmdobj.run(args, argv)


--
Alex Bennée



reply via email to

[Prev in Thread] Current Thread [Next in Thread]