Commit f2dd68ef authored by Mike Hibler's avatar Mike Hibler

When returning from "admin mode", reload the node startupcmd from virt_nodes.

Entering admin mode clears nodes.startupcmd so we need to restore it
afterward. This applies when either returning from taking an image or
doing "node_admin off".
parent 194c0b94
......@@ -1965,7 +1965,8 @@ sub ClearBootAttributes($)
my $node_id = (ref($self) ? $self->node_id() : $self);
my $allocFreeState = TBDB_ALLOCSTATE_FREE_DIRTY();
DBQueryWarn("update nodes set startupcmd='',rpms='',deltas='', ".
DBQueryWarn("update nodes set ".
"startupcmd='',startstatus='none',rpms='',deltas='', ".
"tarballs='',failureaction='fatal', routertype='none', ".
"def_boot_cmd_line='',next_boot_cmd_line='', ".
"temp_boot_osid=NULL,next_boot_osid=NULL, ".
......@@ -2341,6 +2342,60 @@ sub ResetStartStatus($)
return $self->Update({"startstatus" => 'none'});
}
#
# Return the node startupcmd and status fields.
#
sub GetStartupCmd($)
{
my ($self) = @_;
my $oldcmd = $self->startupcmd();
my $oldstatus = $self->startstatus();
return ($oldcmd, $oldstatus);
}
#
# Set the node startupcmd field to the given value or the value
# in the virt_nodes table entry if no value is given.
#
sub SetStartupCmd($$$)
{
my ($self, $cmd, $status) = @_;
$status = 'none' if (!defined($status));
my $node_id = $self->node_id();
if (!$cmd) {
# Get value from virt_nodes
my $result =
DBQueryWarn("select v.startupcmd ".
" from virt_nodes as v, reserved as r ".
" where v.exptidx=r.exptidx and v.vname=r.vname ".
" and r.node_id='$node_id'");
if ($result && $result->numrows > 0) {
($cmd) = $result->fetchrow_array();
}
}
if ($cmd) {
$self->Update({'startupcmd' => $cmd, 'startstatus' => $status});
}
}
#
# Clear the node startupcmd and status fields.
# Returns the old command and status.
#
sub ClearStartupCmd($)
{
my ($self) = @_;
my $oldcmd = $self->startupcmd();
my $oldstatus = $self->startstatus();
$self->Update({'startupcmd' => '', 'startstatus' => 'none'});
return ($oldcmd, $oldstatus);
}
#
# Create new vnodes. The argument is a reference; to a a hash of options to
# be used when creating the new node(s). A list of the node names is
......
......@@ -706,7 +706,7 @@ sub DoCapture($$$$) {
$EUID = $UID = 0;
my $cmd = "$TB/bin/sshtb -n -o ConnectTimeout=10 ".
"-host $node_id touch /var/run/updatemasterpasswdfiles";
print STDERR "About to: '$cmd'\n" if ($debug);
print STDERR "About to: '$cmd'\n" if ($self->debug());
system($cmd);
if ($?) {
$msg = "'$cmd' failed";
......@@ -734,7 +734,7 @@ sub DoCapture($$$$) {
#
my $cmd = "$TB/bin/sshtb -n -o ConnectTimeout=10 ".
"-host $node_id $REBOOT_PREPARE";
print STDERR "About to: '$cmd'\n" if ($debug);
print STDERR "About to: '$cmd'\n" if ($self->debug());
system($cmd);
if ($?) {
$msg = "'$cmd' failed";
......@@ -936,6 +936,15 @@ sub DoCapture($$$$) {
goto out2;
}
#
# Restore the startupcmd.
# Note that we need to do this after the MfsSelect call above.
# XXX we just restore the "default" startup command from virt_nodes
#
$node->SetStartupCmd();
print STDERR "Restored startup cmd from virt_nodes for $node_id\n"
if ($self->debug());
%args = ();
$args{'name'} = $me;
$args{'on'} = 0;
......
......@@ -1672,6 +1672,15 @@ sub cleanup ()
return 0;
}
#
# Restore the startupcmd.
# Note that we need to do this after the MfsSelect call above.
# XXX we just restore the "default" startup command from virt_nodes
#
$node->SetStartupCmd();
print STDERR "Restored startup cmd from virt_nodes for $node_id\n"
if ($debug);
%args = ();
$args{'name'} = $me;
$args{'on'} = 0;
......
#!/usr/bin/perl -wT
#
# Copyright (c) 2000-2009 University of Utah and the Flux Group.
# Copyright (c) 2000-2018 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
......@@ -212,6 +212,14 @@ if ($runcmd ne "") {
" Could not turn admin mode off for @bad!\n");
}
#
# Restore the startupcmd from the virt_nodes table since MfsRunCmd()
# cleared it. We need to do this after the MfsSelect call above.
#
foreach my $node (@nodes) {
$node->SetStartupCmd();
}
if ($reboot) {
%args = ();
$args{'name'} = $0;
......@@ -233,6 +241,16 @@ if (TBAdminMfsSelect(\%args, \@bad, @nodeids)) {
die("*** $0:\n".
" Could not turn admin mode $onoff for @bad!\n");
}
#
# If turning off admin mode, reset the startupcmd.
#
if ($onoff eq "off") {
foreach my $node (@nodes) {
$node->SetStartupCmd();
}
}
if ($reboot) {
%args = ();
$args{'name'} = $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