[PATCH conductor 3/3] BZ #795794 - Don't delete :vanished instances

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


If an instance goes into state 'vanished', we should leave it there,
not delete it. The deletion was meant as an interim solution until
we could handle things more gracefully, but it ended up causing more
problems than it avoided.

Related to https://bugzilla.redhat.com/show_bug.cgi?id=795794
---
 src/app/models/instance_observer.rb |    5 +++++
 src/dbomatic/dbomatic               |   13 +------------
 src/spec/models/instance_spec.rb    |    6 ++++++
 3 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/app/models/instance_observer.rb b/src/app/models/instance_observer.rb
index c6b898d..244a8a4 100644
--- a/src/app/models/instance_observer.rb
+++ b/src/app/models/instance_observer.rb
@@ -119,6 +119,11 @@ class InstanceObserver < ActiveRecord::Observer
                              :change_hash => instance.changes)
         end
         event4.save! if event4
+      elsif instance.state == Instance::STATE_VANISHED
+        Event.create!(
+          :source => instance, :event_time => Time.now,
+          :status_code => 'vanished', :summary => "Instance disappeared from cloud provider"
+        )
       end
 
     end
diff --git a/src/dbomatic/dbomatic b/src/dbomatic/dbomatic
index 1c6c6ee..1113b5a 100755
--- a/src/dbomatic/dbomatic
+++ b/src/dbomatic/dbomatic
@@ -211,18 +211,7 @@ def check_one_account(account)
       else
         # We have an instance in our database, but it didn't come back over the API
         DBomaticLogger.instance.info("known instance missing from provider: #{instance.name} #{instance.external_key}")
-        if instance.state == Instance::STATE_VANISHED
-          # If the instance is found, we automatically update the state, so this means that the
-          # instance was missing on two *consecutive* calls.
-          DBomaticLogger.instance.info("instance was missing on last call as well, so deleting")
-          Event.create(
-            :source => instance, :event_time => Time.now,
-            :status_code => 'vanished', :summary => "Instance disappeared from cloud provider"
-          )
-          instance.destroy
-        else
-          DBomaticLogger.instance.info("instance was present on last call, so setting state to vanished but not deleting")
-          instance.update_attribute(:state, Instance::STATE_VANISHED)
+        instance.update_attribute(:state, Instance::STATE_VANISHED)
         end
       end
     end
diff --git a/src/spec/models/instance_spec.rb b/src/spec/models/instance_spec.rb
index 8af85b1..56b3663 100644
--- a/src/spec/models/instance_spec.rb
+++ b/src/spec/models/instance_spec.rb
@@ -101,6 +101,12 @@ describe Instance do
     @instance.events.last.status_code.should == 'stop_queued'
   end
 
+  it "should create event when an instance vanishes" do
+    @instance.save!
+    @instance.update_attribute(:state, Instance::STATE_VANISHED)
+    @instance.events.last.status_code.should == "vanished"
+  end
+
   describe "with time capsule" do
 
     it "should properly calculate the total time that the instance has been in a monitored state" do
-- 
1.7.6.5




More information about the aeolus-devel mailing list