kitchen-transport-train 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/README.md +53 -0
- data/lib/kitchen-transport-train/version.rb +3 -0
- data/lib/kitchen/transport/train.rb +103 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 133f962428df05c64cdd391b97494d38e8e63bef96ef3ee4df43927f66809516
|
4
|
+
data.tar.gz: 9071b6c0b96470fc32638422f3c2658e7a5dfe63c387269fd176fbf5717d3f7f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 361d12c68100e3ffc4ca93cba6d8ae1ea9cc4a56aa77c09ae85bd8708dbe7bc8a05dabc0edf3785aa553ea22379c27c38c8c37397adba60c22446882e0e558d1
|
7
|
+
data.tar.gz: 84f44ff085c7784525da0b3b2a46d54d5672aca6607190698141874c3c21b1e664ef7ab7f9e5152122687968041b96b6aeaf0329d31e78bfec47d7c9e6e03dc4
|
data/CHANGELOG.md
ADDED
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# kitchen-transport-train
|
2
|
+
|
3
|
+
## Summary
|
4
|
+
|
5
|
+
Kitchen transport to use any Train backend, which makes Test Kitchen much more modular with regards to target machines.
|
6
|
+
|
7
|
+
As Train OS Transports were inspired from Kitchen, they provide an almost identical API. This transport is basically an adapter to use Test Kitchen with all OS-style Train transports.
|
8
|
+
|
9
|
+
In contrast to normal Kitchen transports, this does not support the `kitchen login` command as Train is inherently non-interactive. An error will be displayed if you try to use this command.
|
10
|
+
|
11
|
+
## Examples
|
12
|
+
|
13
|
+
Legacy configurations for easy SSH/WinRM connections are supported. This transport will automaticially detect Unix (`ssh` backend) and Windows (`winrm` backend) systems.
|
14
|
+
|
15
|
+
```yaml
|
16
|
+
---
|
17
|
+
transport:
|
18
|
+
name: train
|
19
|
+
backend: ssh # optional
|
20
|
+
ssh_key: ~/.ssh/testkitchen
|
21
|
+
```
|
22
|
+
|
23
|
+
```yaml
|
24
|
+
---
|
25
|
+
transport:
|
26
|
+
name: train
|
27
|
+
backend: winrm # optional
|
28
|
+
```
|
29
|
+
|
30
|
+
Train-oriented configuration can optionally specify the `backend` transport and then add the transport-specific configuration values:
|
31
|
+
|
32
|
+
```yaml
|
33
|
+
---
|
34
|
+
transport:
|
35
|
+
name: train
|
36
|
+
backend: ssh
|
37
|
+
|
38
|
+
# Use the selected Train transport options here 1:1
|
39
|
+
key_files: '...'
|
40
|
+
compression: true
|
41
|
+
...
|
42
|
+
```
|
43
|
+
|
44
|
+
## Link to Train transport options
|
45
|
+
|
46
|
+
Options `user`, `host` and `password` (for kitchen-ec2 and Windows instances) are set automatically.
|
47
|
+
|
48
|
+
- [AWS Session Manager Transport](https://github.com/tecracer-chef/train-awsssm/blob/master/lib/train-awsssm/transport.rb#L8-L14)
|
49
|
+
- Docker Transport: no additional options
|
50
|
+
- [Serial/USB Transport](https://github.com/tecracer-chef/train-serial/blob/master/lib/train-serial/transport.rb#L8-L22)
|
51
|
+
- [SSH Transport](https://github.com/inspec/train/blob/0b9fd4556745d767c9dac2a83d5323e6b7025872/lib/train/transports/ssh.rb#L45-L74)
|
52
|
+
- [Telnet Transport](https://github.com/tecracer-chef/train-telnet/blob/master/lib/train-telnet/transport.rb#L8-L20)
|
53
|
+
- [WinRM Transport](https://github.com/inspec/train-winrm/blob/980190e44571787c7b60614257bd6dc2bd8a337d/lib/train-winrm/transport.rb#L52-L76)
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require_relative "../../kitchen-transport-train/version"
|
2
|
+
|
3
|
+
require "forwardable" unless defined?(Forwardable)
|
4
|
+
require "kitchen/errors" unless defined?(Kitchen::UserError)
|
5
|
+
require "kitchen/transport/base" unless defined?(Kitchen::Transport::Base)
|
6
|
+
require "train" unless defined?(Train)
|
7
|
+
|
8
|
+
module Kitchen
|
9
|
+
module Transport
|
10
|
+
class ConnectionFailed < TransportFailed; end
|
11
|
+
|
12
|
+
class Train < Kitchen::Transport::Base
|
13
|
+
|
14
|
+
kitchen_transport_api_version 1
|
15
|
+
|
16
|
+
plugin_version KitchenTransportTrain::VERSION
|
17
|
+
|
18
|
+
def connection(state, &block)
|
19
|
+
options = connection_options(config.to_hash.merge(state))
|
20
|
+
options = adjust_options(options)
|
21
|
+
|
22
|
+
Kitchen::Transport::Train::Connection.new(options, &block)
|
23
|
+
end
|
24
|
+
|
25
|
+
class Connection < Kitchen::Transport::Base::Connection
|
26
|
+
# Forward everything to the Train connection, where adapters are not needed
|
27
|
+
extend Forwardable
|
28
|
+
def_delegators :@connection, :close, :upload, :download, :wait_until_ready
|
29
|
+
|
30
|
+
attr_reader :logger
|
31
|
+
|
32
|
+
def initialize(options = {})
|
33
|
+
@options = options
|
34
|
+
@logger = Kitchen.logger
|
35
|
+
|
36
|
+
@backend = ::Train.create(options[:backend], options)
|
37
|
+
@connection = @backend.connection
|
38
|
+
|
39
|
+
yield self if block_given?
|
40
|
+
end
|
41
|
+
|
42
|
+
def execute(command)
|
43
|
+
return if command.nil?
|
44
|
+
|
45
|
+
logger.debug("[Train/#{options[:backend]}] Execute (#{command})")
|
46
|
+
|
47
|
+
command_result = @connection.run_command(command)
|
48
|
+
|
49
|
+
if command_result.exit_status == 0
|
50
|
+
logger.info(command_result.stdout)
|
51
|
+
else
|
52
|
+
logger.error(command_result.stderr)
|
53
|
+
|
54
|
+
raise Transport::ConnectionFailed.new(
|
55
|
+
"Train/#{options[:backend]} exited (#{command_result.exit_status}) for command: [#{command}]",
|
56
|
+
command_result.exit_status
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def login_command
|
62
|
+
raise ::Kitchen::UserError, "Interactive shells are not possible with the Train transport"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
# Builds the hash of options needed by the Connection object on construction.
|
69
|
+
#
|
70
|
+
# @param data [Hash] merged configuration and mutable state data
|
71
|
+
# @return [Hash] hash of connection options
|
72
|
+
# @api private
|
73
|
+
def connection_options(data)
|
74
|
+
# `windows_os?` comes from Kitchen::Configurable, which is included in the Kitchen base transport
|
75
|
+
defaults = {
|
76
|
+
backend: windows_os? ? "winrm" : "ssh",
|
77
|
+
}
|
78
|
+
|
79
|
+
overrides = {
|
80
|
+
instance_name: instance.name,
|
81
|
+
kitchen_root: Dir.pwd,
|
82
|
+
|
83
|
+
# Kitchen to Train parameter conversion
|
84
|
+
host: data[:hostname],
|
85
|
+
user: data[:username],
|
86
|
+
}
|
87
|
+
|
88
|
+
defaults.merge(data).merge(overrides)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Map Kitchen parameters to their Train equivalents for compatibility.
|
92
|
+
def adjust_options(data)
|
93
|
+
if data[:backend] == "ssh"
|
94
|
+
data[:key_files] = data[:ssh_key]
|
95
|
+
data.delete(:ssh_key)
|
96
|
+
end
|
97
|
+
|
98
|
+
data
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kitchen-transport-train
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Heinen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-02-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: train
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.5'
|
27
|
+
description: Use the Train transport ecosystem for all your Kitchen needs
|
28
|
+
email:
|
29
|
+
- theinen@tecracer.de
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- README.md
|
36
|
+
- lib/kitchen-transport-train/version.rb
|
37
|
+
- lib/kitchen/transport/train.rb
|
38
|
+
homepage: https://github.com/tecracer-chef/kitchen-transport-train
|
39
|
+
licenses:
|
40
|
+
- Apache-2.0
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '2.6'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.0.3
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Kitchen transport for any Train backend
|
61
|
+
test_files: []
|