X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fnetwork_services%2Futils.py;h=9c64fecde0414302a2464879b51595f8ec91cdab;hb=8ca60c71beb38d0ea2cd497310814d9df8ca0e8e;hp=cb71a602929e886be12f9b70bc66c6f2a3b4ba72;hpb=1267052bbc7dc3921c429ab299f6335dbe709dc7;p=yardstick.git diff --git a/yardstick/network_services/utils.py b/yardstick/network_services/utils.py index cb71a6029..9c64fecde 100644 --- a/yardstick/network_services/utils.py +++ b/yardstick/network_services/utils.py @@ -16,11 +16,13 @@ from __future__ import absolute_import import logging import os +import re from oslo_config import cfg from oslo_config.cfg import NoSuchOptError from oslo_utils import encodeutils + NSB_ROOT = "/opt/nsb_bin" CONF = cfg.CONF @@ -30,11 +32,77 @@ OPTS = [ help='bin_path for VNFs location.'), cfg.StrOpt('trex_path', default=os.path.join(NSB_ROOT, 'trex/scripts'), - help='trex automation lib pathh.'), + help='trex automation lib path.'), + cfg.StrOpt('trex_client_lib', + default=os.path.join(NSB_ROOT, 'trex_client/stl'), + help='trex python library path.'), + cfg.StrOpt('jre_path_i386', + default='', + help='path to installation of 32-bit Java 1.7+.'), ] CONF.register_opts(OPTS, group="nsb") +HEXADECIMAL = "[0-9a-zA-Z]" + + +class PciAddress(object): + """Class to handle PCI addresses. + + A PCI address could be written in two ways: + - Simple BDF notation: + 00:00.0 # bus:device.function + - With domain extension. + 0000:00:00.0 # domain:bus:device.function + + Note: in Libvirt, 'device' is called 'slot'. + + Reference: https://wiki.xenproject.org/wiki/ + Bus:Device.Function_(BDF)_Notation + """ + PCI_PATTERN_STR = ( + r"((?P[0-9a-zA-Z]{4}):)?(?P[0-9a-zA-Z]{2}):" + r"(?P[0-9a-zA-Z]{2})\.(?P[0-9a-zA-Z]{1})") + + def __init__(self, address): + pci_pattern = re.compile(self.PCI_PATTERN_STR) + match = pci_pattern.search(address) + if not match: + raise ValueError('Invalid PCI address: {}'.format(address)) + + self._domain = (match.group('domain') or '0000').lower() + self._bus = match.group('bus').lower() + self._slot = match.group('slot').lower() + self._function = match.group('function').lower() + self.address = '{:0>4}:{:0>2}:{:0>2}.{:1}'.format(self.domain, + self.bus, + self.slot, + self.function) + self.match = match + + def __repr__(self): + return self.address + + @property + def domain(self): + return self._domain + + @property + def bus(self): + return self._bus + + @property + def slot(self): + return self._slot + + @property + def function(self): + return self._function + + def values(self): + return [self._domain, self._bus, self._slot, self._function] + + def get_nsb_option(option, default=None): """return requested option for yardstick.conf""" @@ -45,20 +113,24 @@ def get_nsb_option(option, default=None): return default -def provision_tool(connection, tool_path): +def provision_tool(connection, tool_path, tool_file=None): """ verify if the tool path exits on the node, if not push the local binary to remote node :return - Tool path """ - bin_path = get_nsb_option("bin_path") - exit_status, stdout = connection.execute("which %s" % tool_path)[:2] + if not tool_path: + tool_path = get_nsb_option('tool_path') + if tool_file: + tool_path = os.path.join(tool_path, tool_file) + exit_status = connection.execute("which %s > /dev/null 2>&1" % tool_path)[0] if exit_status == 0: - return encodeutils.safe_decode(stdout, incoming='utf-8').rstrip() + return encodeutils.safe_decode(tool_path, incoming='utf-8').rstrip() logging.warning("%s not found on %s, will try to copy from localhost", tool_path, connection.host) + bin_path = get_nsb_option("bin_path") connection.execute('mkdir -p "%s"' % bin_path) connection.put(tool_path, tool_path) return tool_path