From nobody Tue May 21 04:54:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562702352; cv=none; d=zoho.com; s=zohoarc; b=XkRtKJX+/c0349WhUmuFSlCgYhysU4FNoL+GHyKD9l4ash6zEkh7hs20+yNo9INy7TiO10Ro7Fmf9snKK88nuHoMVW4xiTHKFptPWuLAGiBt55a+iAFXKBqSggsrGDrspR5J1CvQ5w59lJIiu7kN3l6usp7+A4kh63yiQukyZvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562702352; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ml8Qjb837Du8XL/FKkvtGD3rkvGue5fa85iNKUn97m4=; b=M4KvhX+cX0+H7IFvVrF2stBIpV+n3TdFKx9K7VTdrMRuTj4WVmV3kPbq+efpWQCEFOHUbDmaykp/CgaFewKAi/kb4h48T0wKcO6oqB2n26PJl7zOcCZqANOvvgBq4G0ef8M2RynjBcWJoEHszvRqtUHIjI6RZoyNSHd6Q/62JtY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562702352093621.7542543850659; Tue, 9 Jul 2019 12:59:12 -0700 (PDT) Received: from localhost ([::1]:54340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwGc-00028u-IH for importer@patchew.org; Tue, 09 Jul 2019 15:59:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49424) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkw8j-0005sR-Kg for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:51:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkw8g-0002rA-Gu for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:51:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47242) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkw8c-0002kY-N1 for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:50:56 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6EE7317915D; Tue, 9 Jul 2019 19:43:55 +0000 (UTC) Received: from localhost (ovpn-112-55.ams2.redhat.com [10.36.112.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E19292D3A; Tue, 9 Jul 2019 19:43:47 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 23:43:26 +0400 Message-Id: <20190709194330.837-2-marcandre.lureau@redhat.com> In-Reply-To: <20190709194330.837-1-marcandre.lureau@redhat.com> References: <20190709194330.837-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 09 Jul 2019 19:43:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 1/5] docker.py: add podman support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , berrange@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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=C3=A9 Lureau Acked-by: Alex Benn=C3=A9e --- 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 =3D ['ftp_proxy', 'http_proxy', 'http= s_proxy'] =20 DEVNULL =3D open(os.devnull, 'wb') =20 +class EngineEnum(enum.IntEnum): + AUTO =3D 1 + DOCKER =3D 2 + PODMAN =3D 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 =3D EngineEnum.AUTO =20 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()) =20 =20 -def _guess_docker_command(): - """ Guess a working docker command or raise exception if not found""" - commands =3D [["docker"], ["sudo", "-n", "docker"]] +def _guess_engine_command(): + """ Guess a working engine command or raise exception if not found""" + commands =3D [] + + if USE_ENGINE in [EngineEnum.AUTO, EngineEnum.PODMAN]: + commands +=3D [["podman"]] + if USE_ENGINE in [EngineEnum.AUTO, EngineEnum.DOCKER]: + commands +=3D [["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 =3D "\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) =20 =20 @@ -190,7 +216,7 @@ def _dockerfile_preprocess(df): class Docker(object): """ Running Docker commands """ def __init__(self): - self._command =3D _guess_docker_command() + self._command =3D _guess_engine_command() self._instances =3D [] 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] =3D=3D "sudo": print("sudo") + elif docker._command[0] =3D=3D "podman": + print("podman") except Exception: print("no") =20 @@ -597,9 +625,13 @@ class CheckCommand(SubCommand): =20 =20 def main(): + global USE_ENGINE + parser =3D argparse.ArgumentParser(description=3D"A Docker helper", usage=3D"%s ..." % os.path.basename(sys.argv[0])) + parser.add_argument("--engine", type=3DEngineEnum.argparse, choices=3D= list(EngineEnum), + help=3D"specify which container engine to use") subparsers =3D parser.add_subparsers(title=3D"subcommands", help=3DNon= e) for cls in SubCommand.__subclasses__(): cmd =3D cls() @@ -608,6 +640,7 @@ def main(): cmd.args(subp) subp.set_defaults(cmdobj=3Dcmd) args, argv =3D parser.parse_known_args() + USE_ENGINE =3D args.engine return args.cmdobj.run(args, argv) =20 =20 --=20 2.22.0.214.g8dca754b1e From nobody Tue May 21 04:54:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562702075; cv=none; d=zoho.com; s=zohoarc; b=lht7H+XgYYT3P/b/kNy9EIDOyYUGtiHBgmt0mju4j11PBfR3yBjhqOl4853qzqE+XucEb7vBZB203nz7dxldo+Fy9Z30wyuz6OpfAmC/QjDSY69c8N/zk+6XUlVrWBhq5MG0llQa7V8jWeu0ko6qMIxxZAbgS58bQZKNwVyE78Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562702075; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6dLJDSOHR+Jh2FjryYDPXUU7K73GlfucRvEqRl9H4g8=; b=JHvfYEdChgwICFiwGwQixlsBw6vOeR3ajUd5B6a15VbYGOByI1rbTFa/4jDdVrPeamjsO2MnofXFvjqJGAdQDhfpIcWxGYn8hBZmkaCvpBg7ii/JJ9TPdVpCS4C1vt0PFGtp/QxZJbsEesz1wr0x0Pi/B86K27Ht/sC4GaZr41M= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562702075624150.85608542817545; Tue, 9 Jul 2019 12:54:35 -0700 (PDT) Received: from localhost ([::1]:54152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwC7-00089Z-NG for importer@patchew.org; Tue, 09 Jul 2019 15:54:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49855) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkw9K-0006F3-0G for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:51:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkw9H-0003Jb-Cp for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:51:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40186) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkw9G-0003BL-Up for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:51:35 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9D5DB30C01A8; Tue, 9 Jul 2019 19:44:12 +0000 (UTC) Received: from localhost (ovpn-112-55.ams2.redhat.com [10.36.112.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C6E91001E74; Tue, 9 Jul 2019 19:44:00 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 23:43:27 +0400 Message-Id: <20190709194330.837-3-marcandre.lureau@redhat.com> In-Reply-To: <20190709194330.837-1-marcandre.lureau@redhat.com> References: <20190709194330.837-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 09 Jul 2019 19:44:12 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 2/5] tests/docker: add podman support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , berrange@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gerd Hoffmann , Debarshi Ray , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Allow to specify the container engine to run with ENGINE variable. By default, ENGINE=3Dauto and will select either podman or docker. With current podman, we have to use a uidmap trick in order to be able to rw-share the ccache directory with the container user. With a user 1000, the default mapping is: 1000 (host) -> 0 (container). So write access to /var/tmp/ccache ends will end with permission denied error. With "--uidmap 1000:0:1 --uidmap 0:1:1000", the mapping is: 1000 (host) -> 0 (container, 1st namespace) -> 1000 (container, 2nd namespa= ce). (the rest is mumbo jumbo to avoid holes in the range of UIDs) A future podman version may have an option such as --userns-keep-uid. Thanks to Debarshi Ray for the help! Cc: Debarshi Ray Signed-off-by: Marc-Andr=C3=A9 Lureau --- Makefile | 2 +- tests/docker/Makefile.include | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c63de4e36c..2bcf9bc674 100644 --- a/Makefile +++ b/Makefile @@ -1152,7 +1152,7 @@ endif @echo '' @echo 'Test targets:' @echo ' check - Run all tests (check-help for details)' - @echo ' docker - Help about targets running tests inside Docke= r containers' + @echo ' docker - Help about targets running tests inside conta= iners' @echo ' vm-help - Help about targets running tests inside VM' @echo '' @echo 'Documentation targets:' diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include index aaf5396b85..0abd2ab0c9 100644 --- a/tests/docker/Makefile.include +++ b/tests/docker/Makefile.include @@ -17,7 +17,9 @@ DOCKER_TESTS :=3D $(notdir $(shell \ =20 DOCKER_TOOLS :=3D travis =20 -DOCKER_SCRIPT=3D$(SRC_PATH)/tests/docker/docker.py +ENGINE :=3D auto + +DOCKER_SCRIPT=3D$(SRC_PATH)/tests/docker/docker.py --engine $(ENGINE) =20 TESTS ?=3D % IMAGES ?=3D % @@ -146,7 +148,7 @@ $(foreach i,$(filter-out $(DOCKER_PARTIAL_IMAGES),$(DOC= KER_IMAGES) $(DOCKER_DEPR ) =20 docker: - @echo 'Build QEMU and run tests inside Docker containers' + @echo 'Build QEMU and run tests inside Docker or Podman containers' @echo @echo 'Available targets:' @echo @@ -193,6 +195,14 @@ endif @echo ' EXECUTABLE=3D Include executable in image.' @echo ' EXTRA_FILES=3D" [... ]"' @echo ' Include extra files in image.' + @echo ' ENGINE=3Dauto/docker/podman' + @echo ' Specify which container engine to run.' + +UID=3D$(shell id -u) +UID1=3D$(shell expr $(UID) + 1) +ifeq ($(shell $(DOCKER_SCRIPT) probe),podman) +PODMAN=3D1 +endif =20 # This rule if for directly running against an arbitrary docker target. # It is called by the expanded docker targets (e.g. make @@ -212,7 +222,8 @@ docker-run: docker-qemu-src " COPYING $(EXECUTABLE) to $(IMAGE)")) $(call quiet-command, \ $(DOCKER_SCRIPT) run \ - $(if $(NOUSER),,-u $(shell id -u)) \ + $(if $(NOUSER),,-u $(UID) \ + $(if $(PODMAN),--uidmap $(UID):0:1 --uidmap 0:1:$(UID) --uidmap $(UID1= ):$(UID1):64536)) \ --security-opt seccomp=3Dunconfined \ $(if $V,,--rm) \ $(if $(DEBUG),-ti,) \ --=20 2.22.0.214.g8dca754b1e From nobody Tue May 21 04:54:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562701850; cv=none; d=zoho.com; s=zohoarc; b=cJAOly/FizzxX9YnVJ+fIgAsKi6MD1gin8J6KtWxA3hXQHkyYuGbMwsR0zYQXYnPOIxX8Atwuk+T8/qah3TkKxWYfEic2krKnjYZakfjlZUM1rc3kR0sxnVFjhdy7kELLCEbCHkLE2DVkDNSg965Tzs5UjyDq/Bo5rm3gJbSyuo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562701850; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LYZU0PB5PZdvc9NvGMzLggumCQ/laHLdrotxzuGH7A8=; b=OzcPH2Tw8QLaXaBcbAEvh96YaQRz2JnlCkx7ZSbNoHGjrhmbUkdMxSdZoMIl5TjupbVL7D60FOx8+NJil782LHrlYk5bJgBS0CKXEUEkNWDdCk7SjbLAxrKvZwomf7fYDOQ+LkAwyQVfPSv0aYMW9HATDeG+og/CxdjKAzvytJo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 156270185093812.371710984057131; Tue, 9 Jul 2019 12:50:50 -0700 (PDT) Received: from localhost ([::1]:54137 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkw8S-0005QE-B5 for importer@patchew.org; Tue, 09 Jul 2019 15:50:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48254) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkw7j-0004tO-1G for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:50:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkw7h-0001PU-An for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:49:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52712) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkw7g-0001IL-WF for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:49:57 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F43A7FDF8; Tue, 9 Jul 2019 19:44:19 +0000 (UTC) Received: from localhost (ovpn-112-55.ams2.redhat.com [10.36.112.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E7661001B00; Tue, 9 Jul 2019 19:44:17 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 23:43:28 +0400 Message-Id: <20190709194330.837-4-marcandre.lureau@redhat.com> In-Reply-To: <20190709194330.837-1-marcandre.lureau@redhat.com> References: <20190709194330.837-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 09 Jul 2019 19:44:19 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 3/5] tests: specify the address family when checking bind X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , berrange@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" getaddrinfo() may succeed with PF_UNSPEC, but fail when more specific. (this allows to skip some tests that would fail under podman) Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/socket-helpers.c | 17 +++++++++++++---- tests/socket-helpers.h | 11 ----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/tests/socket-helpers.c b/tests/socket-helpers.c index 8112763f5b..19a51e887e 100644 --- a/tests/socket-helpers.c +++ b/tests/socket-helpers.c @@ -30,7 +30,16 @@ # define EAI_ADDRFAMILY 0 #endif =20 -int socket_can_bind_connect(const char *hostname) +/* + * @hostname: a DNS name or numeric IP address + * + * Check whether it is possible to bind & connect to ports + * on the DNS name or IP address @hostname. If an IP address + * is used, it must not be a wildcard address. + * + * Returns 0 on success, -1 on error with errno set + */ +static int socket_can_bind_connect(const char *hostname, int family) { int lfd =3D -1, cfd =3D -1, afd =3D -1; struct addrinfo ai, *res =3D NULL; @@ -44,7 +53,7 @@ int socket_can_bind_connect(const char *hostname) =20 memset(&ai, 0, sizeof(ai)); ai.ai_flags =3D AI_CANONNAME | AI_ADDRCONFIG; - ai.ai_family =3D AF_UNSPEC; + ai.ai_family =3D family; ai.ai_socktype =3D SOCK_STREAM; =20 /* lookup */ @@ -129,7 +138,7 @@ int socket_check_protocol_support(bool *has_ipv4, bool = *has_ipv6) { *has_ipv4 =3D *has_ipv6 =3D false; =20 - if (socket_can_bind_connect("127.0.0.1") < 0) { + if (socket_can_bind_connect("127.0.0.1", PF_INET) < 0) { if (errno !=3D EADDRNOTAVAIL) { return -1; } @@ -137,7 +146,7 @@ int socket_check_protocol_support(bool *has_ipv4, bool = *has_ipv6) *has_ipv4 =3D true; } =20 - if (socket_can_bind_connect("::1") < 0) { + if (socket_can_bind_connect("::1", PF_INET6) < 0) { if (errno !=3D EADDRNOTAVAIL) { return -1; } diff --git a/tests/socket-helpers.h b/tests/socket-helpers.h index 9de0e6b151..512a004811 100644 --- a/tests/socket-helpers.h +++ b/tests/socket-helpers.h @@ -20,17 +20,6 @@ #ifndef TESTS_SOCKET_HELPERS_H #define TESTS_SOCKET_HELPERS_H =20 -/* - * @hostname: a DNS name or numeric IP address - * - * Check whether it is possible to bind & connect to ports - * on the DNS name or IP address @hostname. If an IP address - * is used, it must not be a wildcard address. - * - * Returns 0 on success, -1 on error with errno set - */ -int socket_can_bind_connect(const char *hostname); - /* * @has_ipv4: set to true on return if IPv4 is available * @has_ipv6: set to true on return if IPv6 is available --=20 2.22.0.214.g8dca754b1e From nobody Tue May 21 04:54:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562702107; cv=none; d=zoho.com; s=zohoarc; b=EaUdkwjHJCgcjt4kNq5IiNpyFFFbpaPh017PNgbo0T9GZwIqR8UF20cEZft9rN6/AUq660hb2HYSFh9RlxmpTNEy+m5jMpchgzcCmV1Df4z1fvZ/qlHehv1cO8JyG2W5J8gw5M1saM+8Y7W9dZxoFg7NVNV058wYuD+J2ivd/j8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562702107; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=hIgK/al4Vd/qQVDsBvRLG8KJpNtKNfOCFupbhT1YsOo=; b=GETIy2IJZ1beVYYXrnPyHuEe4IEX7taoRqWQtVXppNEkWeT9X0tBu7QuEt7yhb/k+VXrdpszEI0IucEqA1NmVBXNOVd5qiQRWWOu1RRIRO+7cnqm1CQ6Is2ycu45hJ8zSFAE6RpH0bzkzomXASsXB4sr3hv+p+eX4IcJ6HcagMQ= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562702107972707.5508561785921; Tue, 9 Jul 2019 12:55:07 -0700 (PDT) Received: from localhost ([::1]:54164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwCc-0000dG-6w for importer@patchew.org; Tue, 09 Jul 2019 15:55:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49296) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkw8Q-0005jn-B7 for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:50:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkw8O-0002c5-2p for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:50:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35384) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkw8N-0002Zz-Lk for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:50:40 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03EE93082E1E; Tue, 9 Jul 2019 19:44:31 +0000 (UTC) Received: from localhost (ovpn-112-55.ams2.redhat.com [10.36.112.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id D29578378A; Tue, 9 Jul 2019 19:44:22 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 23:43:29 +0400 Message-Id: <20190709194330.837-5-marcandre.lureau@redhat.com> In-Reply-To: <20190709194330.837-1-marcandre.lureau@redhat.com> References: <20190709194330.837-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Tue, 09 Jul 2019 19:44:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 4/5] test-char: skip tcp tests if ipv4 check failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , berrange@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/Makefile.include | 2 +- tests/test-char.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index a983dd32da..2bddebaf4b 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -523,7 +523,7 @@ tests/check-qlit$(EXESUF): tests/check-qlit.o $(test-ut= il-obj-y) tests/check-qom-interface$(EXESUF): tests/check-qom-interface.o $(test-qom= -obj-y) tests/check-qom-proplist$(EXESUF): tests/check-qom-proplist.o $(test-qom-o= bj-y) =20 -tests/test-char$(EXESUF): tests/test-char.o $(test-util-obj-y) $(qtest-obj= -y) $(test-io-obj-y) $(chardev-obj-y) +tests/test-char$(EXESUF): tests/test-char.o $(test-util-obj-y) $(qtest-obj= -y) $(test-io-obj-y) $(chardev-obj-y) tests/socket-helpers.o tests/test-coroutine$(EXESUF): tests/test-coroutine.o $(test-block-obj-y) tests/test-aio$(EXESUF): tests/test-aio.o $(test-block-obj-y) tests/test-aio-multithread$(EXESUF): tests/test-aio-multithread.o $(test-b= lock-obj-y) diff --git a/tests/test-char.c b/tests/test-char.c index f9440cdcfd..2dde620afc 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -15,6 +15,7 @@ #include "io/channel-socket.h" #include "qapi/qobject-input-visitor.h" #include "qapi/qapi-visit-sockets.h" +#include "socket-helpers.h" =20 static bool quit; =20 @@ -1356,11 +1357,17 @@ static void char_hotswap_test(void) =20 int main(int argc, char **argv) { + bool has_ipv4, has_ipv6; + qemu_init_main_loop(&error_abort); socket_init(); =20 g_test_init(&argc, &argv, NULL); =20 + if (socket_check_protocol_support(&has_ipv4, &has_ipv6) < 0) { + return -1; + } + module_call_init(MODULE_INIT_QOM); qemu_add_opts(&qemu_chardev_opts); =20 @@ -1438,10 +1445,12 @@ int main(int argc, char **argv) g_test_add_data_func("/char/socket/client/wait-conn-fdpass/" # name, \ &client6 ##name, char_socket_client_test) =20 - SOCKET_SERVER_TEST(tcp, &tcpaddr); - SOCKET_CLIENT_TEST(tcp, &tcpaddr); - g_test_add_data_func("/char/socket/server/two-clients/tcp", &tcpaddr, - char_socket_server_two_clients_test); + if (has_ipv4) { + SOCKET_SERVER_TEST(tcp, &tcpaddr); + SOCKET_CLIENT_TEST(tcp, &tcpaddr); + g_test_add_data_func("/char/socket/server/two-clients/tcp", &tcpad= dr, + char_socket_server_two_clients_test); + } #ifndef WIN32 SOCKET_SERVER_TEST(unix, &unixaddr); SOCKET_CLIENT_TEST(unix, &unixaddr); --=20 2.22.0.214.g8dca754b1e From nobody Tue May 21 04:54:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562701980; cv=none; d=zoho.com; s=zohoarc; b=aqEyI5M5lTvgtqGps+1r3hIE5TWll75zTNW6AOUFEjscOXiVi6YASBeXNBpdx9h4qiiHBI2Pjs7wpIch4KKkciV9whde+3DYdAvej8JaBlKGZjsHzmh/1buE6WTaHJVWS2EqTAsZLkiMwq/neOnsKGeFpwNbIbIN/QA2SiuWGt8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562701980; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=JJXmoE5KxK8LqxIcXXzPzg5LVGhau8QBXxAaJq8z5m4=; b=BejaygJfcAIeZgbipOXEBZ6Kdu9ryKtkbu5yiLoNcnwkmxBDT9c7sH/wZotKMrWLrXRsTnGP0XIfLTjXDaAbSjXKlXfA40kkkdw66pr6tN5SvYeh5/OLXTasRk1wd7fJDqm1trWaVlGbukWHGbKTF1g5to+ry8nPYZVHO0vPX7U= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562701980293756.7152117469991; Tue, 9 Jul 2019 12:53:00 -0700 (PDT) Received: from localhost ([::1]:54150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkwAa-0007Bf-Ba for importer@patchew.org; Tue, 09 Jul 2019 15:52:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48907) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkw8E-0005Lw-E5 for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:50:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkw8D-0002ES-28 for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:50:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56760) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkw8C-0002CR-RG for qemu-devel@nongnu.org; Tue, 09 Jul 2019 15:50:28 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DAF1530860C0; Tue, 9 Jul 2019 19:44:43 +0000 (UTC) Received: from localhost (ovpn-112-55.ams2.redhat.com [10.36.112.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id E17D3196EE; Tue, 9 Jul 2019 19:44:35 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 23:43:30 +0400 Message-Id: <20190709194330.837-6-marcandre.lureau@redhat.com> In-Reply-To: <20190709194330.837-1-marcandre.lureau@redhat.com> References: <20190709194330.837-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 09 Jul 2019 19:44:43 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 5/5] test: skip tests if socket_check_protocol_support() failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , berrange@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Gerd Hoffmann , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Skip the tests if socket_check_protocol_support() failed, but do run g_test_run() to keep TAP harness happy. Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/test-char.c | 4 +++- tests/test-io-channel-socket.c | 4 +++- tests/test-util-sockets.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/test-char.c b/tests/test-char.c index 2dde620afc..b56e43c1eb 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -1365,7 +1365,8 @@ int main(int argc, char **argv) g_test_init(&argc, &argv, NULL); =20 if (socket_check_protocol_support(&has_ipv4, &has_ipv6) < 0) { - return -1; + g_printerr("socket_check_protocol_support() failed\n"); + goto end; } =20 module_call_init(MODULE_INIT_QOM); @@ -1465,5 +1466,6 @@ int main(int argc, char **argv) g_test_add_func("/char/hotswap", char_hotswap_test); g_test_add_func("/char/websocket", char_websock_test); =20 +end: return g_test_run(); } diff --git a/tests/test-io-channel-socket.c b/tests/test-io-channel-socket.c index d2053c464c..d172f3070f 100644 --- a/tests/test-io-channel-socket.c +++ b/tests/test-io-channel-socket.c @@ -566,7 +566,8 @@ int main(int argc, char **argv) * with either IPv4 or IPv6 disabled. */ if (socket_check_protocol_support(&has_ipv4, &has_ipv6) < 0) { - return 1; + g_printerr("socket_check_protocol_support() failed\n"); + goto end; } =20 if (has_ipv4) { @@ -595,5 +596,6 @@ int main(int argc, char **argv) test_io_channel_unix_listen_cleanup); #endif /* _WIN32 */ =20 +end: return g_test_run(); } diff --git a/tests/test-util-sockets.c b/tests/test-util-sockets.c index f1ebffee5a..e2a3a8a093 100644 --- a/tests/test-util-sockets.c +++ b/tests/test-util-sockets.c @@ -242,7 +242,8 @@ int main(int argc, char **argv) * with either IPv4 or IPv6 disabled. */ if (socket_check_protocol_support(&has_ipv4, &has_ipv6) < 0) { - return 1; + g_printerr("socket_check_protocol_support() failed\n"); + goto end; } =20 if (has_ipv4) { @@ -264,5 +265,6 @@ int main(int argc, char **argv) test_socket_fd_pass_num_nocli); } =20 +end: return g_test_run(); } --=20 2.22.0.214.g8dca754b1e