Merge "Fix a error when l3-agent gets filter id for ip" into stable/train

This commit is contained in:
Zuul 2022-04-04 15:02:28 +00:00 committed by Gerrit Code Review
commit d21e5373bc
2 changed files with 31 additions and 1 deletions

View File

@ -62,6 +62,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)
@ -72,7 +73,7 @@ class FloatingIPTcCommandBase(ip_lib.IPDevice):
elif 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)

View File

@ -132,6 +132,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):
@ -225,6 +245,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(