Merge "Add volume_attachment to volume usage notifications"
This commit is contained in:
commit
d620337353
@ -537,6 +537,7 @@ class VolumeTestCase(BaseVolumeTestCase):
|
||||
'replication_extended_status': None,
|
||||
'replication_driver_data': None,
|
||||
'metadata': [],
|
||||
'volume_attachment': [],
|
||||
}
|
||||
self.assertDictMatch(expected, msg['payload'])
|
||||
msg = self.notifier.notifications[1]
|
||||
|
@ -223,8 +223,10 @@ class NotifyUsageTestCase(test.TestCase):
|
||||
self.assertEqual(expected_snapshot, usage_info)
|
||||
|
||||
@mock.patch('cinder.db.volume_glance_metadata_get')
|
||||
def test_usage_from_volume(self, mock_image_metadata):
|
||||
@mock.patch('cinder.db.volume_attachment_get_used_by_volume_id')
|
||||
def test_usage_from_volume(self, mock_attachment, mock_image_metadata):
|
||||
mock_image_metadata.return_value = {'image_id': 'fake_image_id'}
|
||||
mock_attachment.return_value = [{'instance_uuid': 'fake_instance_id'}]
|
||||
raw_volume = {
|
||||
'project_id': '12b0330ec2584a',
|
||||
'user_id': '158cba1b8c2bb6008e',
|
||||
@ -264,6 +266,7 @@ class NotifyUsageTestCase(test.TestCase):
|
||||
'status': 'available',
|
||||
'metadata': {'fake_metadata_key': 'fake_metadata_value'},
|
||||
'glance_metadata': {'image_id': 'fake_image_id'},
|
||||
'volume_attachment': [{'instance_uuid': 'fake_instance_id'}],
|
||||
}
|
||||
self.assertEqual(expected_volume, usage_info)
|
||||
|
||||
|
@ -68,6 +68,10 @@ def _usage_from_volume(context, volume_ref, **kw):
|
||||
|
||||
usage_info.update(kw)
|
||||
try:
|
||||
attachments = db.volume_attachment_get_used_by_volume_id(
|
||||
context, volume_ref['id'])
|
||||
usage_info['volume_attachment'] = attachments
|
||||
|
||||
glance_meta = db.volume_glance_metadata_get(context, volume_ref['id'])
|
||||
if glance_meta:
|
||||
usage_info['glance_metadata'] = glance_meta
|
||||
@ -75,6 +79,7 @@ def _usage_from_volume(context, volume_ref, **kw):
|
||||
pass
|
||||
except exception.VolumeNotFound:
|
||||
LOG.debug("Can not find volume %s at notify usage", volume_ref['id'])
|
||||
|
||||
return usage_info
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user