diff options
29 files changed, 160 insertions, 155 deletions
diff --git a/api/actions/env.py b/api/actions/env.py index 78f9b72ed..fa0f95d90 100644 --- a/api/actions/env.py +++ b/api/actions/env.py @@ -53,7 +53,8 @@ def _create_grafana(): def _create_dashboard(): url = 'http://admin:admin@%s:3000/api/dashboards/db' % api_conf.GATEWAY_IP - data = json.load(file('../dashboard/ping_dashboard.json')) + with open('../dashboard/ping_dashboard.json') as dashboard_json: + data = json.load(dashboard_json) HttpClient().post(url, data) diff --git a/docs/userguide/07-installation.rst b/docs/userguide/07-installation.rst index 09d36bf25..9c2082a27 100644 --- a/docs/userguide/07-installation.rst +++ b/docs/userguide/07-installation.rst @@ -211,9 +211,9 @@ Example command: :: glance --os-image-api-version 1 image-create \ - --name yardstick-trusty-server --is-public true \ + --name yardstick-image --is-public true \ --disk-format qcow2 --container-format bare \ - --file /tmp/workspace/yardstick/yardstick-trusty-server.img + --file /tmp/workspace/yardstick/yardstick-image.img Some Yardstick test cases use a Cirros image, you can find one at http://download.cirros-cloud.net/0.3.3/cirros-0.3.3-x86_64-disk.img diff --git a/tests/unit/benchmark/scenarios/storage/test_storperf.py b/tests/unit/benchmark/scenarios/storage/test_storperf.py index d87ed733c..8fc97d2ed 100644 --- a/tests/unit/benchmark/scenarios/storage/test_storperf.py +++ b/tests/unit/benchmark/scenarios/storage/test_storperf.py @@ -43,7 +43,7 @@ def mocked_requests_job_get(*args, **kwargs): self.content = json_data self.status_code = status_code - return MockResponseJobGet('{"_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}', 200) + return MockResponseJobGet('{"status": "completed", "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}', 200) def mocked_requests_job_post(*args, **kwargs): @@ -152,7 +152,7 @@ class StorPerfTestCase(unittest.TestCase): s = storperf.StorPerf(args, self.ctx) s.setup_done = True - sample_output = '{"_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}' + sample_output = '{"status": "completed", "_ssd_preconditioning.queue-depth.8.block-size.16384.duration": 6}' expected_result = json.loads(sample_output) diff --git a/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py b/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py index 3b1f8ef76..e88fed636 100644 --- a/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py +++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_baremetal.py @@ -61,9 +61,10 @@ class BaremetalAttacker(BaseAttacker): self.setup_done = True def check(self): - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s {0} -W 10".format(self.host_ip), - stdin=open(self.check_script, "r")) + with open(self.check_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s {0} -W 10".format(self.host_ip), + stdin=stdin_file) LOG.debug("check ret: %s out:%s err:%s", exit_status, stdout, stderr) @@ -98,10 +99,11 @@ class BaremetalAttacker(BaseAttacker): LOG.debug("ssh jump host success!") if self.jump_connection is not None: - exit_status, stdout, stderr = self.jump_connection.execute( - "/bin/bash -s {0} {1} {2} {3}".format( - self.ipmi_ip, self.ipmi_user, self.ipmi_pwd, "on"), - stdin=open(self.recovery_script, "r")) + with open(self.recovery_script, "r") as stdin_file: + exit_status, stdout, stderr = self.jump_connection.execute( + "/bin/bash -s {0} {1} {2} {3}".format( + self.ipmi_ip, self.ipmi_user, self.ipmi_pwd, "on"), + stdin=stdin_file) else: exit_status, stdout = _execute_shell_command( "/bin/bash -s {0} {1} {2} {3}".format( diff --git a/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py b/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py index a452c37ac..595067a95 100644 --- a/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py +++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_general.py @@ -65,13 +65,15 @@ class GeneralAttacker(BaseAttacker): if "action_parameter" in self._config: LOG.debug("the shell command is: {0}".format(self.action_param)) - exit_status, stdout, stderr = self.connection.execute( - self.action_param, - stdin=open(self.inject_script, "r")) + with open(self.inject_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.action_param, + stdin=stdin_file) else: - exit_status, stdout, stderr = self.connection.execute( - "/bin/bash -s ", - stdin=open(self.inject_script, "r")) + with open(self.inject_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/bash -s ", + stdin=stdin_file) LOG.debug("the inject_fault's exit status is: {0}".format(exit_status)) if exit_status == 0: @@ -85,10 +87,12 @@ class GeneralAttacker(BaseAttacker): def recover(self): if "rollback_parameter" in self._config: LOG.debug("the shell command is: {0}".format(self.rollback_param)) - exit_status, stdout, stderr = self.connection.execute( - self.rollback_param, - stdin=open(self.recovery_script, "r")) + with open(self.recovery_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.rollback_param, + stdin=stdin_file) else: - exit_status, stdout, stderr = self.connection.execute( - "/bin/bash -s ", - stdin=open(self.recovery_script, "r")) + with open(self.recovery_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/bash -s ", + stdin=stdin_file) diff --git a/yardstick/benchmark/scenarios/availability/attacker/attacker_process.py b/yardstick/benchmark/scenarios/availability/attacker/attacker_process.py index 2ccc231da..1d190a160 100644 --- a/yardstick/benchmark/scenarios/availability/attacker/attacker_process.py +++ b/yardstick/benchmark/scenarios/availability/attacker/attacker_process.py @@ -45,9 +45,10 @@ class ProcessAttacker(BaseAttacker): self.setup_done = True def check(self): - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s {0}".format(self.service_name), - stdin=open(self.check_script, "r")) + with open(self.check_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s {0}".format(self.service_name), + stdin=stdin_file) if stdout and "running" in stdout: LOG.info("check the envrioment success!") @@ -59,11 +60,13 @@ class ProcessAttacker(BaseAttacker): return False def inject_fault(self): - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s {0}".format(self.service_name), - stdin=open(self.inject_script, "r")) + with open(self.inject_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s {0}".format(self.service_name), + stdin=stdin_file) def recover(self): - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s {0} ".format(self.service_name), - stdin=open(self.recovery_script, "r")) + with open(self.recovery_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s {0} ".format(self.service_name), + stdin=stdin_file) diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py index 366d16e73..cd33e6188 100644 --- a/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py +++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_command.py @@ -58,9 +58,10 @@ class MonitorOpenstackCmd(basemonitor.BaseMonitor): def monitor_func(self): exit_status = 0 if self.connection: - exit_status, stdout, stderr = self.connection.execute( - "/bin/bash -s '{0}'".format(self.cmd), - stdin=open(self.check_script, "r")) + with open(self.check_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/bash -s '{0}'".format(self.cmd), + stdin=stdin_file) LOG.debug("the ret stats: %s stdout: %s stderr: %s", exit_status, stdout, stderr) diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py index 359cde671..461a2ded5 100644 --- a/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py +++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_general.py @@ -48,13 +48,15 @@ class GeneralMonitor(basemonitor.BaseMonitor): def monitor_func(self): if "parameter" in self._config: - exit_status, stdout, stderr = self.connection.execute( - self.cmd_param, - stdin=open(self.monitor_script, "r")) + with open(self.monitor_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.cmd_param, + stdin=stdin_file) else: - exit_status, stdout, stderr = self.connection.execute( - "/bin/bash -s ", - stdin=open(self.monitor_script, "r")) + with open(self.monitor_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/bash -s ", + stdin=stdin_file) if exit_status: return False diff --git a/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py b/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py index a88b8d42e..5f492ad69 100644 --- a/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py +++ b/yardstick/benchmark/scenarios/availability/monitor/monitor_process.py @@ -35,9 +35,10 @@ class MonitorProcess(basemonitor.BaseMonitor): self.process_name = self._config["process_name"] def monitor_func(self): - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s {0}".format(self.process_name), - stdin=open(self.check_script, "r")) + with open(self.check_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s {0}".format(self.process_name), + stdin=stdin_file) if not stdout or int(stdout) <= 0: LOG.info("the process (%s) is not running!", self.process_name) return False diff --git a/yardstick/benchmark/scenarios/availability/operation/operation_general.py b/yardstick/benchmark/scenarios/availability/operation/operation_general.py index b3a20c344..c82df836d 100644 --- a/yardstick/benchmark/scenarios/availability/operation/operation_general.py +++ b/yardstick/benchmark/scenarios/availability/operation/operation_general.py @@ -55,13 +55,15 @@ class GeneralOperaion(BaseOperation): def run(self): if "action_parameter" in self._config: - exit_status, stdout, stderr = self.connection.execute( - self.action_param, - stdin=open(self.action_script, "r")) + with open(self.action_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.action_param, + stdin=stdin_file) else: - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s ", - stdin=open(self.action_script, "r")) + with open(self.action_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s ", + stdin=stdin_file) if exit_status == 0: LOG.debug("success,the operation's output is: {0}".format(stdout)) @@ -72,10 +74,12 @@ class GeneralOperaion(BaseOperation): def rollback(self): if "rollback_parameter" in self._config: - exit_status, stdout, stderr = self.connection.execute( - self.rollback_param, - stdin=open(self.rollback_script, "r")) + with open(self.rollback_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.rollback_param, + stdin=stdin_file) else: - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s ", - stdin=open(self.rollback_script, "r")) + with open(self.rollback_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s ", + stdin=stdin_file) diff --git a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py index 8c9d16026..275aff076 100644 --- a/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py +++ b/yardstick/benchmark/scenarios/availability/result_checker/result_checker_general.py @@ -53,17 +53,19 @@ class GeneralResultChecker(BaseResultChecker): def verify(self): if "parameter" in self._config: - exit_status, stdout, stderr = self.connection.execute( - self.shell_cmd, - stdin=open(self.verify_script, "r")) + with open(self.verify_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + self.shell_cmd, + stdin=stdin_file) LOG.debug("action script of the operation is: {0}" .format(self.verify_script)) LOG.debug("action parameter the of operation is: {0}" .format(self.shell_cmd)) else: - exit_status, stdout, stderr = self.connection.execute( - "/bin/bash -s ", - stdin=open(self.verify_script, "r")) + with open(self.verify_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/bash -s ", + stdin=stdin_file) LOG.debug("action script of the operation is: {0}" .format(self.verify_script)) 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 diff --git a/yardstick/benchmark/scenarios/networking/netperf.py b/yardstick/benchmark/scenarios/networking/netperf.py index 08901e12b..28f5bea56 100755 --- a/yardstick/benchmark/scenarios/networking/netperf.py +++ b/yardstick/benchmark/scenarios/networking/netperf.py @@ -85,8 +85,7 @@ class Netperf(base.Scenario): self.client.wait(timeout=600) # copy script to host - self.client.run("cat > ~/netperf.sh", - stdin=open(self.target_script, "rb")) + self.client._put_file_shell(self.target_script, '~/netperf.sh') self.setup_done = True diff --git a/yardstick/benchmark/scenarios/networking/networkcapacity.py b/yardstick/benchmark/scenarios/networking/networkcapacity.py index 438452e40..250f7eaf0 100644 --- a/yardstick/benchmark/scenarios/networking/networkcapacity.py +++ b/yardstick/benchmark/scenarios/networking/networkcapacity.py @@ -50,8 +50,7 @@ class NetworkCapacity(base.Scenario): self.client.wait(timeout=600) # copy script to host - self.client.run("cat > ~/networkcapacity.sh", - stdin=open(self.target_script, 'rb')) + self.client._put_file_shell(self.target_script, '~/networkcapacity.sh') self.setup_done = True diff --git a/yardstick/benchmark/scenarios/networking/ping.py b/yardstick/benchmark/scenarios/networking/ping.py index 2becdaf36..6e49a1437 100644 --- a/yardstick/benchmark/scenarios/networking/ping.py +++ b/yardstick/benchmark/scenarios/networking/ping.py @@ -55,7 +55,7 @@ class Ping(base.Scenario): self.connection = ssh.SSH(user, ip, key_filename=key_filename, port=ssh_port) - self.connection.wait() + self.connection.wait(timeout=600) def run(self, result): """execute the benchmark""" @@ -79,9 +79,10 @@ class Ping(base.Scenario): target_vm = self.scenario_cfg['target'] LOG.debug("ping '%s' '%s'", options, dest) - exit_status, stdout, stderr = self.connection.execute( - "/bin/sh -s {0} {1}".format(dest, options), - stdin=open(self.target_script, "r")) + with open(self.target_script, "r") as stdin_file: + exit_status, stdout, stderr = self.connection.execute( + "/bin/sh -s {0} {1}".format(dest, options), + stdin=stdin_file) if exit_status != 0: raise RuntimeError(stderr) 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") diff --git a/yardstick/benchmark/scenarios/networking/pktgen.py b/yardstick/benchmark/scenarios/networking/pktgen.py index 3e105767a..e2df706a2 100644 --- a/yardstick/benchmark/scenarios/networking/pktgen.py +++ b/yardstick/benchmark/scenarios/networking/pktgen.py @@ -71,8 +71,7 @@ class Pktgen(base.Scenario): self.client.wait(timeout=600) # copy script to host - self.client.run("cat > ~/pktgen.sh", - stdin=open(self.target_script, "rb")) + self.client._put_file_shell(self.target_script, '~/pktgen.sh') self.setup_done = True diff --git a/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py b/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py index 189cc7895..503ea97e1 100644 --- a/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py +++ b/yardstick/benchmark/scenarios/networking/pktgen_dpdk.py @@ -60,8 +60,7 @@ class PktgenDPDKLatency(base.Scenario): self.server.wait(timeout=600) # copy script to host - self.server.run("cat > ~/testpmd_fwd.sh", - stdin=open(self.testpmd_script, "rb")) + self.server._put_file_shell(self.testpmd_script, '~/testpmd_fwd.sh') LOG.info("user:%s, host:%s", host_user, host_ip) self.client = ssh.SSH(host_user, host_ip, @@ -70,8 +69,8 @@ class PktgenDPDKLatency(base.Scenario): self.client.wait(timeout=600) # copy script to host - self.client.run("cat > ~/pktgen_dpdk.sh", - stdin=open(self.pktgen_dpdk_script, "rb")) + self.client._put_file_shell( + self.pktgen_dpdk_script, '~/pktgen_dpdk.sh') self.setup_done = True self.testpmd_args = '' @@ -153,7 +152,7 @@ class PktgenDPDKLatency(base.Scenario): latency_sum = 0 for i in latency_list: latency_sum += int(i) - avg_latency = latency_sum/len(latency_list) + avg_latency = latency_sum / len(latency_list) result.update({"avg_latency": avg_latency}) diff --git a/yardstick/benchmark/scenarios/networking/sfc.py b/yardstick/benchmark/scenarios/networking/sfc.py index 9494e70d2..1bd99b957 100644 --- a/yardstick/benchmark/scenarios/networking/sfc.py +++ b/yardstick/benchmark/scenarios/networking/sfc.py @@ -50,8 +50,7 @@ class Sfc(base.Scenario): # pragma: no cover self.server = ssh.SSH(target_user, target_ip, password=target_pwd, port=target_ssh_port) self.server.wait(timeout=600) - self.server.run("cat > ~/server.sh", - stdin=open(self.server_script, "rb")) + self.server._put_file_shell(self.server_script, '~/server.sh') cmd_server = "sudo bash server.sh" LOG.debug("Executing command: %s", cmd_server) status, stdout, stderr = self.server.execute(cmd_server) diff --git a/yardstick/benchmark/scenarios/networking/vsperf.py b/yardstick/benchmark/scenarios/networking/vsperf.py index 39912a95a..4f4ef21eb 100644 --- a/yardstick/benchmark/scenarios/networking/vsperf.py +++ b/yardstick/benchmark/scenarios/networking/vsperf.py @@ -133,10 +133,8 @@ class Vsperf(base.Scenario): # traffic generation could last long self.client.wait(timeout=1800) - # copy script to host if needed - if self.vsperf_conf: - self.client.run("cat > ~/vsperf.conf", - stdin=open(self.vsperf_conf, "rb")) + # copy script to host + self.client._put_file_shell(self.vsperf_conf, '~/vsperf.conf') # execute external setup script if self.setup_script: diff --git a/yardstick/benchmark/scenarios/storage/fio.py b/yardstick/benchmark/scenarios/storage/fio.py index 0e4153643..4e004235d 100644 --- a/yardstick/benchmark/scenarios/storage/fio.py +++ b/yardstick/benchmark/scenarios/storage/fio.py @@ -70,8 +70,7 @@ class Fio(base.Scenario): self.client.wait(timeout=600) # copy script to host - self.client.run("cat > ~/fio.sh", - stdin=open(self.target_script, "rb")) + self.client._put_file_shell(self.target_script, '~/fio.sh') self.setup_done = True diff --git a/yardstick/benchmark/scenarios/storage/storagecapacity.py b/yardstick/benchmark/scenarios/storage/storagecapacity.py index bed45fa6d..bf5bc2810 100644 --- a/yardstick/benchmark/scenarios/storage/storagecapacity.py +++ b/yardstick/benchmark/scenarios/storage/storagecapacity.py @@ -64,8 +64,7 @@ class StorageCapacity(base.Scenario): self.client.wait(timeout=600) # copy script to host - self.client.run("cat > ~/storagecapacity.sh", - stdin=open(self.target_script, 'rb')) + self.client._put_file_shell(self.target_script, '~/storagecapacity.sh') self.setup_done = True @@ -109,7 +108,7 @@ class StorageCapacity(base.Scenario): for i in range(len(device_name_arr)): r[device_name_arr[i]] = {"min_util": min_util_arr[i], "max_util": max_util_arr[i], - "avg_util": avg_util_arr[i]/count} + "avg_util": avg_util_arr[i] / count} return r def run(self, result): diff --git a/yardstick/benchmark/scenarios/storage/storperf.py b/yardstick/benchmark/scenarios/storage/storperf.py index 06c329d4d..72ceff7ce 100644 --- a/yardstick/benchmark/scenarios/storage/storperf.py +++ b/yardstick/benchmark/scenarios/storage/storperf.py @@ -54,6 +54,7 @@ class StorPerf(base.Scenario): def __init__(self, scenario_cfg, context_cfg): """Scenario construction.""" + super(StorPerf, self).__init__() self.scenario_cfg = scenario_cfg self.context_cfg = context_cfg self.options = self.scenario_cfg["options"] @@ -85,8 +86,10 @@ class StorPerf(base.Scenario): "agent_image", "volume_size"] for env_argument in env_args_payload_list: - if env_argument in self.options: + try: env_args[env_argument] = self.options[env_argument] + except KeyError: + pass LOG.info("Creating a stack on node %s with parameters %s", self.target, env_args) @@ -95,7 +98,7 @@ class StorPerf(base.Scenario): setup_res_content = json.loads(setup_res.content) - if setup_res.status_code == 400: + if setup_res.status_code != 200: raise RuntimeError("Failed to create a stack, error message:", setup_res_content["message"]) elif setup_res.status_code == 200: @@ -105,25 +108,22 @@ class StorPerf(base.Scenario): self._query_setup_state() time.sleep(self.query_interval) - # TODO: Support Storperf job status. + def _query_job_state(self, job_id): + """Query the status of the supplied job_id and report on metrics""" + LOG.info("Fetching report for %s...", job_id) + report_res = requests.get('http://{}:5000/api/v1.0/jobs'.format + (self.target), params={'id': job_id}) - # def _query_job_state(self, job_id): - # """Query the status of the supplied job_id and report on metrics""" - # LOG.info("Fetching report for %s..." % job_id) - # report_res = requests.get('http://%s:5000/api/v1.0/jobs?id=%s' % - # (self.target, job_id)) + report_res_content = json.loads(report_res.content) - # report_res_content = json.loads(report_res.content) + if report_res.status_code != 200: + raise RuntimeError("Failed to fetch report, error message:", + report_res_content["message"]) + else: + job_status = report_res_content["status"] - # if report_res.status_code == 400: - # raise RuntimeError("Failed to fetch report, error message:", - # report_res_content["message"]) - # else: - # job_status = report_res_content["status"] - - # LOG.debug("Job is: %s..." % job_status) - # if job_status == "completed": - # self.job_completed = True + LOG.debug("Job is: %s...", job_status) + self.job_completed = job_status == "completed" # TODO: Support using StorPerf ReST API to read Job ETA. @@ -145,8 +145,10 @@ class StorPerf(base.Scenario): "target", "nossd", "nowarm", "workload"] for job_argument in job_args_payload_list: - if job_argument in self.options: + try: job_args[job_argument] = self.options[job_argument] + except KeyError: + pass LOG.info("Starting a job with parameters %s", job_args) job_res = requests.post('http://%s:5000/api/v1.0/jobs' % self.target, @@ -154,28 +156,25 @@ class StorPerf(base.Scenario): job_res_content = json.loads(job_res.content) - if job_res.status_code == 400: + if job_res.status_code != 200: raise RuntimeError("Failed to start a job, error message:", job_res_content["message"]) elif job_res.status_code == 200: job_id = job_res_content["job_id"] LOG.info("Started job id: %s...", job_id) - time.sleep(self.timeout) + while not self.job_completed: + self._query_job_state(job_id) + time.sleep(self.query_interval) + terminate_res = requests.delete('http://%s:5000/api/v1.0/jobs' % self.target) - if terminate_res.status_code == 400: + if terminate_res.status_code != 200: terminate_res_content = json.loads(terminate_res.content) raise RuntimeError("Failed to start a job, error message:", terminate_res_content["message"]) - # TODO: Support Storperf job status. - - # while not self.job_completed: - # self._query_job_state(job_id) - # time.sleep(self.query_interval) - # TODO: Support using ETA to polls for completion. # Read ETA, next poll in 1/2 ETA time slot. # If ETA is greater than the maximum allowed job time, |