5 s3_multipart_upload.pl - Script to test rgw multipart upload using s3 interface.
10 perl s3_multipart_upload.pl [--help]
13 perl s3_multipart_upload.pl
15 perl s3_multipart_upload.pl --help
19 This script intends to test the rgw multipart upload followed by a download
20 and verify checksum using s3 interface and reports test results
24 s3_multipart_upload.pl takes the following arguments:
26 (optional) Displays the usage message.
37 use lib $FindBin::Bin;
39 use Net::Domain qw(hostfqdn);
43 Getopt::Long::GetOptions(
46 Pod::Usage::pod2usage(-verbose => 1) && exit if ($help);
48 #== local variables ===
50 my $hostdom = $ENV{RGW_FQDN}||hostfqdn();
51 my $port = $ENV{RGW_PORT}||7280;
52 our $hostname = "$hostdom:$port";
56 # upload a file to the bucket
59 create_file($fsize, $i);
60 print "adding file to bucket $bucketname: $mytestfilename\n";
61 ($bucket->add_key_filename( $mytestfilename, $testfileloc,
62 { content_type => 'text/plain', },
63 ) and (print "upload file successful\n" ) and return 0 ) or (print "upload failed\n" and return 1);
68 ($bucket->delete_bucket) and (print "bucket delete succeeded \n") or die $s3->err . "delete bucket failed\n" . $s3->errstr;
71 # Function to perform multipart upload of given file size to the user bucket via s3 interface
74 my ($size, $parts) = @_;
75 # generate random user every time
77 # Divide the file size in to equal parts and upload to bucket in multiple parts
78 my $fsize = ($size/$parts);
83 } elsif ($parts == 100){
86 foreach my $i(1..$parts){
87 print "uploading file - part $i \n";
88 upload_file($fsize1, $i);
90 fetch_file_from_bucket($fsize1, $parts);
91 compare_cksum($fsize1, $parts);
95 # Function to download the files from bucket to verify there is no data corruption
96 sub fetch_file_from_bucket
98 # fetch file from the bucket
99 my ($fsize, $parts) = @_;
100 foreach my $i(1..$parts){
101 my $src_file = "$fsize.$i";
102 my $dest_file = "/tmp/downloadfile.$i";
104 "Downloading $src_file from bucket to $dest_file \n";
106 $bucket->get_key_filename( $src_file, GET,
108 or die $s3->err . ": " . $s3->errstr;
112 # Compare the source file with destination file and verify checksum to ensure
113 # the files are not corrupted
116 my ($fsize, $parts)=@_;
117 my $md5 = Digest::MD5->new;
119 foreach my $i (1..$parts){
120 my $src_file = "/tmp/"."$fsize".".$i";
121 my $dest_file = "/tmp/downloadfile".".$i";
122 open( FILE, $src_file )
123 or die "Error: Could not open $src_file for MD5 checksum...";
124 open( DLFILE, $dest_file )
125 or die "Error: Could not open $dest_file for MD5 checksum.";
128 my $md5sum = $md5->addfile(*FILE)->hexdigest;
129 my $md5sumdl = $md5->addfile(*DLFILE)->hexdigest;
132 # compare the checksums
133 if ( $md5sum eq $md5sumdl ) {
137 if ($flag == $parts){
138 pass("checksum verification for multipart upload passed" );
140 fail("checksum verification for multipart upload failed" );
144 #== Main starts here===
147 # The following test runs multi part upload of file size 1Gb in 10 parts
148 multipart_upload('1048576000', 10);
149 # The following test runs multipart upload of 1 Gb file in 100 parts
150 multipart_upload('1048576000', 100);