From a20af8b52d10a2c43275089dfa0d71f550d2c8b6 Mon Sep 17 00:00:00 2001 From: Mithil Arun Date: Tue, 8 Jul 2014 18:38:04 +0530 Subject: [PATCH] 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 --- neutron/db/db_base_plugin_v2.py | 1 + neutron/tests/unit/test_db_plugin.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/neutron/db/db_base_plugin_v2.py b/neutron/db/db_base_plugin_v2.py index 4d804f559d..4c2994edb9 100644 --- a/neutron/db/db_base_plugin_v2.py +++ b/neutron/db/db_base_plugin_v2.py @@ -1469,6 +1469,7 @@ class NeutronDbPluginV2(neutron_plugin_base_v2.NeutronPluginBaseV2, p = port['port'] changed_ips = False + changed_device_id = False with context.session.begin(subtransactions=True): port = self._get_port(context, id) if 'device_owner' in p: diff --git a/neutron/tests/unit/test_db_plugin.py b/neutron/tests/unit/test_db_plugin.py index c196b8afbd..93b9b4e395 100644 --- a/neutron/tests/unit/test_db_plugin.py +++ b/neutron/tests/unit/test_db_plugin.py @@ -1105,6 +1105,14 @@ fixed_ips=ip_address%%3D%s&fixed_ips=ip_address%%3D%s&fixed_ips=subnet_id%%3D%s neutron_context=neutron_context) self.assertEqual(port['port']['admin_state_up'], False) + def test_update_device_id_unchanged(self): + with self.port() as port: + data = {'port': {'admin_state_up': True, + 'device_id': port['port']['device_id']}} + req = self.new_update_request('ports', data, port['port']['id']) + res = self.deserialize(self.fmt, req.get_response(self.api)) + self.assertEqual(res['port']['admin_state_up'], True) + def test_update_device_id_null(self): with self.port() as port: data = {'port': {'device_id': None}}