[PATCH conductor] BZ 801527: wrong error message when imagefactory is down

mzatko at redhat.com mzatko at redhat.com
Thu Mar 15 15:51:17 UTC 2012


From: Maros Zatko <mzatko at redhat.com>

https://bugzilla.redhat.com/show_bug.cgi?id=801527

API:
* new API exception ServiceUnavailable
* rescue for ECONNREFUSED when imagefactory is down
---
 src/app/controllers/api/images_controller.rb |   14 +++++++++-----
 src/lib/exceptions.rb                        |    1 +
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/src/app/controllers/api/images_controller.rb b/src/app/controllers/api/images_controller.rb
index 465a20b..2bcbeee 100644
--- a/src/app/controllers/api/images_controller.rb
+++ b/src/app/controllers/api/images_controller.rb
@@ -89,11 +89,15 @@ module Api
             :template => @tpl.uuid,
             :environment => @pool_family.name
           })
-          @image = Aeolus::Image::Factory::Image.new(:id => iwhd_image.id)
-          @image.targets = req[:params][:targets]
-          @image.template = req[:params][:template]
-          @image.save!
-          respond_with(@image)
+          begin
+            @image = Aeolus::Image::Factory::Image.new(:id => iwhd_image.id)
+            @image.targets = req[:params][:targets]
+            @image.template = req[:params][:template]
+            @image.save!
+            respond_with(@image)
+          rescue Errno::ECONNREFUSED
+            raise(Aeolus::Conductor::API::ServiceUnavailable.new(503, 'Imagefactory is dead, Jim!'))
+          end
         elsif req[:type] == :import
           account = ProviderAccount.find_by_label(req[:params][:provider_account_name])
           raise(Aeolus::Conductor::API::ProviderAccountNotFound.new(404, t("api.error_messages.provider_account_not_found",
diff --git a/src/lib/exceptions.rb b/src/lib/exceptions.rb
index d56ddb3..9b1edab 100644
--- a/src/lib/exceptions.rb
+++ b/src/lib/exceptions.rb
@@ -38,6 +38,7 @@ module Aeolus
       class ProviderImageDeleteFailure < Error; end
       class ProviderImageNotFound < Error; end
       class ProviderImageStatusNotFound < Error; end
+      class ServiceUnavailable < Error; end
       class TargetImageDeleteFailure < Error; end
       class TargetImageNotFound < Error; end
       class TargetImageStatusNotFound < Error; end
-- 
1.7.7.6




More information about the aeolus-devel mailing list