use context manager for stdin files and use _put_file_shell 57/24957/11
authorRoss Brattain <ross.b.brattain@intel.com>
Thu, 1 Dec 2016 03:56:38 +0000 (19:56 -0800)
committerRoss Brattain <ross.b.brattain@intel.com>
Mon, 5 Dec 2016 12:41:57 +0000 (07:41 -0500)
commit0576844bb2cdae6b479504ec1532a5dc56c0b633
tree8c50f7e7f9b6c37d60bdf907bb0a0e7f1c3143d1
parentcefc4e95e9b410c12faea47994d5a2162fa90870
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 <ross.b.brattain@intel.com>
25 files changed:
yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py
yardstick/benchmark/scenarios/availability/attacker/attacker_general.py
yardstick/benchmark/scenarios/availability/attacker/attacker_process.py
yardstick/benchmark/scenarios/availability/monitor/monitor_command.py
yardstick/benchmark/scenarios/availability/monitor/monitor_general.py
yardstick/benchmark/scenarios/availability/monitor/monitor_process.py
yardstick/benchmark/scenarios/availability/operation/operation_general.py
yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py
yardstick/benchmark/scenarios/compute/cachestat.py
yardstick/benchmark/scenarios/compute/computecapacity.py
yardstick/benchmark/scenarios/compute/cyclictest.py
yardstick/benchmark/scenarios/compute/lmbench.py
yardstick/benchmark/scenarios/compute/perf.py
yardstick/benchmark/scenarios/compute/ramspeed.py
yardstick/benchmark/scenarios/compute/unixbench.py
yardstick/benchmark/scenarios/networking/netperf.py
yardstick/benchmark/scenarios/networking/networkcapacity.py
yardstick/benchmark/scenarios/networking/ping.py
yardstick/benchmark/scenarios/networking/ping6.py
yardstick/benchmark/scenarios/networking/pktgen.py
yardstick/benchmark/scenarios/networking/pktgen_dpdk.py
yardstick/benchmark/scenarios/networking/sfc.py
yardstick/benchmark/scenarios/networking/vsperf.py
yardstick/benchmark/scenarios/storage/fio.py
yardstick/benchmark/scenarios/storage/storagecapacity.py