*Manage nodes log files into a .tar
[tests.git] / system / TestBox.py
1 # $Id$
2 # this models a box that hosts qemu nodes
3 # could probably also be used for boxes that host plc instances
4 import os.path
5
6 import utils
7
8 class TestBox:
9
10     def __init__(self,hostname,buildname,key=None):
11         self.hostname_value=hostname
12         self.buildname=buildname
13         self.key=key
14
15     def hostname (self):
16         return self.hostname_value
17
18     def is_local(self):
19         return utils.is_local (self.hostname())
20     
21     def tar_logs(self):
22         if os.path.isdir("nodeslogs"):
23             tar_command="tar cvf nodeslogs.tar nodeslogs/ && rm -rf nodeslogs"
24             self.run_in_buildname (tar_command)
25             return True
26         return False
27     
28     def run_in_buildname (self,command):
29         if self.is_local():
30             return utils.system(command)
31         ssh_comand="ssh "
32         if self.key:
33             ssh_comand += "-i %s.rsa "%(self.key)
34         ssh_command += "%s/%s"%(self.buildname,utils.backslash_shell_specials(command))
35         return utils.system(ssh_command)
36         
37     # should use rsync instead
38     def copy (self,local_file,recursive=False):
39         if self.is_local():
40             return 0
41         command="scp "
42         if recursive: command += "-r "
43         if self.key:
44             command += "-i %s.rsa "
45         command +="%s %s:%s/%s"%(local_file,self.hostname(),self.buildname,
46                                  os.path.basename(local_file) or ".")
47         return utils.system(command)
48         
49     def clean_dir (self):
50         if self.is_local():
51             return 0
52         return utils.system("rm -rf %s"%self.buildname)            
53
54     def mkdir (self):
55         if self.is_local():
56             return 0
57         return utils.system("mkdir %s"%self.buildname)            
58
59     def kill_all_qemus(self):
60         self.run_in_buildname("killall qemu")
61