forked from autotest/autotest-client-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libvirt_tck.py
118 lines (91 loc) · 3.76 KB
/
libvirt_tck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import re
import shutil
import logging
from autotest.client.shared import error
from autotest.client import utils, test
class libvirt_tck(test.test):
"""
Autotest wrapper for the libvirt Technology Compatibility toolkit.
The libvirt TCK provides a framework for performing testing
of the integration between libvirt drivers, the underlying virt
hypervisor technology, related operating system services and system
configuration. The idea (and name) is motivated by the Java TCK.
@see: git clone git://libvirt.org/libvirt-tck.git
@author: Daniel Berrange <[email protected]>
"""
version = 1
TESTDIR = '/usr/share/libvirt-tck/tests'
def setup(self, tarball='Sys-Virt-TCK-v0.1.0.tar.gz'):
# The absence of Module::Build will hange up the testing
try:
utils.system('perl -MModule::Build -e 1')
except error.CmdError, e:
raise error.TestError("Module::Build is required")
# Install cpanminus script
try:
utils.system('(curl -L http://cpanmin.us | perl - App::cpanminus)2>&1')
except error.CmdError, e:
raise error.TestError("Failed to install cpanminus script.")
tarpath = utils.unmap_url(self.bindir, tarball)
utils.extract_tarball_to_dir(tarpath, self.srcdir)
os.chdir(self.srcdir)
output = utils.system_output('perl Makefile.PL 2>&1', retain_output=True)
required_mods = list(set(re.findall("[^ ']*::[^ ']*", output)))
# Resolve perl modules dependencies
if required_mods:
for mod in required_mods:
ret = utils.system('cpanm %s 2>&1' % mod)
if ret != 0:
raise error.TestError("Failed to install module %s" % mod)
utils.system('make')
utils.system('make test')
utils.system('make install')
def get_testcases(self, testcasecfg, item):
flag = 0
testcases = []
fh = open(testcasecfg, "r")
for eachLine in fh:
line = eachLine.strip()
if line.startswith('#'):
continue
if flag == 0 and not line:
continue
if item == line[:-1]:
flag = 1
continue
if flag == 1 and not line:
flag = 0
break
if flag == 1 and line[0].isdigit():
testcases.append(line)
continue
fh.close()
return testcases
def run_once(self, item=None):
failed_tests = []
if item is None:
raise error.TestError("No item provided")
default_cfg = os.path.join(self.bindir, 'default.cfg')
ks_cfg = os.path.join(self.bindir, 'ks.cfg')
testcase_cfg = os.path.join(self.bindir, 'testcase.cfg')
item_path = os.path.join(self.TESTDIR, item)
testcases = self.get_testcases(testcase_cfg, item)
shutil.copyfile(ks_cfg, '/etc/libvirt-tck/ks.cfg')
logging.debug("Available testcases for item %s: %s", item, testcases)
output = os.path.join(self.resultsdir, 'libvirt_tck_%s.tap' % item)
for testcase in testcases:
testcase_path = os.path.join(item_path, testcase)
os.environ['LIBVIRT_TCK_CONFIG'] = default_cfg
t_cmd = ('perl %s' % testcase_path)
try:
try:
t_output = open(output, 'a+')
cmd_result = utils.run(t_cmd, stdout_tee=t_output,
stderr_tee=t_output)
finally:
t_output.close()
except error.CmdError:
failed_tests.append(testcase)
if failed_tests:
raise error.TestFail('FAIL: %s' % failed_tests)