'replication_extended_status': None,
'replication_driver_data': None,
'metadata': [],
+ 'volume_attachment': [],
}
self.assertDictMatch(expected, msg['payload'])
msg = self.notifier.notifications[1]
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',
'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)
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
pass
except exception.VolumeNotFound:
LOG.debug("Can not find volume %s at notify usage", volume_ref['id'])
+
return usage_info