qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: qemu-block@nongnu.org
Cc: Thomas Huth <thuth@redhat.com>,
	qemu-devel@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: [PATCH v2 02/23] iotests.py: Store socket files in $SOCK_DIR
Date: Thu, 17 Oct 2019 15:31:34 +0200	[thread overview]
Message-ID: <20191017133155.5327-3-mreitz@redhat.com> (raw)
In-Reply-To: <20191017133155.5327-1-mreitz@redhat.com>

iotests.py itself does not store socket files, but machine.py and
qtest.py do.  iotests.py needs to pass the respective path to them, and
they need to adhere to it.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
---
 python/qemu/machine.py        | 15 ++++++++++++---
 python/qemu/qtest.py          |  9 ++++++---
 tests/qemu-iotests/iotests.py |  4 +++-
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 128a3d1dc2..2024e8b1b1 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -71,7 +71,7 @@ class QEMUMachine(object):
 
     def __init__(self, binary, args=None, wrapper=None, name=None,
                  test_dir="/var/tmp", monitor_address=None,
-                 socket_scm_helper=None):
+                 socket_scm_helper=None, sock_dir=None):
         '''
         Initialize a QEMUMachine
 
@@ -90,6 +90,8 @@ class QEMUMachine(object):
             wrapper = []
         if name is None:
             name = "qemu-%d" % os.getpid()
+        if sock_dir is None:
+            sock_dir = test_dir
         self._name = name
         self._monitor_address = monitor_address
         self._vm_monitor = None
@@ -106,12 +108,14 @@ class QEMUMachine(object):
         self._qemu_full_args = None
         self._test_dir = test_dir
         self._temp_dir = None
+        self._sock_dir = sock_dir
         self._launched = False
         self._machine = None
         self._console_set = False
         self._console_device_type = None
         self._console_address = None
         self._console_socket = None
+        self._remove_files = []
 
         # just in case logging wasn't configured by the main script:
         logging.basicConfig()
@@ -236,8 +240,9 @@ class QEMUMachine(object):
         if self._machine is not None:
             args.extend(['-machine', self._machine])
         if self._console_set:
-            self._console_address = os.path.join(self._temp_dir,
+            self._console_address = os.path.join(self._sock_dir,
                                                  self._name + "-console.sock")
+            self._remove_files.append(self._console_address)
             chardev = ('socket,id=console,path=%s,server,nowait' %
                        self._console_address)
             args.extend(['-chardev', chardev])
@@ -253,8 +258,9 @@ class QEMUMachine(object):
         if self._monitor_address is not None:
             self._vm_monitor = self._monitor_address
         else:
-            self._vm_monitor = os.path.join(self._temp_dir,
+            self._vm_monitor = os.path.join(self._sock_dir,
                                             self._name + "-monitor.sock")
+            self._remove_files.append(self._vm_monitor)
         self._qemu_log_path = os.path.join(self._temp_dir, self._name + ".log")
         self._qemu_log_file = open(self._qemu_log_path, 'wb')
 
@@ -279,6 +285,9 @@ class QEMUMachine(object):
             shutil.rmtree(self._temp_dir)
             self._temp_dir = None
 
+        while len(self._remove_files) > 0:
+            self._remove_if_exists(self._remove_files.pop())
+
     def launch(self):
         """
         Launch the VM and make sure we cleanup and expose the
diff --git a/python/qemu/qtest.py b/python/qemu/qtest.py
index 3f1d2cb325..d24ad04256 100644
--- a/python/qemu/qtest.py
+++ b/python/qemu/qtest.py
@@ -84,14 +84,17 @@ class QEMUQtestMachine(QEMUMachine):
     '''A QEMU VM'''
 
     def __init__(self, binary, args=None, name=None, test_dir="/var/tmp",
-                 socket_scm_helper=None):
+                 socket_scm_helper=None, sock_dir=None):
         if name is None:
             name = "qemu-%d" % os.getpid()
+        if sock_dir is None:
+            sock_dir = test_dir
         super(QEMUQtestMachine,
               self).__init__(binary, args, name=name, test_dir=test_dir,
-                             socket_scm_helper=socket_scm_helper)
+                             socket_scm_helper=socket_scm_helper,
+                             sock_dir=sock_dir)
         self._qtest = None
-        self._qtest_path = os.path.join(test_dir, name + "-qtest.sock")
+        self._qtest_path = os.path.join(sock_dir, name + "-qtest.sock")
 
     def _base_args(self):
         args = super(QEMUQtestMachine, self)._base_args()
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 43759e4e27..0616129342 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -57,6 +57,7 @@ qemu_opts = os.environ.get('QEMU_OPTIONS', '').strip().split(' ')
 imgfmt = os.environ.get('IMGFMT', 'raw')
 imgproto = os.environ.get('IMGPROTO', 'file')
 test_dir = os.environ.get('TEST_DIR')
+sock_dir = os.environ.get('SOCK_DIR')
 output_dir = os.environ.get('OUTPUT_DIR', '.')
 cachemode = os.environ.get('CACHEMODE')
 qemu_default_machine = os.environ.get('QEMU_DEFAULT_MACHINE')
@@ -445,7 +446,8 @@ class VM(qtest.QEMUQtestMachine):
         name = "qemu%s-%d" % (path_suffix, os.getpid())
         super(VM, self).__init__(qemu_prog, qemu_opts, name=name,
                                  test_dir=test_dir,
-                                 socket_scm_helper=socket_scm_helper)
+                                 socket_scm_helper=socket_scm_helper,
+                                 sock_dir=sock_dir)
         self._num_drives = 0
 
     def add_object(self, opts):
-- 
2.21.0



  parent reply	other threads:[~2019-10-17 13:57 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 13:31 [PATCH v2 00/23] iotests: Add and use $SOCK_DIR Max Reitz
2019-10-17 13:31 ` [PATCH v2 01/23] iotests: Introduce $SOCK_DIR Max Reitz
2019-10-17 14:52   ` Eric Blake
2019-10-18  9:03     ` Max Reitz
2019-10-18 13:30       ` Eric Blake
2019-10-17 13:31 ` Max Reitz [this message]
2019-10-17 13:31 ` [PATCH v2 03/23] iotests.py: Add @base_dir to FilePaths etc Max Reitz
2019-10-17 13:31 ` [PATCH v2 04/23] iotests: Filter $SOCK_DIR Max Reitz
2019-10-17 15:50   ` Thomas Huth
2019-10-17 13:31 ` [PATCH v2 05/23] iotests: Let common.nbd create socket in $SOCK_DIR Max Reitz
2019-10-17 15:52   ` Thomas Huth
2019-10-17 13:31 ` [PATCH v2 06/23] iotests/083: Create " Max Reitz
2019-10-17 13:31 ` [PATCH v2 07/23] iotests/140: " Max Reitz
2019-10-17 13:31 ` [PATCH v2 08/23] iotests/143: " Max Reitz
2019-10-17 13:31 ` [PATCH v2 09/23] iotests/147: " Max Reitz
2019-10-17 13:31 ` [PATCH v2 10/23] iotests/181: " Max Reitz
2019-10-17 13:31 ` [PATCH v2 11/23] iotests/182: " Max Reitz
2019-10-17 13:31 ` [PATCH v2 12/23] iotests/183: " Max Reitz
2019-10-17 13:31 ` [PATCH v2 13/23] iotests/192: " Max Reitz
2019-10-17 15:53   ` Thomas Huth
2019-10-17 13:31 ` [PATCH v2 14/23] iotests/194: Create sockets " Max Reitz
2019-10-17 13:31 ` [PATCH v2 15/23] iotests/201: Create socket " Max Reitz
2019-10-17 15:55   ` Thomas Huth
2019-10-17 13:31 ` [PATCH v2 16/23] iotests/205: " Max Reitz
2019-10-17 15:56   ` Thomas Huth
2019-10-17 13:31 ` [PATCH v2 17/23] iotests/208: " Max Reitz
2019-10-17 13:31 ` [PATCH v2 18/23] iotests/209: " Max Reitz
2019-10-17 13:31 ` [PATCH v2 19/23] iotests/222: " Max Reitz
2019-10-17 13:31 ` [PATCH v2 20/23] iotests/223: " Max Reitz
2019-10-17 15:57   ` Thomas Huth
2019-10-17 13:31 ` [PATCH v2 21/23] iotests/240: " Max Reitz
2019-10-17 15:57   ` Thomas Huth
2019-10-17 13:31 ` [PATCH v2 22/23] iotests/267: " Max Reitz
2019-10-17 15:58   ` Thomas Huth
2019-10-17 13:31 ` [PATCH v2 23/23] iotests: Drop TEST_DIR filter from _filter_nbd Max Reitz
2019-10-17 15:58   ` Thomas Huth
2019-10-17 14:59 ` [PATCH v2 00/23] iotests: Add and use $SOCK_DIR Eric Blake
2019-10-18 16:02 ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191017133155.5327-3-mreitz@redhat.com \
    --to=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).