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

pass options hash sans target key #1646

Merged

Conversation

jeremymv2
Copy link
Contributor

@jeremymv2 jeremymv2 commented Apr 11, 2017

This PR fixes #1631

validate_backend': Cannot determine backend from target configuration "meta-profile.tar.gz". Valid example: ssh://192.168.0.1. (Train::UserError)

Originally, the :target key was deleted from the options hash in the initialize method of Inspec::Profile, before being passed to Inspec::Backend.create() Recently, in the commit below, the :target delete method was removed so that the key still existed in the hash: d0bc085#diff-d1eede4085683a605d9b8892a198f642L85

This change introduced an unintended behavior: when train goes off to validate in the validate_backend method, it's raising an error since :target is not nil: https://github.com/chef/train/blob/master/lib/train.rb#L121-L124

This PR simply reverts the original behavior by passing the options hash to Inspec::Backend.create() without the :target key in it. With this, the functionality works as before and preserves the desired effect from the commit above.

Signed-off-by: Jeremy J. Miller jm@chef.io

Signed-off-by: Jeremy J. Miller <jm@chef.io>
@@ -89,7 +89,7 @@ def initialize(source_reader, options = {})
@writable = options[:writable] || false
@profile_id = options[:id]
@cache = options[:cache] || Cache.new
@backend = options[:backend] || Inspec::Backend.create(options)
@backend = options[:backend] || Inspec::Backend.create(options.select { |k, _| k != 'target' })
Copy link
Contributor

Choose a reason for hiding this comment

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

The fact that we hit (read: I created) this bug in the first place is because we blindly pass a hash of options that is created by the caller rather than curating a hash of options we actually need. Rather than deleting an option we don't need, I'd rather we only pass the options we do need. Otherwise, people like me will see calls to #delete without knowing why, there won't be a comment as to why, and then bugs are created. 🙂

It's possible that we need to be actually creating the hash we need in Inspec::Backend rather than here.

@chris-rock / @arlimus - thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me this area of the code is a bit opaque (regarding passing of a :target) without knowing what the message spec from Profile -> Backend should look like under different circumstances. I agree that we should determine what the message(s) should contain and be able to enforce that on the receiving end.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to make the separation more clear. The problem with the options we do need is that the backend is getting most of the cli options, since all the ssh or winrm options are just passed through. I think we should create an issue to solve that in another case. The real issue I am seeing here is that we need to run integration tests with Chef Automate for every PR, since a change should break the build.

So we need to do two things:

  • Integration testing with Chef Compliance / Chef Automate
  • Make the interface between inspec / train more clear

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed that additional testing is always a good thing. I don't agree that that's the "real issue." We have a situation in the codebase where A is creating an options hash, B is passing it to C, but not all the options are needed by C and, when they are all included, we break. So even if "all the ssh and winrm options are just passed through," we're not doing a good job with the separation. Testing will catch it, but the lack of testing is not the cause here.

Copy link
Contributor

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

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

I confirmed that issue. LGTM. Thank you for spotting that issue @jeremymv2

@@ -89,7 +89,7 @@ def initialize(source_reader, options = {})
@writable = options[:writable] || false
@profile_id = options[:id]
@cache = options[:cache] || Cache.new
@backend = options[:backend] || Inspec::Backend.create(options)
@backend = options[:backend] || Inspec::Backend.create(options.select { |k, _| k != 'target' })
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to make the separation more clear. The problem with the options we do need is that the backend is getting most of the cli options, since all the ssh or winrm options are just passed through. I think we should create an issue to solve that in another case. The real issue I am seeing here is that we need to run integration tests with Chef Automate for every PR, since a change should break the build.

So we need to do two things:

  • Integration testing with Chef Compliance / Chef Automate
  • Make the interface between inspec / train more clear

Copy link
Contributor

@adamleff adamleff left a comment

Choose a reason for hiding this comment

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

Approved with #1652 and #1653 to address the root issues.

@adamleff adamleff merged commit 2376cba into inspec:master Apr 12, 2017
@jeremymv2 jeremymv2 deleted the jeremymv2/fix_validate_backend_error branch April 12, 2017 21:56
jerryaldrichiii added a commit that referenced this pull request Oct 24, 2017
When passing options to `Train` we need to ensure we do not pass the
`'target'` key. See: #1646

NOTE: When running `inspec exec` that key is `:target` so it is not
removed, but since `options[:backend]` already exists this is not an
issue.
jerryaldrichiii added a commit that referenced this pull request Oct 24, 2017
When passing options to `Train` we need to ensure we do not pass the
`'target'` key. See: #1646

NOTE: When running `inspec exec` that key is `:target` so it is not
removed, but since `options[:backend]` already exists this is not an
issue.

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
jerryaldrichiii added a commit that referenced this pull request Oct 24, 2017
When passing options to `Train` we need to ensure we do not pass the
`'target'` key. See: #1646

NOTE: When running `inspec exec` the key is `:target` so it is not
removed, but since `options[:backend]` already exists this is not an
issue.

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
jerryaldrichiii added a commit that referenced this pull request Oct 24, 2017
When passing options to `Train` we need to ensure we do not pass the
`'target'` key. See: #1646

NOTE: When running `inspec exec` the key is `:target` so it is not
removed, but since `options[:backend]` already exists this is not an
issue.

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
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.

cannot upload meta profile to Automate
4 participants