deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] CIMI: Fixed undefined 'default_frontend' error in CIMI tests
Date Tue, 12 Feb 2013 10:04:27 GMT
From: Michal Fojtik <mfojtik@redhat.com>

In case when db/provider model is accessed outside the Deltacloud
server context (CIMI tests, CIMI client, etc...) the
Deltacloud.default_frontend method is not set, because 'deltacloud_rack'
is not required.

This patch will add 'fallback' mode where if you use this model outside
server context, we try to get the default driver in same way as we
get the provider value.

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/db/provider.rb | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/server/lib/db/provider.rb b/server/lib/db/provider.rb
index ee3e138..59c90ec 100644
--- a/server/lib/db/provider.rb
+++ b/server/lib/db/provider.rb
@@ -15,7 +15,22 @@ module Deltacloud
       # Find the DB provider set in the environment/request
       def self.lookup
         prov = Thread.current[:provider] || ENV['API_PROVIDER'] || 'default'
-        find_or_create(:driver => self.driver_symbol.to_s, :url => prov)
+        find_or_create(:driver => current_driver_name, :url => prov)
+      end
+
+      private
+
+      # In case this model is used outside the Deltacloud server (CIMI tests, CIMI
+      # client, etc), the 'Deltacloud.default_frontend' is not initialized.
+      # In that case we have to use the 'fallback' way to retrieve current
+      # driver name.
+      #
+      def self.current_driver_name
+        if Deltacloud.respond_to?(:default_frontend)
+          self.driver_symbol.to_s
+        else
+          Thread.current[:driver] || ENV['API_DRIVER'] || 'mock'
+        end
       end
     end
 
-- 
1.8.1.2


Mime
View raw message