train 1.4.22 → 1.4.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -7
- data/lib/train/file/local.rb +5 -0
- data/lib/train/file/remote/aix.rb +6 -0
- data/lib/train/file/remote/unix.rb +5 -0
- data/lib/train/file/remote/windows.rb +4 -0
- data/lib/train/transports/ssh_connection.rb +20 -1
- data/lib/train/version.rb +1 -1
- data/test/unit/file/local_test.rb +16 -5
- data/test/unit/file/remote/aix_test.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ecda8bbe5e6b070ad719dbdaa0fd84f7711951331006dca61073f7c466ecf62
|
4
|
+
data.tar.gz: 0c3bf400d8f4feb0c36b5cc0ef1b51b50ed61e2a75a7725197c510652958c0fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d0108b3647bedda9f7b1d7c85ef5ebbd40498b23ea17a6c625b978262328cdb76db8ee3d5e38409d743f95a34bb6f78b6fb5dc22da5eb325a2bb75bc1b5db81
|
7
|
+
data.tar.gz: aadc074f3ce261c4b9d410691e8d6e6e2203ac83ddd297107c2852a24f017800f9465b8b9e9e5eb59aeadefc9270c546a5b95a3c128177630c7c92f3abee9cbc
|
data/CHANGELOG.md
CHANGED
@@ -1,24 +1,30 @@
|
|
1
|
-
<!-- latest_release 1.4.
|
2
|
-
## [v1.4.
|
1
|
+
<!-- latest_release 1.4.24 -->
|
2
|
+
## [v1.4.24](https://github.com/inspec/train/tree/v1.4.24) (2018-07-26)
|
3
3
|
|
4
4
|
#### Merged Pull Requests
|
5
|
-
-
|
5
|
+
- Retry SSH command on IOError (Cisco IOS specific) [#326](https://github.com/inspec/train/pull/326) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
|
6
6
|
<!-- latest_release -->
|
7
7
|
|
8
|
-
<!-- release_rollup since=1.4.
|
9
|
-
### Changes since 1.4.
|
8
|
+
<!-- release_rollup since=1.4.22 -->
|
9
|
+
### Changes since 1.4.22 release
|
10
10
|
|
11
11
|
#### Merged Pull Requests
|
12
|
-
-
|
12
|
+
- Retry SSH command on IOError (Cisco IOS specific) [#326](https://github.com/inspec/train/pull/326) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.4.24 -->
|
13
|
+
- Add shallow_link_path to inspect symlink direct link [#309](https://github.com/inspec/train/pull/309) ([ColinHebert](https://github.com/ColinHebert)) <!-- 1.4.23 -->
|
13
14
|
<!-- release_rollup -->
|
14
15
|
|
15
16
|
<!-- latest_stable_release -->
|
17
|
+
## [v1.4.22](https://github.com/inspec/train/tree/v1.4.22) (2018-07-16)
|
18
|
+
|
19
|
+
#### Merged Pull Requests
|
20
|
+
- Add VMware transport [#321](https://github.com/inspec/train/pull/321) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
|
21
|
+
<!-- latest_stable_release -->
|
22
|
+
|
16
23
|
## [v1.4.21](https://github.com/inspec/train/tree/v1.4.21) (2018-07-05)
|
17
24
|
|
18
25
|
#### Merged Pull Requests
|
19
26
|
- Remove the delivery cookbook [#317](https://github.com/inspec/train/pull/317) ([tas50](https://github.com/tas50))
|
20
27
|
- Modify `WindowsPipeRunner` stderr to use String [#320](https://github.com/inspec/train/pull/320) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
|
21
|
-
<!-- latest_stable_release -->
|
22
28
|
|
23
29
|
## [v1.4.19](https://github.com/inspec/train/tree/v1.4.19) (2018-06-29)
|
24
30
|
|
data/lib/train/file/local.rb
CHANGED
@@ -12,6 +12,12 @@ module Train
|
|
12
12
|
@backend.run_command("perl -e 'print readlink shift' #{@spath}").stdout.chomp
|
13
13
|
end
|
14
14
|
|
15
|
+
def shallow_link_path
|
16
|
+
return nil unless symlink?
|
17
|
+
@shallow_link_path ||=
|
18
|
+
@backend.run_command("perl -e 'print readlink shift' #{@spath}").stdout.chomp
|
19
|
+
end
|
20
|
+
|
15
21
|
def mounted
|
16
22
|
@mounted ||= @backend.run_command("lsfs -c #{@spath}")
|
17
23
|
end
|
@@ -60,6 +60,11 @@ module Train
|
|
60
60
|
symlink? ? path : nil
|
61
61
|
end
|
62
62
|
|
63
|
+
def shallow_link_path
|
64
|
+
return nil unless symlink?
|
65
|
+
@shallow_link_path ||= ::File.readlink(@path)
|
66
|
+
end
|
67
|
+
|
63
68
|
def unix_mode_mask(owner, type)
|
64
69
|
o = UNIX_MODE_OWNERS[owner.to_sym]
|
65
70
|
return nil if o.nil?
|
@@ -32,6 +32,9 @@ class Train::Transports::SSH
|
|
32
32
|
class Connection < BaseConnection # rubocop:disable Metrics/ClassLength
|
33
33
|
attr_reader :hostname
|
34
34
|
def initialize(options)
|
35
|
+
# Track IOS command retries to prevent infinite loop on IOError. This must
|
36
|
+
# be done before `super()` because the parent runs detection commands.
|
37
|
+
@ios_cmd_retries = 0
|
35
38
|
super(options)
|
36
39
|
@username = @options.delete(:username)
|
37
40
|
@hostname = @options.delete(:hostname)
|
@@ -203,7 +206,7 @@ class Train::Transports::SSH
|
|
203
206
|
end
|
204
207
|
end
|
205
208
|
|
206
|
-
def run_command_via_connection(cmd)
|
209
|
+
def run_command_via_connection(cmd) # rubocop:disable AbcSize
|
207
210
|
stdout = stderr = ''
|
208
211
|
exit_status = nil
|
209
212
|
cmd.dup.force_encoding('binary') if cmd.respond_to?(:force_encoding)
|
@@ -242,9 +245,25 @@ class Train::Transports::SSH
|
|
242
245
|
end
|
243
246
|
@session.loop
|
244
247
|
|
248
|
+
# Since `@session.loop` succeeded, reset the IOS command retry counter
|
249
|
+
@ios_cmd_retries = 0
|
250
|
+
|
245
251
|
CommandResult.new(stdout, stderr, exit_status)
|
246
252
|
rescue Net::SSH::Exception => ex
|
247
253
|
raise Train::Transports::SSHFailed, "SSH command failed (#{ex.message})"
|
254
|
+
rescue IOError
|
255
|
+
# Cisco IOS occasionally closes the stream prematurely while we are
|
256
|
+
# running commands to detect if we need to switch to the Cisco IOS
|
257
|
+
# transport. This retries the command if this is the case.
|
258
|
+
# See:
|
259
|
+
# https://github.com/inspec/train/pull/271
|
260
|
+
logger.debug('[SSH] Possible Cisco IOS race condition, retrying command')
|
261
|
+
|
262
|
+
# Only attempt retry up to 5 times to avoid infinite loop
|
263
|
+
@ios_cmd_retries += 1
|
264
|
+
raise if @ios_cmd_retries >= 5
|
265
|
+
|
266
|
+
retry
|
248
267
|
end
|
249
268
|
|
250
269
|
# Returns a connection session, or establishes one when invoked the
|
data/lib/train/version.rb
CHANGED
@@ -10,7 +10,7 @@ describe Train::File::Local do
|
|
10
10
|
File.stub :read, res do
|
11
11
|
connection.file(rand.to_s).content.must_equal(res)
|
12
12
|
end
|
13
|
-
end
|
13
|
+
end
|
14
14
|
|
15
15
|
{
|
16
16
|
exist?: :exist?,
|
@@ -33,13 +33,13 @@ describe Train::File::Local do
|
|
33
33
|
it 'returns the type block_device if it is block device' do
|
34
34
|
File.stub :ftype, "blockSpecial" do
|
35
35
|
connection.file(rand.to_s).type.must_equal :block_device
|
36
|
-
end
|
36
|
+
end
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'returns the type character_device if it is character device' do
|
40
40
|
File.stub :ftype, "characterSpecial" do
|
41
41
|
connection.file(rand.to_s).type.must_equal :character_device
|
42
|
-
end
|
42
|
+
end
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'returns the type symlink if it is symlink' do
|
@@ -77,7 +77,7 @@ describe Train::File::Local do
|
|
77
77
|
connection.file(rand.to_s).type.must_equal :unknown
|
78
78
|
end
|
79
79
|
end
|
80
|
-
end
|
80
|
+
end
|
81
81
|
|
82
82
|
describe '#path' do
|
83
83
|
it 'returns the path if it is not a symlink' do
|
@@ -107,4 +107,15 @@ describe Train::File::Local do
|
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
|
+
describe '#shallow_shlink_path' do
|
112
|
+
it 'returns file\'s direct link path' do
|
113
|
+
out = rand.to_s
|
114
|
+
File.stub :readlink, out do
|
115
|
+
File.stub :symlink?, true do
|
116
|
+
connection.file(rand.to_s).shallow_link_path.must_equal out
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -23,4 +23,11 @@ describe Train::File::Remote::Aix do
|
|
23
23
|
backend.mock_command("perl -e 'print readlink shift' path", 'our_link_path')
|
24
24
|
file.link_path.must_equal 'our_link_path'
|
25
25
|
end
|
26
|
+
|
27
|
+
it 'returns a correct shallow_link_path' do
|
28
|
+
file = cls.new(backend, 'path')
|
29
|
+
file.stubs(:symlink?).returns(true)
|
30
|
+
backend.mock_command("perl -e 'print readlink shift' path", 'our_link_path')
|
31
|
+
file.link_path.must_equal 'our_link_path'
|
32
|
+
end
|
26
33
|
end
|
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: 1.4.
|
4
|
+
version: 1.4.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|