X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Fcompute%2Fcyclictest.py;h=413709f3baf82d882cae794458244af182de8ecb;hb=01628b168c1b718760dc9e74b811233b99c23ca2;hp=6a1afe223e072d59421962ed8f8f5cf61b57f872;hpb=1e132a317acdca7202f009c4d16898705b277665;p=yardstick.git diff --git a/yardstick/benchmark/scenarios/compute/cyclictest.py b/yardstick/benchmark/scenarios/compute/cyclictest.py index 6a1afe223..413709f3b 100644 --- a/yardstick/benchmark/scenarios/compute/cyclictest.py +++ b/yardstick/benchmark/scenarios/compute/cyclictest.py @@ -6,12 +6,16 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## -import pkg_resources +from __future__ import absolute_import +from __future__ import print_function + import logging -import json +import os import re import time -import os + +import pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -69,41 +73,34 @@ class Cyclictest(base.Scenario): rpm_dir = setup_options["rpm_dir"] script_dir = setup_options["script_dir"] image_dir = setup_options["image_dir"] - LOG.debug("Send RPMs from %s to workspace %s" % - (rpm_dir, self.WORKSPACE)) + LOG.debug("Send RPMs from %s to workspace %s", + rpm_dir, self.WORKSPACE) client.put(rpm_dir, self.WORKSPACE, recursive=True) - LOG.debug("Send scripts from %s to workspace %s" % - (script_dir, self.WORKSPACE)) + LOG.debug("Send scripts from %s to workspace %s", + script_dir, self.WORKSPACE) client.put(script_dir, self.WORKSPACE, recursive=True) - LOG.debug("Send guest image from %s to workspace %s" % - (image_dir, self.WORKSPACE)) + LOG.debug("Send guest image from %s to workspace %s", + image_dir, self.WORKSPACE) client.put(image_dir, self.WORKSPACE, recursive=True) def _connect_host(self): host = self.context_cfg["host"] - user = host.get("user", "root") - ip = host.get("ip", None) - key_filename = host.get("key_filename", "~/.ssh/id_rsa") - LOG.debug("user:%s, host:%s", user, ip) - self.host = ssh.SSH(user, ip, key_filename=key_filename) + self.host = ssh.SSH.from_node(host, defaults={"user": "root"}) self.host.wait(timeout=600) def _connect_guest(self): host = self.context_cfg["host"] - user = host.get("user", "root") - ip = host.get("ip", None) - ssh_port = host.get("ssh_port", 5555) - key_filename = host.get("key_filename", "~/.ssh/id_rsa") - - LOG.debug("user:%s, host:%s", user, ip) - self.guest = ssh.SSH(user, ip, port=ssh_port, - key_filename=key_filename) + # why port 5555? + self.guest = ssh.SSH.from_node(host, + defaults={ + "user": "root", "ssh_port": 5555 + }) self.guest.wait(timeout=600) def _run_setup_cmd(self, client, cmd): - LOG.debug("Run cmd: %s" % cmd) - status, stdout, stderr = client.execute(cmd) + LOG.debug("Run cmd: %s", cmd) + status, _, stderr = client.execute(cmd) if status: if re.search(self.REBOOT_CMD_PATTERN, cmd): LOG.debug("Error on reboot") @@ -137,7 +134,7 @@ class Cyclictest(base.Scenario): self._connect_guest() def setup(self): - '''scenario setup''' + """scenario setup""" setup_options = self.scenario_cfg["setup_options"] host_setup_seqs = setup_options["host_setup_seqs"] guest_setup_seqs = setup_options["guest_setup_seqs"] @@ -154,28 +151,29 @@ 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 def run(self, result): """execute the benchmark""" - default_args = "-m -n -q" + default_args = "-m -n -q --notrace" if not self.setup_done: self.setup() options = self.scenario_cfg["options"] affinity = options.get("affinity", 1) + breaktrace = options.get("breaktrace", 1000) interval = options.get("interval", 1000) priority = options.get("priority", 99) loops = options.get("loops", 1000) threads = options.get("threads", 1) histogram = options.get("histogram", 90) - cmd_args = "-a %s -i %s -p %s -l %s -t %s -h %s %s" \ - % (affinity, interval, priority, loops, + cmd_args = "-a %s -b %s -i %s -p %s -l %s -t %s -h %s %s" \ + % (affinity, breaktrace, interval, priority, loops, threads, histogram, default_args) cmd = "bash cyclictest_benchmark.sh %s" % (cmd_args) LOG.debug("Executing command: %s", cmd) @@ -183,7 +181,7 @@ class Cyclictest(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) if "sla" in self.scenario_cfg: sla_error = "" @@ -197,11 +195,11 @@ class Cyclictest(base.Scenario): if latency > sla_latency: sla_error += "%s latency %d > sla:max_%s_latency(%d); " % \ (t, latency, t, sla_latency) - assert sla_error == "", sla_error + self.verify_SLA(sla_error == "", sla_error) def _test(): # pragma: no cover - '''internal test function''' + """internal test function""" key_filename = pkg_resources.resource_filename("yardstick.resources", "files/yardstick_key") ctx = { @@ -217,6 +215,7 @@ def _test(): # pragma: no cover options = { "affinity": 2, + "breaktrace": 1000, "interval": 100, "priority": 88, "loops": 10000, @@ -236,7 +235,8 @@ def _test(): # pragma: no cover cyclictest = Cyclictest(args, ctx) cyclictest.run(result) - print result + print(result) + if __name__ == '__main__': # pragma: no cover _test()