osmith submitted this change.
scripts/kernel-test: build initrd+kernel as user
Refactor code to build the initramfs and kernel as user, instead of
running related code as root. Put the smoke_test.log into /tmp instead
of the cache dir, so we don't write as root into the cache dir. We cat
it on error anyway, so we don't need to have it in the workspace.
Change-Id: I1670dd86f2670f42eb99e4527d483965d8222402
---
M jenkins-common.sh
M scripts/kernel-test/prepare.sh
A scripts/kernel-test/smoke-test.sh
3 files changed, 46 insertions(+), 19 deletions(-)
diff --git a/jenkins-common.sh b/jenkins-common.sh
index f22158b..eae0473 100644
--- a/jenkins-common.sh
+++ b/jenkins-common.sh
@@ -467,11 +467,12 @@
cp "$initrd_project_script" \
"$CACHE_DIR/kernel-test/initrd-project-script.sh"
+ fix_perms
+
+ # Build kernel and initramfs
docker run \
--rm \
- --cap-add=NET_ADMIN \
- $(docker_kvm_param) \
- --device /dev/net/tun:/dev/net/tun \
+ --user "build" \
-v "$CACHE_DIR:/cache" \
-v "$KERNEL_TEST_DIR:/kernel-test:ro" \
-e "KERNEL_BRANCH=$KERNEL_BRANCH" \
@@ -480,11 +481,25 @@
-e "KERNEL_REMOTE_NAME=$KERNEL_REMOTE_NAME" \
-e "KERNEL_URL=$KERNEL_URL" \
-e "KERNEL_SKIP_REBUILD=$KERNEL_SKIP_REBUILD" \
- -e "KERNEL_SKIP_SMOKE_TEST=$KERNEL_SKIP_SMOKE_TEST" \
$DOCKER_ARGS \
"$@" \
"$docker_image" \
"/kernel-test/prepare.sh"
+
+ # Smoke test
+ if [ "$KERNEL_SKIP_SMOKE_TEST" != 1 ]; then
+ docker run \
+ --rm \
+ --cap-add=NET_ADMIN \
+ $(docker_kvm_param) \
+ --device /dev/net/tun:/dev/net/tun \
+ -v "$CACHE_DIR:/cache" \
+ -v "$KERNEL_TEST_DIR:/kernel-test:ro" \
+ $DOCKER_ARGS \
+ "$@" \
+ "$docker_image" \
+ "/kernel-test/smoke-test.sh"
+ fi
}
# Wait until the linux kernel is booted inside QEMU inside docker, and the
diff --git a/scripts/kernel-test/prepare.sh b/scripts/kernel-test/prepare.sh
index 1f1d1d5..a93a93d 100755
--- a/scripts/kernel-test/prepare.sh
+++ b/scripts/kernel-test/prepare.sh
@@ -1,17 +1,6 @@
#!/bin/sh -ex
KERNEL_BUILD="${KERNEL_BUILD:-0}"
-# Test if the kernel boots up, and initd code runs through without error
-kernel_smoke_test() {
- local log=/cache/kernel-test/smoke_test.log
- /kernel-test/run-qemu.sh SMOKE_TEST > "$log" 2>&1 || true
- if ! grep -q SMOKE_TEST_SUCCESS "$log"; then
- cat "$log"
- echo "ERROR: failed to boot the kernel and initrd in QEMU!"
- exit 1
- fi
-}
-
/kernel-test/initrd-build.sh
if [ "$KERNEL_BUILD" = 1 ]; then
@@ -19,7 +8,3 @@
else
cp /boot/vmlinuz-* /cache/kernel-test/linux
fi
-
-if [ "$KERNEL_SKIP_SMOKE_TEST" != 1 ]; then
- kernel_smoke_test
-fi
diff --git a/scripts/kernel-test/smoke-test.sh b/scripts/kernel-test/smoke-test.sh
new file mode 100755
index 0000000..b0570dd
--- /dev/null
+++ b/scripts/kernel-test/smoke-test.sh
@@ -0,0 +1,13 @@
+#!/bin/sh -ex
+# Test if the kernel boots up, and initd code runs through without error
+
+LOG=/tmp/smoke_test.log
+
+/kernel-test/run-qemu.sh SMOKE_TEST > "$LOG" 2>&1 || true
+
+if ! grep -q SMOKE_TEST_SUCCESS "$LOG"; then
+ cat "$LOG"
+ set +x
+ echo "ERROR: failed to boot the kernel and initrd in QEMU!"
+ exit 1
+fi
To view, visit change 36514. To unsubscribe, or for help writing mail filters, visit settings.