Add 'anon' kwarg to FakeDbBlockDeviceDict class
This will allow us to create fake block devices without the database id field, so we can pass them to BDM objects in our test which can then call create(). create() would normally error out if there is a DB id set on the object. Change-Id: I2d1f975633c8b2cb9e2e744c5f769b8f753b5968
This commit is contained in:
parent
c7a7ec7289
commit
f38a27c211
|
@ -22,16 +22,22 @@ from nova.openstack.common import timeutils
|
|||
class FakeDbBlockDeviceDict(block_device.BlockDeviceDict):
|
||||
"""Defaults db fields - useful for mocking database calls."""
|
||||
|
||||
def __init__(self, bdm_dict=None, **kwargs):
|
||||
def __init__(self, bdm_dict=None, anon=False, **kwargs):
|
||||
bdm_dict = bdm_dict or {}
|
||||
db_id = bdm_dict.pop('id', 1)
|
||||
instance_uuid = bdm_dict.pop('instance_uuid', str(uuid.uuid4()))
|
||||
|
||||
super(FakeDbBlockDeviceDict, self).__init__(bdm_dict=bdm_dict,
|
||||
**kwargs)
|
||||
fake_db_fields = {'id': db_id, 'instance_uuid': instance_uuid,
|
||||
'created_at': timeutils.utcnow(),
|
||||
'updated_at': timeutils.utcnow(),
|
||||
fake_db_fields = {'instance_uuid': instance_uuid,
|
||||
'deleted_at': None,
|
||||
'deleted': 0}
|
||||
if not anon:
|
||||
fake_db_fields['id'] = db_id
|
||||
fake_db_fields['created_at'] = timeutils.utcnow()
|
||||
fake_db_fields['updated_at'] = timeutils.utcnow()
|
||||
self.update(fake_db_fields)
|
||||
|
||||
|
||||
def AnonFakeDbBlockDeviceDict(bdm_dict, **kwargs):
|
||||
return FakeDbBlockDeviceDict(bdm_dict=bdm_dict, anon=True, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue