X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Fnetworking%2Fpktgen.py;h=e6aa7e5fb04be76ff8461be793aaf9efe1ec0bf7;hb=07249e010dd9837d63f3090f1eac0fc6763b968f;hp=e2df706a28737e94792cd80c1066a1c664bd9e3e;hpb=3c3ac5d9e89af36bb609017e69f6d03b52d8b251;p=yardstick.git diff --git a/yardstick/benchmark/scenarios/networking/pktgen.py b/yardstick/benchmark/scenarios/networking/pktgen.py index e2df706a2..e6aa7e5fb 100644 --- a/yardstick/benchmark/scenarios/networking/pktgen.py +++ b/yardstick/benchmark/scenarios/networking/pktgen.py @@ -6,9 +6,13 @@ # 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 pkg_resources +from oslo_serialization import jsonutils import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base @@ -43,31 +47,19 @@ class Pktgen(base.Scenario): self.setup_done = False def setup(self): - '''scenario setup''' + """scenario setup""" self.target_script = pkg_resources.resource_filename( 'yardstick.benchmark.scenarios.networking', Pktgen.TARGET_SCRIPT) host = self.context_cfg['host'] - host_user = host.get('user', 'ubuntu') - host_ssh_port = host.get('ssh_port', ssh.DEFAULT_PORT) - host_ip = host.get('ip', None) - host_key_filename = host.get('key_filename', '~/.ssh/id_rsa') target = self.context_cfg['target'] - target_user = target.get('user', 'ubuntu') - target_ssh_port = target.get('ssh_port', ssh.DEFAULT_PORT) - target_ip = target.get('ip', None) - target_key_filename = target.get('key_filename', '~/.ssh/id_rsa') - - LOG.info("user:%s, target:%s", target_user, target_ip) - self.server = ssh.SSH(target_user, target_ip, - key_filename=target_key_filename, - port=target_ssh_port) + + LOG.info("user:%s, target:%s", target['user'], target['ip']) + self.server = ssh.SSH.from_node(target, defaults={"user": "ubuntu"}) self.server.wait(timeout=600) - LOG.info("user:%s, host:%s", host_user, host_ip) - self.client = ssh.SSH(host_user, host_ip, - key_filename=host_key_filename, - port=host_ssh_port) + LOG.info("user:%s, host:%s", host['user'], host['ip']) + self.client = ssh.SSH.from_node(host, defaults={"user": "ubuntu"}) self.client.wait(timeout=600) # copy script to host @@ -130,9 +122,10 @@ class Pktgen(base.Scenario): if status: raise RuntimeError(stderr) - result.update(json.loads(stdout)) + result.update(jsonutils.loads(stdout)) result['packets_received'] = self._iptables_get_result() + result['packetsize'] = packetsize if "sla" in self.scenario_cfg: sent = result['packets_sent'] @@ -144,7 +137,7 @@ class Pktgen(base.Scenario): def _test(): - '''internal test function''' + """internal test function""" key_filename = pkg_resources.resource_filename('yardstick.resources', 'files/yardstick_key') ctx = { @@ -170,7 +163,7 @@ def _test(): p = Pktgen(args, ctx) p.run(result) - print result + print(result) if __name__ == '__main__':