r-train 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -6
- data/README.md +19 -0
- data/Rakefile +6 -0
- data/lib/train/extras/command_wrapper.rb +11 -3
- data/lib/train/transports/ssh_connection.rb +1 -0
- data/lib/train/transports/winrm.rb +17 -21
- data/lib/train/transports/winrm_connection.rb +16 -80
- data/lib/train/version.rb +1 -1
- data/test/unit/extras/command_wrapper_test.rb +2 -1
- data/test/windows/local_test.rb +46 -0
- data/test/windows/winrm_test.rb +52 -0
- data/train.gemspec +2 -2
- metadata +11 -11
- data/test/integration/Berksfile.lock +0 -8
- data/test/tools/os.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d0d1580a540541055d89da66ae4d90b97e85162
|
4
|
+
data.tar.gz: b228d1944aa2b7201223ad47897033ca6e6a531c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d189e9a16f00e5921e7cdd3c15610c35ccdfa70cc969ec82e59e440b2dae214dd92ae65dbd89f5e9dbdc2b8bbf29cd53aedef8dab73bd6cbbadc2b1f321c9f20
|
7
|
+
data.tar.gz: 4a78e3f8dd1b22e3405003e882de552bf7c62ee1c70e491dd36c673248859c0aa566f9043248428d99ce0b52b7f65c7f8151b550ed68ea5f3e5b6e51ae39e905
|
data/CHANGELOG.md
CHANGED
@@ -1,30 +1,51 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [0.9.
|
4
|
-
[Full Changelog](https://github.com/chef/train/compare/v0.9.
|
3
|
+
## [0.9.5](https://github.com/chef/train/tree/0.9.5) (2016-01-25)
|
4
|
+
[Full Changelog](https://github.com/chef/train/compare/v0.9.4...0.9.5)
|
5
|
+
|
6
|
+
**Implemented enhancements:**
|
7
|
+
|
8
|
+
- use minitest for windows tests [\#56](https://github.com/chef/train/pull/56) ([chris-rock](https://github.com/chris-rock))
|
9
|
+
- use negotiate auth for winrm and not basic\_auth [\#55](https://github.com/chef/train/pull/55) ([mwrock](https://github.com/mwrock))
|
10
|
+
- bugfix: pin net-ssh 2.9 in gem file [\#54](https://github.com/chef/train/pull/54) ([chris-rock](https://github.com/chris-rock))
|
11
|
+
- Add appveyor and Windows test [\#53](https://github.com/chef/train/pull/53) ([chris-rock](https://github.com/chris-rock))
|
12
|
+
- Deprecating winrm-tansport gem [\#46](https://github.com/chef/train/pull/46) ([mwrock](https://github.com/mwrock))
|
5
13
|
|
6
14
|
**Fixed bugs:**
|
7
15
|
|
8
|
-
-
|
16
|
+
- Cannot install train on Windows with ChefDK if username \>9 chars in length due to spec filename lengths in docker-api gem. [\#28](https://github.com/chef/train/issues/28)
|
17
|
+
- Properly wrap commands in powershell for local backend [\#57](https://github.com/chef/train/pull/57) ([chris-rock](https://github.com/chris-rock))
|
18
|
+
- Copying https://github.com/test-kitchen/test-kitchen/pull/919 to this repo [\#52](https://github.com/chef/train/pull/52) ([tyler-ball](https://github.com/tyler-ball))
|
9
19
|
|
10
|
-
|
20
|
+
## [v0.9.4](https://github.com/chef/train/tree/v0.9.4) (2016-01-15)
|
21
|
+
[Full Changelog](https://github.com/chef/train/compare/v0.9.3...v0.9.4)
|
22
|
+
|
23
|
+
**Implemented enhancements:**
|
11
24
|
|
12
25
|
- 0.9.3 is empty on Windows [\#48](https://github.com/chef/train/pull/48) ([tyler-ball](https://github.com/tyler-ball))
|
13
26
|
- Updating to the latest release of net-ssh to consume https://github.com/net-ssh/net-ssh/pull/280 [\#47](https://github.com/chef/train/pull/47) ([tyler-ball](https://github.com/tyler-ball))
|
14
27
|
|
28
|
+
**Fixed bugs:**
|
29
|
+
|
30
|
+
- bugfix: command wrapper always return nil [\#50](https://github.com/chef/train/pull/50) ([chris-rock](https://github.com/chris-rock))
|
31
|
+
|
32
|
+
**Merged pull requests:**
|
33
|
+
|
34
|
+
- 0.9.4 [\#51](https://github.com/chef/train/pull/51) ([chris-rock](https://github.com/chris-rock))
|
35
|
+
|
15
36
|
## [v0.9.3](https://github.com/chef/train/tree/v0.9.3) (2016-01-03)
|
16
37
|
[Full Changelog](https://github.com/chef/train/compare/v0.9.2...v0.9.3)
|
17
38
|
|
18
39
|
**Implemented enhancements:**
|
19
40
|
|
41
|
+
- introduce `mounted` as a separate method to retrieve the content [\#44](https://github.com/chef/train/pull/44) ([chris-rock](https://github.com/chris-rock))
|
20
42
|
- Support for local transport on Windows [\#43](https://github.com/chef/train/pull/43) ([chris-rock](https://github.com/chris-rock))
|
21
43
|
- Split integration test preparation from executing [\#42](https://github.com/chef/train/pull/42) ([chris-rock](https://github.com/chris-rock))
|
44
|
+
- Support for AIX and targeted SSH testing [\#41](https://github.com/chef/train/pull/41) ([foobarbam](https://github.com/foobarbam))
|
22
45
|
|
23
46
|
**Merged pull requests:**
|
24
47
|
|
25
48
|
- 0.9.3 [\#45](https://github.com/chef/train/pull/45) ([chris-rock](https://github.com/chris-rock))
|
26
|
-
- introduce `mounted` as a separate method to retrieve the content [\#44](https://github.com/chef/train/pull/44) ([chris-rock](https://github.com/chris-rock))
|
27
|
-
- Support for AIX and targeted SSH testing [\#41](https://github.com/chef/train/pull/41) ([foobarbam](https://github.com/foobarbam))
|
28
49
|
|
29
50
|
## [v0.9.2](https://github.com/chef/train/tree/v0.9.2) (2015-12-11)
|
30
51
|
[Full Changelog](https://github.com/chef/train/compare/v0.9.1...v0.9.2)
|
data/README.md
CHANGED
@@ -89,6 +89,25 @@ puts conn.file('/proc/version').content
|
|
89
89
|
conn.close
|
90
90
|
```
|
91
91
|
|
92
|
+
# Testing
|
93
|
+
|
94
|
+
We perform `unit`, `integration` and `windows` tests.
|
95
|
+
|
96
|
+
* `unit` tests ensure the intended behaviour of the implementation
|
97
|
+
* `integration` tests run against VMs and docker containers
|
98
|
+
* `windows` tests that run on appveyor for windows integration tests
|
99
|
+
|
100
|
+
## Windows
|
101
|
+
|
102
|
+
```
|
103
|
+
# run windows tests
|
104
|
+
bundle exec rake test:windows
|
105
|
+
|
106
|
+
# run single tests
|
107
|
+
bundle exec ruby -I .\test\windows\ .\test\windows\local_test.rb
|
108
|
+
```
|
109
|
+
|
110
|
+
|
92
111
|
# Kudos and Contributors
|
93
112
|
|
94
113
|
Train is heavily based on the work of:
|
data/Rakefile
CHANGED
@@ -33,6 +33,12 @@ namespace :test do
|
|
33
33
|
sh('sh', '-c', "cd #{path} && config=test-runner.yaml ruby -I ../../lib docker_test.rb tests/*")
|
34
34
|
end
|
35
35
|
|
36
|
+
task :windows do
|
37
|
+
Dir.glob('test/windows/*_test.rb').all? do |file|
|
38
|
+
sh(Gem.ruby, '-w', '-I .\test\windows', file)
|
39
|
+
end or fail 'Failures'
|
40
|
+
end
|
41
|
+
|
36
42
|
task :vm do
|
37
43
|
concurrency = ENV['CONCURRENCY'] || 4
|
38
44
|
path = File.join(File.dirname(__FILE__), 'test', 'integration')
|
@@ -99,12 +99,20 @@ module Train::Extras
|
|
99
99
|
def initialize(backend, options)
|
100
100
|
@backend = backend
|
101
101
|
validate_options(options)
|
102
|
+
end
|
102
103
|
|
103
|
-
|
104
|
+
def run(script)
|
105
|
+
# wrap the script to ensure we always run it via powershell
|
106
|
+
# especially in local mode, we cannot be sure that we get a Powershell
|
107
|
+
# we may just get a `cmd`.
|
108
|
+
# TODO: we may want to opt for powershell.exe -command instead of `encodeCommand`
|
109
|
+
"powershell -encodedCommand #{WinRM::PowershellScript.new(safe_script(script)).encoded}"
|
104
110
|
end
|
105
111
|
|
106
|
-
|
107
|
-
|
112
|
+
# reused from https://github.com/WinRb/WinRM/blob/master/lib/winrm/command_executor.rb
|
113
|
+
# suppress the progress stream from leaking to stderr
|
114
|
+
def safe_script(script)
|
115
|
+
"$ProgressPreference='SilentlyContinue';" + script
|
108
116
|
end
|
109
117
|
|
110
118
|
def to_s
|
@@ -35,7 +35,7 @@ module Train::Transports
|
|
35
35
|
# @author Matt Wrock <matt@mattwrock.com>
|
36
36
|
# @author Salim Afiune <salim@afiunemaya.com.mx>
|
37
37
|
# @author Fletcher Nichol <fnichol@nichol.ca>
|
38
|
-
class WinRM < Train.plugin(1)
|
38
|
+
class WinRM < Train.plugin(1)
|
39
39
|
name 'winrm'
|
40
40
|
|
41
41
|
autoload :Connection, 'train/transports/winrm_connection'
|
@@ -89,7 +89,7 @@ module Train::Transports
|
|
89
89
|
opts[:endpoint] = "#{scheme}://#{opts[:host]}:#{port}/#{path}"
|
90
90
|
end
|
91
91
|
|
92
|
-
|
92
|
+
WINRM_FS_SPEC_VERSION = '~> 0.3'.freeze
|
93
93
|
|
94
94
|
# Builds the hash of options needed by the Connection object on
|
95
95
|
# construction.
|
@@ -100,9 +100,9 @@ module Train::Transports
|
|
100
100
|
def connection_options(opts)
|
101
101
|
{
|
102
102
|
logger: logger,
|
103
|
-
winrm_transport: :
|
104
|
-
disable_sspi:
|
105
|
-
basic_auth_only:
|
103
|
+
winrm_transport: :negotiate,
|
104
|
+
disable_sspi: false,
|
105
|
+
basic_auth_only: false,
|
106
106
|
endpoint: opts[:endpoint],
|
107
107
|
user: opts[:user],
|
108
108
|
pass: opts[:password],
|
@@ -132,39 +132,35 @@ module Train::Transports
|
|
132
132
|
|
133
133
|
# (see Base#load_needed_dependencies!)
|
134
134
|
def load_needed_dependencies!
|
135
|
-
spec_version =
|
136
|
-
logger.debug('
|
137
|
-
" loading WinRM::
|
138
|
-
gem 'winrm-
|
139
|
-
first_load = require 'winrm
|
135
|
+
spec_version = WINRM_FS_SPEC_VERSION.dup
|
136
|
+
logger.debug('winrm-fs requested,' \
|
137
|
+
" loading WinRM::FS gem (#{spec_version})")
|
138
|
+
gem 'winrm-fs', spec_version
|
139
|
+
first_load = require 'winrm-fs'
|
140
140
|
load_winrm_transport!
|
141
141
|
|
142
|
-
version = ::WinRM::Transport::VERSION
|
143
142
|
if first_load
|
144
|
-
logger.debug(
|
143
|
+
logger.debug('WinRM::FS library loaded')
|
145
144
|
else
|
146
|
-
logger.debug(
|
145
|
+
logger.debug('WinRM::FS previously loaded')
|
147
146
|
end
|
148
147
|
rescue LoadError => e
|
149
148
|
logger.fatal(
|
150
|
-
"The `winrm-
|
149
|
+
"The `winrm-fs' gem is missing and must" \
|
151
150
|
' be installed or cannot be properly activated. Run' \
|
152
|
-
" `gem install winrm-
|
151
|
+
" `gem install winrm-fs --version '#{spec_version}'`" \
|
153
152
|
' or add the following to your Gemfile if you are using Bundler:' \
|
154
|
-
" `gem 'winrm-
|
153
|
+
" `gem 'winrm-fs', '#{spec_version}'`.",
|
155
154
|
)
|
156
155
|
raise Train::UserError,
|
157
|
-
"Could not load or activate WinRM::
|
156
|
+
"Could not load or activate WinRM::FS (#{e.message})"
|
158
157
|
end
|
159
158
|
|
160
159
|
# Load WinRM::Transport code.
|
161
160
|
#
|
162
161
|
# @api private
|
163
162
|
def load_winrm_transport!
|
164
|
-
silence_warnings { require 'winrm' }
|
165
|
-
require 'winrm/transport/shell_closer'
|
166
|
-
require 'winrm/transport/command_executor'
|
167
|
-
require 'winrm/transport/file_transporter'
|
163
|
+
silence_warnings { require 'winrm-fs' }
|
168
164
|
end
|
169
165
|
|
170
166
|
# Return the last saved WinRM connection instance.
|
@@ -27,7 +27,7 @@ class Train::Transports::WinRM
|
|
27
27
|
# host such as executing commands, transferring files, etc.
|
28
28
|
#
|
29
29
|
# @author Fletcher Nichol <fnichol@nichol.ca>
|
30
|
-
class Connection < BaseConnection
|
30
|
+
class Connection < BaseConnection
|
31
31
|
def initialize(options)
|
32
32
|
super(options)
|
33
33
|
@endpoint = @options.delete(:endpoint)
|
@@ -42,10 +42,8 @@ class Train::Transports::WinRM
|
|
42
42
|
# (see Base::Connection#close)
|
43
43
|
def close
|
44
44
|
return if @session.nil?
|
45
|
-
|
46
|
-
logger.debug("[WinRM] closing remote shell #{shell_id} on #{self}")
|
45
|
+
|
47
46
|
session.close
|
48
|
-
logger.debug("[WinRM] remote shell #{shell_id} closed")
|
49
47
|
ensure
|
50
48
|
@session = nil
|
51
49
|
end
|
@@ -95,10 +93,8 @@ class Train::Transports::WinRM
|
|
95
93
|
def wait_until_ready
|
96
94
|
delay = 3
|
97
95
|
session(
|
98
|
-
|
99
|
-
|
100
|
-
message: "Waiting for WinRM service on #{endpoint}, "\
|
101
|
-
"retrying in #{delay} seconds",
|
96
|
+
retry_limit: @max_wait_until_ready / delay,
|
97
|
+
retry_delay: delay,
|
102
98
|
)
|
103
99
|
execute(PING_COMMAND.dup)
|
104
100
|
end
|
@@ -107,16 +103,6 @@ class Train::Transports::WinRM
|
|
107
103
|
|
108
104
|
PING_COMMAND = "Write-Host '[WinRM] Established\n'".freeze
|
109
105
|
|
110
|
-
RESCUE_EXCEPTIONS_ON_ESTABLISH = lambda do
|
111
|
-
[
|
112
|
-
Errno::EACCES, Errno::EADDRINUSE, Errno::ECONNREFUSED,
|
113
|
-
Errno::ECONNRESET, Errno::ENETUNREACH, Errno::EHOSTUNREACH,
|
114
|
-
::WinRM::WinRMHTTPTransportError, ::WinRM::WinRMAuthorizationError,
|
115
|
-
HTTPClient::KeepAliveDisconnected,
|
116
|
-
HTTPClient::ConnectTimeoutError
|
117
|
-
].freeze
|
118
|
-
end
|
119
|
-
|
120
106
|
# Create a local RDP document and return it
|
121
107
|
#
|
122
108
|
# @param opts [Hash] configuration options
|
@@ -136,35 +122,10 @@ class Train::Transports::WinRM
|
|
136
122
|
content
|
137
123
|
end
|
138
124
|
|
139
|
-
# Establish a remote shell session on the remote host.
|
140
|
-
#
|
141
|
-
# @param opts [Hash] retry options
|
142
|
-
# @option opts [Integer] :retries the number of times to retry before
|
143
|
-
# failing
|
144
|
-
# @option opts [Float] :delay the number of seconds to wait until
|
145
|
-
# attempting a retry
|
146
|
-
# @option opts [String] :message an optional message to be logged on
|
147
|
-
# debug (overriding the default) when a rescuable exception is raised
|
148
|
-
# @return [Winrm::CommandExecutor] the command executor session
|
149
|
-
# @api private
|
150
|
-
def establish_shell(opts)
|
151
|
-
service_args = [@endpoint, @winrm_transport, options]
|
152
|
-
@service = ::WinRM::WinRMWebService.new(*service_args)
|
153
|
-
closer = WinRM::Transport::ShellCloser.new("#{self}", false, service_args)
|
154
|
-
|
155
|
-
executor = WinRM::Transport::CommandExecutor.new(@service, logger, closer)
|
156
|
-
retryable(opts) do
|
157
|
-
logger.debug("[WinRM] opening remote shell on #{self}")
|
158
|
-
shell_id = executor.open
|
159
|
-
logger.debug("[WinRM] remote shell #{shell_id} is open on #{self}")
|
160
|
-
end
|
161
|
-
executor
|
162
|
-
end
|
163
|
-
|
164
125
|
# @return [Winrm::FileTransporter] a file transporter
|
165
126
|
# @api private
|
166
127
|
def file_transporter
|
167
|
-
@file_transporter ||= WinRM::
|
128
|
+
@file_transporter ||= WinRM::FS::Core::FileTransporter.new(session)
|
168
129
|
end
|
169
130
|
|
170
131
|
# Builds a `LoginCommand` for use by Linux-based platforms.
|
@@ -196,38 +157,6 @@ class Train::Transports::WinRM
|
|
196
157
|
LoginCommand.new('mstsc', rdp_doc)
|
197
158
|
end
|
198
159
|
|
199
|
-
# Yields to a block and reties the block if certain rescuable
|
200
|
-
# exceptions are raised.
|
201
|
-
#
|
202
|
-
# @param opts [Hash] retry options
|
203
|
-
# @option opts [Integer] :retries the number of times to retry before
|
204
|
-
# failing
|
205
|
-
# @option opts [Float] :delay the number of seconds to wait until
|
206
|
-
# attempting a retry
|
207
|
-
# @option opts [String] :message an optional message to be logged on
|
208
|
-
# debug (overriding the default) when a rescuable exception is raised
|
209
|
-
# @return [Winrm::CommandExecutor] the command executor session
|
210
|
-
# @api private
|
211
|
-
def retryable(opts)
|
212
|
-
yield
|
213
|
-
rescue *RESCUE_EXCEPTIONS_ON_ESTABLISH.call => e
|
214
|
-
if (opts[:retries] -= 1) <= 0
|
215
|
-
logger.warn("[WinRM] connection failed, terminating (#{e.inspect})")
|
216
|
-
raise
|
217
|
-
end
|
218
|
-
|
219
|
-
if opts[:message]
|
220
|
-
logger.debug("[WinRM] connection failed (#{e.inspect})")
|
221
|
-
message = opts[:message]
|
222
|
-
else
|
223
|
-
message = '[WinRM] connection failed, '\
|
224
|
-
"retrying in #{opts[:delay]} seconds (#{e.inspect})"
|
225
|
-
end
|
226
|
-
logger.info(message)
|
227
|
-
sleep(opts[:delay])
|
228
|
-
retry
|
229
|
-
end
|
230
|
-
|
231
160
|
# Establishes a remote shell session, or establishes one when invoked
|
232
161
|
# the first time.
|
233
162
|
#
|
@@ -235,10 +164,17 @@ class Train::Transports::WinRM
|
|
235
164
|
# @return [Winrm::CommandExecutor] the command executor session
|
236
165
|
# @api private
|
237
166
|
def session(retry_options = {})
|
238
|
-
@session ||=
|
239
|
-
|
240
|
-
|
241
|
-
|
167
|
+
@session ||= begin
|
168
|
+
opts = {
|
169
|
+
retry_limit: @connection_retries.to_i,
|
170
|
+
retry_delay: @connection_retry_sleep.to_i,
|
171
|
+
}.merge(retry_options)
|
172
|
+
|
173
|
+
service_args = [@endpoint, @winrm_transport, options.merge(opts)]
|
174
|
+
@service = ::WinRM::WinRMWebService.new(*service_args)
|
175
|
+
@service.logger = logger
|
176
|
+
@service.create_executor
|
177
|
+
end
|
242
178
|
end
|
243
179
|
|
244
180
|
# String representation of object, reporting its connection details and
|
data/lib/train/version.rb
CHANGED
@@ -51,6 +51,7 @@ describe 'powershell command' do
|
|
51
51
|
|
52
52
|
it 'wraps commands in powershell' do
|
53
53
|
lc = cls.new(backend, {})
|
54
|
-
|
54
|
+
tmp =
|
55
|
+
lc.run(cmd).must_equal "powershell -encodedCommand #{WinRM::PowershellScript.new('$ProgressPreference=\'SilentlyContinue\';' + cmd).encoded}"
|
55
56
|
end
|
56
57
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Christoph Hartmann
|
3
|
+
# author: Dominik Richter
|
4
|
+
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'minitest/spec'
|
7
|
+
require 'mocha/setup'
|
8
|
+
require 'train'
|
9
|
+
|
10
|
+
describe 'windows local command' do
|
11
|
+
let(:conn) {
|
12
|
+
# get final config
|
13
|
+
target_config = Train.target_config({})
|
14
|
+
# initialize train
|
15
|
+
backend = Train.create('local', target_config)
|
16
|
+
|
17
|
+
# start or reuse a connection
|
18
|
+
conn = backend.connection
|
19
|
+
conn
|
20
|
+
}
|
21
|
+
|
22
|
+
it 'verify os' do
|
23
|
+
os = conn.os
|
24
|
+
os[:name].must_equal nil
|
25
|
+
os[:family].must_equal "windows"
|
26
|
+
os[:release].must_equal "Server 2012 R2"
|
27
|
+
os[:arch].must_equal nil
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'run echo test' do
|
31
|
+
cmd = conn.run_command('Write-Output "test"')
|
32
|
+
cmd.stdout.must_equal "test\r\n"
|
33
|
+
cmd.stderr.must_equal ''
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'use powershell piping' do
|
37
|
+
cmd = conn.run_command("New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name A -Value (Write-Output 'PropertyA') -PassThru | Add-Member -MemberType NoteProperty -Name B -Value (Write-Output 'PropertyB') -PassThru | ConvertTo-Json")
|
38
|
+
cmd.stdout.must_equal "{\r\n \"A\": \"PropertyA\",\r\n \"B\": \"PropertyB\"\r\n}\r\n"
|
39
|
+
cmd.stderr.must_equal ''
|
40
|
+
end
|
41
|
+
|
42
|
+
after do
|
43
|
+
# close the connection
|
44
|
+
conn.close
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Christoph Hartmann
|
3
|
+
# author: Dominik Richter
|
4
|
+
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'minitest/spec'
|
7
|
+
require 'mocha/setup'
|
8
|
+
require 'train'
|
9
|
+
|
10
|
+
describe 'windows local command' do
|
11
|
+
let(:conn) {
|
12
|
+
# get final config
|
13
|
+
target_config = Train.target_config({
|
14
|
+
target: ENV['train_target'],
|
15
|
+
password: ENV['winrm_pass'],
|
16
|
+
ssl: ENV['train_ssl'],
|
17
|
+
self_signed: true,
|
18
|
+
})
|
19
|
+
|
20
|
+
# initialize train
|
21
|
+
backend = Train.create('winrm', target_config)
|
22
|
+
|
23
|
+
# start or reuse a connection
|
24
|
+
conn = backend.connection
|
25
|
+
conn
|
26
|
+
}
|
27
|
+
|
28
|
+
it 'verify os' do
|
29
|
+
os = conn.os
|
30
|
+
os[:name].must_equal nil
|
31
|
+
os[:family].must_equal "windows"
|
32
|
+
os[:release].must_equal "Server 2012 R2"
|
33
|
+
os[:arch].must_equal nil
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'run echo test' do
|
37
|
+
cmd = conn.run_command('Write-Output "test"')
|
38
|
+
cmd.stdout.must_equal "test\r\n"
|
39
|
+
cmd.stderr.must_equal ''
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'use powershell piping' do
|
43
|
+
cmd = conn.run_command("New-Object -Type PSObject | Add-Member -MemberType NoteProperty -Name A -Value (Write-Output 'PropertyA') -PassThru | Add-Member -MemberType NoteProperty -Name B -Value (Write-Output 'PropertyB') -PassThru | ConvertTo-Json")
|
44
|
+
cmd.stdout.must_equal "{\r\n \"A\": \"PropertyA\",\r\n \"B\": \"PropertyB\"\r\n}\r\n"
|
45
|
+
cmd.stderr.must_equal ''
|
46
|
+
end
|
47
|
+
|
48
|
+
after do
|
49
|
+
# close the connection
|
50
|
+
conn.close
|
51
|
+
end
|
52
|
+
end
|
data/train.gemspec
CHANGED
@@ -29,8 +29,8 @@ Gem::Specification.new do |spec|
|
|
29
29
|
# 1.9 support is no longer needed here or for Inspec
|
30
30
|
spec.add_dependency 'net-ssh', '>= 2.9', '< 4.0'
|
31
31
|
spec.add_dependency 'net-scp', '~> 1.2'
|
32
|
-
spec.add_dependency 'winrm', '~> 1.
|
33
|
-
spec.add_dependency 'winrm-
|
32
|
+
spec.add_dependency 'winrm', '~> 1.6'
|
33
|
+
spec.add_dependency 'winrm-fs', '~> 0.3'
|
34
34
|
spec.add_dependency 'docker-api', '~> 1.22'
|
35
35
|
|
36
36
|
spec.add_development_dependency 'rake', '~> 10.4'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: r-train
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -78,28 +78,28 @@ dependencies:
|
|
78
78
|
requirements:
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: '1.
|
81
|
+
version: '1.6'
|
82
82
|
type: :runtime
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '1.
|
88
|
+
version: '1.6'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name: winrm-
|
90
|
+
name: winrm-fs
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
95
|
+
version: '0.3'
|
96
96
|
type: :runtime
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - "~>"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '0.3'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: docker-api
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -263,7 +263,6 @@ files:
|
|
263
263
|
- test/integration/.kitchen/logs/default-ubuntu-1404.log
|
264
264
|
- test/integration/.kitchen/logs/kitchen.log
|
265
265
|
- test/integration/Berksfile
|
266
|
-
- test/integration/Berksfile.lock
|
267
266
|
- test/integration/bootstrap.sh
|
268
267
|
- test/integration/chefignore
|
269
268
|
- test/integration/cookbooks/test/metadata.rb
|
@@ -287,7 +286,6 @@ files:
|
|
287
286
|
- test/integration/tests/path_pipe_test.rb
|
288
287
|
- test/integration/tests/path_symlink_test.rb
|
289
288
|
- test/integration/tests/run_command_test.rb
|
290
|
-
- test/tools/os.rb
|
291
289
|
- test/unit/extras/command_wrapper_test.rb
|
292
290
|
- test/unit/extras/file_common_test.rb
|
293
291
|
- test/unit/extras/linux_file_test.rb
|
@@ -304,6 +302,8 @@ files:
|
|
304
302
|
- test/unit/transports/mock_test.rb
|
305
303
|
- test/unit/transports/ssh_test.rb
|
306
304
|
- test/unit/version_test.rb
|
305
|
+
- test/windows/local_test.rb
|
306
|
+
- test/windows/winrm_test.rb
|
307
307
|
- train.gemspec
|
308
308
|
homepage: https://github.com/chef/train/
|
309
309
|
licenses:
|
@@ -381,7 +381,6 @@ test_files:
|
|
381
381
|
- test/integration/.kitchen/logs/default-ubuntu-1404.log
|
382
382
|
- test/integration/.kitchen/logs/kitchen.log
|
383
383
|
- test/integration/Berksfile
|
384
|
-
- test/integration/Berksfile.lock
|
385
384
|
- test/integration/bootstrap.sh
|
386
385
|
- test/integration/chefignore
|
387
386
|
- test/integration/cookbooks/test/metadata.rb
|
@@ -405,7 +404,6 @@ test_files:
|
|
405
404
|
- test/integration/tests/path_pipe_test.rb
|
406
405
|
- test/integration/tests/path_symlink_test.rb
|
407
406
|
- test/integration/tests/run_command_test.rb
|
408
|
-
- test/tools/os.rb
|
409
407
|
- test/unit/extras/command_wrapper_test.rb
|
410
408
|
- test/unit/extras/file_common_test.rb
|
411
409
|
- test/unit/extras/linux_file_test.rb
|
@@ -422,3 +420,5 @@ test_files:
|
|
422
420
|
- test/unit/transports/mock_test.rb
|
423
421
|
- test/unit/transports/ssh_test.rb
|
424
422
|
- test/unit/version_test.rb
|
423
|
+
- test/windows/local_test.rb
|
424
|
+
- test/windows/winrm_test.rb
|
data/test/tools/os.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# encoding: utf-8
|
3
|
-
|
4
|
-
require 'train'
|
5
|
-
|
6
|
-
train = Train.create('local')
|
7
|
-
|
8
|
-
# start or reuse a connection
|
9
|
-
conn = train.connection
|
10
|
-
os = conn.os
|
11
|
-
|
12
|
-
# get OS info
|
13
|
-
conf = {
|
14
|
-
name: os[:name],
|
15
|
-
family: os[:family],
|
16
|
-
release: os[:release],
|
17
|
-
arch: os[:arch],
|
18
|
-
}
|
19
|
-
puts JSON.dump(conf)
|
20
|
-
|
21
|
-
# close the connection
|
22
|
-
conn.close
|