aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/networking/ping6.py
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/networking/ping6.py
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/networking/ping6.py')
-rw-r--r--yardstick/benchmark/scenarios/networking/ping6.py33
1 files changed, 15 insertions, 18 deletions
diff --git a/yardstick/benchmark/scenarios/networking/ping6.py b/yardstick/benchmark/scenarios/networking/ping6.py
index 9aa94c40c..f4d23ce7b 100644
--- a/yardstick/benchmark/scenarios/networking/ping6.py
+++ b/yardstick/benchmark/scenarios/networking/ping6.py
@@ -69,8 +69,8 @@ class Ping6(base.Scenario): # pragma: no cover
def _pre_setup(self):
for node_name in self.host_list:
self._ssh_host(node_name)
- self.client.run("cat > ~/pre_setup.sh",
- stdin=open(self.pre_setup_script, "rb"))
+ self.client._put_file_shell(
+ self.pre_setup_script, '~/pre_setup.sh')
status, stdout, stderr = self.client.execute(
"sudo bash pre_setup.sh")
@@ -117,20 +117,19 @@ class Ping6(base.Scenario): # pragma: no cover
if controller_node_name is None:
LOG.exception("Can't find controller node in the context!!!")
self._ssh_host(controller_node_name)
- self.client.run("cat > ~/metadata.txt",
- stdin=open(self.ping6_metadata_script, "rb"))
+ self.client._put_file_shell(
+ self.ping6_metadata_script, '~/metadata.txt')
# run script to setup ipv6 with nosdn or odl
sdn = self.options.get("sdn", 'nosdn')
if 'odl' in sdn:
- self.client.run("cat > ~/br-ex.radvd.conf",
- stdin=open(self.ping6_radvd_script, "rb"))
- self.client.run("cat > ~/setup_odl.sh",
- stdin=open(self.setup_odl_script, "rb"))
+ self.client._put_file_shell(
+ self.ping6_radvd_script, '~/br-ex.radvd.conf')
+ self.client._put_file_shell(
+ self.setup_odl_script, '~/setup_odl.sh')
setup_bash_file = "setup_odl.sh"
else:
- self.client.run("cat > ~/setup.sh",
- stdin=open(self.setup_script, "rb"))
+ self.client._put_file_shell(self.setup_script, '~/setup.sh')
setup_bash_file = "setup.sh"
cmd = "sudo bash %s %s %s" % \
(setup_bash_file, self.openrc, self.external_network)
@@ -156,8 +155,8 @@ class Ping6(base.Scenario): # pragma: no cover
self._ssh_host(self.host_list[0])
# find ipv4-int-network1 to ssh VM
- self.client.run("cat > ~/find_host.sh",
- stdin=open(self.ping6_find_host_script, "rb"))
+ self.client._put_file_shell(
+ self.ping6_find_host_script, '~/find_host.sh')
cmd = "sudo bash find_host.sh %s" % self.openrc
LOG.debug("Executing find_host command: %s", cmd)
status, stdout, stderr = self.client.execute(cmd)
@@ -171,8 +170,7 @@ class Ping6(base.Scenario): # pragma: no cover
stdin=open("/tmp/vRouterKey", "rb"))
# run ping6 benchmark
- self.client.run("cat > ~/ping6.sh",
- stdin=open(self.ping6_script, "rb"))
+ self.client._put_file_shell(self.ping6_script, '~/ping6.sh')
cmd = "sudo bash ping6.sh %s %s" % (self.openrc, self.ping_options)
LOG.debug("Executing ping6 command: %s", cmd)
status, stdout, stderr = self.client.execute(cmd)
@@ -208,8 +206,7 @@ class Ping6(base.Scenario): # pragma: no cover
self.teardown_script = pkg_resources.resource_filename(
'yardstick.benchmark.scenarios.networking',
Ping6.TEARDOWN_SCRIPT)
- self.client.run("cat > ~/teardown.sh",
- stdin=open(self.teardown_script, "rb"))
+ self.client._put_file_shell(self.teardown_script, '~/teardown.sh')
cmd = "sudo bash teardown.sh %s %s" % \
(self.openrc, self.external_network)
status, stdout, stderr = self.client.execute(cmd)
@@ -229,7 +226,7 @@ class Ping6(base.Scenario): # pragma: no cover
def _post_teardown(self):
for node_name in self.host_list:
self._ssh_host(node_name)
- self.client.run("cat > ~/post_teardown.sh",
- stdin=open(self.post_teardown_script, "rb"))
+ self.client._put_file_shell(
+ self.post_teardown_script, '~/post_teardown.sh')
status, stdout, stderr = self.client.execute(
"sudo bash post_teardown.sh")