summaryrefslogtreecommitdiff
path: root/nova/tests/unit/volume
diff options
context:
space:
mode:
authorIldiko Vancsa <ildiko.vancsa@gmail.com>2017-08-12 17:06:36 +0200
committerIldiko Vancsa <ildiko.vancsa@gmail.com>2017-09-12 20:46:56 -0600
commita3dab72f19e5792e0c0749405e81d5126eabca4d (patch)
treee4719a41419dcbc61ac119b7aed763d8fdac8120 /nova/tests/unit/volume
parent2933f408ee335de624e6176f9cde296afb2a4078 (diff)
downloadnova-a3dab72f19e5792e0c0749405e81d5126eabca4d.tar.gz
Add attachment_complete call to volume/cinder.py
In order to tell Cinder that connecting a volume on the Nova side is completed we need to use a new API call which is a recent addition to the new attach/detach API. As this call is essential to finalizing the attachments we need to bump the minimum required microversion to '3.44' for all the new attach/detach API calls so we have attachment_complete available. Partially Implements: blueprint cinder-new-attach-apis Depends-On: I57631d3deddb2d7cd244584e82206ee17fe2dd78 Depends-On: I3b28d2cb89a8d81c7cdec425f355c78bfdfe3450 Depends-On: I9de10bb5188ad778f06bb59e7f08f2b49089c1da Change-Id: Ia2102f1d47a764819c86972866efcfd1c2be7d0d
Diffstat (limited to 'nova/tests/unit/volume')
-rw-r--r--nova/tests/unit/volume/test_cinder.py75
1 files changed, 59 insertions, 16 deletions
diff --git a/nova/tests/unit/volume/test_cinder.py b/nova/tests/unit/volume/test_cinder.py
index 914d853b7d..86f202c7cd 100644
--- a/nova/tests/unit/volume/test_cinder.py
+++ b/nova/tests/unit/volume/test_cinder.py
@@ -323,16 +323,16 @@ class CinderApiTestCase(test.NoDBTestCase):
@mock.patch('nova.volume.cinder.cinderclient',
side_effect=exception.CinderAPIVersionNotAvailable(
- version='3.27'))
+ version='3.44'))
def test_attachment_create_unsupported_api_version(self,
mock_cinderclient):
"""Tests that CinderAPIVersionNotAvailable is passed back through
- if 3.27 isn't available.
+ if 3.44 isn't available.
"""
self.assertRaises(exception.CinderAPIVersionNotAvailable,
self.api.attachment_create,
self.ctx, uuids.volume_id, uuids.instance_id)
- mock_cinderclient.assert_called_once_with(self.ctx, '3.27')
+ mock_cinderclient.assert_called_once_with(self.ctx, '3.44')
@mock.patch('nova.volume.cinder.cinderclient')
def test_attachment_update(self, mock_cinderclient):
@@ -379,16 +379,16 @@ class CinderApiTestCase(test.NoDBTestCase):
@mock.patch('nova.volume.cinder.cinderclient',
side_effect=exception.CinderAPIVersionNotAvailable(
- version='3.27'))
+ version='3.44'))
def test_attachment_update_unsupported_api_version(self,
mock_cinderclient):
"""Tests that CinderAPIVersionNotAvailable is passed back through
- if 3.27 isn't available.
+ if 3.44 isn't available.
"""
self.assertRaises(exception.CinderAPIVersionNotAvailable,
self.api.attachment_update,
self.ctx, uuids.attachment_id, connector={})
- mock_cinderclient.assert_called_once_with(self.ctx, '3.27',
+ mock_cinderclient.assert_called_once_with(self.ctx, '3.44',
skip_version_check=True)
@mock.patch('nova.volume.cinder.cinderclient')
@@ -400,7 +400,7 @@ class CinderApiTestCase(test.NoDBTestCase):
attachment_id = uuids.attachment
self.api.attachment_delete(self.ctx, attachment_id)
- mock_cinderclient.assert_called_once_with(self.ctx, '3.27',
+ mock_cinderclient.assert_called_once_with(self.ctx, '3.44',
skip_version_check=True)
mock_attachments.delete.assert_called_once_with(attachment_id)
@@ -421,16 +421,59 @@ class CinderApiTestCase(test.NoDBTestCase):
@mock.patch('nova.volume.cinder.cinderclient',
side_effect=exception.CinderAPIVersionNotAvailable(
- version='3.27'))
+ version='3.44'))
def test_attachment_delete_unsupported_api_version(self,
mock_cinderclient):
"""Tests that CinderAPIVersionNotAvailable is passed back through
- if 3.27 isn't available.
+ if 3.44 isn't available.
"""
self.assertRaises(exception.CinderAPIVersionNotAvailable,
self.api.attachment_delete,
self.ctx, uuids.attachment_id)
- mock_cinderclient.assert_called_once_with(self.ctx, '3.27',
+ mock_cinderclient.assert_called_once_with(self.ctx, '3.44',
+ skip_version_check=True)
+
+ @mock.patch('nova.volume.cinder.cinderclient')
+ def test_attachment_complete(self, mock_cinderclient):
+ mock_attachments = mock.MagicMock()
+ mock_cinderclient.return_value = \
+ mock.MagicMock(attachments=mock_attachments)
+
+ attachment_id = uuids.attachment
+ self.api.attachment_complete(self.ctx, attachment_id)
+
+ mock_cinderclient.assert_called_once_with(self.ctx, '3.44',
+ skip_version_check=True)
+ mock_attachments.complete.assert_called_once_with(attachment_id)
+
+ @mock.patch('nova.volume.cinder.cinderclient')
+ def test_attachment_complete_failed(self, mock_cinderclient):
+ mock_cinderclient.return_value.attachments.complete.side_effect = (
+ cinder_exception.NotFound(404, '404'))
+
+ attachment_id = uuids.attachment
+ ex = self.assertRaises(exception.VolumeAttachmentNotFound,
+ self.api.attachment_complete,
+ 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_complete_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_complete,
+ 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')
@@ -801,7 +844,7 @@ class CinderClientTestCase(test.NoDBTestCase):
an exception.
"""
self.assertRaises(exception.CinderAPIVersionNotAvailable,
- cinder.cinderclient, self.ctxt, microversion='3.27')
+ cinder.cinderclient, self.ctxt, microversion='3.44')
get_volume_api.assert_called_once_with(
self.mock_session.get_endpoint.return_value)
@@ -817,7 +860,7 @@ class CinderClientTestCase(test.NoDBTestCase):
exception.
"""
self.assertRaises(exception.CinderAPIVersionNotAvailable,
- cinder.cinderclient, self.ctxt, microversion='3.27')
+ cinder.cinderclient, self.ctxt, microversion='3.44')
get_volume_api.assert_called_once_with(
self.mock_session.get_endpoint.return_value)
get_highest_version.assert_called_once_with(
@@ -834,8 +877,8 @@ class CinderClientTestCase(test.NoDBTestCase):
is available in the server and supported by the client will result in
creating a Client object with the requested microversion.
"""
- client = cinder.cinderclient(self.ctxt, microversion='3.27')
- self.assertEqual(cinder_api_versions.APIVersion('3.27'),
+ client = cinder.cinderclient(self.ctxt, microversion='3.44')
+ self.assertEqual(cinder_api_versions.APIVersion('3.44'),
client.api_version)
get_volume_api.assert_called_once_with(
self.mock_session.get_endpoint.return_value)
@@ -851,9 +894,9 @@ class CinderClientTestCase(test.NoDBTestCase):
"""Tests that creating a v3 client and requesting a microversion
but asking to skip the version discovery check is honored.
"""
- client = cinder.cinderclient(self.ctxt, microversion='3.27',
+ client = cinder.cinderclient(self.ctxt, microversion='3.44',
skip_version_check=True)
- self.assertEqual(cinder_api_versions.APIVersion('3.27'),
+ self.assertEqual(cinder_api_versions.APIVersion('3.44'),
client.api_version)
get_volume_api.assert_called_once_with(
self.mock_session.get_endpoint.return_value)