Skip to content

Commit

Permalink
fsck: Add test for --delete corruption, fix repair, and partial commi…
Browse files Browse the repository at this point in the history
…t checks

The ostree fsck test is aimed to check that it will still fail an fsck
if the repository has been repaired by fsck.  It also checks that a
pull operation corrects the error and ostree fsck will exit with zero.

The test was modeled after the following script:

rm -rf ./f1
mkdir -p ./f1
./ostree --repo=./f1 init --mode=archive-z2
mkdir -p ./trial
echo test > ./trial/test
./ostree --repo=./f1 commit --tree=dir=./trial --skip-if-unchanged --branch=exp1 --subject="test Commit"

rm -rf ./f2
mkdir -p ./f2
./ostree --repo=./f2 init
./ostree --repo=./f2 pull-local  ./f1

echo whoops > `find ./f2 |grep objects |grep \\.file `
./ostree fsck --repo=./f2 ; echo Exit: $?
./ostree fsck --delete --repo=./f2 ; echo Exit: $?
./ostree fsck --repo=./f2 ; echo Exit: $?
./ostree --repo=./f2 pull-local  ./f1
./ostree fsck --repo=./f2 ; echo Exit: $?

Signed-off-by: Jason Wessel <[email protected]>

fsck: Update test so that it will pass on fs without xattrs

The fsck test does not require xattrs to prove that it works.  It is
simple enough to change it to use an archvie instead of a bare type
repository.

Signed-off-by: Jason Wessel <[email protected]>

Closes: #1910
Approved by: cgwalters
  • Loading branch information
jwessel authored and rh-atomic-bot committed Sep 9, 2019
1 parent b709c3c commit bdbce9d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile-tests.am
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ _installed_or_uninstalled_test_scripts = \
tests/test-create-usb.sh \
tests/test-find-remotes.sh \
tests/test-fsck-collections.sh \
tests/test-fsck-delete.sh \
tests/test-init-collections.sh \
tests/test-prune-collections.sh \
tests/test-refs-collections.sh \
Expand Down
83 changes: 83 additions & 0 deletions tests/test-fsck-delete.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash
#
# Copyright © 2019 Wind River Systems, 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, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.

set -euo pipefail

. $(dirname $0)/libtest.sh

echo '1..6'

cd ${test_tmpdir}

rm -rf ./f1
mkdir -p ./f1
${CMD_PREFIX} ostree --repo=./f1 init --mode=archive-z2
rm -rf ./trial
mkdir -p ./trial
echo test > ./trial/test
${CMD_PREFIX} ostree --repo=./f1 commit --tree=dir=./trial --skip-if-unchanged --branch=exp1 --subject="test Commit"

rm -rf ./f2
mkdir -p ./f2
${CMD_PREFIX} ostree --repo=./f2 init --mode=archive-z2
${CMD_PREFIX} ostree --repo=./f2 pull-local ./f1
echo "ok 1 fsck-pre-commit"

file=`find ./f2 |grep objects |grep \\.file |tail -1 `
rm $file
echo whoops > $file

# First check for corruption
if ${CMD_PREFIX} ostree fsck --repo=./f2 > fsck 2> fsck-error; then
assert_not_reached "fsck did not fail"
fi
assert_file_has_content fsck "^Validating refs\.\.\.$"
assert_file_has_content fsck-error "^error: In commits"

echo "ok 2 fsck-fail-check"

# Fix the corruption
if ${CMD_PREFIX} ostree fsck --delete --repo=./f2 > fsck 2> fsck-error; then
assert_not_reached "fsck did not fail"
fi
assert_file_has_content fsck "^Validating refs\.\.\.$"
assert_file_has_content fsck-error "^In commits"

echo "ok 3 fsck-delete-check"

# Check that fsck still exits with non-zero after corruption fix
if ${CMD_PREFIX} ostree fsck --repo=./f2 > fsck 2> fsck-error; then
assert_not_reached "fsck did not fail"
fi
assert_file_has_content fsck "^Validating refs\.\.\.$"
assert_file_has_content fsck-error "^error: 1"

echo "ok 4 fsck-post-delete-check"

${CMD_PREFIX} ostree --repo=./f2 pull-local ./f1 > /dev/null
echo "ok 5 fsck-repair"

if ! ${CMD_PREFIX} ostree fsck --repo=./f2 > fsck 2> fsck-error; then
assert_not_reached "fsck failed when it should have passed"
fi
assert_file_has_content fsck "^Validating refs\.\.\.$"
assert_file_empty fsck-error
echo "ok 6 fsck-good"

0 comments on commit bdbce9d

Please sign in to comment.