Merge "neutron: handle attach interface case with no networks"
This commit is contained in:
commit
7083166966
|
@ -115,7 +115,8 @@ class InterfaceAttachmentController(wsgi.Controller):
|
|||
try:
|
||||
vif = self.compute_api.attach_interface(context,
|
||||
instance, network_id, port_id, req_ip)
|
||||
except (exception.NetworkDuplicated,
|
||||
except (exception.InterfaceAttachFailedNoNetwork,
|
||||
exception.NetworkDuplicated,
|
||||
exception.NetworkAmbiguous,
|
||||
exception.NoMoreFixedIps,
|
||||
exception.PortNotUsable) as e:
|
||||
|
|
|
@ -124,6 +124,7 @@ class InterfaceAttachmentController(object):
|
|||
exception.NetworkNotFound) as e:
|
||||
raise exc.HTTPNotFound(explanation=e.format_message())
|
||||
except (exception.FixedIpAlreadyInUse,
|
||||
exception.InterfaceAttachFailedNoNetwork,
|
||||
exception.NoMoreFixedIps,
|
||||
exception.PortInUse,
|
||||
exception.NetworkDuplicated,
|
||||
|
|
|
@ -1553,6 +1553,11 @@ class InterfaceAttachFailed(Invalid):
|
|||
"%(instance_uuid)s")
|
||||
|
||||
|
||||
class InterfaceAttachFailedNoNetwork(InterfaceAttachFailed):
|
||||
msg_fmt = _("No specific network was requested and none are available "
|
||||
"for project '%(project_id)s'.")
|
||||
|
||||
|
||||
class InterfaceDetachFailed(Invalid):
|
||||
msg_fmt = _("Failed to detach network adapter device from "
|
||||
"%(instance_uuid)s")
|
||||
|
|
|
@ -585,6 +585,11 @@ class API(base_api.NetworkAPI):
|
|||
# pci_request_id=None):
|
||||
if (not requested_networks
|
||||
or requested_networks.is_single_unspecified):
|
||||
# If no networks were requested and none are available, consider
|
||||
# it a bad request.
|
||||
if not nets:
|
||||
raise exception.InterfaceAttachFailedNoNetwork(
|
||||
project_id=instance.project_id)
|
||||
# bug/1267723 - if no network is requested and more
|
||||
# than one is available then raise NetworkAmbiguous Exception
|
||||
if len(nets) > 1:
|
||||
|
|
|
@ -404,6 +404,23 @@ class InterfaceAttachTestsV21(test.NoDBTestCase):
|
|||
want_objects=True,
|
||||
expected_attrs=None)
|
||||
|
||||
@mock.patch.object(compute_api.API, 'get')
|
||||
@mock.patch.object(compute_api.API, 'attach_interface')
|
||||
def test_attach_interface_failed_no_network(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.InterfaceAttachFailedNoNetwork(project_id=FAKE_UUID2))
|
||||
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,
|
||||
want_objects=True,
|
||||
expected_attrs=None)
|
||||
|
||||
@mock.patch.object(compute_api.API, 'get')
|
||||
@mock.patch.object(compute_api.API, 'attach_interface')
|
||||
def test_attach_interface_no_more_fixed_ips(self,
|
||||
|
|
|
@ -3611,6 +3611,30 @@ class TestNeutronv2WithMock(test.TestCase):
|
|||
mock.ANY,
|
||||
mock.ANY)
|
||||
|
||||
@mock.patch('nova.network.neutronv2.api.API._process_requested_networks')
|
||||
@mock.patch('nova.network.neutronv2.api.API._has_port_binding_extension')
|
||||
@mock.patch('nova.network.neutronv2.api.API._get_available_networks')
|
||||
@mock.patch('nova.network.neutronv2.api.get_client')
|
||||
def test_allocate_port_for_instance_no_networks(self,
|
||||
mock_getclient,
|
||||
mock_avail_nets,
|
||||
mock_has_pbe,
|
||||
mock_process_request_net):
|
||||
"""Tests that if no networks are requested and no networks are
|
||||
available, we fail with InterfaceAttachFailedNoNetwork.
|
||||
"""
|
||||
instance = fake_instance.fake_instance_obj(self.context)
|
||||
mock_has_pbe.return_value = False
|
||||
mock_process_request_net.return_value = ({}, [], [], None)
|
||||
mock_avail_nets.return_value = []
|
||||
api = neutronapi.API()
|
||||
ex = self.assertRaises(exception.InterfaceAttachFailedNoNetwork,
|
||||
api.allocate_port_for_instance,
|
||||
self.context, instance, port_id=None)
|
||||
self.assertEqual(
|
||||
"No specific network was requested and none are available for "
|
||||
"project 'fake-project'.", six.text_type(ex))
|
||||
|
||||
@mock.patch('nova.objects.network_request.utils')
|
||||
@mock.patch('nova.network.neutronv2.api.LOG')
|
||||
@mock.patch('nova.network.neutronv2.api.base_api')
|
||||
|
|
Loading…
Reference in New Issue