Merge "Remove useless function _add_port_tag_info"

This commit is contained in:
Zuul 2022-04-21 09:09:33 +00:00 committed by Gerrit Code Review
commit bdd6d4daee
2 changed files with 0 additions and 112 deletions

View File

@ -1179,41 +1179,6 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
port_other_config)
return True
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']: {
'tag': x['tag'],
'other_config': x['other_config'] or {}
}
for x in port_info
}
for port_detail in need_binding_ports:
try:
lvm = self.vlan_manager.get(port_detail['network_id'])
except vlanmanager.MappingNotFound:
continue
port = port_detail['vif_port']
try:
cur_info = info_by_port[port.port_name]
except KeyError:
continue
str_vlan = str(lvm.vlan)
other_config = cur_info['other_config']
if (cur_info['tag'] != lvm.vlan or
other_config.get('tag') != str_vlan):
other_config['tag'] = str_vlan
self.int_br.set_db_attribute(
"Port", port.port_name, "other_config", other_config)
# Uninitialized port has tag set to []
if cur_info['tag']:
LOG.warning("Uninstall flows of ofport %s due to "
"local vlan change.", port.ofport)
self.int_br.uninstall_flows(in_port=port.ofport)
def _bind_devices(self, need_binding_ports):
devices_up = []
devices_down = []
@ -2195,7 +2160,6 @@ class OVSNeutronAgent(l2population_rpc.L2populationRpcCallBackTunnelMixin,
# unnecessarily, (eg: when there are no IP address changes)
added_ports = (port_info.get('added', set()) - skipped_devices -
binding_no_activated_devices - migrating_devices)
self._add_port_tag_info(need_binding_devices)
self.process_install_ports_egress_flows(need_binding_devices)
added_to_datapath = added_ports - devices_not_in_datapath
self.sg_agent.setup_port_filters(added_to_datapath,

View File

@ -691,82 +691,6 @@ class TestOvsNeutronAgent(object):
expected_failed_devices_retries_map,
new_failed_devices_retries_map)
def test_add_port_tag_info(self):
lvm = mock.Mock()
lvm.vlan = 1
self.agent.vlan_manager.mapping["net1"] = lvm
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_add_port_tag_info_with_tagged_ports(self):
lvm = mock.Mock()
lvm.vlan = 1
self.agent.vlan_manager.mapping["net1"] = lvm
ovs_db_list1 = [{'name': 'tap1',
'tag': 1,
'other_config': {'segmentation_id': '1', 'tag': '1'}}]
ovs_db_list2 = [{'name': 'tap2',
'tag': 2,
'other_config': {'segmentation_id': '1', 'tag': '1'}},
{'name': 'tap3',
'tag': 1,
'other_config': {'segmentation_id': '2', 'tag': '2'}}]
vif_port1 = mock.Mock()
vif_port1.port_name = 'tap1'
vif_port2 = mock.Mock()
vif_port2.port_name = 'tap2'
vif_port2.ofport = 7
vif_port3 = mock.Mock()
vif_port3.port_name = 'tap3'
vif_port3.ofport = 8
port_details1 = [{'network_id': 'net1', 'vif_port': vif_port1}]
port_details2 = [{'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_list1
self.agent._add_port_tag_info(port_details1)
int_br.set_db_attribute.assert_not_called()
# Reset mock to check port with changed tag
int_br.reset_mock()
int_br.get_ports_attributes.return_value = ovs_db_list2
self.agent._add_port_tag_info(port_details2)
expected_calls = \
[mock.call.set_db_attribute("Port", "tap2",
"other_config", {'segmentation_id': '1', 'tag': '1'}),
mock.call.uninstall_flows(in_port=7),
mock.call.set_db_attribute("Port", "tap3",
"other_config", {'segmentation_id': '2', 'tag': '1'}),
mock.call.uninstall_flows(in_port=8)]
int_br.assert_has_calls(expected_calls)
def test_bind_devices(self):
devices_up = ['tap1']
devices_down = ['tap2']