Skip to content

Commit

Permalink
Fix test_dynamic_acl incompatible issue on dualtor (#17274)
Browse files Browse the repository at this point in the history
* Fix test_dynamic_acl uncompatible issue on dualtor

Signed-off-by: Zhaohui Sun <[email protected]>

Description of PR
Summary:
Fixes # (issue)
test_dynamic_acl failed on dualtor testbed due to:

28/02/2025 16:40:42 __init__._fixture_func_decorator         L0073 ERROR  |               
AttributeError("'AnsibleUnsafeText' object has no attribute 'get'")
Traceback (most recent call last):
  File "/data/tests/common/plugins/log_section_start/__init__.py", line 71, in _fixture_func_decorator
    return fixture_func(*args, **kargs)
  File "/data/tests/generic_config_updater/test_dynamic_acl.py", line 227, in setup  
    if config_facts['VLAN_INTERFACE'][vlan_name][vlan_ip_address].get("secondary"):
AttributeError: 'AnsibleUnsafeText' object has no attribute 'get'

It's because the VLAN_INTERFACE is like this on dualtor:

    "VLAN_INTERFACE": {
      "Vlan1000": {
        "grat_arp": "enabled",
        "proxy_arp": "enabled",
        "192.168.0.1/21": {
          
        },
        "fc02:1000::1/64": {
          
        }
      }
    },

Approach
What is the motivation for this PR?
How did you do it?
Avoid to get secondary key from a string object
Signed-off-by: Zhaohui Sun <[email protected]>
  • Loading branch information
ZhaohuiS authored Mar 3, 2025
1 parent 7349353 commit b3055a8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions tests/generic_config_updater/test_dynamic_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,17 @@ def setup(rand_selected_dut, rand_unselected_dut, tbinfo, vlan_name, topo_scenar
config_facts = rand_selected_dut.config_facts(host=rand_selected_dut.hostname, source="running")['ansible_facts']

vlan_ips = {}
for vlan_ip_address in config_facts['VLAN_INTERFACE'][vlan_name].keys():
if config_facts['VLAN_INTERFACE'][vlan_name][vlan_ip_address].get("secondary"):
continue
ip_address = vlan_ip_address.split("/")[0]
for vlan_ip_address, value in config_facts['VLAN_INTERFACE'][vlan_name].items():
try:
if isinstance(value, dict) and value.get("secondary"):
continue
ip_address = vlan_ip_address.split("/")[0]
if netaddr.IPAddress(str(ip_address)).version == 6:
vlan_ips["V6"] = ip_address
elif netaddr.IPAddress(str(ip_address)).version == 4:
vlan_ips["V4"] = ip_address
except netaddr.core.AddrFormatError:
except Exception as e:
logger.error("Error parsing IP address {} {}: {}".format(vlan_ip_address, value, e))
continue

vlans = config_facts['VLAN']
Expand Down Expand Up @@ -378,10 +379,10 @@ def prepare_ptf_intf_and_ip(request, rand_selected_dut, config_facts, intfs_for_
vlan_interface = list(config_facts['VLAN_INTERFACE'].items())[0][1]

# Filter out addresses that have the "secondary" attribute set
vlan_addrs = [
addr for addr, attrs in vlan_interface.items()
if not attrs.get("secondary") # Only include if "secondary" is not set (or is false)
]
vlan_addrs = []
for addr, attrs in vlan_interface.items():
if isinstance(attrs, dict) and not attrs.get("secondary", False):
vlan_addrs.append(addr)

intf_ipv6_addr = None
intf_ipv4_addr = None
Expand Down

0 comments on commit b3055a8

Please sign in to comment.