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-10537) Resolve Ruby 2.7 Warnings #8179

Merged
merged 16 commits into from
Jun 4, 2020

Conversation

melissa
Copy link
Contributor

@melissa melissa commented May 27, 2020

No description provided.

@melissa melissa requested review from a team May 27, 2020 18:12
@melissa
Copy link
Contributor Author

melissa commented May 27, 2020

This is blocked on #8175

@puppetcla
Copy link

CLA signed by all contributors.

@melissa melissa force-pushed the maint/master/ruby-2.7 branch 4 times, most recently from ef9435c to ac71e39 Compare May 27, 2020 21:52
@melissa
Copy link
Contributor Author

melissa commented May 28, 2020

I'm not going to be able to fix all the warnings.

rspec-mocks currently is raising a warning with Ruby 2.7 when we use and_call_original in our tests.
rspec/rspec-mocks#1306
rspec/rspec-mocks#1324

@melissa melissa requested a review from a team May 28, 2020 17:34
@melissa
Copy link
Contributor Author

melissa commented May 28, 2020

I was just going to leave the commit messages as they are, unless you think I should squash them down by type.

@melissa melissa closed this May 28, 2020
@melissa melissa reopened this May 28, 2020
Gemfile Outdated Show resolved Hide resolved
lib/puppet/util.rb Outdated Show resolved Hide resolved
lib/puppet/resource.rb Outdated Show resolved Hide resolved
@melissa melissa changed the title Maint/master/ruby 2.7 (PUP-10537) Resolve Ruby 2.7 Warnings May 29, 2020
@melissa
Copy link
Contributor Author

melissa commented Jun 1, 2020

I forgot I can't enable Ruby 2.7 testing with Travis yet because of the scanf failures :( That'll have to wait until https://tickets.puppetlabs.com/browse/PA-3182 is done.

lib/puppet/util.rb Outdated Show resolved Hide resolved
@melissa melissa force-pushed the maint/master/ruby-2.7 branch 2 times, most recently from 4ad229d to dbd750e Compare June 3, 2020 17:55
super(path, data.map { |k, v| [k.to_sym, v] }.to_h)
links = data.fetch('links', nil) || data.fetch(:links, nil)
relative_path = data.fetch('relative_path', nil) || data.fetch(:relative_path, nil)
source = @source || data.fetch(:source, nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't the cleanest, but it works...

Copy link
Contributor

Choose a reason for hiding this comment

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

ah 👍 It's interesting how making this explicit shows how confusing it is for callers, to pass a string for owner, but symbol or string for links).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah... I had it as strings originally, but the tests failed. So, symbols it is. I'm not confident that owner is necessarily a string, but it's working as is, so...

melissa added 16 commits June 3, 2020 11:05
`warning: deprecated Object#=~ is called on Array; it always returns
nil`

In order to fix this warning, ensure that `place` is a string prior to
checking for a match
`warning: $SAFE will become a normal global variable in Ruby 3.0`

`$SAFE` and `taint` are deprecated concepts. See:
https://rubyreferences.github.io/rubychanges/2.7.html#safe-and-taint-concepts-are-deprecated-in-general

This is largely based on changes in ruby/ruby@c5c0546

This code was originally introduced by
puppetlabs@19cf4be,
which was based on the ruby code. It makes sense to follow their logic
on how we extract `$SAFE` from our code.
`warning: Using the last argument as keyword parameters is deprecated;
maybe ** should be added to the call`

In preparation for Ruby 3, Ruby 2.7 has added warnings around how
keyword and positional arguments are used. Details can be found at:
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
`warning: Using the last argument as keyword parameters is deprecated;
maybe ** should be added to the call`

In preparation for Ruby 3, Ruby 2.7 has added warnings around how
keyword and positional arguments are used. Details can be found at:
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/

This commit is just covering the changes needed for ssl_provider_spec.rb, though it might be a better idea to merge these commits.
`warning: Using the last argument as keyword parameters is deprecated;
maybe ** should be added to the call`
`warning: deprecated Object#=~ is called on Puppet::Type::File; it
always returns nil`
Rather than polluting the run output, we should warn if a LoadError
occurs with standard warning protocol in Puppet. This allows for a
more standardized experience with how users are exposed to these
warnings. It also means that we can clean up spec output, which is nice.

The following is rspec output prior to this change. This commit removed
the multiple warnings `Could not load confine test 'osfamily':
LoadError` from popping up in the output.
```
➜  bundle exec rspec --format d --force-color spec/unit/confine_spec.rb:77
Run options:
  include {:locations=>{"./spec/unit/confine_spec.rb"=>[77]}}
  exclude {:broken=>true, :benchmark=>true}

Puppet::Confine
  when requiring
Could not load confine test 'osfamily': LoadError
Could not load confine test 'osfamily': LoadError
    does not cache failed requires when always_retry_plugins is true
Could not load confine test 'osfamily': LoadError
    caches failed requires when always_retry_plugins is false
```
`warning: deprecated Object#=~ is called on Puppet::Type::File; it
always returns nil`
`warning: Using the last argument as keyword parameters is deprecated;
maybe ** should be added to the call`
`warning: deprecated Object#=~ is called on Float; it always returns
nil`
Both Fixnum and Bignum were unified into Integer in Ruby 2.4. This
commit removes the references to them so we do not emit the deprecation
warnings when running tests.

https://bugs.ruby-lang.org/issues/12005
It appears that in Ruby 2.7 the error message that is raised for
SyntaxErrors is slightly different. This commit updates the regex to
catch the error in 2.7 while maintaining backwards compatability with
earlier ruby versions.

```
  1) loaders when a 3x load takes place a function with syntax error has helpful error message
     Failure/Error:
       expect {
         loader.load_typed(typed_name(:function, 'func_with_syntax_error'))
       }.to raise_error(/syntax error, unexpected (keyword_|`)?end/)

       expected /syntax error, unexpected (keyword_)?end/, got #<SyntaxError: /Users/melissa/workdir/puppet/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_fu...ib/puppet/parser/functions/func_with_syntax_error.rb:8: syntax error, unexpected `end'
         end
         ^~~
       > with backtrace:
         # ./lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb:42:in `eval'
         # ./lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb:42:in `create'
         # ./lib/puppet/pops/loader/module_loaders.rb:284:in `instantiate'
         # ./lib/puppet/pops/loader/module_loaders.rb:258:in `find'
         # ./lib/puppet/pops/loader/base_loader.rb:163:in `internal_load'
         # ./lib/puppet/pops/loader/base_loader.rb:42:in `load_typed'
         # ./lib/puppet/pops/loader/dependency_loader.rb:50:in `block in find'
         # ./lib/puppet/pops/loader/dependency_loader.rb:48:in `each'
         # ./lib/puppet/pops/loader/dependency_loader.rb:48:in `reduce'
         # ./lib/puppet/pops/loader/dependency_loader.rb:48:in `find'
         # ./lib/puppet/pops/loader/base_loader.rb:163:in `internal_load'
         # ./lib/puppet/pops/loader/base_loader.rb:42:in `load_typed'
         # ./spec/unit/pops/loaders/loaders_spec.rb:464:in `block (4 levels) in <top (required)>'
         # ./spec/unit/pops/loaders/loaders_spec.rb:463:in `block (3 levels) in <top (required)>'
         # ./spec/spec_helper.rb:180:in `block (2 levels) in <top (required)>'
     # ./spec/unit/pops/loaders/loaders_spec.rb:463:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:180:in `block (2 levels) in <top (required)>'

Finished in 3 minutes 20.5 seconds (files took 1.38 seconds to load)
1 example, 1 failure
```
@melissa melissa force-pushed the maint/master/ruby-2.7 branch 2 times, most recently from 1af644e to ab59036 Compare June 3, 2020 20:46
@melissa
Copy link
Contributor Author

melissa commented Jun 3, 2020

Trying to enable Ruby 2.7 testing on windows just produced errors


ruby : -e:1:in `<main>': uninitialized constant OpenSSL::OPENSSL_LIBRARY_VERSION (NameError)
At line:8 char:1
+ ruby -ropenssl -e 'puts \"OpenSSL Version - #{OpenSSL::OPENSSL_VERSIO ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (-e:1:in `<main>...ION (NameError):String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
OpenSSL Version - OpenSSL 1.0.0o 15 Oct 2014

@melissa
Copy link
Contributor Author

melissa commented Jun 4, 2020

Also, the way we run out tests, with bundle exec rake parallell:spec, completely obfuscates any deprecation warnings that are surfaced during the run. If you look at the test output, you'll see a distinct lack of warnings, when there are many due to an updated requited in rspec-mocks. This might be worthwhile to fix. I would think we would want to see deprecation warnings when running spec tests.

@joshcooper joshcooper merged commit ec1fe7e into puppetlabs:master Jun 4, 2020
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.

None yet

4 participants