[KVM-AUTOTEST PATCH v2 2/4] KVM test: add boolean 'testdev' VM parameter for RHEL-6 style unit tests

Michael Goldish
2010-06-08T21:50:42Z

Should be set to "yes" to enable testdev.

Signed-off-by: Michael Goldish <mgoldish@redhat.com>
---
client/tests/kvm/kvm_vm.py | 28 ++++++++++++++++++++--------
1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/client/tests/kvm/kvm_vm.py b/client/tests/kvm/kvm_vm.py
index f3c05f3..af45a81 100755
--- a/client/tests/kvm/kvm_vm.py
+++ b/client/tests/kvm/kvm_vm.py
@@ -118,12 +118,16 @@ class VM:

# Find available monitor filename
while True:
- # The monitor filename should be unique
+ # A unique identifier for this VM
self.instance = (time.strftime("%Y%m%d-%H%M%S-") +
kvm_utils.generate_random_string(4))
- self.monitor_file_name = os.path.join("/tmp",
- "monitor-" + self.instance)
- if not os.path.exists(self.monitor_file_name):
+ # Monitor
+ self.monitor_file_name = "/tmp/monitor-" + self.instance
+ # Test log for unit tests
+ self.testlog_file_name = "/tmp/testlog-" + self.instance
+ # Verify uniqueness
+ if True not in map(os.path.exists, [self.monitor_file_name,
+ self.testlog_file_name]):
break

@@ -274,6 +278,10 @@ class VM:
def add_kernel_cmdline(help, cmdline):
return " -append %s" % cmdline

+ def add_testdev(help, filename):
+ return (" -chardev file,id=testlog,path=%s"
+ " -device testdev,chardev=testlog" % filename)
+
# End of command line option wrappers

if name is None: name = self.name
@@ -393,6 +401,9 @@ class VM:
elif params.get("uuid"):
qemu_cmd += add_uuid(help, params.get("uuid"))

+ if params.get("testdev") == "yes":
+ qemu_cmd += add_testdev(help, self.testlog_file_name)
+
# If the PCI assignment step went OK, add each one of the PCI assigned
# devices to the qemu command line.
if self.pci_assignable:
@@ -728,10 +739,11 @@ class VM:
self.pci_assignable.release_devs()
if self.process:
self.process.close()
- try:
- os.unlink(self.monitor_file_name)
- except OSError:
- pass
+ for f in [self.monitor_file_name, self.testlog_file_name]:
+ try:
+ os.unlink(f)
+ except OSError:
+ pass

def is_alive(self):
--
1.5.4.1