[PATCH conductor] Fixed checking if there is a queued start request when doing rollback

jprovazn at redhat.com jprovazn at redhat.com
Thu Sep 6 14:12:39 UTC 2012


From: Jan Provaznik <jprovazn at redhat.com>

---
 src/app/models/deployment.rb |  2 +-
 src/app/models/instance.rb   | 12 ++++++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index f9bc95b..d8fd88a 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -730,7 +730,7 @@ class Deployment < ActiveRecord::Base
       cleanup_failed_launch
     elsif instance.state == Instance::STATE_RUNNING
       deployment_rollback
-    elsif instances.all? {|i| i.inactive? or i.state == Instance::STATE_NEW}
+    elsif instances.all? {|i| i.finished?}
       # some other instances might be failed (because their
       # launch failed), but it shouldn't be a problem if all
       # running instances stopped correctly
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 42befa9..c21c734 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -349,6 +349,14 @@ class Instance < ActiveRecord::Base
     ! instance_config_xml.nil? || assembly_xml.requires_config_server?
   end
 
+  # represents states from which instance doesn't automatically transits
+  # into any other state, also checks that there is no queued 'start' action
+  # for stopped instance (rhevm, vpshere)
+  def finished?
+    return false if state == Instance::STATE_STOPPED && pending_or_successful_start?
+    inactive? || state == Instance::STATE_NEW
+  end
+
   def self.list(order_field, order_dir)
     #Instance.all(:include => [ :owner ],
     #             :order => (order_field || 'name') +' '+ (order_dir || 'asc'))
@@ -603,8 +611,8 @@ class Instance < ActiveRecord::Base
   end
 
   def pending_or_successful_start?
-    task = tasks.find_last_by_action('start')
-    return false unless task
+    task = tasks.last
+    return false if task.nil? || task.action != 'start'
     return true if task.state == Task::STATE_FINISHED
     # it's possible that start request takes more than 30 secs on rhevm,
     # but dbomatic kills child process after 30sec by default, so
-- 
1.7.11.4




More information about the aeolus-devel mailing list