incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] Fixed auth exception reporting and improved exception reporting itself. (JIRA: #DTACLOUD-29)
Date Wed, 30 Mar 2011 12:46:13 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 server/lib/deltacloud/base_driver/base_driver.rb   |   31 ++++++++++++++------
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    4 +-
 .../lib/deltacloud/drivers/gogrid/gogrid_driver.rb |    9 ------
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |    4 +-
 .../drivers/rackspace/rackspace_driver.rb          |   12 ++++----
 server/server.rb                                   |    3 +-
 6 files changed, 34 insertions(+), 29 deletions(-)

diff --git a/server/lib/deltacloud/base_driver/base_driver.rb b/server/lib/deltacloud/base_driver/base_driver.rb
index 77257ee..c1922c4 100644
--- a/server/lib/deltacloud/base_driver/base_driver.rb
+++ b/server/lib/deltacloud/base_driver/base_driver.rb
@@ -238,18 +238,31 @@ module Deltacloud
     def safely(&block)
       begin
         block.call
-      rescue *catched_exceptions_list[:error] => e
-        raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace)
-      rescue *catched_exceptions_list[:auth] => e
-        raise Deltacloud::AuthException.new
       rescue => e
+        puts "# MESSAGE: #{e.message}"
+        puts "# CLASS: #{e.class}"
+        catched_exceptions_list[:auth].each do |ex|
+          if e.class == ex or e.class.name =~ ex or e.message =~ ex
+            puts "# AUTH: #{e.message}"
+            raise Deltacloud::AuthException.new
+          end
+        end
+        catched_exceptions_list[:error].each do |ex|
+          if e.class == ex or e.class.name =~ ex or e.message =~ ex
+            puts "# ERROR: #{e.message}"
+            raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace)
if e.class.name =~ ex
+          end
+        end
         catched_exceptions_list[:glob].each do |ex|
-          raise Deltacloud::BackendError.new(502, e.class.to_s, e.message, e.backtrace) if
e.class.name =~ ex
+          if e.class == ex or e.class.name =~ ex or e.message =~ ex
+            puts "# GLOBAL: #{e.message}"
+            raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)

+          end
         end
-        puts "======= UNHANDLED EXCEPTION ============"
-        puts e.inspect
-        puts "========================================"
-        raise e
+        $stderr.puts "# UNCAUGHT EXCEPTION # -> '#{e.class}' - '#{e.message}'"
+        $stderr.puts "# #{e.backtrace.join("\n")}"
+        $stderr.puts "##############"
+        raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
       end
     end
 
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index fea340e..302aac2 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -715,8 +715,8 @@ module Deltacloud
 
         def catched_exceptions_list
           {
-            :auth => [], # [ ::Aws::AuthFailure ],
-            :error => [ ::Aws::AwsError ],
+            :auth => [ /AuthFailure/ ],
+            :error => [ /Aws::AwsError/, /Error/ ],
             :glob => [ /AWS::(\w+)/, /Deltacloud::Runner::(\w+)/ ]
           }
         end
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index b769609..b1802a3 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -471,15 +471,6 @@ class GogridDriver < Deltacloud::BaseDriver
     end
     return ip
   end
-
-  def safely(&block)
-    begin
-      block.call
-    rescue Exception => e
-      raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
-    end
-  end
-
 end
 
     end
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 7d229c4..a4f9e11 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -508,8 +508,8 @@ class MockDriver < Deltacloud::BaseDriver
   def catched_exceptions_list
     {
       :auth => [],
-      :error => [ ::Deltacloud::BackendError, Errno::ENOENT ],
-      :glob => []
+      :error => [ /Deltacloud::BackendError/, /Errno::ENOENT/ ],
+      :glob => [ /Error/ ]
     }
   end
 
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index 4363580..b5f0c27 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -390,12 +390,12 @@ private
     end
   end
 
-  def safely(&block)
-    begin
-      block.call
-    rescue Exception => e
-      raise Deltacloud::BackendError.new(500, e.class.to_s, e.message, e.backtrace)
-    end
+  def catched_exceptions_list
+    {
+      :auth => [ /Authentication failed/ ],
+      :error => [ /Error/ ],
+      :glob => [ /CloudServers::Exception::(\w+)/, /Deltacloud::Runner::(\w+)/ ]
+    }
   end
 
   private
diff --git a/server/server.rb b/server/server.rb
index 3c4273c..d537d3a 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -66,8 +66,9 @@ end
 error Deltacloud::BackendCapability::Failure do
   report_error(405, "backend_capability_failure")
 end
+
 error Deltacloud::AuthException do
-  report_error(403, "auth_exception")
+  report_error(401, "auth_exception")
 end
 
 error Deltacloud::BackendError do
-- 
1.7.4.1


Mime
View raw message