- merge from PlanetLab Europe
[plcapi.git] / plctest / TestMain.py
1 #!/usr/bin/env python
2
3 import os, sys, time
4 from optparse import OptionParser
5
6 from TestPlc import TestPlc
7 from TestSite import TestSite
8 from TestNode import TestNode
9 import TestConfig
10 import threading
11 class TestMain:
12
13     subversion_id = "$Id: TestMain.py 767 2007-08-06 08:32:04Z amine $"
14
15     def __init__ (self):
16         self.path=os.path.dirname(sys.argv[0])
17
18     def main (self):
19         try:
20             usage = """usage: %prog [options] MyplcURL"""
21             parser=OptionParser(usage=usage,version=self.subversion_id)
22             # verbosity
23             parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False, 
24                               help="Run in verbose mode")
25             # debug mode
26             parser.add_option("-g","--debug", action="store", dest="debug", 
27                               help="Run in debug mode for eventual virtual problems")
28             #exporting Display
29             parser.add_option("-d","--display", action="store", dest="Xterm", default='bellami:0.0',
30                               help="export the display on the mentionneted one")
31        
32         
33             (self.options, self.args) = parser.parse_args()
34
35             display=''
36             url=''
37             
38            
39             if (len (self.args)):
40                 url=self.args[0]
41                 print 'the myplc url is ',url
42             else:
43                 print "PLease introduce a right URL for the myplc instal"
44                 sys.exit(1)
45
46             if (self.options.Xterm):
47                 display=self.options.Xterm
48                 print 'the display is', display
49
50             if (self.options.debug):
51                 file=self.path+'/'+self.options.debug+'/My_Virtual_Machine.vmx'
52                 if os.path.exists(file):
53                     print 'vmx file is',file
54                     arg='< /dev/null &>/dev/null &'
55                     os.system('DISPLAY=%s vmplayer %s %s '%(display,file,arg))
56                     sys.exit(0)
57                 else:
58                     print "no way to find the virtual file"
59                     sys.exit(1)
60                             
61
62             
63             test_plcs=[]
64             test_nodes=[]
65             pids=[]
66             timset=time.strftime("%H:%M:%S", time.localtime())
67             
68             for plc_spec in TestConfig.plc_specs:
69                 print '========>Creating plc at '+timset+':',plc_spec
70                 test_plc = TestPlc(plc_spec)
71                 test_plc.connect()
72                 test_plcs.append(test_plc)
73                 test_plc.cleanup_plc()
74                 print '========>Installing myplc at: ', timset
75                 if (len(sys.argv) > 1):
76                     test_plc.install_plc(url)
77                     test_plc.config_plc(plc_spec)
78                 else :
79                     print "========>PLease insert a valid url for the myplc install"
80         
81                 for site_spec in plc_spec['sites']:
82                     print '========>Creating site at '+timset+ ':',site_spec
83                     test_site = test_plc.init_site(site_spec)
84                     
85                     for node_spec in site_spec['nodes']:
86                         print '========>Creating node at  '+ timset+' :',node_spec
87                         test_nodes.append(node_spec)
88                         test_node = test_plc.init_node(test_site,node_spec,self.path)
89                         
90                 test_node.create_slice ("pi",test_nodes)
91                 print 'Runing Checkers and Vmwares for Site nodes at :',timset
92                 test_site.run_vmware(test_nodes,display)
93                 if(test_site.node_check_status(test_nodes,True)):
94                     test_plc.db_dump()
95                     test_site.slice_access(test_nodes)
96                     print "all is alright"
97                     return 0
98                     #sys.exit(0)
99                 else :
100                     print "There is something wrong"
101                     sys.exit(1)
102                 
103         except Exception, e:
104             print str(e)
105             sys.exit(1)
106             
107 if __name__ == "__main__":
108     TestMain().main()