Skip to content

Commit 81cf1b8

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Handle PortLimitExceeded in POST /servers/{server_id}/os-interface" into stable/stein
2 parents 32554e8 + 43926eb commit 81cf1b8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

nova/api/openstack/compute/attach_interfaces.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def show(self, req, server_id, id):
133133
context, port_info['port'],
134134
show_tag=api_version_request.is_supported(req, '2.70'))}
135135

136-
@wsgi.expected_errors((400, 404, 409, 500, 501))
136+
@wsgi.expected_errors((400, 403, 404, 409, 500, 501))
137137
@validation.schema(attach_interfaces.create, '2.0', '2.48')
138138
@validation.schema(attach_interfaces.create_v249, '2.49')
139139
def create(self, req, server_id, body):
@@ -183,6 +183,8 @@ def create(self, req, server_id, body):
183183
except (exception.PortNotFound,
184184
exception.NetworkNotFound) as e:
185185
raise exc.HTTPNotFound(explanation=e.format_message())
186+
except exception.PortLimitExceeded as e:
187+
raise exc.HTTPForbidden(explanation=e.format_message())
186188
except exception.InterfaceAttachFailed as e:
187189
raise webob.exc.HTTPInternalServerError(
188190
explanation=e.format_message())

nova/tests/unit/api/openstack/compute/test_attach_interfaces.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# under the License.
1515

1616
import mock
17+
import six
1718
from webob import exc
1819

1920
from nova.api.openstack import common
@@ -308,6 +309,20 @@ def fake_attach_interface_invalid_state(*args, **kwargs):
308309
self.attachments.create, self.req, FAKE_UUID1,
309310
body=body)
310311

312+
def test_attach_interface_port_limit_exceeded(self):
313+
"""Tests the scenario where nova-compute attempts to create a port to
314+
attach but the tenant port quota is exceeded and PortLimitExceeded
315+
is raised from the neutron API code which results in a 403 response.
316+
"""
317+
with mock.patch.object(self.attachments.compute_api,
318+
'attach_interface',
319+
side_effect=exception.PortLimitExceeded):
320+
body = {'interfaceAttachment': {}}
321+
ex = self.assertRaises(
322+
exc.HTTPForbidden, self.attachments.create,
323+
self.req, FAKE_UUID1, body=body)
324+
self.assertIn('Maximum number of ports exceeded', six.text_type(ex))
325+
311326
def test_detach_interface_with_invalid_state(self):
312327
def fake_detach_interface_invalid_state(*args, **kwargs):
313328
raise exception.InstanceInvalidState(

0 commit comments

Comments
 (0)