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

(PUP-7130) Unify ruby Integer types, ENV['HOME'] handling and HTTP time #5653

Merged

Conversation

thallgren
Copy link
Contributor

@thallgren thallgren commented Feb 21, 2017

This PR changes three things to make the Puppet code base execute without problems using a Ruby 2.4.0 runtime.

  1. Changes all Fixnum references to Integer.
  2. Fixes an ambiguous time representation in HttpMetaData uses UTC.
  3. Conditions some tests that sets ENV['HOME'] to nil (no-op on 2.4).

@puppetcla
Copy link

CLA signed by all contributors.

@@ -2,6 +2,13 @@
require 'spec_helper'

describe Puppet::Util::RunMode do

# Discriminator for tests that attempts to unset HOME since that, for reasons currently unknown,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing a problem (with core Ruby ENV), at least on OSX / Ruby 2.4.0

irb(main):001:0> RUBY_VERSION
=> "2.4.0"
irb(main):002:0> ENV['HOME']
=> "/Users/Iristyle"
irb(main):003:0> ENV['HOME'] = nil
=> nil
irb(main):004:0> ENV['HOME']
=> nil

irb(main):009:0> ENV.keys.include?('HOME')
=> false

With our helpers:

[1] pry(main)> require 'puppet'
=> true
[2] pry(main)> Puppet::Util.get_env('HOME')
=> "/Users/Iristyle"
[3] pry(main)> Puppet::Util.set_env('HOME')
=> nil
[4] pry(main)> Puppet::Util.get_env('HOME')
=> nil
[5] pry(main)> RUBY_VERSION
=> "2.4.0"
[6] pry(main)> Puppet.version
=> "5.0.0"

Copy link
Contributor

Choose a reason for hiding this comment

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

Were there particular platforms you saw having a problem with unsetting HOME @thallgren ?

Copy link
Contributor Author

@thallgren thallgren Feb 23, 2017

Choose a reason for hiding this comment

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

The tests you do do not reveal the problem. Try:

File.expand_path('~/tmp')

and you will discover that it expands the path even when you have set the ENV['HOME'] to nil. Prior to 2.4.0, you'd get an exception and that exception is what the disabled tests rely on.

Copy link
Contributor

@Iristyle Iristyle Feb 23, 2017

Choose a reason for hiding this comment

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

I would have preferred we understand / solve this problem rather than papering over the test failures with exclusions, as some Puppet code may need to change to accommodate the new behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW - it looks like the change was made in ruby/ruby@6b88dd2

The associated Ruby ticket is https://bugs.ruby-lang.org/issues/12695

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Iristyle, Great job finding the actual issue. I tried but didn't succeed. I agree that it's a good thing to understand the problem. My intention was not to paper over it, but rather that the current tests could be made into acceptance tests instead. I suggest that in the commit comment.

Copy link
Contributor

@hlindberg hlindberg left a comment

Choose a reason for hiding this comment

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

In addition to the individual comments - the changes realted to HOME are about something else than the changes related to Integer/Fixnum. It should at least be a separate commit - but preferably a separate ticket.

@@ -203,7 +203,7 @@ def close_augeas

def is_numeric?(s)
case s
when Fixnum
when Integer,Float
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the same - augeas may not handle floats well.

Copy link
Contributor Author

@thallgren thallgren Feb 23, 2017

Choose a reason for hiding this comment

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

Take a look at the regular expression used for the String a couple of lines down. It accepts floats. Seems rather odd that the string form would, but the numeric form would not. One of them should be adjusted. I chose to make that adjustment in a way that isn't more restrictive than before.

Copy link
Contributor

Choose a reason for hiding this comment

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

While I agree that it looks like a bug in the original, this is not a change that is required to make puppet run on Ruby 2.4.0. After this change, more values are allowed than earlier (floats in float form).

Copy link
Contributor

Choose a reason for hiding this comment

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

If also attempting to fix the potential bug, I would like that as a separate commit with rationale etc.

expect(calculator.type(c).class).to eq(PIntegerType)
end
it 'should yield \'PIntegerType\' for Integer' do
expect(calculator.type(Integer).class).to eq(PIntegerType)
Copy link
Contributor

Choose a reason for hiding this comment

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

The original test needs to be retained for < Ruby 2.4 as we otherwise remove the assertion of how Fixnum/Bignum are mapped to an Integer PType. Make the test depend on Ruby version, and add new test for >= 2.4.

Copy link
Contributor Author

@thallgren thallgren Feb 23, 2017

Choose a reason for hiding this comment

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

I added the tests, but without dependency on Ruby version. The Fixnum and Bignum still exists in Ruby 2.4 so they might be encountered.

@@ -799,8 +799,8 @@ module Puppet::Util::Plist
it "should accept a hash containing a PBKDF2 password hash, salt, and iterations value and return the correct iterations value" do
expect(provider.class.get_salted_sha512_pbkdf2('iterations', pbkdf2_embedded_bplist_hash)).to eq(pbkdf2_iterations_value)
end
it "should return a Fixnum value when looking up the PBKDF2 iterations value" do
expect(provider.class.get_salted_sha512_pbkdf2('iterations', pbkdf2_embedded_bplist_hash)).to be_a_kind_of(Fixnum)
it "should return a Integer value when looking up the PBKDF2 iterations value" do
Copy link
Contributor

Choose a reason for hiding this comment

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

"return an Integer"

@thallgren
Copy link
Contributor Author

@hlindberg, regarding the change of HOME. I think the title of this ticket should change instead. To "Make it possible to run Puppet with Ruby 2.4". It makes no sense to me having separate tickets for what needs to be fixed since they wouldn't produce a functional code-base.

@hlindberg
Copy link
Contributor

It would be much better if the changes were split up into several commits. You list them as "1,2,3" already - plus add one for the possible bug-fixed auegas.

This commit changes  all Fixnum/Bignum references to Integer
Setting `ENV['HOME'] = nil` was used to provoke an exception when using
a tilde character in `expand_path`. In 2.4.0, the expansion works OK
even after assigning nil.

NOTE! The exception can be provoked in an acceptance test if HOME set
to empty before the Ruby process is started:
```
$ export HOME=
$ irb
2.4.0 :001 > File.expand_path('~/tmp')
ArgumentError: non-absolute home
```
In Ruby versions prior <2.4.0, the statement
```
x = DateTime.httpdate('Sat, 03 Feb 2001 04:05:06 GMT').to_time.to_s
```
produces a local time like "2001-02-03 05:05:06 +0100". In 2.4.0 the
timezone is retained. This commit ensures that the time used for the
http_metadata checksum is UTC and that the test expects UTC. That works,
regardless of Ruby version.
@thallgren thallgren force-pushed the issue/pup-7130/unify-ruby-integer-types branch from ed393e5 to d472bef Compare February 23, 2017 13:09
@hlindberg hlindberg merged commit 94202f8 into puppetlabs:master Feb 23, 2017
@thallgren thallgren deleted the issue/pup-7130/unify-ruby-integer-types branch May 23, 2017 16:45
Iristyle added a commit to Iristyle/puppet that referenced this pull request Jun 14, 2017
 - Now that RubyInstaller has produced an installer for Ruby 2.4.1 on
   Windows and AppVeyor has integrated it into their workflow per
   appveyor/ci#1350 we can move from 2.3 to
   2.4 given Puppet 5 will be shipping against 2.4

 - Update tests that behave differently under Ruby 2.4:

   * Ruby has changed how ~ resolves when no HOME, HOMEDRIVE or
     USERPROFILE has set. It no longer fails to resolve / causes an
     exception thanks to https://bugs.ruby-lang.org/issues/12695

     puppetlabs#5653 was the first pass
     in f4f5ccb but was incomplete.

   * Ruby has changed the implementation of sort_by! so that items
     already in order will not be returned in the same order. For
     instance, compare the behaviors between Ruby 2.3 and 2.4:

     [[1.0, 'a'], [1.0, 'b'], [1.0, 'c']].sort_by! { |i| i[0] }
       Ruby 2.3:
       [[1.0, "a"], [1.0, "b"], [1.0, "c"]]
       Ruby 2.4:
       [[1.0, "b"], [1.0, "c"], [1.0, "a"]]

     [[1.0, 'c'], [1.0, 'b'], [1.0, 'a']].sort_by! { |i| i[0] }
       Ruby 2.3:
       [[1.0, "c"], [1.0, "b"], [1.0, "a"]]
       Ruby 2.4:
       [[1.0, "b"], [1.0, "a"], [1.0, "c"]]
Iristyle added a commit to Iristyle/puppet that referenced this pull request Jun 14, 2017
 - Now that RubyInstaller has produced an installer for Ruby 2.4.1 on
   Windows and AppVeyor has integrated it into their workflow per
   appveyor/ci#1350 we can move from 2.3 to
   2.4 given Puppet 5 will be shipping against 2.4

 - Update tests that behave differently under Ruby 2.4:

   * Ruby has changed how ~ resolves when no HOME, HOMEDRIVE or
     USERPROFILE has set. It no longer fails to resolve / causes an
     exception thanks to https://bugs.ruby-lang.org/issues/12695

     puppetlabs#5653 was the first pass
     in f4f5ccb but was incomplete.

   * Ruby has changed the implementation of sort_by! so that items
     already in order will not be returned in the same order. For
     instance, compare the behaviors between Ruby 2.3 and 2.4:

     [[1.0, 'a'], [1.0, 'b'], [1.0, 'c']].sort_by! { |i| i[0] }
       Ruby 2.3:
       [[1.0, "a"], [1.0, "b"], [1.0, "c"]]
       Ruby 2.4:
       [[1.0, "b"], [1.0, "c"], [1.0, "a"]]

     [[1.0, 'c'], [1.0, 'b'], [1.0, 'a']].sort_by! { |i| i[0] }
       Ruby 2.3:
       [[1.0, "c"], [1.0, "b"], [1.0, "a"]]
       Ruby 2.4:
       [[1.0, "b"], [1.0, "a"], [1.0, "c"]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants