X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Fnetworking%2Fping.py;h=d2081469751c9d53e2a0883d97d4abd6b553b4cf;hb=03d764791eeb708ade47b5e2196b18ce04552dd1;hp=54c19229467928c026981591b62bbcfb79fd84ad;hpb=4fc53e85b6cef0208bafc653b32abbcca8460582;p=yardstick.git diff --git a/yardstick/benchmark/scenarios/networking/ping.py b/yardstick/benchmark/scenarios/networking/ping.py index 54c192294..d20814697 100644 --- a/yardstick/benchmark/scenarios/networking/ping.py +++ b/yardstick/benchmark/scenarios/networking/ping.py @@ -9,6 +9,8 @@ # ping scenario +from __future__ import print_function +from __future__ import absolute_import import pkg_resources import logging @@ -39,6 +41,7 @@ class Ping(base.Scenario): 'yardstick.benchmark.scenarios.networking', Ping.TARGET_SCRIPT) host = self.context_cfg['host'] user = host.get('user', 'ubuntu') + ssh_port = host.get("ssh_port", ssh.DEFAULT_PORT) ip = host.get('ip', None) key_filename = host.get('key_filename', '/root/.ssh/id_rsa') password = host.get('password', None) @@ -46,13 +49,15 @@ class Ping(base.Scenario): if password is not None: LOG.info("Log in via pw, user:%s, host:%s, pw:%s", user, ip, password) - self.connection = ssh.SSH(user, ip, password=password) + self.connection = ssh.SSH(user, ip, password=password, + port=ssh_port) else: LOG.info("Log in via key, user:%s, host:%s, key_filename:%s", user, ip, key_filename) - self.connection = ssh.SSH(user, ip, key_filename=key_filename) + 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""" @@ -76,9 +81,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) @@ -96,7 +102,7 @@ class Ping(base.Scenario): def _test(): # pragma: no cover - '''internal test function''' + """internal test function""" key_filename = pkg_resources.resource_filename("yardstick.resources", "files/yardstick_key") ctx = { @@ -118,7 +124,8 @@ def _test(): # pragma: no cover p = Ping(args, ctx) p.run(result) - print result + print(result) + if __name__ == '__main__': # pragma: no cover _test()