Fix database poison warnings, part 2

The following warning appears in the unit test logs a number of times.
This patch fixes some of those warnings by stubbing at the object layer
rather than the database layer.

    "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: I29dca2fd07c7b106a51fb1608caa87b1a5548863
Related-Bug: #1568414
This commit is contained in:
Diana Clarke 2016-04-15 22:14:14 -04:00
parent 044edbe366
commit 2acc8960c5
1 changed files with 9 additions and 4 deletions

View File

@ -37,6 +37,7 @@ import nova.conf
from nova import context
from nova import exception
from nova import objects
from nova.objects import base
from nova import test
from nova.tests.unit.api.openstack import fakes
from nova.tests.unit import fake_block_device
@ -103,8 +104,9 @@ def fake_compute_volume_snapshot_create(self, context, volume_id,
pass
def fake_bdms_get_all_by_instance(context, instance_uuid, use_slave=False):
return [fake_block_device.FakeDbBlockDeviceDict(
@classmethod
def fake_bdm_list_get_by_instance_uuid(cls, context, instance_uuid):
db_list = [fake_block_device.FakeDbBlockDeviceDict(
{'id': 1,
'instance_uuid': instance_uuid,
'device_name': '/dev/fake0',
@ -124,6 +126,8 @@ def fake_bdms_get_all_by_instance(context, instance_uuid, use_slave=False):
'snapshot_id': None,
'volume_id': FAKE_UUID_B,
'volume_size': 1})]
item_cls = objects.BlockDeviceMapping
return base.obj_make_list(context, cls(), item_cls, db_list)
class BootFromVolumeTest(test.TestCase):
@ -357,8 +361,9 @@ class VolumeAttachTestsV21(test.NoDBTestCase):
def setUp(self):
super(VolumeAttachTestsV21, self).setUp()
self.stub_out('nova.db.block_device_mapping_get_all_by_instance',
fake_bdms_get_all_by_instance)
self.stub_out('nova.objects.BlockDeviceMappingList'
'.get_by_instance_uuid',
fake_bdm_list_get_by_instance_uuid)
self.stubs.Set(compute_api.API, 'get', fake_get_instance)
self.stubs.Set(cinder.API, 'get', fake_get_volume)
self.context = context.get_admin_context()