first step towards using testbox properly
[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 run_in_buildname (self,command):
22         if self.is_local():
23             return utils.system(command)
24         ssh_comand="ssh "
25         if self.key:
26             ssh_comand += "-i %s.rsa "%(self.key)
27         ssh_command += "%s/%s"%(self.buildname,utils.backslash_shell_specials(command))
28         return utils.system(ssh_command)
29         
30     # should use rsync instead
31     def copy (self,local_file,recursive=False):
32         if self.is_local():
33             return 0
34         command="scp "
35         if recursive: command += "-r "
36         if self.key:
37             command += "-i %s.rsa "
38         command +="%s %s:%s/%s"%(local_file,self.hostname(),self.buildname,
39                                  os.path.basename(local_file) or ".")
40         return utils.system(command)
41         
42     def clean_dir (self):
43         if self.is_local():
44             return 0
45         return utils.system("rm -rf %s"%self.buildname)            
46
47     def mkdir (self):
48         if self.is_local():
49             return 0
50         return utils.system("mkdir %s"%self.buildname)            
51
52     def kill_all_qemus(self):
53         self.run_in_buildname("killall qemu")
54