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)
23 except Exception as e:
26 def create_test_ssh(self):
27 private_key = self.test_slice.locate_private_key()
29 raise Exception("Cannot find the private key for slice {}".format(self.test_slice.name()))
30 return TestSsh(self.test_node.name(), key=private_key, username=self.test_slice.name(),
31 # so that copies end up in the home dir
35 return "{}@{}".format(self.test_slice.name(), self.test_node.name())
37 def check_initscript_stamp(self, stamp):
38 utils.header("Checking for initscript stamp {} on sliver {}".format(stamp, self.name()))
39 return self.test_ssh.run("ls -l /var/tmp/{}.stamp".format(stamp)) == 0
41 def check_tcp_ready(self, port):
42 ready_command = "./tcptest.py ready -p {}".format(port)
43 return self.test_ssh.copy("tcptest.py") == 0 and \
44 self.test_ssh.run(ready_command) == 0
46 def run_tcp_server(self, servername, port, timeout=10):
47 server_command = "./tcptest.py server -a {} -p {} -t {}"\
48 .format(servername, port, timeout)
49 return self.test_ssh.copy("tcptest.py") == 0 and \
50 self.test_ssh.run(server_command, background=True) == 0
52 def run_tcp_client(self, servername, port, retry=5):
53 client_command = "./tcptest.py client -a {} -p {}"\
54 .format(servername, port)
55 if self.test_ssh.copy("tcptest.py") != 0:
57 if self.test_ssh.run(client_command) == 0:
61 # use the node's main ssh root entrance, as the slice entrance might be down
62 #def tar_var_logs(self):
63 # return self.test_ssh.actual_command("sudo tar -C /var/log -cf - .")
64 def tar_var_logs(self):
65 test_ssh = self.test_node.create_test_ssh()
66 dir_to_tar = "/vservers/{}/var/log".format(self.test_slice.name())
67 return test_ssh.actual_command("tar -C {} -cf - .".format(dir_to_tar))
69 def check_hooks(self):
70 print('NOTE: slice hooks check scripts NOT (yet?) run in sudo')
71 extensions = [ 'py','pl','sh' ]
73 scripts = utils.locate_hooks_scripts('sliver '+self.name(), path,extensions)
75 for script in scripts:
76 if not self.check_hooks_script(script):
80 def check_hooks_script(self,local_script):
81 script_name = os.path.basename(local_script)
82 utils.header("SLIVER hook {} ({})".format(script_name, self.name()))
83 test_ssh = self.create_test_ssh()
84 test_ssh.copy_home(local_script)
85 if test_ssh.run("./"+script_name) != 0:
86 utils.header("WARNING: hooks check script {} FAILED (ignored)".format(script_name))
90 utils.header("SUCCESS: sliver hook {} OK".format(script_name))