5 s3_bucket_quota.pl - Script to test the rgw bucket quota functionality using s3 interface.
10 perl s3_bucket_quota.pl [--help]
13 perl s3_bucket_quota.pl
15 perl s3_bucket_quota.pl --help
19 This script intends to test the rgw bucket quota funcionality using s3 interface
20 and reports the test results
24 s3_bucket_quota.pl takes the following arguments:
26 (optional) Displays the usage message.
38 use lib $FindBin::Bin;
40 use Net::Domain qw(hostfqdn);
44 Getopt::Long::GetOptions(
47 Pod::Usage::pod2usage(-verbose => 1) && exit if ($help);
49 #== local variables ===
55 my $hostdom = $ENV{RGW_FQDN}||hostfqdn();
56 my $port = $ENV{RGW_PORT}||7280;
57 our $hostname = "$hostdom:$port";
59 my $rgw_user = "qa_user";
61 # Function that deletes the user $rgw_user and write to logfile.
64 my $cmd = "$radosgw_admin user rm --uid=$rgw_user";
65 my $cmd_op = get_command_output($cmd);
66 if ($cmd_op !~ /aborting/){
67 print "user $rgw_user deleted\n";
69 print "user $rgw_user NOT deleted\n";
75 sub quota_set_max_size {
76 my $set_quota = `$radosgw_admin quota set --bucket=$bucketname --max-size=1048576000`;
77 if ($set_quota !~ /./){
78 print "quota set for the bucket: $bucketname \n";
80 print "quota set failed for the bucket: $bucketname \n";
86 sub quota_set_max_size_zero {
88 my $set_quota = `$radosgw_admin quota set --bucket=$bucketname --max-size=0`;
89 if ($set_quota !~ /./){
90 pass ("quota set for the bucket: $bucketname with max size as zero\n");
92 fail ("quota set with max size 0 failed for the bucket: $bucketname \n");
97 sub quota_set_max_objs_zero {
99 my $set_quota = `$radosgw_admin quota set --bucket=$bucketname --max-objects=0`;
100 if ($set_quota !~ /./){
101 pass ("quota set for the bucket: $bucketname with max objects as zero\n");
103 fail ("quota set with max objects 0 failed for the bucket: $bucketname \n");
108 sub quota_set_neg_size {
110 my $set_quota = `$radosgw_admin quota set --bucket=$bucketname --max-size=-1`;
111 if ($set_quota !~ /./){
112 pass ("quota set for the bucket: $bucketname with max size -1\n");
114 fail ("quota set failed for the bucket: $bucketname with max size -1 \n");
119 sub quota_set_neg_objs {
121 my $set_quota = `$radosgw_admin quota set --bucket=$bucketname --max-objects=-1`;
122 if ($set_quota !~ /./){
123 pass ("quota set for the bucket: $bucketname max objects -1 \n");
125 fail ("quota set failed for the bucket: $bucketname \n with max objects -1");
130 sub quota_set_user_objs {
131 my $set_quota = `$radosgw_admin quota set --uid=$rgw_user --quota-scope=bucket`;
132 my $set_quota1 = `$radosgw_admin quota set --bucket=$bucketname --max-objects=1`;
133 if ($set_quota1 !~ /./){
134 print "bucket quota max_objs set for the given user: $bucketname \n";
136 print "bucket quota max_objs set failed for the given user: $bucketname \n";
142 sub quota_set_user_size {
143 my $set_quota = `$radosgw_admin quota set --uid=$rgw_user --quota-scope=bucket`;
144 my $set_quota1 = `$radosgw_admin quota set --bucket=$bucketname --max-size=1048576000`;
145 if ($set_quota1 !~ /./){
146 print "bucket quota max size set for the given user: $bucketname \n";
148 print "bucket quota max size set failed for the user: $bucketname \n";
154 sub quota_set_max_obj {
156 my $set_quota = `$radosgw_admin quota set --bucket=$bucketname --max-objects=1`;
157 if ($set_quota !~ /./){
158 print "quota set for the bucket: $bucketname \n";
160 print "quota set failed for the bucket: $bucketname \n";
167 my $en_quota = `$radosgw_admin quota enable --bucket=$bucketname`;
168 if ($en_quota !~ /./){
169 print "quota enabled for the bucket: $bucketname \n";
171 print "quota enable failed for the bucket: $bucketname \n";
178 my $dis_quota = `$radosgw_admin quota disable --bucket=$bucketname`;
179 if ($dis_quota !~ /./){
180 print "quota disabled for the bucket: $bucketname \n";
182 print "quota disable failed for the bucket: $bucketname \n";
188 # upload a file to the bucket
190 print "adding file to bucket: $mytestfilename\n";
191 ($bucket->add_key_filename( $mytestfilename, $testfileloc,
192 { content_type => 'text/plain', },
193 ) and (print "upload file successful\n" ) and return 0 ) or (return 1);
198 #($bucket->delete_key($mytestfilename1) and print "delete keys on bucket succeeded second time\n" ) or die $s3->err . "delete keys on bucket failed second time\n" . $s3->errstr;
199 ($bucket->delete_bucket) and (print "bucket delete succeeded \n") or die $s3->err . "delete bucket failed\n" . $s3->errstr;
202 # set bucket quota with max_objects and verify
203 sub test_max_objects {
209 my $ret_value = upload_file();
210 if ($ret_value == 0){
211 pass ( "Test max objects passed" );
213 fail ( "Test max objects failed" );
216 delete_keys($mytestfilename);
220 # Set bucket quota for specific user and ensure max objects set for the user is validated
221 sub test_max_objects_per_user{
225 quota_set_user_objs();
227 my $ret_value = upload_file();
228 if ($ret_value == 0){
229 pass ( "Test max objects for the given user passed" );
231 fail ( "Test max objects for the given user failed" );
234 delete_keys($mytestfilename);
238 # set bucket quota with max_objects and try to exceed the max_objects and verify
239 sub test_beyond_max_objs {
246 my $ret_value = readd_file();
247 if ($ret_value == 1){
248 pass ( "set max objects and test beyond max objects passed" );
250 fail ( "set max objects and test beyond max objects failed" );
253 delete_keys($mytestfilename);
257 # set bucket quota for a user with max_objects and try to exceed the max_objects and verify
258 sub test_beyond_max_objs_user {
262 quota_set_user_objs();
265 my $ret_value = readd_file();
266 if ($ret_value == 1){
267 pass ( "set max objects for a given user and test beyond max objects passed" );
269 fail ( "set max objects for a given user and test beyond max objects failed" );
272 delete_keys($mytestfilename);
276 # set bucket quota for max size and ensure it is validated
277 sub test_quota_size {
282 quota_set_max_size();
284 my $ret_value = upload_file();
285 if ($ret_value == 1) {
286 pass ( "set max size and ensure that objects upload beyond max size is not entertained" );
287 my $retdel = delete_keys($mytestfilename);
289 print "delete objects successful \n";
292 my $ret_val1 = upload_file();
293 if ($ret_val1 == 0) {
294 pass ( "set max size and ensure that the max size is in effect" );
296 fail ( "set max size and ensure the max size takes effect" );
300 fail ( "set max size and ensure that objects beyond max size is not allowed" );
303 delete_keys($mytestfilename);
307 # set bucket quota for max size for a given user and ensure it is validated
308 sub test_quota_size_user {
313 quota_set_user_size();
315 my $ret_value = upload_file();
316 if ($ret_value == 1) {
317 pass ( "set max size for a given user and ensure that objects upload beyond max size is not entertained" );
318 my $retdel = delete_keys($mytestfilename);
320 print "delete objects successful \n";
323 my $ret_val1 = upload_file();
324 if ($ret_val1 == 0) {
325 pass ( "set max size for a given user and ensure that the max size is in effect" );
327 fail ( "set max size for a given user and ensure the max size takes effect" );
331 fail ( "set max size for a given user and ensure that objects beyond max size is not allowed" );
334 delete_keys($mytestfilename);
338 # set bucket quota size but disable quota and verify
339 sub test_quota_size_disabled {
344 quota_set_max_size();
346 my $ret_value = upload_file();
347 if ($ret_value == 0) {
348 pass ( "bucket quota size doesnt take effect when quota is disabled" );
350 fail ( "bucket quota size doesnt take effect when quota is disabled" );
353 delete_keys($mytestfilename);
357 # set bucket quota size for a given user but disable quota and verify
358 sub test_quota_size_disabled_user {
363 quota_set_user_size();
365 my $ret_value = upload_file();
366 if ($ret_value == 0) {
367 pass ( "bucket quota size for a given user doesnt take effect when quota is disabled" );
369 fail ( "bucket quota size for a given user doesnt take effect when quota is disabled" );
372 delete_keys($mytestfilename);
376 # set bucket quota for specified user and verify
378 #== Main starts here===
381 test_max_objects_per_user();
382 test_beyond_max_objs();
383 test_beyond_max_objs_user();
384 quota_set_max_size_zero();
385 quota_set_max_objs_zero();
386 quota_set_neg_objs();
387 quota_set_neg_size();
389 test_quota_size_user();
390 test_quota_size_disabled();
391 test_quota_size_disabled_user();