aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/ssh.py
diff options
context:
space:
mode:
authorRex Lee <limingjiang@huawei.com>2016-12-05 06:38:48 +0000
committerGerrit Code Review <gerrit@opnfv.org>2016-12-05 06:38:48 +0000
commitce64e77f9e97d3cad4be9c8fee068a2a5b557f3e (patch)
tree733ebff663568e521f0ccf40c4bbad58b3caa5e0 /yardstick/ssh.py
parentcee61dec722722c76d71d32fe56ad877c08e1d36 (diff)
parentbcb8ace09d7ebb80d2430bceb8fbfa0ce71959a9 (diff)
Merge "fix SSH object examples to use correct context manager form"
Diffstat (limited to 'yardstick/ssh.py')
-rw-r--r--yardstick/ssh.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/yardstick/ssh.py b/yardstick/ssh.py
index b9d9262cf..46d53b7d2 100644
--- a/yardstick/ssh.py
+++ b/yardstick/ssh.py
@@ -29,24 +29,29 @@ Execute command and get output:
Execute command with huge output:
- class PseudoFile(object):
+ class PseudoFile(io.RawIOBase):
def write(chunk):
if "error" in chunk:
email_admin(chunk)
- ssh = sshclient.SSH("root", "example.com")
- ssh.run("tail -f /var/log/syslog", stdout=PseudoFile(), timeout=False)
+ ssh = SSH("root", "example.com")
+ with PseudoFile() as p:
+ ssh.run("tail -f /var/log/syslog", stdout=p, timeout=False)
Execute local script on remote side:
ssh = sshclient.SSH("user", "example.com")
- status, out, err = ssh.execute("/bin/sh -s arg1 arg2",
- stdin=open("~/myscript.sh", "r"))
+
+ with open("~/myscript.sh", "r") as stdin_file:
+ status, out, err = ssh.execute('/bin/sh -s "arg1" "arg2"',
+ stdin=stdin_file)
Upload file:
- ssh = sshclient.SSH("user", "example.com")
- ssh.run("cat > ~/upload/file.gz", stdin=open("/store/file.gz", "rb"))
+ ssh = SSH("user", "example.com")
+ # use rb for binary files
+ with open("/store/file.gz", "rb") as stdin_file:
+ ssh.run("cat > ~/upload/file.gz", stdin=stdin_file)
Eventlet:
@@ -54,7 +59,7 @@ Eventlet:
or
eventlet.monkey_patch()
or
- sshclient = eventlet.import_patched("opentstack.common.sshclient")
+ sshclient = eventlet.import_patched("yardstick.ssh")
"""
import os