[Tools] testbot: Validate and adjust the VM limits on startup.

Francois Gouget <[email protected]>
Newsgroups gmane.comp.emulators.wine.patches
Message-ID <E1e6dMq-0007Nh-82@amboise>
Signed-off-by: Francois Gouget <[email protected]>
---
 testbot/bin/Engine.pl           | 15 +++++++++++++++
 testbot/lib/WineTestBot/Jobs.pm |  5 ++---
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/testbot/bin/Engine.pl b/testbot/bin/Engine.pl
index fe16f178..9b497023 100755
--- a/testbot/bin/Engine.pl
+++ b/testbot/bin/Engine.pl
@@ -700,6 +700,21 @@ sub main()
   $WineTestBot::Engine::Notify::RunningInEngine = 1;
   LogMsg "Starting the WineTestBot Engine\n";
 
+  # Validate and adjust the configuration options
+  $MaxActiveVMs ||= 1;
+  $MaxRevertingVMs ||= $MaxActiveVMs;
+  if ($MaxRevertingVMs > $MaxActiveVMs)
+  {
+    $MaxRevertingVMs = $MaxActiveVMs;
+    LogMsg "Capping MaxRevertingVMs to MaxActiveVMs ($MaxRevertingVMs)\n";
+  }
+  $MaxRevertsWhileRunningVMs ||= 0;
+  if ($MaxRevertsWhileRunningVMs > $MaxRevertingVMs)
+  {
+    $MaxRevertsWhileRunningVMs = $MaxRevertingVMs;
+    LogMsg "Capping MaxRevertsWhileRunningVMs to MaxRevertingVMs ($MaxRevertsWhileRunningVMs)\n";
+  }
+  $MaxVMsWhenIdle ||= $MaxActiveVMs;
   Cleanup();
 
   # Check for patches that arrived while the server was off.
diff --git a/testbot/lib/WineTestBot/Jobs.pm b/testbot/lib/WineTestBot/Jobs.pm
index 3a3e5177..3c7ce0df 100644
--- a/testbot/lib/WineTestBot/Jobs.pm
+++ b/testbot/lib/WineTestBot/Jobs.pm
@@ -691,15 +691,14 @@ sub ScheduleOnHost($$$)
   }
 
   # Finally, if we are otherwise idle, prepare some VMs for future jobs
-  my $MaxIdleVMs = defined $MaxVMsWhenIdle ? $MaxVMsWhenIdle : $MaxActiveVMs;
-  if ($ActiveCount - $IdleCount == 0 && $ActiveCount < $MaxIdleVMs)
+  if ($ActiveCount == $IdleCount && $ActiveCount < $MaxVMsWhenIdle)
   {
     # Sort from most important to least important
     my @SortedVMs = sort { $VMPriorities{$b} <=> $VMPriorities{$a} } keys %VMPriorities;
     foreach my $VMKey (@SortedVMs)
     {
       last if ($RevertingCount == $MaxReverts);
-      last if ($ActiveCount >= $MaxIdleVMs);
+      last if ($ActiveCount >= $MaxVMsWhenIdle);
 
       my $VM = $HostVMs->GetItem($VMKey);
       next if ($VM->Status ne "off");
-- 
2.14.2
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.