Update log file when rgw is not running

Signed-off-by: tamil <tamil.muthamizhan@inktank.com>
This commit is contained in:
tamil 2012-11-07 11:49:15 -08:00
parent 13486857cf
commit cca606f423
2 changed files with 42 additions and 14 deletions

View File

@ -9,11 +9,26 @@ package S3Lib;
use Cwd;
use Exporter;
@ISA = 'Exporter';
@EXPORT_OK = qw(get_user_info $rgw_user delete_user _write_log_entry _exit_result);
@EXPORT_OK = qw(get_hostname get_user_info $rgw_user delete_user _write_log_entry _exit_result get_status);
#==variables ===
my $rgw_user = "qa_user";
# Function to check if radosgw is already running
sub get_status {
my $service = "radosgw";
my $cmd = "ps -ef | grep $service | grep -v grep";
my $status = get_cmd_op($cmd);
if (!$status) {
my $cmd1 = "echo $?";
my $status1 = get_cmd_op($cmd1);
if (!$status1){
return 0;
}
}
return 1;
}
#Function that executes the CLI commands and returns the output of the command
sub get_command_output {
@ -45,23 +60,22 @@ sub _exit_result {
}
# Function to create the user "qa_user" and extract the user access_key and secret_key of the user
sub get_user_info
{
my $cmd = "sudo radosgw-admin user create --uid=$rgw_user --display-name=$rgw_user";
my $cmd_op = get_command_output($cmd);
my $cmd_op = get_command_output($cmd);
if ($cmd_op !~ /keys/){
_write_log_entry( "user $rgw_user NOT created" );
return (0,0);
return (0,0);
}
_write_log_entry( "user $rgw_user created" );
my @get_user = (split/,/,$cmd_op);
foreach (@get_user) {
if ($_ =~ /access_key/ ){
$get_acc_key = $_;
} elsif ($_ =~ /secret_key/ ){
} elsif ($_ =~ /secret_key/ ){
$get_sec_key = $_;
}
}
}
my $access_key = $get_acc_key;
my $acc_key = (split /:/, $access_key)[1];
@ -75,8 +89,7 @@ sub get_user_info
$sec_key =~ s/\\//g;
$sec_key =~ s/ //g;
$sec_key =~ s/"//g;
print "print $acc_key $sec_key \n";
return ($acc_key, $sec_key);
return ($acc_key, $sec_key);
}
# Function that deletes the user $rgw_user and write to logfile.
@ -90,3 +103,12 @@ sub delete_user
_write_log_entry( "user $rgw_user NOT deleted" );
}
}
# Function to get the hostname
sub get_hostname
{
my $cmd = "hostname";
my $get_host = get_command_output($cmd);
chomp($get_host);
return($get_host);
}

View File

@ -6,7 +6,7 @@ use IO::File;
use Getopt::Long;
use Digest::MD5;
use S3Lib qw(get_user_info $rgw_user delete_user _write_log_entry _exit_result);
use S3Lib qw(get_hostname get_user_info $rgw_user delete_user _write_log_entry _exit_result get_status);
my $exit_status=0;
my $tc;
@ -23,6 +23,10 @@ my $wday;
my $yday;
my $isdst;
my $s3;
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"; }
@ -45,7 +49,12 @@ system ("ceph -v >> log.txt");
$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");
@ -66,9 +75,6 @@ my $testfileloc = "/tmp/".$mytestfilename;
print "Test file = $testfileloc\n";
#**************************************************************************
# Modify access keys to suit the target account
#my $aws_access_key_id = 'YTK5QR2XKATOSU5D9462';
#my $aws_secret_access_key = 'i6xbrQs+edkWBdG8dY7e2DGjCZNfUwLjgEXzQw0B';
my ($access_key, $secret_key) = get_user_info();
if ( ($access_key) && ($secret_key) ) {
@ -78,7 +84,7 @@ if ( ($access_key) && ($secret_key) ) {
$s3 = Amazon::S3->new(
{ aws_access_key_id => $access_key,
aws_secret_access_key => $secret_key,
host => 'burnupi60.front.sepia.ceph.com',
host => $hostname,
secure => 0,
retry => 1,
}