use qa_config.py instead of config.py
[tests.git] / qaapi / system-test.py
1 #!/usr/bin/python
2 import commands
3 import os
4 import sys
5 from random import Random
6 from time import localtime
7 from qa.utils import commands 
8 from qa.Config import Config 
9 from qa.tests.vserver_create import vserver_create
10 from qa.tests.vserver_delete import vserver_delete
11 from qa.tests.plc_configure import plc_configure
12 from qa.tests.plc_start import plc_start
13 from qa.tests.add_test_data import add_test_data
14 from qa.tests.sync_person_key import sync_person_key
15 from qa.tests.boot_node import boot_node
16 from qa.tests.get_boot_state import get_boot_state
17 from qa.tests.node_remote_call import node_remote_call
18 from qa.tests.access_slice import access_slice
19 random = Random()
20
21 def randint(min = 0.0, max = 1.0):
22     return float(min) + (random.random() * (float(max) - float(min))) 
23
24 # Determine vserver name, distribution and mailto
25 # The distribution and current date will be part of of the vserver name  
26 MAX_VSERVERS =  5
27 VSERVER_HOME = '/vservers/'
28 VSERVER_BASENAME = 'plc'
29 WORKDIR = '/tmp/'
30 SVNPATH='http://svn.planet-lab.org/svn/tests/trunk/'
31 TEST_MODULE = 'qaapi'
32 YEAR, MONTH, DAY = [str(x) for x in localtime()[:3]]
33 DATE = ".".join([YEAR, MONTH, DAY])
34 FCDISTRO = 'f8'  
35 TEST_VSERVER = VSERVER_BASENAME + "-"+ FCDISTRO + "-" + DATE
36 VSERVER_PATH = VSERVER_HOME +os.sep+ TEST_VSERVER
37 MAILTO = 'tmack@cs.princeton.edu'
38 PLCNAME = 'TestPLC'
39
40 # Specify a range of available ports to use. These ports must be 
41 # allowed by the firewall
42 HTTP_PORT_MIN = 51000
43 HTTP_PORT_MAX = 51200
44
45 # Setup configuration 
46 config = Config()
47 config.load("qa/qa_config.py")  
48 config.plcs[PLCNAME]['vserver'] = TEST_VSERVER
49 config.plcs[PLCNAME]['ip'] = config.ip
50 config.plcs[PLCNAME]['api_path'] = ""
51 config.plcs[PLCNAME]['port'] = str(randint(HTTP_PORT_MIN, HTTP_PORT_MAX))
52 config.plcs[PLCNAME].config.update_api(config.plcs[PLCNAME])
53
54
55 # create a vserer for this system test
56 vserver_create(config)(TEST_VSERVER, FCDISTRO, MAILTO)
57
58 # configure the plc in this vserver
59 plc_configure(config)(PLCNAME)
60 plc_start(config)(PLCNAME)
61
62 # Add test site, node, person and slice data
63 # Adds slice to node and person to slice 
64 add_test_data(config)(PLCNAME)
65 person_email = config.persons.values()[0]['email']
66 sync_person_key(config)(person_email)
67
68 # Boot test node and confirm boot state
69 node_hostname = config.nodes.values()[0]['hostname'] 
70 boot_node(config)(node_hostname)
71
72 # remove old vsevers
73 # only keep the newest MAX_VSERVERS 
74 vserver_basepath = "%(VSERVER_HOME)s/%(VSERVER_BASENAME)s" 
75 vservers = os.listdir("%(vserver_basepath)s*" % locals())
76 vservers.sort()
77 vservers.reverse()
78 deleted_vservers = vservers[5:]
79 for vserver in deleted_vservers:
80     utils.header("Deleting vserver: %(vserver)s" % locals())    
81     #vserver_delete()(vserver)
82