remote_host.py: re-use ssh session across commands 46/23246/3
authorGary Wu <Gary.Wu1@huawei.com>
Wed, 24 Jun 2015 17:19:40 +0000 (10:19 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 29 Jun 2015 21:58:15 +0000 (21:58 +0000)
Refactored remote_host.py to re-use a single ssh
connection to each cluster node for multiple
shell commands, instead of creating a separate
ssh connection for each command to be executed.
This reduces the delays experienced in the ssh
connection startup.

Change-Id: I74395ed3f2a90f6fc3fef1a509f48f9bcba7aff4
Signed-off-by: Gary Wu <Gary.Wu1@huawei.com>
(cherry picked from commit 14c6191d72fb8e11259baf6f009833b8d2155f25)

test/tools/clustering/cluster-deployer/remote_host.py

index bae137b82a6fcf9f067ebaf09a4d636443df17d1..04f334ae29e32c72a2a027eb2cc85242f329e404 100644 (file)
@@ -15,14 +15,16 @@ class RemoteHost:
         self.user = user
         self.password = password
         self.rootdir = rootdir
+        self.lib = SSHLibrary()
+        self.lib.open_connection(self.host)
+        self.lib.login(username=self.user, password=self.password)
+
+    def __del__(self):
+        self.lib.close_connection()
 
     def exec_cmd(self, command):
         print "Executing command " + command + " on host " + self.host
-        lib = SSHLibrary()
-        lib.open_connection(self.host)
-        lib.login(username=self.user, password=self.password)
-        rc = lib.execute_command(command, return_rc=True)
-        lib.close_connection()
+        rc = self.lib.execute_command(command, return_rc=True)
         if rc[1] != 0:
             raise Exception('remote command failed [{0}] with exit code {1}'
                             .format(command, rc))
@@ -39,12 +41,8 @@ class RemoteHost:
             print "Src file " + src + " was not found"
             return
 
-        lib = SSHLibrary()
-        lib.open_connection(self.host)
-        lib.login(username=self.user, password=self.password)
         print "Copying " + src + " to " + dest + " on " + self.host
-        lib.put_file(src, dest)
-        lib.close_connection()
+        self.lib.put_file(src, dest)
 
     def kill_controller(self):
         self.exec_cmd("sudo ps axf | grep karaf | grep -v grep "