diff options
author | Eli Young <elyscape@gmail.com> | 2015-01-28 15:28:54 -0800 |
---|---|---|
committer | Eli Young <elyscape@gmail.com> | 2015-02-12 14:04:47 -0800 |
commit | 84f866ffafbb27a6aa6a1eea92c393a63829e242 (patch) | |
tree | 7e0792a13888ccd15bee9d2da13bebfd79071dd3 /lib | |
parent | afc83ea564520378ac507251ddfea46f8d571829 (diff) | |
download | puppet-stdlib-84f866ffafbb27a6aa6a1eea92c393a63829e242.tar.gz puppet-stdlib-84f866ffafbb27a6aa6a1eea92c393a63829e242.tar.bz2 |
(MODULES-1738) Don't modify global seed in fqdn_rotate()
As per puppetlabs/puppet@292233c, this leaves the global seed in a
deterministic state, which is bad. Puppet::Util.deterministic_rand()
exists to avoid running into this issue, but is only present starting in
Puppet 3.2.0.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/puppet/parser/functions/fqdn_rotate.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/puppet/parser/functions/fqdn_rotate.rb b/lib/puppet/parser/functions/fqdn_rotate.rb index 7f4d37d..cf22d36 100644 --- a/lib/puppet/parser/functions/fqdn_rotate.rb +++ b/lib/puppet/parser/functions/fqdn_rotate.rb @@ -31,8 +31,20 @@ Rotates an array a random number of times based on a nodes fqdn. elements = result.size - srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),arguments].join(':')).hex) - rand(elements).times { + seed = Digest::MD5.hexdigest([lookupvar('::fqdn'),arguments].join(':')).hex + # deterministic_rand() was added in Puppet 3.2.0; reimplement if necessary + if Puppet::Util.respond_to?(:deterministic_rand) + offset = Puppet::Util.deterministic_rand(seed, elements).to_i + else + if defined?(Random) == 'constant' && Random.class == Class + offset = Random.new(seed).rand(elements) + else + srand(seed) + offset = rand(elements) + srand() + end + end + offset.times { result.push result.shift } |