[PATCH conductor 6/6] Fixed deployment rollback

jprovazn at redhat.com jprovazn at redhat.com
Tue Jun 5 12:59:03 UTC 2012


From: Jan Provaznik <jprovazn at redhat.com>

When rollback was initiated, 'stop' request was sent to instances
in 'pending' state too. But it seems that 'stop' is not valid action
for 'pending' state. Now we wait until pending instances are running
and send 'stop' request then.
---
 src/app/models/deployment.rb       |   14 +++++++++-----
 src/app/models/instance.rb         |    1 +
 src/spec/models/deployment_spec.rb |    2 ++
 3 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index 921b6a6..1fdd666 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -673,6 +673,8 @@ class Deployment < ActiveRecord::Base
     if Instance::ACTIVE_FAILED_STATES.include?(instance.state)
       # if this instance stop failed, whole deployment rollback failed
       self.state = STATE_ROLLBACK_FAILED
+    elsif instance.state == Instance::STATE_RUNNING
+      deployment_rollback
     elsif instances.all? {|i| i.inactive?}
       # some other instances might be failed (because their
       # launch failed), but it shouldn't be a problem if all
@@ -682,17 +684,19 @@ class Deployment < ActiveRecord::Base
   end
 
   def deployment_rollback
-    stoppable_instances = instances.stoppable
-    if stoppable_instances.empty?
+    unless self.state == STATE_ROLLBACK_IN_PROGRESS
+      self.state = STATE_ROLLBACK_IN_PROGRESS
+      save!
+    end
+
+    if instances.all? {|i| i.inactive?}
       self.state = STATE_ROLLBACK_COMPLETE
       save!
       return
     end
 
-    self.state = STATE_ROLLBACK_IN_PROGRESS
-    save!
     error_occured = false
-    stoppable_instances.each do |instance|
+    instances.running.each do |instance|
       begin
         instance.stop(nil)
       rescue
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index ba2221e..0bddeb0 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -129,6 +129,7 @@ class Instance < ActiveRecord::Base
   scope :deployed,  :conditions => { :state => [STATE_RUNNING, STATE_SHUTTING_DOWN] }
   # FIXME: "pending" is misleading as it doesn't just cover STATE_PENDING
   scope :pending,   :conditions => { :state => [STATE_NEW, STATE_PENDING] }
+  scope :running,   :conditions => { :state => [STATE_RUNNING] }
   scope :pending_or_deployed,   :conditions => { :state => [STATE_NEW, STATE_PENDING, STATE_RUNNING, STATE_SHUTTING_DOWN] }
   # FIXME: "failed" is misleading too...
   scope :failed,    :conditions => { :state => FAILED_STATES }
diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb
index 0c8dca6..09a9899 100644
--- a/src/spec/models/deployment_spec.rb
+++ b/src/spec/models/deployment_spec.rb
@@ -424,6 +424,8 @@ describe Deployment do
         end
 
         it "should stop all running instances if an instance fails" do
+          @inst1.state = Instance::STATE_RUNNING
+          @inst1.save!
           Instance.any_instance.stub(:stop).and_return(true)
           Instance.any_instance.should_receive(:stop)
           @inst2.state = Instance::STATE_ERROR
-- 
1.7.7.6




More information about the aeolus-devel mailing list