From: Ilya Tyaptin Date: Thu, 6 Nov 2014 12:32:33 +0000 (+0400) Subject: Fix _usage_from_snapshot in volume.utils X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ad5d20a26628cbd5266645a73b98970934a5e6d2;p=openstack-build%2Fcinder-build.git Fix _usage_from_snapshot in volume.utils Now in this function we trying to get snapshot_ref.volume for collecting 'availability_zone'. It's invalid because snapshot_ref in this function is __dict__. In this patchset there is fix for it. Change-Id: I4cb86c0efd7520904fdf2288048d07cc40ed3a13 Closes-bug: #1390064 --- diff --git a/cinder/tests/test_volume_utils.py b/cinder/tests/test_volume_utils.py index 2a1defa10..978e7228e 100644 --- a/cinder/tests/test_volume_utils.py +++ b/cinder/tests/test_volume_utils.py @@ -193,6 +193,36 @@ class NotifyUsageTestCase(test.TestCase): 'snapshot.test_suffix', mock_usage.return_value) + def test_usage_from_snapshot(self): + raw_snapshot = { + 'project_id': '12b0330ec2584a', + 'user_id': '158cba1b8c2bb6008e', + 'volume': {'availability_zone': 'nova'}, + 'volume_id': '55614621', + 'volume_size': 1, + 'id': '343434a2', + 'display_name': '11', + 'created_at': '2014-12-11T10:10:00', + 'status': 'pause', + 'deleted': '', + } + usage_info = volume_utils._usage_from_snapshot( + mock.sentinel.context, + raw_snapshot) + expected_snapshot = { + 'tenant_id': '12b0330ec2584a', + 'user_id': '158cba1b8c2bb6008e', + 'availability_zone': 'nova', + 'volume_id': '55614621', + 'volume_size': 1, + 'snapshot_id': '343434a2', + 'display_name': '11', + 'created_at': '2014-12-11T10:10:00', + 'status': 'pause', + 'deleted': '', + } + self.assertEqual(expected_snapshot, usage_info) + @mock.patch('cinder.volume.utils._usage_from_consistencygroup') @mock.patch('cinder.volume.utils.CONF') @mock.patch('cinder.volume.utils.rpc') diff --git a/cinder/volume/utils.py b/cinder/volume/utils.py index 89aa147b8..11267c525 100644 --- a/cinder/volume/utils.py +++ b/cinder/volume/utils.py @@ -120,7 +120,7 @@ def _usage_from_snapshot(context, snapshot_ref, **extra_usage_info): usage_info = { 'tenant_id': snapshot_ref['project_id'], 'user_id': snapshot_ref['user_id'], - 'availability_zone': snapshot_ref.volume['availability_zone'], + 'availability_zone': snapshot_ref['volume']['availability_zone'], 'volume_id': snapshot_ref['volume_id'], 'volume_size': snapshot_ref['volume_size'], 'snapshot_id': snapshot_ref['id'],