5
from commands import getstatusoutput
8
from abrek.utils import geturl
10
class AbrekTest(object):
12
This can be used by test definition files to create an object that
13
contains the building blocks for installing tests, running them,
14
and parsing the results.
16
testname - name of the test or test suite
17
version - version of the test or test suite
18
installer - AbrekInstaller instance to use
19
runner - AbrekRunner instance to use
20
parser - AbrekParser instance to use
23
def __init__(self, testname, version="", installer=None, runner=None,
25
self.config = abrek.config.AbrekConfig()
26
self.testname = testname
27
self.version = version
28
self.installer = installer
31
self.origdir = os.path.abspath(os.curdir)
35
Install the test suite. This creates an install directory under
36
the user's XDG_DATA_HOME directory to mark that the test is installed.
37
The installer's install() method is then called from this directory
38
to complete any test specific install that may be needed.
41
path = os.path.join(self.config.installdir, self.testname)
42
if os.path.exists(path):
43
raise RuntimeError, "%s is already installed" % self.testname
46
rc = self.installer.install()
49
raise RuntimeError, "An error was detected during", \
50
"installation, cleaning up"
54
Uninstalling just recursively removes the test specific directory
55
under the user's XDG_DATA_HOME directory. This will both mark
56
the test as removed, and clean up any files that were downloaded
57
or installed under that directory. Dependencies are intentionally
60
os.chdir(self.origdir)
61
path = os.path.join(self.config.installdir, self.testname)
62
if os.path.exists(path):
67
return self.runner.run()
69
def parse(self,results):
71
return self.parser.parse(results)
73
class AbrekTestInstaller(object):
75
Base class for defining an installer object. This class can be used
76
as-is for simple installers, or extended for more advanced funcionality.
78
steps - list of steps to be executed in a shell
79
deps - list of dependencies to apt-get install before running the steps
80
url - location from which the test suite should be downloaded
81
md5 - md5sum to check the integrety of the download
84
def __init__(self, steps=[], deps=[], url="", md5="", **kwargs):
90
def _installdeps(self):
93
cmd = "sudo apt-get install %s", " ".join(self.deps)
94
rc,output = getstatusoutput(cmd)
96
raise RuntimeError, "Dependency installation failed"
100
Download the file specified by the url and check the md5.
101
Return the path and filename if successful, otherwise return None
105
filename = geturl(self.url)
106
#If the file does not exist, then the download was not successful
107
if not os.path.exists(filename):
110
checkmd5 = hashlib.md5()
111
with open(filename, 'rb') as fd:
112
for data in fd.read(0x10000):
113
checkmd5.update(data)
114
if checkmd5.hexdigest() != self.md5:
115
raise RuntimeError, "Unexpected md5sum downloading %s" % \
121
for cmd in self.steps:
122
rc,output = getstatusoutput(cmd)
129
def testloader(testname):
131
Load the test definition, which can be either an individual
132
file, or a directory with an __init__.py
134
importpath = "abrek.test_definitions.%s" % testname
136
mod = __import__(importpath)
138
print "unknown test '%s'" % testname
140
for i in importpath.split('.')[1:]:
143
base = mod.testdir.testobj
144
except AttributeError: