[PATCH conductor] BZ 791195 - Clean up destroy_on_provider code
Matt Wagner
matt.wagner at redhat.com
Fri Feb 17 22:07:38 UTC 2012
This cleans up some crazy code that obsessively retries to destroy
instances on the provider after they are removed in Conductor.
This particular patch is not tested.
Relates to https://bugzilla.redhat.com/show_bug.cgi?id=791195
---
src/app/models/instance.rb | 23 ++++++++---------------
src/app/util/taskomatic.rb | 28 ++++++----------------------
2 files changed, 14 insertions(+), 37 deletions(-)
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index a7a82b5..03da558 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -457,21 +457,10 @@ class Instance < ActiveRecord::Base
]
def destroy_on_provider
- if provider_account and !['ec2', 'mock'].include?(provider_account.provider.provider_type.deltacloud_driver) and
- ![STATE_CREATE_FAILED, STATE_VANISHED].include?(state)
- retries = 0
- begin
- retries += 1
- @task = self.queue_action(self.owner, 'destroy')
- unless @task
- raise I18n.t"instance.errors.cannot_destroy"
- end
- Taskomatic.destroy_instance(@task)
- rescue Exception => e
- if self.tasks.last.action != 'destroy' and retries < 500
- retry
- end
- end
+ if provider_account and destroy_supported?(provider_account) and ![STATE_CREATE_FAILED, STATE_VANISHED].include?(state)
+ @task = self.queue_action(self.owner, 'destroy')
+ raise I18n.t("instance.errors.cannot_destroy") unless @task
+ Taskomatic.destroy_instance(@task)
end
end
@@ -485,6 +474,10 @@ class Instance < ActiveRecord::Base
end
end
+ def destroy_supported?(account)
+ !['ec2', 'mock'].include?(account.provider.provider_type.deltacloud_driver)
+ end
+
def key_name
"#{self.name}_#{Time.now.to_i}_key_#{self.object_id}".gsub(/[^a-zA-Z0-9\.\-]/, '_')
end
diff --git a/src/app/util/taskomatic.rb b/src/app/util/taskomatic.rb
index 8bdbc66..5ddb782 100644
--- a/src/app/util/taskomatic.rb
+++ b/src/app/util/taskomatic.rb
@@ -63,8 +63,11 @@ module Taskomatic
Rails.logger.info("Task instance '#{action}' complete, now in state #{dcloud_instance.state}.")
- task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
- task.instance.save!
+ # Don't update the instance if we're in the process of destroying it:
+ unless action == :destroy!
+ task.instance.state = dcloud_to_instance_state(dcloud_instance.state)
+ task.instance.save!
+ end
task.state = Task::STATE_FINISHED
rescue Exception => ex
task.state = Task::STATE_FAILED
@@ -87,26 +90,7 @@ module Taskomatic
end
def self.destroy_instance(task)
- task.time_started = Time.now
-
- begin
- client = task.instance.provider_account.connect
- dcloud_instance = client.instance(task.instance.external_key)
-
- task.state = Task::STATE_PENDING
- task.save!
-
- dcloud_instance.destroy!
-
- Rails.logger.info("Task Destroy completed.")
-
- task.state = Task::STATE_FINISHED
- rescue Exception => ex
- task.state = Task::STATE_FAILED
- task.message = ex.message
- ensure
- task.save!
- end
+ do_action(task, :destroy!)
end
def self.dcloud_to_instance_state(state_str)
--
1.7.6.5
More information about the aeolus-devel
mailing list