]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cleaned up scripts
authortamil <tamil@ubuntu.(none)>
Sat, 10 Nov 2012 01:55:20 +0000 (17:55 -0800)
committertamil <tamil@ubuntu.(none)>
Sat, 10 Nov 2012 01:55:32 +0000 (17:55 -0800)
Signed-off-by: tamil <tamil.muthamizhan@inktank.com>
qa/qa_scripts/S3Lib.pm
qa/qa_scripts/s3-file-test.pl

index 6e16bfc7a39b08c0efe91f0e0d73d5659c2c31f9..c6527d0835cb233a1969b16217cff056b009b716 100644 (file)
@@ -9,10 +9,50 @@ package S3Lib;
 use Cwd;
 use Exporter;
 @ISA = 'Exporter';
-@EXPORT_OK = qw(get_hostname get_user_info $rgw_user delete_user _write_log_entry _exit_result get_status);
+@EXPORT_OK = qw(display_ceph_os_info get_timestamp get_hostname get_user_info $rgw_user delete_user _write_log_entry _exit_result get_status);
 
 #==variables ===
 my $rgw_user = "qa_user";
+my $sec;
+my $min;
+my $hour;
+my $mon;
+my $year;
+my $mday;
+my $wday;
+my $yday;
+my $isdst;
+
+# function to get the current time stamp from the test set up
+sub get_timestamp {
+   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
+   if ($mon < 10) { $mon = "0$mon"; }
+   if ($hour < 10) { $hour = "0$hour"; }
+   if ($min < 10) { $min = "0$min"; }
+   if ($sec < 10) { $sec = "0$sec"; }
+   $year=$year+1900;
+   return $year . '_' . $mon . '_' . $mday . '__' . $hour . '_' . $min . '_' . $sec;
+}
+
+# Function to get the Ceph and distro info
+sub ceph_os_info
+{
+        my $ceph_v = get_command_output ( "ceph -v" );
+        my @ceph_arr = split(" ",$ceph_v);
+        $ceph_v = "Ceph Version:   $ceph_arr[2]";
+        my $os_distro = get_command_output ( "lsb_release -d" );
+        my @os_arr = split(":",$os_distro);
+        $os_distro = "Linux Flavor:$os_arr[1]";
+        return ($ceph_v, $os_distro);
+}
+
+# Function to log ceph info to log file
+sub display_ceph_os_info
+{
+        my ($vceph, $vos) = ceph_os_info();
+        my $msg = "The Tests are running on";
+        _write_log_entry ( "$msg\n$vos$vceph" );
+}
 
 # function to execute the command and return output
 sub get_cmd_op
@@ -54,12 +94,19 @@ sub _write_log_entry {
     close(TC);
 }
 
-# Function that creates the test_completed.txt as required by xstudio run at the end of the test
+# Function that creates the test_completed.txt and reports success/failure to log.txt as required by xstudio run at the end of the test
 
 sub _exit_result {
     my $exit_status = shift;
+    my $REPORT_LOG = "SUCCESS";
     open (TCOMP, '>>test_completed.txt');
     close (TCOMP);
+    if ($exit_status != 0) {
+       $REPORT_LOG = "FAILURE";
+    }
+    open(TC,'>>log.txt');
+    print TC "[$REPORT_LOG]\n";
+    close(TC);
     exit($exit_status);
 }
 
@@ -116,3 +163,4 @@ sub get_hostname
     chomp($get_host);
     return($get_host);
 }
+1;
index f96272b50753c47231883d2e6a899d81e6fe8428..cd6ee94a6e0d6624c3a4bdd42a42f6347b93ccdc 100755 (executable)
-#!/usr/bin/perl
+#! /usr/bin/perl
+
+=head1 NAME
+
+s3-file-test.pl - Script to test the S3 functionality
+
+=head1 SYNOPSIS
+
+Use:
+        perl s3-file-test.pl <test_id> [--help]
+
+Examples:
+        perl s3-file-test.pl <1|2|3|4|5>
+        or
+        perl s3-file-test.pl  --help
+
+=head1 DESCRIPTION
+
+This script intends to test the S3 functionality
+and reports the test results
+
+=head1 ARGUMENTS
+
+s3-file-test.pl takes the following arguments:
+   <test_id>
+   (mandatory) Specify the test case ID. It should be one of these values: 1|2|3|4|5
+   --help
+   (optional) Displays the usage message.
+
+=cut
+
 use Amazon::S3;
 use Data::Dumper;
 use strict;
 use IO::File;
 use Getopt::Long;
 use Digest::MD5;
+use S3Lib qw(display_ceph_os_info get_timestamp get_hostname get_user_info $rgw_user delete_user _write_log_entry _exit_result get_status);
+use Pod::Usage();
+
+my ( $help, $tc );
 
-use S3Lib qw(get_hostname get_user_info $rgw_user delete_user _write_log_entry _exit_result get_status);
+Getopt::Long::GetOptions(
+    'help' => \$help
+);
+my $tc = $ARGV[0];
+Pod::Usage::pod2usage(-verbose => 1) && exit if (( @ARGV == 0 ) || ($help) );
 
-my $exit_status=0;
-my $tc;
+#== local variables ===
+my $exit_status = 0;
 my $mytestfilename;
 my $logmsg;
 my $kruft;
-my $sec;
-my $min;
-my $hour;
-my $mon;
-my $year;
-my $mday;
-my $wday;
-my $yday;
-my $isdst;
 my $s3;
-my $domain = "front.sepia.ceph.com";
-my $host = get_hostname();
+my $domain   = "front.sepia.ceph.com";
+my $host     = get_hostname();
 my $hostname = "$host.$domain";
-
-sub get_timestamp {
-   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
-   if ($mon < 10) { $mon = "0$mon"; }
-   if ($hour < 10) { $hour = "0$hour"; }
-   if ($min < 10) { $min = "0$min"; }
-   if ($sec < 10) { $sec = "0$sec"; }
-   $year=$year+1900;
-
-   return $year . '_' . $mon . '_' . $mday . '__' . $hour . '_' . $min . '_' . $sec;
-}
-
-#
-# one time write to log with ceph version
-#
-open (TC,'>>log.txt');
-print TC "[Log] ";
-system ("ceph -v >> log.txt");
-
-#Retrieve test case index
-$tc=$ARGV[0];
-print "$tc\n";
-
-# check if service is already running
-my $state = get_status();
-if ($state){
-        _write_log_entry( "radosgw is NOT running. quitting" );
-        exit 1;
-}
-    if ($tc == 1)  { system ("dd if=/dev/zero of=/tmp/10MBfile bs=10485760 count=1");
-$mytestfilename = '10MBfile'; }
-    elsif ($tc == 2)  { system ("dd if=/dev/zero of=/tmp/100MBfile bs=10485760 count=10");
-$mytestfilename = '100MBfile'; }
-    elsif ($tc == 3)  { system ("dd if=/dev/zero of=/tmp/500MBfile bs=10485760 count=50");
-$mytestfilename = '500MBfile'; }
-    elsif ($tc == 4)  { system ("dd if=/dev/zero of=/tmp/1GBfile bs=10485760 count=100");
-$mytestfilename = '1GBfile'; }
-    elsif ($tc == 5)  { system ("dd if=/dev/zero of=/tmp/2GBfile bs=10485760 count=200");
-$mytestfilename = '2GBfile'; }
-
-    else { open (TCOMP, '>>test_completed.txt');
-        close (TCOMP);
-        exit(2)
-    }  
-
-my $testfileloc = "/tmp/".$mytestfilename;
-print "Test file = $testfileloc\n";
-#**************************************************************************
-# Modify access keys to suit the target account
-my ($access_key, $secret_key) = get_user_info();
-if ( ($access_key) && ($secret_key) ) {
-
-# Make S3 connection 
-# modify the host name if this test is run outside of QA.
-
-  $s3 = Amazon::S3->new(
-      {   aws_access_key_id     => $access_key,
-          aws_secret_access_key => $secret_key,
-          host                  => $hostname, 
-          secure                => 0,
-          retry                 => 1,
-      }
-  );
-
+my $testfileloc;
+
+# Execute the test case based on the input to the script
+sub create_file {
+    if ( $tc == 1 ) {
+        system("dd if=/dev/zero of=/tmp/10MBfile bs=10485760 count=1");
+        $mytestfilename = '10MBfile';
+    }
+    elsif ( $tc == 2 ) {
+        system("dd if=/dev/zero of=/tmp/100MBfile bs=10485760 count=10");
+        $mytestfilename = '100MBfile';
+    }
+    elsif ( $tc == 3 ) {
+        system("dd if=/dev/zero of=/tmp/500MBfile bs=10485760 count=50");
+        $mytestfilename = '500MBfile';
+    }
+    elsif ( $tc == 4 ) {
+        system("dd if=/dev/zero of=/tmp/1GBfile bs=10485760 count=100");
+        $mytestfilename = '1GBfile';
+    }
+    elsif ( $tc == 5 ) {
+        system("dd if=/dev/zero of=/tmp/2GBfile bs=10485760 count=200");
+        $mytestfilename = '2GBfile';
+    } else {
+        $exit_status = 1;
+        _exit_result($exit_status);
+    }
+    return 0;
 }
-#**************************************************************************
-
- # List the existing buckets
-  my $response = $s3->buckets;
-  foreach my $bucket ( @{ $response->{buckets} } ) {
-      print "You have a bucket: " . $bucket->bucket . "\n";
-  }
 
-  # create a new bucket (the test bucket)
-
-  my $bucketname = 'kftestbucket' . get_timestamp();
-  print "Attempting to create bucket = $bucketname\n";
-  my $bucket = $s3->add_bucket( { bucket => $bucketname } )
+# Run tests for the S3 functionality
+sub run_tests {
+    # Modify access keys to suit the target account
+    my ( $access_key, $secret_key ) = get_user_info();
+    if ( ($access_key) && ($secret_key) ) {
+        $s3 = Amazon::S3->new(
+            {
+                aws_access_key_id     => $access_key,
+                aws_secret_access_key => $secret_key,
+                host                  => $hostname,
+                secure                => 0,
+                retry                 => 1,
+            }
+        );
+    }
+
+    # List the existing buckets
+    my $response = $s3->buckets;
+    foreach my $bucket ( @{ $response->{buckets} } ) {
+        print "You have a bucket: " . $bucket->bucket . "\n";
+    }
+
+    # create a new bucket (the test bucket)
+    my $bucketname = 'kftestbucket' . get_timestamp();
+    print "Attempting to create bucket = $bucketname\n";
+    my $bucket = $s3->add_bucket( { bucket => $bucketname } )
       or die $s3->err . $s3->errstr;
-  print "Bucket Created: $bucketname\n";
-  $logmsg =  "Bucket Created: $bucketname";
-  _write_log_entry($logmsg);
-
-  # or use an existing bucket
-  #$bucket = $s3->bucket($bucketname);
-
-  # upload a file to the bucket
-print "adding file to bucket: $mytestfilename\n";
-  $bucket->add_key_filename( $mytestfilename, $testfileloc,
-      { content_type => 'text/plain', },
-  ) or die $s3->err . ": " . $s3->errstr;
-  $logmsg =  "$mytestfilename uploaded";
-  _write_log_entry($logmsg);
-
-
-  # store a value in the bucket
-  $bucket->add_key( 'reminder.txt', 'this is text via add_key' )
+    print "Bucket Created: $bucketname\n";
+    $logmsg = "Bucket Created: $bucketname";
+    _write_log_entry($logmsg);
+
+    # upload a file to the bucket
+    print "adding file to bucket: $mytestfilename\n";
+    $bucket->add_key_filename( $mytestfilename, $testfileloc,
+        { content_type => 'text/plain', },
+    ) or die $s3->err . ": " . $s3->errstr;
+    $logmsg = "$mytestfilename uploaded";
+    _write_log_entry($logmsg);
+
+    # store a value in the bucket
+    $bucket->add_key( 'reminder.txt', 'this is text via add_key' )
       or die $s3->err . ": " . $s3->errstr;
-  $logmsg =  "Text value stored in file";
-  _write_log_entry($logmsg);
-
-  # copy a file inthe bucket
-
+    $logmsg = "Text value stored in file";
+    _write_log_entry($logmsg);
 
-  # list files in the bucket
-  $response = $bucket->list_all
+    # list files in the bucket
+    $response = $bucket->list_all
       or die $s3->err . ": " . $s3->errstr;
-  foreach my $key ( @{ $response->{keys} } ) {
-      my $key_name = $key->{key};
-      my $key_size = $key->{size};
-      print "Bucket contains key '$key_name' of size $key_size\n";
-  }
-
-  # fetch file from the bucket
-print "Downloading $mytestfilename to temp file: /tmp/downloadfilepurgeme...";
-  $response = $bucket->get_key_filename( $mytestfilename, 'GET', '/tmp/downloadfilepurgeme' )
+    foreach my $key ( @{ $response->{keys} } ) {
+        my $key_name = $key->{key};
+        my $key_size = $key->{size};
+        print "Bucket contains key '$key_name' of size $key_size\n";
+    }
+
+    # fetch file from the bucket
+    print
+      "Downloading $mytestfilename to temp file: /tmp/downloadfilepurgeme...";
+    $response =
+      $bucket->get_key_filename( $mytestfilename, 'GET',
+        '/tmp/downloadfilepurgeme' )
       or die $s3->err . ": " . $s3->errstr;
-  $logmsg =  "file downloaded";
-  _write_log_entry($logmsg);
+    $logmsg = "file downloaded";
+    _write_log_entry($logmsg);
 
-
-  # fetch value from the bucket
-  $response = $bucket->get_key('reminder.txt')
+    # fetch value from the bucket
+    $response = $bucket->get_key('reminder.txt')
       or die $s3->err . ": " . $s3->errstr;
-  print "reminder.txt:\n";
-  print "  content length: " . $response->{content_length} . "\n";
-  print "    content type: " . $response->{content_type} . "\n";
-  print "            etag: " . $response->{content_type} . "\n";
-  print "         content: " . $response->{value} . "\n";
-#
-# check the original file against the downloaded file to see if the file has been
-# corrupted.
-#
-
-my $md5 = Digest::MD5->new;
-my $check = 1;
-my $File = $testfileloc;
-my $dlfile = "/tmp/downloadfilepurgeme";
-open(FILE, $File) or die "Error: Could not open $File for MD5 checksum...";
-open(DLFILE, $dlfile) or die "Error: Could not open $dlfile for MD5 checksum.";
- binmode(FILE);
- binmode(DLFILE);
- my $md5sum = $md5->addfile(*FILE)->hexdigest;
- my $md5sumdl = $md5->addfile(*DLFILE)->hexdigest;
-close FILE;
-close DLFILE;
-
-print "\n";
- print "Finished MD5 Checksum for $File:\n";
- print "$md5sum\n";
- print "Finished MD5 Checksum for $dlfile:\n";
- print "$md5sumdl\n";
- print "\n";
-
-#Compare
-if ( $md5sum eq $md5sumdl) {
-   print "Checksums are equal\n";
-  $logmsg =  "Checksums are equal";
-  _write_log_entry($logmsg);
-   }
-else {
-   print "Checksums are not equal\n";
-   $exit_status=2;  
-   $logmsg =  "[Failure] Checksums are not equal";
-  _write_log_entry($logmsg);
-
-   }
-
-  # Negative test: try deleting the bucket which still contains objects
-  # the method should return false 
-  if (!$bucket->delete_bucket) { 
-     $logmsg=  "Negative test - delete full bucket - Pass"}
-  else {
-       $logmsg = " Negative test - delete full bucket - Fail";
-       $exit_status = 3;
-       } 
-  _write_log_entry($logmsg);
-
-  # delete keys
-  $bucket->delete_key('reminder.txt') or die $s3->err . ": " . $s3->errstr;
-  $bucket->delete_key($mytestfilename)        or die $s3->err . ": " . $s3->errstr;
-  $bucket->delete_key('bogusfile')        or die $s3->err . ": " . $s3->errstr;
-  # and finally delete the bucket
-  $bucket->delete_bucket or die $s3->err . ": " . $s3->errstr;
-
-delete_user();
-
-if ($exit_status == 0){
-        open(TC,'>>log.txt');
-        print TC "[Success]\n";
-        close(TC);
-        _exit_result();
-} else {
-        open(TC,'>>log.txt');
-        print TC "[Failure]\n";
-        close(TC);
+    print "reminder.txt:\n";
+    print "  content length: " . $response->{content_length} . "\n";
+    print "    content type: " . $response->{content_type} . "\n";
+    print "            etag: " . $response->{content_type} . "\n";
+    print "         content: " . $response->{value} . "\n";
+
+    # check the original file against the downloaded file to see if the file has been
+    # corrupted.
+    my $md5    = Digest::MD5->new;
+    my $check  = 1;
+    my $File   = $testfileloc;
+    my $dlfile = "/tmp/downloadfilepurgeme";
+    open( FILE, $File )
+      or die "Error: Could not open $File for MD5 checksum...";
+    open( DLFILE, $dlfile )
+      or die "Error: Could not open $dlfile for MD5 checksum.";
+    binmode(FILE);
+    binmode(DLFILE);
+    my $md5sum   = $md5->addfile(*FILE)->hexdigest;
+    my $md5sumdl = $md5->addfile(*DLFILE)->hexdigest;
+    close FILE;
+    close DLFILE;
+
+    print "\n";
+    print "Finished MD5 Checksum for $File:\n";
+    print "$md5sum\n";
+    print "Finished MD5 Checksum for $dlfile:\n";
+    print "$md5sumdl\n";
+    print "\n";
+
+    # compare the checksums
+    if ( $md5sum eq $md5sumdl ) {
+        print "Checksums are equal\n";
+        $logmsg = "Checksums are equal";
+        _write_log_entry($logmsg);
+    }
+    else {
+        print "Checksums are not equal\n";
+        $exit_status = 2;
+        $logmsg      = "[Failure] Checksums are not equal";
+        _write_log_entry($logmsg);
+
+    }
+
+    # Negative test: try deleting the bucket which still contains objects
+    # the method should return false
+    if ( !$bucket->delete_bucket ) {
+        $logmsg = "Negative test - delete full bucket - Pass";
+    }
+    else {
+        $logmsg      = " Negative test - delete full bucket - Fail";
+        $exit_status = 3;
+    }
+    _write_log_entry($logmsg);
+
+    # delete keys
+    $bucket->delete_key('reminder.txt')  or die $s3->err . ": " . $s3->errstr;
+    $bucket->delete_key($mytestfilename) or die $s3->err . ": " . $s3->errstr;
+    $bucket->delete_key('bogusfile')     or die $s3->err . ": " . $s3->errstr;
+
+    # and finally delete the bucket
+    $bucket->delete_bucket or die $s3->err . ": " . $s3->errstr;
+}
+
+#== Main starts here===
+display_ceph_os_info();
+
+# check if service is already running
+sub check
+{
+    my $state = get_status();
+    if ($state) {
+        _write_log_entry("radosgw is NOT running. quitting");
+        $exit_status = 1;
         _exit_result($exit_status);
+    }
+}
+check();
+my $flag = create_file();
+if (!$flag) {
+    $testfileloc = "/tmp/" . $mytestfilename;
+    print "Test file = $testfileloc\n";
+    run_tests();
+    delete_user();
 }
+_exit_result($exit_status);