Commit 9a5350e9 authored by Mike Hibler's avatar Mike Hibler

Bug Fix: Fix the "valid transition" logic and add some missing transitions.

Previously a number of invalid transitions were allowed due to the way the
check was coded. Note that this change has no functional impact as detected
invalid transitions were allowed anyway. Essentially this just changes what
gets logged.
parent 99a65f9a
......@@ -464,7 +464,7 @@ sub getValid() {
"FROM state_transitions");
my %valid;
while (my ($mode,$state1, $state2) = $result->fetchrow()) {
while (my ($mode, $state1, $state2) = $result->fetchrow()) {
$valid{$mode}{$state1}{$state2} = 1;
}
return %valid;
......@@ -477,15 +477,28 @@ sub getValid() {
sub IsValidTransition($$$)
{
my ($mode, $oldstate, $newstate) = @_;
my $isvalid = 1;
$isvalid = 0
if ($valid{$mode} &&
($valid{$mode}{$oldstate} || $valid{$mode}{"*"}) &&
! ($valid{$mode}{$oldstate}{$newstate} ||
$valid{$mode}{"*"}{$newstate}));
# If there are no transitions for mode, then all transitions are invalid.
if (!exists($valid{$mode})) {
return 0;
}
# See if there is a specific transition for mode/oldstate -> newstate
if (exists($valid{$mode}{$oldstate}) &&
exists($valid{$mode}{$oldstate}{$newstate}) &&
$valid{$mode}{$oldstate}{$newstate} == 1) {
return 1;
}
return $isvalid;
# See if there is a wildcard transition for mode/* -> newstate
if (exists($valid{$mode}{"*"}) &&
exists($valid{$mode}{"*"}{$newstate}) &&
$valid{$mode}{"*"}{$newstate} == 1) {
return 1;
}
# Otherwise, transition is invalid.
return 0;
}
#
......@@ -674,6 +687,7 @@ sub stateTransition($$) {
notify("Moving $node to $newstate because it's in $mode\n");
}
}
#
# Nodes that are in the SECVIOLATION state are not allowed to leave!
#
......
......@@ -678,6 +678,13 @@ REPLACE INTO state_transitions VALUES ('WIMRELOAD','SHUTDOWN','PXEBOOTING','Wron
REPLACE INTO state_transitions VALUES ('WIMRELOAD','RELOADSETUP','SHUTDOWN','Error');
REPLACE INTO state_transitions VALUES ('WIMRELOAD','RELOADING','SHUTDOWN','Error');
REPLACE INTO state_transitions VALUES ('PXEKERNEL','PXEBOOTING','REBOOTING','ForcedReboot');
REPLACE INTO state_transitions VALUES ('PXEFBSD','BOOTING','MFSSETUP','BootOK');
REPLACE INTO state_transitions VALUES ('PXEFBSD','BOOTING','SHUTDOWN','Error');
REPLACE INTO state_transitions VALUES ('PXEFBSD','MFSSETUP','ISUP','BootDone');
REPLACE INTO state_transitions VALUES ('PXEFBSD','MFSSETUP','SHUTDOWN','Error');
REPLACE INTO state_transitions VALUES ('PXEFBSD','ISUP','SHUTDOWN','Reboot');
REPLACE INTO state_transitions VALUES ('PXEFBSD','SHUTDOWN','PXEBOOTING','DHCP');
REPLACE INTO state_transitions VALUES ('SECURELOAD','TPMSIGNOFF','GPXEBOOTING','ReloadDone');
--
-- Dumping data for table `state_triggers`
......
#
# Missing state transitions previously silently allowed by stated.
#
use strict;
use libdb;
sub DoUpdate($$$)
{
my ($dbhandle, $dbname, $version) = @_;
my @mode_transitions = (
);
my @timeouts = (
);
my @transitions = (
["PXEFBSD","BOOTING","MFSSETUP","BootOK"],
["PXEFBSD","BOOTING","SHUTDOWN","Error"],
["PXEFBSD","MFSSETUP","ISUP","BootDone"],
["PXEFBSD","MFSSETUP","SHUTDOWN","Error"],
["PXEFBSD","ISUP","SHUTDOWN","Reboot"],
["PXEFBSD","SHUTDOWN","PXEBOOTING","DHCP"],
["SECURELOAD","TPMSIGNOFF","GPXEBOOTING","ReloadDone"],
);
my @triggers = (
);
foreach my $row (@mode_transitions) {
my ($opm1,$s1,$opm2,$s2,$lab) = @$row;
my $query_result =
DBQueryFatal("SELECT op_mode1 FROM mode_transitions WHERE ".
"op_mode1='$opm1' AND state1='$s1' AND ".
"op_mode2='$opm2' AND state2='$s2'");
if ($query_result->numrows == 0) {
DBQueryFatal("INSERT INTO mode_transitions VALUES ".
"('$opm1','$s1','$opm2', '$s2','$lab')");
}
}
foreach my $row (@timeouts) {
my ($opm,$s,$to,$act) = @$row;
my $query_result =
DBQueryFatal("SELECT op_mode FROM state_timeouts WHERE ".
"op_mode='$opm' AND state='$s'");
if ($query_result->numrows == 0) {
DBQueryFatal("INSERT INTO state_timeouts VALUES ".
"('$opm','$s','$to', '$act')");
}
}
foreach my $row (@transitions) {
my ($opm,$s1,$s2,$lab) = @$row;
my $query_result =
DBQueryFatal("SELECT op_mode FROM state_transitions WHERE ".
"op_mode='$opm' AND state1='$s1' AND state2='$s2'");
if ($query_result->numrows == 0) {
DBQueryFatal("INSERT INTO state_transitions VALUES ".
"('$opm','$s1','$s2','$lab')");
}
}
foreach my $row (@triggers) {
my ($node,$opm,$s,$trig) = @$row;
my $query_result =
DBQueryFatal("SELECT node_id FROM state_triggers WHERE ".
"node_id='$node' AND op_mode='$opm' AND state='$s'");
if ($query_result->numrows == 0) {
DBQueryFatal("INSERT INTO state_triggers VALUES ".
"('$node','$opm','$s','$trig')");
}
}
# XXX these are currently using NORMALv2 but should be using PXEFBSD
DBQueryFatal("UPDATE os_info SET op_mode='PXEFBSD' WHERE ".
" osname='ADMIN-LINUX' or osname='NEWNODE-LINUX'");
return 0;
}
1;
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