1 # Thierry Parmentelat <thierry.parmentelat@inria.fr>
2 # Copyright (C) 2010 INRIA
8 from TestSsh import TestSsh
12 def __init__ (self,test_plc,test_node,test_slice):
13 self.test_plc=test_plc
14 self.test_node=test_node
15 self.test_slice=test_slice
16 self.test_ssh = self.create_test_ssh()
18 def get_privateKey(self):
19 slice_spec=self.test_slice.slice_spec
21 (found,privatekey)=self.test_slice.locate_key()
22 return (found,privatekey)
26 def create_test_ssh(self):
27 (found,privatekey) = self.get_privateKey()
29 raise Exception,"Cannot find the private key for slice %s"%self.test_slice.name()
30 return TestSsh (self.test_node.name(),key=privatekey,username=self.test_slice.name(),
31 # so that copies end up in the home dir
35 return "%s@%s"%(self.test_slice.name(),self.test_node.name())
37 def check_initscript(self,initscript):
38 slice_spec=self.test_slice.slice_spec
39 initscript = slice_spec['initscriptname']
40 utils.header("Checking initscript %s on sliver %s"%(initscript,self.name()))
41 return self.test_ssh.run("ls -l /tmp/%s.stamp"%initscript)==0
43 def run_tcp_server (self,port,timeout=10):
44 server_command = "./tcptest.py server -p %d -t %d"%(port,timeout)
45 return self.test_ssh.copy("tcptest.py")==0 and \
46 self.test_ssh.run(server_command,background=True)==0
48 def run_tcp_client (self,servername,port):
49 client_command="./tcptest.py client -a %s -p %d"%(servername,port)
50 return self.test_ssh.copy("tcptest.py")==0 and \
51 self.test_ssh.run(client_command,background=True)==0
53 # use the node's main ssh root entrance, as the slice entrance might be down
54 #def tar_var_logs (self):
55 # return self.test_ssh.actual_command("sudo tar -C /var/log -cf - .")
56 def tar_var_logs (self):
57 test_ssh=self.test_node.create_test_ssh()
58 dir_to_tar="/vservers/%s/var/log"%self.test_slice.name()
59 return test_ssh.actual_command("tar -C %s -cf - ."%dir_to_tar)
61 def check_hooks (self):
62 print 'NOTE: slice hooks check scripts NOT (yet?) run in sudo'
63 extensions = [ 'py','pl','sh' ]
65 scripts=utils.locate_hooks_scripts ('sliver '+self.name(), path,extensions)
67 for script in scripts:
68 if not self.check_hooks_script (script):
72 def check_hooks_script (self,local_script):
73 script_name=os.path.basename(local_script)
74 utils.header ("SLIVER hook %s (%s)"%(script_name,self.name()))
75 test_ssh=self.create_test_ssh()
76 test_ssh.copy_home(local_script)
77 if test_ssh.run("./"+script_name) != 0:
78 utils.header ("WARNING: hooks check script %s FAILED (ignored)"%script_name)
82 utils.header ("SUCCESS: sliver hook %s OK"%script_name)