check locality more appropriately
[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 utils
5
6 class TestBox:
7
8     def __init__(self,hostname,key=None):
9         self.hostname=hostname
10         self.key=key
11
12     def is_local(self):
13         return utils.is_local (self.hostname)
14
15     def run (self,command):
16         if self.is_local():
17             return utils.system(command)
18         else:
19             if self.key:
20                 to_run="ssh -i %s.rsa %s %s"%(self.key,self.hostname,
21                                               utils.backslash_shell_specials(command))
22             else:
23                 to_run="ssh %s %s"%(self.hostname,
24                                     utils.backslash_shell_specials(command))
25             return utils.system(to_run)
26         
27     def copy (self,local_file):
28         if self.is_local():
29             return 0
30         else:
31             if self.key:
32                 to_run="scp -i %s.rsa %s %s:"%(self.key,local_file,self.hostname)
33             else:
34                 to_run="scp %s %s:"%(local_file,self.hostname)
35             return utils.system(to_run)
36         
37     def kill_all_qemus(self):
38         self.run("killall qemu")
39