Skip to content

Commit 0da447b

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Reproduce bug 1981813 in func env" into stable/xena
2 parents fe5aee0 + 0c87681 commit 0da447b

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

nova/tests/fixtures/libvirt.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,9 +2185,12 @@ def setUp(self):
21852185

21862186
# libvirt driver needs to call out to the filesystem to get the
21872187
# parent_ifname for the SRIOV VFs.
2188-
self.useFixture(fixtures.MockPatch(
2189-
'nova.pci.utils.get_ifname_by_pci_address',
2190-
return_value='fake_pf_interface_name'))
2188+
self.mock_get_ifname_by_pci_address = self.useFixture(
2189+
fixtures.MockPatch(
2190+
"nova.pci.utils.get_ifname_by_pci_address",
2191+
return_value="fake_pf_interface_name",
2192+
)
2193+
).mock
21912194

21922195
self.useFixture(fixtures.MockPatch(
21932196
'nova.pci.utils.get_mac_by_pci_address',

nova/tests/functional/libvirt/test_pci_sriov_servers.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import nova
3030
from nova import context
31+
from nova import exception
3132
from nova.network import constants
3233
from nova import objects
3334
from nova.objects import fields
@@ -944,6 +945,79 @@ def test_create_server_after_change_in_nonsriov_pf_to_sriov_pf(self):
944945
],
945946
)
946947

948+
def test_change_bound_port_vnic_type_kills_compute_at_restart(self):
949+
"""Create a server with a direct port and change the vnic_type of the
950+
bound port to macvtap. Then restart the compute service.
951+
952+
As the vnic_type is changed on the port but the vif_type is hwveb
953+
instead of macvtap the vif plug logic will try to look up the netdev
954+
of the parent VF. Howvere that VF consumed by the instance so the
955+
netdev does not exists. This causes that the compute service will fail
956+
with an exception during startup
957+
"""
958+
pci_info = fakelibvirt.HostPCIDevicesInfo(num_pfs=1, num_vfs=2)
959+
self.start_compute(pci_info=pci_info)
960+
961+
# create a direct port
962+
port = self.neutron.network_4_port_1
963+
self.neutron.create_port({'port': port})
964+
965+
# create a server using the VF via neutron
966+
server = self._create_server(networks=[{'port': port['id']}])
967+
968+
# update the vnic_type of the port in neutron
969+
port = copy.deepcopy(port)
970+
port['binding:vnic_type'] = 'macvtap'
971+
self.neutron.update_port(port['id'], {"port": port})
972+
973+
compute = self.computes['compute1']
974+
975+
# Force an update on the instance info cache to ensure nova gets the
976+
# information about the updated port
977+
with context.target_cell(
978+
context.get_admin_context(),
979+
self.host_mappings['compute1'].cell_mapping
980+
) as cctxt:
981+
compute.manager._heal_instance_info_cache(cctxt)
982+
983+
def fake_get_ifname_by_pci_address(pci_addr: str, pf_interface=False):
984+
# we want to fail the netdev lookup only if the pci_address is
985+
# already consumed by our instance. So we look into the instance
986+
# definition to see if the device is attached to the instance as VF
987+
conn = compute.manager.driver._host.get_connection()
988+
dom = conn.lookupByUUIDString(server['id'])
989+
dev = dom._def['devices']['nics'][0]
990+
lookup_addr = pci_addr.replace(':', '_').replace('.', '_')
991+
if (
992+
dev['type'] == 'hostdev' and
993+
dev['source'] == 'pci_' + lookup_addr
994+
):
995+
# nova tried to look up the netdev of an already consumed VF.
996+
# So we have to fail
997+
raise exception.PciDeviceNotFoundById(id=pci_addr)
998+
999+
# We need to simulate the actual failure manually as in our functional
1000+
# environment all the PCI lookup is mocked. In reality nova tries to
1001+
# look up the netdev of the pci device on the host used by the port as
1002+
# the parent of the macvtap. However, as the originally direct port is
1003+
# bound to the instance, the VF pci device is already consumed by the
1004+
# instance and therefore there is no netdev for the VF.
1005+
with mock.patch(
1006+
'nova.pci.utils.get_ifname_by_pci_address',
1007+
side_effect=fake_get_ifname_by_pci_address,
1008+
):
1009+
# This is bug 1981813 as the compute service fails to start with an
1010+
# exception.
1011+
# Nova cannot prevent the vnic_type change on a bound port. Neutron
1012+
# should prevent that instead. But the nova-compute should still
1013+
# be able to start up and only log an ERROR for this instance in
1014+
# inconsistent state.
1015+
self.assertRaises(
1016+
exception.PciDeviceNotFoundById,
1017+
self.restart_compute_service,
1018+
'compute1',
1019+
)
1020+
9471021

9481022
class SRIOVAttachDetachTest(_PCIServersTestBase):
9491023
# no need for aliases as these test will request SRIOV via neutron

0 commit comments

Comments
 (0)