[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] cluster/fence/agents/scsi Makefile fence_scsi_ ...



CVSROOT:	/cvs/cluster
Module name:	cluster
Changes by:	rohara sourceware org	2006-11-03 17:31:54

Modified files:
	fence/agents/scsi: Makefile 
Added files:
	fence/agents/scsi: fence_scsi_test.pl 

Log message:
	Added fence_scsi_test to help test SCSI reservation capabilities.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/fence_scsi_test.pl.diff?cvsroot=cluster&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/fence/agents/scsi/Makefile.diff?cvsroot=cluster&r1=1.8&r2=1.9

/cvs/cluster/cluster/fence/agents/scsi/fence_scsi_test.pl,v  -->  standard output
revision 1.1
--- cluster/fence/agents/scsi/fence_scsi_test.pl
+++ -	2006-11-03 17:31:55.019217000 +0000
@@ -0,0 +1,234 @@
+#!/usr/bin/perl
+
+use IPC::Open3;
+use Sys::Hostname;
+use Getopt::Std;
+use POSIX;
+
+my @devices;
+my %results;
+
+# WARNING!! Do not add code bewteen "#BEGIN_VERSION_GENERATION" and
+# "#END_VERSION_GENERATION"  It is generated by the Makefile
+
+#BEGIN_VERSION_GENERATION
+$FENCE_RELEASE_NAME="";
+$REDHAT_COPYRIGHT="";
+$BUILD_DATE="";
+#END_VERSION_GENERATION
+
+sub get_key
+{
+    my $addr = gethostbyname($name) or die "$!\n";
+
+    return unpack("H*", $addr);
+}
+
+sub register_device
+{
+    my $func = (caller(0))[3];
+    my ($dev, $key) = @_;
+
+    print "DEBUG: $func ($dev, $key)\n" if ($opt_d);
+
+    my ($in, $out, $err);
+    my $cmd = "sg_persist $dev -o -G -S $key";
+
+    my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
+
+    waitpid($pid, 0);
+
+    my $rval = WEXITSTATUS($?);
+
+    $results{$dev}[0] = $rval;
+
+    print "DEBUG: [$rval] $cmd\n" if $opt_d;
+
+    close($in);
+    close($out);
+    close($err);
+
+    return $rval;
+}
+
+sub unregister_device
+{
+    my $func = (caller(0))[3];
+    my ($dev, $key) = @_;
+
+    print "DEBUG: $func ($dev, $key)\n" if $opt_d;
+
+    my ($in, $out, $err);
+    my $cmd = "sg_persist $dev -o -G -K $key -S 0";
+
+    my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
+
+    waitpid($pid, 0);
+
+    my $rval = WEXITSTATUS($?);
+
+    $results{$dev}[1] = $rval;
+
+    print "DEBUG: [$rval] $cmd\n" if $opt_d;
+
+    close($in);
+    close($out);
+    close($err);
+
+    return $rval;
+}
+
+sub get_block_devices
+{
+    my $block_dir = "/sys/block";
+
+    opendir(DIR, $block_dir) or die "Error: $! $block_dir\n";
+
+    my @block_devices = grep { /^sd*/ } readdir(DIR);
+
+    closedir(DIR);
+
+    for $dev (@block_devices)
+    {
+	push @devices, "/dev/" . $dev;
+    }
+}
+
+sub get_cluster_devices
+{
+    my ($in, $out, $err);
+    my $cmd = "lvs --noheadings --separator : -o vg_attr,devices";
+    my $pid = open3($in, $out, $err, $cmd) or die "$!\n";
+
+    waitpid($pid, 0);
+
+    die "Error: unable to exec lvs command.\n" if WEXITSTATUS($?);
+
+    while (<$out>)
+    {
+	chomp;
+
+	my ($vg_attr, $dev) = split /:/, $_, 3;
+
+	if ($vg_attr =~ /.*c$/)
+	{
+	    $dev =~ s/\(.*\)//;
+	    push @devices, $dev;
+	}
+    }
+
+    close($in);
+    close($out);
+    close($err);
+}
+
+sub test_devices
+{
+    my $name = hostname() or die "$!\n";
+    my $addr = gethostbyname($name) or die "$!\n";
+    my $key = unpack("H*", $addr);
+
+    foreach $dev (@devices)
+    {
+	if (register_device($dev, $key) != 0)
+	{
+	}
+	if (unregister_device($dev, $key) != 0)
+	{
+	}
+    }
+}
+
+sub print_results
+{
+    my $device_count = scalar(@devices);
+
+    my $failure_count = 0;
+    my $success_count = 0;
+
+    print "\nAttempted to register with devices:\n";
+    print "-------------------------------------\n";
+
+    for $dev (@devices)
+    {
+	print "\t$dev\t";
+	if ($results{$dev}[0] == 0)
+	{
+	    $success_count++;
+	    print "Success\n";
+	}
+	else
+	{
+	    $failure_count++;
+	    print "Failure\n";
+	}
+    }
+
+    print "-------------------------------------\n";
+    print "Number of devices tested: $device_count\n";
+    print "Number of devices passed: $success_count\n";
+    print "Number of devices failed: $failure_count\n\n";
+
+    if ($failure_count != 0)
+    {
+	exit(1);
+    }
+}
+
+sub print_usage
+{
+    print "\nUsage: scsi_test [-c|-s] [-d] [-h]\n\n";
+
+    print "Options:\n\n";
+
+    print "  -c     Cluster mode. This mode is intended to test\n";
+    print "         SCSI persistent reservation capabilties for\n";
+    print "         devices that are part of existing clustered\n";
+    print "         volumes. Only devices in LVM cluster volumes\n";
+    print "         will be tested.\n\n";
+    print "  -s     SCSI mode. This mode is intended to test SCSI\n";
+    print "         persistent reservation capabilities for all SCSI\n";
+    print "         devices visible on a node.\n\n";
+    print "  -d     Debug flag. This will print debugging information\n";
+    print "         such as the actual commands being run to register\n";
+    print "         and unregister a device.\n\n";
+    print "  -h     Help. Prints out this usage information.\n\n";
+}
+
+### main ###
+
+if (getopts("cdhsv") == 0)
+{
+    print_usage;
+    exit(1);
+}
+
+if ($opt_h)
+{
+    print_usage;
+    exit(0);
+}
+
+if ($opt_c)
+{
+    print "\nTesting devices in cluster volumes...\n";
+    get_cluster_devices;
+}
+
+if ($opt_s)
+{
+    print "\nTesting all SCSI block devices...\n";
+    get_block_devices;
+}
+
+if (!$opt_c && !$opt_s)
+{
+    print "\nPlease specify either cluster or SCSI mode.\n";
+    print_usage;
+    exit(1);
+}
+
+test_devices;
+
+print_results;
+
--- cluster/fence/agents/scsi/Makefile	2006/10/13 20:40:52	1.8
+++ cluster/fence/agents/scsi/Makefile	2006/11/03 17:31:54	1.9
@@ -14,10 +14,13 @@
 TARGET= fence_scsi
 SCRIPT= scsi_reserve
 
+TEST_SOURCE= fence_scsi_test.pl
+TEST_TARGET= fence_scsi_test
+
 top_srcdir=../..
 include ${top_srcdir}/make/defines.mk
 
-all: $(TARGET)
+all: $(TARGET) $(TEST_TARGET)
 
 fence_scsi: fence_scsi.pl
 	: > $(TARGET)
@@ -28,15 +31,25 @@
 	awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(SOURCE) >> $(TARGET)
 	chmod +x $(TARGET)
 
+fence_scsi_test: fence_scsi_test.pl
+	: > $(TEST_TARGET)
+	awk "{print}(\$$1 ~ /#BEGIN_VERSION_GENERATION/){exit 0}" $(TEST_SOURCE) >> $(TEST_TARGET)
+	echo "\$$FENCE_RELEASE_NAME=\"${RELEASE}\";" >> $(TEST_TARGET)
+	${top_srcdir}/scripts/define2var ${top_srcdir}/config/copyright.cf perl REDHAT_COPYRIGHT >> $(TEST_TARGET)
+	echo "\$$BUILD_DATE=\"(built `date`)\";" >> $(TEST_TARGET)
+	awk -v p=0 "(\$$1 ~ /#END_VERSION_GENERATION/){p = 1} {if(p==1)print}" $(TEST_SOURCE) >> $(TEST_TARGET)
+	chmod +x $(TEST_TARGET)
+
 install: all
 	if [ ! -d ${sbindir} ]; then \
 		install -d ${sbindir}; \
 	fi
 	install -m755 ${TARGET} ${sbindir}
+	install -m755 ${TEST_TARGET} ${sbindir}
 	if [ ! -d ${initdir} ]; then \
 		install -d ${initdir}; \
 	fi
 	install -m755 ${SCRIPT} ${initdir}
 
 clean:
-	rm -f $(TARGET)
+	rm -f $(TARGET) $($TEST_TARGET)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]