Return 400 when SecurityGroupCannotBeApplied is raised

Return 400 when SecurityGroupCannotBeApplied is raised
in attaching an interface to a VM instance.

Change-Id: I6cc0e2b43b82dc3b16a581b1f8ec75b35995934e
Closes-Bug: #1584676
This commit is contained in:
Takashi NATSUME 2016-05-31 21:08:35 +09:00
parent 414df1e56e
commit dba6713e83
2 changed files with 19 additions and 1 deletions

View File

@ -120,7 +120,8 @@ class InterfaceAttachmentController(wsgi.Controller):
exception.NetworkAmbiguous,
exception.NoMoreFixedIps,
exception.PortNotUsable,
exception.AttachInterfaceNotSupported) as e:
exception.AttachInterfaceNotSupported,
exception.SecurityGroupCannotBeApplied) as e:
raise exc.HTTPBadRequest(explanation=e.format_message())
except (exception.InstanceIsLocked,
exception.FixedIpAlreadyInUse,

View File

@ -425,6 +425,23 @@ class InterfaceAttachTestsV21(test.NoDBTestCase):
get_mock.assert_called_once_with(ctxt, FAKE_UUID1,
expected_attrs=None)
@mock.patch.object(compute_api.API, 'get')
@mock.patch.object(compute_api.API, 'attach_interface')
def test_attach_interface_failed_securitygroup_cannot_be_applied(
self, attach_mock, get_mock):
fake_instance = objects.Instance(uuid=FAKE_UUID1,
project_id=FAKE_UUID2)
get_mock.return_value = fake_instance
attach_mock.side_effect = (
exception.SecurityGroupCannotBeApplied())
self.assertRaises(exc.HTTPBadRequest, self.attachments.create,
self.req, FAKE_UUID1, body={})
ctxt = self.req.environ['nova.context']
attach_mock.assert_called_once_with(ctxt, fake_instance, None,
None, None)
get_mock.assert_called_once_with(ctxt, FAKE_UUID1,
expected_attrs=None)
def _test_attach_interface_with_invalid_parameter(self, param):
self.stubs.Set(compute_api.API, 'attach_interface',
fake_attach_interface)