ref: ca50f1198fbbb02b45ae585ff70e8348e2915826
parent: 2b9b4dd2bf8f2768c2f3ad2eb246d3d601d1ee2b
author: Natanael Copa <ncopa@alpinelinux.org>
date: Tue Apr 25 09:14:28 CDT 2023
init: add test for apkovl from network check that machine uuid expands in url
--- a/initramfs-init.in
+++ b/initramfs-init.in
@@ -130,12 +130,12 @@
ip_choose_if() {
if [ -n "$KOPT_BOOTIF" ]; then
mac=$(printf "%s\n" "$KOPT_BOOTIF"|sed 's/^01-//;s/-/:/g')
- dev=$(grep -l $mac /sys/class/net/*/address|head -n 1)
+ dev=$(grep -l $mac "$ROOT"/sys/class/net/*/address|head -n 1)
dev=${dev%/*}
[ -n "$dev" ] && echo "${dev##*/}" && return
fi
- for x in /sys/class/net/eth*; do
- if grep -iq up $x/operstate;then
+ for x in "$ROOT"/sys/class/net/eth*; do
+ if grep -iq up $x/operstate 2>/dev/null;then
[ -e "$x" ] && echo ${x##*/} && return
fi
done
@@ -190,13 +190,13 @@
if [ "$autoconf" = "dhcp" ]; then
# automatic configuration
- if [ ! -e /usr/share/udhcpc/default.script ]; then
+ if [ ! -e "$ROOT"/usr/share/udhcpc/default.script ]; then
echo "ERROR: DHCP requested but not present in initrd"
return 1
fi
ebegin "Obtaining IP via DHCP ($device)"
- ifconfig "$device" 0.0.0.0
- udhcpc -i "$device" -f -q
+ $MOCK ifconfig "$device" 0.0.0.0
+ $MOCK udhcpc -i "$device" -f -q
eend $?
else
# manual configuration
@@ -627,10 +627,10 @@
fi
elif is_url "$KOPT_apkovl"; then
# Fetch apkovl via network
- MACHINE_UUID=$(cat /sys/class/dmi/id/product_uuid 2>/dev/null)
+ MACHINE_UUID=$(cat "$ROOT"/sys/class/dmi/id/product_uuid 2>/dev/null)
url="$(echo "$KOPT_apkovl" | sed -e "s/{MAC}/$MAC_ADDRESS/" -e "s/{UUID}/$MACHINE_UUID/")"
ovl=/tmp/${url##*/}
- wget -O "$ovl" "$url" || ovl=
+ $MOCK wget -O "$ovl" "$url" || ovl=
else
ovl="$KOPT_apkovl"
fi
--- a/tests/initramfs-init.test
+++ b/tests/initramfs-init.test
@@ -6,7 +6,8 @@
initramfs_init_cmdline_root \
initramfs_init_blacklist \
initramfs_init_tmpfs_root \
- initramfs_init_tmpfs_root_modloop_sign
+ initramfs_init_tmpfs_root_modloop_sign \
+ initramfs_init_tmpfs_root_net_apkovl
fake_cmdline() {
mkdir -p proc
@@ -78,4 +79,16 @@
test -f sysroot/var/cache/misc/modloop.SIGN.RSA.ncopa-4d1b7620.rsa.pub
}
+initramfs_init_tmpfs_root_net_apkovl_body() {
+ fake_cmdline "apkovl=https://example.com/{UUID}/foo.apkovl.tar.gz"
+ fake_switch_root
+ fake_sysroot_init
+
+ mkdir -p sys/class/dmi/id
+ echo "c7c29fe0-cf90-4024-8ba3-208387fc7ac6" > sys/class/dmi/id/product_uuid
+
+ atf_check \
+ -o match:"wget .* https://example.com/c7c29fe0-cf90-4024-8ba3-208387fc7ac6/foo.apkovl.tar.gz" \
+ initramfs-init
+}