t_setquota.sh revision 1.1.2.6 1 # $NetBSD: t_setquota.sh,v 1.1.2.6 2011/02/02 19:17:08 bouyer Exp $
2 #
3 # Copyright (c) 2011 Manuel Bouyer
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 for e in le be; do
29 for v in 1 2; do
30 for q in "user" "group"; do
31 test_case_root set_${e}_${v}_${q} set_quota \
32 "set quota with ${q} enabled" ${e} ${v} ${q}
33 test_case_root set_new_${e}_${v}_${q} set_quota_new \
34 "set quota for new id with ${q} enabled" ${e} ${v} ${q}
35 test_case_root set_default_${e}_${v}_${q} set_quota_default \
36 "set default quota with ${q} enabled" ${e} ${v} ${q}
37 done
38 test_case_root set_${e}_${v}_"both" set_quota \
39 "set quota with both enabled" ${e} ${v} "both"
40 test_case_root set_new_${e}_${v}_"both" set_quota_new \
41 "set quota for new id with both enabled" ${e} ${v} "both"
42 test_case_root set_default_${e}_${v}_"both" set_quota_default \
43 "set default quota with both enabled" ${e} ${v} "both"
44 done
45 done
46
47 set_quota()
48 {
49 create_with_quotas_server $*
50 local q=$3
51 local expect
52 local fail
53
54 case ${q} in
55 user)
56 expect=u
57 fail=g
58 ;;
59 group)
60 expect=g
61 fail=u
62 ;;
63 both)
64 expect="u g"
65 fail=""
66 ;;
67 *)
68 atf_fail "wrong quota type"
69 ;;
70 esac
71
72 #check that we can set the expected quota
73 for q in ${expect} ; do
74 local id=$(id -${q})
75 atf_check -s exit:0 \
76 $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k \
77 -t 2W/3D ${id}
78 atf_check -s exit:0 \
79 -o "match:/mnt 0 10 40960 2weeks 1 20 51200 3days" \
80 -o "match:Disk quotas for .*: $" \
81 $(atf_get_srcdir)/rump_quota -${q} -v
82 atf_check -s exit:0 \
83 -o "match:-- 0 10 40960 1 20 51200" \
84 $(atf_get_srcdir)/rump_repquota -${q} /mnt
85 done
86
87 #check that we do not get positive reply for non-expected quota
88 for q in ${fail} ; do
89 local id=$(id -${q})
90 atf_check -s exit:0 \
91 $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
92 atf_check -s exit:0 -o "not-match:/mnt" \
93 -o "not-match:Disk quotas for .*: $" \
94 -o "match:Disk quotas for .*: none$" \
95 $(atf_get_srcdir)/rump_quota -${q} -v
96 atf_check -s exit:0 \
97 -o "not-match:-- 0 - -" \
98 $(atf_get_srcdir)/rump_repquota -${q} /mnt
99 done
100 rump_shutdown
101 }
102
103 set_quota_new()
104 {
105 create_with_quotas_server $*
106 local q=$3
107 local expect
108 local fail
109
110 case ${q} in
111 user)
112 expect=u
113 fail=g
114 ;;
115 group)
116 expect=g
117 fail=u
118 ;;
119 both)
120 expect="u g"
121 fail=""
122 ;;
123 *)
124 atf_fail "wrong quota type"
125 ;;
126 esac
127
128 #check that we can set the expected quota
129 for q in ${expect} ; do
130 local id=1
131 atf_check -s exit:0 \
132 $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k \
133 -t 120W/255D ${id}
134 atf_check -s exit:0 \
135 -o "match:/mnt 0 10 40960 2years 0 20 51200 9months" \
136 -o "match:Disk quotas for .*: $" \
137 $(atf_get_srcdir)/rump_quota -${q} -v ${id}
138 done
139
140 #check that we do not get positive reply for non-expected quota
141 for q in ${fail} ; do
142 local id=$(id -${q})
143 atf_check -s exit:0 \
144 $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
145 atf_check -s exit:0 -o "not-match:/mnt" \
146 -o "not-match:Disk quotas for .*: $" \
147 -o "match:Disk quotas for .*: none$" \
148 $(atf_get_srcdir)/rump_quota -${q} -v ${id}
149 done
150 rump_shutdown
151 }
152
153 set_quota_default()
154 {
155 create_with_quotas_server $*
156 local q=$3
157 local expect
158 local fail
159
160 case ${q} in
161 user)
162 expect=u
163 fail=g
164 ;;
165 group)
166 expect=g
167 fail=u
168 ;;
169 both)
170 expect="u g"
171 fail=""
172 ;;
173 *)
174 atf_fail "wrong quota type"
175 ;;
176 esac
177
178 #check that we can set the expected quota
179 for q in ${expect} ; do
180 local id="-d"
181 atf_check -s exit:0 \
182 $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k \
183 -t 2H2M/3540 ${id}
184 atf_check -s exit:0 \
185 -o "match:/mnt 0 10 40960 2:2 0 20 51200 59" \
186 -o "match:Default (user|group) disk quotas: $" \
187 $(atf_get_srcdir)/rump_quota -${q} -v ${id}
188 done
189
190 #check that we do not get positive reply for non-expected quota
191 for q in ${fail} ; do
192 local id="-d"
193 atf_check -s exit:0 \
194 $(atf_get_srcdir)/rump_edquota -$q -s10k/20 -h40M/50k ${id}
195 atf_check -s exit:0 -o "not-match:/mnt" \
196 -o "not-match:Default (user|group) disk quotas: $" \
197 -o "match:Default (user|group) disk quotas: none$" \
198 $(atf_get_srcdir)/rump_quota -${q} -v ${id}
199 done
200 rump_shutdown
201 }
202