train 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +71 -0
- data/CHANGELOG.md +308 -0
- data/Gemfile +30 -0
- data/LICENSE +201 -0
- data/README.md +156 -0
- data/Rakefile +148 -0
- data/lib/train.rb +117 -0
- data/lib/train/errors.rb +23 -0
- data/lib/train/extras.rb +17 -0
- data/lib/train/extras/command_wrapper.rb +148 -0
- data/lib/train/extras/file_aix.rb +20 -0
- data/lib/train/extras/file_common.rb +161 -0
- data/lib/train/extras/file_linux.rb +16 -0
- data/lib/train/extras/file_unix.rb +79 -0
- data/lib/train/extras/file_windows.rb +91 -0
- data/lib/train/extras/linux_lsb.rb +60 -0
- data/lib/train/extras/os_common.rb +136 -0
- data/lib/train/extras/os_detect_darwin.rb +32 -0
- data/lib/train/extras/os_detect_linux.rb +148 -0
- data/lib/train/extras/os_detect_unix.rb +99 -0
- data/lib/train/extras/os_detect_windows.rb +57 -0
- data/lib/train/extras/stat.rb +133 -0
- data/lib/train/options.rb +80 -0
- data/lib/train/plugins.rb +40 -0
- data/lib/train/plugins/base_connection.rb +86 -0
- data/lib/train/plugins/transport.rb +49 -0
- data/lib/train/transports/docker.rb +103 -0
- data/lib/train/transports/local.rb +52 -0
- data/lib/train/transports/local_file.rb +90 -0
- data/lib/train/transports/local_os.rb +51 -0
- data/lib/train/transports/mock.rb +147 -0
- data/lib/train/transports/ssh.rb +163 -0
- data/lib/train/transports/ssh_connection.rb +225 -0
- data/lib/train/transports/winrm.rb +184 -0
- data/lib/train/transports/winrm_connection.rb +194 -0
- data/lib/train/version.rb +7 -0
- data/test/integration/.kitchen.yml +43 -0
- data/test/integration/Berksfile +3 -0
- data/test/integration/bootstrap.sh +17 -0
- data/test/integration/chefignore +1 -0
- data/test/integration/cookbooks/test/metadata.rb +1 -0
- data/test/integration/cookbooks/test/recipes/default.rb +100 -0
- data/test/integration/cookbooks/test/recipes/prep_files.rb +47 -0
- data/test/integration/docker_run.rb +153 -0
- data/test/integration/docker_test.rb +24 -0
- data/test/integration/docker_test_container.rb +24 -0
- data/test/integration/helper.rb +61 -0
- data/test/integration/sudo/customcommand.rb +15 -0
- data/test/integration/sudo/nopasswd.rb +16 -0
- data/test/integration/sudo/passwd.rb +21 -0
- data/test/integration/sudo/reqtty.rb +17 -0
- data/test/integration/sudo/run_as.rb +12 -0
- data/test/integration/test-travis-1.yaml +13 -0
- data/test/integration/test-travis-2.yaml +13 -0
- data/test/integration/test_local.rb +19 -0
- data/test/integration/test_ssh.rb +39 -0
- data/test/integration/tests/path_block_device_test.rb +74 -0
- data/test/integration/tests/path_character_device_test.rb +74 -0
- data/test/integration/tests/path_file_test.rb +79 -0
- data/test/integration/tests/path_folder_test.rb +90 -0
- data/test/integration/tests/path_missing_test.rb +77 -0
- data/test/integration/tests/path_pipe_test.rb +78 -0
- data/test/integration/tests/path_symlink_test.rb +95 -0
- data/test/integration/tests/run_command_test.rb +28 -0
- data/test/unit/extras/command_wrapper_test.rb +78 -0
- data/test/unit/extras/file_common_test.rb +180 -0
- data/test/unit/extras/linux_file_test.rb +167 -0
- data/test/unit/extras/os_common_test.rb +269 -0
- data/test/unit/extras/os_detect_linux_test.rb +189 -0
- data/test/unit/extras/os_detect_windows_test.rb +99 -0
- data/test/unit/extras/stat_test.rb +148 -0
- data/test/unit/extras/windows_file_test.rb +44 -0
- data/test/unit/helper.rb +7 -0
- data/test/unit/plugins/connection_test.rb +44 -0
- data/test/unit/plugins/transport_test.rb +111 -0
- data/test/unit/plugins_test.rb +22 -0
- data/test/unit/train_test.rb +156 -0
- data/test/unit/transports/local_file_test.rb +184 -0
- data/test/unit/transports/local_test.rb +87 -0
- data/test/unit/transports/mock_test.rb +87 -0
- data/test/unit/transports/ssh_test.rb +109 -0
- data/test/unit/version_test.rb +8 -0
- data/test/windows/local_test.rb +46 -0
- data/test/windows/winrm_test.rb +52 -0
- data/train.gemspec +38 -0
- metadata +295 -0
@@ -0,0 +1,167 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
require 'train/transports/mock'
|
4
|
+
require 'train/extras'
|
5
|
+
|
6
|
+
describe 'file common' do
|
7
|
+
let(:cls) { Train::Extras::LinuxFile }
|
8
|
+
let(:backend) {
|
9
|
+
backend = Train::Transports::Mock.new.connection
|
10
|
+
backend.mock_os({ family: 'linux' })
|
11
|
+
backend
|
12
|
+
}
|
13
|
+
|
14
|
+
def mock_stat(args, out, err = '', code = 0)
|
15
|
+
backend.mock_command(
|
16
|
+
"stat #{args} 2>/dev/null --printf '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'",
|
17
|
+
out, err, code,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'works on nil path' do
|
22
|
+
cls.new(backend, nil).path.must_equal ''
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'provides the full path' do
|
26
|
+
cls.new(backend, '/dir/file').path.must_equal '/dir/file'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'provides the basename to a unix path' do
|
30
|
+
cls.new(backend, '/dir/file').basename.must_equal 'file'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'reads file contents' do
|
34
|
+
out = rand.to_s
|
35
|
+
backend.mock_command('cat path || echo -n', out)
|
36
|
+
cls.new(backend, 'path').content.must_equal out
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'reads file contents' do
|
40
|
+
backend.mock_command('cat path || echo -n', '')
|
41
|
+
mock_stat('-L path', '', 'some error...', 1)
|
42
|
+
cls.new(backend, 'path').content.must_equal nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'checks for file existance' do
|
46
|
+
backend.mock_command('test -e path', true)
|
47
|
+
cls.new(backend, 'path').exist?.must_equal true
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'checks for file existance' do
|
51
|
+
backend.mock_command('test -e path', nil, nil, 1)
|
52
|
+
cls.new(backend, 'path').exist?.must_equal false
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'retrieves the link path via #path()' do
|
56
|
+
out = rand.to_s
|
57
|
+
mock_stat('path', "13\na1ff\nz\n1001\nz\n1001\n1444573475\n1444573475\n?")
|
58
|
+
backend.mock_command('readlink -n path -f', out)
|
59
|
+
cls.new(backend, 'path').path.must_equal File.join(Dir.pwd, out)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'retrieves the link path' do
|
63
|
+
out = rand.to_s
|
64
|
+
mock_stat('path', "13\na1ff\nz\n1001\nz\n1001\n1444573475\n1444573475\n?")
|
65
|
+
backend.mock_command('readlink -n path -f', out)
|
66
|
+
cls.new(backend, 'path').link_path.must_equal File.join(Dir.pwd, out)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'provide the source path' do
|
70
|
+
cls.new(backend, 'path').source_path.must_equal 'path'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'checks a mounted path' do
|
74
|
+
backend.mock_command("mount | grep -- ' on /mount/path '", rand.to_s)
|
75
|
+
cls.new(backend, '/mount/path').mounted?.must_equal true
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'has nil product version' do
|
79
|
+
cls.new(backend, 'path').product_version.must_be_nil
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'has nil file version' do
|
83
|
+
cls.new(backend, 'path').file_version.must_be_nil
|
84
|
+
end
|
85
|
+
|
86
|
+
describe 'stat on a file' do
|
87
|
+
before { mock_stat('-L path', "13\na1ff\nz\n1001\nz2\n1002\n1444573475\n1444573475\nlabels") }
|
88
|
+
let(:f) { cls.new(backend, 'path') }
|
89
|
+
|
90
|
+
it 'retrieves the file type' do
|
91
|
+
f.type.must_equal :symlink
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'retrieves the file mode' do
|
95
|
+
f.mode.must_equal 00777
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'retrieves the file owner' do
|
99
|
+
f.owner.must_equal 'z'
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'retrieves the file uid' do
|
103
|
+
f.uid.must_equal 1001
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'retrieves the file group' do
|
107
|
+
f.group.must_equal 'z2'
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'retrieves the file gid' do
|
111
|
+
f.gid.must_equal 1002
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'retrieves the file mtime' do
|
115
|
+
f.mtime.must_equal 1444573475
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'retrieves the file size' do
|
119
|
+
f.size.must_equal 13
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'retrieves the file selinux_label' do
|
123
|
+
f.selinux_label.must_equal 'labels'
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe 'stat on the source file' do
|
128
|
+
before { mock_stat('path', "13\na1ff\nz\n1001\nz2\n1002\n1444573475\n1444573475\nlabels") }
|
129
|
+
let(:f) { cls.new(backend, 'path').source }
|
130
|
+
|
131
|
+
it 'retrieves the file type' do
|
132
|
+
f.type.must_equal :symlink
|
133
|
+
end
|
134
|
+
|
135
|
+
it 'retrieves the file mode' do
|
136
|
+
f.mode.must_equal 00777
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'retrieves the file owner' do
|
140
|
+
f.owner.must_equal 'z'
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'retrieves the file uid' do
|
144
|
+
f.uid.must_equal 1001
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'retrieves the file group' do
|
148
|
+
f.group.must_equal 'z2'
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'retrieves the file gid' do
|
152
|
+
f.gid.must_equal 1002
|
153
|
+
end
|
154
|
+
|
155
|
+
it 'retrieves the file mtime' do
|
156
|
+
f.mtime.must_equal 1444573475
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'retrieves the file size' do
|
160
|
+
f.size.must_equal 13
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'retrieves the file selinux_label' do
|
164
|
+
f.selinux_label.must_equal 'labels'
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,269 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Dominik Richter
|
3
|
+
# author: Christoph Hartmann
|
4
|
+
|
5
|
+
require 'helper'
|
6
|
+
require 'train/extras'
|
7
|
+
|
8
|
+
describe 'os common plugin' do
|
9
|
+
let(:cls) {
|
10
|
+
Class.new(Train::Extras::OSCommon) do
|
11
|
+
def detect_family; end
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
def mock_platform(x)
|
16
|
+
cls.new(nil, { family: x })
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'provides a method to access platform data' do
|
20
|
+
family = rand
|
21
|
+
os = mock_platform(family)
|
22
|
+
os[:family].must_equal family
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'provides an accessor for the full hash' do
|
26
|
+
x = rand.to_s
|
27
|
+
os = mock_platform(x)
|
28
|
+
os.to_hash.must_equal({ family: x })
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'with platform set to redhat' do
|
32
|
+
let(:os) { mock_platform('redhat') }
|
33
|
+
it { os.redhat?.must_equal(true) }
|
34
|
+
it { os.debian?.must_equal(false) }
|
35
|
+
it { os.suse?.must_equal(false) }
|
36
|
+
it { os.linux?.must_equal(true) }
|
37
|
+
it { os.unix?.must_equal(true) }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'with platform set to oracle' do
|
41
|
+
let(:os) { mock_platform('oracle') }
|
42
|
+
it { os.redhat?.must_equal(true) }
|
43
|
+
it { os.debian?.must_equal(false) }
|
44
|
+
it { os.suse?.must_equal(false) }
|
45
|
+
it { os.linux?.must_equal(true) }
|
46
|
+
it { os.unix?.must_equal(true) }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'with platform set to centos' do
|
50
|
+
let(:os) { mock_platform('centos') }
|
51
|
+
it { os.redhat?.must_equal(true) }
|
52
|
+
it { os.debian?.must_equal(false) }
|
53
|
+
it { os.suse?.must_equal(false) }
|
54
|
+
it { os.linux?.must_equal(true) }
|
55
|
+
it { os.unix?.must_equal(true) }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'with platform set to fedora' do
|
59
|
+
let(:os) { mock_platform('fedora') }
|
60
|
+
it { os.redhat?.must_equal(true) }
|
61
|
+
it { os.debian?.must_equal(false) }
|
62
|
+
it { os.suse?.must_equal(false) }
|
63
|
+
it { os.linux?.must_equal(true) }
|
64
|
+
it { os.unix?.must_equal(true) }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'with platform set to debian' do
|
68
|
+
let(:os) { mock_platform('debian') }
|
69
|
+
it { os.redhat?.must_equal(false) }
|
70
|
+
it { os.debian?.must_equal(true) }
|
71
|
+
it { os.suse?.must_equal(false) }
|
72
|
+
it { os.linux?.must_equal(true) }
|
73
|
+
it { os.unix?.must_equal(true) }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'with platform set to ubuntu' do
|
77
|
+
let(:os) { mock_platform('ubuntu') }
|
78
|
+
it { os.redhat?.must_equal(false) }
|
79
|
+
it { os.debian?.must_equal(true) }
|
80
|
+
it { os.suse?.must_equal(false) }
|
81
|
+
it { os.linux?.must_equal(true) }
|
82
|
+
it { os.unix?.must_equal(true) }
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'with platform set to linuxmint' do
|
86
|
+
let(:os) { mock_platform('linuxmint') }
|
87
|
+
it { os.redhat?.must_equal(false) }
|
88
|
+
it { os.debian?.must_equal(true) }
|
89
|
+
it { os.suse?.must_equal(false) }
|
90
|
+
it { os.linux?.must_equal(true) }
|
91
|
+
it { os.unix?.must_equal(true) }
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'with platform set to raspbian' do
|
95
|
+
let(:os) { mock_platform('raspbian') }
|
96
|
+
it { os.redhat?.must_equal(false) }
|
97
|
+
it { os.debian?.must_equal(true) }
|
98
|
+
it { os.suse?.must_equal(false) }
|
99
|
+
it { os.linux?.must_equal(true) }
|
100
|
+
it { os.unix?.must_equal(true) }
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'with platform set to suse' do
|
104
|
+
let(:os) { mock_platform('suse') }
|
105
|
+
it { os.redhat?.must_equal(false) }
|
106
|
+
it { os.debian?.must_equal(false) }
|
107
|
+
it { os.suse?.must_equal(true) }
|
108
|
+
it { os.linux?.must_equal(true) }
|
109
|
+
it { os.unix?.must_equal(true) }
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'with platform set to opensuse' do
|
113
|
+
let(:os) { mock_platform('opensuse') }
|
114
|
+
it { os.redhat?.must_equal(false) }
|
115
|
+
it { os.debian?.must_equal(false) }
|
116
|
+
it { os.suse?.must_equal(true) }
|
117
|
+
it { os.linux?.must_equal(true) }
|
118
|
+
it { os.unix?.must_equal(true) }
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'with platform set to alpine' do
|
122
|
+
let(:os) { mock_platform('alpine') }
|
123
|
+
it { os.redhat?.must_equal(false) }
|
124
|
+
it { os.debian?.must_equal(false) }
|
125
|
+
it { os.suse?.must_equal(false) }
|
126
|
+
it { os.linux?.must_equal(true) }
|
127
|
+
it { os.unix?.must_equal(true) }
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'with platform set to arch' do
|
131
|
+
let(:os) { mock_platform('arch') }
|
132
|
+
it { os.redhat?.must_equal(false) }
|
133
|
+
it { os.debian?.must_equal(false) }
|
134
|
+
it { os.suse?.must_equal(false) }
|
135
|
+
it { os.linux?.must_equal(true) }
|
136
|
+
it { os.unix?.must_equal(true) }
|
137
|
+
end
|
138
|
+
|
139
|
+
describe 'with platform set to coreos' do
|
140
|
+
let(:os) { mock_platform('coreos') }
|
141
|
+
it { os.redhat?.must_equal(false) }
|
142
|
+
it { os.debian?.must_equal(false) }
|
143
|
+
it { os.suse?.must_equal(false) }
|
144
|
+
it { os.linux?.must_equal(true) }
|
145
|
+
it { os.unix?.must_equal(true) }
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'with platform set to exherbo' do
|
149
|
+
let(:os) { mock_platform('exherbo') }
|
150
|
+
it { os.redhat?.must_equal(false) }
|
151
|
+
it { os.debian?.must_equal(false) }
|
152
|
+
it { os.suse?.must_equal(false) }
|
153
|
+
it { os.linux?.must_equal(true) }
|
154
|
+
it { os.unix?.must_equal(true) }
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'with platform set to gentoo' do
|
158
|
+
let(:os) { mock_platform('gentoo') }
|
159
|
+
it { os.redhat?.must_equal(false) }
|
160
|
+
it { os.debian?.must_equal(false) }
|
161
|
+
it { os.suse?.must_equal(false) }
|
162
|
+
it { os.linux?.must_equal(true) }
|
163
|
+
it { os.unix?.must_equal(true) }
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'with platform set to slackware' do
|
167
|
+
let(:os) { mock_platform('slackware') }
|
168
|
+
it { os.redhat?.must_equal(false) }
|
169
|
+
it { os.debian?.must_equal(false) }
|
170
|
+
it { os.suse?.must_equal(false) }
|
171
|
+
it { os.linux?.must_equal(true) }
|
172
|
+
it { os.unix?.must_equal(true) }
|
173
|
+
end
|
174
|
+
|
175
|
+
describe 'with platform set to wrlinux' do
|
176
|
+
let(:os) { mock_platform('wrlinux') }
|
177
|
+
it { os.redhat?.must_equal(true) }
|
178
|
+
it { os.debian?.must_equal(false) }
|
179
|
+
it { os.suse?.must_equal(false) }
|
180
|
+
it { os.linux?.must_equal(true) }
|
181
|
+
it { os.unix?.must_equal(true) }
|
182
|
+
end
|
183
|
+
|
184
|
+
describe 'with platform set to linux' do
|
185
|
+
let(:os) { mock_platform('linux') }
|
186
|
+
it { os.linux?.must_equal(true) }
|
187
|
+
it { os.unix?.must_equal(true) }
|
188
|
+
end
|
189
|
+
|
190
|
+
describe 'with platform set to freebsd' do
|
191
|
+
let(:os) { mock_platform('freebsd') }
|
192
|
+
it { os.bsd?.must_equal(true) }
|
193
|
+
it { os.linux?.must_equal(false) }
|
194
|
+
it { os.unix?.must_equal(true) }
|
195
|
+
end
|
196
|
+
|
197
|
+
describe 'with platform set to netbsd' do
|
198
|
+
let(:os) { mock_platform('netbsd') }
|
199
|
+
it { os.bsd?.must_equal(true) }
|
200
|
+
it { os.linux?.must_equal(false) }
|
201
|
+
it { os.unix?.must_equal(true) }
|
202
|
+
end
|
203
|
+
|
204
|
+
describe 'with platform set to openbsd' do
|
205
|
+
let(:os) { mock_platform('openbsd') }
|
206
|
+
it { os.bsd?.must_equal(true) }
|
207
|
+
it { os.linux?.must_equal(false) }
|
208
|
+
it { os.unix?.must_equal(true) }
|
209
|
+
end
|
210
|
+
|
211
|
+
describe 'with platform set to darwin' do
|
212
|
+
let(:os) { mock_platform('darwin') }
|
213
|
+
it { os.bsd?.must_equal(true) }
|
214
|
+
it { os.linux?.must_equal(false) }
|
215
|
+
it { os.unix?.must_equal(true) }
|
216
|
+
end
|
217
|
+
|
218
|
+
describe 'with platform set to solaris' do
|
219
|
+
let(:os) { mock_platform('solaris') }
|
220
|
+
it { os.solaris?.must_equal(true) }
|
221
|
+
it { os.linux?.must_equal(false) }
|
222
|
+
it { os.unix?.must_equal(true) }
|
223
|
+
end
|
224
|
+
|
225
|
+
describe 'with platform set to smartos' do
|
226
|
+
let(:os) { mock_platform('smartos') }
|
227
|
+
it { os.solaris?.must_equal(true) }
|
228
|
+
it { os.linux?.must_equal(false) }
|
229
|
+
it { os.unix?.must_equal(true) }
|
230
|
+
end
|
231
|
+
|
232
|
+
describe 'with platform set to openindiana' do
|
233
|
+
let(:os) { mock_platform('openindiana') }
|
234
|
+
it { os.solaris?.must_equal(true) }
|
235
|
+
it { os.linux?.must_equal(false) }
|
236
|
+
it { os.unix?.must_equal(true) }
|
237
|
+
end
|
238
|
+
|
239
|
+
describe 'with platform set to opensolaris' do
|
240
|
+
let(:os) { mock_platform('opensolaris') }
|
241
|
+
it { os.solaris?.must_equal(true) }
|
242
|
+
it { os.linux?.must_equal(false) }
|
243
|
+
it { os.unix?.must_equal(true) }
|
244
|
+
end
|
245
|
+
|
246
|
+
describe 'with platform set to nexentacore' do
|
247
|
+
let(:os) { mock_platform('nexentacore') }
|
248
|
+
it { os.solaris?.must_equal(true) }
|
249
|
+
it { os.linux?.must_equal(false) }
|
250
|
+
it { os.unix?.must_equal(true) }
|
251
|
+
end
|
252
|
+
|
253
|
+
describe 'with platform set to windows' do
|
254
|
+
let(:os) { mock_platform('windows') }
|
255
|
+
it { os.solaris?.must_equal(false) }
|
256
|
+
it { os.bsd?.must_equal(false) }
|
257
|
+
it { os.linux?.must_equal(false) }
|
258
|
+
it { os.unix?.must_equal(false) }
|
259
|
+
end
|
260
|
+
|
261
|
+
describe 'with platform set to hpux' do
|
262
|
+
let(:os) { mock_platform('hpux') }
|
263
|
+
it { os.solaris?.must_equal(false) }
|
264
|
+
it { os.linux?.must_equal(false) }
|
265
|
+
it { os.unix?.must_equal(true) }
|
266
|
+
it { os.hpux?.must_equal(true) }
|
267
|
+
end
|
268
|
+
|
269
|
+
end
|
@@ -0,0 +1,189 @@
|
|
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_via_config' do
|
18
|
+
|
19
|
+
before do
|
20
|
+
detector.stubs(:get_config)
|
21
|
+
detector.stubs(:fetch_os_release)
|
22
|
+
detector.stubs(:redhatish_version).returns('redhat-version')
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '/etc/enterprise-release' do
|
26
|
+
it 'sets the correct family/release for oracle' do
|
27
|
+
detector.stubs(:get_config).with('/etc/enterprise-release').returns('data')
|
28
|
+
|
29
|
+
detector.detect_linux_via_config.must_equal(true)
|
30
|
+
detector.platform[:family].must_equal('oracle')
|
31
|
+
detector.platform[:release].must_equal('redhat-version')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '/etc/debian_version' do
|
36
|
+
|
37
|
+
before { detector.stubs(:get_config).with('/etc/debian_version').returns('deb-version') }
|
38
|
+
|
39
|
+
describe 'ubuntu' do
|
40
|
+
it 'sets the correct family/release for ubuntu' do
|
41
|
+
detector.stubs(:lsb).returns({ id: 'ubuntu', release: 'ubuntu-release' })
|
42
|
+
|
43
|
+
detector.detect_linux_via_config.must_equal(true)
|
44
|
+
detector.platform[:family].must_equal('ubuntu')
|
45
|
+
detector.platform[:release].must_equal('ubuntu-release')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'linuxmint' do
|
50
|
+
it 'sets the correct family/release for ubuntu' do
|
51
|
+
detector.stubs(:lsb).returns({ id: 'linuxmint', release: 'mint-release' })
|
52
|
+
|
53
|
+
detector.detect_linux_via_config.must_equal(true)
|
54
|
+
detector.platform[:family].must_equal('linuxmint')
|
55
|
+
detector.platform[:release].must_equal('mint-release')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe 'raspbian' do
|
60
|
+
it 'sets the correct family/release for raspbian ' do
|
61
|
+
detector.stubs(:lsb).returns({ id: 'something_else', release: 'some_release' })
|
62
|
+
detector.expects(:unix_file?).with('/usr/bin/raspi-config').returns(true)
|
63
|
+
|
64
|
+
detector.detect_linux_via_config.must_equal(true)
|
65
|
+
detector.platform[:family].must_equal('raspbian')
|
66
|
+
detector.platform[:release].must_equal('deb-version')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'everything else' do
|
71
|
+
it 'sets the correct family/release for debian ' do
|
72
|
+
detector.stubs(:lsb).returns({ id: 'something_else', release: 'some_release' })
|
73
|
+
detector.expects(:unix_file?).with('/usr/bin/raspi-config').returns(false)
|
74
|
+
|
75
|
+
detector.detect_linux_via_config.must_equal(true)
|
76
|
+
detector.platform[:family].must_equal('debian')
|
77
|
+
detector.platform[:release].must_equal('deb-version')
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '/etc/os-release' do
|
83
|
+
describe 'when not on a wrlinux build' do
|
84
|
+
it 'does not set a platform family/release' do
|
85
|
+
detector.stubs(:fetch_os_release).returns({ 'ID_LIKE' => 'something_else' })
|
86
|
+
|
87
|
+
detector.detect_linux_via_config.must_equal(false)
|
88
|
+
detector.platform[:family].must_equal(nil)
|
89
|
+
detector.platform[:release].must_equal(nil)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'when on a wrlinux build' do
|
94
|
+
let(:data) do
|
95
|
+
{
|
96
|
+
'ID_LIKE' => 'cisco-wrlinux',
|
97
|
+
'VERSION' => 'cisco123'
|
98
|
+
}
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'sets the correct family/release for wrlinux' do
|
102
|
+
detector.stubs(:fetch_os_release).returns(data)
|
103
|
+
|
104
|
+
detector.detect_linux_via_config.must_equal(true)
|
105
|
+
detector.platform[:family].must_equal('wrlinux')
|
106
|
+
detector.platform[:release].must_equal('cisco123')
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#fetch_os_release' do
|
113
|
+
describe 'when no os-release data is available' do
|
114
|
+
it 'returns nil' do
|
115
|
+
detector.expects(:get_config).with('/etc/os-release').returns(nil)
|
116
|
+
detector.fetch_os_release.must_equal(nil)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'when os-release data exists with no CISCO_RELEASE_INFO' do
|
121
|
+
let(:os_release) { { 'KEY1' => 'VALUE1' } }
|
122
|
+
|
123
|
+
it 'returns a correct hash' do
|
124
|
+
detector.expects(:get_config).with('/etc/os-release').returns('os-release data')
|
125
|
+
detector.expects(:parse_os_release_info).with('os-release data').returns(os_release)
|
126
|
+
detector.fetch_os_release['KEY1'].must_equal('VALUE1')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'when os-release data exists with CISCO_RELEASE_INFO' do
|
131
|
+
let(:os_release) { { 'KEY1' => 'VALUE1', 'CISCO_RELEASE_INFO' => 'cisco_file' } }
|
132
|
+
let(:cisco_release) { { 'KEY1' => 'NEWVALUE1', 'KEY2' => 'VALUE2' } }
|
133
|
+
|
134
|
+
it 'returns a correct hash' do
|
135
|
+
detector.expects(:get_config).with('/etc/os-release').returns('os-release data')
|
136
|
+
detector.expects(:get_config).with('cisco_file').returns('cisco data')
|
137
|
+
detector.expects(:parse_os_release_info).with('os-release data').returns(os_release)
|
138
|
+
detector.expects(:parse_os_release_info).with('cisco data').returns(cisco_release)
|
139
|
+
|
140
|
+
os_info = detector.fetch_os_release
|
141
|
+
os_info['KEY1'].must_equal('NEWVALUE1')
|
142
|
+
os_info['KEY2'].must_equal('VALUE2')
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe '#parse_os_release_info' do
|
148
|
+
describe 'when nil is supplied' do
|
149
|
+
it 'returns an empty hash' do
|
150
|
+
detector.parse_os_release_info(nil).must_equal({})
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe 'when unexpectedly-formatted data is supplied' do
|
155
|
+
let(:data) do
|
156
|
+
<<-EOL
|
157
|
+
blah blah
|
158
|
+
no good data here
|
159
|
+
EOL
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'returns an empty hash' do
|
163
|
+
detector.parse_os_release_info(nil).must_equal({})
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe 'when properly-formatted data is supplied' do
|
168
|
+
let(:data) do
|
169
|
+
<<-EOL
|
170
|
+
KEY1=value1
|
171
|
+
KEY2=
|
172
|
+
KEY3=value3
|
173
|
+
KEY4="value4 with spaces"
|
174
|
+
KEY5="value5 with a = sign"
|
175
|
+
EOL
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'parses the data correctly' do
|
179
|
+
parsed_data = detector.parse_os_release_info(data)
|
180
|
+
|
181
|
+
parsed_data['KEY1'].must_equal('value1')
|
182
|
+
parsed_data.key?('KEY2').must_equal(false)
|
183
|
+
parsed_data['KEY3'].must_equal('value3')
|
184
|
+
parsed_data['KEY4'].must_equal('value4 with spaces')
|
185
|
+
parsed_data['KEY5'].must_equal('value5 with a = sign')
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|