Fix issue with kill_controller not working in certain environments
[integration/test.git] / test / tools / clustering / cluster-deployer / remote_host.py
1 # remote_host.py
2 #
3 #
4 # The RemoteHost class provides methods to do operations on a remote host
5 #
6
7 from SSHLibrary import SSHLibrary
8
9
10 class RemoteHost:
11     def __init__(self, host, user, password, rootdir):
12         self.host = host
13         self.user = user
14         self.password = password
15         self.rootdir = rootdir
16
17     def exec_cmd(self, command):
18         print "Executing command " + command + " on host " + self.host
19         lib = SSHLibrary()
20         lib.open_connection(self.host)
21         lib.login(username=self.user, password=self.password)
22         rc = lib.execute_command(command, return_rc=True)
23         lib.close_connection()
24         if rc[1] != 0:
25             raise Exception('remote command failed [{0}] with exit code {1}'.format(command, rc))
26
27     def mkdir(self, dir_name):
28         self.exec_cmd("mkdir -p " + dir_name)
29
30     def copy_file(self, src, dest):
31         lib = SSHLibrary()
32         lib.open_connection(self.host)
33         lib.login(username=self.user, password=self.password)
34         print "Copying " + src + " to " + dest + " on " + self.host
35         lib.put_file(src, dest)
36         lib.close_connection()
37
38     def kill_controller(self):
39         self.exec_cmd("sudo ps axf | grep karaf | grep -v grep | awk '{print \"kill -9 \" $1}' | sudo sh")
40
41     def start_controller(self, dir_name):
42         self.exec_cmd(dir_name + "/odl/bin/start")