On 08/29/2012 10:06 AM, [email protected] wrote:
From: Jan Provaznik <[email protected]>If partial launch is enabled and all instances fails, the deployment is marked as failed instead of running. Also if there is a failed instance but rest of instances are running, the deployment is marked as incomplete. --- src/app/models/deployment.rb | 4 +++- src/spec/models/deployment_spec.rb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb index 6e5e5d7..bbc3065 100644 --- a/src/app/models/deployment.rb +++ b/src/app/models/deployment.rb @@ -651,8 +651,10 @@ class Deployment < ActiveRecord::Base def state_transition_from_pending(instance) if instances.all? {|i| i.state == Instance::STATE_RUNNING} self.state = STATE_RUNNING + elsif partial_launch and instances.all? {|i| i.failed?} + self.state = STATE_FAILED elsif partial_launch and instances.all? {|i| i.failed_or_running?} - self.state = STATE_RUNNING + self.state = STATE_INCOMPLETE elsif !partial_launch and Instance::FAILED_STATES.include?(instance.state) # TODO: now this is done in instance's after_update callback - as part # of instance save transaction - this might be done on background by diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb index aa78f50..5178a83 100644 --- a/src/spec/models/deployment_spec.rb +++ b/src/spec/models/deployment_spec.rb @@ -456,6 +456,22 @@ describe Deployment do @deployment.reload @deployment.state.should == Deployment::STATE_PENDING end + + it "should set incomplete status if all instances are failed or running" do + @inst1.state = Instance::STATE_RUNNING + @inst1.save! + @inst2.state = Instance::STATE_CREATE_FAILED + @inst2.save! + @deployment.reload.state.should == Deployment::STATE_INCOMPLETE + end + + it "should set failed status if all instances failed" do + @inst1.state = Instance::STATE_CREATE_FAILED + @inst1.save! + @inst2.state = Instance::STATE_CREATE_FAILED + @inst2.save! + @deployment.reload.state.should == Deployment::STATE_FAILED + end end end
ACK. Works as expected. Jirka
