chef 11.14.0.alpha.3 → 11.14.0.alpha.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTING.md +140 -99
- data/lib/chef/application.rb +80 -2
- data/lib/chef/application/apply.rb +1 -0
- data/lib/chef/application/client.rb +5 -0
- data/lib/chef/application/knife.rb +4 -0
- data/lib/chef/application/windows_service.rb +1 -0
- data/lib/chef/chef_fs/parallelizer/parallel_enumerable.rb +6 -4
- data/lib/chef/config.rb +5 -3
- data/lib/chef/exceptions.rb +2 -0
- data/lib/chef/http/basic_client.rb +1 -0
- data/lib/chef/knife.rb +1 -0
- data/lib/chef/platform/provider_mapping.rb +7 -0
- data/lib/chef/provider/env/windows.rb +2 -0
- data/lib/chef/provider/group/usermod.rb +1 -1
- data/lib/chef/provider/mount/solaris.rb +233 -0
- data/lib/chef/provider/package/apt.rb +9 -0
- data/lib/chef/provider/package/windows.rb +3 -0
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/resource/mount.rb +6 -1
- data/lib/chef/util/path_helper.rb +94 -0
- data/lib/chef/version.rb +1 -1
- data/spec/functional/application_spec.rb +58 -0
- data/spec/functional/resource/mount_spec.rb +14 -11
- data/spec/integration/client/client_spec.rb +11 -0
- data/spec/integration/knife/common_options_spec.rb +9 -0
- data/spec/unit/application_spec.rb +157 -0
- data/spec/unit/http/basic_client_spec.rb +42 -0
- data/spec/unit/provider/env/windows_spec.rb +67 -0
- data/spec/unit/provider/group/usermod_spec.rb +2 -1
- data/spec/unit/provider/mount/mount_spec.rb +3 -3
- data/spec/unit/provider/mount/solaris_spec.rb +646 -0
- data/spec/unit/provider/package/apt_spec.rb +5 -0
- data/spec/unit/provider/package/windows_spec.rb +6 -0
- data/spec/unit/resource_reporter_spec.rb +2 -2
- data/spec/unit/util/path_helper_spec.rb +136 -0
- metadata +23 -16
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Cameron Cope (<ccope@brightcove.com>)
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
|
18
|
+
require 'spec_helper'
|
19
|
+
require 'chef/http/basic_client'
|
20
|
+
|
21
|
+
describe "HTTP Connection" do
|
22
|
+
|
23
|
+
let(:uri) { URI("https://example.com:4443") }
|
24
|
+
subject { Chef::HTTP::BasicClient.new(uri) }
|
25
|
+
|
26
|
+
describe ".new" do
|
27
|
+
it "creates an instance" do
|
28
|
+
subject
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#build_http_client" do
|
33
|
+
it "should build an http client" do
|
34
|
+
subject.build_http_client
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set an open timeout" do
|
38
|
+
subject.build_http_client.open_timeout.should_not be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Sander van Harmelen <svanharmelen@schubergphilis.com>
|
3
|
+
# Copyright:: Copyright (c) 2014 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
|
21
|
+
describe Chef::Provider::Env::Windows, :windows_only do
|
22
|
+
before do
|
23
|
+
@node = Chef::Node.new
|
24
|
+
@events = Chef::EventDispatch::Dispatcher.new
|
25
|
+
@run_context = Chef::RunContext.new(@node, {}, @events)
|
26
|
+
@new_resource = Chef::Resource::Env.new("CHEF_WINDOWS_ENV_TEST")
|
27
|
+
@new_resource.value("foo")
|
28
|
+
@provider = Chef::Provider::Env::Windows.new(@new_resource, @run_context)
|
29
|
+
@provider.stub(:env_obj).and_return(double('null object').as_null_object)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "action_create" do
|
33
|
+
before do
|
34
|
+
ENV.delete('CHEF_WINDOWS_ENV_TEST')
|
35
|
+
@provider.key_exists = false
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should update the ruby ENV object when it creates the key" do
|
39
|
+
@provider.action_create
|
40
|
+
expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql('foo')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "action_modify" do
|
45
|
+
before do
|
46
|
+
ENV['CHEF_WINDOWS_ENV_TEST'] = 'foo'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should update the ruby ENV object when it updates the value" do
|
50
|
+
@provider.should_receive(:compare_value).and_return(true)
|
51
|
+
@new_resource.value("foobar")
|
52
|
+
@provider.action_modify
|
53
|
+
expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql('foobar')
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "action_delete" do
|
58
|
+
before do
|
59
|
+
ENV['CHEF_WINDOWS_ENV_TEST'] = 'foo'
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should update the ruby ENV object when it deletes the key" do
|
63
|
+
@provider.action_delete
|
64
|
+
expect(ENV['CHEF_WINDOWS_ENV_TEST']).to eql(nil)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -53,7 +53,7 @@ describe Chef::Provider::Mount::Mount do
|
|
53
53
|
@provider.current_resource.device.should == '/dev/sdz1'
|
54
54
|
end
|
55
55
|
|
56
|
-
it "should accecpt device_type :uuid" do
|
56
|
+
it "should accecpt device_type :uuid", :not_supported_on_solaris do
|
57
57
|
@new_resource.device_type :uuid
|
58
58
|
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
|
59
59
|
@stdout_findfs = double("STDOUT", :first => "/dev/sdz1")
|
@@ -92,7 +92,7 @@ describe Chef::Provider::Mount::Mount do
|
|
92
92
|
@provider.load_current_resource
|
93
93
|
end
|
94
94
|
|
95
|
-
it "should raise an error if the mount device (uuid) does not exist" do
|
95
|
+
it "should raise an error if the mount device (uuid) does not exist", :not_supported_on_solaris do
|
96
96
|
@new_resource.device_type :uuid
|
97
97
|
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
|
98
98
|
status_findfs = double("Status", :exitstatus => 1)
|
@@ -304,7 +304,7 @@ describe Chef::Provider::Mount::Mount do
|
|
304
304
|
@provider.mount_fs()
|
305
305
|
end
|
306
306
|
|
307
|
-
it "should mount the filesystem specified by uuid" do
|
307
|
+
it "should mount the filesystem specified by uuid", :not_supported_on_solaris do
|
308
308
|
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
|
309
309
|
@new_resource.device_type :uuid
|
310
310
|
@stdout_findfs = double("STDOUT", :first => "/dev/sdz1")
|
@@ -0,0 +1,646 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Lamont Granquist (<lamont@getchef.com>)
|
3
|
+
# Copyright:: Copyright (c) 2008-2014 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'spec_helper'
|
20
|
+
require 'ostruct'
|
21
|
+
|
22
|
+
describe Chef::Provider::Mount::Solaris do
|
23
|
+
let(:node) { Chef::Node.new }
|
24
|
+
|
25
|
+
let(:events) { Chef::EventDispatch::Dispatcher.new }
|
26
|
+
|
27
|
+
let(:run_context) { Chef::RunContext.new(node, {}, events) }
|
28
|
+
|
29
|
+
let(:device_type) { :device }
|
30
|
+
|
31
|
+
let(:fstype) { "ufs" }
|
32
|
+
|
33
|
+
let(:device) { "/dev/dsk/c0t2d0s7" }
|
34
|
+
|
35
|
+
let(:mountpoint) { "/mnt/foo" }
|
36
|
+
|
37
|
+
let(:options) { nil }
|
38
|
+
|
39
|
+
let(:new_resource) {
|
40
|
+
new_resource = Chef::Resource::Mount.new(mountpoint)
|
41
|
+
new_resource.device device
|
42
|
+
new_resource.device_type device_type
|
43
|
+
new_resource.fstype fstype
|
44
|
+
new_resource.options options
|
45
|
+
|
46
|
+
new_resource.supports :remount => false
|
47
|
+
new_resource
|
48
|
+
}
|
49
|
+
|
50
|
+
let(:provider) {
|
51
|
+
Chef::Provider::Mount::Solaris.new(new_resource, run_context)
|
52
|
+
}
|
53
|
+
|
54
|
+
let(:vfstab_file_contents) {
|
55
|
+
<<-EOF.gsub /^\s*/, ''
|
56
|
+
#device device mount FS fsck mount mount
|
57
|
+
#to mount to fsck point type pass at boot options
|
58
|
+
#
|
59
|
+
fd - /dev/fd fd - no -
|
60
|
+
/proc - /proc proc - no -
|
61
|
+
# swap
|
62
|
+
/dev/dsk/c0t0d0s1 - - swap - no -
|
63
|
+
# root
|
64
|
+
/dev/dsk/c0t0d0s0 /dev/rdsk/c0t0d0s0 / ufs 1 no -
|
65
|
+
# tmpfs
|
66
|
+
swap - /tmp tmpfs - yes -
|
67
|
+
# nfs
|
68
|
+
cartman:/share2 - /cartman nfs - yes rw,soft
|
69
|
+
# ufs
|
70
|
+
/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -
|
71
|
+
EOF
|
72
|
+
}
|
73
|
+
|
74
|
+
let(:vfstab_file) {
|
75
|
+
t = Tempfile.new("rspec-vfstab")
|
76
|
+
t.write(vfstab_file_contents)
|
77
|
+
t.close
|
78
|
+
t
|
79
|
+
}
|
80
|
+
|
81
|
+
let(:mount_output) {
|
82
|
+
<<-EOF.gsub /^\s*/, ''
|
83
|
+
/dev/dsk/c0t0d0s0 on / type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012
|
84
|
+
/dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012
|
85
|
+
EOF
|
86
|
+
}
|
87
|
+
|
88
|
+
before do
|
89
|
+
stub_const("Chef::Provider::Mount::Solaris::VFSTAB", vfstab_file.path )
|
90
|
+
provider.stub(:shell_out!).with("mount -v").and_return(OpenStruct.new(:stdout => mount_output))
|
91
|
+
File.stub(:symlink?).with(device).and_return(false)
|
92
|
+
File.stub(:exist?).and_call_original # Tempfile.open on ruby 1.8.7 calls File.exist?
|
93
|
+
File.stub(:exist?).with(device).and_return(true)
|
94
|
+
File.stub(:exist?).with(mountpoint).and_return(true)
|
95
|
+
expect(File).to_not receive(:exists?)
|
96
|
+
end
|
97
|
+
|
98
|
+
describe "#define_resource_requirements" do
|
99
|
+
before do
|
100
|
+
# we're not testing the actual actions so stub them all out
|
101
|
+
[:mount_fs, :umount_fs, :remount_fs, :enable_fs, :disable_fs].each {|m| provider.stub(m) }
|
102
|
+
end
|
103
|
+
|
104
|
+
it "run_action(:mount) should raise an error if the device does not exist" do
|
105
|
+
File.stub(:exist?).with(device).and_return(false)
|
106
|
+
expect { provider.run_action(:mount) }.to raise_error(Chef::Exceptions::Mount)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "run_action(:remount) should raise an error if the device does not exist" do
|
110
|
+
File.stub(:exist?).with(device).and_return(false)
|
111
|
+
expect { provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "run_action(:mount) should raise an error if the mountpoint does not exist" do
|
115
|
+
File.stub(:exist?).with(mountpoint).and_return false
|
116
|
+
expect { provider.run_action(:mount) }.to raise_error(Chef::Exceptions::Mount)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "run_action(:remount) should raise an error if the mountpoint does not exist" do
|
120
|
+
File.stub(:exist?).with(mountpoint).and_return false
|
121
|
+
expect { provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount)
|
122
|
+
end
|
123
|
+
|
124
|
+
%w{tmpfs nfs ctfs proc mntfs objfs sharefs fd smbfs}.each do |ft|
|
125
|
+
context "when the device has a fstype of #{ft}" do
|
126
|
+
let(:fstype) { ft }
|
127
|
+
let(:device) { "something_that_is_not_a_file" }
|
128
|
+
|
129
|
+
before do
|
130
|
+
expect(File).to_not receive(:exist?).with(device)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "run_action(:mount) should not raise an error" do
|
134
|
+
expect { provider.run_action(:mount) }.to_not raise_error
|
135
|
+
end
|
136
|
+
|
137
|
+
it "run_action(:remount) should not raise an error" do
|
138
|
+
expect { provider.run_action(:remount) }.to_not raise_error
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "#load_current_resource" do
|
146
|
+
context "when loading a normal UFS filesystem" do
|
147
|
+
|
148
|
+
before do
|
149
|
+
provider.load_current_resource
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should create a current_resource of type Chef::Resource::Mount" do
|
153
|
+
expect(provider.current_resource).to be_a(Chef::Resource::Mount)
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should set the name on the current_resource" do
|
157
|
+
provider.current_resource.name.should == mountpoint
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should set the mount_point on the current_resource" do
|
161
|
+
provider.current_resource.mount_point.should == mountpoint
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should set the device on the current_resource" do
|
165
|
+
provider.current_resource.device.should == device
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should set the device_type on the current_resource" do
|
169
|
+
provider.current_resource.device_type.should == device_type
|
170
|
+
end
|
171
|
+
|
172
|
+
it "should set the mounted status on the current_resource" do
|
173
|
+
expect(provider.current_resource.mounted).to be_true
|
174
|
+
end
|
175
|
+
|
176
|
+
it "should set the enabled status on the current_resource" do
|
177
|
+
expect(provider.current_resource.enabled).to be_true
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should set the fstype field on the current_resource" do
|
181
|
+
expect(provider.current_resource.fstype).to eql("ufs")
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should set the options field on the current_resource" do
|
185
|
+
expect(provider.current_resource.options).to eql(["-", "noauto"])
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should set the pass field on the current_resource" do
|
189
|
+
expect(provider.current_resource.pass).to eql(2)
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should not throw an exception when the device does not exist - CHEF-1565" do
|
193
|
+
File.stub(:exist?).with(device).and_return(false)
|
194
|
+
expect { provider.load_current_resource }.to_not raise_error
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should not throw an exception when the mount point does not exist" do
|
198
|
+
File.stub(:exist?).with(mountpoint).and_return false
|
199
|
+
expect { provider.load_current_resource }.to_not raise_error
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
context "when the device is an smbfs mount" do
|
204
|
+
let(:mount_output) {
|
205
|
+
<<-EOF.gsub /^\s*/, ''
|
206
|
+
//solarsystem/tmp on /mnt type smbfs read/write/setuid/devices/dev=5080000 on Tue Mar 29 11:40:18 2011
|
207
|
+
EOF
|
208
|
+
}
|
209
|
+
let(:vfstab_file_contents) {
|
210
|
+
<<-EOF.gsub /^\s*/, ''
|
211
|
+
//WORKGROUP;username:password@host/share - /mountpoint smbfs - no fileperms=0777,dirperms=0777
|
212
|
+
EOF
|
213
|
+
}
|
214
|
+
|
215
|
+
it "should work at some point in the future" do
|
216
|
+
pending "SMBFS mounts on solaris look like they will need some future code work and more investigation"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
context "when the device is an NFS mount" do
|
221
|
+
let(:mount_output) {
|
222
|
+
<<-EOF.gsub /^\s*/, ''
|
223
|
+
cartman:/share2 on /cartman type nfs rsize=32768,wsize=32768,NFSv4,dev=4000004 on Tue Mar 29 11:40:18 2011
|
224
|
+
EOF
|
225
|
+
}
|
226
|
+
|
227
|
+
let(:vfstab_file_contents) {
|
228
|
+
<<-EOF.gsub /^\s*/, ''
|
229
|
+
cartman:/share2 - /cartman nfs - yes rw,soft
|
230
|
+
EOF
|
231
|
+
}
|
232
|
+
|
233
|
+
let(:fstype) { "nfs" }
|
234
|
+
|
235
|
+
let(:device) { "cartman:/share2" }
|
236
|
+
|
237
|
+
let(:mountpoint) { "/cartman" }
|
238
|
+
|
239
|
+
before do
|
240
|
+
provider.load_current_resource
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should set the name on the current_resource" do
|
244
|
+
provider.current_resource.name.should == mountpoint
|
245
|
+
end
|
246
|
+
|
247
|
+
it "should set the mount_point on the current_resource" do
|
248
|
+
provider.current_resource.mount_point.should == mountpoint
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should set the device on the current_resource" do
|
252
|
+
provider.current_resource.device.should == device
|
253
|
+
end
|
254
|
+
|
255
|
+
it "should set the device_type on the current_resource" do
|
256
|
+
provider.current_resource.device_type.should == device_type
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should set the mounted status on the current_resource" do
|
260
|
+
expect(provider.current_resource.mounted).to be_true
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should set the enabled status on the current_resource" do
|
264
|
+
expect(provider.current_resource.enabled).to be_true
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should set the fstype field on the current_resource" do
|
268
|
+
expect(provider.current_resource.fstype).to eql("nfs")
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should set the options field on the current_resource" do
|
272
|
+
expect(provider.current_resource.options).to eql(["rw", "soft", "noauto"])
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should set the pass field on the current_resource" do
|
276
|
+
# is this correct or should it be nil?
|
277
|
+
expect(provider.current_resource.pass).to eql(0)
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
281
|
+
|
282
|
+
context "when the device is symlink" do
|
283
|
+
|
284
|
+
let(:target) { "/dev/mapper/target" }
|
285
|
+
|
286
|
+
let(:mount_output) {
|
287
|
+
<<-EOF.gsub /^\s*/, ''
|
288
|
+
#{target} on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012
|
289
|
+
EOF
|
290
|
+
}
|
291
|
+
|
292
|
+
let(:vfstab_file_contents) {
|
293
|
+
<<-EOF.gsub /^\s*/, ''
|
294
|
+
#{target} /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -
|
295
|
+
EOF
|
296
|
+
}
|
297
|
+
|
298
|
+
before do
|
299
|
+
File.should_receive(:symlink?).with(device).at_least(:once).and_return(true)
|
300
|
+
File.should_receive(:readlink).with(device).at_least(:once).and_return(target)
|
301
|
+
|
302
|
+
provider.load_current_resource()
|
303
|
+
end
|
304
|
+
|
305
|
+
it "should set mounted true if the symlink target of the device is found in the mounts list" do
|
306
|
+
expect(provider.current_resource.mounted).to be_true
|
307
|
+
end
|
308
|
+
|
309
|
+
it "should set enabled true if the symlink target of the device is found in the vfstab" do
|
310
|
+
expect(provider.current_resource.enabled).to be_true
|
311
|
+
end
|
312
|
+
|
313
|
+
it "should have the correct mount options" do
|
314
|
+
expect(provider.current_resource.options).to eql(["-", "noauto"])
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
context "when the device is a relative symlink" do
|
319
|
+
let(:target) { "foo" }
|
320
|
+
|
321
|
+
let(:absolute_target) { File.expand_path(target, File.dirname(device)) }
|
322
|
+
|
323
|
+
let(:mount_output) {
|
324
|
+
<<-EOF.gsub /^\s*/, ''
|
325
|
+
#{absolute_target} on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012
|
326
|
+
EOF
|
327
|
+
}
|
328
|
+
|
329
|
+
let(:vfstab_file_contents) {
|
330
|
+
<<-EOF.gsub /^\s*/, ''
|
331
|
+
#{absolute_target} /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -
|
332
|
+
EOF
|
333
|
+
}
|
334
|
+
|
335
|
+
before do
|
336
|
+
File.should_receive(:symlink?).with(device).at_least(:once).and_return(true)
|
337
|
+
File.should_receive(:readlink).with(device).at_least(:once).and_return(target)
|
338
|
+
|
339
|
+
provider.load_current_resource()
|
340
|
+
end
|
341
|
+
|
342
|
+
it "should set mounted true if the symlink target of the device is found in the mounts list" do
|
343
|
+
expect(provider.current_resource.mounted).to be_true
|
344
|
+
end
|
345
|
+
|
346
|
+
it "should set enabled true if the symlink target of the device is found in the vfstab" do
|
347
|
+
expect(provider.current_resource.enabled).to be_true
|
348
|
+
end
|
349
|
+
|
350
|
+
it "should have the correct mount options" do
|
351
|
+
expect(provider.current_resource.options).to eql(["-", "noauto"])
|
352
|
+
end
|
353
|
+
end
|
354
|
+
|
355
|
+
context "when the matching mount point is last in the mounts list" do
|
356
|
+
let(:mount_output) {
|
357
|
+
<<-EOF.gsub /^\s*/, ''
|
358
|
+
/dev/dsk/c0t0d0s0 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012
|
359
|
+
/dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012
|
360
|
+
EOF
|
361
|
+
}
|
362
|
+
it "should set mounted true" do
|
363
|
+
provider.load_current_resource()
|
364
|
+
provider.current_resource.mounted.should be_true
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
context "when the matching mount point is not last in the mounts list" do
|
369
|
+
let(:mount_output) {
|
370
|
+
<<-EOF.gsub /^\s*/, ''
|
371
|
+
/dev/dsk/c0t2d0s7 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012
|
372
|
+
/dev/dsk/c0t0d0s0 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200000 on Tue Jul 31 22:34:46 2012
|
373
|
+
EOF
|
374
|
+
}
|
375
|
+
it "should set mounted false" do
|
376
|
+
provider.load_current_resource()
|
377
|
+
provider.current_resource.mounted.should be_false
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
context "when the matching mount point is not in the mounts list (mountpoint wrong)" do
|
382
|
+
let(:mount_output) {
|
383
|
+
<<-EOF.gsub /^\s*/, ''
|
384
|
+
/dev/dsk/c0t2d0s7 on /mnt/foob type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012
|
385
|
+
EOF
|
386
|
+
}
|
387
|
+
it "should set mounted false" do
|
388
|
+
provider.load_current_resource()
|
389
|
+
provider.current_resource.mounted.should be_false
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
context "when the matching mount point is not in the mounts list (raw device wrong)" do
|
394
|
+
let(:mount_output) {
|
395
|
+
<<-EOF.gsub /^\s*/, ''
|
396
|
+
/dev/dsk/c0t2d0s72 on /mnt/foo type ufs read/write/setuid/intr/largefiles/xattr/onerror=panic/dev=2200007 on Tue Jul 31 22:34:46 2012
|
397
|
+
EOF
|
398
|
+
}
|
399
|
+
it "should set mounted false" do
|
400
|
+
provider.load_current_resource()
|
401
|
+
provider.current_resource.mounted.should be_false
|
402
|
+
end
|
403
|
+
end
|
404
|
+
|
405
|
+
context "when the mount point is last in fstab" do
|
406
|
+
let(:vfstab_file_contents) {
|
407
|
+
<<-EOF.gsub /^\s*/, ''
|
408
|
+
/dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -
|
409
|
+
/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -
|
410
|
+
EOF
|
411
|
+
}
|
412
|
+
|
413
|
+
it "should set enabled to true" do
|
414
|
+
provider.load_current_resource
|
415
|
+
provider.current_resource.enabled.should be_true
|
416
|
+
end
|
417
|
+
end
|
418
|
+
|
419
|
+
context "when the mount point is not last in fstab and is a substring of another mount" do
|
420
|
+
let(:vfstab_file_contents) {
|
421
|
+
<<-EOF.gsub /^\s*/, ''
|
422
|
+
/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -
|
423
|
+
/dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo/bar ufs 2 yes -
|
424
|
+
EOF
|
425
|
+
}
|
426
|
+
|
427
|
+
it "should set enabled to true" do
|
428
|
+
provider.load_current_resource
|
429
|
+
provider.current_resource.enabled.should be_true
|
430
|
+
end
|
431
|
+
end
|
432
|
+
|
433
|
+
context "when the mount point is not last in fstab" do
|
434
|
+
let(:vfstab_file_contents) {
|
435
|
+
<<-EOF.gsub /^\s*/, ''
|
436
|
+
/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -
|
437
|
+
/dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s72 /mnt/foo ufs 2 yes -
|
438
|
+
EOF
|
439
|
+
}
|
440
|
+
|
441
|
+
it "should set enabled to false" do
|
442
|
+
provider.load_current_resource
|
443
|
+
provider.current_resource.enabled.should be_false
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
context "when the mount point is not in fstab, but the mountpoint is a substring of one that is" do
|
448
|
+
let(:vfstab_file_contents) {
|
449
|
+
<<-EOF.gsub /^\s*/, ''
|
450
|
+
/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foob ufs 2 yes -
|
451
|
+
EOF
|
452
|
+
}
|
453
|
+
|
454
|
+
it "should set enabled to false" do
|
455
|
+
provider.load_current_resource
|
456
|
+
provider.current_resource.enabled.should be_false
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
context "when the mount point is not in fstab, but the device is a substring of one that is" do
|
461
|
+
let(:vfstab_file_contents) {
|
462
|
+
<<-EOF.gsub /^\s*/, ''
|
463
|
+
/dev/dsk/c0t2d0s72 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -
|
464
|
+
EOF
|
465
|
+
}
|
466
|
+
|
467
|
+
it "should set enabled to false" do
|
468
|
+
provider.load_current_resource
|
469
|
+
provider.current_resource.enabled.should be_false
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
context "when the mountpoint line is commented out" do
|
474
|
+
let(:vfstab_file_contents) {
|
475
|
+
<<-EOF.gsub /^\s*/, ''
|
476
|
+
#/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -
|
477
|
+
EOF
|
478
|
+
}
|
479
|
+
|
480
|
+
it "should set enabled to false" do
|
481
|
+
provider.load_current_resource
|
482
|
+
provider.current_resource.enabled.should be_false
|
483
|
+
end
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
487
|
+
context "after the mount's state has been discovered" do
|
488
|
+
describe "mount_fs" do
|
489
|
+
it "should mount the filesystem" do
|
490
|
+
provider.should_receive(:shell_out!).with("mount -F #{fstype} -o defaults #{device} #{mountpoint}")
|
491
|
+
provider.mount_fs()
|
492
|
+
end
|
493
|
+
|
494
|
+
it "should mount the filesystem with options if options were passed" do
|
495
|
+
options = "logging,noatime,largefiles,nosuid,rw,quota"
|
496
|
+
new_resource.options(options.split(/,/))
|
497
|
+
provider.should_receive(:shell_out!).with("mount -F #{fstype} -o #{options} #{device} #{mountpoint}")
|
498
|
+
provider.mount_fs()
|
499
|
+
end
|
500
|
+
|
501
|
+
it "should delete the 'noauto' magic option" do
|
502
|
+
options = "rw,noauto"
|
503
|
+
new_resource.options(%w{rw noauto})
|
504
|
+
provider.should_receive(:shell_out!).with("mount -F #{fstype} -o rw #{device} #{mountpoint}")
|
505
|
+
provider.mount_fs()
|
506
|
+
end
|
507
|
+
end
|
508
|
+
|
509
|
+
describe "umount_fs" do
|
510
|
+
it "should umount the filesystem if it is mounted" do
|
511
|
+
provider.should_receive(:shell_out!).with("umount #{mountpoint}")
|
512
|
+
provider.umount_fs()
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
describe "remount_fs" do
|
517
|
+
it "should use mount -o remount" do
|
518
|
+
provider.should_receive(:shell_out!).with("mount -o remount #{new_resource.mount_point}")
|
519
|
+
provider.remount_fs
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
describe "when enabling the fs" do
|
524
|
+
context "in the typical case" do
|
525
|
+
let(:other_mount) { "/dev/dsk/c0t2d0s0 /dev/rdsk/c0t2d0s0 / ufs 2 yes -" }
|
526
|
+
|
527
|
+
let(:this_mount) { "/dev/dsk/c0t2d0s7\t-\t/mnt/foo\tufs\t2\tyes\tdefaults\n" }
|
528
|
+
|
529
|
+
let(:vfstab_file_contents) { [other_mount].join("\n") }
|
530
|
+
|
531
|
+
before do
|
532
|
+
provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab"))
|
533
|
+
provider.load_current_resource
|
534
|
+
provider.enable_fs
|
535
|
+
end
|
536
|
+
|
537
|
+
it "should leave the other mountpoint alone" do
|
538
|
+
IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/)
|
539
|
+
end
|
540
|
+
|
541
|
+
it "should enable the mountpoint we care about" do
|
542
|
+
IO.read(vfstab_file.path).should match(/^#{Regexp.escape(this_mount)}/)
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
546
|
+
context "when the mount has options=noauto" do
|
547
|
+
let(:other_mount) { "/dev/dsk/c0t2d0s0 /dev/rdsk/c0t2d0s0 / ufs 2 yes -" }
|
548
|
+
|
549
|
+
let(:this_mount) { "/dev/dsk/c0t2d0s7\t-\t/mnt/foo\tufs\t2\tno\t-\n" }
|
550
|
+
|
551
|
+
let(:options) { [ "noauto" ] }
|
552
|
+
|
553
|
+
let(:vfstab_file_contents) { [other_mount].join("\n") }
|
554
|
+
|
555
|
+
before do
|
556
|
+
provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab"))
|
557
|
+
provider.load_current_resource
|
558
|
+
provider.enable_fs
|
559
|
+
end
|
560
|
+
|
561
|
+
it "should leave the other mountpoint alone" do
|
562
|
+
IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/)
|
563
|
+
end
|
564
|
+
|
565
|
+
it "should enable the mountpoint we care about" do
|
566
|
+
IO.read(vfstab_file.path).should match(/^#{Regexp.escape(this_mount)}/)
|
567
|
+
end
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
describe "when disabling the fs" do
|
572
|
+
context "in the typical case" do
|
573
|
+
let(:other_mount) { "/dev/dsk/c0t2d0s0 /dev/rdsk/c0t2d0s0 / ufs 2 yes -" }
|
574
|
+
|
575
|
+
let(:this_mount) { "/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -" }
|
576
|
+
|
577
|
+
let(:vfstab_file_contents) { [other_mount, this_mount].join("\n") }
|
578
|
+
|
579
|
+
before do
|
580
|
+
provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab"))
|
581
|
+
provider.disable_fs
|
582
|
+
end
|
583
|
+
|
584
|
+
it "should leave the other mountpoint alone" do
|
585
|
+
IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/)
|
586
|
+
end
|
587
|
+
|
588
|
+
it "should disable the mountpoint we care about" do
|
589
|
+
IO.read(vfstab_file.path).should_not match(/^#{Regexp.escape(this_mount)}/)
|
590
|
+
end
|
591
|
+
end
|
592
|
+
|
593
|
+
context "when there is a commented out line" do
|
594
|
+
let(:other_mount) { "/dev/dsk/c0t2d0s0 /dev/rdsk/c0t2d0s0 / ufs 2 yes -" }
|
595
|
+
|
596
|
+
let(:this_mount) { "/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -" }
|
597
|
+
|
598
|
+
let(:comment) { "#/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -" }
|
599
|
+
|
600
|
+
let(:vfstab_file_contents) { [other_mount, this_mount, comment].join("\n") }
|
601
|
+
|
602
|
+
before do
|
603
|
+
provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab"))
|
604
|
+
provider.disable_fs
|
605
|
+
end
|
606
|
+
|
607
|
+
it "should leave the other mountpoint alone" do
|
608
|
+
IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/)
|
609
|
+
end
|
610
|
+
|
611
|
+
it "should disable the mountpoint we care about" do
|
612
|
+
IO.read(vfstab_file.path).should_not match(/^#{Regexp.escape(this_mount)}/)
|
613
|
+
end
|
614
|
+
|
615
|
+
it "should keep the comment" do
|
616
|
+
IO.read(vfstab_file.path).should match(/^#{Regexp.escape(comment)}/)
|
617
|
+
end
|
618
|
+
end
|
619
|
+
|
620
|
+
context "when there is a duplicated line" do
|
621
|
+
let(:other_mount) { "/dev/dsk/c0t2d0s0 /dev/rdsk/c0t2d0s0 / ufs 2 yes -" }
|
622
|
+
|
623
|
+
let(:this_mount) { "/dev/dsk/c0t2d0s7 /dev/rdsk/c0t2d0s7 /mnt/foo ufs 2 yes -" }
|
624
|
+
|
625
|
+
let(:vfstab_file_contents) { [this_mount, other_mount, this_mount].join("\n") }
|
626
|
+
|
627
|
+
before do
|
628
|
+
provider.stub(:etc_tempfile).and_yield(Tempfile.open("vfstab"))
|
629
|
+
provider.disable_fs
|
630
|
+
end
|
631
|
+
|
632
|
+
it "should leave the other mountpoint alone" do
|
633
|
+
IO.read(vfstab_file.path).should match(/^#{Regexp.escape(other_mount)}/)
|
634
|
+
end
|
635
|
+
|
636
|
+
it "should still match the duplicated mountpoint" do
|
637
|
+
IO.read(vfstab_file.path).should match(/^#{Regexp.escape(this_mount)}/)
|
638
|
+
end
|
639
|
+
|
640
|
+
it "should have removed the last line" do
|
641
|
+
IO.read(vfstab_file.path).should eql( "#{this_mount}\n#{other_mount}\n" )
|
642
|
+
end
|
643
|
+
end
|
644
|
+
end
|
645
|
+
end
|
646
|
+
end
|