Port update crashes when device id does not need to be updated

Bug #1337787 reported by Mithil Arun
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
High
Mithil Arun

Bug Description

When I call the update_port() method using the ML2 plugin, I see the following error:
2014-07-04 10:05:40.043 17585 ERROR neutron.api.v2.resource [-] add_router_interface failed
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource Traceback (most recent call last):
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource File "/usr/lib/python2.6/site-packages/neutron/api/v2/resource.py", line 84, in resource
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource result = method(request=request, **args)
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource File "/usr/lib/python2.6/site-packages/neutron/api/v2/base.py", line 185, in _handle_action
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource return getattr(self._plugin, name)(*arg_list, **kwargs)
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource File "/usr/lib/python2.6/site-packages/neutron/services/pn_services/router.py", line 224, in add_router_interface
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource self.update_port(context, p['id'], port_info)
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource File "/usr/lib/python2.6/site-packages/neutron/services/pn_services/router.py", line 349, in update_port
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource """
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource File "/usr/lib/python2.6/site-packages/neutron/db/db_base_plugin_v2.py", line 1397, in update_port
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource and (changed_device_id or changed_device_owner)):
2014-07-04 10:05:40.043 17585 TRACE neutron.api.v2.resource UnboundLocalError: local variable 'changed_device_id' referenced before assignment

On further inspection of the file in question (/usr/lib/python2.6/site-packages/neutron/db/db_base_plugin_v2.py: update_port()), I see that the variable 'changed_device_id' is only declared within an 'if' condition, and not otherwise. This causes the crash as a later 'if' tries to read from it but finds it not declared.

--snip--
    def update_port(self, context, id, port):
        p = port['port']

        changed_ips = False
        with context.session.begin(subtransactions=True):
            port = self._get_port(context, id)
            if 'device_owner' in p:
                current_device_owner = p['device_owner']
                changed_device_owner = True
            else:
                current_device_owner = port['device_owner']
                changed_device_owner = False
            if p.get('device_id') != port['device_id']:
                changed_device_id = True

            # if the current device_owner is ROUTER_INF and the device_id or
            # device_owner changed check device_id is not another tenants
            # router
            if ((current_device_owner == constants.DEVICE_OWNER_ROUTER_INTF)
                    and (changed_device_id or changed_device_owner)):
                self._enforce_device_owner_not_router_intf_or_device_id(
                    context, p, port['tenant_id'], port)
--snip--

'changed_device_id' should be set to 'False' by default.

Tags: ml2
Changed in neutron:
assignee: nobody → Mithil Arun (arun-mithil)
Changed in neutron:
importance: Undecided → High
status: New → Confirmed
tags: added: ml2
Changed in neutron:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

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

Shiv Haris (shh)
Changed in neutron:
milestone: none → juno-2
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.openstack.org/105471
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=ee86bf175e7ee79720462338a0d0988e6e8342c1
Submitter: Jenkins
Branch: master

commit ee86bf175e7ee79720462338a0d0988e6e8342c1
Author: Mithil Arun <email address hidden>
Date: Tue Jul 8 18:38:04 2014 +0530

    Fixes port update failure when device ID is not updated

    The updation was failing because the changed_device_id variable
    was undeclared.This fix declares the variable with a default value
    at the beginning of the method.

    Change-Id: I06dfea1170a6b2a649f4e1efe4bf70b7cee0eacb
    Closes-Bug: 1337787

Changed in neutron:
status: In Progress → Fix Committed
Changed in neutron:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in neutron:
milestone: juno-2 → 2014.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers