Fix ForbiddenWithAccelerators to HTTPForbidden for shelve API

ForbiddenWithAccelerators is not converted to HTTPForbidden unless
that is explicitly converted in API controller. For example:
- https://github.com/openstack/nova/blob/46899968619e4ea0ff2ab380977619bb29578d43/nova/api/openstack/compute/migrate_server.py#L154

Otherwise it end up raising 500 because ForbiddenWithAccelerators is
not inherrited from nova.exception.Forbidden
- https://github.com/openstack/nova/blob/46899968619e4ea0ff2ab380977619bb29578d43/nova/exception.py#L158

and expected_errors() decorator convert it to 500.
- https://github.com/openstack/nova/blob/46899968619e4ea0ff2ab380977619bb29578d43/nova/api/openstack/wsgi.py#L689

Except shelve API, all other APIs which can get
ForbiddenWithAccelerators via block_accelerators decorator convert it
explicitly.

If we inherit ForbiddenWithAccelerators from nova.exception.Forbidden
then expected_errors() decorator will take care of convertion to
HTTPForbidden automatically for all APIs.

Also adding tests for APIs can get ForbiddenWithAccelerators.

Change-Id: I9335ddb2d72909a110c313d5b609f2be279b18ef
This commit is contained in:
Ghanshyam Mann
2021-01-08 16:48:29 -06:00
committed by Brin Zhang
parent 67c76de5f4
commit cb56ae6aad
5 changed files with 38 additions and 2 deletions
@@ -300,6 +300,14 @@ class MigrateServerTestsV21(admin_only_action_common.CommonTests):
expected_exc=webob.exc.HTTPInternalServerError,
check_response=False)
@mock.patch('nova.compute.api.API.live_migrate',
side_effect=exception.ForbiddenWithAccelerators)
def test_live_migration_raises_http_forbidden(self, mock_migrate):
body = self._get_migration_body(host='hostname')
self.assertRaises(webob.exc.HTTPForbidden,
self.controller._migrate_live,
self.req, fakes.FAKE_UUID, body=body)
class MigrateServerTestsV225(MigrateServerTestsV21):