From eadbacbda628ecc969a980378faf55bc02f514bf Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Thu, 7 Sep 2017 17:08:16 -0400 Subject: [PATCH] Drop support for the Cinder v2 API We deprecated support for the Cinder v2 API in Pike: Ice67d29f31aa5bd5c84fad4e828435d8552a9629 Enough time has passed that we can drop support for the v2 API and rely solely on the v3 API. Change-Id: Ibbc30b071f638114a4f0967a90c43b593bf47e1f --- nova/conf/cinder.py | 6 +-- nova/tests/unit/test_cinder.py | 45 +++++++++++++------ nova/tests/unit/volume/test_cinder.py | 11 ----- nova/volume/cinder.py | 26 ++++------- ...op-cinder-v2-support-d761d12d552616aa.yaml | 8 ++++ 5 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 releasenotes/notes/drop-cinder-v2-support-d761d12d552616aa.yaml diff --git a/nova/conf/cinder.py b/nova/conf/cinder.py index 133e9de039ff..955dd473bf13 100644 --- a/nova/conf/cinder.py +++ b/nova/conf/cinder.py @@ -33,7 +33,7 @@ Possible values: * Format is separated values of the form: :: -Note: Nova does not support the Cinder v1 API since the Nova 15.0.0 Ocata +Note: Nova does not support the Cinder v2 API since the Nova 17.0.0 Queens release. Related options: @@ -48,9 +48,9 @@ this template for cinder endpoint Possible values: * URL for cinder endpoint API - e.g. http://localhost:8776/v2/%(project_id)s + e.g. http://localhost:8776/v3/%(project_id)s -Note: Nova does not support the Cinder v1 API since the Nova 15.0.0 Ocata +Note: Nova does not support the Cinder v2 API since the Nova 17.0.0 Queens release. Related options: diff --git a/nova/tests/unit/test_cinder.py b/nova/tests/unit/test_cinder.py index 8b08d8b0fce1..4f3ca68cb40f 100644 --- a/nova/tests/unit/test_cinder.py +++ b/nova/tests/unit/test_cinder.py @@ -14,7 +14,7 @@ import collections -from cinderclient.v2 import client as cinder_client_v2 +from cinderclient.v3 import client as cinder_client_v3 import mock from requests_mock.contrib import fixture @@ -134,26 +134,45 @@ class CinderV1TestCase(test.NoDBTestCase): get_api_version.assert_called_once_with(get_endpoint.return_value) -class CinderV2TestCase(BaseCinderTestCase, test.NoDBTestCase): - """Test case for cinder volume v2 api.""" +# NOTE(mriedem): This does not extend BaseCinderTestCase because Cinder v2 is +# no longer supported, this is just to test that trying to use v2 fails. +class CinderV2TestCase(test.NoDBTestCase): - URL = "http://localhost:8776/v2/project_id" + @mock.patch('nova.volume.cinder.cinder_client.get_volume_api_from_url', + return_value='2') + def test_cinderclient_unsupported_v2(self, get_api_version): + """Tests that we fail if trying to use Cinder v2.""" + self.flags(catalog_info='volumev2:cinderv2:publicURL', group='cinder') + # setup mocks + get_endpoint = mock.Mock( + return_value='http://localhost:8776/v2/%(project_id)s') + fake_session = mock.Mock(get_endpoint=get_endpoint) + ctxt = context.get_admin_context() + with mock.patch.object(cinder, '_SESSION', fake_session): + self.assertRaises(exception.UnsupportedCinderAPIVersion, + cinder.cinderclient, ctxt) + get_api_version.assert_called_once_with(get_endpoint.return_value) + + +class CinderV3TestCase(BaseCinderTestCase, test.NoDBTestCase): + """Test case for cinder volume v3 api.""" + + URL = "http://localhost:8776/v3/project_id" CATALOG = [{ - "type": "volumev2", - "name": "cinder", + "type": "volumev3", + "name": "cinderv3", "endpoints": [{"publicURL": URL}] }] def setUp(self): - super(CinderV2TestCase, self).setUp() - CONF.set_override('catalog_info', - 'volumev2:cinder:publicURL', group='cinder') + super(CinderV3TestCase, self).setUp() self.addCleanup(CONF.reset) def create_client(self): - c = super(CinderV2TestCase, self).create_client() - self.assertIsInstance(c, cinder_client_v2.Client) + c = super(CinderV3TestCase, self).create_client() + self.assertIsInstance(c, cinder_client_v3.Client) + self.assertEqual('3.0', c.api_version.get_string()) return c def stub_volume(self, **kwargs): @@ -176,9 +195,9 @@ class CinderV2TestCase(BaseCinderTestCase, test.NoDBTestCase): return volume def test_cinder_endpoint_template(self): - endpoint = 'http://other_host:8776/v2/%(project_id)s' + endpoint = 'http://other_host:8776/v3/%(project_id)s' self.flags(endpoint_template=endpoint, group='cinder') - self.assertEqual('http://other_host:8776/v2/project_id', + self.assertEqual('http://other_host:8776/v3/project_id', self.create_client().client.endpoint_override) def test_get_non_existing_volume(self): diff --git a/nova/tests/unit/volume/test_cinder.py b/nova/tests/unit/volume/test_cinder.py index eba81e942f5a..ec1a21b9b607 100644 --- a/nova/tests/unit/volume/test_cinder.py +++ b/nova/tests/unit/volume/test_cinder.py @@ -840,17 +840,6 @@ class CinderClientTestCase(test.NoDBTestCase): get_volume_api.assert_called_once_with( self.mock_session.get_endpoint.return_value) - @mock.patch('cinderclient.client.get_volume_api_from_url', - return_value='2') - def test_create_v2_client_with_microversion_fails(self, get_volume_api): - """Tests that requesting a microversion against a v2 client will raise - an exception. - """ - self.assertRaises(exception.CinderAPIVersionNotAvailable, - cinder.cinderclient, self.ctxt, microversion='3.44') - get_volume_api.assert_called_once_with( - self.mock_session.get_endpoint.return_value) - @mock.patch('cinderclient.client.get_volume_api_from_url', return_value='3') @mock.patch('cinderclient.client.get_highest_client_server_version', diff --git a/nova/volume/cinder.py b/nova/volume/cinder.py index 756a871bd0a7..356f92db6b7a 100644 --- a/nova/volume/cinder.py +++ b/nova/volume/cinder.py @@ -120,25 +120,17 @@ def cinderclient(context, microversion=None, skip_version_check=False): # values. version = cinder_client.get_volume_api_from_url(url) - if version == '1': + if version != '3': raise exception.UnsupportedCinderAPIVersion(version=version) - if version == '2': - if microversion is not None: - # The Cinder v2 API does not support microversions. - raise exception.CinderAPIVersionNotAvailable(version=microversion) - LOG.warning("The support for the Cinder API v2 is deprecated, please " - "upgrade to Cinder API v3.") - - if version == '3': - version = '3.0' - # Check to see a specific microversion is requested and if so, can it - # be handled by the backing server. - if microversion is not None: - if skip_version_check: - version = microversion - else: - version = _check_microversion(url, microversion) + version = '3.0' + # Check to see a specific microversion is requested and if so, can it + # be handled by the backing server. + if microversion is not None: + if skip_version_check: + version = microversion + else: + version = _check_microversion(url, microversion) return cinder_client.Client(version, session=_SESSION, diff --git a/releasenotes/notes/drop-cinder-v2-support-d761d12d552616aa.yaml b/releasenotes/notes/drop-cinder-v2-support-d761d12d552616aa.yaml new file mode 100644 index 000000000000..689f8d043984 --- /dev/null +++ b/releasenotes/notes/drop-cinder-v2-support-d761d12d552616aa.yaml @@ -0,0 +1,8 @@ +--- +upgrade: + - | + Nova no longer supports the Block Storage (Cinder) v2 API. Ensure the + following configuration options are set properly for Cinder v3: + + - ``[cinder]/catalog_info`` - Already defaults to Cinder v3 + - ``[cinder]/endpoint_template`` - Not used by default.