forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_distribution.sh
executable file
·146 lines (114 loc) · 5.35 KB
/
check_distribution.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/sh
@INCLUDE_COMMON@
echo
echo ELEKTRA CHECK DISTRIBUTION
echo
# Adds the specified namespace to a key name if the key does not have one.
# If the key already has a namespace, the namespace remains unchanged.
# The result is printed to stdout.
# $1 ... namespace
# $2 ... key name
prepend_namespace_if_not_present() {
local present_namespace=$("$KDB" namespace "$2")
if [ -z "$present_namespace" ]; then
echo "$1":"$2"
else
echo "$2"
fi
}
# high level test to check whether keys are distributed to correct
# backend
is_plugin_available sync || {
echo "Test requires sync plugin, aborting" >&2
exit 0
}
check_version
#method that does all the checking
check_distribution() {
echo " Check distribution of $1 and $2"
MOUNTPOINT1="$1"
MOUNTPOINT2="$2"
FILE1=$(mktemp /tmp/file1XXXXXX)
FILE2=$(mktemp /tmp/file2XXXXXX)
VALUE1="value111111"
VALUE2="value222222"
"$KDB" mount "$FILE1" "$MOUNTPOINT1" "$KDB_DEFAULT_STORAGE" 1> /dev/null
succeed_if "could not mount 1: $FILE1 at $MOUNTPOINT1"
"$KDB" mount "$FILE2" "$MOUNTPOINT2" "$KDB_DEFAULT_STORAGE" 1> /dev/null
succeed_if "could not mount 2: $FILE2 at $MOUNTPOINT2"
FILE=$("$KDB" file -n $(prepend_namespace_if_not_present system "$MOUNTPOINT1"))
[ "x$FILE" = "x$FILE1" ]
succeed_if "resolving of $MOUNTPOINT1 did not yield $FILE1 but $FILE"
FILE=$("$KDB" file -n $(prepend_namespace_if_not_present system "$MOUNTPOINT1"/xxx))
[ "x$FILE" = "x$FILE1" ]
succeed_if "resolving of $MOUNTPOINT1/xxx did not yield $FILE1 but $FILE"
FILE=$("$KDB" file -n $(prepend_namespace_if_not_present system "$MOUNTPOINT2"))
[ "x$FILE" = "x$FILE2" ]
succeed_if "resolving of $MOUNTPOINT2 did not yield $FILE2 but $FILE"
FILE=$("$KDB" file -n $(prepend_namespace_if_not_present system "$MOUNTPOINT2"/xxx))
[ "x$FILE" = "x$FILE2" ]
succeed_if "resolving of $MOUNTPOINT2/xxx did not yield $FILE2 but $FILE"
KEY1=$MOUNTPOINT1/key
"$KDB" set $(prepend_namespace_if_not_present system "$KEY1") $VALUE1 > /dev/null
succeed_if "could not set $KEY1"
KEY2=$MOUNTPOINT2/key
"$KDB" set $(prepend_namespace_if_not_present system "$KEY2") $VALUE2 > /dev/null
succeed_if "could not set $KEY2"
[ "x$("$KDB" sget "$KEY1" defvalue 2> /dev/null)" = "x$VALUE1" ]
succeed_if "Did not get value $VALUE1 for $KEY1"
[ "x$("$KDB" sget "$KEY2" defvalue 2> /dev/null)" = "x$VALUE2" ]
succeed_if "Did not get value $VALUE2 for $KEY2"
grep $VALUE1 "$FILE1" > /dev/null
succeed_if "did not find $VALUE1 within $FILE1"
grep $VALUE2 "$FILE2" > /dev/null
succeed_if "did not find $VALUE2 within $FILE2"
"$KDB" rm "$KEY1"
succeed_if "Could not remove $KEY1"
"$KDB" rm "$KEY2"
succeed_if "Could not remove $KEY2"
"$KDB" umount "$MOUNTPOINT1" > /dev/null
succeed_if "could not umount $MOUNTPOINT1"
"$KDB" umount "$MOUNTPOINT2" > /dev/null
succeed_if "could not umount $MOUNTPOINT2"
rm -f "$FILE1"
rm -f "$FILE2"
}
echo "Testing sibling"
check_distribution system:"$MOUNTPOINT"/distribution/a1 system:"$MOUNTPOINT"/distribution/b2
check_distribution system:/"$MOUNTPOINT"/distribution/a1 system:/"$MOUNTPOINT"/distribution/b2
check_distribution system:////"$MOUNTPOINT"/distribution///a1 system://///"$MOUNTPOINT"/distribution////b2
echo "Testing direct below"
check_distribution system:"$MOUNTPOINT"/distribution system:"$MOUNTPOINT"/distribution/b2
check_distribution system:"$MOUNTPOINT"/distribution/a1 system:"$MOUNTPOINT"/distribution
check_distribution system:///"$MOUNTPOINT"///distribution system://"$MOUNTPOINT"///distribution///b2
check_distribution system://"$MOUNTPOINT"///distribution///a1 system://"$MOUNTPOINT"///distribution
echo "Testing below"
check_distribution system:"$MOUNTPOINT"/distribution system:"$MOUNTPOINT"/distribution/b2/more/below
check_distribution system:"$MOUNTPOINT"/distribution/a1/more/below system:"$MOUNTPOINT"/distribution
check_distribution system:///"$MOUNTPOINT"////distribution system://"$MOUNTPOINT"//distribution/b2///more///below
check_distribution system:///"$MOUNTPOINT"//distribution///a1/more///below system://"$MOUNTPOINT"////distribution
if [ "x$WRITE_TO_SYSTEM" = "xYES" ]; then
echo "Testing root with normal"
check_distribution / system:"$MOUNTPOINT"/distribution
check_distribution / system://"$MOUNTPOINT"////distribution
check_distribution system:"$MOUNTPOINT"/distribution /
check_distribution system://"$MOUNTPOINT"////distribution /
echo "Testing root with cascading"
check_distribution / "$MOUNTPOINT"/distribution
check_distribution / "$MOUNTPOINT"////distribution
check_distribution "$MOUNTPOINT"/distribution /
check_distribution //"$MOUNTPOINT"////distribution /
else
echo "Excluded tests with root, set WRITE_TO_SYSTEM=YES to include them"
fi
echo "Testing cascading with normal"
check_distribution "$MOUNTPOINT"/distribution/a1 system:"$MOUNTPOINT"/distribution/b2
check_distribution "$MOUNTPOINT"/distribution system:"$MOUNTPOINT"/distribution/b2
check_distribution "$MOUNTPOINT"/distribution/a1 system:"$MOUNTPOINT"/distribution
check_distribution "$MOUNTPOINT"/distribution/a1//deep///below system:"$MOUNTPOINT"/distribution
echo "Testing cascading with cascading"
check_distribution "$MOUNTPOINT"/distribution/a1 "$MOUNTPOINT"/distribution/b2
check_distribution "$MOUNTPOINT"/distribution "$MOUNTPOINT"/distribution/b2
check_distribution "$MOUNTPOINT"/distribution/a1 "$MOUNTPOINT"/distribution
check_distribution "$MOUNTPOINT"/distribution/a1//deep///below "$MOUNTPOINT"/distribution
end_script resolver