In Ruby 1.9 you have to require 'digest/md5' instead of just 'md5'.  The
following irb sessions from each version of Ruby should explain the changes in
how MD5 is used between Ruby versions and why this patch was made.

ruby-1.9.2-p136 :001 > require 'md5'
LoadError: no such file to load -- md5
ruby-1.9.2-p136 :002 > require 'digest/md5'
 => true
ruby-1.9.2-p136 :003 > Digest::MD5.hexdigest('mystring')
 => "169319501261c644a58610f967e8f9d0"
ruby-1.9.2-p136 :004 > Digest::MD5.new('mystring')
 => #<Digest::MD5: d41d8cd98f00b204e9800998ecf8427e>

ruby-1.8.7-p330 :001 > require 'digest/md5'
 => []
ruby-1.8.7-p330 :002 > require 'md5'
 => ["MD5"]
ruby-1.8.7-p330 :003 > Digest::MD5.hexdigest('mystring')
 => "169319501261c644a58610f967e8f9d0"
ruby-1.8.7-p330 :004 > MD5.new('mystring')
 => #<MD5: 169319501261c644a58610f967e8f9d0>
ruby-1.8.7-p330 :005 > MD5.new('mystring').to_s
 => "169319501261c644a58610f967e8f9d0"
ruby-1.8.7-p330 :006 > Digest::MD5.new('mystring')
ArgumentError: wrong number of arguments (1 for 0)

Reviewed-by: Jesse Wolfe <je...@puppetlabs.com>
Signed-off-by: Matt Robinson <m...@puppetlabs.com>
---
Local-branch: ticket/next/6830-ready_to_merge
 lib/puppet/parser/functions/fqdn_rand.rb |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/puppet/parser/functions/fqdn_rand.rb 
b/lib/puppet/parser/functions/fqdn_rand.rb
index 52946f2..91157a1 100644
--- a/lib/puppet/parser/functions/fqdn_rand.rb
+++ b/lib/puppet/parser/functions/fqdn_rand.rb
@@ -5,8 +5,8 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => 
:rvalue, :doc =>
 
       $random_number = fqdn_rand(30)
       $random_number_seed = fqdn_rand(30,30)") do |args|
-    require 'md5'
+    require 'digest/md5'
     max = args.shift
-    srand MD5.new([lookupvar('fqdn'),args].join(':')).to_s.hex
+    srand(Digest::MD5.hexdigest([lookupvar('fqdn'),args].join(':')).hex)
     rand(max).to_s
 end
-- 
1.7.3.1

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

Reply via email to