]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix _usage_from_snapshot in volume.utils
authorIlya Tyaptin <ityaptin@mirantis.com>
Thu, 6 Nov 2014 12:32:33 +0000 (16:32 +0400)
committerIlya Tyaptin <ityaptin@mirantis.com>
Thu, 22 Jan 2015 13:59:49 +0000 (13:59 +0000)
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

cinder/tests/test_volume_utils.py
cinder/volume/utils.py

index 2a1defa103ad90959486241fe79d35f1b5230974..978e7228e9574a08b37f73606ab70fe2a13d655d 100644 (file)
@@ -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')
index 89aa147b8c99cf11162432a171df3260ddf21b8c..11267c52502bf4acbbcb6e6f616d4af1e27db2ef 100644 (file)
@@ -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'],