From: Peter Palfrader Date: Mon, 17 Jun 2013 11:24:59 +0000 (+0200) Subject: Use a more stable hash function X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=5a0d8476e567fd2c8a80a11327fc8713b868f3b8;p=mirror%2Fdsa-puppet.git Use a more stable hash function --- diff --git a/modules/puppetmaster/lib/puppet/parser/functions/entropy_provider.rb b/modules/puppetmaster/lib/puppet/parser/functions/entropy_provider.rb index 19b3366f7..85b8bf1db 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/entropy_provider.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/entropy_provider.rb @@ -2,6 +2,7 @@ module Puppet::Parser::Functions newfunction(:entropy_provider, :type => :rvalue) do |args| begin require '/var/lib/puppet/lib/puppet/parser/functions/whohosts.rb' + require 'digest/sha1' fqdn = args[0] nodeinfo = args[1] @@ -44,15 +45,18 @@ module Puppet::Parser::Functions entropy_provider_hoster = nil end + hash = Digest::SHA1.digest(fqdn) + hashval = hash[0].ord + hash[1].ord*256 + if provider.include?(fqdn) # if the host has an ekeyd ans = 'local' elsif entropy_provider_hoster # if there are more than one ekeys at this hoster pick an arbitrary # one, but the same every time - index = fqdn.hash % hoster[entropy_provider_hoster].length + index = hashval % hoster[entropy_provider_hoster].length ans = hoster[entropy_provider_hoster][index] else # pick an arbitrary provider from all providers - index = fqdn.hash % provider.size + index = hashval % provider.size ans = provider[index] end