train 0.29.2 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -2
- data/lib/train.rb +1 -0
- data/lib/train/errors.rb +6 -0
- data/lib/train/extras.rb +0 -1
- data/lib/train/platforms.rb +82 -0
- data/lib/train/platforms/common.rb +34 -0
- data/lib/train/platforms/detect.rb +12 -0
- data/lib/train/platforms/detect/helpers/os_common.rb +56 -0
- data/lib/train/platforms/detect/helpers/os_linux.rb +75 -0
- data/lib/train/{extras/os_detect_windows.rb → platforms/detect/helpers/os_windows.rb} +3 -10
- data/lib/train/platforms/detect/scanner.rb +84 -0
- data/lib/train/platforms/detect/specifications/os.rb +480 -0
- data/lib/train/platforms/family.rb +26 -0
- data/lib/train/platforms/platform.rb +80 -0
- data/lib/train/plugins/base_connection.rb +75 -27
- data/lib/train/transports/docker.rb +17 -28
- data/lib/train/transports/local.rb +21 -22
- data/lib/train/transports/mock.rb +44 -30
- data/lib/train/transports/ssh_connection.rb +55 -67
- data/lib/train/transports/winrm_connection.rb +16 -26
- data/lib/train/version.rb +1 -1
- data/test/unit/file/remote/linux_test.rb +2 -2
- data/test/unit/platforms/detect/os_common_test.rb +85 -0
- data/test/unit/platforms/detect/os_linux_test.rb +124 -0
- data/test/unit/{extras/os_detect_windows_test.rb → platforms/detect/os_windows_test.rb} +5 -2
- data/test/unit/platforms/detect/scanner_test.rb +61 -0
- data/test/unit/platforms/family_test.rb +32 -0
- data/test/unit/platforms/os_detect_test.rb +175 -0
- data/test/unit/{extras/os_common_test.rb → platforms/platform_test.rb} +103 -18
- data/test/unit/platforms/platforms_test.rb +42 -0
- data/test/unit/plugins/connection_test.rb +106 -8
- data/test/unit/transports/local_test.rb +20 -15
- data/test/unit/transports/mock_test.rb +16 -6
- data/test/unit/transports/ssh_test.rb +17 -15
- metadata +28 -19
- data/lib/train/extras/linux_lsb.rb +0 -60
- data/lib/train/extras/os_common.rb +0 -151
- data/lib/train/extras/os_detect_arista_eos.rb +0 -34
- data/lib/train/extras/os_detect_darwin.rb +0 -40
- data/lib/train/extras/os_detect_esx.rb +0 -22
- data/lib/train/extras/os_detect_linux.rb +0 -164
- data/lib/train/extras/os_detect_openvms.rb +0 -29
- data/lib/train/extras/os_detect_unix.rb +0 -106
- data/lib/train/extras/uname.rb +0 -28
- data/lib/train/transports/local_os.rb +0 -51
- data/test/unit/extras/os_detect_linux_test.rb +0 -230
data/lib/train/extras/uname.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# author: Dominik Richter
|
3
|
-
# author: Christoph Hartmann
|
4
|
-
#
|
5
|
-
# This is heavily based on:
|
6
|
-
#
|
7
|
-
# OHAI https://github.com/chef/ohai
|
8
|
-
# by Adam Jacob, Chef Software Inc
|
9
|
-
#
|
10
|
-
module Train::Extras
|
11
|
-
module Uname
|
12
|
-
def uname_s
|
13
|
-
@uname_s ||= backend.run_command('uname -s').stdout
|
14
|
-
end
|
15
|
-
|
16
|
-
def uname_r
|
17
|
-
@uname_r ||= begin
|
18
|
-
res = backend.run_command('uname -r').stdout
|
19
|
-
res.strip! unless res.nil?
|
20
|
-
res
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def uname_m
|
25
|
-
@uname_m ||= backend.run_command('uname -m').stdout.chomp
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
# author: Dominik Richter
|
3
|
-
# author: Christoph Hartmann
|
4
|
-
#
|
5
|
-
# This is heavily based on:
|
6
|
-
#
|
7
|
-
# OHAI https://github.com/chef/ohai
|
8
|
-
# by Adam Jacob, Chef Software Inc
|
9
|
-
#
|
10
|
-
|
11
|
-
require 'rbconfig'
|
12
|
-
|
13
|
-
class Train::Transports::Local
|
14
|
-
class OS < OSCommon
|
15
|
-
def initialize(backend)
|
16
|
-
super(backend, { family: detect_local_os })
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def detect_local_os
|
22
|
-
case ::RbConfig::CONFIG['host_os']
|
23
|
-
when /aix(.+)$/
|
24
|
-
return 'aix'
|
25
|
-
when /darwin(.+)$/
|
26
|
-
return 'darwin'
|
27
|
-
when /hpux(.+)$/
|
28
|
-
return 'hpux'
|
29
|
-
when /linux/
|
30
|
-
return 'linux'
|
31
|
-
when /freebsd(.+)$/
|
32
|
-
return 'freebsd'
|
33
|
-
when /openbsd(.+)$/
|
34
|
-
return 'openbsd'
|
35
|
-
when /netbsd(.*)$/
|
36
|
-
return 'netbsd'
|
37
|
-
when /solaris2/
|
38
|
-
return 'solaris2'
|
39
|
-
when /mswin|mingw32|windows/
|
40
|
-
# After long discussion in IRC the "powers that be" have come to a consensus
|
41
|
-
# that no Windows platform exists that was not based on the
|
42
|
-
# Windows_NT kernel, so we herby decree that "windows" will refer to all
|
43
|
-
# platforms built upon the Windows_NT kernel and have access to win32 or win64
|
44
|
-
# subsystems.
|
45
|
-
return 'windows'
|
46
|
-
else
|
47
|
-
return ::RbConfig::CONFIG['host_os']
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,230 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'helper'
|
3
|
-
require 'train/extras'
|
4
|
-
|
5
|
-
class OsDetectLinuxTester
|
6
|
-
attr_reader :platform
|
7
|
-
include Train::Extras::DetectLinux
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@platform = {}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'os_detect_linux' do
|
15
|
-
let(:detector) { OsDetectLinuxTester.new }
|
16
|
-
|
17
|
-
describe '#detect_linux_arch' do
|
18
|
-
it "sets the arch using uname" do
|
19
|
-
be = mock("Backend")
|
20
|
-
detector.stubs(:backend).returns(be)
|
21
|
-
be.stubs(:run_command).with("uname -m").returns(mock("Output", stdout: "x86_64\n"))
|
22
|
-
detector.detect_linux_arch
|
23
|
-
detector.platform[:arch].must_equal("x86_64")
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#detect_linux_via_config' do
|
28
|
-
|
29
|
-
before do
|
30
|
-
detector.stubs(:get_config)
|
31
|
-
detector.stubs(:fetch_os_release)
|
32
|
-
detector.stubs(:redhatish_version).returns('redhat-version')
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '/etc/enterprise-release' do
|
36
|
-
it 'sets the correct family/release for oracle' do
|
37
|
-
detector.stubs(:get_config).with('/etc/enterprise-release').returns('data')
|
38
|
-
|
39
|
-
detector.detect_linux_via_config.must_equal(true)
|
40
|
-
detector.platform[:name].must_equal('oracle')
|
41
|
-
detector.platform[:family].must_equal('redhat')
|
42
|
-
detector.platform[:release].must_equal('redhat-version')
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "/etc/redhat-release" do
|
47
|
-
describe "and /etc/os-release" do
|
48
|
-
it "sets the correct family, name, and release on centos" do
|
49
|
-
detector.stubs(:get_config).with("/etc/redhat-release").returns("CentOS Linux release 7.2.1511 (Core) \n")
|
50
|
-
detector.stubs(:get_config).with("/etc/os-release").returns("NAME=\"CentOS Linux\"\nVERSION=\"7 (Core)\"\nID=\"centos\"\nID_LIKE=\"rhel fedora\"\n")
|
51
|
-
detector.detect_linux_via_config.must_equal(true)
|
52
|
-
detector.platform[:name].must_equal('centos')
|
53
|
-
detector.platform[:family].must_equal('redhat')
|
54
|
-
detector.platform[:release].must_equal('redhat-version')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '/etc/debian_version' do
|
60
|
-
|
61
|
-
before { detector.stubs(:get_config).with('/etc/debian_version').returns('deb-version') }
|
62
|
-
|
63
|
-
describe 'ubuntu' do
|
64
|
-
it 'sets the correct family/release for ubuntu' do
|
65
|
-
detector.stubs(:lsb).returns({ id: 'ubuntu', release: 'ubuntu-release' })
|
66
|
-
|
67
|
-
detector.detect_linux_via_config.must_equal(true)
|
68
|
-
detector.platform[:name].must_equal('ubuntu')
|
69
|
-
detector.platform[:family].must_equal('debian')
|
70
|
-
detector.platform[:release].must_equal('ubuntu-release')
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'linuxmint' do
|
75
|
-
it 'sets the correct family/release for ubuntu' do
|
76
|
-
detector.stubs(:lsb).returns({ id: 'linuxmint', release: 'mint-release' })
|
77
|
-
|
78
|
-
detector.detect_linux_via_config.must_equal(true)
|
79
|
-
detector.platform[:name].must_equal('linuxmint')
|
80
|
-
detector.platform[:family].must_equal('debian')
|
81
|
-
detector.platform[:release].must_equal('mint-release')
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe 'raspbian' do
|
86
|
-
it 'sets the correct family/release for raspbian ' do
|
87
|
-
detector.stubs(:lsb).returns({ id: 'something_else', release: 'some_release' })
|
88
|
-
detector.expects(:unix_file?).with('/usr/bin/raspi-config').returns(true)
|
89
|
-
|
90
|
-
detector.detect_linux_via_config.must_equal(true)
|
91
|
-
detector.platform[:name].must_equal('raspbian')
|
92
|
-
detector.platform[:family].must_equal('debian')
|
93
|
-
detector.platform[:release].must_equal('deb-version')
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe 'everything else' do
|
98
|
-
it 'sets the correct family/release for debian ' do
|
99
|
-
detector.stubs(:lsb).returns({ id: 'something_else', release: 'some_release' })
|
100
|
-
detector.expects(:unix_file?).with('/usr/bin/raspi-config').returns(false)
|
101
|
-
|
102
|
-
detector.detect_linux_via_config.must_equal(true)
|
103
|
-
detector.platform[:name].must_equal('debian')
|
104
|
-
detector.platform[:family].must_equal('debian')
|
105
|
-
detector.platform[:release].must_equal('deb-version')
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe '/etc/coreos/update.conf' do
|
111
|
-
it 'sets the correct family/release for coreos' do
|
112
|
-
detector.stubs(:get_config).with('/etc/coreos/update.conf').returns('data')
|
113
|
-
detector.stubs(:lsb).returns({ id: 'Container Linux by CoreOS', release: 'coreos-version' })
|
114
|
-
|
115
|
-
detector.detect_linux_via_config.must_equal(true)
|
116
|
-
detector.platform[:name].must_equal('coreos')
|
117
|
-
detector.platform[:family].must_equal('coreos')
|
118
|
-
detector.platform[:release].must_equal('coreos-version')
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe '/etc/os-release' do
|
123
|
-
describe 'when not on a wrlinux build' do
|
124
|
-
it 'does not set a platform family/release' do
|
125
|
-
detector.stubs(:fetch_os_release).returns({ 'ID_LIKE' => 'something_else' })
|
126
|
-
|
127
|
-
detector.detect_linux_via_config.must_equal(false)
|
128
|
-
detector.platform[:family].must_be_nil
|
129
|
-
detector.platform[:release].must_be_nil
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
describe 'when on a wrlinux build' do
|
134
|
-
let(:data) do
|
135
|
-
{
|
136
|
-
'ID_LIKE' => 'cisco-wrlinux',
|
137
|
-
'VERSION' => 'cisco123'
|
138
|
-
}
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'sets the correct family/release for wrlinux' do
|
142
|
-
detector.stubs(:fetch_os_release).returns(data)
|
143
|
-
|
144
|
-
detector.detect_linux_via_config.must_equal(true)
|
145
|
-
detector.platform[:name].must_equal('wrlinux')
|
146
|
-
detector.platform[:family].must_equal('redhat')
|
147
|
-
detector.platform[:release].must_equal('cisco123')
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe '#fetch_os_release' do
|
154
|
-
describe 'when no os-release data is available' do
|
155
|
-
it 'returns nil' do
|
156
|
-
detector.expects(:get_config).with('/etc/os-release').returns(nil)
|
157
|
-
detector.fetch_os_release.must_be_nil
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe 'when os-release data exists with no CISCO_RELEASE_INFO' do
|
162
|
-
let(:os_release) { { 'KEY1' => 'VALUE1' } }
|
163
|
-
|
164
|
-
it 'returns a correct hash' do
|
165
|
-
detector.expects(:get_config).with('/etc/os-release').returns('os-release data')
|
166
|
-
detector.expects(:parse_os_release_info).with('os-release data').returns(os_release)
|
167
|
-
detector.fetch_os_release['KEY1'].must_equal('VALUE1')
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
describe 'when os-release data exists with CISCO_RELEASE_INFO' do
|
172
|
-
let(:os_release) { { 'KEY1' => 'VALUE1', 'CISCO_RELEASE_INFO' => 'cisco_file' } }
|
173
|
-
let(:cisco_release) { { 'KEY1' => 'NEWVALUE1', 'KEY2' => 'VALUE2' } }
|
174
|
-
|
175
|
-
it 'returns a correct hash' do
|
176
|
-
detector.expects(:get_config).with('/etc/os-release').returns('os-release data')
|
177
|
-
detector.expects(:get_config).with('cisco_file').returns('cisco data')
|
178
|
-
detector.expects(:parse_os_release_info).with('os-release data').returns(os_release)
|
179
|
-
detector.expects(:parse_os_release_info).with('cisco data').returns(cisco_release)
|
180
|
-
|
181
|
-
os_info = detector.fetch_os_release
|
182
|
-
os_info['KEY1'].must_equal('NEWVALUE1')
|
183
|
-
os_info['KEY2'].must_equal('VALUE2')
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe '#parse_os_release_info' do
|
189
|
-
describe 'when nil is supplied' do
|
190
|
-
it 'returns an empty hash' do
|
191
|
-
detector.parse_os_release_info(nil).must_equal({})
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe 'when unexpectedly-formatted data is supplied' do
|
196
|
-
let(:data) do
|
197
|
-
<<-EOL
|
198
|
-
blah blah
|
199
|
-
no good data here
|
200
|
-
EOL
|
201
|
-
end
|
202
|
-
|
203
|
-
it 'returns an empty hash' do
|
204
|
-
detector.parse_os_release_info(nil).must_equal({})
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
describe 'when properly-formatted data is supplied' do
|
209
|
-
let(:data) do
|
210
|
-
<<-EOL
|
211
|
-
KEY1=value1
|
212
|
-
KEY2=
|
213
|
-
KEY3=value3
|
214
|
-
KEY4="value4 with spaces"
|
215
|
-
KEY5="value5 with a = sign"
|
216
|
-
EOL
|
217
|
-
end
|
218
|
-
|
219
|
-
it 'parses the data correctly' do
|
220
|
-
parsed_data = detector.parse_os_release_info(data)
|
221
|
-
|
222
|
-
parsed_data['KEY1'].must_equal('value1')
|
223
|
-
parsed_data.key?('KEY2').must_equal(false)
|
224
|
-
parsed_data['KEY3'].must_equal('value3')
|
225
|
-
parsed_data['KEY4'].must_equal('value4 with spaces')
|
226
|
-
parsed_data['KEY5'].must_equal('value5 with a = sign')
|
227
|
-
end
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|