deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [6/6] git commit: Core: Refactor how we load the driver source file (DTACLOUD-540)
Date Wed, 10 Apr 2013 19:38:22 GMT
Core: Refactor how we load the driver source file (DTACLOUD-540)

The current way how we load the driver using #driver helper
will exit silently (with nil) if 'NameError' is raised while
the *Driver#new.

For example, if you require MockDriver but you don't require the
mock_initialize.rb file, you get 'NameError' exception for not existing
MOCK_STORAGE constant.


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/5a19b0df
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/5a19b0df
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/5a19b0df

Branch: refs/heads/master
Commit: 5a19b0df5a34a761a1a7475e0a873ad23a36c472
Parents: a88c1f1
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Wed Apr 10 11:22:25 2013 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Wed Apr 10 21:31:36 2013 +0200

----------------------------------------------------------------------
 server/lib/deltacloud/helpers/driver_helper.rb |   11 ++++-------
 server/tests/deltacloud/drivers_test.rb        |    2 +-
 2 files changed, 5 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/5a19b0df/server/lib/deltacloud/helpers/driver_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/driver_helper.rb b/server/lib/deltacloud/helpers/driver_helper.rb
index 1c52894..3f4f89b 100644
--- a/server/lib/deltacloud/helpers/driver_helper.rb
+++ b/server/lib/deltacloud/helpers/driver_helper.rb
@@ -45,19 +45,16 @@ module Deltacloud::Helpers
     end
 
     def driver_class
-      begin
-        m = Deltacloud::Drivers.const_get(driver_class_name)
-        m.const_get(driver_class_name + "Driver").new
-      rescue NameError
-        nil
-      end
+      m = Deltacloud::Drivers.const_get(driver_class_name)
+      m.const_get(driver_class_name + "Driver").new
     end
 
     def driver
       $:.unshift File.join(File.dirname(__FILE__), '..', '..')
       begin
-        require_relative(driver_source_name) unless driver_class
         driver_class
+      rescue NameError => e
+        require_relative(driver_source_name) ? retry : raise(LoadError.new(e.message))
       rescue LoadError => e
         raise "[ERROR] The driver '#{driver_name}' is unknown or not installed (#{driver_source_name})\n"
+
           "\n#{e.message}\n"

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/5a19b0df/server/tests/deltacloud/drivers_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/deltacloud/drivers_test.rb b/server/tests/deltacloud/drivers_test.rb
index 8142fe1..fd3126d 100644
--- a/server/tests/deltacloud/drivers_test.rb
+++ b/server/tests/deltacloud/drivers_test.rb
@@ -64,7 +64,7 @@ describe Deltacloud::Helpers::Drivers do
   it 'should throw an exception on unknown driver' do
     begin
       Thread.current[:driver] = 'unknown'
-      Proc.new { @helper.driver }.must_raise RuntimeError
+      Proc.new { @helper.driver }.must_raise LoadError
     ensure
       Thread.current[:driver] = 'mock'
     end


Mime
View raw message