Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(MODULES-1738) Don't modify the global seed in fqdn_rotate() #406

Merged

Conversation

elyscape
Copy link
Contributor

MODULES-1738 is similar to Redmine-15791, which was addressed in puppetlabs/puppet@292233c. The current implementation of fqdn_rotate() 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.

An alternative (and, IMO, superior) way to handle this would be to instead replace lines 34-37 of fqdn_rotate.rb with:

Puppet::Parser::Functions.function('fqdn_rand')
function_fqdn_rand([elements, arguments]).to_i.times {
   result.push result.shift
}

This would have the benefits of being much cleaner and not having duplicated code from the Puppet codebase that would have to be maintained if for some reason it changed there. On the other hand, it would not prevent fqdn_rotate() from poisoning the global seed in versions of Puppet prior to 3.2.0. That being said, since fqdn_rand() already poisons the global seed in versions of Puppet prior to 3.2.0, maybe it doesn't matter if fqdn_rotate() does the same in those versions.

@elyscape elyscape force-pushed the fix/fqdn_rotate_pollutes_global_seed branch from ffb46ee to 0c71e88 Compare February 2, 2015 18:41
@elyscape elyscape changed the title Don't modify the global seed in fqdn_rotate() (MODULES-1738) Don't modify the global seed in fqdn_rotate() Feb 3, 2015
@elyscape elyscape force-pushed the fix/fqdn_rotate_pollutes_global_seed branch 3 times, most recently from 9e79d98 to 2e7efda Compare February 3, 2015 03:06
scope.function_fqdn_rotate(["asdf"])
end

it "should not leave the global seed in a deterministic state" do
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the event that we change fqdn_rotate() so that it uses fqdn_rand() to generate numbers in order to avoid duplicating Puppet::Util.deterministic_rand, we'll need to modify this test to only execute on Puppet >=3.2.0. One way to do that would be to extract the if Puppet::Util.respond_to?(:deterministic_rand) from the preceding test and have it wrap both the preceding test and this one.

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.
@elyscape elyscape force-pushed the fix/fqdn_rotate_pollutes_global_seed branch from 2e7efda to 84f866f Compare February 12, 2015 22:05
@elyscape
Copy link
Contributor Author

Rebased onto master, so tests should pass soon.

@cmurphy
Copy link
Contributor

cmurphy commented Feb 12, 2015

I think this implementation is fine, and it makes it easy to remove the reimplemented code when it's appropriate. Thanks!

cmurphy added a commit that referenced this pull request Feb 12, 2015
…_seed

(MODULES-1738) Don't modify the global seed in fqdn_rotate()
@cmurphy cmurphy merged commit ad57272 into puppetlabs:master Feb 12, 2015
@elyscape elyscape deleted the fix/fqdn_rotate_pollutes_global_seed branch February 12, 2015 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants