node_testsuite 4.52 KB
Newer Older
1
#!/usr/bin/perl -w
2 3
#
# Copyright (c) 2003, 2005 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
23
#
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72

use strict;

$| = 1;

my $MAX_COPY_TRIES = 5;
my $LOCAL_TEST_DIR      = "/usr/scratch";
my $LOCAL_DATABASE_DUMP = "$LOCAL_TEST_DIR/tbdb.sql";
my $LOCAL_SRC_DIR       = "$LOCAL_TEST_DIR/testbed";
my $LOCAL_TESTSUITE_DIR = "$LOCAL_TEST_DIR/testsuite";

my @CREATE_DIRS = ($LOCAL_TEST_DIR, $LOCAL_TESTSUITE_DIR);

my $basedir;
if (@ARGV == 2) {
    my ($pid, $eid) = @ARGV;
    $basedir = "/proj/$pid/exp/$eid/testsuite";
} elsif (@ARGV == 1) {
    $basedir = $ARGV[0];
} else {
    die "Usage: $0 <[pid eid] | dir>\n";
}

my $source_location = $basedir . "/testbed";
my $database_dump = $basedir . "/tbdb.sql";
my $logfile = $basedir . "/testsuite.log";
my $logdir = $basedir . "/logs";

#
# Safety check - this script WILL drop tbdb, so we want to make sure nobody
# runs it on anything other than the clone of boss!
#
my $hostname = `hostname -s`;
chomp $hostname;
if ($hostname ne "dolly") {
    die "Sorry, you're only supposed to run this on the clone of boss!";
}

$ENV{PATH} = "/usr/local/bin:/usr/local/sbin:$ENV{PATH}";

#
# Log our output
#
open STDOUT, ">$logfile" or die "Unable to open $logfile for writing: $!\n";
open STDERR, ">&STDOUT";

#
# The basic step we have to go through - all functions die() if they fail
#
73 74 75 76 77 78
sub CreateDirectories();
sub CopySource($);
sub FillDatabase($);
sub RunTestsuite();
sub CopyResults($);

79 80 81 82 83 84 85 86 87 88 89 90 91 92
CreateDirectories();
CopySource($source_location);
FillDatabase($database_dump);
RunTestsuite();
CopyResults($logdir);

sub CreateDirectories() {
    print "##### Creating directories\n";
    foreach my $dir (@CREATE_DIRS) {
	system "sudo mkdir -p $dir" and die "Unable to create $dir\n";
	system "sudo chown $< $dir" and die "Unable to set ownership on $dir\n";
    }
}

93
sub CopySource($) {
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    print "##### Copying source code\n";
    my ($source_location) = @_;
    ReliableCopy("$source_location/*",$LOCAL_SRC_DIR);
}

sub FillDatabase($) {
    my ($database_dump) = @_;
    print "##### Copying database dump\n";
    ReliableCopy($database_dump,$LOCAL_DATABASE_DUMP);
    print "##### Creating database\n";
    system "yes | mysqladmin drop tbdb" and die "Failed to drop database\n";
    system "mysqladmin create tbdb" and die "Failed to create database\n";
    print "##### Filling database\n";
    system "mysql tbdb < $LOCAL_DATABASE_DUMP"
	and die "Failed to fill database\n";
}

sub RunTestsuite() {
    print "##### Running testsuite\n";
    chdir $LOCAL_TESTSUITE_DIR
	or die "Unable to change to $LOCAL_TESTSUITE_DIR: $!\n";
    # We accept failure here, because we want to still copy the logs out
    system "$LOCAL_SRC_DIR/testsuite/tbtest -flest run tbdb frontend";
}

119 120
sub ReliableCopy($$;$);

121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
sub CopyResults($) {
    print "##### Copying back results\n";
    my ($logdir) = @_;
    system "mkdir -p $logdir" and die "Unable to create $logdir\n";
    #
    # Copy everything but the .txt files, which contain database dumps
    #
    ReliableCopy($LOCAL_TESTSUITE_DIR,"$logdir/*","*.txt");
}

#
# Copy a directory heirarchy, retrying if there are failurese, to avoid
# transient NFS problems. Returns nothing - dies if it fails
#
sub ReliableCopy($$;$) {
    my ($src, $dst, $exclude) = @_;
    #
    # We use rsync so that if something fails halfway through a big copy, we
    # will basically start where we left off rather than doing the whole thing
    # again. Bound the number of tries in case there are other, non-NFS related
    # problems (like permissions)
    #
    my $success = 0;
    my $excludestr = "";
    if ($exclude) {
	$excludestr = "--exclude '$exclude'";
    }
    foreach my $attempt (1 .. $MAX_COPY_TRIES) {
	if (!system "rsync $excludestr -a $src $dst") {
	    $success = 1;
	    last;
	}
    }

    if ($success) {
	return;
    } else {
	die "Failed to copy $src to $dst after $MAX_COPY_TRIES attempts";
    }
}