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

Change testbed/down to emulab-ops/hwdown.

Minor cleanups in os_setup, and move some code to libdb.
parent b7f83b8e
......@@ -153,6 +153,72 @@ sub ProjMember($;$)
return 1;
}
#
# Return Experiment leader. First argument pid. Second argument is eid.
#
# usage: ExpLeader(char *pid, char *eid)
# returns char *leader if a valid pid/eid.
# returns 0 if an invalid pid/eid.
#
sub ExpLeader($$)
{
my($pid, $eid) = @_;
my $query_result =
DBQueryFatal("select expt_head_uid from experiments ".
"where eid='$eid' and pid='$pid'");
if ($query_result->numrows == 0) {
return 0;
}
my @row = $query_result->fetchrow_array();
return $row[0];
}
#
# Mark a node as down, moving it to special pid/eid. First argument is nodeid.
#
# usage: MarkNodeDown(char *nodeid)
#
sub MarkNodeDown($)
{
my($node) = $_[0];
my $query_result =
DBQueryFatal("update reserved set pid='emulab-ops', eid='hwdown' ".
"where node_id='$node'");
if ($query_result->num_rows < 1) {
DBWarn("WARNING: Could not mark $node down");
}
}
#
# Check if a particular feature is supported by an OSID.
#
# usage: OSFeatureSupported(char *osid, char *feature)
# returns 1 if supported, 0 if not.
#
sub OSFeatureSupported {
my($osid, $feature) = @_;
my $query_result =
DBQueryFatal("select osfeatures from os_info where osid='$osid'");
# Invalid OSID?
if ($query_result->numrows < 1) {
return 0;
}
foreach my $osfeature (split(',', $query_result->fetchrow_array())) {
if ($feature eq $osfeature) {
return 1;
}
}
return 0;
}
#
# Issue a DB query. Argument is a string. Returns the actual query object, so
# it is up to the caller to test it. I would not for one moment view this
......
......@@ -34,6 +34,7 @@ my $dbg = 0;
my @nodes = ();
my %osid = ();
my %waitfor = ();
my $db_result;
my @row;
#
......@@ -52,9 +53,10 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
$| = 1; #Turn off line buffering on output
#
# Testbed Support library
# Testbed Support libraries
#
push(@INC, "$TB/lib");
require libdb;
require libtestbed;
#
......@@ -87,43 +89,29 @@ else {
die("Bad data in eid: $eid.");
}
#
# Set up for querying the database.
#
use Mysql;
my $DB = Mysql->connect("localhost", $DBNAME, "script", "none");
#
# Figure out who called us. Only root, people with admin status
# in the DB, or the owner of the experiment can run this script.
#
$db_result = $DB->query("select expt_head_uid from experiments ".
"where eid='$eid' and pid='$pid'");
if ($db_result->numrows < 1) {
die("There is no experiment '$eid' in project '$pid'.\n");
}
if ($UID != 0) {
if ($UID && !TBAdmin($UID)) {
my ($me) = getpwuid($UID)
or die "$UID not in passwd file";
@row = $db_result->fetchrow_array();
if ($row[0] ne "$me") {
print STDERR "Checking for admin status ...\n" if $dbg;
$db_result = $DB->query("select admin from users where uid='$me'");
@row = $db_result->fetchrow_array();
if ($row[0] != 1) {
die("os_setup: You must be root or a TB administrator\n");
}
my $leader = ExpLeader($pid, $eid);
if ($me ne $leader) {
die("os_setup: You must be root or a TB administrator\n");
}
}
#
# Get the set of nodes, as well as the nodes table information for them.
#
$db_result = $DB->query("select * from nodes left join reserved on ".
"nodes.node_id=reserved.node_id ".
"where reserved.pid='$pid' and reserved.eid='$eid'");
$db_result =
DBQueryFatal("select * from nodes left join reserved on ".
"nodes.node_id=reserved.node_id ".
"where reserved.pid='$pid' and reserved.eid='$eid'");
if ($db_result->numrows < 1) {
die("There are no nodes assigned to experiment '$eid' in project '$pid'.");
}
......@@ -262,17 +250,8 @@ foreach my $node ( @nodes ) {
print STDOUT "$node may be down. This has been reported to testbed-ops.\n";
print STDOUT "Please end this experiment, and try again.\n";
# Reserve it to testbed down
$cmd = "update reserved set pid='testbed',eid='down' ".
"where eid='$eid' and pid='$pid' and node_id='$node'";
print "Using '$cmd'\n" if $dbg;
$db_result = $DB->query($cmd)
|| print STDERR "WARNING: Couldn't change reservation:".
$DB->errmsg."\n";
if ($db_result->num_rows < 1 ) {
print STDERR "WARNING: Couldn't change reservation!\n";
}
# Reserve it to down experiment.
MarkNodeDown($node);
# Send mail to testbed-ops about it
SENDMAIL($TBOPS, "TESTBED: Node $node is down",
......@@ -342,21 +321,3 @@ sub WaitTillAlive {
}
}
}
sub OSFeatureSupported {
local($os) = $_[0];
local($feature) = $_[1];
local($db_result);
$db_result = $DB->query("select osfeatures from os_info where osid='$os'");
if ($db_result->numrows < 1) {
return 0;
}
foreach $osfeature (split(',', $db_result->fetchrow_array())) {
if ($feature eq $osfeature) {
return 1;
}
}
return 0;
}
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