From 57c54a011b5cad9e471f060dee9461cdd64a8d82 Mon Sep 17 00:00:00 2001 From: Michael Chapman Date: Tue, 11 Feb 2014 16:29:44 +1100 Subject: [PATCH 1/2] Regex matching for node names This patch adds naive support for regexes in hostnames in the same format as the traditional puppet node terminus. --- lib/puppet/bodepd/scenario_helper.rb | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/puppet/bodepd/scenario_helper.rb b/lib/puppet/bodepd/scenario_helper.rb index 2ea41d7..a82e4d6 100644 --- a/lib/puppet/bodepd/scenario_helper.rb +++ b/lib/puppet/bodepd/scenario_helper.rb @@ -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 From d20bbb9b73aaf80542533fe95aebece64f7134b9 Mon Sep 17 00:00:00 2001 From: Michael Chapman Date: Tue, 11 Feb 2014 17:28:51 +1100 Subject: [PATCH 2/2] Fix syntax error in spec input yaml --- spec/unit/puppet/bodepd/scenario_helper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/unit/puppet/bodepd/scenario_helper_spec.rb b/spec/unit/puppet/bodepd/scenario_helper_spec.rb index ab370b6..e2186f5 100644 --- a/spec/unit/puppet/bodepd/scenario_helper_spec.rb +++ b/spec/unit/puppet/bodepd/scenario_helper_spec.rb @@ -76,7 +76,7 @@ def setup_hiera_data overridable_key: default_value array: - one -hash +hash: one: two EOT )