"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "nova/tests/unit/virt/libvirt/fakelibvirt.py" between
nova-22.0.0.tar.gz and nova-22.0.1.tar.gz

About: OpenStack Nova (Core Service: Compute) manages the lifecycle of compute instances in an OpenStack environment. Responsibilities include spawning, scheduling and decomissioning of machines on demand.
The "Victoria" series (latest release).

fakelibvirt.py  (nova-22.0.0):fakelibvirt.py  (nova-22.0.1)
skipping to change at line 282 skipping to change at line 282
VF). VF).
:param slot: (int) Slot number of the device. :param slot: (int) Slot number of the device.
:param function: (int) Function number of the device. :param function: (int) Function number of the device.
:param iommu_group: (int) IOMMU group ID. :param iommu_group: (int) IOMMU group ID.
:param numa_node: (int) NUMA node of the device. :param numa_node: (int) NUMA node of the device.
:param vf_ratio: (int) Ratio of Virtual Functions on Physical. Only :param vf_ratio: (int) Ratio of Virtual Functions on Physical. Only
applicable if ``dev_type`` is one of: ``PF``, ``VF``. applicable if ``dev_type`` is one of: ``PF``, ``VF``.
:param multiple_gpu_types: (bool) Supports different vGPU types :param multiple_gpu_types: (bool) Supports different vGPU types
""" """
self.dev_type = dev_type
self.slot = slot
self.function = function
self.iommu_group = iommu_group
self.numa_node = numa_node
self.vf_ratio = vf_ratio
self.multiple_gpu_types = multiple_gpu_types
self.parent = parent
self.generate_xml()
def generate_xml(self, skip_capability=False):
vend_id = PCI_VEND_ID vend_id = PCI_VEND_ID
vend_name = PCI_VEND_NAME vend_name = PCI_VEND_NAME
if dev_type == 'PCI': capability = ''
if vf_ratio: if self.dev_type == 'PCI':
if self.vf_ratio:
raise ValueError('vf_ratio does not apply for PCI devices') raise ValueError('vf_ratio does not apply for PCI devices')
prod_id = PCI_PROD_ID prod_id = PCI_PROD_ID
prod_name = PCI_PROD_NAME prod_name = PCI_PROD_NAME
driver = PCI_DRIVER_NAME driver = PCI_DRIVER_NAME
capability = '' elif self.dev_type == 'PF':
elif dev_type == 'PF':
prod_id = PF_PROD_ID prod_id = PF_PROD_ID
prod_name = PF_PROD_NAME prod_name = PF_PROD_NAME
driver = PF_DRIVER_NAME driver = PF_DRIVER_NAME
capability = self.cap_templ % { if not skip_capability:
'cap_type': PF_CAP_TYPE, capability = self.cap_templ % {
'addresses': '\n'.join([ 'cap_type': PF_CAP_TYPE,
self.addr_templ % { 'addresses': '\n'.join([
# these are the slot, function values of the child VFs self.addr_templ % {
# we can only assign 8 functions to a slot (0-7) so # these are the slot, function values of the child
# bump the slot each time we exceed this # VFs, we can only assign 8 functions to a slot
'slot': slot + (x // 8), # (0-7) so bump the slot each time we exceed this
# ...and wrap the function value 'slot': self.slot + (x // 8),
'function': x % 8, # ...and wrap the function value
# the offset is because the PF is occupying function 0 'function': x % 8,
} for x in range(1, vf_ratio + 1)]) # the offset is because the PF is occupying function 0
} } for x in range(1, self.vf_ratio + 1)])
elif dev_type == 'VF': }
elif self.dev_type == 'VF':
prod_id = VF_PROD_ID prod_id = VF_PROD_ID
prod_name = VF_PROD_NAME prod_name = VF_PROD_NAME
driver = VF_DRIVER_NAME driver = VF_DRIVER_NAME
capability = self.cap_templ % { if not skip_capability:
'cap_type': VF_CAP_TYPE, capability = self.cap_templ % {
'addresses': self.addr_templ % { 'cap_type': VF_CAP_TYPE,
# this is the slot, function value of the parent PF 'addresses': self.addr_templ % {
# if we're e.g. device 8, we'll have a different slot # this is the slot, function value of the parent PF
# to our parent so reverse this # if we're e.g. device 8, we'll have a different slot
'slot': slot - ((vf_ratio + 1) // 8), # to our parent so reverse this
# the parent PF is always function 0 'slot': self.slot - ((self.vf_ratio + 1) // 8),
'function': 0, # the parent PF is always function 0
'function': 0,
}
} }
} elif self.dev_type == 'MDEV_TYPES':
elif dev_type == 'MDEV_TYPES':
prod_id = MDEV_CAPABLE_PROD_ID prod_id = MDEV_CAPABLE_PROD_ID
prod_name = MDEV_CAPABLE_PROD_NAME prod_name = MDEV_CAPABLE_PROD_NAME
driver = MDEV_CAPABLE_DRIVER_NAME driver = MDEV_CAPABLE_DRIVER_NAME
vend_id = MDEV_CAPABLE_VEND_ID vend_id = MDEV_CAPABLE_VEND_ID
vend_name = MDEV_CAPABLE_VEND_NAME vend_name = MDEV_CAPABLE_VEND_NAME
types = [self.mdevtypes_templ % { types = [self.mdevtypes_templ % {
'type_id': NVIDIA_11_VGPU_TYPE, 'type_id': NVIDIA_11_VGPU_TYPE,
'instances': 16, 'instances': 16,
}] }]
if multiple_gpu_types: if self.multiple_gpu_types:
types.append(self.mdevtypes_templ % { types.append(self.mdevtypes_templ % {
'type_id': NVIDIA_12_VGPU_TYPE, 'type_id': NVIDIA_12_VGPU_TYPE,
'instances': 8, 'instances': 8,
}) })
capability = self.cap_templ % { if not skip_capability:
'cap_type': MDEV_CAPABLE_CAP_TYPE, capability = self.cap_templ % {
'addresses': '\n'.join(types) 'cap_type': MDEV_CAPABLE_CAP_TYPE,
} 'addresses': '\n'.join(types)
}
self.is_capable_of_mdevs = True self.is_capable_of_mdevs = True
else: else:
raise ValueError('Expected one of: PCI, VF, PCI') raise ValueError('Expected one of: PCI, VF, PCI')
self.pci_device = self.pci_device_template % { self.pci_device = self.pci_device_template % {
'slot': slot, 'slot': self.slot,
'function': function, 'function': self.function,
'vend_id': vend_id, 'vend_id': vend_id,
'vend_name': vend_name, 'vend_name': vend_name,
'prod_id': prod_id, 'prod_id': prod_id,
'prod_name': prod_name, 'prod_name': prod_name,
'driver': driver, 'driver': driver,
'capability': capability, 'capability': capability,
'iommu_group': iommu_group, 'iommu_group': self.iommu_group,
'numa_node': numa_node, 'numa_node': self.numa_node,
'parent': parent or self.pci_default_parent 'parent': self.parent or self.pci_default_parent
} }
# -1 is the sentinel set in /sys/bus/pci/devices/*/numa_node # -1 is the sentinel set in /sys/bus/pci/devices/*/numa_node
# for no NUMA affinity. When the numa_node is set to -1 on a device # for no NUMA affinity. When the numa_node is set to -1 on a device
# Libvirt omits the NUMA element so we remove it. # Libvirt omits the NUMA element so we remove it.
if numa_node == -1: if self.numa_node == -1:
self.pci_device = self.pci_device.replace("<numa node='-1'/>", "") self.pci_device = self.pci_device.replace("<numa node='-1'/>", "")
def XMLDesc(self, flags): def XMLDesc(self, flags):
return self.pci_device return self.pci_device
class HostPCIDevicesInfo(object): class HostPCIDevicesInfo(object):
"""Represent a pool of host PCI devices.""" """Represent a pool of host PCI devices."""
TOTAL_NUMA_NODES = 2 TOTAL_NUMA_NODES = 2
pci_devname_template = 'pci_0000_81_%(slot)02x_%(function)d' pci_devname_template = 'pci_0000_81_%(slot)02x_%(function)d'
skipping to change at line 928 skipping to change at line 942
mac = nic.find('./mac') mac = nic.find('./mac')
if mac is not None: if mac is not None:
nic_info['mac'] = mac.get('address') nic_info['mac'] = mac.get('address')
source = nic.find('./source') source = nic.find('./source')
if source is not None: if source is not None:
if nic_info['type'] == 'network': if nic_info['type'] == 'network':
nic_info['source'] = source.get('network') nic_info['source'] = source.get('network')
elif nic_info['type'] == 'bridge': elif nic_info['type'] == 'bridge':
nic_info['source'] = source.get('bridge') nic_info['source'] = source.get('bridge')
elif nic_info['type'] == 'hostdev':
# <interface type='hostdev'> is for VF when vnic_type
# is direct. Add sriov vf pci information in nic_info
address = source.find('./address')
pci_type = address.get('type')
pci_domain = address.get('domain').replace('0x', '')
pci_bus = address.get('bus').replace('0x', '')
pci_slot = address.get('slot').replace('0x', '')
pci_function = address.get('function').replace(
'0x', '')
pci_device = "%s_%s_%s_%s_%s" % (pci_type, pci_domain,
pci_bus, pci_slot,
pci_function)
nic_info['source'] = pci_device
nics_info += [nic_info] nics_info += [nic_info]
devices['nics'] = nics_info devices['nics'] = nics_info
hostdev_info = [] hostdev_info = []
hostdevs = device_nodes.findall('./hostdev') hostdevs = device_nodes.findall('./hostdev')
for hostdev in hostdevs: for hostdev in hostdevs:
address = hostdev.find('./source/address') address = hostdev.find('./source/address')
# NOTE(gibi): only handle mdevs as pci is complicated # NOTE(gibi): only handle mdevs as pci is complicated
skipping to change at line 969 skipping to change at line 997
'path': path, 'path': path,
'size': size, 'size': size,
'alignsize': alignsize, 'alignsize': alignsize,
'node': node}) 'node': node})
devices['vpmems'] = vpmem_info devices['vpmems'] = vpmem_info
definition['devices'] = devices definition['devices'] = devices
return definition return definition
def verify_hostdevs_interface_are_vfs(self):
"""Verify for interface type hostdev if the pci device is VF or not.
"""
error_message = ("Interface type hostdev is currently supported on "
"SR-IOV Virtual Functions only")
nics = self._def['devices'].get('nics', [])
for nic in nics:
if nic['type'] == 'hostdev':
pci_device = nic['source']
pci_info_from_connection = self._connection.pci_info.devices[
pci_device]
if 'phys_function' not in pci_info_from_connection.pci_device:
raise make_libvirtError(
libvirtError,
error_message,
error_code=VIR_ERR_CONFIG_UNSUPPORTED,
error_domain=VIR_FROM_DOMAIN)
def create(self): def create(self):
self.createWithFlags(0) self.createWithFlags(0)
def createWithFlags(self, flags): def createWithFlags(self, flags):
# FIXME: Not handling flags at the moment # FIXME: Not handling flags at the moment
self.verify_hostdevs_interface_are_vfs()
self._state = VIR_DOMAIN_RUNNING self._state = VIR_DOMAIN_RUNNING
self._connection._mark_running(self) self._connection._mark_running(self)
self._has_saved_state = False self._has_saved_state = False
def isActive(self): def isActive(self):
return int(self._state == VIR_DOMAIN_RUNNING) return int(self._state == VIR_DOMAIN_RUNNING)
def undefine(self): def undefine(self):
self._connection._undefine(self) self._connection._undefine(self)
skipping to change at line 1097 skipping to change at line 1146
disks += '''<disk type='%(type)s' device='%(device)s'> disks += '''<disk type='%(type)s' device='%(device)s'>
<driver name='%(driver_name)s' type='%(driver_type)s'/> <driver name='%(driver_name)s' type='%(driver_type)s'/>
<source %(source_attr)s='%(source)s'/> <source %(source_attr)s='%(source)s'/>
<target dev='%(target_dev)s' bus='%(target_bus)s'/> <target dev='%(target_dev)s' bus='%(target_bus)s'/>
<address type='drive' controller='0' bus='0' unit='0'/> <address type='drive' controller='0' bus='0' unit='0'/>
</disk>''' % dict(source_attr=source_attr, **disk) </disk>''' % dict(source_attr=source_attr, **disk)
nics = '' nics = ''
for nic in self._def['devices']['nics']: for nic in self._def['devices']['nics']:
if 'source' in nic: if 'source' in nic and nic['type'] != 'hostdev':
nics += '''<interface type='%(type)s'> nics += '''<interface type='%(type)s'>
<mac address='%(mac)s'/> <mac address='%(mac)s'/>
<source %(type)s='%(source)s'/> <source %(type)s='%(source)s'/>
<target dev='tap274487d1-60'/> <target dev='tap274487d1-60'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' <address type='pci' domain='0x0000' bus='0x00' slot='0x03'
function='0x0'/> function='0x0'/>
</interface>''' % nic </interface>''' % nic
# this covers for direct nic type # this covers for direct nic type
else: else:
nics += '''<interface type='%(type)s'> nics += '''<interface type='%(type)s'>
skipping to change at line 1778 skipping to change at line 1827
exc.err = (error_code, error_domain, error_message, error_level, exc.err = (error_code, error_domain, error_message, error_level,
str1, str2, str3, int1, int2) str1, str2, str3, int1, int2)
return exc return exc
virDomain = Domain virDomain = Domain
virNodeDevice = NodeDevice virNodeDevice = NodeDevice
virConnect = Connection virConnect = Connection
virSecret = Secret virSecret = Secret
# A private libvirt-python class and global only provided here for testing to
# ensure it's not returned by libvirt.host.Host.get_libvirt_proxy_classes.
class FakeHandler(object):
def __init__(self):
pass
_EventAddHandleFunc = FakeHandler
class FakeLibvirtFixture(fixtures.Fixture): class FakeLibvirtFixture(fixtures.Fixture):
"""Performs global setup/stubbing for all libvirt tests. """Performs global setup/stubbing for all libvirt tests.
""" """
def __init__(self, stub_os_vif=True): def __init__(self, stub_os_vif=True):
self.stub_os_vif = stub_os_vif self.stub_os_vif = stub_os_vif
def setUp(self): def setUp(self):
super(FakeLibvirtFixture, self).setUp() super(FakeLibvirtFixture, self).setUp()
# Some modules load the libvirt library in a strange way # Some modules load the libvirt library in a strange way
 End of changes. 16 change blocks. 
41 lines changed or deleted 98 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)