Browse Source

tests/docker: improve handling of docker probes

The docker.py script has logic to guess the container command and
detects one of

  * docker
  * sudo -n docker
  * podman

but the "docker.py probe" command then throws away the detected argv
and prints a slightly different argv based solely on the detected
argv[0]. The result is that 'probe' will print

  * docker
  * sudo docker
  * podman

which means that if sudo was detected & the result of 'probe' were
used directly, it would end up prompting for password interaction
every time.

The 'configure' script, however, runs 'probe' and then throws away
the printed argv again, reporting only 'podman' or 'docker', which
is used to set the $(RUNC) variable for tests/docker/Makefile.include
which is in turn used to pass --engine to docker.py. So the docker.py
command will re-detect the need for 'sudo -n' and use it correctly

The problem with this is that some commands in Makefile.include do
not call docker.py at all, they invoke $(RUNC) directly. Since
configure threw away the 'sudo' command prefix Makefile.in won't
be adding either 'sudo' or 'sudo -n', it'll just run plain 'docker'
which is wrong.

This commit sanitizes things so that the 'docker.py probe' prints
out the exact detected ARGV, and configure fully preserves this
ARGV when setting $(RUNC). Since "$(RUNC)" is no longer just a bare
engine name, however, we must now also set the $(CONTAINER_ENGINE)
variable for Makefile.include so it can pass something sane to
the --engine arg for docker.py

Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20260210163556.713841-2-berrange@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
master
Daniel P. Berrangé 2 months ago
committed by Thomas Huth
parent
commit
fbf4fa1091
  1. 19
      configure
  2. 5
      tests/docker/Makefile.include
  3. 7
      tests/docker/docker.py

19
configure

@ -1319,17 +1319,11 @@ fi
########################################## ##########################################
# functions to probe cross compilers # functions to probe cross compilers
container="no" runc="no"
runc=""
if test $use_containers = "yes" && (has "docker" || has "podman"); then if test $use_containers = "yes" && (has "docker" || has "podman"); then
case $($python "$source_path"/tests/docker/docker.py --engine "$container_engine" probe) in runc=$($python "$source_path"/tests/docker/docker.py --engine "$container_engine" probe)
*docker) container=docker ;; if test "$runc" != "no"; then
podman) container=podman ;; docker_py="$python $source_path/tests/docker/docker.py --engine $container_engine"
no) container=no ;;
esac
if test "$container" != "no"; then
docker_py="$python $source_path/tests/docker/docker.py --engine $container"
runc=$container
fi fi
fi fi
@ -1449,7 +1443,7 @@ probe_target_compiler() {
esac esac
for host in $container_hosts; do for host in $container_hosts; do
test "$container" != no || continue test "$runc" != no || continue
test "$host" = "$cpu" || continue test "$host" = "$cpu" || continue
case $target_arch in case $target_arch in
# debian-all-test-cross architectures # debian-all-test-cross architectures
@ -1771,8 +1765,9 @@ echo all: >> $config_host_mak
echo "SRC_PATH=$source_path" >> $config_host_mak echo "SRC_PATH=$source_path" >> $config_host_mak
echo "TARGET_DIRS=$target_list" >> $config_host_mak echo "TARGET_DIRS=$target_list" >> $config_host_mak
echo "GDB=$gdb_bin" >> $config_host_mak echo "GDB=$gdb_bin" >> $config_host_mak
if test "$container" != no; then if test "$runc" != no; then
echo "RUNC=$runc" >> $config_host_mak echo "RUNC=$runc" >> $config_host_mak
echo "CONTAINER_ENGINE=$container_engine" >> $config_host_mak
fi fi
echo "SUBDIRS=$subdirs" >> $config_host_mak echo "SUBDIRS=$subdirs" >> $config_host_mak
if test "$rust" != disabled; then if test "$rust" != disabled; then

5
tests/docker/Makefile.include

@ -16,8 +16,9 @@ DOCKER_DEFAULT_REGISTRY := registry.gitlab.com/qemu-project/qemu
endif endif
DOCKER_REGISTRY := $(if $(REGISTRY),$(REGISTRY),$(DOCKER_DEFAULT_REGISTRY)) DOCKER_REGISTRY := $(if $(REGISTRY),$(REGISTRY),$(DOCKER_DEFAULT_REGISTRY))
RUNC ?= $(if $(shell command -v docker), docker, podman) CONTAINER_ENGINE = auto
DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(RUNC) DOCKER_SCRIPT=$(SRC_PATH)/tests/docker/docker.py --engine $(CONTAINER_ENGINE)
RUNC ?= $(shell $(DOCKER_SCRIPT) probe)
CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$) CUR_TIME := $(shell date +%Y-%m-%d-%H.%M.%S.$$$$)
DOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME) DOCKER_SRC_COPY := $(BUILD_DIR)/docker-src.$(CUR_TIME)

7
tests/docker/docker.py

@ -618,12 +618,7 @@ class ProbeCommand(SubCommand):
def run(self, args, argv): def run(self, args, argv):
try: try:
docker = Docker() docker = Docker()
if docker._command[0] == "docker": print(" ".join(docker._command))
print("docker")
elif docker._command[0] == "sudo":
print("sudo docker")
elif docker._command[0] == "podman":
print("podman")
except Exception: except Exception:
print("no") print("no")

Loading…
Cancel
Save