]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Update DVR agent to use get_vifs_by_id
authorKevin Benton <blak111@gmail.com>
Fri, 26 Jun 2015 17:00:42 +0000 (10:00 -0700)
committerKevin Benton <kevinbenton@buttewifi.com>
Sat, 4 Jul 2015 07:34:24 +0000 (07:34 +0000)
The new get_vifs_by_id function retrieves all of the VIFs
for a port iteration at once to eliminate unnecessary multiple
calls to OVSDB.

Change-Id: If18557faead836121bfa3b4e6efccd0318ce72d3
Related-Bug: #1460233

neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py
neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py

index 94d0e8b2082c8dfdd56fd1e23c7b2c4b45f01fd5..905c8a8e9e8868010b356c9d2504bbd4a7a9d12e 100644 (file)
@@ -400,8 +400,10 @@ class OVSDVRNeutronAgent(object):
         LOG.debug("DVR: List of ports received from "
                   "get_ports_on_host_by_subnet %s",
                   local_compute_ports)
+        vif_by_id = self.int_br.get_vifs_by_ids(
+            [prt['id'] for prt in local_compute_ports])
         for prt in local_compute_ports:
-            vif = self.int_br.get_vif_port_by_id(prt['id'])
+            vif = vif_by_id.get(prt['id'])
             if not vif:
                 continue
             ldm.add_compute_ofport(vif.vif_id, vif.ofport)
index 9b4cf01103890e36c227da9e0bac9de433fa8cea..3d42adea658a4394d521109b7d99cae02ff26f81 100644 (file)
@@ -1327,12 +1327,15 @@ class TestOvsDvrNeutronAgent(object):
                                     'ip_address': '1.1.1.3'}]
 
     @staticmethod
-    def _expected_port_bound(port, lvid):
-        return [
+    def _expected_port_bound(port, lvid, is_dvr=True):
+        resp = [
             mock.call.db_get_val('Port', port.port_name, 'other_config'),
             mock.call.set_db_attribute('Port', port.port_name, 'other_config',
                                        mock.ANY),
         ]
+        if is_dvr:
+            resp = [mock.call.get_vifs_by_ids([])] + resp
+        return resp
 
     def _expected_install_dvr_process(self, lvid, port, ip_version,
                                       gateway_ip, gateway_mac):
@@ -1441,7 +1444,7 @@ class TestOvsDvrNeutronAgent(object):
                     dst_port=self._compute_port.ofport,
                     vlan_tag=segmentation_id,
                 ),
-            ] + self._expected_port_bound(self._compute_port, lvid)
+            ] + self._expected_port_bound(self._compute_port, lvid, False)
             self.assertEqual(expected_on_int_br, int_br.mock_calls)
             self.assertFalse([], tun_br.mock_calls)
             self.assertFalse([], phys_br.mock_calls)
@@ -1523,7 +1526,7 @@ class TestOvsDvrNeutronAgent(object):
                     dst_port=self._compute_port.ofport,
                     vlan_tag=lvid,
                 ),
-            ] + self._expected_port_bound(self._compute_port, lvid)
+            ] + self._expected_port_bound(self._compute_port, lvid, False)
             self.assertEqual(expected_on_int_br, int_br.mock_calls)
             self.assertEqual([], tun_br.mock_calls)
             self.assertEqual([], phys_br.mock_calls)
@@ -1594,7 +1597,7 @@ class TestOvsDvrNeutronAgent(object):
                     dst_port=self._port.ofport,
                     vlan_tag=lvid,
                 ),
-            ] + self._expected_port_bound(self._port, lvid)
+            ] + self._expected_port_bound(self._port, lvid, is_dvr=False)
             self.assertEqual(expected_on_int_br, int_br.mock_calls)
             expected_on_tun_br = [
                 mock.call.provision_local_vlan(
@@ -1756,7 +1759,7 @@ class TestOvsDvrNeutronAgent(object):
                         dst_port=self._compute_port.ofport,
                         vlan_tag=lvid,
                     ),
-                ] + self._expected_port_bound(self._compute_port, lvid),
+                ] + self._expected_port_bound(self._compute_port, lvid, False),
                 int_br.mock_calls)
             self.assertEqual([], tun_br.mock_calls)
 
@@ -1835,7 +1838,7 @@ class TestOvsDvrNeutronAgent(object):
                     dst_port=self._port.ofport,
                     vlan_tag=lvid,
                 ),
-            ] + self._expected_port_bound(self._port, lvid)
+            ] + self._expected_port_bound(self._port, lvid, is_dvr=False)
             self.assertEqual(expected_on_int_br, int_br.mock_calls)
             expected_on_tun_br = [
                 mock.call.provision_local_vlan(