From bb2b7cad294bebd6b3bdd6d10043c3c2fb038140 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Fri, 13 Sep 2019 14:58:49 -0400 Subject: [PATCH] Use SpawnIsSynchronousFixture in reschedule functional tests We see that in successful tests that are usually running some kind of negative or reschedule scenario that they will dump a stacktrace to the subunit output buffer because _allocate_network_async will raise an error. Too many of these can eventually blow up the subunit output buffer and cause tests to fail. To guard against this, we use the SpawnIsSynchronousFixture in the base class of two known test classes [1][2] that show a stacktace with _allocate_network_async in successful runs. As a result, one of the tests has to be fixed due to improper stubbing. [1] UnsupportedPortResourceRequestBasedSchedulingTest [2] PortResourceRequestReSchedulingTest Change-Id: Ib18ecaebbeccc9c9cea32ca8949175fcea0414ac Related-Bug: #1813147 --- nova/tests/functional/test_servers.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/nova/tests/functional/test_servers.py b/nova/tests/functional/test_servers.py index 54e9a035ffc5..bf91918c8267 100644 --- a/nova/tests/functional/test_servers.py +++ b/nova/tests/functional/test_servers.py @@ -36,6 +36,7 @@ from nova.compute import instance_actions from nova.compute import manager as compute_manager from nova import context from nova import exception +from nova.network.neutronv2 import api as neutronapi from nova.network.neutronv2 import constants from nova import objects from nova.objects import block_device as block_device_obj @@ -5506,6 +5507,9 @@ class PortResourceRequestBasedSchedulingTestBase( FakeDriverWithPciResourcesConfigFixture()) super(PortResourceRequestBasedSchedulingTestBase, self).setUp() + # Make ComputeManager._allocate_network_async synchronous to detect + # errors in tests that involve rescheduling. + self.useFixture(nova_fixtures.SpawnIsSynchronousFixture()) self.compute1 = self._start_compute('host1') self.compute1_rp_uuid = self._get_provider_uuid_by_host('host1') self.ovs_bridge_rp_per_host = {} @@ -6800,15 +6804,17 @@ class PortResourceRequestReSchedulingTest( # First call is during boot, we want that to succeed normally. Then the # fake virt driver triggers a re-schedule. During that re-schedule the # fill is called again, and we simulate that call raises. - fill = nova.scheduler.utils.fill_provider_mapping + original_fill = nova.scheduler.utils.fill_provider_mapping + + def stub_fill_provider_mapping(*args, **kwargs): + if not mock_fill.called: + return original_fill(*args, **kwargs) + raise exception.ResourceProviderTraitRetrievalFailed( + uuid=uuids.rp1) with mock.patch( 'nova.scheduler.utils.fill_provider_mapping', - side_effect=[ - fill, - exception.ResourceProviderTraitRetrievalFailed( - uuid=uuids.rp1)], - autospec=True): + side_effect=stub_fill_provider_mapping) as mock_fill: server = self._create_server( flavor=self.flavor, networks=[{'port': port['id']}]) @@ -6823,5 +6829,5 @@ class PortResourceRequestReSchedulingTest( # assert that unbind removes the allocation from the binding updated_port = self.neutron.show_port(port['id'])['port'] - binding_profile = updated_port['binding:profile'] + binding_profile = neutronapi.get_binding_profile(updated_port) self.assertNotIn('allocation', binding_profile)