r-train 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +45 -0
  4. data/.travis.yml +12 -0
  5. data/Gemfile +22 -0
  6. data/LICENSE +201 -0
  7. data/README.md +137 -0
  8. data/Rakefile +39 -0
  9. data/lib/train.rb +100 -0
  10. data/lib/train/errors.rb +23 -0
  11. data/lib/train/extras.rb +15 -0
  12. data/lib/train/extras/command_wrapper.rb +105 -0
  13. data/lib/train/extras/file_common.rb +131 -0
  14. data/lib/train/extras/linux_file.rb +74 -0
  15. data/lib/train/extras/linux_lsb.rb +60 -0
  16. data/lib/train/extras/os_common.rb +131 -0
  17. data/lib/train/extras/os_detect_darwin.rb +32 -0
  18. data/lib/train/extras/os_detect_linux.rb +126 -0
  19. data/lib/train/extras/os_detect_unix.rb +77 -0
  20. data/lib/train/extras/os_detect_windows.rb +73 -0
  21. data/lib/train/extras/stat.rb +92 -0
  22. data/lib/train/extras/windows_file.rb +85 -0
  23. data/lib/train/options.rb +80 -0
  24. data/lib/train/plugins.rb +40 -0
  25. data/lib/train/plugins/base_connection.rb +86 -0
  26. data/lib/train/plugins/transport.rb +49 -0
  27. data/lib/train/transports/docker.rb +102 -0
  28. data/lib/train/transports/local.rb +52 -0
  29. data/lib/train/transports/local_file.rb +77 -0
  30. data/lib/train/transports/local_os.rb +51 -0
  31. data/lib/train/transports/mock.rb +125 -0
  32. data/lib/train/transports/ssh.rb +163 -0
  33. data/lib/train/transports/ssh_connection.rb +216 -0
  34. data/lib/train/transports/winrm.rb +187 -0
  35. data/lib/train/transports/winrm_connection.rb +258 -0
  36. data/lib/train/version.rb +7 -0
  37. data/test/integration/.kitchen.yml +43 -0
  38. data/test/integration/Berksfile +3 -0
  39. data/test/integration/bootstrap.sh +17 -0
  40. data/test/integration/chefignore +1 -0
  41. data/test/integration/cookbooks/test/metadata.rb +1 -0
  42. data/test/integration/cookbooks/test/recipes/default.rb +101 -0
  43. data/test/integration/docker_run.rb +153 -0
  44. data/test/integration/docker_test.rb +24 -0
  45. data/test/integration/docker_test_container.rb +24 -0
  46. data/test/integration/helper.rb +58 -0
  47. data/test/integration/sudo/nopasswd.rb +16 -0
  48. data/test/integration/sudo/passwd.rb +21 -0
  49. data/test/integration/sudo/run_as.rb +12 -0
  50. data/test/integration/test-runner.yaml +24 -0
  51. data/test/integration/test_local.rb +19 -0
  52. data/test/integration/test_ssh.rb +24 -0
  53. data/test/integration/tests/path_block_device_test.rb +74 -0
  54. data/test/integration/tests/path_character_device_test.rb +74 -0
  55. data/test/integration/tests/path_file_test.rb +79 -0
  56. data/test/integration/tests/path_folder_test.rb +88 -0
  57. data/test/integration/tests/path_missing_test.rb +77 -0
  58. data/test/integration/tests/path_pipe_test.rb +78 -0
  59. data/test/integration/tests/path_symlink_test.rb +83 -0
  60. data/test/integration/tests/run_command_test.rb +28 -0
  61. data/test/unit/extras/command_wrapper_test.rb +41 -0
  62. data/test/unit/extras/file_common_test.rb +133 -0
  63. data/test/unit/extras/linux_file_test.rb +98 -0
  64. data/test/unit/extras/os_common_test.rb +258 -0
  65. data/test/unit/extras/stat_test.rb +105 -0
  66. data/test/unit/helper.rb +6 -0
  67. data/test/unit/plugins/connection_test.rb +44 -0
  68. data/test/unit/plugins/transport_test.rb +111 -0
  69. data/test/unit/plugins_test.rb +22 -0
  70. data/test/unit/train_test.rb +132 -0
  71. data/test/unit/transports/local_file_test.rb +112 -0
  72. data/test/unit/transports/local_test.rb +73 -0
  73. data/test/unit/transports/mock_test.rb +76 -0
  74. data/test/unit/transports/ssh_test.rb +95 -0
  75. data/test/unit/version_test.rb +8 -0
  76. data/train.gemspec +32 -0
  77. metadata +299 -0
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+ require 'train/transports/mock'
4
+ require 'digest/sha2'
5
+
6
+ describe 'mock transport' do
7
+ let(:transport) { Train::Transports::Mock.new }
8
+ let(:connection) { transport.connection }
9
+
10
+ it 'can be instantiated' do
11
+ transport.wont_be_nil
12
+ end
13
+
14
+ it 'can create a connection' do
15
+ connection.wont_be_nil
16
+ end
17
+
18
+ describe 'when running a mocked command' do
19
+ let(:mock_cmd) { }
20
+
21
+ it 'has a simple mock command creator' do
22
+ out = rand
23
+ cls = Train::Transports::Mock::Connection::Command
24
+ res = cls.new(out, '', 0)
25
+ connection.mock_command('test', out).must_equal res
26
+ end
27
+
28
+ it 'gets results for stdout' do
29
+ out = rand
30
+ cmd = rand
31
+ connection.mock_command(cmd, out)
32
+ connection.run_command(cmd).stdout.must_equal(out)
33
+ end
34
+
35
+ it 'gets results for stderr' do
36
+ err = rand
37
+ cmd = rand
38
+ connection.mock_command(cmd, nil, err)
39
+ connection.run_command(cmd).stderr.must_equal(err)
40
+ end
41
+
42
+ it 'gets results for exit_status' do
43
+ code = rand
44
+ cmd = rand
45
+ connection.mock_command(cmd, nil, nil, code)
46
+ connection.run_command(cmd).exit_status.must_equal(code)
47
+ end
48
+
49
+ it 'can mock a command via its SHA2 sum' do
50
+ out = rand.to_s
51
+ cmd = rand.to_s
52
+ shacmd = Digest::SHA256.hexdigest cmd
53
+ connection.mock_command(shacmd, out)
54
+ connection.run_command(cmd).stdout.must_equal(out)
55
+ end
56
+ end
57
+
58
+ describe 'when accessing a mocked os' do
59
+ it 'has the default mock os faily set to unknown' do
60
+ connection.os[:family].must_equal 'unknown'
61
+ end
62
+
63
+ it 'sets the OS to the mocked value' do
64
+ connection.mock_os({ family: 'centos' })
65
+ connection.os.linux?.must_equal true
66
+ connection.os.redhat?.must_equal true
67
+ connection.os[:family].must_equal 'centos'
68
+ end
69
+ end
70
+
71
+ describe 'when accessing a mocked file' do
72
+ it 'gets results for content' do
73
+
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,95 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+ require 'train/transports/ssh'
4
+
5
+ describe 'ssh transport' do
6
+ let(:cls) { Train::Transports::SSH }
7
+ let(:conf) {{
8
+ host: rand.to_s,
9
+ password: rand.to_s,
10
+ key_files: rand.to_s,
11
+ }}
12
+
13
+ describe 'default options' do
14
+ let(:ssh) { cls.new({ host: 'dummy' }) }
15
+
16
+ it 'can be instantiated (with valid config)' do
17
+ ssh.wont_be_nil
18
+ end
19
+
20
+ it 'configures the host' do
21
+ ssh.options[:host].must_equal 'dummy'
22
+ end
23
+
24
+ it 'has default port' do
25
+ ssh.options[:port].must_equal 22
26
+ end
27
+
28
+ it 'has default user' do
29
+ ssh.options[:user].must_equal 'root'
30
+ end
31
+ end
32
+
33
+ describe 'opening a connection' do
34
+ let(:ssh) { cls.new(conf) }
35
+ let(:connection) { ssh.connection }
36
+
37
+ it 'gets the connection' do
38
+ connection.must_be_kind_of Train::Transports::SSH::Connection
39
+ end
40
+
41
+ it 'must respond to wait_until_ready' do
42
+ connection.must_respond_to :wait_until_ready
43
+ end
44
+
45
+ it 'can be closed' do
46
+ connection.close.must_be_nil
47
+ end
48
+
49
+ it 'has a login command == ssh' do
50
+ connection.login_command.command.must_equal 'ssh'
51
+ end
52
+
53
+ it 'has login command arguments' do
54
+ connection.login_command.arguments.must_equal([
55
+ "-o", "UserKnownHostsFile=/dev/null",
56
+ "-o", "StrictHostKeyChecking=no",
57
+ "-o", "IdentitiesOnly=yes",
58
+ "-o", "LogLevel=VERBOSE",
59
+ "-o", "ForwardAgent=no",
60
+ "-i", conf[:key_files],
61
+ "-p", "22",
62
+ "root@#{conf[:host]}",
63
+ ])
64
+ end
65
+ end
66
+
67
+ describe 'failed configuration' do
68
+ it 'works with a minimum valid config' do
69
+ cls.new(conf).connection
70
+ end
71
+
72
+ it 'doesnt like host == nil' do
73
+ conf.delete(:host)
74
+ proc { cls.new(conf).connection }.must_raise Train::ClientError
75
+ end
76
+
77
+ it 'reverts to root on user == nil' do
78
+ conf[:user] = nil
79
+ cls.new(conf).connection.method(:options).call[:user] == 'root'
80
+ end
81
+
82
+ it 'doesnt like key and password == nil' do
83
+ conf.delete(:password)
84
+ conf.delete(:key_files)
85
+ proc { cls.new(conf).connection }.must_raise Train::ClientError
86
+ end
87
+
88
+ it 'wont connect if its not possible' do
89
+ conf[:host] = 'localhost'
90
+ conf[:port] = 1
91
+ conn = cls.new(conf).connection
92
+ proc { conn.run_command('uname') }.must_raise Train::Transports::SSHFailed
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ require 'helper'
3
+
4
+ describe Train do
5
+ it 'defines a version' do
6
+ Train::VERSION.must_be_instance_of String
7
+ end
8
+ end
data/train.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'train/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'r-train'
8
+ spec.version = Train::VERSION
9
+ spec.authors = ['Dominik Richter']
10
+ spec.email = ['dominik.richter@gmail.com']
11
+ spec.summary = 'Transport interface to talk to different backends.'
12
+ spec.description = 'Transport interface to talk to different backends.'
13
+ spec.homepage = 'https://github.com/chef/train/'
14
+ spec.license = 'Apache 2.0'
15
+
16
+ spec.files = `hash git 2>/dev/null && git ls-files -z`.split("\x0").find_all { |x| x !~ /^\.delivery/ }
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'json', '~> 1.8'
22
+ spec.add_dependency 'mixlib-shellout', '~> 2.1'
23
+ spec.add_dependency 'net-ssh', '~> 2.9'
24
+ spec.add_dependency 'net-scp', '~> 1.2'
25
+ spec.add_dependency 'winrm', '~> 1.3'
26
+ spec.add_dependency 'winrm-transport', '~> 1.0'
27
+ spec.add_dependency 'docker-api', '~> 1.22'
28
+
29
+ spec.add_development_dependency 'rake', '~> 10.4'
30
+ spec.add_development_dependency 'minitest', '~> 5.8'
31
+ spec.add_development_dependency 'rubocop', '~> 0.34'
32
+ end
metadata ADDED
@@ -0,0 +1,299 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r-train
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.1
5
+ platform: ruby
6
+ authors:
7
+ - Dominik Richter
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mixlib-shellout
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: net-ssh
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.9'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: net-scp
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: winrm
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: winrm-transport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: docker-api
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.22'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.22'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: minitest
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '5.8'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '5.8'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.34'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.34'
153
+ description: Transport interface to talk to different backends.
154
+ email:
155
+ - dominik.richter@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rubocop.yml"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE
165
+ - README.md
166
+ - Rakefile
167
+ - lib/train.rb
168
+ - lib/train/errors.rb
169
+ - lib/train/extras.rb
170
+ - lib/train/extras/command_wrapper.rb
171
+ - lib/train/extras/file_common.rb
172
+ - lib/train/extras/linux_file.rb
173
+ - lib/train/extras/linux_lsb.rb
174
+ - lib/train/extras/os_common.rb
175
+ - lib/train/extras/os_detect_darwin.rb
176
+ - lib/train/extras/os_detect_linux.rb
177
+ - lib/train/extras/os_detect_unix.rb
178
+ - lib/train/extras/os_detect_windows.rb
179
+ - lib/train/extras/stat.rb
180
+ - lib/train/extras/windows_file.rb
181
+ - lib/train/options.rb
182
+ - lib/train/plugins.rb
183
+ - lib/train/plugins/base_connection.rb
184
+ - lib/train/plugins/transport.rb
185
+ - lib/train/transports/docker.rb
186
+ - lib/train/transports/local.rb
187
+ - lib/train/transports/local_file.rb
188
+ - lib/train/transports/local_os.rb
189
+ - lib/train/transports/mock.rb
190
+ - lib/train/transports/ssh.rb
191
+ - lib/train/transports/ssh_connection.rb
192
+ - lib/train/transports/winrm.rb
193
+ - lib/train/transports/winrm_connection.rb
194
+ - lib/train/version.rb
195
+ - test/integration/.kitchen.yml
196
+ - test/integration/Berksfile
197
+ - test/integration/bootstrap.sh
198
+ - test/integration/chefignore
199
+ - test/integration/cookbooks/test/metadata.rb
200
+ - test/integration/cookbooks/test/recipes/default.rb
201
+ - test/integration/docker_run.rb
202
+ - test/integration/docker_test.rb
203
+ - test/integration/docker_test_container.rb
204
+ - test/integration/helper.rb
205
+ - test/integration/sudo/nopasswd.rb
206
+ - test/integration/sudo/passwd.rb
207
+ - test/integration/sudo/run_as.rb
208
+ - test/integration/test-runner.yaml
209
+ - test/integration/test_local.rb
210
+ - test/integration/test_ssh.rb
211
+ - test/integration/tests/path_block_device_test.rb
212
+ - test/integration/tests/path_character_device_test.rb
213
+ - test/integration/tests/path_file_test.rb
214
+ - test/integration/tests/path_folder_test.rb
215
+ - test/integration/tests/path_missing_test.rb
216
+ - test/integration/tests/path_pipe_test.rb
217
+ - test/integration/tests/path_symlink_test.rb
218
+ - test/integration/tests/run_command_test.rb
219
+ - test/unit/extras/command_wrapper_test.rb
220
+ - test/unit/extras/file_common_test.rb
221
+ - test/unit/extras/linux_file_test.rb
222
+ - test/unit/extras/os_common_test.rb
223
+ - test/unit/extras/stat_test.rb
224
+ - test/unit/helper.rb
225
+ - test/unit/plugins/connection_test.rb
226
+ - test/unit/plugins/transport_test.rb
227
+ - test/unit/plugins_test.rb
228
+ - test/unit/train_test.rb
229
+ - test/unit/transports/local_file_test.rb
230
+ - test/unit/transports/local_test.rb
231
+ - test/unit/transports/mock_test.rb
232
+ - test/unit/transports/ssh_test.rb
233
+ - test/unit/version_test.rb
234
+ - train.gemspec
235
+ homepage: https://github.com/chef/train/
236
+ licenses:
237
+ - Apache 2.0
238
+ metadata: {}
239
+ post_install_message:
240
+ rdoc_options: []
241
+ require_paths:
242
+ - lib
243
+ required_ruby_version: !ruby/object:Gem::Requirement
244
+ requirements:
245
+ - - ">="
246
+ - !ruby/object:Gem::Version
247
+ version: '0'
248
+ required_rubygems_version: !ruby/object:Gem::Requirement
249
+ requirements:
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ version: '0'
253
+ requirements: []
254
+ rubyforge_project:
255
+ rubygems_version: 2.4.5.1
256
+ signing_key:
257
+ specification_version: 4
258
+ summary: Transport interface to talk to different backends.
259
+ test_files:
260
+ - test/integration/.kitchen.yml
261
+ - test/integration/Berksfile
262
+ - test/integration/bootstrap.sh
263
+ - test/integration/chefignore
264
+ - test/integration/cookbooks/test/metadata.rb
265
+ - test/integration/cookbooks/test/recipes/default.rb
266
+ - test/integration/docker_run.rb
267
+ - test/integration/docker_test.rb
268
+ - test/integration/docker_test_container.rb
269
+ - test/integration/helper.rb
270
+ - test/integration/sudo/nopasswd.rb
271
+ - test/integration/sudo/passwd.rb
272
+ - test/integration/sudo/run_as.rb
273
+ - test/integration/test-runner.yaml
274
+ - test/integration/test_local.rb
275
+ - test/integration/test_ssh.rb
276
+ - test/integration/tests/path_block_device_test.rb
277
+ - test/integration/tests/path_character_device_test.rb
278
+ - test/integration/tests/path_file_test.rb
279
+ - test/integration/tests/path_folder_test.rb
280
+ - test/integration/tests/path_missing_test.rb
281
+ - test/integration/tests/path_pipe_test.rb
282
+ - test/integration/tests/path_symlink_test.rb
283
+ - test/integration/tests/run_command_test.rb
284
+ - test/unit/extras/command_wrapper_test.rb
285
+ - test/unit/extras/file_common_test.rb
286
+ - test/unit/extras/linux_file_test.rb
287
+ - test/unit/extras/os_common_test.rb
288
+ - test/unit/extras/stat_test.rb
289
+ - test/unit/helper.rb
290
+ - test/unit/plugins/connection_test.rb
291
+ - test/unit/plugins/transport_test.rb
292
+ - test/unit/plugins_test.rb
293
+ - test/unit/train_test.rb
294
+ - test/unit/transports/local_file_test.rb
295
+ - test/unit/transports/local_test.rb
296
+ - test/unit/transports/mock_test.rb
297
+ - test/unit/transports/ssh_test.rb
298
+ - test/unit/version_test.rb
299
+ has_rdoc: