diff --git a/cinder/api/contrib/resource_common_manage.py b/cinder/api/contrib/resource_common_manage.py index ca11172c860..01396516814 100644 --- a/cinder/api/contrib/resource_common_manage.py +++ b/cinder/api/contrib/resource_common_manage.py @@ -12,6 +12,8 @@ # License for the specific language governing permissions and limitations # under the License. +import oslo_messaging as messaging + from cinder.api import common from cinder import exception from cinder.i18n import _ @@ -39,10 +41,16 @@ def get_manageable_resources(req, is_detail, function_get_manageable, msg = _("Invalid sort dirs passed: %s") % ', '.join(invalid_dirs) raise exception.InvalidParameterValue(err=msg) - resources = function_get_manageable(context, host, cluster_name, - marker=marker, limit=limit, - offset=offset, sort_keys=sort_keys, - sort_dirs=sort_dirs) + try: + resources = function_get_manageable(context, host, cluster_name, + marker=marker, limit=limit, + offset=offset, sort_keys=sort_keys, + sort_dirs=sort_dirs) + except messaging.RemoteError as err: + if err.exc_type == "InvalidInput": + raise exception.InvalidInput(err.value) + raise + resource_count = len(resources) if is_detail: diff --git a/cinder/tests/unit/api/contrib/test_snapshot_manage.py b/cinder/tests/unit/api/contrib/test_snapshot_manage.py index bdf4cbea9e5..17cc03b1edd 100644 --- a/cinder/tests/unit/api/contrib/test_snapshot_manage.py +++ b/cinder/tests/unit/api/contrib/test_snapshot_manage.py @@ -15,6 +15,7 @@ import mock from oslo_config import cfg +import oslo_messaging as messaging from oslo_serialization import jsonutils try: from urllib import urlencode @@ -258,6 +259,15 @@ class SnapshotManageTest(test.TestCase): marker=None, offset=0, sort_dirs=['desc'], sort_keys=['reference']) + @mock.patch('cinder.volume.api.API.get_manageable_snapshots', + side_effect=messaging.RemoteError( + exc_type='InvalidInput', value='marker not found: 1234')) + def test_get_manageable_snapshots_non_existent_marker( + self, mock_api_manageable): + res = self._get_resp_get('fakehost', detailed=False, paging=True) + self.assertEqual(400, res.status_int) + self.assertTrue(mock_api_manageable.called) + @mock.patch('cinder.volume.api.API.get_manageable_snapshots', wraps=api_get_manageable_snapshots) def test_get_manageable_snapshots_detailed_ok(self, mock_api_manageable): @@ -280,6 +290,15 @@ class SnapshotManageTest(test.TestCase): self._admin_ctxt, 'fakehost', None, limit=10, marker='1234', offset=4, sort_dirs=['asc'], sort_keys=['reference']) + @mock.patch('cinder.volume.api.API.get_manageable_snapshots', + side_effect=messaging.RemoteError( + exc_type='InvalidInput', value='marker not found: 1234')) + def test_get_manageable_snapshots_non_existent_marker_detailed( + self, mock_api_manageable): + res = self._get_resp_get('fakehost', detailed=True, paging=True) + self.assertEqual(400, res.status_int) + self.assertTrue(mock_api_manageable.called) + @mock.patch('cinder.objects.service.Service.is_up', return_value=True) @mock.patch('cinder.db.sqlalchemy.api.service_get') def test_get_manageable_snapshots_disabled(self, mock_db, mock_is_up): diff --git a/cinder/tests/unit/api/contrib/test_volume_manage.py b/cinder/tests/unit/api/contrib/test_volume_manage.py index eaa87d17c09..aaeede066ca 100644 --- a/cinder/tests/unit/api/contrib/test_volume_manage.py +++ b/cinder/tests/unit/api/contrib/test_volume_manage.py @@ -16,6 +16,7 @@ import ddt import mock from oslo_config import cfg +import oslo_messaging as messaging from oslo_serialization import jsonutils try: from urllib import urlencode @@ -414,6 +415,15 @@ class VolumeManageTest(test.TestCase): self._admin_ctxt, 'fakehost', None, limit=10, marker='1234', offset=4, sort_dirs=['asc'], sort_keys=['reference']) + @mock.patch('cinder.volume.api.API.get_manageable_volumes', + side_effect=messaging.RemoteError( + exc_type='InvalidInput', value='marker not found: 1234')) + def test_get_manageable_volumes_non_existent_marker(self, + mock_api_manageable): + res = self._get_resp_get('fakehost', detailed=False, paging=True) + self.assertEqual(400, res.status_int) + self.assertTrue(mock_api_manageable.called) + @mock.patch('cinder.volume.api.API.get_manageable_volumes', wraps=api_get_manageable_volumes) def test_get_manageable_volumes_detailed_ok(self, mock_api_manageable): @@ -433,6 +443,15 @@ class VolumeManageTest(test.TestCase): marker=None, offset=0, sort_dirs=['desc'], sort_keys=['reference']) + @mock.patch('cinder.volume.api.API.get_manageable_volumes', + side_effect=messaging.RemoteError( + exc_type='InvalidInput', value='marker not found: 1234')) + def test_get_manageable_volumes_non_existent_marker_detailed( + self, mock_api_manageable): + res = self._get_resp_get('fakehost', detailed=True, paging=True) + self.assertEqual(400, res.status_int) + self.assertTrue(mock_api_manageable.called) + @ddt.data({'a' * 256: 'a'}, {'a': 'a' * 256}, {'': 'a'},