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

Replace the usage of const_defined? in the WinRM detection helper #406

Merged
merged 1 commit into from
Mar 13, 2019

Conversation

hartmantis
Copy link
Contributor

Ruby 2.6.1 came with some changes to const_defined? that now have it evaluating as true from this helper method, matching the behavior of const_get, even though the constant is inaccessible by name. This results in an exception bubbling up from the winrm? method:

✗ bundle exec kitchen verify default-amazonlinux-2-chef-14
-----> Starting Kitchen (v1.24.0)
-----> Verifying <default-amazonlinux-2-chef-14>...
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #verify action: [uninitialized constant Train::Transports::WinRM] on default-amazonlinux-2-chef-14

A quick way around it is to make this backend comparison match the one here.

Signed-off-by: Jonathan Hartman [email protected]

Ruby 2.6.1 came with some [changes](ruby/ruby#2061) to `const_defined?` that now have it evaluating as true from this helper method, matching the behavior of `const_get`, even though the constant is inaccessible by name. This results in an exception bubbling up from the `winrm?` method:

```
✗ bundle exec kitchen verify default-amazonlinux-2-chef-14
-----> Starting Kitchen (v1.24.0)
-----> Verifying <default-amazonlinux-2-chef-14>...
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #verify action: [uninitialized constant Train::Transports::WinRM] on default-amazonlinux-2-chef-14
```

A quick way around it is to make this backend comparison match the one [here](https://github.com/inspec/train/blob/v1.7.2/lib/train/platforms/detect/specifications/os.rb#L24).

Signed-off-by: Jonathan Hartman <[email protected]>
@hartmantis
Copy link
Contributor Author

For the record, I'm a little unclear on what's going on in Inspec/Train's requires/includes to result in this. If it looks more like a Ruby bug to y'all, please disregard. I started here after discovering that const_get had already been behaving this way.

@michaelklishin
Copy link

michaelklishin commented Mar 4, 2019

kitchen verify currently fails on Ruby 2.6 for me, a stack trace from Kitchen log is below.

Kitchen reports this as Failed to complete #verify action: [uninitialized constant Train::Transports::WinRM] and without looking at the logs it's not obvious that Train's OS detector fails due to how it addresses a potentially undefined constant.

cat .kitchen/logs/kitchen.log
I, [2019-03-04T17:06:25.979692 #70524]  INFO -- Kitchen: -----> Starting Kitchen (v1.24.0)
I, [2019-03-04T17:06:29.465911 #70524]  INFO -- Kitchen: -----> Verifying <default-deb-ubuntu-1604>...
E, [2019-03-04T17:06:29.526373 #70524] ERROR -- Kitchen: ------Exception-------
E, [2019-03-04T17:06:29.526456 #70524] ERROR -- Kitchen: Class: Kitchen::ActionFailed
E, [2019-03-04T17:06:29.526499 #70524] ERROR -- Kitchen: Message: 1 actions failed.
>>>>>>     Failed to complete #verify action: [uninitialized constant Train::Transports::WinRM] on default-deb-ubuntu-1604
E, [2019-03-04T17:06:29.526536 #70524] ERROR -- Kitchen: ----------------------
E, [2019-03-04T17:06:29.526593 #70524] ERROR -- Kitchen: ------Backtrace-------
E, [2019-03-04T17:06:29.526636 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/test-kitchen-1.24.0/lib/kitchen/command.rb:183:in `report_errors'
E, [2019-03-04T17:06:29.526677 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/test-kitchen-1.24.0/lib/kitchen/command.rb:174:in `run_action'
E, [2019-03-04T17:06:29.526715 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/test-kitchen-1.24.0/lib/kitchen/command/action.rb:36:in `block in call'
E, [2019-03-04T17:06:29.526753 #70524] ERROR -- Kitchen: /Users/antares/.rvm/rubies/ruby-2.6.1/lib/ruby/2.6.0/benchmark.rb:293:in `measure'
E, [2019-03-04T17:06:29.526792 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/test-kitchen-1.24.0/lib/kitchen/command/action.rb:34:in `call'
E, [2019-03-04T17:06:29.526830 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/test-kitchen-1.24.0/lib/kitchen/cli.rb:52:in `perform'
E, [2019-03-04T17:06:29.526868 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/test-kitchen-1.24.0/lib/kitchen/cli.rb:193:in `block (2 levels) in <class:CLI>'
E, [2019-03-04T17:06:29.526905 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
E, [2019-03-04T17:06:29.526946 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
E, [2019-03-04T17:06:29.526981 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
E, [2019-03-04T17:06:29.527017 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
E, [2019-03-04T17:06:29.527058 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/test-kitchen-1.24.0/bin/kitchen:13:in `block in <top (required)>'
E, [2019-03-04T17:06:29.527089 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/test-kitchen-1.24.0/lib/kitchen/errors.rb:171:in `with_friendly_errors'
E, [2019-03-04T17:06:29.527115 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/test-kitchen-1.24.0/bin/kitchen:13:in `<top (required)>'
E, [2019-03-04T17:06:29.527139 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/bin/kitchen:23:in `load'
E, [2019-03-04T17:06:29.527162 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/bin/kitchen:23:in `<main>'
E, [2019-03-04T17:06:29.527193 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `eval'
E, [2019-03-04T17:06:29.527230 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/bin/ruby_executable_hooks:24:in `<main>'
E, [2019-03-04T17:06:29.527268 #70524] ERROR -- Kitchen: ----End Backtrace-----
E, [2019-03-04T17:06:29.527304 #70524] ERROR -- Kitchen: -Composite Exception--
E, [2019-03-04T17:06:29.527339 #70524] ERROR -- Kitchen: Class: Kitchen::ActionFailed
E, [2019-03-04T17:06:29.527377 #70524] ERROR -- Kitchen: Message: Failed to complete #verify action: [uninitialized constant Train::Transports::WinRM] on default-deb-ubuntu-1604
E, [2019-03-04T17:06:29.527412 #70524] ERROR -- Kitchen: ----------------------
E, [2019-03-04T17:06:29.527447 #70524] ERROR -- Kitchen: ------Backtrace-------
E, [2019-03-04T17:06:29.527482 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/train-1.7.4/lib/train/platforms/detect/helpers/os_common.rb:18:in `winrm?'
E, [2019-03-04T17:06:29.528161 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/train-1.7.4/lib/train/platforms/detect/specifications/os.rb:22:in `block in load'
E, [2019-03-04T17:06:29.528206 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/train-1.7.4/lib/train/platforms/detect/scanner.rb:46:in `instance_eval'
E, [2019-03-04T17:06:29.528233 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/train-1.7.4/lib/train/platforms/detect/scanner.rb:46:in `block in scan_children'
E, [2019-03-04T17:06:29.528256 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/train-1.7.4/lib/train/platforms/detect/scanner.rb:45:in `each'
E, [2019-03-04T17:06:29.528278 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/train-1.7.4/lib/train/platforms/detect/scanner.rb:45:in `scan_children'
E, [2019-03-04T17:06:29.528300 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/train-1.7.4/lib/train/platforms/detect/scanner.rb:33:in `block in scan'
E, [2019-03-04T17:06:29.528322 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/train-1.7.4/lib/train/platforms/detect/scanner.rb:27:in `each'
E, [2019-03-04T17:06:29.528343 #70524] ERROR -- Kitchen: /Users/antares/.rvm/gems/ruby-2.6.1/gems/train-1.7.4/lib/train/platforms/detect/scanner.rb:27:in `scan'

I applied @RoboticCheese's PR manually to the installed gem and the issue goes away.

michaelklishin added a commit to rabbitmq/chef-cookbook that referenced this pull request Mar 4, 2019
Commited while investigating what ended up being
a Train bug specific to Ruby 2.6 [1].

No harm in keeping it around.

1. inspec/train#406
michaelklishin added a commit to rabbitmq/chef-cookbook that referenced this pull request Mar 4, 2019
@webframp
Copy link

webframp commented Mar 7, 2019

Hit this same exact issue the other day. Would be great to see this merged if possible

@michaelklishin
Copy link

@clintoncwolfe really sorry to bother you directly but Test Kitchen is unusable on Ruby 2.6 due to the above issue. Any chance this PR or some alternative solution can get some attention soon? Thank you 🙏

Copy link
Contributor

@miah miah left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@clintoncwolfe clintoncwolfe left a comment

Choose a reason for hiding this comment

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

Thanks - I'm not sure how that was working in the first place. Also, kudos for excellent tests!

@clintoncwolfe clintoncwolfe merged commit c1648ba into inspec:master Mar 13, 2019
@hartmantis hartmantis deleted the jdh/const-defined branch March 13, 2019 17:20
marcparadise pushed a commit to marcparadise/train that referenced this pull request Mar 18, 2019
…spec#406)

Ruby 2.6.1 came with some [changes](ruby/ruby#2061) to `const_defined?` that now have it evaluating as true from this helper method, matching the behavior of `const_get`, even though the constant is inaccessible by name. This results in an exception bubbling up from the `winrm?` method:

```
✗ bundle exec kitchen verify default-amazonlinux-2-chef-14
-----> Starting Kitchen (v1.24.0)
-----> Verifying <default-amazonlinux-2-chef-14>...
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #verify action: [uninitialized constant Train::Transports::WinRM] on default-amazonlinux-2-chef-14
```

A quick way around it is to make this backend comparison match the one [here](https://github.com/inspec/train/blob/v1.7.2/lib/train/platforms/detect/specifications/os.rb#L24).

Signed-off-by: Jonathan Hartman <[email protected]>
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.

5 participants