Please review pull request #37: Bug #12122 fix opened by (carlasouza)

Description:

The lookup method cannot return nil in case there isn't an available answer. Instead, an empty data structure ("", [] or {}) will be returned. Also, calling hiera_array and hiera_hash should return all results from all backends.

  • Opened: Sat Mar 10 16:48:13 UTC 2012
  • Based on: puppetlabs:master (4b2ae058e9a60532886158af1ef8d7ce08118653)
  • Requested merge: carlasouza:master (3df2a56b3146dc92f250dd9e1c5cc8d9c16a304d)

Diff follows:

diff --git a/lib/hiera/backend.rb b/lib/hiera/backend.rb
index e0c7c85..80d6691 100644
--- a/lib/hiera/backend.rb
+++ b/lib/hiera/backend.rb
@@ -152,21 +152,28 @@ def resolve_answer(answer, resolution_type)
       # backend will not create new instances
       def lookup(key, default, scope, order_override, resolution_type)
         @backends ||= {}
-        answer = nil
+        answer = empty_answer(resolution_type)
 
         Config[:backends].each do |backend|
           if constants.include?("#{backend.capitalize}_backend") || constants.include?("#{backend.capitalize}_backend".to_sym)
             @backends[backend] ||= Backend.const_get("#{backend.capitalize}_backend").new
-            answer = @backends[backend].lookup(key, scope, order_override, resolution_type)
-
-            break if answer
+            new_answer = @backends[backend].lookup(key, scope, order_override, resolution_type)
+            case resolution_type
+              when :priority
+                answer = new_answer
+                break if answer
+              when :array
+                answer << new_answer
+              when :hash
+                answer.merge! new_answer
+            end
           end
         end
 
         answer = resolve_answer(answer, resolution_type)
         answer = parse_string(default, scope) if answer.nil?
 
-        return default if answer == empty_answer(resolution_type)
+        return default if answer == empty_answer(resolution_type) unless default.nil?
         return answer
       end
     end
diff --git a/lib/hiera/backend/yaml_backend.rb b/lib/hiera/backend/yaml_backend.rb
index 147a76c..7a65e1b 100644
--- a/lib/hiera/backend/yaml_backend.rb
+++ b/lib/hiera/backend/yaml_backend.rb
@@ -35,7 +35,7 @@ def lookup(key, scope, order_override, resolution_type)
             answer << new_answer
           when :hash
             raise Exception, "Hiera type mismatch: expected Hash and got #{new_answer.class}" unless new_answer.kind_of? Hash
-            answer = new_answer.merge answer
+            answer.merge! new_answer
           else
             answer = new_answer
             break

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to [email protected].
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to