stores url in URL for next runs - boot from cdrom first - intermediate confif file...
[tests.git] / system / TestMain.py
1 #!/usr/bin/env python
2 # $Id$
3
4 import os, sys, time
5 from optparse import OptionParser
6 from TestPlc import TestPlc
7 from TestSite import TestSite
8 from TestNode import TestNode
9 import TestConfig
10 import threading
11
12 class TestMain:
13
14     subversion_id = "$Id$"
15
16     def __init__ (self):
17         self.path=os.path.dirname(sys.argv[0])
18
19     def main (self):
20         try:
21             usage = """usage: %prog [options] [myplc-url]
22 myplc-url defaults to the last value used, as stored in URL"""
23             parser=OptionParser(usage=usage,version=self.subversion_id)
24             # verbosity
25             parser.add_option("-v","--verbose", action="store_true", dest="verbose", default=False, 
26                               help="Run in verbose mode")
27             # debug mode
28             parser.add_option("-g","--debug", action="store", dest="debug", 
29                               help="Run in debug mode for eventual virtual problems")
30             #exporting Display
31             parser.add_option("-d","--display", action="store", dest="Xterm", default='bellami:0.0',
32                               help="export the display on the mentionneted one")
33         
34             (self.options, self.args) = parser.parse_args()
35
36             display=''
37             url=''
38             test_plcs=[]
39             test_nodes=[]
40             pids=[]
41             timset=time.strftime("%H:%M:%S", time.localtime())
42             #test the existence of the URL
43             if (len (self.args) > 2):
44                 parser.print_help()
45                 sys.exit(1)
46             else if (len (self.args) == 1):
47                 url=self.args[0]
48             else:
49                 try:
50                     url=open("%s/URL"%self.path)
51                     url=url_file.read().strip()
52                     url_file.close()
53                 except:
54                     print "Cannot determine myplc url"
55                     parser.print_help()
56                     sys.exit(1)
57             print '* Using myplc url:',url
58             #check where to display Virtual machines
59             if (self.options.Xterm):
60                 display=self.options.Xterm
61                 print 'the display is', display
62             #the debug option 
63             if (self.options.debug):
64                 file=self.path+'/'+self.options.debug+'/My_Virtual_Machine.vmx'
65                 if os.path.exists(file):
66                     print 'vmx file is',file
67                     arg='< /dev/null &>/dev/null &'
68                     os.system('DISPLAY=%s vmplayer %s %s '%(display,file,arg))
69                     sys.exit(0)
70                 else:
71                     print "no way to find the virtual file"
72                     sys.exit(1)
73             
74             print 'Saving myplc url into URL'
75             fsave=open('%s/URL'%self.path,"w")
76             fsave.write(url)
77             fsave.write('\n')
78             fsave.close()
79
80             for plc_spec in TestConfig.plc_specs:
81                 print '========>Creating plc at '+timset+':',plc_spec
82                 test_plc = TestPlc(plc_spec)
83                 test_plc.connect()
84                 test_plcs.append(test_plc)
85                 test_plc.cleanup_plc()
86                 print '========>Installing myplc at: ', timset
87                 if (len(sys.argv) > 1):
88                     test_plc.install_plc(url)
89                     test_plc.config_plc(plc_spec)
90                 else :
91                     print "========>PLease insert a valid url for the myplc install"
92                 ##create all the sites under the new plc,and then populate them with
93                 ##nodes,persons and slices
94                 for site_spec in plc_spec['sites']:
95                     print '========>Creating site at '+timset+ ':',site_spec
96                     test_site = test_plc.init_site(site_spec)
97                     for node_spec in site_spec['nodes']:
98                         print '========>Creating node at  '+ timset+' :',node_spec
99                         test_nodes.append(node_spec)
100                         test_node = test_plc.init_node(test_site,node_spec,self.path)
101                 test_node.create_slice ("pi")
102                 print 'Runing Checkers and Vmwares for Site nodes at :',timset
103                 test_site.run_vmware(test_nodes,display)
104                 if(test_site.node_check_status(test_nodes,True)):
105                     test_plc.db_dump()
106                     test_site.slice_access(test_nodes)
107                     print "all is alright"
108                     return 0
109                 else :
110                     print "There is something wrong"
111                     sys.exit(1)
112         except Exception, e:
113             print str(e)
114             sys.exit(1)
115             
116 if __name__ == "__main__":
117     TestMain().main()