]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix binding:host_id is set to None when port update
authorhyunsun <hyunsun.moon@gmail.com>
Wed, 18 Dec 2013 09:03:34 +0000 (18:03 +0900)
committerGerrit Code Review <review@openstack.org>
Mon, 10 Feb 2014 06:41:14 +0000 (06:41 +0000)
when updating a port 'binding:host_id' is reset if not specified among
the parameter to be updated. As a result, a None value for
'binding:host_id' is sent from the notifier which might potentially
cause consumers to not work properly.

Closes-Bug: #1245310
Change-Id: Icfb5179940cca9f8a705eb36bdbfcbc8a421a272

neutron/db/portbindings_db.py
neutron/tests/unit/_test_extension_portbindings.py

index 678f7433453ab42da1ef953a49d5aa95f4c2d786..c7ab4d37e2b2a27ec22deca18ce7a1b1d91a39e2 100644 (file)
@@ -73,17 +73,17 @@ class PortBindingMixin(portbindings_base.PortBindingBaseMixin):
             del port[portbindings.PROFILE]
         host = port_data.get(portbindings.HOST_ID)
         host_set = attributes.is_attr_set(host)
-        if not host_set:
-            self._extend_port_dict_binding_host(port, None)
-            return
         with context.session.begin(subtransactions=True):
             bind_port = context.session.query(
                 PortBindingPort).filter_by(port_id=port['id']).first()
-            if not bind_port:
-                context.session.add(PortBindingPort(port_id=port['id'],
-                                                    host=host))
+            if host_set:
+                if not bind_port:
+                    context.session.add(PortBindingPort(port_id=port['id'],
+                                                        host=host))
+                else:
+                    bind_port.host = host
             else:
-                bind_port.host = host
+                host = (bind_port and bind_port.host or None)
         self._extend_port_dict_binding_host(port, host)
 
     def get_port_host(self, context, port_id):
index 85df2f7cacc45d53616bd499acf40f23d78128ac..f362f92eadc0835f9fc2eb2b56445087b0f12291 100644 (file)
@@ -247,6 +247,24 @@ class PortBindingsHostTestCaseMixin(object):
         for port in ports:
             self.assertEqual('testhosttemp', port[portbindings.HOST_ID])
 
+    def test_ports_vif_non_host_update(self):
+        host_arg = {portbindings.HOST_ID: self.hostname}
+        with self.port(name='name', arg_list=(portbindings.HOST_ID,),
+                       **host_arg) as port:
+            data = {'port': {'admin_state_up': False}}
+            req = self.new_update_request('ports', data, port['port']['id'])
+            res = self.deserialize(self.fmt, req.get_response(self.api))
+            self.assertEqual(port['port'][portbindings.HOST_ID],
+                             res['port'][portbindings.HOST_ID])
+
+    def test_ports_vif_non_host_update_when_host_null(self):
+        with self.port() as port:
+            data = {'port': {'admin_state_up': False}}
+            req = self.new_update_request('ports', data, port['port']['id'])
+            res = self.deserialize(self.fmt, req.get_response(self.api))
+            self.assertEqual(port['port'][portbindings.HOST_ID],
+                             res['port'][portbindings.HOST_ID])
+
     def test_ports_vif_host_list(self):
         cfg.CONF.set_default('allow_overlapping_ips', True)
         host_arg = {portbindings.HOST_ID: self.hostname}