aboutsummaryrefslogtreecommitdiff
path: root/python/qemu
diff options
context:
space:
mode:
Diffstat (limited to 'python/qemu')
-rw-r--r--python/qemu/machine.py15
-rw-r--r--python/qemu/qtest.py9
2 files changed, 18 insertions, 6 deletions
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 128a3d1..2024e8b 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 3f1d2cb..d24ad04 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()