Skip to content

Commit

Permalink
Fix TypeError: 'list' object is not an iterator for test_cacl_applica…
Browse files Browse the repository at this point in the history
…tion (sonic-net#9022)

What is the motivation for this PR?
test_cacl_application failed on dualtor testbed due to TypeError: 'list' object is not an iterator.
That's because the type of ip_ntwrk.hosts() is list for LOOPBACK_INTERFACE ip address FC00:1::38/128, can't be called for next() function.
For VLAN_INTERFACE, it has some non-ip address key for dualtor testbed, such as grat_arp or proxy_arp, if call ipaddress.ip_network for them, it will throw ValueError exception, but in existing code, it executes pass next. At this time, the iface_table_name == "VLAN_INTERFACE", the code will execute next() function for previous ip_ntwrk which is got from LOOPBACK_INTERFACE. According to previous saying, the TypeError: 'list' object is not an iterator will happen here.

Signed-off-by: Zhaohui Sun <zhaohuisun@microsoft.com>
  • Loading branch information
ZhaohuiS authored Jul 20, 2023
1 parent 332dd9c commit dcaef1b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/cacl/test_cacl_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def generate_and_append_block_ip2me_traffic_rules(duthost, iptables_rules, ip6ta
# There are non-ip_address keys in ifaces. We ignore them with the except
ip_ntwrk = ipaddress.ip_network(iface_cidr, strict=False)
except ValueError:
pass
continue
# For VLAN interfaces, the IP address we want to block is the default gateway (i.e.,
# the first available host IP address of the VLAN subnet)
ip_addr = next(ip_ntwrk.hosts()) if iface_table_name == "VLAN_INTERFACE" \
Expand Down

0 comments on commit dcaef1b

Please sign in to comment.