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
This commit is contained in:
Kevin Benton 2015-06-26 10:00:42 -07:00 committed by Kevin Benton
parent c69018aece
commit 26f50761ef
2 changed files with 13 additions and 8 deletions

View 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)

View 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(