Commit fcb9808c authored by Leigh B. Stoller's avatar Leigh B. Stoller

New versions that reflect changes for calling with suexec from the

webserver, as the uid of the experimentor. Not fully debugged yet
since the testbed has been kinda broken all day, but this needs to get
in if anyone else works on it.
parent 87604a1a
#!/usr/bin/perl
#!/usr/bin/perl -wT
use English;
#
# For debugging all this goo. Leaves the experiment directory intact,
# and placed in a subdir of the project directory.
#
my $debug = 1;
#
# This gets invoked from the Web interface. CD into the proper directory
# and do the tb stuff.
#
# usage: tbdoit <path to working directory> <pid> <eid> <nsfile>
# usage: tbdoit <pid> <eid> <temp_nsfile>
#
my $tbdir = "/usr/testbed/bin/";
my $projroot = "/proj";
my $tbdata = "tbdata";
#
my $tbdir = "/usr/testbed/bin/";
# Untaint the path
#
$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
if (@ARGV != 4) {
print STDOUT "Usage: tbdoit <working dir> <pid> <eid> <nsfile>\n";
#
# Check args.
#
if (@ARGV != 3) {
print STDOUT "Usage: tbdoit <pid> <eid> <temp_nsfile>\n";
exit(-1);
}
my $workdir = $ARGV[0];
my $project = $ARGV[1];
my $eid = $ARGV[2];
my $nsfile = $ARGV[3];
my $base = "$nsfile";
$_ = $base;
s/\.ns//g;
$base = $_;
my $irfile = "$base.ir";
my $repfile = "$base.report";
my $project = $ARGV[0];
my $eid = $ARGV[1];
my $tempfile= $ARGV[2];
#
# We run the TB stuff in the given directory.
# Untaint the arguments.
#
if (! chdir($workdir)) {
print STDOUT "Could not chdir to $workdir\n";
exit(-1);
if ($project =~ /^([-\@\w.]+)$/) {
$project = $1;
}
if ($eid =~ /^([-\@\w.]+)$/) {
$eid = $1;
}
if ($tempfile =~ /^([-\@\w.]+)$/) {
$tempfile = $1;
}
my $piddir = "$projroot/$project";
my $expdir = "$piddir/exp";
my $eiddir = "$expdir/$eid";
my $nsfile = "$eid.ns";
my $irfile = "$eid.ir";
my $repfile = "$eid.report";
#
# Create a directory structure for the experiment in the project directory.
#
if (system("$tbdir/mkexpdir $project $eid") != 0) {
print STDOUT "$tbdir/mkexpdir failed\n";
exit(1);
}
#
# Copy the nsfile from wherever the web server stuffed it, into the
# experiment directory.
#
if (! chdir("$eiddir/$tbdata")) {
print STDOUT "Could not chdir to $tbdata in $eiddir: $!\n";
fatal();
}
if (system("/bin/cp", "$tempfile", "$nsfile") != 0) {
print STDOUT
"Could not copy $tempfile to $eiddir/$tbdata/$nsfile: $!\n";
fatal();
}
#
# Run the various scripts.
#
print STDOUT "Running $tbdir/tbprerun with arguments: $project $eid $nsfile\n";
if (system("$tbdir/tbprerun $project $eid $nsfile") != 0) {
print STDOUT "tbprerun failed!\n";
exit(-1);
dumplog();
fatal();
}
print STDOUT "Running $tbdir/tbrun with arguments: $project $eid $irfile\n";
if (system("$tbdir/tbrun $project $eid $irfile") != 0) {
print STDOUT "tbrun failed!\n";
exit(-1);
dumplog();
fatal();
}
print STDOUT "Running tbreport with arguments: -v $irfile 2>&1 > $repfile\n";
if (system("$tbdir/tbreport -v $irfile 2>&1 > $repfile") != 0) {
print STDOUT "tbreport failed!\n";
exit(-1);
dumplog();
fatal();
}
#print STDOUT "Running mkacct with argument: $eid";
print STDOUT "Running mkacct with argument: $eid\n";
#if (system("$tbdir/mkacct $eid") != 0) {
# print STDOUT "mkacct failed!\n";
# exit(-1);
# fatal();
#}
#
# The web server will not be able to access the report file, so just
# dump it STDOUT and let the php script do something with it.
#
dumplog();
print STDOUT "Setup Success\n";
exit 0;
sub fatal()
{
if (! chdir($expdir)) {
print STDOUT "In Fatal: Could not chdir to $expdir!\n";
exit(-1);
}
if ($debug) {
$save = "$eid-$PID";
system("mv $eid $save");
}
else {
system("rm -r $eid");
}
exit(-1);
}
sub dumplog()
{
if (open(IN, "$eid.report")) {
print STDOUT "Dumping $eid.report\n";
while (<IN>) {
print STDOUT "$_";
}
close(IN);
}
}
#!/usr/bin/perl
#!/usr/bin/perl -wT
#
# This gets invoked from the Web interface. CD into the proper directory
# and do the tb stuff.
#
# usage: tbstopit <path to working directory> <project> <eid> <irfile>
# usage: tbstopit <pid> <eid>
#
my $tbdir = "/usr/testbed/bin/";
my $tbdir = "/usr/testbed/bin/";
my $projroot = "/proj";
my $tbdata = "tbdata";
if (@ARGV != 4) {
print STDOUT "Usage: tbstopit <working dir> <project> <eid> <irfile>\n";
#
# Untaint the path
#
$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Check args.
#
if (@ARGV != 2) {
print STDOUT "Usage: tbstopit <pid> <eid>\n";
exit(-1);
}
my $workdir = $ARGV[0];
my $project = $ARGV[1];
my $eid = $ARGV[2];
my $irfile = $ARGV[3];
my $project = $ARGV[0];
my $eid = $ARGV[1];
#
# We run the TB stuff in the given directory.
# Untaint the arguments.
#
if (! chdir($workdir)) {
print STDOUT "Could not chdir to $workdir\n";
exit(-1);
if ($project =~ /^([-\@\w.]+)$/) {
$project = $1;
}
if ($eid =~ /^([-\@\w.]+)$/) {
$eid = $1;
}
my $piddir = "$projroot/$project";
my $expdir = "$piddir/exp";
my $eiddir = "$expdir/$eid";
#
# CD to the proper experiment directory.
#
if (! chdir($eiddir)) {
print STDOUT "Could not chdir to $eiddir: $!\n";
#
# This exit code matters. The web script uses it.
#
exit(69);
}
print STDOUT "Running tbend with arguments: $project $eid $irfile\n";
if (system("$tbdir/tbend $project $eid $irfile") != 0) {
print STDOUT "Running tbend with arguments: $project $eid\n";
if (system("$tbdir/tbend $project $eid") != 0) {
print STDOUT "tbend failed!\n";
exit(-1);
}
print STDOUT "Removing experiment directory: $eiddir\n";
if (! chdir($expdir)) {
print STDOUT "In Fatal: Could not chdir to $expdir: $!!\n";
exit(-1);
}
system("rm -r $eid");
#print STDOUT "Running rmacct with argument: $eid\n";
#if (system("$tbdir/rmacct $eid") != 0) {
# print STDOUT "rmacct failed!\n";
......@@ -40,4 +73,3 @@ if (system("$tbdir/tbend $project $eid $irfile") != 0) {
print STDOUT "Termination Success\n";
exit 0;
......@@ -6,7 +6,7 @@ include("defs.php3");
#
PAGEHEADER("Begin an Experiment");
$mydebug = 0;
$mydebug = 1;
#
# First off, sanity check the form to make sure all the required fields
......@@ -99,6 +99,16 @@ if (strcmp($trust, "group_root") && strcmp($trust, "local_root")) {
"cannot begin an experiment in that project.", 1);
}
#
# We need the unix gid for the project for running the scripts below.
#
$query_result = mysql_db_query($TBDBNAME,
"SELECT unix_gid from projects where pid=\"$exp_pid\"");
if (($row = mysql_fetch_row($query_result)) == 0) {
TBERROR("Database Error: Getting GID for project $exp_pid.", 1);
}
$gid = $row[0];
#
# At this point enter the exp_id into the database so that it shows up as
# valid when the tb scripts run. We need to remove the entry if any of
......@@ -115,6 +125,11 @@ if (! $query_result) {
TBERROR("Database Error adding new experiment $exp_id: $err\n", 1);
}
#
# This is where the experiment hierarchy is going to be created.
#
$dirname = "$TBPROJ_DIR/$exp_pid/exp/$exp_id";
#
# If an experiment "shell" give some warm fuzzies and be done with it.
# The user is responsible for running the tb scripts on his/her own!
......@@ -122,12 +137,15 @@ if (! $query_result) {
# to clear it out of the database.
#
if ($nonsfile) {
$retval = SUEXEC($uid, $gid, "mkexpdir $exp_pid $exp_id", 0);
echo "<center><br>
<h2>Experiment Configured!<br>
The ID for your experiment in project $exp_pid is $exp_id<br>
Since you did not provide an NS script, no nodes have been
allocated.<br> You must log in and run the tbsetup scripts
yourself.
yourself. For your convenience, we have created a directory
hierarchy on the control node:<br>$dirname
</h2></center><br>\n";
if (1) {
......@@ -149,34 +167,18 @@ if ($nonsfile) {
}
#
# We are going to write out the NS file to a subdir of the testbed
# directory. The name of this directory is <pid>-<eid>, and we stash
# the <eid>.ns file in there. We then run a wrapper script as:
# We run a wrapper script that does all the work of creating the directory
# and running the tb scripts. If it fails, we get back all the output and
# give that to the user. If it succeeds, we go and find the report file
# and give that to the user.
#
# tbdoit <path to directory> <pid> <eid> <eid>.ns
# tbdoit <pid> <eid> <temp_nsfile>
#
# Later, when the experiment is ended, the directory will be deleted.
#
# There is similar path stuff in endexp.php3. Be sure to sync that up
# if you change things here.
#
# No need to tell me how bogus this is.
#
$dirname = "$TBWWW_DIR"."$TBNSSUBDIR" . "/" . "$exp_pid" . "-" . "$exp_id";
$nsname = "$dirname" . "/" . "$exp_id" . ".ns";
$irname = "$dirname" . "/" . "$exp_id" . ".ir";
$repname = "$dirname" . "/" . "$exp_id" . ".report";
$logname = "$dirname" . "/" . "$exp_id" . ".log";
$assname = "$dirname" . "/" . "assign" . ".log";
if (! mkdir($dirname, 0777)) {
TBERROR("Making directory for experiment: $dirname.", 1);
}
if (! copy($exp_nsfile, "$nsname")) {
rmdir($dirname);
TBERROR("Copying NS file for experiment into $dirname.", 1);
}
echo "<center><br>";
echo "<h3>Setting up experiment. This may take a few minutes ...</h3>";
echo "</center>";
......@@ -190,8 +192,10 @@ echo "</center>";
#
$output = array();
$retval = 0;
$result = exec("$TBBIN_DIR/tbdoit $dirname $exp_pid $exp_id $exp_id.ns",
$output, $retval);
$result = exec("$TBSUEXEC_PATH $uid $gid ".
"tbdoit $exp_pid $exp_id $exp_nsfile",
$output, $retval);
if ($retval) {
echo "<br><br><h2>
Setup Failure($retval): Output as follows:
......@@ -203,40 +207,9 @@ if ($retval) {
}
echo "</XMP>\n";
#
# Lets dump the log file also.
#
$fp = fopen($logname, "r");
if ($fp) {
echo "<br><h2>
Logfile as follows:
</h2>
<br>\n";
echo "<XMP>\n";
while ($line = fgets($fp, 1024)) {
echo "$line";
}
echo "</XMP>\n";
fclose($fp);
}
$query_result = mysql_db_query($TBDBNAME,
"DELETE FROM experiments WHERE eid='$exp_id' and pid=\"$exp_pid\"");
if (! $mydebug) {
unlink("$nsname");
if (file_exists($irname))
unlink("$irname");
if (file_exists($repname))
unlink("$repname");
if (file_exists($logname))
unlink("$logname");
if (file_exists($assname))
unlink("$assname");
if (file_exists($dirname))
rmdir("$dirname");
}
die("");
}
......@@ -251,28 +224,6 @@ if ($mydebug) {
echo "</XMP>\n";
}
#
# Make sure the report file exists, just to be safe!
#
if (! file_exists($repname)) {
$query_result = mysql_db_query($TBDBNAME,
"DELETE FROM experiments WHERE eid='$exp_id' and pid=\"$exp_pid\"");
if (! $mydebug) {
if (file_exists($nsname))
unlink("$nsname");
if (file_exists($irname))
unlink("$irname");
if (file_exists($logname))
unlink("$logname");
if (file_exists($assname))
unlink("$assname");
if (file_exists($dirname))
rmdir("$dirname");
}
TBERROR("Report file for new experiment does not exist!\n", 1);
}
echo "<center><br>";
echo "<h2>Experiment Configured!<br>";
echo "The ID for your experiment in project $exp_pid is $exp_id<br>";
......@@ -280,17 +231,17 @@ echo "Here is a summary of the nodes that were allocated<br>";
echo "</h2></center><br>";
#
# Lets dump the report file to the user.
# The tbdoit scripts dumps report output to stdout. Look for it in the
# output and send that out to the user. We cannot open the actual file
# because the project directory is not readable by world.
#
$fp = fopen($repname, "r");
if (! $fp) {
TBERROR("Error opening report file for experiment: $exp_id\n", 1);
for ($i = 0; $i < count($output); $i++) {
if (strcmp($output[$i], "Dumping $exp_id.report") == 0)
break;
}
$summary = "";
echo "<XMP>";
while ($line = fgets($fp, 1024)) {
echo "$line";
$summary = "$summary" . "$line";
echo "<XMP>\n";
for ($i = $i + 1; $i < count($output); $i++) {
echo "$output[$i]\n";
}
echo "</XMP>\n";
......
......@@ -67,55 +67,21 @@ if (mysql_num_rows($query_result) == 0) {
}
#
# As per what happened when the experiment was created, we need to
# go back to that directory and use the .ir file to terminate the
# experiment, and then delete the files and the directory.
# We need the unix gid for the project for running the scripts below.
#
# XXX These paths/filenames are setup in beginexp_process.php3.
#
# No need to tell me how bogus this is.
#
$dirname = "$TBWWW_DIR"."$TBNSSUBDIR" . "/" . "$exp_pid" . "-" . "$exp_eid";
$nsname = "$dirname" . "/" . "$exp_eid" . ".ns";
$irname = "$dirname" . "/" . "$exp_eid" . ".ir";
$repname = "$dirname" . "/" . "$exp_eid" . ".report";
$logname = "$dirname" . "/" . "$exp_eid" . ".log";
$elogname = "$dirname" . "/" . "$exp_eid" . "_end.log";
$assname = "$dirname" . "/" . "assign" . ".log";
#
# Check to see if the experiment directory exists before continuing.
# We will allow experiments to be deleted even without the files
# describing it, since in some cases the user is handling that part on
# his/her own.
#
if (! file_exists($dirname)) {
$query_result = mysql_db_query($TBDBNAME,
"DELETE FROM experiments WHERE eid='$exp_eid' and pid=\"$exp_pid\"");
if (! $query_result) {
$err = mysql_error();
TBERROR("Database Error deleting experiment $exp_eid ".
"in project $exp_pid: $err\n", 1);
}
echo "<center><br><h2>
Experiment '$exp_eid' in project '$exp_pid' Terminated!<br>
Since there was no IR file to work from, the EID has been removed,
<br>but you will need to make sure the nodes are released yourself.
</h2></center><br>";
echo "</body>
</html>\n";
die("");
$query_result = mysql_db_query($TBDBNAME,
"SELECT unix_gid from projects where pid=\"$exp_pid\"");
if (($row = mysql_fetch_row($query_result)) == 0) {
TBERROR("Database Error: Getting GID for project $exp_pid.", 1);
}
$gid = $row[0];
#
# By this point, the IR file must exist to go on.
#
if (! file_exists($irname)) {
TBERROR("IR file $irname for experiment $exp_eid does not exist!\n", 1);
}
# We run a wrapper script that does all the work of terminating the
# experiment.
#
# tbstopit <pid> <eid>
#
echo "<center><br>";
echo "<h3>Terminating the experiment. This may take a few minutes ...</h3>";
echo "</center>";
......@@ -127,40 +93,23 @@ echo "</center>";
#
$output = array();
$retval = 0;
$result = exec("$TBBIN_DIR/tbstopit $dirname $exp_pid $exp_eid $exp_eid.ir",
$output, $retval);
if ($retval) {
$result = exec("$TBSUEXEC_PATH $uid $gid tbstopit $exp_pid $exp_eid",
$output, $retval);
if ($retval && $retval != 69) {
echo "<br><br><h2>
Termination Failure($retval): Output as follows:
</h2>
<br>
<XMP>\n";
for ($i = 0; $i < count($output); $i++) {
echo "$output[$i]\n";
echo "$output[$i]\n";
}
echo "</XMP>\n";
die("");
}
#
# Remove all trace!
#
if (file_exists($nsname))
unlink("$nsname");
if (file_exists($irname))
unlink("$irname");
if (file_exists($repname))
unlink("$repname");
if (file_exists($logname))
unlink("$logname");
if (file_exists($elogname))
unlink("$elogname");
if (file_exists($assname))
unlink("$assname");
if (file_exists($dirname))
rmdir("$dirname");
#
# From the database too!
#
......@@ -174,6 +123,12 @@ if (! $query_result) {
echo "<center><br>";
echo "<h2>Experiment '$exp_eid' in project '$exp_pid' Terminated!<br>";
if ($retval == 69) {
echo "Since there was no experiment directory to work from, the EID has
been removed<br>
but you will need to make sure the nodes/vlans are released
yourself.\n";
}
echo "</h2>";
echo "</center>\n";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment