Skip to content

Commit

Permalink
Merge "_bind_devices query only existing ports"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Sep 5, 2015
2 parents a5193bc + 1b25e30 commit 84497a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Expand Up @@ -793,7 +793,7 @@ def _bind_devices(self, need_binding_ports):
devices_down = []
port_names = [p['vif_port'].port_name for p in need_binding_ports]
port_info = self.int_br.get_ports_attributes(
"Port", columns=["name", "tag"], ports=port_names)
"Port", columns=["name", "tag"], ports=port_names, if_exists=True)
tags_by_name = {x['name']: x['tag'] for x in port_info}
for port_detail in need_binding_ports:
lvm = self.local_vlan_map.get(port_detail['network_id'])
Expand All @@ -805,6 +805,10 @@ def _bind_devices(self, need_binding_ports):
device = port_detail['device']
# Do not bind a port if it's already bound
cur_tag = tags_by_name.get(port.port_name)
if cur_tag is None:
LOG.info(_LI("Port %s was deleted concurrently, skipping it"),
port.port_name)
continue
if cur_tag != lvm.vlan:
self.int_br.delete_flows(in_port=port.ofport)
if self.prevent_arp_spoofing:
Expand Down
Expand Up @@ -368,11 +368,17 @@ def test_bind_devices(self):
devices_up = ['tap1']
devices_down = ['tap2']
self.agent.local_vlan_map["net1"] = mock.Mock()
ovs_db_list = [{'name': 'tap1', 'tag': []},
{'name': 'tap2', 'tag': []}]
vif_port1 = mock.Mock()
vif_port1.port_name = 'tap1'
vif_port2 = mock.Mock()
vif_port2.port_name = 'tap2'
port_details = [
{'network_id': 'net1', 'vif_port': mock.Mock(),
{'network_id': 'net1', 'vif_port': vif_port1,
'device': devices_up[0],
'admin_state_up': True},
{'network_id': 'net1', 'vif_port': mock.Mock(),
{'network_id': 'net1', 'vif_port': vif_port2,
'device': devices_down[0],
'admin_state_up': False}]
with mock.patch.object(
Expand All @@ -383,7 +389,7 @@ def test_bind_devices(self):
'failed_devices_down': []}) as update_devices, \
mock.patch.object(self.agent,
'int_br') as int_br:
int_br.db_list.return_value = []
int_br.get_ports_attributes.return_value = ovs_db_list
self.agent._bind_devices(port_details)
update_devices.assert_called_once_with(mock.ANY, devices_up,
devices_down,
Expand Down Expand Up @@ -413,7 +419,7 @@ def _test_arp_spoofing(self, enable_prevent_arp_spoofing):
mock.patch.object(
self.agent,
'setup_arp_spoofing_protection') as setup_arp:
int_br.db_list.return_value = ovs_db_list
int_br.get_ports_attributes.return_value = ovs_db_list
self.agent._bind_devices(need_binding_ports)
self.assertEqual(enable_prevent_arp_spoofing, setup_arp.called)

Expand Down

0 comments on commit 84497a6

Please sign in to comment.