[PATCH conductor] BZ 843079 - set deployment's state to stopped when all instances are stopped
Tomas Hrcka
thrcka at redhat.com
Wed Aug 8 15:03:14 UTC 2012
On Tue, 2012-07-31 at 15:10 +0200, jprovazn at redhat.com wrote:
> From: Jan Provaznik <jprovazn at redhat.com>
>
> ---
> src/app/models/deployment.rb | 8 +++++-
> src/spec/models/deployment_spec.rb | 55 ++++++++++++++++++++++++++++++------
> 2 files changed, 53 insertions(+), 10 deletions(-)
>
> diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
> index 277f9b3..fa8605f 100644
> --- a/src/app/models/deployment.rb
> +++ b/src/app/models/deployment.rb
> @@ -660,13 +660,19 @@ class Deployment < ActiveRecord::Base
>
> def state_transition_from_running(instance)
> if instance.state != STATE_RUNNING
> - self.state = STATE_INCOMPLETE
> + if instances.all? {|i| i.state == Instance::STATE_STOPPED}
> + self.state = STATE_STOPPED
> + else
> + self.state = STATE_INCOMPLETE
> + end
> end
> end
>
> def state_transition_from_incomplete(instance)
> if instances.all? {|i| i.state == Instance::STATE_RUNNING}
> self.state = STATE_RUNNING
> + elsif instances.all? {|i| i.state == Instance::STATE_STOPPED}
> + self.state = STATE_STOPPED
> end
> end
>
> diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb
> index 9b2a37e..8627169 100644
> --- a/src/spec/models/deployment_spec.rb
> +++ b/src/spec/models/deployment_spec.rb
> @@ -376,17 +376,45 @@ describe Deployment do
> before :each do
> @deployment.state = Deployment::STATE_RUNNING
> @deployment.save!
> - @inst1 = Factory.create(:instance, :deployment => @deployment, :state => Instance::STATE_RUNNING)
> - @inst2 = Factory.create(:instance, :deployment => @deployment, :state => Instance::STATE_RUNNING)
> - @deployment.instances << @inst1
> - @deployment.instances << @inst2
> end
>
> - it "should be incomplete if only some instances are running" do
> - @inst1.state = Instance::STATE_ERROR
> - @inst1.save!
> - @deployment.reload
> - @deployment.state.should == Deployment::STATE_INCOMPLETE
> + describe "multi-instance deployment" do
> + before :each do
> + @inst1 = Factory.create(:instance, :deployment => @deployment, :state => Instance::STATE_RUNNING)
> + @inst2 = Factory.create(:instance, :deployment => @deployment, :state => Instance::STATE_RUNNING)
> + @deployment.instances << @inst1
> + @deployment.instances << @inst2
> + end
> +
> + it "should be incomplete if only some instances are running" do
> + @inst1.state = Instance::STATE_ERROR
> + @inst1.save!
> + @deployment.reload
> + @deployment.state.should == Deployment::STATE_INCOMPLETE
> + end
> +
> + it "should be stopped if all instances are stopped" do
> + @inst1.state = Instance::STATE_STOPPED
> + @inst1.save!
> + @inst2.state = Instance::STATE_STOPPED
> + @inst2.save!
> + @deployment.reload
> + @deployment.state.should == Deployment::STATE_STOPPED
> + end
> + end
> +
> + describe "single-instance deployment" do
> + before :each do
> + @inst1 = Factory.create(:instance, :deployment => @deployment, :state => Instance::STATE_RUNNING)
> + @deployment.instances << @inst1
> + end
> +
> + it "should be stopped if all instances are stopped" do
> + @inst1.state = Instance::STATE_STOPPED
> + @inst1.save!
> + @deployment.reload
> + @deployment.state.should == Deployment::STATE_STOPPED
> + end
> end
> end
>
> @@ -544,6 +572,15 @@ describe Deployment do
> @deployment.reload
> @deployment.state.should == Deployment::STATE_RUNNING
> end
> +
> + it "should be stopped if all instances are stopped" do
> + @inst1.state = Instance::STATE_STOPPED
> + @inst1.save!
> + @inst2.state = Instance::STATE_STOPPED
> + @inst2.save!
> + @deployment.reload
> + @deployment.state.should == Deployment::STATE_STOPPED
> + end
> end
>
> end
ACK works for me
More information about the aeolus-devel
mailing list