From 5cbe247e2190d2659c32c8c86b378954c5035815 Mon Sep 17 00:00:00 2001 From: Matthew Booth Date: Wed, 18 Feb 2015 13:47:12 +0000 Subject: [PATCH] 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 --- nova/tests/unit/api/ec2/test_cloud.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nova/tests/unit/api/ec2/test_cloud.py b/nova/tests/unit/api/ec2/test_cloud.py index 24069d27387a..222a0c3f0580 100644 --- a/nova/tests/unit/api/ec2/test_cloud.py +++ b/nova/tests/unit/api/ec2/test_cloud.py @@ -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)