Skip to content

Commit c50ed80

Browse files
authored
Fix GCU test_dynamic_acl failure on 2vlan config testbed (sonic-net#16637)
What is the motivation for this PR? With 2vlan config on testbed, such as t0-118, by default, ipv4 range for vlan1000 is 192.168.0.1/25 and ipv4 range for vlan2000 192.168.0.129/25, so set increment to 65. Otherwise, incrementing by 129 will cause IP overlap within the second VLAN's IP range, 192.168.0.129. two_vlan_a: Vlan1000: id: 1000 intfs: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62] prefix: 192.168.0.1/25 prefix_v6: fc02:1000::1/64 tag: 1000 Vlan2000: id: 2000 intfs: [63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117] prefix: 192.168.0.129/25 prefix_v6: fc02:1000:0:1::1/64 tag: 2000 Get the ipv4 or ipv6 address for specific vlan interface from configuration. How did you do it? For vlan 1000, intf_ipv4_addr.network_address is 192.168.0.0, after increase 129, it becomes 192.168.0.129, which is same with ip address of the second vlan interface. ptf_intf_ipv4_addr = increment_ipv4_addr(intf_ipv4_addr.network_address, incr=129) Parse ipv4 or ipv6 address from config_facts['VLAN_INTERFACE'][vlan_name], different vlan_name will get differnet ip address How did you verify/test it? run tests/generic_config_updater/test_dynamic_acl.py -------------------------------------------------------------------------------------------------------------------------------------------------- live log sessionfinish --------------------------------------------------------------------------------------------------------------------------------------------------10:29:19 __init__.pytest_terminal_summary L0067 INFO | Can not get Allure report URL. Please check logs ====================================================================================================================================== 24 passed, 236 warnings in 4379.67s (1:12:59) =======================================================================================================================================DEBUG:tests.conftest:[log_custom_msg] item: <Function test_gcu_acl_nonexistent_table_removal[default-Vlan1000]> INFO:root:Can not get Allure report URL. Please check logs #### Any platform specific information?
1 parent 052724b commit c50ed80

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

tests/generic_config_updater/test_dynamic_acl.py

+22-10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import binascii
55
import netaddr
66
import struct
7+
import math
78

89
from tests.common.helpers.assertions import pytest_require, pytest_assert
910

@@ -214,16 +215,16 @@ def setup(rand_selected_dut, rand_unselected_dut, tbinfo, vlan_name, topo_scenar
214215
scale_dest_ips[ipv4_rule_name] = ipv4_address
215216
scale_dest_ips[ipv6_rule_name] = ipv6_address
216217

217-
vlan_ips = {}
218-
219-
for vlan_interface_info_dict in mg_facts['minigraph_vlan_interfaces']:
220-
if netaddr.IPAddress(str(vlan_interface_info_dict['addr'])).version == 6:
221-
vlan_ips["V6"] = vlan_interface_info_dict['addr']
222-
elif netaddr.IPAddress(str(vlan_interface_info_dict['addr'])).version == 4:
223-
vlan_ips["V4"] = vlan_interface_info_dict['addr']
224-
225218
config_facts = rand_selected_dut.config_facts(host=rand_selected_dut.hostname, source="running")['ansible_facts']
226219

220+
vlan_ips = {}
221+
for vlan_ip_address in config_facts['VLAN_INTERFACE'][vlan_name].keys():
222+
ip_address = vlan_ip_address.split("/")[0]
223+
if netaddr.IPAddress(str(ip_address)).version == 6:
224+
vlan_ips["V6"] = ip_address
225+
elif netaddr.IPAddress(str(ip_address)).version == 4:
226+
vlan_ips["V4"] = ip_address
227+
227228
vlans = config_facts['VLAN']
228229
topology = tbinfo['topo']['name']
229230
dut_mac = ''
@@ -381,14 +382,25 @@ def prepare_ptf_intf_and_ip(request, rand_selected_dut, config_facts, intfs_for_
381382
except ValueError:
382383
continue
383384

385+
vlan_num = len(config_facts['VLAN_INTERFACE'])
386+
logging.info("It has {} vlan.".format(config_facts['VLAN_INTERFACE'].keys()))
387+
# by default, if it's 2 vlan config, ipv4 range for vlan1000 is 192.168.0.1/25
388+
# and ipv4 range for vlan2000 192.168.0.129/25, so set increment to 65,
389+
# ptf_intf_ipv4_addr will be in the first VLAN's IP range.
390+
# otherwise, incrementing by 129 will cause ptf_intf_ipv4_addr overlap within the second VLAN's IP range
391+
392+
# For 1 vlan, increment is 129
393+
# for 2 vlans, increment is 65
394+
increment = math.ceil(129 / vlan_num)
395+
384396
# Increment address by 3 to offset it from the intf on which the address may be learned
385397
if intf_ipv4_addr is not None:
386-
ptf_intf_ipv4_addr = increment_ipv4_addr(intf_ipv4_addr.network_address, incr=129)
398+
ptf_intf_ipv4_addr = increment_ipv4_addr(intf_ipv4_addr.network_address, incr=increment)
387399
else:
388400
ptf_intf_ipv4_addr = None
389401

390402
if intf_ipv6_addr is not None:
391-
ptf_intf_ipv6_addr = increment_ipv6_addr(intf_ipv6_addr.network_address, incr=129)
403+
ptf_intf_ipv6_addr = increment_ipv6_addr(intf_ipv6_addr.network_address, incr=increment)
392404
else:
393405
ptf_intf_ipv6_addr = None
394406

0 commit comments

Comments
 (0)