Issue #22617 has been reported by Don Law. ---------------------------------------- Feature #22617: augeas onlyif comparitor for strings that are integers should do numeric compare https://projects.puppetlabs.com/issues/22617
* Author: Don Law * Status: Unreviewed * Priority: Normal * Assignee: * Category: augeas * Target version: * Affected Puppet version: 2.6.18 * Keywords: numeric comparitor onlyif * Branch: ---------------------------------------- The onlyif get comparitor always does string comparison. This is fine until you try < or > (less than/greater than). Many configuration parameters are numeric and should be compared as such when they are. For an example use case, imagine a resource that enforces that the maximum password expiration must be less than 90 days. If someone configures their system to use less than 90, no problem, but if it is configured for more than 90, we need to set it to 90: augeas {'testcase' : incl => '/home/dlaw/augeas/login.defs', lens => 'Login_defs.lns', context => '/files/home/dlaw/augeas/login.defs', onlyif => 'get PASS_MAX_DAYS > 90', changes => 'set PASS_MAX_DAYS 90', } The problem is if the following line appears in login.defs: PASS_MAX_DAYS 120 the string comparision will show that 120 < 90, and the onlyif will not be true. The following patch is a proposed fix for the problem: --- OLD/site_ruby/1.8/puppet/provider/augeas/augeas.rb 2013-09-19 14:09:52.000000000 -0400 +++ NEW/site_ruby/1.8/puppet/provider/augeas/augeas.rb 2013-09-19 16:23:48.000000000 -0400 @@ -164,6 +164,10 @@ end end + def is_numeric?(s) + s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true + end + # Used by the need_to_run? method to process get filters. Returns # true if there is a match, false if otherwise # Assumes a syntax of get /files/path [COMPARATOR] value @@ -179,10 +183,14 @@ #check the value in augeas result = @aug.get(path) || '' - case comparator - when "!=" + + if comparator == "<" and is_numeric?(result) and is_numeric?(arg) + return_value = result.to_s.to_f < arg.to_s.to_f + elsif comparator == ">" and is_numeric?(result) and is_numeric?(arg) + return_value = result.to_s.to_f > arg.to_s.to_f + elsif comparator == "!=" return_value = (result != arg) - when "=~" + elsif comparator == "=~" regex = Regexp.new(arg) return_value = (result =~ regex) else -- You have received this notification because you have either subscribed to it, or are involved in it. To change your notification preferences, please click here: http://projects.puppetlabs.com/my/account -- You received this message because you are subscribed to the Google Groups "Puppet Bugs" group. To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com. To post to this group, send email to puppet-bugs@googlegroups.com. Visit this group at http://groups.google.com/group/puppet-bugs. For more options, visit https://groups.google.com/groups/opt_out.