Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Bug #12122 fix #37

Closed
wants to merge 9 commits into from

4 participants

@carlasouza

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.

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
@hunner Owner
hunner added a note

Is this not a change in behaviour?

>> foo = {:foo => 'foo'}
>> bar = {:foo => 'bar'}
>> foo = bar.merge foo
 => {:foo=>"foo"}
>> foo = {:foo => 'foo'}
>> bar = {:foo => 'bar'}
>> foo.merge! bar
 => {:foo=>"bar"}

Yes, you're right. The first value found shouldn't be overridden.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/hiera/backend.rb
((6 lines not shown))
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.empty?

This fails if answer is nil:

err: undefined method `empty?' for nil:NilClass

empty? is also not defined for TrueClass or FalseClass it seems.

You're right, thanks for pointing that out. I pushed a fix for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@lfrancke

Thanks for this fix but unfortunately it still fails (can't find any variables right now). I think it should be

answer = new_answer unless new_answer.nil?

Exactly. That was a silly mistake. Fixed at this commit

@kelseyhightower

@carlasouza Looks like we should try and rebase this on master, then it will be ready for review. Let me know if you need help rebasing this.

@kelseyhightower

@carlasouza This should now be fixed: e6d57c0411d8d3c97053752375c94dba40c2d2ab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 8, 2012
  1. @carlasouza

    Bug #12122 fix: the lookup method cannot return nil and the answer wh…

    carlasouza authored
    …en calling hiera_array and hiera_hash should return all results from all backends
Commits on Mar 9, 2012
  1. @carlasouza
Commits on Mar 10, 2012
  1. @carlasouza

    It cannot return nil in case there isn't an available answer. Instead…

    carlasouza authored
    …, an empty data structure ("", [] or {}) will be returned.
  2. @carlasouza
  3. @carlasouza

    Small refactoring

    carlasouza authored
Commits on Mar 11, 2012
  1. @carlasouza
Commits on Mar 23, 2012
  1. @carlasouza
Commits on Mar 26, 2012
  1. @carlasouza
  2. @carlasouza
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 5 deletions.
  1. +12 −5 lib/hiera/backend.rb
View
17 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 unless new_answer.nil?
+ break if answer != empty_answer(:priority)
+ when :array
+ answer << new_answer
+ when :hash
+ answer = new_answer.merge 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
Something went wrong with that request. Please try again.