Commit dc8e62a3 authored by Leigh Stoller's avatar Leigh Stoller

Minor changes to per-experiment DB stuff.

* Create a per-experiment DB user for the per-experiment DB; the user
  name is equal to the DB name.

* Add a dpdbpassword field to the experiments table; this is the
  randomly generated password for the DB user mentioned above.

* For Templates, use the above user/password in the environment,
  instead of the swapper uid/password.

* Add experiment dbname/dbpassword to the Show Experiment page.
parent 8403cf39
......@@ -127,6 +127,7 @@ sub autoswap_timeout($) { return field($_[0], 'autoswap_timeout');}
sub prerender_pid($) { return field($_[0], 'prerender_pid');}
sub dpdb($) { return field($_[0], 'dpdb');}
sub dpdbname($) { return field($_[0], 'dpdbname');}
sub dpdbpassword($) { return field($_[0], 'dpdbpassword');}
sub instance_idx($) { return field($_[0], 'instance_idx'); }
#
......
......@@ -2909,7 +2909,8 @@ sub InitializeEnvVariables($;$)
== 0 or return -1;
if ($experiment->dpdb() && $experiment->dpdbname() ne "") {
my $dpdbname = $experiment->dpdbname();
my $dpdbname = $experiment->dpdbname();
my $dpdbpassword = $experiment->dpdbpassword();
$experiment->AddEnvVariable("DP_DBNAME", $dpdbname) == 0
or return -1;
......@@ -2917,21 +2918,11 @@ sub InitializeEnvVariables($;$)
$experiment->AddEnvVariable("DP_HOST", $CONTROL) == 0
or return -1;
#
# XXX This needs to change to a per-experiment user/password.
#
$experiment->AddEnvVariable("DP_USER", $dbuid) == 0
$experiment->AddEnvVariable("DP_USER", $dpdbname) == 0
or return -1;
$query_result =
DBQueryFatal("select mailman_password from users ".
"where uid='$dbuid'");
my ($mailman_password) = $query_result->fetchrow_array();
if (defined($mailman_password)) {
$experiment->AddEnvVariable("DP_PASSWORD", $mailman_password) == 0
or return -1;
}
$experiment->AddEnvVariable("DP_PASSWORD", $dpdbpassword) == 0
or return -1;
}
#
......
......@@ -474,17 +474,24 @@ sub AddExpDB(@)
# Check to see if the experiment actually wants its own DB.
#
my $query_result =
DBQueryFatal("select dpdbname from experiments ".
DBQueryFatal("select dpdbname,dpdbpassword from experiments ".
"where pid='$pid' and eid='$eid' and dpdb!=0");
return 0
if (!$query_result->numrows);
my ($dpdbname) = $query_result->fetchrow_array();
my ($dpdbname,$dpdbpassword) = $query_result->fetchrow_array();
if (defined($dpdbname)) {
# Allow override.
$dbname = $dpdbname;
}
if (!defined($dpdbpassword)) {
$dpdbpassword = TBGenSecretKey();
$dpdbpassword = substr($dpdbpassword, 0, 10);
DBQueryFatal("update experiments set dpdbpassword='$dpdbpassword' ".
"where pid='$pid' and eid='$eid'");
}
return -1
if (!TBExptIDX($pid, $eid, \$exptidx));
......@@ -510,6 +517,20 @@ sub AddExpDB(@)
DBQueryFatal("update experiment_stats set dpdbname='$dbname' ".
"where exptidx='$exptidx'");
#
# Add a user that is named by this DB, with the password from above.
# Basically, a per-experiment DB user for the DB.
#
print "Adding user '$dbname' to mysql database on $CONTROL.\n";
$retval = DoOpsStuff("adduser $dbname", $dpdbpassword);
if ($retval && $retval != EEXIST()) {
fatal("$OPSDBPROXY failed on $CONTROL!");
}
$retval = DoOpsStuff("setdbs", "$dbname $dbname");
if ($retval) {
fatal("$OPSDBPROXY failed on $CONTROL!");
}
#
# Now we need to update the access list for everyone in the group.
#
......@@ -567,8 +588,17 @@ sub DelExpDB(@)
return -1
if (!defined($dbname));
#
# Delete the per-experiment DB user for the DB.
#
print "Deleting user '$dbname' from mysql database on $CONTROL.\n";
my $retval = DoOpsStuff("deluser $dbname");
if ($retval) {
fatal("$OPSDBPROXY failed on $CONTROL!");
}
print "Removing DB '$dbname' from mysql database on $CONTROL.\n";
my $retval = DoOpsStuff("deldb $dbname");
$retval = DoOpsStuff("deldb $dbname");
if ($retval) {
fatal("$OPSDBPROXY failed on $CONTROL!");
}
......
......@@ -764,6 +764,9 @@ function SHOWEXP($pid, $eid, $short = 0, $sortby = "") {
$lockdown = $exprow["lockdown"];
$exptidx = $exprow["idx"];
$archive_idx = $exprow["archive_idx"];
$dpdb = $exprow["dpdb"];
$dpdbname = $exprow["dpdbname"];
$dpdbpassword= $exprow["dpdbpassword"];
$autoswap_hrs= ($autoswap_timeout/60.0);
$idleswap_hrs= ($idleswap_timeout/60.0);
......@@ -1068,6 +1071,17 @@ function SHOWEXP($pid, $eid, $short = 0, $sortby = "") {
<td class=\"left\">$syncserver</td>
</tr>\n";
}
if ($dpdb && $dpdbname && $dpdbpassword) {
echo "<tr>
<td>DataBase Name: </td>
<td class=\"left\">$dpdbname</td>
</tr>\n";
echo "<tr>
<td>DataBase Password: </td>
<td class=\"left\">$dpdbpassword</td>
</tr>\n";
}
echo "<tr>
<td>Index: </td>
<td class=\"left\">$exptidx";
......
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