X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fbenchmark%2Fscenarios%2Fnetworking%2Fnetutilization.py;h=cecb64fa0118981bbd23fef8ec3397a55386417a;hb=07249e010dd9837d63f3090f1eac0fc6763b968f;hp=ecde7568e72d0959f084adf311f461c716967ec5;hpb=293a8ed0c22d7944c8fc671792683d45d3fa8d48;p=yardstick.git diff --git a/yardstick/benchmark/scenarios/networking/netutilization.py b/yardstick/benchmark/scenarios/networking/netutilization.py index ecde7568e..cecb64fa0 100644 --- a/yardstick/benchmark/scenarios/networking/netutilization.py +++ b/yardstick/benchmark/scenarios/networking/netutilization.py @@ -6,11 +6,13 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from __future__ import absolute_import import logging import re import yardstick.ssh as ssh from yardstick.benchmark.scenarios import base +from six.moves import zip LOG = logging.getLogger(__name__) @@ -69,21 +71,15 @@ class NetUtilization(base.Scenario): def setup(self): """Scenario setup.""" 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', '~/.ssh/id_rsa') - - LOG.info("user:%s, host:%s", user, ip) - self.client = ssh.SSH(user, ip, key_filename=key_filename, - port=ssh_port) + + self.client = ssh.SSH.from_node(host, defaults={"user": "ubuntu"}) self.client.wait(timeout=600) self.setup_done = True def _execute_command(self, cmd): """Execute a command on target.""" - LOG.info("Executing: %s" % cmd) + LOG.info("Executing: %s", cmd) status, stdout, stderr = self.client.execute(cmd) if status: raise RuntimeError("Failed executing command: ", @@ -98,25 +94,17 @@ class NetUtilization(base.Scenario): average = {} time_marker = re.compile("^([0-9]+):([0-9]+):([0-9]+)$") - ampm_marker = re.compile("(AM|PM)$") # Parse network utilization stats - for row in raw_result.split('\n'): + for row in raw_result.splitlines(): line = row.split() if line and re.match(time_marker, line[0]): - if re.match(ampm_marker, line[1]): - del line[:2] - if line[0] == 'IFACE': - # header fields - fields = line[1:] - if len(fields) != NetUtilization.\ - NET_UTILIZATION_FIELD_SIZE: - raise RuntimeError("network_utilization: unexpected\ - field size", fields) - else: - # value fields + try: + index = line.index('IFACE') + except ValueError: + del line[:index] net_interface = line[0] values = line[1:] @@ -142,6 +130,13 @@ class NetUtilization(base.Scenario): else: raise RuntimeError("network_utilization: parse error", fields, line) + else: + del line[:index] + fields = line[1:] + if len(fields) != NetUtilization.\ + NET_UTILIZATION_FIELD_SIZE: + raise RuntimeError("network_utilization: unexpected\ + field size", fields) elif line and line[0] == 'Average:': del line[:1] @@ -158,7 +153,8 @@ class NetUtilization(base.Scenario): net_interface = line[0] values = line[1:] if values and len(values) == len(fields): - average[net_interface] = dict(zip(fields, values)) + average[net_interface] = dict( + zip(fields, values)) else: raise RuntimeError("network_utilization average: \ parse error", fields, line)