From: Ross Brattain Date: Mon, 21 Aug 2017 05:09:33 +0000 (-0700) Subject: ssh: add new get_file_obj method to fetch remote files X-Git-Tag: opnfv-5.0.RC1~246^2 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=bb3ad3827f02bb27bcc84e191afc27ddd2da38b2;p=yardstick.git ssh: add new get_file_obj method to fetch remote files We can either cat remote files, or we can just sftp get them. use sftp get for /proc/cpuinfo since it can be so very large on systems with 88+ cores. Change-Id: I420b8c5eefdce8bb3e3b13dcc8257583dee537c1 Signed-off-by: Ross Brattain --- diff --git a/yardstick/network_services/helpers/cpu.py b/yardstick/network_services/helpers/cpu.py index a5ba6c31e..8c21754ff 100644 --- a/yardstick/network_services/helpers/cpu.py +++ b/yardstick/network_services/helpers/cpu.py @@ -13,6 +13,9 @@ # limitations under the License. +import io + + class CpuSysCores(object): def __init__(self, connection=""): @@ -20,8 +23,9 @@ class CpuSysCores(object): self.connection = connection def _open_cpuinfo(self): - lines = [] - lines = self.connection.execute("cat /proc/cpuinfo")[1].split(u'\n') + cpuinfo = io.BytesIO() + self.connection.get_file_obj("/proc/cpuinfo", cpuinfo) + lines = cpuinfo.getvalue().decode('utf-8').splitlines() return lines def _get_core_details(self, lines): diff --git a/yardstick/ssh.py b/yardstick/ssh.py index 8ac3eaa3a..a024cf64a 100644 --- a/yardstick/ssh.py +++ b/yardstick/ssh.py @@ -423,6 +423,12 @@ class SSH(object): if mode is not None: sftp.chmod(remotepath, mode) + def get_file_obj(self, remotepath, file_obj): + client = self._get_client() + + with client.open_sftp() as sftp: + sftp.getfo(remotepath, file_obj) + class AutoConnectSSH(SSH): @@ -471,6 +477,10 @@ class AutoConnectSSH(SSH): self._connect() return super(AutoConnectSSH, self).put_file_obj(file_obj, remote_path, mode) + def get_file_obj(self, remote_path, file_obj): + self._connect() + return super(AutoConnectSSH, self).get_file_obj(remote_path, file_obj) + def provision_tool(self, tool_path, tool_file=None): self._connect() return super(AutoConnectSSH, self).provision_tool(tool_path, tool_file)