From nobody Tue Feb 10 15:44:58 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of _spf.google.com designates 209.85.128.41 as permitted sender) client-ip=209.85.128.41; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-wm1-f41.google.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1615849743; cv=none; d=zohomail.com; s=zohoarc; b=kyI8w5dpsjLyYc4qI7yAL0LzfpfJAjOKNAQhkVzVteVfSQuotdYTxhX2H+yIo4neGV3wYtTBvKNrLimwISKFpbgFVaqf7X9VfM79o/C9fiCpsXlk5ycedRoSWt3zS0VXqlxrhxMWpBhIPznyS3kcQUKfAdRtDGP/6AqFd2Ertw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615849743; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aBbDjOPo2KNb79pU06GVUHksAp78Q462ezyUFGJx4LU=; b=Ps4PtngE9CDJkvKjpTcRaBJw8Fv40MAn9aisB5acmRHyuJVoE9STQABBx3RV2G80/YSB1gKGnNNqB1kd0yvo5GEs8zmh/VaUcf62YHbW6uVARONAyAlXYoDfB6wE2IxK451pbg4VXdvQewgrsGXNyg1ofHgvlGZ56+ggl/WExeE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of _spf.google.com designates 209.85.128.41 as permitted sender) smtp.mailfrom=philippe.mathieu.daude@gmail.com Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by mx.zohomail.com with SMTPS id 1615849743028918.5507336579487; Mon, 15 Mar 2021 16:09:03 -0700 (PDT) Received: by mail-wm1-f41.google.com with SMTP id b2-20020a7bc2420000b029010be1081172so400953wmj.1 for ; Mon, 15 Mar 2021 16:09:02 -0700 (PDT) Return-Path: Return-Path: Received: from x1w.redhat.com (17.red-88-21-201.staticip.rima-tde.net. [88.21.201.17]) by smtp.gmail.com with ESMTPSA id y1sm1059521wmq.29.2021.03.15.16.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 16:09:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aBbDjOPo2KNb79pU06GVUHksAp78Q462ezyUFGJx4LU=; b=I0uzjyT5ZkiUwsuTCh9Oh/LROMloQWrUChZR5Lgn8bwsELaTlPD7683fg69/dATgNA eO3G1k9ze0UHhr21YmR31ZzYgn3t2xlR2IjSfCohlYlr8saEWIXRD1j08+TqWZ/OT80+ LVp+AIMNCmwPNBDZtetHGWqk6qKT3JvUOAtl1jf2yZBXYLa4RJUp5sSA+OCJh/XJiS3V FlsgvXPvrqDr3H+ayAuUlS2yvAWetuXrjmgGXXv1CG68OQl18AyNBRU/F8pdQ5MQK/2/ +kJ8xjTeGGFQFPhZwYeZjN3XpwF67S2LAhBlN53rLzQ99RcN/2b3Cmld+AZjQC3Uv3QT Rl1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=aBbDjOPo2KNb79pU06GVUHksAp78Q462ezyUFGJx4LU=; b=P9TBU/XmLpwwiLCUIA/DhqKcNkqaIeXWxMpV+y9lEQTVQGmzmQ7Jr09x45V93o1pY/ M6HDLq1G5I+599XjQUfUQiaYhLf2ACWMS2zj0u8XkTe7UCM1wpGeekiYR7ZPnKlYCPlz Z9o2HMmp7C8WM016z64klIAguzLK9bDl/ZmkGMr2AME6blHbY+nvdcGz3q5a6G12hLQU JvPdYr7rYivN7gdkW/aj4jHvmMpT30IP+iGDyGuPH7Beu5XTrzg43iA95zkhzPFO2yJ8 28F1NeRz6hcgKOwQRAwlMnXJqYKr90Arf1mmyLp4RcJFvQGMXT/W1EhrZZZCOF6wlmOU w6Tg== X-Gm-Message-State: AOAM530Q316dFChZ8/9NJKWH/oIQCr5Q6Sr6WDWiOzakTmNn0DMjfTnK QX/5yqN+kbCXWcsy+bkRR64= X-Google-Smtp-Source: ABdhPJzM1rTP2Ro3XwpejzVpRvf0n2FX/EexqPehL/ELWoM+YV1eaPCLZlgfPDoDkDYQRZ8QGABuZA== X-Received: by 2002:a05:600c:c4:: with SMTP id u4mr1786902wmm.27.1615849741232; Mon, 15 Mar 2021 16:09:01 -0700 (PDT) Sender: =?UTF-8?Q?Philippe_Mathieu=2DDaud=C3=A9?= From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Cleber Rosa , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Willian Rampazzo , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH v3 4/5] tests/acceptance: Share useful helpers from virtiofs_submounts test Date: Tue, 16 Mar 2021 00:08:37 +0100 Message-Id: <20210315230838.2973103-5-f4bug@amsat.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210315230838.2973103-1-f4bug@amsat.org> References: <20210315230838.2973103-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) Move the useful has_cmd()/has_cmds() helpers from the virtiofs test to the avocado_qemu public class. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Wainer dos Santos Moschetta --- tests/acceptance/avocado_qemu/__init__.py | 57 ++++++++++++++++++++++ tests/acceptance/virtiofs_submounts.py | 59 +---------------------- 2 files changed, 59 insertions(+), 57 deletions(-) diff --git a/tests/acceptance/avocado_qemu/__init__.py b/tests/acceptance/a= vocado_qemu/__init__.py index b471bee66e0..48c705fe3d2 100644 --- a/tests/acceptance/avocado_qemu/__init__.py +++ b/tests/acceptance/avocado_qemu/__init__.py @@ -11,6 +11,7 @@ import logging import os import shutil +import subprocess import sys import uuid import tempfile @@ -45,6 +46,62 @@ from qemu.accel import tcg_available from qemu.machine import QEMUMachine =20 +def has_cmd(name, args=3DNone): + """ + This function is for use in a @avocado.skipUnless decorator, e.g.: + + @skipUnless(*has_cmd('sudo -n', ('sudo', '-n', 'true'))) + def test_something_that_needs_sudo(self): + ... + """ + + if args is None: + args =3D ('which', name) + + try: + _, stderr, exitcode =3D run_cmd(args) + except Exception as e: + exitcode =3D -1 + stderr =3D str(e) + + if exitcode !=3D 0: + cmd_line =3D ' '.join(args) + err =3D f'{name} required, but "{cmd_line}" failed: {stderr.strip(= )}' + return (False, err) + else: + return (True, '') + +def has_cmds(*cmds): + """ + This function is for use in a @avocado.skipUnless decorator and + allows checking for the availability of multiple commands, e.g.: + + @skipUnless(*has_cmds(('cmd1', ('cmd1', '--some-parameter')), + 'cmd2', 'cmd3')) + def test_something_that_needs_cmd1_and_cmd2(self): + ... + """ + + for cmd in cmds: + if isinstance(cmd, str): + cmd =3D (cmd,) + + ok, errstr =3D has_cmd(*cmd) + if not ok: + return (False, errstr) + + return (True, '') + +def run_cmd(args): + subp =3D subprocess.Popen(args, + stdout=3Dsubprocess.PIPE, + stderr=3Dsubprocess.PIPE, + universal_newlines=3DTrue) + stdout, stderr =3D subp.communicate() + ret =3D subp.returncode + + return (stdout, stderr, ret) + def is_readable_executable_file(path): return os.path.isfile(path) and os.access(path, os.R_OK | os.X_OK) =20 diff --git a/tests/acceptance/virtiofs_submounts.py b/tests/acceptance/virt= iofs_submounts.py index 46fa65392a1..201645cd740 100644 --- a/tests/acceptance/virtiofs_submounts.py +++ b/tests/acceptance/virtiofs_submounts.py @@ -6,67 +6,12 @@ =20 from avocado import skipUnless from avocado_qemu import LinuxTest, BUILD_DIR +from avocado_qemu import has_cmds +from avocado_qemu import run_cmd from avocado_qemu import wait_for_console_pattern from avocado.utils import ssh =20 =20 -def run_cmd(args): - subp =3D subprocess.Popen(args, - stdout=3Dsubprocess.PIPE, - stderr=3Dsubprocess.PIPE, - universal_newlines=3DTrue) - stdout, stderr =3D subp.communicate() - ret =3D subp.returncode - - return (stdout, stderr, ret) - -def has_cmd(name, args=3DNone): - """ - This function is for use in a @avocado.skipUnless decorator, e.g.: - - @skipUnless(*has_cmd('sudo -n', ('sudo', '-n', 'true'))) - def test_something_that_needs_sudo(self): - ... - """ - - if args is None: - args =3D ('which', name) - - try: - _, stderr, exitcode =3D run_cmd(args) - except Exception as e: - exitcode =3D -1 - stderr =3D str(e) - - if exitcode !=3D 0: - cmd_line =3D ' '.join(args) - err =3D f'{name} required, but "{cmd_line}" failed: {stderr.strip(= )}' - return (False, err) - else: - return (True, '') - -def has_cmds(*cmds): - """ - This function is for use in a @avocado.skipUnless decorator and - allows checking for the availability of multiple commands, e.g.: - - @skipUnless(*has_cmds(('cmd1', ('cmd1', '--some-parameter')), - 'cmd2', 'cmd3')) - def test_something_that_needs_cmd1_and_cmd2(self): - ... - """ - - for cmd in cmds: - if isinstance(cmd, str): - cmd =3D (cmd,) - - ok, errstr =3D has_cmd(*cmd) - if not ok: - return (False, errstr) - - return (True, '') - - class VirtiofsSubmountsTest(LinuxTest): """ :avocado: tags=3Darch:x86_64 --=20 2.26.2