diff options
author | Dino Madarang <dinox.madarang@intel.com> | 2017-11-01 09:10:16 -0700 |
---|---|---|
committer | Ross Brattain <ross.b.brattain@intel.com> | 2017-12-15 06:03:26 +0000 |
commit | 6cfec77db6b95af5b31b741d513955ee3dfa3bb2 (patch) | |
tree | ba8174fdf1b328355b1d591be0a0a735feeca889 /yardstick/network_services | |
parent | 93f53ca898891f5fd5fb5994c40932900aea1e73 (diff) |
NSB: Fix standalone.model.Libvirt SR-IOV modeling
Fixed standalone.model.Libvirt SR-IOV XML interface modeling, acording
to [1]:
- All PCI attributes now are printed in hexadecimal format.
- The PCI address is now added in the correct section, 'interface'.
network_services.utils.PciAddress was refactored to accept both 'domain:
bus:slot:function' and 'bus:slot:function' format inputs. This class is
used as input in the previous class, Libvirt, to print in XML the PCI
address of a SR-IOV interface.
network_services.utils.PciAddress.parse_address is now deprecated. Instead
the class standard instantiation must be used:
libvirt_obj = utils.PciAddress(text_with_address)
A deprecation decorator is implemented along with this patch. This
decorator is used for the first time in the previously mentioned function.
This decorator stores every decorated function name and deprecation message
and raises a logging warning message the first time this function is used.
[1] https://goo.gl/so2Mrp
Change-Id: I22e95c488e27d6e2a8fdf6c1a07faab275fa6bba
Signed-off-by: Dino Simeon Madarang <dinox.madarang@intel.com>
Reviewed-by: Alain Jebara <alain.jebara@intel.com>
Reviewed-by: Deepak S <deepak.s@linux.intel.com>
Reviewed-by: Ross Brattain <ross.b.brattain@intel.com>
Reviewed-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Diffstat (limited to 'yardstick/network_services')
-rw-r--r-- | yardstick/network_services/utils.py | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/yardstick/network_services/utils.py b/yardstick/network_services/utils.py index eac3c814f..7a1815eb9 100644 --- a/yardstick/network_services/utils.py +++ b/yardstick/network_services/utils.py @@ -22,6 +22,7 @@ from oslo_config import cfg from oslo_config.cfg import NoSuchOptError from oslo_utils import encodeutils + NSB_ROOT = "/opt/nsb_bin" CONF = cfg.CONF @@ -43,30 +44,37 @@ HEXADECIMAL = "[0-9a-zA-Z]" class PciAddress(object): + """Class to handle PCI addresses. - PCI_PATTERN_STR = HEXADECIMAL.join([ - "(", - "{4}):(", # domain (4 bytes) - "{2}):(", # bus (2 bytes) - "{2}).(", # function (2 bytes) - ")", # slot (1 byte) - ]) + 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 - PCI_PATTERN = re.compile(PCI_PATTERN_STR) + Note: in Libvirt, 'device' is called 'slot'. - @classmethod - def parse_address(cls, text, multi_line=False): - if multi_line: - text = text.replace(os.linesep, '') - match = cls.PCI_PATTERN.search(text) - return cls(match.group(0)) + Reference: https://wiki.xenproject.org/wiki/ + Bus:Device.Function_(BDF)_Notation + """ + PCI_PATTERN_STR = ( + r"((?P<domain>[0-9a-zA-Z]{4}):)?(?P<bus>[0-9a-zA-Z]{2}):" + r"(?P<slot>[0-9a-zA-Z]{2})\.(?P<function>[0-9a-zA-Z]{1})") def __init__(self, address): - super(PciAddress, self).__init__() - match = self.PCI_PATTERN.match(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.address = 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): @@ -74,22 +82,22 @@ class PciAddress(object): @property def domain(self): - return self.match.group(1) + return self._domain @property def bus(self): - return self.match.group(2) + return self._bus @property def slot(self): - return self.match.group(3) + return self._slot @property def function(self): - return self.match.group(4) + return self._function def values(self): - return [self.match.group(n) for n in range(1, 5)] + return [self._domain, self._bus, self._slot, self._function] def get_nsb_option(option, default=None): |