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
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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'],
|
||||
|
||||
Reference in New Issue
Block a user