]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix BigSwitch plugin to handle device_id re-use in porttracker code
authorKevin Benton <kevin.benton@bigswitch.com>
Tue, 6 Aug 2013 15:19:08 +0000 (08:19 -0700)
committerKevin Benton <kevin.benton@bigswitch.com>
Tue, 6 Aug 2013 19:34:25 +0000 (12:34 -0700)
Updates the BigSwitch port_tracker code to use the sqlalchemy merge method
instead of the add method for the port location tracking code to avoid primary
 key constraint errors if device-ids are moved or re-used

Fixes: bug #1208990
Change-Id: I06065ac888873b00f445d4356b17f084ee38c1ea

neutron/plugins/bigswitch/db/porttracker_db.py
neutron/tests/unit/bigswitch/test_restproxy_plugin.py

index b2e3ec80796660c1b57675b247c2334164472613..845516b1c8bed4876445f79de65226d942934cec 100644 (file)
@@ -47,4 +47,4 @@ def put_port_hostid(context, port_id, host_id):
         return
     with context.session.begin(subtransactions=True):
         location = PortLocation(port_id=port_id, host_id=host_id)
-        context.session.add(location)
+        context.session.merge(location)
index 13caebb6d96ebbb5ca8242396987443dccf30861..4748114725ac0a87f3cbd977a1500e2990438cb0 100644 (file)
@@ -190,6 +190,16 @@ class TestBigSwitchVIFOverride(test_plugin.TestPortsV2,
         with self.port(**kwargs) as port:
             self.assertEqual(port['port']['binding:vif_type'], self.VIF_TYPE)
 
+    def test_port_move(self):
+        kwargs = {'name': 'name', 'binding:host_id': 'ivshost',
+                  'device_id': 'override_dev'}
+        with self.port(**kwargs) as port:
+            data = {'port': {'binding:host_id': 'someotherhost',
+                             'device_id': 'override_dev'}}
+            req = self.new_update_request('ports', data, port['port']['id'])
+            res = self.deserialize(self.fmt, req.get_response(self.api))
+            self.assertEqual(res['port']['binding:vif_type'], self.VIF_TYPE)
+
     def _make_port(self, fmt, net_id, expected_res_status=None, **kwargs):
         res = self._create_port(fmt, net_id, expected_res_status,
                                 ('binding:host_id', ), **kwargs)