On Wed, 2012-08-01 at 18:58 +0100, R.I.Pienaar wrote:
From: "Eric Shamow" <eric@puppetlabs.com>
Not sure that this should be considered a bug in fqdn_rand - the idea
with fqdn_rand is that it should generate the same random number
each time it is run in order to maintain idempotency.
The bug is that it does:

* set salt to cause consistant random numbers
* get random data

I think it should do:

* set salt to cause consistant random numbers
* get random data
* reset salt to produce random data
This will retain the behaviour of fqdn_rand and not break random for everyone else
I was going to say that an even *better* solution would be to do this:

* Create a private Random object for use only by fqdn_rand
* Set the seed on the private Random object, without disturbing
the Kernel.rand implementation
* get random data from the private Random object

...but then I remembered that the Random class was introduced in Ruby
1.9, so this won't work on older versions like 1.8.7, and I had
forgotten that fqdn_rand should always return the same number on the
same machine when it is called with the same arguments.

The definition of 'srand' is actually kind of interesting:
srand(number=0) => old_seed
so the patch to fix this is actually quite trivial:

diff --git a/lib/puppet/parser/functions/fqdn_rand.rb b/lib/puppet/parser/functi
index 93ab98b..987815c 100644
--- a/lib/puppet/parser/functions/fqdn_rand.rb
+++ b/lib/puppet/parser/functions/fqdn_rand.rb
@@ -7,6 +7,7 @@ Puppet::Parser::Functions::newfunction(:fqdn_rand, :type => :rva
$random_number_seed = fqdn_rand(30,30)") do |args|
require 'digest/md5'
max = args.shift
- srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),args].join(':')).hex)
+ old_seed = srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),args].join(':')).hex)
+ srand(old_seed)

Calvin Walton <calvin.walton@kepstin.ca>

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

Search Discussions

Discussion Posts


Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 5 of 7 | next ›
Discussion Overview
grouppuppet-users @
postedAug 1, '12 at 4:15p
activeAug 2, '12 at 9:59a



site design / logo © 2022 Grokbase