Merge "Add VLAN tag info to port before applying SG initial setup." into stable/liberty
This commit is contained in:
commit
006e5f93cf
|
@ -822,6 +822,25 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
|
|||
self.int_br.set_db_attribute("Port", port.port_name, "other_config",
|
||||
port_other_config)
|
||||
|
||||
def _add_port_tag_info(self, need_binding_ports):
|
||||
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", "other_config"],
|
||||
ports=port_names, if_exists=True)
|
||||
info_by_port = {x['name']: [x['tag'], x['other_config']]
|
||||
for x in port_info}
|
||||
for port_detail in need_binding_ports:
|
||||
lvm = self.local_vlan_map.get(port_detail['network_id'])
|
||||
if not lvm:
|
||||
continue
|
||||
port = port_detail['vif_port']
|
||||
cur_info = info_by_port.get(port.port_name)
|
||||
if cur_info is not None and cur_info[0] != lvm.vlan:
|
||||
other_config = cur_info[1] or {}
|
||||
other_config['tag'] = lvm.vlan
|
||||
self.int_br.set_db_attribute(
|
||||
"Port", port.port_name, "other_config", other_config)
|
||||
|
||||
def _bind_devices(self, need_binding_ports):
|
||||
devices_up = []
|
||||
devices_down = []
|
||||
|
@ -1539,6 +1558,7 @@ class OVSNeutronAgent(sg_rpc.SecurityGroupAgentRpcCallbackMixin,
|
|||
# TODO(salv-orlando): Optimize avoiding applying filters
|
||||
# unnecessarily, (eg: when there are no IP address changes)
|
||||
added_ports = port_info.get('added', set())
|
||||
self._add_port_tag_info(need_binding_devices)
|
||||
if security_disabled_ports:
|
||||
added_ports -= set(security_disabled_ports)
|
||||
self.sg_agent.setup_port_filters(added_ports,
|
||||
|
|
|
@ -421,6 +421,40 @@ class TestOvsNeutronAgent(object):
|
|||
vif_port_set, registered_ports, port_tags_dict=port_tags_dict)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
def test_add_port_tag_info(self):
|
||||
self.agent.local_vlan_map["net1"] = mock.Mock()
|
||||
self.agent.local_vlan_map["net1"].vlan = "1"
|
||||
ovs_db_list = [{'name': 'tap1',
|
||||
'tag': [],
|
||||
'other_config': {'segmentation_id': '1'}},
|
||||
{'name': 'tap2',
|
||||
'tag': [],
|
||||
'other_config': {}},
|
||||
{'name': 'tap3',
|
||||
'tag': [],
|
||||
'other_config': None}]
|
||||
vif_port1 = mock.Mock()
|
||||
vif_port1.port_name = 'tap1'
|
||||
vif_port2 = mock.Mock()
|
||||
vif_port2.port_name = 'tap2'
|
||||
vif_port3 = mock.Mock()
|
||||
vif_port3.port_name = 'tap3'
|
||||
port_details = [
|
||||
{'network_id': 'net1', 'vif_port': vif_port1},
|
||||
{'network_id': 'net1', 'vif_port': vif_port2},
|
||||
{'network_id': 'net1', 'vif_port': vif_port3}]
|
||||
with mock.patch.object(self.agent, 'int_br') as int_br:
|
||||
int_br.get_ports_attributes.return_value = ovs_db_list
|
||||
self.agent._add_port_tag_info(port_details)
|
||||
set_db_attribute_calls = \
|
||||
[mock.call.set_db_attribute("Port", "tap1",
|
||||
"other_config", {"segmentation_id": "1", "tag": "1"}),
|
||||
mock.call.set_db_attribute("Port", "tap2",
|
||||
"other_config", {"tag": "1"}),
|
||||
mock.call.set_db_attribute("Port", "tap3",
|
||||
"other_config", {"tag": "1"})]
|
||||
int_br.assert_has_calls(set_db_attribute_calls, any_order=True)
|
||||
|
||||
def test_bind_devices(self):
|
||||
devices_up = ['tap1']
|
||||
devices_down = ['tap2']
|
||||
|
|
Loading…
Reference in New Issue