From nobody Wed Nov 19 00:18:02 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613081921; cv=none; d=zohomail.com; s=zohoarc; b=JVCScKqridpVfpvdIhZ3pdZ7n/8+1d0iAxXtcbbAabuwr9uxdMOyDsaYKqVQ/LN3adl0oxPm0RGneRj3Ch6DNRMozyZrzPoGJmOfTJvfQ+IudIyZFJXCy8O0Mlh9TYJ6hsHQgoOAjd6JhlJG3lzma45DRcxXdW341SQKi5ICTyc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613081921; 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; bh=y2hvibq9qOY9t7tRlKusvRT2KSYUM2Z2KjXnneBL7KQ=; b=hb29ML8/P6N1gJtpGiO9Ha0IkMmbxSGNhJwjoCzpIbrYexsjGJyioq7U1IZVy/J07OgLyTAilG6NW+Z1/u2ffFXlDpcmt4RfpUlaj5kvE3ptW85FCVO424dqiqANnYzHUPcTSDI0A9JLIijN136KXZdK9YIeQEc2G/pcYR3Olqg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1613081920746386.75662206152117; Thu, 11 Feb 2021 14:18:40 -0800 (PST) Received: from localhost ([::1]:46214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lAKIJ-0005Bm-OY for importer@patchew.org; Thu, 11 Feb 2021 17:18:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lAK2G-0000Ky-4u for qemu-devel@nongnu.org; Thu, 11 Feb 2021 17:02:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:52078) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1lAK2D-0005tn-Fs for qemu-devel@nongnu.org; Thu, 11 Feb 2021 17:02:03 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-25-N9mEZOxZNTG9mQzr4OPW-g-1; Thu, 11 Feb 2021 17:01:57 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E9A0C7402; Thu, 11 Feb 2021 22:01:56 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-89.rdu2.redhat.com [10.10.116.89]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B213D60BF1; Thu, 11 Feb 2021 22:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613080920; 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=y2hvibq9qOY9t7tRlKusvRT2KSYUM2Z2KjXnneBL7KQ=; b=JlwdDYmOFw9tV/9TuA5Ukb6uyMApCPR1fq4S55nn5SSE9Pd7Gg72TJqpVeDrFLPUhoaRrt ze2JJD7zgIKZ6jVoK6wEGpZLnWguuE+W3p6n07a5yQOX6EIVTpYwjFez0nkaMBgd20jgwq mNZb9rd86hUx+PRcnS/5oVaRMQxpzlA= X-MC-Unique: N9mEZOxZNTG9mQzr4OPW-g-1 From: Cleber Rosa To: qemu-devel@nongnu.org Subject: [PATCH 2/6] Python: expose QEMUMachine's temporary directory Date: Thu, 11 Feb 2021 17:01:42 -0500 Message-Id: <20210211220146.2525771-3-crosa@redhat.com> In-Reply-To: <20210211220146.2525771-1-crosa@redhat.com> References: <20210211220146.2525771-1-crosa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=crosa@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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=216.205.24.124; envelope-from=crosa@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -33 X-Spam_score: -3.4 X-Spam_bar: --- X-Spam_report: (-3.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.569, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action 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: Kevin Wolf , Thomas Huth , Eduardo Habkost , qemu-block@nongnu.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Wainer dos Santos Moschetta , Max Reitz , =?UTF-8?q?Alex=20Benn=C3=A9e?= , Willian Rampazzo , Cleber Rosa , John Snow , Beraldo Leal Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Each instance of qemu.machine.QEMUMachine currently has a "test directory", which may not have any relation to a "test", and it's really a temporary directory. Users instantiating the QEMUMachine class will be able to set the location of the directory that will *contain* the QEMUMachine unique temporary directory, so that parameter name has been changed from test_dir to base_temp_dir. A property has been added to allow users to access it without using private attributes, and with that, the directory is created on first use of the property. Signed-off-by: Cleber Rosa Reviewed-by: Wainer dos Santos Moschetta --- python/qemu/machine.py | 24 ++++++++++++++++-------- python/qemu/qtest.py | 6 +++--- tests/acceptance/virtio-gpu.py | 2 +- tests/qemu-iotests/iotests.py | 2 +- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/python/qemu/machine.py b/python/qemu/machine.py index 6e44bda337..b379fcbe72 100644 --- a/python/qemu/machine.py +++ b/python/qemu/machine.py @@ -84,7 +84,7 @@ class QEMUMachine: args: Sequence[str] =3D (), wrapper: Sequence[str] =3D (), name: Optional[str] =3D None, - test_dir: str =3D "/var/tmp", + base_temp_dir: str =3D "/var/tmp", monitor_address: Optional[SocketAddrT] =3D None, socket_scm_helper: Optional[str] =3D None, sock_dir: Optional[str] =3D None, @@ -97,10 +97,10 @@ class QEMUMachine: @param args: list of extra arguments @param wrapper: list of arguments used as prefix to qemu binary @param name: prefix for socket and log file names (default: qemu-P= ID) - @param test_dir: where to create socket and log file + @param base_temp_dir: default location where temporary files are c= reated @param monitor_address: address for QMP monitor @param socket_scm_helper: helper program, required for send_fd_scm= () - @param sock_dir: where to create socket (overrides test_dir for so= ck) + @param sock_dir: where to create socket (defaults to base_temp_dir) @param drain_console: (optional) True to drain console socket to b= uffer @param console_log: (optional) path to console log file @note: Qemu process is not started until launch() is used. @@ -112,8 +112,8 @@ class QEMUMachine: self._wrapper =3D wrapper =20 self._name =3D name or "qemu-%d" % os.getpid() - self._test_dir =3D test_dir - self._sock_dir =3D sock_dir or self._test_dir + self._base_temp_dir =3D base_temp_dir + self._sock_dir =3D sock_dir or self._base_temp_dir self._socket_scm_helper =3D socket_scm_helper =20 if monitor_address is not None: @@ -303,9 +303,7 @@ class QEMUMachine: return args =20 def _pre_launch(self) -> None: - self._temp_dir =3D tempfile.mkdtemp(prefix=3D"qemu-machine-", - dir=3Dself._test_dir) - self._qemu_log_path =3D os.path.join(self._temp_dir, self._name + = ".log") + self._qemu_log_path =3D os.path.join(self.temp_dir, self._name + "= .log") self._qemu_log_file =3D open(self._qemu_log_path, 'wb') =20 if self._console_set: @@ -744,3 +742,13 @@ class QEMUMachine: file=3Dself._console_log_path, drain=3Dself._drain_console) return self._console_socket + + @property + def temp_dir(self) -> str: + """ + Returns a temporary directory to be used for this machine + """ + if self._temp_dir is None: + self._temp_dir =3D tempfile.mkdtemp(prefix=3D"qemu-machine-", + dir=3Dself._base_temp_dir) + return self._temp_dir diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py index 39a0cf62fe..78b97d13cf 100644 --- a/python/qemu/qtest.py +++ b/python/qemu/qtest.py @@ -112,14 +112,14 @@ class QEMUQtestMachine(QEMUMachine): binary: str, args: Sequence[str] =3D (), name: Optional[str] =3D None, - test_dir: str =3D "/var/tmp", + base_temp_dir: str =3D "/var/tmp", socket_scm_helper: Optional[str] =3D None, sock_dir: Optional[str] =3D None): if name is None: name =3D "qemu-%d" % os.getpid() if sock_dir is None: - sock_dir =3D test_dir - super().__init__(binary, args, name=3Dname, test_dir=3Dtest_dir, + sock_dir =3D base_temp_dir + super().__init__(binary, args, name=3Dname, base_temp_dir=3Dbase_t= emp_dir, socket_scm_helper=3Dsocket_scm_helper, sock_dir=3Dsock_dir) self._qtest: Optional[QEMUQtestProtocol] =3D None diff --git a/tests/acceptance/virtio-gpu.py b/tests/acceptance/virtio-gpu.py index 211f02932f..8d689eb820 100644 --- a/tests/acceptance/virtio-gpu.py +++ b/tests/acceptance/virtio-gpu.py @@ -119,7 +119,7 @@ class VirtioGPUx86(Test): os.set_inheritable(vug_sock.fileno(), True) =20 self._vug_log_path =3D os.path.join( - self.vm._test_dir, "vhost-user-gpu.log" + self.vm.temp_dir, "vhost-user-gpu.log" ) self._vug_log_file =3D open(self._vug_log_path, "wb") print(self._vug_log_path) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 00be68eca3..b02a3dc092 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -562,7 +562,7 @@ class VM(qtest.QEMUQtestMachine): def __init__(self, path_suffix=3D''): name =3D "qemu%s-%d" % (path_suffix, os.getpid()) super().__init__(qemu_prog, qemu_opts, name=3Dname, - test_dir=3Dtest_dir, + base_temp_dir=3Dtest_dir, socket_scm_helper=3Dsocket_scm_helper, sock_dir=3Dsock_dir) self._num_drives =3D 0 --=20 2.25.4