Browse Source

Merge "functional: Add test for SR-IOV neutron ports"

tags/22.0.0.0rc1
Zuul 2 weeks ago
committed by Gerrit Code Review
parent
commit
e0f088c95d
2 changed files with 74 additions and 5 deletions
  1. +10
    -4
      nova/tests/functional/libvirt/base.py
  2. +64
    -1
      nova/tests/functional/libvirt/test_pci_sriov_servers.py

+ 10
- 4
nova/tests/functional/libvirt/base.py View File

@@ -321,12 +321,9 @@ class LibvirtNeutronFixture(nova_fixtures.NeutronFixture):
'subnet_id': subnet_4['id']
}
],
'binding:vif_details': {'vlan': 42},
'binding:vif_type': 'hw_veb',
'binding:vif_details': {'vlan': 42},
'binding:vnic_type': 'direct',
'binding:profile': {'pci_vendor_info': '1377:0047',
'pci_slot': '0000:81:00.1',
'physical_network': 'physnet4'},
}

def __init__(self, test):
@@ -357,6 +354,15 @@ class LibvirtNeutronFixture(nova_fixtures.NeutronFixture):
# network_2_port_1 below at the update call
port = copy.deepcopy(port)
port.update(body['port'])

# the tenant ID is normally extracted from credentials in the request
# and is not present in the body
if 'tenant_id' not in port:
port['tenant_id'] = nova_fixtures.NeutronFixture.tenant_id

# similarly, these attributes are set by neutron itself
port['admin_state_up'] = True

self._ports[port['id']] = port
# this copy is here as nova sometimes modifies the returned port
# locally and we want to avoid that nova modifies the fixture internals


+ 64
- 1
nova/tests/functional/libvirt/test_pci_sriov_servers.py View File

@@ -74,6 +74,7 @@ class SRIOVServersTest(_PCIServersTestBase):
{
'vendor_id': fakelibvirt.PCI_VEND_ID,
'product_id': fakelibvirt.VF_PROD_ID,
'physical_network': 'physnet4',
},
)]
# PFs will be removed from pools unless they are specifically
@@ -168,12 +169,74 @@ class SRIOVServersTest(_PCIServersTestBase):
flavor_id=flavor_id_pfs, networks='none', expected_state='ERROR',
)

def test_create_server_with_neutron(self):
"""Create an instance using a neutron-provisioned SR-IOV VIF."""

pci_info = fakelibvirt.HostPCIDevicesInfo(num_pfs=1, num_vfs=2)

orig_create = nova.virt.libvirt.guest.Guest.create

def fake_create(cls, xml, host):
tree = etree.fromstring(xml)
elem = tree.find('./devices/interface/source/address')

# compare address
expected = ('0x81', '0x00', '0x2')
actual = (
elem.get('bus'), elem.get('slot'), elem.get('function'),
)
self.assertEqual(expected, actual)

return orig_create(xml, host)

self.stub_out(
'nova.virt.libvirt.guest.Guest.create',
fake_create,
)

self.start_compute(pci_info=pci_info)

# create the port
self.neutron.create_port({'port': self.neutron.network_4_port_1})

# ensure the binding details are currently unset
port = self.neutron.show_port(
base.LibvirtNeutronFixture.network_4_port_1['id'],
)['port']
self.assertNotIn('binding:profile', port)

# create a server using the VF via neutron
flavor_id = self._create_flavor()
self._create_server(
flavor_id=flavor_id,
networks=[
{'port': base.LibvirtNeutronFixture.network_4_port_1['id']},
],
)

# ensure the binding details sent to "neutron" were correct
port = self.neutron.show_port(
base.LibvirtNeutronFixture.network_4_port_1['id'],
)['port']
self.assertIn('binding:profile', port)
self.assertEqual(
{
'pci_vendor_info': '8086:1515',
'pci_slot': '0000:81:00.2',
'physical_network': 'physnet4',
},
port['binding:profile'],
)

def test_get_server_diagnostics_server_with_VF(self):
"""Ensure server disagnostics include info on VF-type PCI devices."""

pci_info = fakelibvirt.HostPCIDevicesInfo()
self.start_compute(pci_info=pci_info)

# create the SR-IOV port
self.neutron.create_port({'port': self.neutron.network_4_port_1})

# create a server using the VF and multiple networks
extra_spec = {'pci_passthrough:alias': f'{self.VFS_ALIAS_NAME}:1'}
flavor_id = self._create_flavor(extra_spec=extra_spec)
@@ -181,7 +244,7 @@ class SRIOVServersTest(_PCIServersTestBase):
flavor_id=flavor_id,
networks=[
{'uuid': base.LibvirtNeutronFixture.network_1['id']},
{'uuid': base.LibvirtNeutronFixture.network_4['id']},
{'port': base.LibvirtNeutronFixture.network_4_port_1['id']},
],
)



Loading…
Cancel
Save