3 # Copyright (C) 2015 Red Hat <contact@redhat.com>
5 # Author: David Zafman <dzafman@redhat.com>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Library Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library Public License for more details.
17 source $CEPH_ROOT/qa
/standalone
/ceph-helpers.sh
19 # Test development and debugging
20 # Set to "yes" in order to ignore diff errors and save results to update test
27 export CEPH_MON
="127.0.0.1:7121" # git grep '\<7121\>' : there must be only one
29 CEPH_ARGS
+="--fsid=$(uuidgen) --auth-supported=none "
30 CEPH_ARGS
+="--mon-host=$CEPH_MON "
32 local funcs
=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')}
33 for func
in $funcs ; do
34 setup
$dir ||
return 1
35 $func $dir ||
return 1
36 teardown
$dir ||
return 1
40 function TEST_scrub_snaps
() {
46 TESTDATA
="testdata.$$"
48 run_mon
$dir a
--osd_pool_default_size=$OSDS ||
return 1
49 run_mgr
$dir x ||
return 1
50 for osd
in $
(seq 0 $
(expr $OSDS - 1))
52 run_osd
$dir $osd ||
return 1
55 # Create a pool with a single pg
56 create_pool
$poolname 1 1
57 wait_for_clean ||
return 1
58 poolid
=$
(ceph osd dump |
grep "^pool.*[']test[']" |
awk '{ print $2 }')
60 dd if=/dev
/urandom of
=$TESTDATA bs
=1032 count
=1
61 for i
in `seq 1 $OBJS`
63 rados
-p $poolname put obj
${i} $TESTDATA
66 local primary
=$
(get_primary
$poolname obj1
)
68 rados
-p $poolname mksnap snap
${SNAP}
69 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
70 rados
-p $poolname put obj1
$TESTDATA
71 rados
-p $poolname put obj5
$TESTDATA
72 rados
-p $poolname put obj3
$TESTDATA
74 do rados
-p $poolname put obj
${i} $TESTDATA
78 rados
-p $poolname mksnap snap
${SNAP}
79 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
80 rados
-p $poolname put obj5
$TESTDATA
83 rados
-p $poolname mksnap snap
${SNAP}
84 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
85 rados
-p $poolname put obj3
$TESTDATA
88 rados
-p $poolname mksnap snap
${SNAP}
89 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
90 rados
-p $poolname put obj5
$TESTDATA
91 rados
-p $poolname put obj2
$TESTDATA
94 rados
-p $poolname mksnap snap
${SNAP}
96 rados
-p $poolname mksnap snap
${SNAP}
97 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=${SNAP}
98 rados
-p $poolname put obj5
$TESTDATA
101 rados
-p $poolname mksnap snap
${SNAP}
103 rados
-p $poolname rm obj4
104 rados
-p $poolname rm obj2
106 kill_daemons
$dir TERM osd ||
return 1
108 # Don't need to use ceph_objectstore_tool() function because osd stopped
110 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj1)"
111 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" --force remove
113 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --op list obj5 | grep \"snapid\":2)"
114 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" remove
116 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --op list obj5 | grep \"snapid\":1)"
118 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" remove
120 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --op list obj5 | grep \"snapid\":4)"
121 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=18
122 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" set-bytes
$TESTDATA
124 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj3)"
125 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=15
126 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" set-bytes
$TESTDATA
128 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --op list obj4 | grep \"snapid\":7)"
129 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" remove
131 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj2)"
132 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" rm-attr snapset
134 # Create a clone which isn't in snapset and doesn't have object info
135 JSON
="$(echo "$OBJ5SAVE" | sed s/snapid\":1/snapid\":7/)"
136 dd if=/dev
/urandom of
=$TESTDATA bs
=256 count
=7
137 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" set-bytes
$TESTDATA
141 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj6)"
142 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" clear-snapset
143 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj7)"
144 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" clear-snapset corrupt
145 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj8)"
146 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" clear-snapset
seq
147 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj9)"
148 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" clear-snapset clone_size
149 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj10)"
150 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" clear-snapset clone_overlap
151 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj11)"
152 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" clear-snapset clones
153 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj12)"
154 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" clear-snapset
head
155 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj13)"
156 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" clear-snapset snaps
157 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj14)"
158 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" clear-snapset size
160 echo "garbage" > $dir/bad
161 JSON
="$(ceph-objectstore-tool --data-path $dir/${primary} --head --op list obj15)"
162 ceph-objectstore-tool
--data-path $dir/${primary} "$JSON" set-attr snapset
$dir/bad
165 for osd
in $
(seq 0 $
(expr $OSDS - 1))
167 run_osd
$dir $osd ||
return 1
170 local pgid
="${poolid}.0"
171 if ! pg_scrub
"$pgid" ; then
175 grep 'log_channel' $dir/osd
.0.log
177 rados list-inconsistent-pg
$poolname > $dir/json ||
return 1
179 test $
(jq
'. | length' $dir/json
) = "1" ||
return 1
181 test $
(jq
-r '.[0]' $dir/json
) = $pgid ||
return 1
183 rados list-inconsistent-snapset
$pgid > $dir/json ||
return 1
185 local jqfilter
='.inconsistents'
186 local sortkeys
='import json; import sys ; JSON=sys.stdin.read() ; ud = json.loads(JSON) ; print json.dumps(ud, sort_keys=True, indent=2)'
188 jq
"$jqfilter" << EOF | python -c "$sortkeys" > $dir/checkcsjson
667 jq
"$jqfilter" $dir/json | python
-c "$sortkeys" > $dir/csjson
668 diff ${DIFFCOLOPTS} $dir/checkcsjson
$dir/csjson ||
test $getjson = "yes" ||
return 1
669 if test $getjson = "yes"
671 jq
'.' $dir/json
> save1.json
674 if test "$LOCALRUN" = "yes" && which jsonschema
> /dev
/null
;
676 jsonschema
-i $dir/json
$CEPH_ROOT/doc
/rados
/command
/list-inconsistent-snap.json ||
return 1
681 rados
-p $poolname rmsnap snap
$i
686 pidfile
=$
(find $dir 2>/dev
/null |
grep $name_prefix'[^/]*\.pid')
690 echo "OSD crash occurred"
691 tail -100 $dir/osd
.0.log
692 ERRORS
=$
(expr $ERRORS + 1)
695 kill_daemons
$dir ||
return 1
697 declare -a err_strings
698 err_strings
[0]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj10:.* is missing in clone_overlap"
699 err_strings
[1]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj5:7 no '_' attr"
700 err_strings
[2]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj5:7 is an unexpected clone"
701 err_strings
[3]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*::obj5:4 on disk size [(]4608[)] does not match object info size [(]512[)] adjusted for ondisk to [(]512[)]"
702 err_strings
[4]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj5:head expected clone .*:::obj5:2"
703 err_strings
[5]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj5:head expected clone .*:::obj5:1"
704 err_strings
[6]="log_channel[(]cluster[)] log [[]INF[]] : scrub [0-9]*[.]0 .*:::obj5:head 2 missing clone[(]s[)]"
705 err_strings
[7]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj12:head snapset.head_exists=false, but head exists"
706 err_strings
[8]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj8:head snaps.seq not set"
707 err_strings
[9]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj7:head snapset.head_exists=false, but head exists"
708 err_strings
[10]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj7:1 is an unexpected clone"
709 err_strings
[11]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj3:head on disk size [(]3840[)] does not match object info size [(]768[)] adjusted for ondisk to [(]768[)]"
710 err_strings
[12]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj6:1 is an unexpected clone"
711 err_strings
[13]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj2:head no 'snapset' attr"
712 err_strings
[14]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj2:7 clone ignored due to missing snapset"
713 err_strings
[15]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj2:4 clone ignored due to missing snapset"
714 err_strings
[16]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj4:head expected clone .*:::obj4:7"
715 err_strings
[17]="log_channel[(]cluster[)] log [[]INF[]] : scrub [0-9]*[.]0 .*:::obj4:head 1 missing clone[(]s[)]"
716 err_strings
[18]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj1:1 is an unexpected clone"
717 err_strings
[19]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj9:1 is missing in clone_size"
718 err_strings
[20]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj11:1 is an unexpected clone"
719 err_strings
[21]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj14:1 size 1032 != clone_size 1033"
720 err_strings
[22]="log_channel[(]cluster[)] log [[]ERR[]] : [0-9]*[.]0 scrub 22 errors"
721 err_strings
[23]="log_channel[(]cluster[)] log [[]ERR[]] : scrub [0-9]*[.]0 .*:::obj15:head can't decode 'snapset' attr buffer"
723 for err_string
in "${err_strings[@]}"
725 if ! grep "$err_string" $dir/osd.
${primary}.log
> /dev
/null
;
727 echo "Missing log message '$err_string'"
728 ERRORS
=$
(expr $ERRORS + 1)
732 if [ $ERRORS != "0" ];
734 echo "TEST FAILED WITH $ERRORS ERRORS"
742 main osd-scrub-snaps
"$@"
745 # compile-command: "cd ../.. ; make -j4 && \
746 # test/osd/osd-scrub-snaps.sh"