Remove unneed functions
There is already a sync function, so there is no need to recheck the flows when VM IPs are being exposed Change-Id: I15100bbec6b8856a9a34f00e2d92164cc992447b
This commit is contained in:
parent
b42a05ac30
commit
71bd3b396f
@ -488,9 +488,6 @@ class OVNBGPDriver(driver_api.AgentDriverBase):
|
||||
self._expose_provider_port([fip_address], fip_datapath)
|
||||
LOG.debug("Added BGP route for FIP with ip %s", fip_address)
|
||||
return [fip_address]
|
||||
else:
|
||||
ovs.ensure_default_ovs_flows(self.ovn_bridge_mappings.values(),
|
||||
constants.OVS_RULE_COOKIE)
|
||||
|
||||
# FIP association to VM
|
||||
elif row.type == constants.OVN_PATCH_VIF_PORT_TYPE:
|
||||
|
@ -12,8 +12,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import re
|
||||
|
||||
from oslo_log import log as logging
|
||||
from ovs.db import idl
|
||||
from ovsdbapp.backend.ovs_idl import connection
|
||||
@ -161,55 +159,6 @@ def remove_evpn_network_ovs_flow(bridge, cookie, mac, net):
|
||||
'ovs-ofctl', ['del-flows', bridge, flow])
|
||||
|
||||
|
||||
def ensure_default_ovs_flows(ovn_bridge_mappings, cookie):
|
||||
cookie_id = "cookie={}/-1".format(cookie)
|
||||
for bridge in ovn_bridge_mappings:
|
||||
ovs_ports = ovn_bgp_agent.privileged.ovs_vsctl.ovs_cmd(
|
||||
'ovs-vsctl', ['list-ports', bridge])[0].rstrip()
|
||||
if not ovs_ports:
|
||||
continue
|
||||
ovs_ofport = None
|
||||
for ovs_port in ovs_ports.split("\n"):
|
||||
if ovs_port.startswith('patch-provnet-'):
|
||||
ovs_ofport = get_device_port_at_ovs(ovs_port)
|
||||
break
|
||||
if not ovs_ofport:
|
||||
continue
|
||||
flow_filter = '{},in_port={}'.format(cookie_id, ovs_ofport)
|
||||
current_flows = get_bridge_flows(bridge, flow_filter)
|
||||
|
||||
# assume if the are 2 rules they are right ones as they have
|
||||
# the right cookie and in_port
|
||||
if len(current_flows) != 2:
|
||||
with pyroute2.NDB() as ndb:
|
||||
flow = ("cookie={},priority=900,ip,in_port={},"
|
||||
"actions=mod_dl_dst:{},NORMAL".format(
|
||||
cookie, ovs_ofport,
|
||||
ndb.interfaces[bridge]['address']))
|
||||
flow_v6 = ("cookie={},priority=900,ipv6,in_port={},"
|
||||
"actions=mod_dl_dst:{},NORMAL".format(
|
||||
cookie, ovs_ofport,
|
||||
ndb.interfaces[bridge]['address']))
|
||||
ovn_bgp_agent.privileged.ovs_vsctl.ovs_cmd(
|
||||
'ovs-ofctl', ['add-flow', bridge, flow])
|
||||
ovn_bgp_agent.privileged.ovs_vsctl.ovs_cmd(
|
||||
'ovs-ofctl', ['add-flow', bridge, flow_v6])
|
||||
|
||||
# Remove unneeded flows
|
||||
current_flows = get_bridge_flows(bridge, cookie_id)
|
||||
# The regex ensures that the next character after the port
|
||||
# number is either a comma, end of line or a space. This avoids
|
||||
# things like "in_port=1" matching with "in_port=10" for example.
|
||||
port_regex = 'in_port={}(,|$| )'.format(ovs_ofport)
|
||||
for flow in current_flows:
|
||||
if not flow or re.search(port_regex, flow):
|
||||
continue
|
||||
in_port = flow.split("in_port=")[1].split(" ")[0]
|
||||
del_flow = ('{},in_port={}').format(cookie_id, in_port)
|
||||
ovn_bgp_agent.privileged.ovs_vsctl.ovs_cmd(
|
||||
'ovs-ofctl', ['del-flows', bridge, del_flow])
|
||||
|
||||
|
||||
def add_device_to_ovs_bridge(device, bridge, vlan_tag=None):
|
||||
args = ['--may-exist', 'add-port', bridge, device]
|
||||
if vlan_tag is not None:
|
||||
|
@ -946,13 +946,11 @@ class TestOVNBGPDriver(test_base.TestCase):
|
||||
mock_add_route.assert_called_once_with(
|
||||
mock.ANY, self.fip, 'fake-table', self.bridge, vlan=10)
|
||||
|
||||
@mock.patch.object(ovs, 'ensure_default_ovs_flows')
|
||||
@mock.patch.object(linux_net, 'add_ip_route')
|
||||
@mock.patch.object(linux_net, 'add_ip_rule')
|
||||
@mock.patch.object(linux_net, 'add_ips_to_dev')
|
||||
def test_expose_ip_vm_with_fip_no_fip_address(
|
||||
self, mock_add_ip_dev, mock_add_rule, mock_add_route,
|
||||
mock_ovs_flows):
|
||||
self, mock_add_ip_dev, mock_add_rule, mock_add_route):
|
||||
self.sb_idl.is_provider_network.return_value = False
|
||||
self.sb_idl.get_fip_associated.return_value = (None, None)
|
||||
row = fakes.create_object({
|
||||
@ -969,10 +967,6 @@ class TestOVNBGPDriver(test_base.TestCase):
|
||||
mock_add_rule.assert_not_called()
|
||||
mock_add_route.assert_not_called()
|
||||
|
||||
# Assert ensure_default_ovs_flows() is called instead
|
||||
mock_ovs_flows.assert_called_once_with(
|
||||
mock.ANY, constants.OVS_RULE_COOKIE)
|
||||
|
||||
@mock.patch.object(linux_net, 'add_ip_route')
|
||||
@mock.patch.object(linux_net, 'add_ip_rule')
|
||||
@mock.patch.object(linux_net, 'add_ips_to_dev')
|
||||
|
@ -294,89 +294,6 @@ class TestOVS(test_base.TestCase):
|
||||
self.mock_ovs_vsctl.ovs_cmd.assert_called_once_with(
|
||||
'ovs-vsctl', ['list-ports', self.bridge])
|
||||
|
||||
@mock.patch.object(ovs_utils, 'get_bridge_flows')
|
||||
@mock.patch.object(ovs_utils, 'get_device_port_at_ovs')
|
||||
def test_ensure_default_ovs_flows(self, mock_ofport, mock_flows):
|
||||
port = 'patch-provnet-fake-port'
|
||||
port_iface = '1'
|
||||
uneeded_port_iface = '10'
|
||||
fake_flow_0 = '{},ip,in_port={}'.format(self.cookie_id, port_iface)
|
||||
fake_flow_1 = '{},ipv6,in_port={}'.format(self.cookie_id, port_iface)
|
||||
uneeded_flow = '{},in_port={}'.format(self.cookie_id,
|
||||
uneeded_port_iface)
|
||||
|
||||
ovn_bridge_mappings = [self.bridge]
|
||||
address = '172.24.200.7'
|
||||
self.fake_ndb.interfaces[self.bridge] = {'address': address}
|
||||
self.mock_ovs_vsctl.ovs_cmd.side_effect = ([port], None, None, None)
|
||||
mock_flows.return_value = [fake_flow_0, fake_flow_1]
|
||||
mock_flows.side_effect = ([fake_flow_0, fake_flow_1],
|
||||
[fake_flow_0, fake_flow_1, uneeded_flow])
|
||||
mock_ofport.return_value = port_iface
|
||||
|
||||
# Invoke the method
|
||||
ovs_utils.ensure_default_ovs_flows(ovn_bridge_mappings, self.cookie)
|
||||
|
||||
expected_flow_filter = '{},in_port={}'.format(self.cookie_id,
|
||||
port_iface)
|
||||
expected_calls = [
|
||||
mock.call('ovs-vsctl', ['list-ports', self.bridge]),
|
||||
mock.call('ovs-ofctl', ['del-flows', self.bridge, uneeded_flow])]
|
||||
self.mock_ovs_vsctl.ovs_cmd.assert_has_calls(expected_calls)
|
||||
self.assertEqual(len(expected_calls),
|
||||
self.mock_ovs_vsctl.ovs_cmd.call_count)
|
||||
mock_ofport.assert_called_once_with(port)
|
||||
expected_calls_flows = [
|
||||
mock.call(self.bridge, expected_flow_filter),
|
||||
mock.call(self.bridge, self.cookie_id)]
|
||||
mock_flows.assert_has_calls(expected_calls_flows)
|
||||
self.assertEqual(len(expected_calls_flows), mock_flows.call_count)
|
||||
|
||||
@mock.patch.object(ovs_utils, 'get_bridge_flows')
|
||||
@mock.patch.object(ovs_utils, 'get_device_port_at_ovs')
|
||||
def test_ensure_default_ovs_flows_no_match(self, mock_ofport, mock_flows):
|
||||
port = 'patch-provnet-fake-port'
|
||||
port_iface = '1'
|
||||
uneeded_port_iface = '10'
|
||||
fake_flow_0 = '{},ip,in_port={}'.format(self.cookie_id, port_iface)
|
||||
fake_flow_1 = '{},ipv6,in_port={}'.format(self.cookie_id, port_iface)
|
||||
uneeded_flow = '{},in_port={}'.format(self.cookie_id,
|
||||
uneeded_port_iface)
|
||||
ovn_bridge_mappings = [self.bridge]
|
||||
address = '172.24.200.7'
|
||||
self.fake_ndb.interfaces[self.bridge] = {'address': address}
|
||||
self.mock_ovs_vsctl.ovs_cmd.side_effect = ([port], None, None, None)
|
||||
mock_flows.side_effect = ([fake_flow_0],
|
||||
[fake_flow_0, fake_flow_1, uneeded_flow])
|
||||
mock_ofport.return_value = port_iface
|
||||
|
||||
# Invoke the method
|
||||
ovs_utils.ensure_default_ovs_flows(ovn_bridge_mappings, self.cookie)
|
||||
|
||||
expected_flow = ('cookie={},priority=900,ip,in_port={},'
|
||||
'actions=mod_dl_dst:{},NORMAL'.format(
|
||||
self.cookie, port_iface, address))
|
||||
expected_flow_v6 = ('cookie={},priority=900,ipv6,in_port={},'
|
||||
'actions=mod_dl_dst:{},NORMAL'.format(
|
||||
self.cookie, port_iface, address))
|
||||
expected_flow_filter = '{},in_port={}'.format(self.cookie_id,
|
||||
port_iface)
|
||||
expected_calls = [
|
||||
mock.call('ovs-vsctl', ['list-ports', self.bridge]),
|
||||
mock.call('ovs-ofctl', ['add-flow', self.bridge, expected_flow]),
|
||||
mock.call('ovs-ofctl', ['add-flow', self.bridge,
|
||||
expected_flow_v6]),
|
||||
mock.call('ovs-ofctl', ['del-flows', self.bridge, uneeded_flow])]
|
||||
self.mock_ovs_vsctl.ovs_cmd.assert_has_calls(expected_calls)
|
||||
self.assertEqual(len(expected_calls),
|
||||
self.mock_ovs_vsctl.ovs_cmd.call_count)
|
||||
mock_ofport.assert_called_once_with(port)
|
||||
expected_calls_flows = [
|
||||
mock.call(self.bridge, expected_flow_filter),
|
||||
mock.call(self.bridge, self.cookie_id)]
|
||||
mock_flows.assert_has_calls(expected_calls_flows)
|
||||
self.assertEqual(len(expected_calls_flows), mock_flows.call_count)
|
||||
|
||||
def _test_add_device_to_ovs_bridge(self, vlan_tag=False):
|
||||
device = 'ethX'
|
||||
vtag = '1001' if vlan_tag else None
|
||||
|
Loading…
Reference in New Issue
Block a user