From 803621f21367c31880aff0e7b8bdb06254f0f3fb Mon Sep 17 00:00:00 2001 From: Thomas Heinen <33926466+thheinen@users.noreply.github.com> Date: Sun, 14 Jul 2024 15:33:06 +0200 Subject: [PATCH] Add properties to use Test Kitchen with Chef 19 Target Mode (#1) * Add credentials file generation * Fix disparity to TestKitchen SSH; Fix user passing --- .vscode/settings.json | 2 +- CHANGELOG.md | 6 ++++++ README.md | 4 ++++ lib/kitchen-transport-train/version.rb | 2 +- lib/kitchen/transport/train.rb | 29 ++++++++++++++++++++++++++ 5 files changed, 41 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index ffd5cfb..e39a55b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,5 @@ { - "editor.renderFinalNewline": true, + "editor.renderFinalNewline": "on", "editor.renderWhitespace":"all", "editor.trimAutoWhitespace": true, "files.exclude": { diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a07868..dea6e51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 9e65d58..07aa65b 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/lib/kitchen-transport-train/version.rb b/lib/kitchen-transport-train/version.rb index 28af646..44d7213 100644 --- a/lib/kitchen-transport-train/version.rb +++ b/lib/kitchen-transport-train/version.rb @@ -1,3 +1,3 @@ module KitchenTransportTrain - VERSION = "0.1.0".freeze + VERSION = "0.2.0".freeze end diff --git a/lib/kitchen/transport/train.rb b/lib/kitchen/transport/train.rb index c49afbb..1180dc5 100644 --- a/lib/kitchen/transport/train.rb +++ b/lib/kitchen/transport/train.rb @@ -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? @@ -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