From nobody Mon Feb 9 17:24:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1636388297; cv=none; d=zohomail.com; s=zohoarc; b=DK6BBklx78gcEOWJurXCp8GwywFKQi651nH7g9MkoXuhYocaKKXcjRbEoBvSmpiZ6WqDcuppVfcVW2tErTnSpRW92iyIQXTTX5+xT2jlub/DSC2oNQCKBVkF5TXZXg1shO/bYBEY87mVsRS0bH4TFYaptNiLStmLu4uLfwEA4/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1636388297; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=Kig7GyB9MliSxk4dpCwMT9fFAcU2KC7uvJYsdHZHBGs=; b=ZOsY8VAH/DTYHu6OHJKXpKy5j4sZCtde0uqsL580dRjMUqoNpLYRvho4tDwO1LN9O4lIIweMpBiCUAlXzCAOPzXS/Qm74cUsKRvXLrtcUzsybnM0LA9qTRWdBGlWglLHVypqeKG90b55/UiwI97bXMiIQodjEiwIS9OvQMZ8dmM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1636388297988373.5938084354485; Mon, 8 Nov 2021 08:18:17 -0800 (PST) Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-118-ldgSwG5QM_SWR43yOTdCIg-1; Mon, 08 Nov 2021 11:18:15 -0500 Received: by mail-wr1-f71.google.com with SMTP id d13-20020adf9b8d000000b00160a94c235aso4215296wrc.2 for ; Mon, 08 Nov 2021 08:18:15 -0800 (PST) Return-Path: Return-Path: Received: from x1w.. (46.red-193-152-127.dynamicip.rima-tde.net. [193.152.127.46]) by smtp.gmail.com with ESMTPSA id o9sm17308511wrs.4.2021.11.08.08.18.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Nov 2021 08:18:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1636388297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Kig7GyB9MliSxk4dpCwMT9fFAcU2KC7uvJYsdHZHBGs=; b=HhKUpBcdcZ+DC8CYG5asQECizjef5UOG1V++eW8ehsAEfxGZZeAvWp0ypIcooDeU47xx/I v5iiivO7HMma6BMYcHkou9iyWRX7EUKyt894mbLHics73rv98GLNd2HvUfFTSxs1DLaL+r ZEbWXOw8lSOSnYmR8qI53+jf0YaVJTw= X-MC-Unique: ldgSwG5QM_SWR43yOTdCIg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kig7GyB9MliSxk4dpCwMT9fFAcU2KC7uvJYsdHZHBGs=; b=IjvgLbE8uDCXx7askC3T2yr8oxxoonsQXUZRXK1vp0uk739te7E7vCEh25s4TfHhjK WVTa+TZgTb3chHLXlyLRur31ec0/zu2dzAwb8s+HHBDiB0TEYwc5RQY/mWWNY35ljqx2 yE9Cmos86po/NYA+S2ZNSHXOY6zYoHqRtiXn2EBOfsQ/0D4zCYeyFacYdarV2uv8V5oL FbfA9Mak4TtclXaVlvs3fkASDHWMTmqc49BLM/+Dh9ngdrzEwv2VGyDheLSbMRF+6/y7 KBgsTYAsJaApxqv4PDkDQt4WBz1qKMA0lfeJFWhOAC2uBbrSJPbMTjN6pHjVbtjkl0xw AHBg== X-Gm-Message-State: AOAM532fhvz+bEJ6Bj/YKsdGWx0pQu8zvkRKWwqmseB3NHpwkbYMKR6b 1JXYgbkEk1RT7hVVJwENF1+e3Sl4uABipcGA/xIDzXPxC+ppD8AvKLOEiN5ZHkEul4F99DAIzT3 0xV0DHFtTD78rAw== X-Received: by 2002:adf:d1cd:: with SMTP id b13mr341699wrd.323.1636388294299; Mon, 08 Nov 2021 08:18:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJynbI3mbrMXZduZeg+EvCyMLLcq2njFLlgNhupiViSOWgSOf+YYtWqM9GWEwVlmYDsU9ZTvNg== X-Received: by 2002:adf:d1cd:: with SMTP id b13mr341660wrd.323.1636388294060; Mon, 08 Nov 2021 08:18:14 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Cleber Rosa , Wainer dos Santos Moschetta , Willian Rampazzo , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 6/9] tests/avocado: Share useful helpers from virtiofs_submounts test Date: Mon, 8 Nov 2021 17:17:36 +0100 Message-Id: <20211108161739.1371503-7-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211108161739.1371503-1-philmd@redhat.com> References: <20211108161739.1371503-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1636388299013100001 From: Philippe Mathieu-Daud=C3=A9 Move the useful has_cmd()/has_cmds() helpers from the virtiofs test to the avocado_qemu public class. Reviewed-by: Wainer dos Santos Moschetta Reviewed-by: Willian Rampazzo Signed-off-by: Philippe Mathieu-Daud=C3=A9 Message-Id: <20211105143416.148332-5-f4bug@amsat.org> --- tests/avocado/avocado_qemu/__init__.py | 57 +++++++++++++++++++++++++ tests/avocado/virtiofs_submounts.py | 59 +------------------------- 2 files changed, 59 insertions(+), 57 deletions(-) diff --git a/tests/avocado/avocado_qemu/__init__.py b/tests/avocado/avocado= _qemu/__init__.py index e46b3ecb89e..1efc22dabfa 100644 --- a/tests/avocado/avocado_qemu/__init__.py +++ b/tests/avocado/avocado_qemu/__init__.py @@ -11,6 +11,7 @@ import logging import os import shutil +import subprocess import sys import tempfile import time @@ -41,6 +42,62 @@ tcg_available) =20 =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/avocado/virtiofs_submounts.py b/tests/avocado/virtiofs_s= ubmounts.py index 21ad7d792e7..e6dc32ffd4e 100644 --- a/tests/avocado/virtiofs_submounts.py +++ b/tests/avocado/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.31.1