Commit 02aaf8e4 authored by Mac Newbold's avatar Mac Newbold

Round of changes related to idleswapping and autoswapping. The web and

back end scripts now support 3 different kind of forced swaps:

1. Idle-Swap : this is ths same one we had before. Email message to them
says it was swapped "because it was idle for too long"

2. Auto-Swap : A new one, typically for user-requested timed swapouts.
Email says it was swapped "because it was swapped in too long"

3. Force swap: Generic one, for "none of the above" cases. Just says
Experiment "has been forcibly swapped out by Testbed Operations."

The force swap option on the web now lets you choose which of these three
you want. Only "Idle-Swap" counts as an idleswap in the stats. Soon
idleswap and autoswap will be used by idlemail when it does automatic
swapping.
parent c49bba8a
......@@ -10,15 +10,14 @@ use English;
use Getopt::Std;
#
# This gets invoked from the Web interface.
# Swap an experiment in, swap it out, restart or modify.
# This gets invoked from the Web interface and from idlemail
#
sub usage()
{
print STDOUT "Usage: idleswap [-r] <pid> <eid>\n";
print STDOUT "Usage: idleswap [-i | -a] <pid> <eid>\n";
exit(-1);
}
my $optlist = "r";
my $optlist = "ia";
#
# Configure variables
......@@ -30,68 +29,50 @@ my $TBLOGS = "@TBLOGSEMAIL@";
my $TBAUDIT = "@TBAUDITEMAIL@";
my $swapexp = "$TB/bin/swapexp";
#
# Testbed Support libraries
#
use lib "@prefix@/lib";
use libaudit;
use libdb;
use libtestbed;
#
# Locals.
#
my $request = 0;
#
my $idleswap = 0;
my $autoswap = 0;
# Untaint the path
#
$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
#
# Turn off line buffering on output
#
$| = 1;
#
# We don't want to run this script unless its the real version.
#
if ($EUID != 0) {
die("*** $0:\n".
" Must be root! Maybe its a development version?\n");
}
#
# This script is setuid, so please do not run it as root. Hard to track
# what has happened.
#
if ($UID == 0) {
die("*** $0:\n".
" Please do not run this as root! Its already setuid!\n");
}
#
# Parse command arguments. Once we return from getopts, all that should
# left are the required arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
usage();
}
if (! getopts($optlist, \%options)) { usage(); }
if (defined($options{"i"})) { $idleswap = 1; }
if (defined($options{"a"})) { $autoswap = 1; }
if (defined($options{"r"})) {
$request = 1;
}
if (@ARGV != 2) {
usage();
}
my $pid = $ARGV[0];
my $eid = $ARGV[1];
#
# Untaint the arguments.
#
if ($pid =~ /^([-\@\w.]+)$/) {
$pid = $1;
}
......@@ -105,9 +86,7 @@ else {
die("Tainted argument $eid!\n");
}
#
# Only admins can forcibly swap an idle experiment out.
#
if (! TBAdmin($UID)) {
die("*** $0:\n".
" Only testbed administrators can issue a forcible swap!\n");
......@@ -123,9 +102,7 @@ if (AuditStart(0)) {
exit(0);
}
#
# Need to know the creator of the experiment.
#
my $query_result =
DBQueryFatal("SELECT * FROM experiments WHERE eid='$eid' and pid='$pid'");
......@@ -137,38 +114,33 @@ my %hashrow = $query_result->fetchhash();
my $creator = $hashrow{'expt_head_uid'};
my $gid = $hashrow{'gid'};
if (! $request) {
#
# Fire off the swap and exit.
#
# Flip to the creator. The swap happens as the creator of the
# experiment.
#
my ($unix_uid, $unix_gid, $unix_gname);
(undef,undef,$unix_uid) = getpwnam($creator) or
die("*** $0:\n".
" No such user $creator\n");
TBGroupUnixInfo($pid, $gid, \$unix_gid, \$unix_gname) or
die("*** $0:\n".
" No such group $pid/$gid\n");
# Send the email now, which terminates the audit.
AuditEnd();
$EGID = $GID = $unix_gid;
$EUID = $UID = $unix_uid;
$ENV{'USER'} = $creator;
$ENV{'LOGNAME'} = $creator;
exec "$swapexp -i -s out $pid $eid";
die("*** $0:\n".
" Failed to exec $swapexp!\n");
}
#
# Stub out the request function. Mac can move this part in when its
# time to automate the email.
# Fire off the swap and exit.
#
# Flip to the creator. The swap happens as the creator of the
# experiment.
my ($unix_uid, $unix_gid, $unix_gname);
(undef,undef,$unix_uid) = getpwnam($creator) or
die("*** $0:\n".
" No such user $creator\n");
TBGroupUnixInfo($pid, $gid, \$unix_gid, \$unix_gname) or
die("*** $0:\n".
" No such group $pid/$gid\n");
# Send the email now, which terminates the audit.
AuditEnd();
$EGID = $GID = $unix_gid;
$EUID = $UID = $unix_uid;
$ENV{'USER'} = $creator;
$ENV{'LOGNAME'} = $creator;
if ($idleswap) { $arg = "-i"; }
elsif ($autoswap) { $arg = "-a"; }
else { $arg = "-f"; }
exec "$swapexp $arg -s out $pid $eid";
die("*** $0:\n".
" The -r option is not implemented yet!\n");
" Failed to exec $swapexp!\n");
......@@ -16,11 +16,11 @@ use Getopt::Std;
sub usage()
{
print STDOUT "Usage: swapexp [-b] [-i] [-r] ".
print STDOUT "Usage: swapexp [-b] [-i | -a | -f] [-r] ".
"<-s in | out | restart | modify> <pid> <eid> [<nsfile>]\n";
exit(-1);
}
my $optlist = "s:irb";
my $optlist = "biafrs:";
#
# Configure variables
......@@ -29,6 +29,7 @@ my $TB = "@prefix@";
my $TBOPS = "@TBOPSEMAIL@";
my $TBLOGS = "@TBLOGSEMAIL@";
my $TBINFO = "$TB/expinfo";
my $TBDOCBASE = "@TBDOCBASE@";
#
# Testbed Support libraries
......@@ -41,6 +42,8 @@ my $tbdir = "$TB/bin/";
my $tbdata = "tbdata";
my $batch = 0;
my $idleswap = 0;
my $autoswap = 0;
my $force = 0;
my $reboot = 0;
my $errorstat= -1;
......@@ -82,6 +85,12 @@ if (! getopts($optlist, \%options)) {
if (defined($options{"i"})) {
$idleswap = 1;
}
if (defined($options{"a"})) {
$autoswap = 1;
}
if (defined($options{"f"})) {
$force = 1;
}
if (defined($options{"b"})) {
$batch = 1;
}
......@@ -531,9 +540,21 @@ if (defined($logname)) {
my $message =
"Experiment $eid in project $pid has been ";
if ($idleswap) {
$message .= "forcibly swapped out by\n".
"Testbed Operations because it was idle for too long.\n";
if ($idleswap || $autoswap || $force) {
$link="";
$message .= "forcibly swapped out by\nTestbed Operations";
if ($idleswap) {
$message .= " because it was idle for too long (Idle-Swap).\n".
"(See also the Idle-Swap info in \n".
"$TBDOCBASE/docwrapper.php3?docname=swapping.html )\n";
} elsif ($autoswap) {
$message .= " because it was swapped in too long (Auto-Swap).\n".
"(See also the Auto-Swap info in \n".
"$TBDOCBASE/docwrapper.php3?docname=swapping.html )\n";
} elsif ($force) {
$message .= ". (See also our Node Usage Policies in \n".
"$TBDOCBASE/docwrapper.php3?docname=swapping.html )\n";
}
}
else {
$message .= "$action.\n";
......
......@@ -46,6 +46,9 @@ if (isset($force) && $force == 1) {
}
if (!isset($idleswap)) { $idleswap=0; }
if (!isset($autoswap)) { $autoswap=0; }
if (!isset($forcetype)){ $forcetype="force"; }
if ($forcetype=="idleswap") { $idleswap=1; }
if ($forcetype=="autoswap") { $autoswap=1; }
}
else {
$force = 0;
......@@ -109,7 +112,9 @@ if (! TBExptAccessCheck($uid, $exp_pid, $exp_eid, $TB_EXPT_MODIFY)) {
#
if ($canceled) {
echo "<center><h2><br>
Experiment $action canceled!
Experiment $action canceled <br> for experiment
<A href='showproject.php3?pid=$exp_pid'>$exp_pid</A>/<a
href='showexp.php3?pid=$exp_pid&eid=$exp_eid'>$exp_eid</a>!
</h2></center>\n";
PAGEFOOTER();
......@@ -136,6 +141,14 @@ if (!$confirmed) {
if (!$swappable) {
echo "<h2>Note: This experiment is <em>NOT</em> swappable!</h2>\n";
}
echo "Force Type: <select name=forcetype>\n";
echo "<option value=force ".($forcetype=="force"?"selected":"").
">Forced Swap</option>\n";
echo "<option value=idleswap ".($forcetype=="idleswap"?"selected":"").
">Idle-Swap</option>\n";
echo "<option value=autoswap ".($forcetype=="autoswap"?"selected":"").
">Auto-Swap</option>\n";
echo "</select><br><br>\n";
echo "<input type=hidden name=force value=$force>\n";
echo "<input type=hidden name=idleswap value=$idleswap>\n";
echo "<input type=hidden name=autoswap value=$autoswap>\n";
......@@ -188,11 +201,17 @@ flush();
#
set_time_limit(0);
# Args for idleswap It passes them on to swapexp, or if it is just a
# plain force swap, it passes -f for us.
$args = "";
if ($idleswap) { $args = "-i"; }
elseif ($autoswap) { $args = "-a"; }
$output = array();
$retval = 0;
$result = exec("$TBSUEXEC_PATH $uid $unix_gid ".
($force ?
"webidleswap $exp_pid $exp_eid" :
"webidleswap $args $exp_pid $exp_eid" :
"webswapexp -s $inout $exp_pid $exp_eid"),
$output, $retval);
......
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