train 0.31.0 → 0.31.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfe0c95ba3361d579100ba1b832fb9f01f584267
4
- data.tar.gz: d8449a2875c73e05e5e1f188eb530e25d184a89e
3
+ metadata.gz: 45cc6cfd826d49507368b99a990fed0eeba925af
4
+ data.tar.gz: b1dd4839b1a46ac0c246cdd0d7a00e8adda03150
5
5
  SHA512:
6
- metadata.gz: b1239cd1ece638eb4273037034fe1ba7e3c1c864674f53d89f7a7dfdf6f4683eaf54445b5ff92ab1b2e482fbb5743143365111f516bcd1f4f0f3ae4e6f150a0b
7
- data.tar.gz: 9c6d7296f8396a5dbac8323ef29eeb247af3c2cf4cd285ee44dafddaf7e515af921d7288360381ebfb3ac5bcca9edee08663efd0ea570353d6fa1562840bed94
6
+ metadata.gz: ab1770e2b5e06c10cc21dfb327c934acc4b9a2a38f8a016584e426a0d1da27b4cfcf794da4777bda6c51d251092848b538de98236b03d55d30dce0cfdd9b53e9
7
+ data.tar.gz: 3c98eba3d01ab9f934e613a4d9ce6bd566f7a97fefa38b4e7986f1894e1e8428ac52807e3c9ace7dfe1cf2cacb0364eb3fda9735676ac1aa8d6a8a0040d92cb5
data/CHANGELOG.md CHANGED
@@ -1,7 +1,14 @@
1
1
  # Change Log
2
2
 
3
- ## [0.31.0](https://github.com/chef/train/tree/0.31.0) (2017-12-05)
4
- [Full Changelog](https://github.com/chef/train/compare/v0.30.0...0.31.0)
3
+ ## [0.31.1](https://github.com/chef/train/tree/0.31.1) (2017-12-06)
4
+ [Full Changelog](https://github.com/chef/train/compare/v0.31.0...0.31.1)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - Allow runner specifications for local connections [\#225](https://github.com/chef/train/pull/225) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
9
+
10
+ ## [v0.31.0](https://github.com/chef/train/tree/v0.31.0) (2017-12-05)
11
+ [Full Changelog](https://github.com/chef/train/compare/v0.30.0...v0.31.0)
5
12
 
6
13
  **Fixed bugs:**
7
14
 
@@ -9,6 +16,7 @@
9
16
 
10
17
  **Merged pull requests:**
11
18
 
19
+ - Release 0.31.0 [\#224](https://github.com/chef/train/pull/224) ([adamleff](https://github.com/adamleff))
12
20
  - Use named pipe to decrease local Windows runtime [\#220](https://github.com/chef/train/pull/220) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
13
21
 
14
22
  ## [v0.30.0](https://github.com/chef/train/tree/v0.30.0) (2017-12-04)
@@ -10,8 +10,6 @@ module Train::Transports
10
10
  class Local < Train.plugin(1)
11
11
  name 'local'
12
12
 
13
- include_options Train::Extras::CommandWrapper
14
-
15
13
  class PipeError < ::StandardError; end
16
14
 
17
15
  def connection(_ = nil)
@@ -22,18 +20,11 @@ module Train::Transports
22
20
  def initialize(options)
23
21
  super(options)
24
22
 
25
- # While OS is being discovered, use the GenericRunner
26
- @runner = GenericRunner.new
27
- @runner.cmd_wrapper = CommandWrapper.load(self, options)
28
-
29
- if os.windows?
30
- # Attempt to use a named pipe but fallback to ShellOut if that fails
31
- begin
32
- @runner = WindowsPipeRunner.new
33
- rescue PipeError
34
- @runner = WindowsShellRunner.new
35
- end
36
- end
23
+ @runner = if options[:command_runner]
24
+ force_runner(options[:command_runner])
25
+ else
26
+ select_runner(options)
27
+ end
37
28
  end
38
29
 
39
30
  def local?
@@ -50,8 +41,42 @@ module Train::Transports
50
41
 
51
42
  private
52
43
 
44
+ def select_runner(options)
45
+ if os.windows?
46
+ # Attempt to use a named pipe but fallback to ShellOut if that fails
47
+ begin
48
+ WindowsPipeRunner.new
49
+ rescue PipeError
50
+ WindowsShellRunner.new
51
+ end
52
+ else
53
+ GenericRunner.new(self, options)
54
+ end
55
+ end
56
+
57
+ def force_runner(command_runner)
58
+ case command_runner
59
+ when :generic
60
+ GenericRunner.new(self, options)
61
+ when :windows_pipe
62
+ WindowsPipeRunner.new
63
+ when :windows_shell
64
+ WindowsShellRunner.new
65
+ else
66
+ fail "Runner type `#{command_runner}` not supported"
67
+ end
68
+ end
69
+
53
70
  def run_command_via_connection(cmd)
54
- @runner.run_command(cmd)
71
+ # Use the runner if it is available
72
+ return @runner.run_command(cmd) if defined?(@runner)
73
+
74
+ # If we don't have a runner, such as at the beginning of setting up the
75
+ # transport and performing the first few steps of OS detection, fall
76
+ # back to shelling out.
77
+ res = Mixlib::ShellOut.new(cmd)
78
+ res.run_command
79
+ Local::CommandResult.new(res.stdout, res.stderr, res.exitstatus)
55
80
  rescue Errno::ENOENT => _
56
81
  CommandResult.new('', '', 1)
57
82
  end
@@ -65,7 +90,11 @@ module Train::Transports
65
90
  end
66
91
 
67
92
  class GenericRunner
68
- attr_writer :cmd_wrapper
93
+ include_options Train::Extras::CommandWrapper
94
+
95
+ def initialize(connection, options)
96
+ @cmd_wrapper = Local::CommandWrapper.load(connection, options)
97
+ end
69
98
 
70
99
  def run_command(cmd)
71
100
  if defined?(@cmd_wrapper) && !@cmd_wrapper.nil?
data/lib/train/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
4
 
5
5
  module Train
6
- VERSION = '0.31.0'.freeze
6
+ VERSION = '0.31.1'.freeze
7
7
  end
@@ -13,7 +13,7 @@ class TransportHelper
13
13
  plat.family_hierarchy = opts[:family_hierarchy]
14
14
  plat.add_platform_methods
15
15
  Train::Platforms::Detect.stubs(:scan).returns(plat)
16
- @transport = Train::Transports::Local.new
16
+ @transport = Train::Transports::Local.new(user_opts)
17
17
  end
18
18
  end
19
19
 
@@ -55,6 +55,58 @@ describe 'local transport' do
55
55
  methods.include?(:file_via_connection).must_equal true
56
56
  end
57
57
 
58
+ describe 'when overriding runner selection' do
59
+ it 'can select the `GenericRunner`' do
60
+ Train::Transports::Local::Connection::GenericRunner
61
+ .expects(:new)
62
+
63
+ Train::Transports::Local::Connection::WindowsPipeRunner
64
+ .expects(:new)
65
+ .never
66
+
67
+ Train::Transports::Local::Connection::WindowsShellRunner
68
+ .expects(:new)
69
+ .never
70
+
71
+ Train::Transports::Local::Connection.new(command_runner: :generic)
72
+ end
73
+
74
+ it 'can select the `WindowsPipeRunner`' do
75
+ Train::Transports::Local::Connection::GenericRunner
76
+ .expects(:new)
77
+ .never
78
+
79
+ Train::Transports::Local::Connection::WindowsPipeRunner
80
+ .expects(:new)
81
+
82
+ Train::Transports::Local::Connection::WindowsShellRunner
83
+ .expects(:new)
84
+ .never
85
+
86
+ Train::Transports::Local::Connection.new(command_runner: :windows_pipe)
87
+ end
88
+
89
+ it 'can select the `WindowsShellRunner`' do
90
+ Train::Transports::Local::Connection::GenericRunner
91
+ .expects(:new)
92
+ .never
93
+
94
+ Train::Transports::Local::Connection::WindowsPipeRunner
95
+ .expects(:new)
96
+ .never
97
+
98
+ Train::Transports::Local::Connection::WindowsShellRunner
99
+ .expects(:new)
100
+
101
+ Train::Transports::Local::Connection.new(command_runner: :windows_shell)
102
+ end
103
+
104
+ it 'throws a RuntimeError when an invalid runner type is passed' do
105
+ proc { Train::Transports::Local::Connection.new(command_runner: :nope ) }
106
+ .must_raise(RuntimeError, "Runner type `:nope` not supported")
107
+ end
108
+ end
109
+
58
110
  describe 'when running a local command' do
59
111
  let(:cmd_runner) { Minitest::Mock.new }
60
112
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 0.31.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-05 00:00:00.000000000 Z
11
+ date: 2017-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json