Skip to content

Commit d2a5fe5

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Convert features not supported error to HTTPBadRequest"
2 parents ec70a93 + 1b6a6e3 commit d2a5fe5

21 files changed

+163
-114
lines changed

nova/api/openstack/compute/attach_interfaces.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ def create(self, req, server_id, body):
180180
exception.ForbiddenPortsWithAccelerator) as e:
181181
raise exc.HTTPBadRequest(explanation=e.format_message())
182182
except (
183-
exception.OperationNotSupportedForVDPAInterface,
184183
exception.InstanceIsLocked,
185184
exception.FixedIpAlreadyInUse,
186185
exception.PortInUse,
@@ -218,10 +217,7 @@ def delete(self, req, server_id, id):
218217
instance, port_id=port_id)
219218
except exception.PortNotFound as e:
220219
raise exc.HTTPNotFound(explanation=e.format_message())
221-
except (
222-
exception.OperationNotSupportedForVDPAInterface,
223-
exception.InstanceIsLocked,
224-
) as e:
220+
except exception.InstanceIsLocked as e:
225221
raise exc.HTTPConflict(explanation=e.format_message())
226222
except NotImplementedError:
227223
common.raise_feature_not_supported()

nova/api/openstack/compute/evacuate.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,6 @@ def _evacuate(self, req, id, body):
130130
exception.ExtendedResourceRequestOldCompute,
131131
) as e:
132132
raise exc.HTTPBadRequest(explanation=e.format_message())
133-
except exception.ForbiddenWithAccelerators as e:
134-
raise exc.HTTPForbidden(explanation=e.format_message())
135-
except (
136-
exception.OperationNotSupportedForVTPM,
137-
exception.OperationNotSupportedForVDPAInterface,
138-
) as e:
139-
raise exc.HTTPConflict(explanation=e.format_message())
140133

141134
if (not api_version_request.is_supported(req, min_version='2.14') and
142135
CONF.api.enable_instance_password):

nova/api/openstack/compute/migrate_server.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ def _migrate(self, req, id, body):
5757
try:
5858
self.compute_api.resize(req.environ['nova.context'], instance,
5959
host_name=host_name)
60-
except (exception.TooManyInstances, exception.QuotaError,
61-
exception.ForbiddenWithAccelerators) as e:
60+
except (exception.TooManyInstances, exception.QuotaError) as e:
6261
raise exc.HTTPForbidden(explanation=e.format_message())
6362
except (
6463
exception.InstanceIsLocked,
6564
exception.InstanceNotReady,
6665
exception.ServiceUnavailable,
67-
exception.OperationNotSupportedForVDPAInterface,
6866
) as e:
6967
raise exc.HTTPConflict(explanation=e.format_message())
7068
except exception.InstanceInvalidState as state_error:
@@ -143,12 +141,6 @@ def _migrate_live(self, req, id, body):
143141
"'%(ex)s'", {'ex': ex})
144142
else:
145143
raise exc.HTTPBadRequest(explanation=ex.format_message())
146-
except (
147-
exception.OperationNotSupportedForSEV,
148-
exception.OperationNotSupportedForVTPM,
149-
exception.OperationNotSupportedForVDPAInterface,
150-
) as e:
151-
raise exc.HTTPConflict(explanation=e.format_message())
152144
except exception.InstanceIsLocked as e:
153145
raise exc.HTTPConflict(explanation=e.format_message())
154146
except (
@@ -159,8 +151,6 @@ def _migrate_live(self, req, id, body):
159151
except exception.InstanceInvalidState as state_error:
160152
common.raise_http_conflict_for_instance_invalid_state(state_error,
161153
'os-migrateLive', id)
162-
except exception.ForbiddenWithAccelerators as e:
163-
raise exc.HTTPForbidden(explanation=e.format_message())
164154

165155
def _get_force_param_for_live_migration(self, body, host):
166156
force = body["os-migrateLive"].get("force", False)

nova/api/openstack/compute/rescue.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ def _rescue(self, req, id, body):
6565
allow_bfv_rescue=allow_bfv_rescue)
6666
except (
6767
exception.InstanceIsLocked,
68-
exception.OperationNotSupportedForVTPM,
69-
exception.OperationNotSupportedForVDPAInterface,
7068
exception.InvalidVolume,
7169
) as e:
7270
raise exc.HTTPConflict(explanation=e.format_message())

nova/api/openstack/compute/servers.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,12 +1039,10 @@ def _resize(self, req, instance_id, flavor_id, auto_disk_config=None):
10391039
try:
10401040
self.compute_api.resize(context, instance, flavor_id,
10411041
auto_disk_config=auto_disk_config)
1042-
except (exception.QuotaError,
1043-
exception.ForbiddenWithAccelerators) as error:
1042+
except exception.QuotaError as error:
10441043
raise exc.HTTPForbidden(
10451044
explanation=error.format_message())
10461045
except (
1047-
exception.OperationNotSupportedForVDPAInterface,
10481046
exception.InstanceIsLocked,
10491047
exception.InstanceNotReady,
10501048
exception.MixedInstanceNotSupportByComputeService,
@@ -1067,7 +1065,6 @@ def _resize(self, req, instance_id, flavor_id, auto_disk_config=None):
10671065
exception.CannotResizeDisk,
10681066
exception.CannotResizeToSameFlavor,
10691067
exception.FlavorNotFound,
1070-
exception.ForbiddenPortsWithAccelerator,
10711068
exception.ExtendedResourceRequestOldCompute,
10721069
) as e:
10731070
raise exc.HTTPBadRequest(explanation=e.format_message())
@@ -1212,11 +1209,7 @@ def _action_rebuild(self, req, id, body):
12121209
image_href,
12131210
password,
12141211
**kwargs)
1215-
except (
1216-
exception.InstanceIsLocked,
1217-
exception.OperationNotSupportedForVTPM,
1218-
exception.OperationNotSupportedForVDPAInterface,
1219-
) as e:
1212+
except exception.InstanceIsLocked as e:
12201213
raise exc.HTTPConflict(explanation=e.format_message())
12211214
except exception.InstanceInvalidState as state_error:
12221215
common.raise_http_conflict_for_instance_invalid_state(state_error,
@@ -1230,8 +1223,7 @@ def _action_rebuild(self, req, id, body):
12301223
except exception.KeypairNotFound:
12311224
msg = _("Invalid key_name provided.")
12321225
raise exc.HTTPBadRequest(explanation=msg)
1233-
except (exception.QuotaError,
1234-
exception.ForbiddenWithAccelerators) as error:
1226+
except exception.QuotaError as error:
12351227
raise exc.HTTPForbidden(explanation=error.format_message())
12361228
except (exception.AutoDiskConfigDisabledByImage,
12371229
exception.CertificateValidationFailed,

nova/api/openstack/compute/shelve.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,9 @@ def _shelve(self, req, id, body):
4949
self.compute_api.shelve(context, instance)
5050
except (
5151
exception.InstanceIsLocked,
52-
exception.OperationNotSupportedForVTPM,
53-
exception.OperationNotSupportedForVDPAInterface,
5452
exception.UnexpectedTaskStateError,
5553
) as e:
5654
raise exc.HTTPConflict(explanation=e.format_message())
57-
except exception.ForbiddenWithAccelerators as e:
58-
raise exc.HTTPForbidden(explanation=e.format_message())
5955
except exception.InstanceInvalidState as state_error:
6056
common.raise_http_conflict_for_instance_invalid_state(state_error,
6157
'shelve', id)

nova/api/openstack/compute/suspend_server.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,11 @@ def _suspend(self, req, id, body):
3838
target={'user_id': server.user_id,
3939
'project_id': server.project_id})
4040
self.compute_api.suspend(context, server)
41-
except (
42-
exception.OperationNotSupportedForSEV,
43-
exception.OperationNotSupportedForVDPAInterface,
44-
exception.InstanceIsLocked,
45-
) as e:
41+
except exception.InstanceIsLocked as e:
4642
raise exc.HTTPConflict(explanation=e.format_message())
4743
except exception.InstanceInvalidState as state_error:
4844
common.raise_http_conflict_for_instance_invalid_state(state_error,
4945
'suspend', id)
50-
except exception.ForbiddenWithAccelerators as e:
51-
raise exc.HTTPForbidden(explanation=e.format_message())
5246
except exception.ForbiddenPortsWithAccelerator as e:
5347
raise exc.HTTPBadRequest(explanation=e.format_message())
5448

nova/api/openstack/compute/volumes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,7 @@ def create(self, req, server_id, body):
392392
except exception.VolumeNotFound as e:
393393
raise exc.HTTPNotFound(explanation=e.format_message())
394394
except (exception.InstanceIsLocked,
395-
exception.DevicePathInUse,
396-
exception.MultiattachNotSupportedByVirtDriver) as e:
395+
exception.DevicePathInUse) as e:
397396
raise exc.HTTPConflict(explanation=e.format_message())
398397
except exception.InstanceInvalidState as state_error:
399398
common.raise_http_conflict_for_instance_invalid_state(state_error,

nova/api/openstack/wsgi.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,15 @@ def wrapped(*args, **kwargs):
671671
# calls. ResourceExceptionHandler silently
672672
# converts NotAuthorized to HTTPForbidden
673673
raise
674+
elif isinstance(exc, exception.NotSupported):
675+
# Note(gmann): Special case to handle
676+
# NotSupported exceptions. We want to raise 400 BadRequest
677+
# for the NotSupported exception which is basically used
678+
# to raise for not supported features. Converting it here
679+
# will avoid converting every NotSupported inherited
680+
# exception in API controller.
681+
raise webob.exc.HTTPBadRequest(
682+
explanation=exc.format_message())
674683
elif isinstance(exc, exception.ValidationError):
675684
# Note(oomichi): Handle a validation error, which
676685
# happens due to invalid API parameters, as an

nova/exception.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,24 @@ class Forbidden(NovaException):
155155
code = 403
156156

157157

158-
class ForbiddenWithAccelerators(Forbidden):
159-
msg_fmt = _("Forbidden with instances that have accelerators.")
158+
class NotSupported(NovaException):
159+
# This exception use return code as 400 and can be used
160+
# directly or as base exception for operations whihc are not
161+
# supported in Nova. Any feature that is not yet implemented
162+
# but plan to implement in future (example: Cyborg
163+
# integration operations), should use this exception as base
164+
# and override the msg_fmt with feature details.
165+
# Example: MultiattachNotSupportedByVirtDriver exception.
166+
msg_fmt = _("Bad Request - Feature is not supported in Nova")
167+
code = 400
168+
160169

170+
class ForbiddenWithAccelerators(NotSupported):
171+
msg_fmt = _("Feature not supported with instances that have accelerators.")
161172

162-
class ForbiddenPortsWithAccelerator(Forbidden):
163-
msg_fmt = _("Forbidden with Ports that have accelerators.")
173+
174+
class ForbiddenPortsWithAccelerator(NotSupported):
175+
msg_fmt = _("Feature not supported with Ports that have accelerators.")
164176

165177

166178
class AdminRequired(Forbidden):
@@ -281,14 +293,13 @@ class VolumeExtendFailed(Invalid):
281293
"Reason: %(reason)s")
282294

283295

284-
class MultiattachNotSupportedByVirtDriver(NovaException):
296+
class MultiattachNotSupportedByVirtDriver(NotSupported):
285297
# This exception indicates the compute hosting the instance does not
286298
# support multiattach volumes. This should generally be considered a
287-
# 409 HTTPConflict error in the API since we expect all virt drivers to
299+
# 400 HTTPBadRequest error in the API since we expect all virt drivers to
288300
# eventually support multiattach volumes.
289301
msg_fmt = _("Volume %(volume_id)s has 'multiattach' set, "
290302
"which is not supported for this instance.")
291-
code = 409
292303

293304

294305
class MultiattachNotSupportedOldMicroversion(Invalid):
@@ -538,24 +549,21 @@ class UnableToMigrateToSelf(Invalid):
538549
"to current host (%(host)s).")
539550

540551

541-
class OperationNotSupportedForSEV(NovaException):
552+
class OperationNotSupportedForSEV(NotSupported):
542553
msg_fmt = _("Operation '%(operation)s' not supported for SEV-enabled "
543554
"instance (%(instance_uuid)s).")
544-
code = 409
545555

546556

547-
class OperationNotSupportedForVTPM(NovaException):
557+
class OperationNotSupportedForVTPM(NotSupported):
548558
msg_fmt = _("Operation '%(operation)s' not supported for vTPM-enabled "
549559
"instance (%(instance_uuid)s).")
550-
code = 409
551560

552561

553-
class OperationNotSupportedForVDPAInterface(NovaException):
562+
class OperationNotSupportedForVDPAInterface(NotSupported):
554563
msg_fmt = _(
555564
"Operation '%(operation)s' not supported for instance with "
556565
"vDPA ports ((instance_uuid)s)."
557566
)
558-
code = 409
559567

560568

561569
class InvalidHypervisorType(Invalid):

0 commit comments

Comments
 (0)