aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/compute
diff options
context:
space:
mode:
authorRoss Brattain <ross.b.brattain@intel.com>2016-11-30 19:56:38 -0800
committerRoss Brattain <ross.b.brattain@intel.com>2016-12-05 07:41:57 -0500
commit0576844bb2cdae6b479504ec1532a5dc56c0b633 (patch)
tree8c50f7e7f9b6c37d60bdf907bb0a0e7f1c3143d1 /yardstick/benchmark/scenarios/compute
parentcefc4e95e9b410c12faea47994d5a2162fa90870 (diff)
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>
Diffstat (limited to 'yardstick/benchmark/scenarios/compute')
-rw-r--r--yardstick/benchmark/scenarios/compute/cachestat.py3
-rw-r--r--yardstick/benchmark/scenarios/compute/computecapacity.py3
-rw-r--r--yardstick/benchmark/scenarios/compute/cyclictest.py4
-rw-r--r--yardstick/benchmark/scenarios/compute/lmbench.py12
-rw-r--r--yardstick/benchmark/scenarios/compute/perf.py3
-rw-r--r--yardstick/benchmark/scenarios/compute/ramspeed.py8
-rw-r--r--yardstick/benchmark/scenarios/compute/unixbench.py4
7 files changed, 17 insertions, 20 deletions
diff --git a/yardstick/benchmark/scenarios/compute/cachestat.py b/yardstick/benchmark/scenarios/compute/cachestat.py
index 25300dd46..20786ff61 100644
--- a/yardstick/benchmark/scenarios/compute/cachestat.py
+++ b/yardstick/benchmark/scenarios/compute/cachestat.py
@@ -85,8 +85,7 @@ class CACHEstat(base.Scenario):
self.client.wait(timeout=600)
# copy scripts to host
- self.client.run("cat > ~/cache_stat.sh",
- stdin=open(self.target_script, 'rb'))
+ self.client._put_file_shell(self.target_script, '~/cache_stat.sh')
self.setup_done = True
diff --git a/yardstick/benchmark/scenarios/compute/computecapacity.py b/yardstick/benchmark/scenarios/compute/computecapacity.py
index 9d7a923b1..7f0c58de1 100644
--- a/yardstick/benchmark/scenarios/compute/computecapacity.py
+++ b/yardstick/benchmark/scenarios/compute/computecapacity.py
@@ -49,8 +49,7 @@ class ComputeCapacity(base.Scenario):
self.client.wait(timeout=600)
# copy script to host
- self.client.run("cat > ~/computecapacity.sh",
- stdin=open(self.target_script, 'rb'))
+ self.client._put_file_shell(self.target_script, '~/computecapacity.sh')
self.setup_done = True
diff --git a/yardstick/benchmark/scenarios/compute/cyclictest.py b/yardstick/benchmark/scenarios/compute/cyclictest.py
index a6c4d95cf..568e6e7df 100644
--- a/yardstick/benchmark/scenarios/compute/cyclictest.py
+++ b/yardstick/benchmark/scenarios/compute/cyclictest.py
@@ -154,8 +154,8 @@ class Cyclictest(base.Scenario):
self.target_script = pkg_resources.resource_filename(
"yardstick.benchmark.scenarios.compute",
Cyclictest.TARGET_SCRIPT)
- self.guest.run("cat > ~/cyclictest_benchmark.sh",
- stdin=open(self.target_script, "rb"))
+ self.guest._put_file_shell(
+ self.target_script, '~/cyclictest_benchmark.sh')
self.setup_done = True
diff --git a/yardstick/benchmark/scenarios/compute/lmbench.py b/yardstick/benchmark/scenarios/compute/lmbench.py
index 9ceb2484c..518840c09 100644
--- a/yardstick/benchmark/scenarios/compute/lmbench.py
+++ b/yardstick/benchmark/scenarios/compute/lmbench.py
@@ -87,12 +87,12 @@ class Lmbench(base.Scenario):
self.client.wait(timeout=600)
# copy scripts to host
- self.client.run("cat > ~/lmbench_latency.sh",
- stdin=open(self.latency_target_script, 'rb'))
- self.client.run("cat > ~/lmbench_bandwidth.sh",
- stdin=open(self.bandwidth_target_script, 'rb'))
- self.client.run("cat > ~/lmbench_latency_for_cache.sh",
- stdin=open(self.latency_for_cache_script, 'rb'))
+ self.client._put_file_shell(
+ self.latency_target_script, '~/lmbench_latency.sh')
+ self.client._put_file_shell(
+ self.bandwidth_target_script, '~/lmbench_bandwidth.sh')
+ self.client._put_file_shell(
+ self.latency_for_cache_script, '~/lmbench_latency_for_cache.sh')
self.setup_done = True
def run(self, result):
diff --git a/yardstick/benchmark/scenarios/compute/perf.py b/yardstick/benchmark/scenarios/compute/perf.py
index 6c827efc2..8f1a4d630 100644
--- a/yardstick/benchmark/scenarios/compute/perf.py
+++ b/yardstick/benchmark/scenarios/compute/perf.py
@@ -57,8 +57,7 @@ class Perf(base.Scenario):
self.client.wait(timeout=600)
# copy script to host
- self.client.run("cat > ~/perf_benchmark.sh",
- stdin=open(self.target_script, "rb"))
+ self.client._put_file_shell(self.target_script, '~/perf_benchmark.sh')
self.setup_done = True
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):
diff --git a/yardstick/benchmark/scenarios/compute/unixbench.py b/yardstick/benchmark/scenarios/compute/unixbench.py
index e6299346f..b22be29c9 100644
--- a/yardstick/benchmark/scenarios/compute/unixbench.py
+++ b/yardstick/benchmark/scenarios/compute/unixbench.py
@@ -77,8 +77,8 @@ class Unixbench(base.Scenario):
self.client.wait(timeout=600)
# copy scripts to host
- self.client.run("cat > ~/unixbench_benchmark.sh",
- stdin=open(self.target_script, 'rb'))
+ self.client._put_file_shell(
+ self.target_script, '~/unixbench_benchmark.sh')
self.setup_done = True