From nobody Sat Dec 28 10:59:38 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1734451608; cv=none; d=zohomail.com; s=zohoarc; b=oBVEia+tabBfrcVKjuej3znE64QFzQSId2vHXKYP2Y6nCTyT+Y4SxA0fkLabTwY8nv+bFK5jdSK60jZvZPBWxTtwhvuoRu31SzCC47TA7A+3h05u9BIqAPrbrMsgpZn2S02EPfJlGS+b4JBzOLB/gP9kR4OWWuY/GHS4yeLdYTc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734451608; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=sAmrbxoAoZ9PR/4gbrF0EEd1IpdvHSc5XD3afoe70/Q=; b=idUKiBFvVqHlI+iJARpZvuvS/W7GMwsT1U8nIgUswqynddQl/2u4K1w7j35vIViS8wKYb/BXB3oIcJ5W0Ck7w6AFVOYPLUWkvNoMn9NeFLatAnPXzn4ySctrQmFHYKh9paaT/TZh4pk6rBgLNzljM4fKK/IpWm1i841+Map6+4A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1734451608131115.3108526835972; Tue, 17 Dec 2024 08:06:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNa12-00060e-Vy; Tue, 17 Dec 2024 11:01:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tNa0r-0005cD-B9 for qemu-devel@nongnu.org; Tue, 17 Dec 2024 11:01:33 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tNa0m-0002F7-8t for qemu-devel@nongnu.org; Tue, 17 Dec 2024 11:01:31 -0500 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-543-ivtFr7s1MwyQ1lxfSn-rUQ-1; Tue, 17 Dec 2024 11:01:23 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 83C59195605E; Tue, 17 Dec 2024 16:01:22 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.136]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E950A30044C1; Tue, 17 Dec 2024 16:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734451287; 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=sAmrbxoAoZ9PR/4gbrF0EEd1IpdvHSc5XD3afoe70/Q=; b=XaW1uTxEZSWISHbagSxsLwSVnHlOHElPOIM8T0v23cVu5wDh6OLRWy9snscCULkG+mzXvF QQ6lUM5Ny6IuNNtkJHKoW6+SwOcR1C6euEdVDOT7HQ2Rci5Dl2pduhkzvCudp9fZuBV2im SG43qAMs6XNOvSzpRQ49A842PN0mMHw= X-MC-Unique: ivtFr7s1MwyQ1lxfSn-rUQ-1 X-Mimecast-MFC-AGG-ID: ivtFr7s1MwyQ1lxfSn-rUQ From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , Thomas Huth Subject: [PATCH v3 28/32] tests/functional: replace 'run_cmd' with subprocess helpers Date: Tue, 17 Dec 2024 15:59:49 +0000 Message-ID: <20241217155953.3950506-29-berrange@redhat.com> In-Reply-To: <20241217155953.3950506-1-berrange@redhat.com> References: <20241217155953.3950506-1-berrange@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=berrange@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.116, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1734451608445116600 The 'run_cmd' helper is re-implementing a convenient helper that already exists in the form of the 'run' and 'check_call' methods provided by 'subprocess'. Reviewed-by: Thomas Huth Signed-off-by: Daniel P. Berrang=C3=A9 --- tests/functional/qemu_test/archive.py | 9 ++++--- tests/functional/qemu_test/tesseract.py | 10 ++++---- tests/functional/qemu_test/testcase.py | 31 +++++++++++++----------- tests/functional/qemu_test/tuxruntest.py | 8 +++--- tests/functional/test_aarch64_virt.py | 6 +++-- tests/functional/test_ppc64_tuxrun.py | 7 ++++-- 6 files changed, 41 insertions(+), 30 deletions(-) diff --git a/tests/functional/qemu_test/archive.py b/tests/functional/qemu_= test/archive.py index c439d9413a..c803fdaf6d 100644 --- a/tests/functional/qemu_test/archive.py +++ b/tests/functional/qemu_test/archive.py @@ -14,7 +14,6 @@ import zipfile =20 from .asset import Asset -from .cmd import run_cmd =20 =20 def tar_extract(archive, dest_dir, member=3DNone): @@ -52,9 +51,11 @@ def deb_extract(archive, dest_dir, member=3DNone): cwd =3D os.getcwd() os.chdir(dest_dir) try: - (stdout, stderr, ret) =3D run_cmd(['ar', 't', archive]) - file_path =3D stdout.split()[2] - run_cmd(['ar', 'x', archive, file_path]) + proc =3D run(['ar', 't', archive], + check=3DTrue, capture_output=3DTrue, encoding=3D'utf8') + file_path =3D proc.stdout.split()[2] + check_call(['ar', 'x', archive, file_path], + stdout=3DDEVNULL, stderr=3DDEVNULL) tar_extract(file_path, dest_dir, member) finally: os.chdir(cwd) diff --git a/tests/functional/qemu_test/tesseract.py b/tests/functional/qem= u_test/tesseract.py index 1b7818090a..ede6c6501e 100644 --- a/tests/functional/qemu_test/tesseract.py +++ b/tests/functional/qemu_test/tesseract.py @@ -6,18 +6,18 @@ # later. See the COPYING file in the top-level directory. =20 import logging +from subprocess import run =20 -from . import run_cmd =20 def tesseract_ocr(image_path, tesseract_args=3D''): console_logger =3D logging.getLogger('console') console_logger.debug(image_path) - (stdout, stderr, ret) =3D run_cmd(['tesseract', image_path, - 'stdout']) - if ret: + proc =3D run(['tesseract', image_path, 'stdout'], + capture_output=3DTrue, encoding=3D'utf8') + if proc.returncode: return None lines =3D [] - for line in stdout.split('\n'): + for line in proc.stdout.split('\n'): sline =3D line.strip() if len(sline): console_logger.debug(sline) diff --git a/tests/functional/qemu_test/testcase.py b/tests/functional/qemu= _test/testcase.py index d0bb3141d5..aa6c9c0d64 100644 --- a/tests/functional/qemu_test/testcase.py +++ b/tests/functional/qemu_test/testcase.py @@ -16,7 +16,7 @@ from pathlib import Path import pycotap import shutil -import subprocess +from subprocess import run import sys import tempfile import unittest @@ -27,7 +27,6 @@ =20 from .archive import archive_extract from .asset import Asset -from .cmd import run_cmd from .config import BUILD_DIR from .uncompress import uncompress =20 @@ -251,11 +250,11 @@ def add_ldpath(self, ldpath): self._ldpath.append(os.path.abspath(ldpath)) =20 def run_cmd(self, bin_path, args=3D[]): - return subprocess.run([self.qemu_bin] - + ["-L %s" % ldpath for ldpath in self._ldpa= th] - + [bin_path] - + args, - text=3DTrue, capture_output=3DTrue) + return run([self.qemu_bin] + + ["-L %s" % ldpath for ldpath in self._ldpath] + + [bin_path] + + args, + text=3DTrue, capture_output=3DTrue) =20 class QemuSystemTest(QemuBaseTest): """Facilitates system emulation tests.""" @@ -282,7 +281,9 @@ def setUp(self): def set_machine(self, machinename): # TODO: We should use QMP to get the list of available machines if not self._machinehelp: - self._machinehelp =3D run_cmd([self.qemu_bin, '-M', 'help'])[0= ]; + self._machinehelp =3D run( + [self.qemu_bin, '-M', 'help'], + capture_output=3DTrue, check=3DTrue, encoding=3D'utf8').st= dout if self._machinehelp.find(machinename) < 0: self.skipTest('no support for machine ' + machinename) self.machine =3D machinename @@ -310,15 +311,17 @@ def require_accelerator(self, accelerator): "available" % accelerator) =20 def require_netdev(self, netdevname): - netdevhelp =3D run_cmd([self.qemu_bin, - '-M', 'none', '-netdev', 'help'])[0]; - if netdevhelp.find('\n' + netdevname + '\n') < 0: + help =3D run([self.qemu_bin, + '-M', 'none', '-netdev', 'help'], + capture_output=3DTrue, check=3DTrue, encoding=3D'utf8')= .stdout; + if help.find('\n' + netdevname + '\n') < 0: self.skipTest('no support for " + netdevname + " networking') =20 def require_device(self, devicename): - devhelp =3D run_cmd([self.qemu_bin, - '-M', 'none', '-device', 'help'])[0]; - if devhelp.find(devicename) < 0: + help =3D run([self.qemu_bin, + '-M', 'none', '-device', 'help'], + capture_output=3DTrue, check=3DTrue, encoding=3D'utf8')= .stdout; + if help.find(devicename) < 0: self.skipTest('no support for device ' + devicename) =20 def _new_vm(self, name, *args): diff --git a/tests/functional/qemu_test/tuxruntest.py b/tests/functional/qe= mu_test/tuxruntest.py index 0b1bb8f0ed..7227a83757 100644 --- a/tests/functional/qemu_test/tuxruntest.py +++ b/tests/functional/qemu_test/tuxruntest.py @@ -11,11 +11,12 @@ =20 import os import stat +from subprocess import check_call, DEVNULL =20 from qemu_test import QemuSystemTest from qemu_test import exec_command_and_wait_for_pattern from qemu_test import wait_for_console_pattern -from qemu_test import which, run_cmd, get_qemu_img +from qemu_test import which, get_qemu_img =20 class TuxRunBaselineTest(QemuSystemTest): =20 @@ -76,8 +77,9 @@ def fetch_tuxrun_assets(self, kernel_asset, rootfs_asset,= dtb_asset=3DNone): =20 disk_image =3D self.scratch_file("rootfs.ext4") =20 - run_cmd(['zstd', "-f", "-d", disk_image_zst, - "-o", disk_image]) + check_call(['zstd', "-f", "-d", disk_image_zst, + "-o", disk_image], + stdout=3DDEVNULL, stderr=3DDEVNULL) # zstd copies source archive permissions for the output # file, so must make this writable for QEMU os.chmod(disk_image, stat.S_IRUSR | stat.S_IWUSR) diff --git a/tests/functional/test_aarch64_virt.py b/tests/functional/test_= aarch64_virt.py index cc49f8963d..08576b0694 100755 --- a/tests/functional/test_aarch64_virt.py +++ b/tests/functional/test_aarch64_virt.py @@ -12,10 +12,11 @@ =20 import time import logging +from subprocess import check_call, DEVNULL =20 from qemu_test import QemuSystemTest, Asset from qemu_test import exec_command, wait_for_console_pattern -from qemu_test import get_qemu_img, run_cmd +from qemu_test import get_qemu_img =20 =20 class Aarch64VirtMachine(QemuSystemTest): @@ -96,7 +97,8 @@ def common_aarch64_virt(self, machine): logger.info('creating scratch qcow2 image') image_path =3D self.scratch_file('scratch.qcow2') qemu_img =3D get_qemu_img(self) - run_cmd([qemu_img, 'create', '-f', 'qcow2', image_path, '8M']) + check_call([qemu_img, 'create', '-f', 'qcow2', image_path, '8M'], + stdout=3DDEVNULL, stderr=3DDEVNULL) =20 # Add the device self.vm.add_args('-blockdev', diff --git a/tests/functional/test_ppc64_tuxrun.py b/tests/functional/test_= ppc64_tuxrun.py index 03b47e07f2..8a98d18ab3 100755 --- a/tests/functional/test_ppc64_tuxrun.py +++ b/tests/functional/test_ppc64_tuxrun.py @@ -11,9 +11,10 @@ # # SPDX-License-Identifier: GPL-2.0-or-later =20 +from subprocess import check_call, DEVNULL import tempfile =20 -from qemu_test import run_cmd, Asset +from qemu_test import Asset from qemu_test.tuxruntest import TuxRunBaselineTest =20 class TuxRunPPC64Test(TuxRunBaselineTest): @@ -70,7 +71,9 @@ def ppc64_common_tuxrun(self, kernel_asset, rootfs_asset,= prefix): # Create a temporary qcow2 and launch the test-case with tempfile.NamedTemporaryFile(prefix=3Dprefix, suffix=3D'.qcow2') as qcow2: - run_cmd([self.qemu_img, 'create', '-f', 'qcow2', qcow2.name, '= 1G']) + check_call([self.qemu_img, 'create', '-f', 'qcow2', + qcow2.name, ' 1G'], + stdout=3DDEVNULL, stderr=3DDEVNULL) =20 self.vm.add_args('-drive', 'file=3D' + qcow2.name + ',format=3Dqcow2,if=3Dnone,id=3D' --=20 2.46.0