Skip to content

Commit a1f7320

Browse files
committed
tests: rename commonlib function, update
Let's update `get_ip_for_nic()` to `get_ipv4_for_nic()` since we're inspecting the ipv4 address. Let's also make it not use a shared global variable but rather capture the return value from the function call.
1 parent 03e6a53 commit a1f7320

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

tests/kola/data/commonlib.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ fatal() {
1212
exit 1
1313
}
1414

15-
get_ip_for_nic () {
15+
get_ipv4_for_nic() {
1616
local nic_name=$1
17-
nic_ip=""
18-
nic_ip=`ip -j addr show ${nic_name} | jq -r '.[0].addr_info | map(select(.family == "inet")) | .[0].local'`
19-
if [ -z "$nic_ip" ]; then
20-
echo "Error: can not get ${nic_name} ip"
17+
local ip=$(ip -j addr show ${nic_name} | jq -r '.[0].addr_info | map(select(.family == "inet")) | .[0].local')
18+
if [ -z "$ip" ]; then
19+
echo "Error: can not get ip for ${nic_name}"
2120
exit 1
2221
fi
22+
echo $ip
2323
}

tests/kola/networking/force-persist-ip/test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ set -xeuo pipefail
1717

1818
# Verify ens5 get staic ip via kargs
1919
nic_name="ens5"
20-
nic_ip=""
21-
get_ip_for_nic ${nic_name}
20+
nic_ip=$(get_ipv4_for_nic ${nic_name})
2221
if [ ${nic_ip} != "10.10.10.10" ]; then
2322
fatal "Error: get ${nic_name} ip = ${nic_ip}, expected is 10.10.10.10"
2423
fi

tests/kola/networking/prefer-ignition-networking/test.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ set -xeuo pipefail
1717

1818
# Verify ens5 get ip address via dhcp
1919
nic_name="ens5"
20-
nic_ip=""
21-
get_ip_for_nic ${nic_name}
20+
nic_ip=$(get_ipv4_for_nic ${nic_name})
2221
if [ ${nic_ip} != "10.0.2.31" ]; then
2322
fatal "Error: get ${nic_name} ip = ${nic_ip}, expected is 10.0.2.31"
2423
fi

0 commit comments

Comments
 (0)