- merge from PlanetLab Europe
[plcapi.git] / plctest / TestPlc.py
1 import os
2 import sys
3 import xmlrpclib
4 import datetime
5 from TestSite import TestSite
6 from TestNode import TestNode
7
8 class TestPlc:
9
10     def __init__ (self,plc_spec):
11         self.plc_spec=plc_spec
12         self.url="https://%s:443/PLCAPI/"%plc_spec['hostname']
13         self.server=xmlrpclib.Server(self.url,allow_none=True)
14         self.path=os.path.dirname(sys.argv[0])
15         
16     def connect (self):
17         # tricky : define les methodes de l'API sur cet object
18         pass
19     
20     def auth_root (self):
21         return {'Username':self.plc_spec['PLC_ROOT_USER'],
22                 'AuthMethod':'password',
23                 'AuthString':self.plc_spec['PLC_ROOT_PASSWORD'],
24                 'Role' : self.plc_spec['role']
25                 }
26     def affiche_results(self, test_case_name, status, timers):
27         timers=datetime.datetime.now()
28         fileHandle = open (self.path+'/results.txt', 'a' )
29         fileHandle.write ( str(test_case_name)+'                    ' +str(status)+'                    '+str(timers))
30         fileHandle.close()
31
32         
33
34     def config_plc(self,plc_spec):
35 # Thierry 2007-07-05 
36 # now plc-config-tty silently creates needed directories
37 #        os.system('mkdir -p /etc/planetlab/configs')
38
39         fileconf=open('tty_conf','w')
40         for var in [ 'PLC_NAME',
41                      'PLC_ROOT_PASSWORD',
42                      'PLC_ROOT_USER',
43                      'PLC_MAIL_ENABLED',
44                      'PLC_MAIL_SUPPORT_ADDRESS',
45                      'PLC_DB_HOST',
46                      'PLC_API_DEBUG',
47                      'PLC_API_HOST',
48                      'PLC_WWW_HOST',
49                      'PLC_BOOT_HOST',
50                      'PLC_NET_DNS1',
51                      'PLC_NET_DNS2']:
52             fileconf.write ('e %s\n%s\n'%(var,plc_spec[var]))
53         fileconf.write('w\n')
54         fileconf.write('q\n')
55         fileconf.close()
56         os.system('set -x ; cat tty_conf')
57         os.system('set -x ; chroot /plc/root  plc-config-tty < tty_conf')
58         os.system('set -x ; service plc start')
59         os.system('set -x; service sendmail stop')
60         os.system('set -x; chroot /plc/root service sendmail restart')
61         
62     def cleanup_plc(self):
63         os.system('service plc safestop')
64         #####detecting the last myplc version installed and remove it
65         os.system('set -x; rpm -e myplc')
66         print "=======================>Remove Myplc DONE!"
67         ##### Clean up the /plc directory
68         os.system('set -x; rm -rf  /plc/data')
69         print "=======================>Clean up  DONE!"
70
71
72         
73     def install_plc(self,url):
74         print url
75         os.system('set -x; rpm -ivh '+url)
76         os.system('set -x; service plc mount')
77       
78     def init_site (self,site_spec):
79         test_site = TestSite (self,site_spec)
80         test_site.create_site()
81         for key in ['pi_spec','tech_spec','user_spec','tech_user_spec','pi_tech_spec']:
82             test_site.create_user(site_spec[key])
83             test_site.enable_user(site_spec[key])
84             test_site.add_key_user(site_spec[key])            
85         return test_site
86
87     def init_node (self,test_site,node_spec,path):
88
89         test_node = TestNode(self, test_site, node_spec)
90         test_node.create_node ("pi")
91         test_node.create_node ("tech")
92         test_node.create_boot_cd(node_spec,path)
93        
94
95         return test_node
96
97     
98     def db_dump(self):
99         
100         t=datetime.datetime.now()
101         d=t.date()
102         dump='/var/lib/pgsql/backups/planetlab4-'+str(d)+'-2nodes'
103         os.system('chroot /plc/root pg_dump -U pgsqluser planetlab4 -f '+ dump)
104         print 'dump is done',dump
105         
106
107