diff options
Diffstat (limited to 'nova/tests/functional/regressions/test_bug_1781286.py')
-rw-r--r-- | nova/tests/functional/regressions/test_bug_1781286.py | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/nova/tests/functional/regressions/test_bug_1781286.py b/nova/tests/functional/regressions/test_bug_1781286.py index 05771f4b42..c123fd9214 100644 --- a/nova/tests/functional/regressions/test_bug_1781286.py +++ b/nova/tests/functional/regressions/test_bug_1781286.py @@ -67,11 +67,11 @@ class RescheduleBuildAvailabilityZoneUpCall( def wrap_bari(*args, **kwargs): # Poison the AZ query to blow up as if the cell conductor does not # have access to the API DB. - patcher = mock.patch('nova.objects.AggregateList.get_by_host', - side_effect=oslo_db_exc.CantStartEngineError) - patcher.start() - self.addCleanup(patcher.stop) - return original_bari(*args, **kwargs) + with mock.patch( + 'nova.objects.AggregateList.get_by_host', + side_effect=oslo_db_exc.CantStartEngineError + ): + return original_bari(*args, **kwargs) self.stub_out('nova.compute.manager.ComputeManager.' 'build_and_run_instance', wrap_bari) @@ -81,10 +81,6 @@ class RescheduleBuildAvailabilityZoneUpCall( # compute service we have to wait for the notification that the build # is complete and then stop the mock so we can use the API again. self.notifier.wait_for_versioned_notifications('instance.create.end') - # Note that we use stopall here because we actually called - # build_and_run_instance twice so we have more than one instance of - # the mock that needs to be stopped. - mock.patch.stopall() server = self._wait_for_state_change(server, 'ACTIVE') # We should have rescheduled and the instance AZ should be set from the # Selection object. Since neither compute host is in an AZ, the server @@ -128,20 +124,20 @@ class RescheduleMigrateAvailabilityZoneUpCall( self.rescheduled = None def wrap_prep_resize(_self, *args, **kwargs): - # Poison the AZ query to blow up as if the cell conductor does not - # have access to the API DB. - patcher = mock.patch('nova.objects.AggregateList.get_by_host', - side_effect=oslo_db_exc.CantStartEngineError) - self.agg_mock = patcher.start() - self.addCleanup(patcher.stop) - if self.rescheduled is None: # Track the first host that we rescheduled from. self.rescheduled = _self.host # Trigger a reschedule. raise exception.ComputeResourcesUnavailable( reason='test_migrate_reschedule_blocked_az_up_call') - return original_prep_resize(_self, *args, **kwargs) + # Poison the AZ query to blow up as if the cell conductor does not + # have access to the API DB. + with mock.patch( + 'nova.objects.AggregateList.get_by_host', + side_effect=oslo_db_exc.CantStartEngineError, + ) as agg_mock: + self.agg_mock = agg_mock + return original_prep_resize(_self, *args, **kwargs) self.stub_out('nova.compute.manager.ComputeManager._prep_resize', wrap_prep_resize) |