b2f6ab2f758714db842f06528c2f1c37be8acff6
[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 import utils
6 from TestSsh import TestSsh
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         self.test_ssh=TestSsh(self)
15         
16     def hostname (self):
17         return self.hostname_value
18
19     def is_local(self):
20         return TestSsh.is_local (self.hostname())
21     
22     def tar_logs(self):
23         if os.path.isdir("nodeslogs"):
24             tar_command="tar cvf nodeslogs.tar nodeslogs/"
25             self.run_in_buildname (tar_command)
26             return True
27         return False
28     
29     def run_in_buildname (self,command):
30         return self.test_ssh.run_in_buildname (command)
31     # should use rsync instead
32     def copy (self,local_file,recursive=False):
33         return self.test_ssh.copy (local_file,recursive=False)
34         
35     def clean_dir (self):
36         if self.is_local():
37             return 0
38         return utils.system("rm -rf %s"%self.buildname)            
39
40     def mkdir (self):
41         if self.is_local():
42             return 0
43         return utils.system("mkdir %s"%self.buildname)            
44
45     def kill_all_qemus(self):
46         self.run_in_buildname("killall qemu")
47