Add attachment_get call to volume/cinder_api
The new cinder v3 live-migrate code will need to query cinder to get the current connection information. This call is added to support that. The new cinder v3 migration flow will be made dependent on this change (review 463987). Partially Implements: blueprint cinder-new-attach-apis Change-Id: Ia5b9def46c687249803eaeb0dd60f6e18401dbb2
This commit is contained in:
parent
3268ddc557
commit
0fe0b94a83
@ -525,6 +525,48 @@ class CinderApiTestCase(test.NoDBTestCase):
|
||||
mock_cinderclient.assert_called_with(self.ctx)
|
||||
mock_volumes.detach.assert_called_once_with('id1', 'fakeid')
|
||||
|
||||
@mock.patch('nova.volume.cinder.cinderclient')
|
||||
def test_attachment_get(self, mock_cinderclient):
|
||||
mock_attachment = mock.MagicMock()
|
||||
mock_cinderclient.return_value = \
|
||||
mock.MagicMock(attachments=mock_attachment)
|
||||
|
||||
attachment_id = uuids.attachment
|
||||
self.api.attachment_get(self.ctx, attachment_id)
|
||||
|
||||
mock_cinderclient.assert_called_once_with(self.ctx, '3.44',
|
||||
skip_version_check=True)
|
||||
mock_attachment.show.assert_called_once_with(attachment_id)
|
||||
|
||||
@mock.patch('nova.volume.cinder.cinderclient')
|
||||
def test_attachment_get_failed(self, mock_cinderclient):
|
||||
mock_cinderclient.return_value.attachments.show.side_effect = (
|
||||
cinder_exception.NotFound(404, '404'))
|
||||
|
||||
attachment_id = uuids.attachment
|
||||
ex = self.assertRaises(exception.VolumeAttachmentNotFound,
|
||||
self.api.attachment_get,
|
||||
self.ctx,
|
||||
attachment_id)
|
||||
|
||||
self.assertEqual(404, ex.code)
|
||||
self.assertIn(attachment_id, six.text_type(ex))
|
||||
|
||||
@mock.patch('nova.volume.cinder.cinderclient',
|
||||
side_effect=exception.CinderAPIVersionNotAvailable(
|
||||
version='3.44'))
|
||||
def test_attachment_get_unsupported_api_version(self, mock_cinderclient):
|
||||
"""Tests that CinderAPIVersionNotAvailable is passed back.
|
||||
|
||||
If microversion 3.44 isn't available that should result in a
|
||||
CinderAPIVersionNotAvailable exception.
|
||||
"""
|
||||
self.assertRaises(exception.CinderAPIVersionNotAvailable,
|
||||
self.api.attachment_get,
|
||||
self.ctx, uuids.attachment_id)
|
||||
mock_cinderclient.assert_called_once_with(self.ctx, '3.44',
|
||||
skip_version_check=True)
|
||||
|
||||
@mock.patch('nova.volume.cinder.cinderclient')
|
||||
def test_initialize_connection(self, mock_cinderclient):
|
||||
connection_info = {'foo': 'bar'}
|
||||
|
@ -572,6 +572,31 @@ class API(object):
|
||||
'code': getattr(ex, 'code', None)},
|
||||
instance_uuid=instance_id)
|
||||
|
||||
@translate_attachment_exception
|
||||
def attachment_get(self, context, attachment_id):
|
||||
"""Gets a volume attachment.
|
||||
|
||||
:param context: The nova request context.
|
||||
:param attachment_id: UUID of the volume attachment to get.
|
||||
:returns: a dict created from the
|
||||
cinderclient.v3.attachments.VolumeAttachment object with a backward
|
||||
compatible connection_info dict
|
||||
"""
|
||||
try:
|
||||
attachment_ref = cinderclient(
|
||||
context, '3.44', skip_version_check=True).attachments.show(
|
||||
attachment_id)
|
||||
translated_attach_ref = _translate_attachment_ref(
|
||||
attachment_ref.to_dict())
|
||||
return translated_attach_ref
|
||||
except cinder_exception.ClientException as ex:
|
||||
with excutils.save_and_reraise_exception():
|
||||
LOG.error(('Show attachment failed for attachment '
|
||||
'%(id)s. Error: %(msg)s Code: %(code)s'),
|
||||
{'id': attachment_id,
|
||||
'msg': six.text_type(ex),
|
||||
'code': getattr(ex, 'code', None)})
|
||||
|
||||
@translate_attachment_exception
|
||||
def attachment_update(self, context, attachment_id, connector):
|
||||
"""Updates the connector on the volume attachment. An attachment
|
||||
|
Loading…
x
Reference in New Issue
Block a user