From 5e4c9dec01cb841280e3e9e7a5b9473edd14c539 Mon Sep 17 00:00:00 2001 From: Diana Clarke Date: Tue, 26 Apr 2016 18:33:20 -0400 Subject: [PATCH] Fix database poison warnings, part 5 The following warning appears in the unit test logs a number of times. This patch fixes the last warnings in unit.compute.test_compute_api. "UserWarning: This test uses methods that set internal oslo_db state, but it does not claim to use the database. This will conflict with the setup of tests that do use the database and cause failures later." Note that this warning is only emitted once per unit test worker, so new offenders will show up in the logs each time you fix a test until they are all gone. Change-Id: I9f81e22fda8dbab2007aa7d2aa972b9dce364b5f Related-Bug: #1568414 --- nova/tests/unit/compute/test_compute_api.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/nova/tests/unit/compute/test_compute_api.py b/nova/tests/unit/compute/test_compute_api.py index 9260e6a7e25a..033c6e237799 100644 --- a/nova/tests/unit/compute/test_compute_api.py +++ b/nova/tests/unit/compute/test_compute_api.py @@ -53,7 +53,6 @@ from nova.tests.unit.image import fake as fake_image from nova.tests.unit import matchers from nova.tests.unit.objects import test_flavor from nova.tests.unit.objects import test_migration -from nova.tests.unit.objects import test_service from nova.tests import uuidsentinel as uuids from nova import utils from nova.volume import cinder @@ -954,7 +953,7 @@ class _ComputeAPIUnitTestMixIn(object): 'get_by_instance_uuid') self.mox.StubOutWithMock(quota.QUOTAS, 'reserve') self.mox.StubOutWithMock(self.context, 'elevated') - self.mox.StubOutWithMock(db, 'service_get_by_compute_host') + self.mox.StubOutWithMock(objects.Service, 'get_by_compute_host') self.mox.StubOutWithMock(self.compute_api.servicegroup_api, 'service_is_up') self.mox.StubOutWithMock(compute_utils, 'downsize_quota_delta') @@ -968,6 +967,7 @@ class _ComputeAPIUnitTestMixIn(object): self.mox.StubOutWithMock(compute_utils, 'notify_about_instance_usage') self.mox.StubOutWithMock(quota.QUOTAS, 'commit') + self.mox.StubOutWithMock(quota.QUOTAS, 'rollback') rpcapi = self.compute_api.compute_rpcapi self.mox.StubOutWithMock(rpcapi, 'confirm_resize') @@ -1015,9 +1015,8 @@ class _ComputeAPIUnitTestMixIn(object): soft_delete = True if inst.vm_state != vm_states.SHELVED_OFFLOADED: self.context.elevated().AndReturn(self.context) - db.service_get_by_compute_host( - self.context, inst.host).AndReturn( - test_service.fake_service) + objects.Service.get_by_compute_host(self.context, + inst.host).AndReturn(objects.Service()) self.compute_api.servicegroup_api.service_is_up( mox.IsA(objects.Service)).AndReturn( inst.host != 'down-host') @@ -1048,6 +1047,11 @@ class _ComputeAPIUnitTestMixIn(object): reservations=cast_reservations, delete_type=delete_type) + if soft_delete: + quota.QUOTAS.rollback(self.context, reservations, + project_id=inst.project_id, + user_id=inst.user_id) + if commit_quotas: # Local delete or when we're testing API cell. quota.QUOTAS.commit(self.context, reservations,