@@ -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
@@ -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()
@@ -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):
iotests.py itself does not store socket files, but it 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> --- python/qemu/machine.py | 15 ++++++++++++--- python/qemu/qtest.py | 9 ++++++--- tests/qemu-iotests/iotests.py | 4 +++- 3 files changed, 21 insertions(+), 7 deletions(-)