Browse Source

Merge "Fix a error when l3-agent gets filter id for ip"

changes/97/820897/13
Zuul 4 months ago committed by Gerrit Code Review
parent
commit
dac03f4f9e
  1. 3
      neutron/agent/linux/l3_tc_lib.py
  2. 29
      neutron/tests/unit/agent/linux/test_l3_tc_lib.py

3
neutron/agent/linux/l3_tc_lib.py

@ -63,6 +63,7 @@ class FloatingIPTcCommandBase(ip_lib.IPDevice):
if not filters_output:
raise exceptions.FilterIDForIPNotFound(ip=ip)
filter_lines = filters_output.split('\n')
filter_id = None
for line in filter_lines:
line = line.strip()
m = FILTER_ID_REGEX.match(line)
@ -73,7 +74,7 @@ class FloatingIPTcCommandBase(ip_lib.IPDevice):
if not line.startswith('match'):
continue
parts = line.split(" ")
if ip + '/32' in parts:
if ip + '/32' in parts and filter_id:
filterids_for_ip.append(filter_id)
if len(filterids_for_ip) > 1:
raise exceptions.MultipleFilterIDForIPFound(ip=ip)

29
neutron/tests/unit/agent/linux/test_l3_tc_lib.py

@ -133,6 +133,26 @@ QDISC_IDS = {constants.INGRESS_DIRECTION: INGRESS_QSIC_ID,
TC_QDISCS = [{'handle': '1:', 'qdisc_type': 'htb', 'parent': 'root'},
{'handle': 'ffff:', 'qdisc_type': 'ingress', 'parent': 'ingress'}]
TC_FILTERS_ADD_BY_OTHERS_BASE = (
'filter protocol %(protocol)s u32 %(chain_name)s \n'
'filter protocol %(protocol)s u32 %(chain_name)s fh 800: ht divisor 1 \n'
'filter protocol %(protocol)s u32 %(chain_name)s fh %(filter_id1)s order '
'2048 key ht 800 bkt 0 flowid :1 not_in_hw (rule hit 0 success 0) \n'
'match %(matches)s at 16 (success 0 ) \n'
'police 0x3 rate 3000Kbit burst 3Mb mtu 64Kb action drop overhead 0b '
'linklayer ethernet \n'
'ref 1 bind 1 installed 22 sec used 22 sec \n'
'\n'
' Sent 111 bytes 222 pkts (dropped 0, overlimits 0)\n'
)
TC_FILTERS_ADD_BY_OTHERS_FOR_ALL_PROTOCOL = TC_FILTERS_ADD_BY_OTHERS_BASE % {
"protocol": "all",
"chain_name": "chain 1 ",
"filter_id1": FILETER_ID_1,
"matches": "c0a8dc06/ffffffff"
}
class TestFloatingIPTcCommandBase(base.BaseTestCase):
def setUp(self):
@ -227,6 +247,15 @@ class TestFloatingIPTcCommandBase(base.BaseTestCase):
def test__get_filterid_for_ip_not_found_with_chain(self):
self._test__get_filterid_for_ip_not_found(TC_EGRESS_FILTERS_WITH_CHAIN)
def test__get_filterid_for_ip_with_additional_filters(self):
with mock.patch.object(tc_lib.FloatingIPTcCommandBase,
'_get_filters') as get_filters:
get_filters.return_value = \
TC_FILTERS_ADD_BY_OTHERS_FOR_ALL_PROTOCOL
self.assertRaises(exceptions.FilterIDForIPNotFound,
self.tc._get_filterid_for_ip,
INGRESS_QSIC_ID, "192.168.220.6")
def test__del_filter_by_id(self):
self.tc._del_filter_by_id(INGRESS_QSIC_ID, FLOATING_IP_1)
self.execute.assert_called_once_with(

Loading…
Cancel
Save