Return most specific error instead of 404
Particularly for client-side errors, we ought to at least return the actual error status instead of a generic 404. Enablement of negative Tempest tests. Change-Id: Ieaf658c9bd202dbb5000c10c43bdd1afa15a2aa1
This commit is contained in:
parent
4c9fbc0e6c
commit
22f45add29
|
@ -12,6 +12,8 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import collections
|
||||
import six
|
||||
import requests
|
||||
import flask
|
||||
|
||||
|
@ -231,21 +233,33 @@ class RequestHandler(object):
|
|||
if not CONF.search_by_broadcast:
|
||||
return self._local_forward()
|
||||
|
||||
errors = collections.defaultdict(lambda: [])
|
||||
for sp in self.enabled_sps:
|
||||
if sp == 'default':
|
||||
response = self._do_request_on('default')
|
||||
if 200 <= response.status_code < 300:
|
||||
return self._finalize(response)
|
||||
else:
|
||||
errors[response.status_code].append(response)
|
||||
else:
|
||||
self.service_provider = sp
|
||||
for p in auth.get_projects_at_sp(sp, self.details['token']):
|
||||
response = self._do_request_on(sp, p)
|
||||
if 200 <= response.status_code < 300:
|
||||
return self._finalize(response)
|
||||
return flask.Response(
|
||||
"Not found\n.",
|
||||
404
|
||||
)
|
||||
else:
|
||||
errors[response.status_code].append(response)
|
||||
|
||||
if six.viewkeys(errors) == {404}:
|
||||
return self._finalize(errors[404][0])
|
||||
else:
|
||||
utils.safe_pop(errors, 404)
|
||||
|
||||
if len(errors.keys()) == 1:
|
||||
return self._finalize(list(errors.values())[0][0])
|
||||
|
||||
# TODO(jfreud): log
|
||||
return flask.Response("Something strange happened.\n", 500)
|
||||
|
||||
def _aggregate_forward(self):
|
||||
if not CONF.aggregation:
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
negative
|
||||
Negative
|
||||
tempest.api.image.admin.v2.test_images.BasicAdminOperationsImagesTest.test_admin_deactivate_reactivate_image
|
||||
tempest.api.image.v2.test_images_metadefs_namespaces.MetadataNamespacesTest.test_basic_metadata_definition_namespaces
|
||||
tempest.api.volume.admin.v3.test_user_messages.UserMessagesTest.test_delete_message
|
||||
|
|
|
@ -167,7 +167,7 @@ class TestImages(base.BaseTest):
|
|||
headers=self.auth.get_headers()
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 404)
|
||||
self.assertEqual(response.status_code, 500)
|
||||
|
||||
def test_list_images(self):
|
||||
self.requests_fixture.get(
|
||||
|
|
Loading…
Reference in New Issue