Fix DB access by FormatMappingTestCase
Change I682a377d769312e8f37f874aa4548665b3b52ed3 made this test inherit from NoDBTestCase. However, this test does access the db if ec2utils.get_int_id_from_snapshot_uuid() can't return a value from its memo cache. That is, it was only passing due to fortunate test ordering which populated this cache in a previous test. If you ran the test isolated, it failed. This change mocks ec2utils.id_to_ec2_snap_id to return expected values without touching the db. Change-Id: I9e44f93dba5d56bf8c3dd3fda28a9b54eb95507f
This commit is contained in:
parent
8a6c418e13
commit
5cbe247e21
|
@ -3213,6 +3213,10 @@ class CloudTestCaseNeutronProxy(test.NoDBTestCase):
|
|||
class FormatMappingTestCase(test.NoDBTestCase):
|
||||
|
||||
def test_format_mapping(self):
|
||||
id_to_ec2_snap_id_map = {
|
||||
'993b31ac-452e-4fed-b745-7718385f1811': 'snap-00000001',
|
||||
'b409a2de-1c79-46bf-aa7e-ebdb4bf427ef': 'snap-00000002',
|
||||
}
|
||||
properties = {'block_device_mapping':
|
||||
[{'guest_format': None, 'boot_index': 0,
|
||||
'no_device': None, 'volume_id': None,
|
||||
|
@ -3244,7 +3248,6 @@ class FormatMappingTestCase(test.NoDBTestCase):
|
|||
'rootDeviceType': 'instance-store',
|
||||
'rootDeviceName': '/dev/vda',
|
||||
'imageType': 'machine', 'name': 'xb'}
|
||||
cloud._format_mappings(properties, result)
|
||||
expected = {'architecture': None,
|
||||
'blockDeviceMapping':
|
||||
[{'ebs': {'snapshotId': 'snap-00000002'}}],
|
||||
|
@ -3258,4 +3261,9 @@ class FormatMappingTestCase(test.NoDBTestCase):
|
|||
'name': 'xb',
|
||||
'rootDeviceName': '/dev/vda',
|
||||
'rootDeviceType': 'instance-store'}
|
||||
|
||||
with mock.patch.object(ec2utils, 'id_to_ec2_snap_id',
|
||||
lambda id: id_to_ec2_snap_id_map[id]):
|
||||
cloud._format_mappings(properties, result)
|
||||
|
||||
self.assertEqual(expected, result)
|
||||
|
|
Loading…
Reference in New Issue