fine-grain & brute force qemu kill (kill_qemus and kill_all_qemus)
[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 run (self,command):
13         if self.hostname == "localhost":
14             return utils.system(command)
15         else:
16             if self.key:
17                 to_run="ssh -i %s.rsa %s %s"%(self.key,self.hostname,
18                                               utils.backslash_shell_specials(command))
19             else:
20                 to_run="ssh %s %s"%(self.hostname,
21                                     utils.backslash_shell_specials(command))
22             return utils.system(to_run)
23         
24     def copy (self,local_file):
25         if self.hostname == "localhost":
26             return 0
27         else:
28             if self.key:
29                 to_run="scp -i %s.rsa %s %s:"%(self.key,local_file,self.hostname)
30             else:
31                 to_run="scp %s %s:"%(local_file,self.hostname)
32             return utils.system(to_run)
33         
34     def kill_all_qemus(self):
35         self.run("killall qemu")
36