1 # Common subroutines shared by the s3 testing code
14 our $radosgw_admin = $ENV{RGW_ADMIN}||"sudo radosgw-admin";
16 # function to get the current time stamp from the test set up
18 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
19 if ($mon < 10) { $mon = "0$mon"; }
20 if ($hour < 10) { $hour = "0$hour"; }
21 if ($min < 10) { $min = "0$min"; }
22 if ($sec < 10) { $sec = "0$sec"; }
24 return $year . '_' . $mon . '_' . $mday . '_' . $hour . '_' . $min . '_' . $sec;
27 # Function to check if radosgw is already running
29 my $service = "radosgw";
30 my $cmd = "pgrep $service";
31 my $status = get_cmd_op($cmd);
32 if ($status =~ /\d+/ ){
38 # function to execute the command and return output
46 #Function that executes the CLI commands and returns the output of the command
47 sub get_command_output {
48 my $cmd_output = shift;
49 open( FH, ">>$test_log" );
50 print FH "\"$cmd_output\"\n";
51 my $exec_cmd = `$cmd_output 2>&1`;
52 print FH "$exec_cmd\n";
57 # Function to get the hostname
61 my $get_host = get_command_output($cmd);
68 print "Comment required." unless length $comment;
71 print "Test case: $TC_CNT PASSED - $comment \n";
78 print "Comment required." unless length $comment;
81 print "Test case: $TC_CNT FAILED - $comment \n";
87 print "~" x 90 . "\n";
90 # Function to create the user "qa_user" and extract the user access_key and secret_key of the user
94 my $cmd = "$radosgw_admin user create --uid=$rgw_user --display-name=$rgw_user";
95 my $cmd_op = get_command_output($cmd);
96 if ($cmd_op !~ /keys/){
99 my @get_user = (split/\n/,$cmd_op);
100 foreach (@get_user) {
101 if ($_ =~ /access_key/ ){
103 } elsif ($_ =~ /secret_key/ ){
107 my $access_key = $get_acc_key;
108 my $acc_key = (split /:/, $access_key)[1];
113 my $secret_key = $get_sec_key;
114 my $sec_key = (split /:/, $secret_key)[1];
119 return ($acc_key, $sec_key);
122 # Function that deletes the given user and all associated user data
126 my $cmd = "$radosgw_admin user rm --uid=$rgw_user --purge-data";
127 my $cmd_op = get_command_output($cmd);
129 print "user $rgw_user deleted\n";
131 print "user $rgw_user NOT deleted\n";
137 # Function to get the Ceph and distro info
140 my $ceph_v = get_command_output ( "ceph -v" );
141 my @ceph_arr = split(" ",$ceph_v);
142 $ceph_v = "Ceph Version: $ceph_arr[2]";
143 my $os_distro = get_command_output ( "lsb_release -d" );
144 my @os_arr = split(":",$os_distro);
145 $os_distro = "Linux Flavor:$os_arr[1]";
146 return ($ceph_v, $os_distro);
149 # Execute the test case based on the input to the script
151 my ($file_size, $part) = @_;
153 $mytestfilename = "$file_size.$part";
154 $testfileloc = "/tmp/".$mytestfilename;
155 if ($file_size == '10Mb'){
157 } elsif ($file_size == '100Mb'){
159 } elsif ($file_size == '500Mb'){
161 } elsif ($file_size == '1Gb'){
163 } elsif ($file_size == '2Gb'){
166 my $ret = system("dd if=/dev/zero of=$testfileloc bs=10485760 count=$cnt");
167 if ($ret) { exit 1 };
173 # Run tests for the S3 functionality
174 # Modify access key and secret key to suit the user account
176 our ( $access_key, $secret_key ) = get_user_info($user);
177 if ( ($access_key) && ($secret_key) ) {
178 $s3 = Amazon::S3->new(
180 aws_access_key_id => $access_key,
181 aws_secret_access_key => $secret_key,
189 our $bucketname = 'buck_'.get_timestamp();
190 # create a new bucket (the test bucket)
191 our $bucket = $s3->add_bucket( { bucket => $bucketname } )
192 or die $s3->err. "bucket $bucketname create failed\n". $s3->errstr;
193 print "Bucket Created: $bucketname \n";
199 (($bucket->delete_key($_[0])) and return 0) or return 1;
202 # Readd the file back to bucket
204 system("dd if=/dev/zero of=/tmp/10MBfile1 bs=10485760 count=1");
205 $mytestfilename1 = '10MBfile1';
206 print "readding file to bucket: $mytestfilename1\n";
207 ((($bucket->add_key_filename( $mytestfilename1, $testfileloc,
208 { content_type => 'text/plain', },
209 )) and (print "readding file success\n") and return 0) or (return 1));
212 # check if rgw service is already running
215 my $state = get_status();