Fix database poison warnings, part 16

The following warning appears in the unit test logs a number of times.

    "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."

This patch fixes all the warnings from:

    nova.tests.unit.api.openstack.compute.test_shelve.py

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: I39cca6587f99cfe6f980b6d8fe857618fac6bb5a
Related-Bug: #1568414
This commit is contained in:
Diana Clarke 2016-09-24 15:40:15 -04:00
parent c983a6a2bc
commit 2f670bf40c
1 changed files with 12 additions and 17 deletions

View File

@ -21,12 +21,10 @@ import webob
from nova.api.openstack.compute import shelve as shelve_v21
from nova.compute import api as compute_api
from nova import exception
from nova import objects
from nova import policy
from nova import test
from nova.tests.unit.api.openstack import fakes
from nova.tests.unit import fake_instance
from nova.tests import uuidsentinel
class ShelvePolicyTestV21(test.NoDBTestCase):
@ -37,31 +35,28 @@ class ShelvePolicyTestV21(test.NoDBTestCase):
self.controller = self.plugin.ShelveController()
self.req = fakes.HTTPRequest.blank('')
@mock.patch('nova.objects.instance.Instance.get_by_uuid')
def test_shelve_locked_server(self, mock_instance_get):
instance = objects.Instance(
uuid=uuidsentinel.instance1,
project_id=self.req.environ['nova.context'].project_id,
user_id=self.req.environ['nova.context'].user_id)
mock_instance_get.return_value = instance
@mock.patch('nova.api.openstack.common.get_instance')
def test_shelve_locked_server(self, get_instance_mock):
get_instance_mock.return_value = (
fake_instance.fake_instance_obj(self.req.environ['nova.context']))
self.stubs.Set(compute_api.API, 'shelve',
fakes.fake_actions_to_locked_server)
self.assertRaises(webob.exc.HTTPConflict, self.controller._shelve,
self.req, str(uuid.uuid4()), {})
@mock.patch('nova.objects.instance.Instance.get_by_uuid')
def test_unshelve_locked_server(self, mock_instance_get):
instance = objects.Instance(uuid=uuidsentinel.instance1)
mock_instance_get.return_value = instance
@mock.patch('nova.api.openstack.common.get_instance')
def test_unshelve_locked_server(self, get_instance_mock):
get_instance_mock.return_value = (
fake_instance.fake_instance_obj(self.req.environ['nova.context']))
self.stubs.Set(compute_api.API, 'unshelve',
fakes.fake_actions_to_locked_server)
self.assertRaises(webob.exc.HTTPConflict, self.controller._unshelve,
self.req, str(uuid.uuid4()), {})
@mock.patch('nova.objects.instance.Instance.get_by_uuid')
def test_shelve_offload_locked_server(self, mock_instance_get):
instance = objects.Instance(uuid=uuidsentinel.instance1)
mock_instance_get.return_value = instance
@mock.patch('nova.api.openstack.common.get_instance')
def test_shelve_offload_locked_server(self, get_instance_mock):
get_instance_mock.return_value = (
fake_instance.fake_instance_obj(self.req.environ['nova.context']))
self.stubs.Set(compute_api.API, 'shelve_offload',
fakes.fake_actions_to_locked_server)
self.assertRaises(webob.exc.HTTPConflict,