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

Allow runner specifications for local connections #225

Merged
merged 4 commits into from
Dec 6, 2017

Conversation

jerryaldrichiii
Copy link
Contributor

This allows for overriding the default runner selection. For example, when running InSpec unit tests via AppVeyor on Windows the mock file loads would create too many named pipe processes thus exhausting available resources.

This allows for overriding the default runner selection. For example, when
running InSpec unit tests via AppVeyor on Windows the mock file loads would
create too many named pipe processes thus exhausting available resources.

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
@jerryaldrichiii jerryaldrichiii requested a review from a team December 6, 2017 17:05
WindowsPipeRunner.new
when 'windows_shell'
WindowsShellRunner.new
end
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably raise an exception if a runner was supplied that we don't support.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, will add an exception.

def run_command_via_connection(cmd)
@runner.run_command(cmd)
if defined?(@runner)
Copy link
Contributor

Choose a reason for hiding this comment

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

If we add the exception handling above, do we need this change? Would there ever be a case where we didn't have a valid @runner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the first few commands run do not use GenericRunner, but instead just use ShellOut.

The difference being that GenericRunner attempts to do the CommandWrapper bits.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, I understand.

We can probably then just clean this up a wee bit.

def run_command_via_connection(cmd)
  # use the runner if it's defined
  return @runner.run_command(cmd) if defined?(@runner)

  # if we don't have a runner, such as at the beginning of setting up the transport
  # and while we're performing the first few steps of OS detection, fall back to
  # standard shelling out.
  res = Mixlib::ShellOut.new(cmd.
  ... etc ...
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Love it. Much nicer! Will make it so.

@runner = WindowsShellRunner.new
end
end
@runner = if options[:runner]
Copy link
Contributor

Choose a reason for hiding this comment

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

I also wonder if this should be :command_runner and not just :runner in case we have file runners, etc. in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't see any reason not to do it. Will make it so.

Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
@jerryaldrichiii jerryaldrichiii force-pushed the ja/allow-local-runner-specification branch from 1cc9137 to 39f9245 Compare December 6, 2017 17:31
Signed-off-by: Jerry Aldrich <jerryaldrichiii@gmail.com>
Copy link
Contributor

@arlimus arlimus left a comment

Choose a reason for hiding this comment

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

Fantastic fix thank you @jerryaldrichiii !

@arlimus arlimus merged commit 0c091ef into master Dec 6, 2017
@arlimus arlimus deleted the ja/allow-local-runner-specification branch December 6, 2017 19:25
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.

3 participants