Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/puppet/bodepd/scenario_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,28 @@ def get_role(name)
end
role_mappings = YAML.load_file(role_mapper)
split_name = name.split('.')

regexes = Hash.new
role_mappings.each do | role_match, role|
# Strip the regex of any wrapping slashes that might exist
role_match = role_match.sub(/^\//, '').sub(/\/$/, '')
begin
regexes[(Regexp.new(role_match))] = role
rescue => detail
raise ArgumentError, "Invalid regex in role_mappings '#{role_match}': #{detail}", detail.backtrace
end
end

split_name.size.times do |x|
cur_name = split_name[0..(split_name.size-x-1)].join('.')
role = role_mappings[cur_name]
if role
Puppet.debug("Found role from role mappings: #{role}")
return role
regexes.each do | regex, role|
if ( cur_name =~ regex)
Puppet.debug("Found role from role mappings: #{role}")
return role
end
end
end

Puppet.debug("Did not find role mapping for #{name}")
return nil
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/puppet/bodepd/scenario_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def setup_hiera_data
overridable_key: default_value
array:
- one
hash
hash:
one: two
EOT
)
Expand Down