From 0576844bb2cdae6b479504ec1532a5dc56c0b633 Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Wed, 30 Nov 2016 19:56:38 -0800 Subject: use context manager for stdin files and use _put_file_shell requires https://gerrit.opnfv.org/gerrit/#/c/25183/ use new ssh method _put_file_shell to upload files. We have to use _put_file_shell because we rely on ~/ path expansions. Eventually we should move to remote absolute paths so we can use sftp upload. For ssh.execute() replace open() with context manager context managers were invented partly to control freeing resources. Opening files without closing them will leak file descriptors. The old standard method for closing files: f = open('data.txt') try: data = f.read() finally: f.close() was replaced with a context manager with open('data.txt') as f: data = f.read() Reference: Raymond Hettinger's Pycon 2013 presentation: https://speakerdeck.com/pyconslides/transforming-code-into-beautiful-idiomatic-python-by-raymond-hettinger-1 Video: https://youtu.be/OSGv2VnC0go?t=2522 Always use context managers for files Update: rebased now that _put_file_shell was merged Change-Id: Iabfc0e43aa3b7766d7c658115e13d21c31efb2a9 Signed-off-by: Ross Brattain --- yardstick/benchmark/scenarios/compute/ramspeed.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'yardstick/benchmark/scenarios/compute/ramspeed.py') diff --git a/yardstick/benchmark/scenarios/compute/ramspeed.py b/yardstick/benchmark/scenarios/compute/ramspeed.py index bc33f8af2..db70af90b 100644 --- a/yardstick/benchmark/scenarios/compute/ramspeed.py +++ b/yardstick/benchmark/scenarios/compute/ramspeed.py @@ -97,10 +97,10 @@ class Ramspeed(base.Scenario): self.client.wait(timeout=600) # copy scripts to host - self.client.run("cat > ~/ramspeed_mark_benchmark.sh", - stdin=open(self.mark_target_script, 'rb')) - self.client.run("cat > ~/ramspeed_mem_benchmark.sh", - stdin=open(self.mem_target_script, 'rb')) + self.client._put_file_shell( + self.mark_target_script, '~/ramspeed_mark_benchmark.sh') + self.client._put_file_shell( + self.mem_target_script, '~/ramspeed_mem_benchmark.sh') self.setup_done = True def run(self, result): -- cgit 1.2.3-korg