Skip to content

Commit

Permalink
Basic testing for overlayfs whiteout passthrough
Browse files Browse the repository at this point in the history
  • Loading branch information
mangelajo committed Sep 22, 2022
1 parent 177cdfc commit e23d202
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile-tests.am
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ _installed_or_uninstalled_test_scripts = \
tests/test-admin-deploy-nomerge.sh \
tests/test-admin-deploy-none.sh \
tests/test-admin-deploy-bootid-gc.sh \
tests/test-admin-deploy-whiteouts.sh \
tests/test-osupdate-dtb.sh \
tests/test-admin-instutil-set-kargs.sh \
tests/test-admin-upgrade-not-backwards.sh \
Expand Down
25 changes: 24 additions & 1 deletion tests/basic-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

set -euo pipefail

echo "1..$((88 + ${extra_basic_tests:-0}))"
echo "1..$((90 + ${extra_basic_tests:-0}))"

CHECKOUT_U_ARG=""
CHECKOUT_H_ARGS="-H"
Expand Down Expand Up @@ -1203,3 +1203,26 @@ if test "$(id -u)" != "0"; then
else
echo "ok # SKIP not run when root"
fi

cd ${test_tmpdir}
rm checkout-test2 -rf
$OSTREE checkout test2 checkout-test2

assert_not_has_file checkout-test2/whiteouts/whiteout
assert_not_has_file checkout-test2/whiteouts/whiteout2
assert_has_file checkout-test2/whiteouts/.ostree-wh.whiteout
assert_has_file checkout-test2/whiteouts/.ostree-wh.whiteout2

echo "ok checkout: no whiteout passthrough by default"

cd ${test_tmpdir}
rm checkout-test2 -rf
$OSTREE checkout --process-passthrough-whiteouts test2 checkout-test2

assert_not_has_file checkout-test2/whiteouts/.ostree-wh.whiteout
assert_not_has_file checkout-test2/whiteouts/.ostree-wh.whiteout2

assert_is_whiteout_device checkout-test2/whiteouts/whiteout
assert_is_whiteout_device checkout-test2/whiteouts/whiteout2

echo "ok checkout: whiteout with overlayfs passthrough processing"
7 changes: 7 additions & 0 deletions tests/kolainst/data-shared/libtest-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ assert_file_has_mode () {
fi
}

assert_is_whiteout_device () {
device_details="$(stat -c '%F %t:%T' $1)"
if [ "$device_details" != "character special file 0:0" ]; then
fatal "File '$1' is not a whiteout character device 0:0"
fi
}

assert_symlink_has_content () {
if ! test -L "$1"; then
fatal "File '$1' is not a symbolic link"
Expand Down
15 changes: 14 additions & 1 deletion tests/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ setup_test_repository () {
ln -s nonexistent baz/alink
mkdir baz/another/
echo x > baz/another/y

mkdir whiteouts
touch whiteouts/.ostree-wh.whiteout
touch whiteouts/.ostree-wh.whiteout2
chmod 755 whiteouts/.ostree-wh.whiteout2

umask "${oldumask}"

cd ${test_tmpdir}/files
Expand Down Expand Up @@ -406,7 +412,7 @@ setup_os_repository () {
mkdir osdata
cd osdata
kver=3.6.0
mkdir -p usr/bin ${bootdir} usr/lib/modules/${kver} usr/share usr/etc
mkdir -p usr/bin ${bootdir} usr/lib/modules/${kver} usr/share usr/etc usr/container/layers/abcd
kernel_path=${bootdir}/vmlinuz
initramfs_path=${bootdir}/initramfs.img
# the HMAC file is only in /usr/lib/modules
Expand Down Expand Up @@ -449,6 +455,13 @@ EOF
mkdir -p usr/etc/testdirectory
echo "a default daemon file" > usr/etc/testdirectory/test

# overlayfs whiteout passhthrough marker file
touch usr/container/layers/abcd/.ostree-wh.whiteout
chmod 400 usr/container/layers/abcd/.ostree-wh.whiteout

# overlayfs whiteout passhthrough marker file
touch usr/container/layers/abcd/.ostree-wh.whiteout2
chmod 777 usr/container/layers/abcd/.ostree-wh.whiteout2
${CMD_PREFIX} ostree --repo=${test_tmpdir}/testos-repo commit ${bootable_flag} --add-metadata-string version=1.0.9 -b testos/buildmain/x86_64-runtime -s "Build"

# Ensure these commits have distinct second timestamps
Expand Down
40 changes: 40 additions & 0 deletions tests/test-admin-deploy-whiteouts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash
#
# Copyright (C) 2020 Red Hat, Inc.
#
# SPDX-License-Identifier: LGPL-2.0+
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <https://www.gnu.org/licenses/>.

set -euox pipefail

. $(dirname $0)/libtest.sh

# Exports OSTREE_SYSROOT so --sysroot not needed.
setup_os_repository "archive" "syslinux"
${CMD_PREFIX} ostree --repo=sysroot/ostree/repo pull-local --remote=testos testos-repo testos/buildmain/x86_64-runtime

echo "1..3"
${CMD_PREFIX} ostree admin deploy --os=testos --karg=root=LABEL=foo --karg=testkarg=1 testos:testos/buildmain/x86_64-runtime
origdeployment=$(${CMD_PREFIX} ostree admin --sysroot=sysroot --print-current-dir)

assert_is_whiteout_device "${origdeployment}"/usr/container/layers/abcd/whiteout
echo "ok whiteout deployment"

assert_not_has_file "${origdeployment}"/usr/container/layers/abcd/.ostree-wh.whiteout
echo "ok .ostree-wh.whiteout not created"

assert_file_has_mode "${origdeployment}"/usr/container/layers/abcd/whiteout 400
assert_file_has_mode "${origdeployment}"/usr/container/layers/abcd/whiteout2 777
echo "ok whiteout permissions are preserved"

0 comments on commit e23d202

Please sign in to comment.