summaryrefslogtreecommitdiffstats
path: root/test-framework/vmware/run.py
blob: f025710513a64a82490224e02a7a160b1c39a5ca (plain)
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ConfigParser, datetime, optparse, os, sys
from functools import partial
import cdashreporter, control, ftpsource, source, reporter, utils

def die( msg ):
    sys.stderr( msg + '\n' )
    sys.exit( 1 )
    
optionParser = optparse.OptionParser(usage="%prog [options] configfile installer0 [installer1 ...]", version="%prog 0.1")
optionParser.add_option("-r", "--vmrun", dest="vmrun", help="vmrun executable to use", metavar="VMRUN" )
optionParser.add_option("-s", "--only-since", dest="since", help="test only installers newer than timestamp (YYYY-MM-DD or YYYY-MM-DD-hh-mm)", metavar="SINCE" )
optionParser.add_option("-c", "--checkerInstallation", dest="checkerInstallation", help="checker installation to use for post-installation checks", metavar="CHECKERINSTALLATION" )
(options, args) = optionParser.parse_args()

try:
    configpath = utils.makeAbsolutePath( args[0], os.getcwd() )
except IndexError:
    optionParser.print_usage( sys.stderr )
    sys.exit( 1 )

config = ConfigParser.SafeConfigParser()
config.read( configpath )

#make an unary functor to create absolute paths
abspath = partial( utils.makeAbsolutePath, relativeTo=os.path.dirname( configpath ) )

vmrun = utils.get_config_option( config, options.vmrun, "vmrun", utils.findVMRun() )
useGui = utils.get_config_option( config, None, "gui", "true" ).lower() == "true"
createErrorSnapshots = utils.get_config_option( config, None, "createErrorSnapshots", "true" ).lower() == "true"
hostType = utils.get_config_option( config, None, "type", "", "Host" )
hostLocation = utils.get_config_option( config, None, "location", "", "Host" )
hostUsername = utils.get_config_option( config, None, "username", "", "Host" )
hostPassword = utils.get_config_option( config, None, "password", "", "Host" )

cdashHost = utils.get_config_option( config, None, "host", "", "CDash" )
cdashLocation = utils.get_config_option( config, None, "location", "", "CDash" )
cdashProject = utils.get_config_option( config, None, "project", "", "CDash" )

if vmrun == None:
    die( "Could not find vmrun executable. Please specify it in the config file (vmrun=...) or via the --vmrun option" )

checkerInstallation = utils.get_config_option( config, options.checkerInstallation, "checkerInstallation" )
if checkerInstallation == None:
    die( "Could not find checker installation. Please specify it in the config file (checkerInstallation=...) or via the --checkerInstallation option" )

#apply functor to list to get absolute paths:
testcases = map( abspath, utils.get_enumerated_config_option( config, 'testcase' ) )
if len( testcases ) == 0:
    die( "No testcases specified. Please specify at least one test case in the configuration" )

vms = map( abspath, utils.get_enumerated_config_option( config, 'vm' ) )
if len( vms ) == 0:
    die( "No VMs specified. Please specify at least one VM in the configuration" )
    
installers = args[1:]

if len( installers ) > 0:
    source = source.Source()
    for i in installers:
        source.addDummy( 5, i )
else:
    source = ftpsource.FtpSource()
    if options.since:
        try:
            sdt = datetime.datetime.strptime( options.since, '%Y-%m-%d' )
        except ValueError:
            sdt = datetime.datetime.strptime( options.since, '%Y-%m-%d-%H-%M' )
        source.setStartDate( sdt )
    found = True
    nextsec = 0
    while found:
        sec = "Source{0}".format( nextsec )
        nextsec += 1
        try:
            host = config.get( sec, "host" )
            path = config.get( sec, "path" )
            platform = config.get( sec, "platform" )
            print( "** Add FTP location {0}:{1} ({2})".format( host, path, platform ) )
            source.addLocation( host, path, platform )
        except ConfigParser.NoSectionError:
            found = False
             
cdashHost = utils.get_config_option( config, None, "host", "", "CDash" )
cdashLocation = utils.get_config_option( config, None, "location", "", "CDash" )
cdashProject = utils.get_config_option( config, None, "project", "", "CDash" )

if len( cdashHost ) > 0:
    reporter = cdashreporter.CDashReporter( cdashHost, cdashLocation, cdashProject )
else:
    reporter = reporter.Reporter()
    
control = control.Control( vmrun, checkerInstallation, source, reporter )
control.setGuiEnabled( useGui )
control.setCreateErrorSnapshots( createErrorSnapshots )

if len( hostType ) > 0:
    control.setRemoteHost( hostType, hostLocation, hostUsername, hostPassword )

for i in vms:
    control.addVM( i )
for i in testcases:
    control.addTestCase( i )

control.run()