# 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__)
def setup(self):
"""Scenario setup."""
host = self.context_cfg['host']
- user = host.get('user', 'ubuntu')
- 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)
+ 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: ",
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:]
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]
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)