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

Add host and port config options #110

Merged
merged 1 commit into from
Nov 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ verifier:
sudo_command: 'skittles'
```

You can also specify the host and port to be used by InSpec when targeting the node. Otherwise, it defaults to the hostname and port used by kitchen for converging.

```yaml
verifier:
name: inspec
host: 192.168.56.40
port: 22
```

### Directory Structure

By default `kitchen-inspec` expects test to be in `test/integration/%suite%` directory structure (we use Chef as provisioner here):
Expand Down
8 changes: 4 additions & 4 deletions lib/kitchen/verifier/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def runner_options_for_ssh(config_data)
# pass-in sudo config from kitchen verifier
"sudo" => config[:sudo],
"sudo_command" => config[:sudo_command],
"host" => kitchen[:hostname],
"port" => kitchen[:port],
"host" => config[:host] || kitchen[:hostname],
"port" => config[:port] || kitchen[:port],
"user" => kitchen[:username],
"keepalive" => kitchen[:keepalive],
"keepalive_interval" => kitchen[:keepalive_interval],
Expand All @@ -196,8 +196,8 @@ def runner_options_for_winrm(config_data)
opts = {
"backend" => "winrm",
"logger" => logger,
"host" => URI(kitchen[:endpoint]).hostname,
"port" => URI(kitchen[:endpoint]).port,
"host" => config[:host] || URI(kitchen[:endpoint]).hostname,
"port" => config[:port] || URI(kitchen[:endpoint]).port,
"user" => kitchen[:user],
"password" => kitchen[:password] || kitchen[:pass],
"connection_retries" => kitchen[:connection_retries],
Expand Down
34 changes: 34 additions & 0 deletions spec/kitchen/verifier/inspec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@
verifier.call(port: 123)
end

it "constructs a Inspec::Runner using transport config data(host and port)" do
config[:host] = "192.168.33.40"
config[:port] = 222

expect(Inspec::Runner).to receive(:new)
.with(
hash_including(
"backend" => "ssh",
"host" => "192.168.33.40",
"port" => 222
)
)
.and_return(runner)

verifier.call(port: 123)
end

it "constructs an Inspec::Runner with a specified inspec output format" do
config[:format] = "documentation"

Expand Down Expand Up @@ -324,6 +341,23 @@

verifier.call(hostname: "win.dows", port: 123)
end

it "constructs a Inspec::Runner using transport config data(host and port)" do
config[:host] = "192.168.56.40"
config[:port] = 22

expect(Inspec::Runner).to receive(:new)
.with(
hash_including(
"backend" => "winrm",
"host" => "192.168.56.40",
"port" => 22
)
)
.and_return(runner)

verifier.call(hostname: "win.dows", port: 123)
end
end

context "with an unsupported transport" do
Expand Down