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