From: Kevin Benton Date: Fri, 26 Jun 2015 17:00:42 +0000 (-0700) Subject: Update DVR agent to use get_vifs_by_id X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=26f50761efaa5bc362e35a41f0adc458e0224296;p=openstack-build%2Fneutron-build.git Update DVR agent to use get_vifs_by_id 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 --- diff --git a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py index 94d0e8b20..905c8a8e9 100644 --- a/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py +++ b/neutron/plugins/ml2/drivers/openvswitch/agent/ovs_dvr_neutron_agent.py @@ -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) diff --git a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py index 9b4cf0110..3d42adea6 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py +++ b/neutron/tests/unit/plugins/ml2/drivers/openvswitch/agent/test_ovs_neutron_agent.py @@ -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(