Skip to content

Commit

Permalink
Add properties to use Test Kitchen with Chef 19 Target Mode (#1)
Browse files Browse the repository at this point in the history
* Add credentials file generation
* Fix disparity to TestKitchen SSH; Fix user passing
  • Loading branch information
thheinen authored Jul 14, 2024
1 parent 5890bd2 commit 803621f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"editor.renderFinalNewline": true,
"editor.renderFinalNewline": "on",
"editor.renderWhitespace":"all",
"editor.trimAutoWhitespace": true,
"files.exclude": {
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Version 0.2.0

- Fix disparity between TestKitchen SSH wait parameters and Train
- Fix user passing via a `train_user` override parameters
- Add call to generate an RFC099 credentials file

## Version 0.1.0

- Initial version
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ transport:

Options `user`, `host` and `password` (for kitchen-ec2 and Windows instances) are set automatically.

If you want to use `kitchen-ec2` with the `root` user however (as needed in Chef 19 Target Mode), you need to additionally specify `train_user: root`. This is due to a long-standing bug in Kitchen-EC2 where the standard platform's autodetected user will override manually specified `root` values.

Standard and community-supported options for transports:

- [AWS Session Manager Transport](https://github.com/tecracer-chef/train-awsssm/blob/master/lib/train-awsssm/transport.rb#L8-L14)
- Docker Transport: no additional options
- [Serial/USB Transport](https://github.com/tecracer-chef/train-serial/blob/master/lib/train-serial/transport.rb#L8-L22)
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen-transport-train/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module KitchenTransportTrain
VERSION = "0.1.0".freeze
VERSION = "0.2.0".freeze
end
29 changes: 29 additions & 0 deletions lib/kitchen/transport/train.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,31 @@ def initialize(options = {})
yield self if block_given?
end

def train_uri
@connection.uri
end

def credentials_file
instance_name = @connection.transport_options[:instance_name]

config = @backend.instance_variable_get(:@connection_options)
config.compact!
config.transform_values! { |v| v.is_a?(Symbol) ? v.to_s : v }

# Some configuration variables vary between transports
config[:host] = config[:hostname] = @connection.transport_options[:host]
config[:key_files] = @connection.transport_options[:key_files]

# Due to a long-standing bug in TestKitchen, standard platforms will override
# kitchen.yml `user` settings, so this transport introduces an "train_user" override.
# See https://github.com/test-kitchen/kitchen-ec2/pull/273
config[:user] = config[:username] = @connection.transport_options[:train_user] || @connection.transport_options[:user]

require "toml-rb" unless defined?(TomlRB)

"['#{instance_name}']\n" + TomlRB.dump(config)
end

def execute(command)
return if command.nil?

Expand Down Expand Up @@ -95,6 +120,10 @@ def adjust_options(data)
data.delete(:ssh_key)
end

# Adjust option defaults
data[:retries] = 15
data[:delay] = 5

data
end
end
Expand Down

0 comments on commit 803621f

Please sign in to comment.