neutron: 500 error when trying to attach no network to an instance with no network

Bug #1545117 reported by Matt Riedemann
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Low
Matt Riedemann

Bug Description

It's possible to create a VM with nova using neutron as the backend and have no network information. If the tenant doesn't have any available network in neutron and doesn't request any network, the neutron backend will simply log a message and continue.

If you then later attempt to use the os-attach-interface API and don't provider a network, and the tenant still doesn't have any networks available in neutron, then the request fails in the neutronv2 API code with an IndexError because it's assuming there is at least one available network:

http://paste.openstack.org/show/486856/

2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions Traceback (most recent call last):
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/usr/local/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 143, in _dispatch_and_reply
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions executor_callback))
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/usr/local/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 189, in _dispatch
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions executor_callback)
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/usr/local/lib/python2.7/dist-packages/oslo_messaging/rpc/dispatcher.py", line 130, in _do_dispatch
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions result = func(ctxt, **new_args)
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/opt/stack/nova/nova/exception.py", line 110, in wrapped
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions payload)
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/usr/local/lib/python2.7/dist-packages/oslo_utils/excutils.py", line 204, in __exit__
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions six.reraise(self.type_, self.value, self.tb)
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/opt/stack/nova/nova/exception.py", line 89, in wrapped
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions return f(self, context, *args, **kw)
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/opt/stack/nova/nova/compute/manager.py", line 385, in decorated_function
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions kwargs['instance'], e, sys.exc_info())
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/usr/local/lib/python2.7/dist-packages/oslo_utils/excutils.py", line 204, in __exit__
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions six.reraise(self.type_, self.value, self.tb)
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/opt/stack/nova/nova/compute/manager.py", line 373, in decorated_function
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions return function(self, context, *args, **kwargs)
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/opt/stack/nova/nova/compute/manager.py", line 4933, in attach_interface
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions context, instance, port_id, network_id, requested_ip)
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/opt/stack/nova/nova/network/neutronv2/api.py", line 775, in allocate_port_for_instance
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions requested_networks=requested_networks)
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions File "/opt/stack/nova/nova/network/neutronv2/api.py", line 579, in allocate_for_instance
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions objects.NetworkRequest(network_id=nets[0]['id']))
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions
2016-02-12 09:34:32.188 TRACE nova.api.openstack.extensions IndexError: list index out of range

We should at least handle that case and report a 400 to the user.

Matt Riedemann (mriedem)
Changed in nova:
importance: Undecided → Low
status: New → Confirmed
Matt Riedemann (mriedem)
Changed in nova:
assignee: nobody → Matt Riedemann (mriedem)
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

Fix proposed to branch: master
Review: https://review.openstack.org/279839

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to nova (master)

Reviewed: https://review.openstack.org/279839
Committed: https://git.openstack.org/cgit/openstack/nova/commit/?id=d90115c3e806f896dc90e226af7b06b21ba92abc
Submitter: Jenkins
Branch: master

commit d90115c3e806f896dc90e226af7b06b21ba92abc
Author: Matt Riedemann <email address hidden>
Date: Fri Feb 12 18:34:59 2016 -0800

    neutron: handle attach interface case with no networks

    It's possible to boot an instance without a network and it's
    also possible to try and attach an interface without specifying
    a port, network or fixed IP. If no network is specified on the
    attach request and there are no networks available to the
    instance's project (shared or not), then the
    allocate_port_for_instance method fails with an IndexError.

    The code is currently checking for a case of ambiguous networks
    when a specific network ID is not requested, but is not checking
    for the case that no network ID is specified and no networks are
    available. This change adds that check.

    A new type of exception is raised from the network API and handled
    in the REST API so we return a 400 to the user rather than a 500.

    Note that we don't return an empty network_info to the compute
    manager because that results in InterfaceAttachFailed raised to
    the REST API which is interpreted as a 500.

    Closes-Bug: #1545117

    Change-Id: Iad762ebef08c259339ea5582e65266620fbab0ac

Changed in nova:
status: In Progress → Fix Released
Revision history for this message
Thierry Carrez (ttx) wrote : Fix included in openstack/nova 13.0.0.0rc1

This issue was fixed in the openstack/nova 13.0.0.0rc1 release candidate.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.