Skip to content

Commit 14f9044

Browse files
committed
test: improve method for finding secondary interface
In some cases, the interface given in MAC_ADDR_MATCH_INTERFACE can be an alias or altname. The test cannot use the altname, it must use the "real" interface name. For example, on some systems, if `MAC_ADDR_MATCH_INTERFACE=enX1`, the test will fail because it is an altname for `ens4`: ``` + ip addr show enX1 3: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:12:34:57 brd ff:ff:ff:ff:ff:ff altname enp0s4 altname enx525400123457 altname enX1 ``` The test will now parse the output of `ip addr show $name` to get the real interface name. Also, improve the fallback method to look for common secondary interface names such as eth1 and ens4 in case MAC_ADDR_MATCH_INTERFACE is not one of these. Signed-off-by: Rich Megginson <[email protected]>
1 parent 592ad67 commit 14f9044

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/playbooks/tests_mac_address_match.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# - `vlan_profile2` (e.g., `120-vlan`) has a fixed name, designed to test a scenario
1919
# where lexicographic sorting causes the VLAN to appear before its parent interface.
2020
default_interface: "{{ lookup('env', 'MAC_ADDR_MATCH_INTERFACE') | default('eth1', true) }}"
21+
interfaces_to_check: "{{ [default_interface] + ['eth1', 'ens4', 'ens6'] | unique | list }}"
2122
profile: "{{ interface }}"
2223
vlan_profile1: "{{ interface }}.3732"
2324
vlan_profile2: "120-vlan"
@@ -44,12 +45,18 @@
4445
executable: /bin/bash
4546
cmd: |
4647
set -euxo pipefail
47-
for iface in '{{ default_interface }}' ens4; do
48+
for iface in {{ interfaces_to_check | join(" ") }}; do
4849
if ip addr show "$iface" 1>&2; then
50+
# interface exists, but may be an alias or altname
51+
# find the real name
52+
real_iface="$(ip addr show "$iface" | awk -F'[ :]' '/^[^ ]/ {print $3}')"
4953
break
5054
fi
5155
done
52-
echo "$iface"
56+
if [ -z "${real_iface:-}" ]; then
57+
real_iface=UNKNOWN_DEVICE
58+
fi
59+
echo "$real_iface"
5360
changed_when: false
5461
register: __network_interface_cmd
5562

0 commit comments

Comments
 (0)