[PATCH conductor 2/3] BZ #795891 - Deployment should not show "running" with no instances

Matt Wagner matt.wagner at redhat.com
Tue Feb 21 21:08:22 UTC 2012


Resolves https://bugzilla.redhat.com/show_bug.cgi?id=795891
---
 src/app/models/deployment.rb       |    4 ++--
 src/app/models/instance.rb         |    5 ++++-
 src/spec/models/deployment_spec.rb |    6 ++++++
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/app/models/deployment.rb b/src/app/models/deployment.rb
index a23080c..63cc1e5 100644
--- a/src/app/models/deployment.rb
+++ b/src/app/models/deployment.rb
@@ -416,9 +416,9 @@ class Deployment < ActiveRecord::Base
   end
 
   def status
-    if instances.all? {|i| i.state == Instance::STATE_RUNNING}
+    if instances.any? and instances.all? {|i| i.state == Instance::STATE_RUNNING}
       :running
-    elsif instances.all? {|i| [Instance::STATE_STOPPED, Instance::STATE_ERROR, Instance::STATE_CREATE_FAILED].include? i.state}
+    elsif instances.empty? or instances.all? {|i| (Instance::FAILED_STATES + [Instance::STATE_STOPPED]).include?(i.state)}
       :stopped
     else
       :pending
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 0042074..a2074cb 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -114,11 +114,14 @@ class Instance < ActiveRecord::Base
              STATE_SHUTTING_DOWN, STATE_STOPPED, STATE_CREATE_FAILED,
              STATE_ERROR, STATE_VANISHED]
 
+  # States that indicate some sort of failure/problem with an instance:
+  FAILED_STATES = [STATE_CREATE_FAILED, STATE_ERROR, STATE_VANISHED]
+
   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] }
   # FIXME: "failed" is misleading too...
-  scope :failed,    :conditions => { :state => [STATE_CREATE_FAILED, STATE_ERROR, STATE_VANISHED] }
+  scope :failed,    :conditions => { :state => FAILED_STATES }
   scope :stopped,   :conditions => {:state => STATE_STOPPED}
   scope :not_stopped, :conditions => "state <> 'stopped'"
   scope :stopable,    :conditions => { :state => [STATE_NEW, STATE_PENDING, STATE_RUNNING] }
diff --git a/src/spec/models/deployment_spec.rb b/src/spec/models/deployment_spec.rb
index 740780c..0feecfc 100644
--- a/src/spec/models/deployment_spec.rb
+++ b/src/spec/models/deployment_spec.rb
@@ -307,6 +307,12 @@ describe Deployment do
       deployment.stub(:instances) { [instance, instance2] }
       deployment.status.should == :pending
     end
+
+    it "should be stopped if no instances exist" do
+      deployment = Factory.build :deployment
+      deployment.stub(:instances) {[]}
+      deployment.status.should == :stopped
+    end
   end
 
   describe ".instances.instance_parameters" do
-- 
1.7.6.5




More information about the aeolus-devel mailing list