Skip to content

Commit 715ca06

Browse files
Avishai Ish-Shalomdanielsdeleo
authored andcommitted
Fixes CHEF-187
1 parent 45432c7 commit 715ca06

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

‎chef/lib/chef/provider/mount/mount.rb‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def load_current_resource
3939
Chef::Log.debug("Checking for mount point #{@current_resource.mount_point}")
4040

4141
# only check for existence of non-remote devices
42-
if(@new_resource.device !~ /:/ && @new_resource.device !~ /\/\// && !::File.exists?(@new_resource.device) )
42+
if(@new_resource.device !~ /:/ && @new_resource.device !~ /\/\// && !::File.exists?(device_real) )
4343
raise Chef::Exceptions::Mount, "Device #{@new_resource.device} does not exist"
4444
elsif( !::File.exists?(@new_resource.mount_point) )
4545
raise Chef::Exceptions::Mount, "Mount point #{@new_resource.mount_point} does not exist"
@@ -84,7 +84,14 @@ def mount_fs
8484
unless @current_resource.mounted
8585
command = "mount -t #{@new_resource.fstype}"
8686
command << " -o #{@new_resource.options.join(',')}" unless @new_resource.options.nil? || @new_resource.options.empty?
87-
command << " #{device_real}"
87+
command << case @new_resource.device_type
88+
when :device
89+
" #{device_real}"
90+
when :label
91+
" -L #{@new_resource.device}"
92+
when :uuid
93+
" -U #{@new_resource.device}"
94+
end
8895
command << " #{@new_resource.mount_point}"
8996
shell_out!(command)
9097
Chef::Log.info("Mounted #{@new_resource.mount_point}")
@@ -174,11 +181,10 @@ def device_real
174181
if @new_resource.device_type == :device
175182
@real_device = @new_resource.device
176183
else
184+
@real_device = ""
177185
status = popen4("/sbin/findfs #{device_fstab}") do |pid, stdin, stdout, stderr|
178-
@real_device = stdout.first.chomp
179-
end
180-
unless status.exitstatus == 0
181-
@real_device = "/dev/null"
186+
device_line = stdout.first # stdout.first consumes
187+
@real_device = device_line.chomp unless device_line.nil?
182188
end
183189
end
184190
end

‎chef/spec/unit/provider/mount/mount_spec.rb‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,35 @@
4949
@provider.current_resource.mount_point.should == '/tmp/foo'
5050
@provider.current_resource.device.should == '/dev/sdz1'
5151
end
52+
53+
it "should accecpt device_type :uuid" do
54+
@new_resource.device_type :uuid
55+
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
56+
@stdout_findfs = mock("STDOUT", :first => "/dev/sdz1")
57+
@provider.should_receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status)
58+
@provider.load_current_resource()
59+
end
5260

5361
it "should raise an error if the mount device does not exist" do
5462
::File.stub!(:exists?).with("/dev/sdz1").and_return false
5563
lambda { @provider.load_current_resource() }.should raise_error(Chef::Exceptions::Mount)
5664
end
57-
65+
66+
it "should raise an error if the mount device (uuid) does not exist" do
67+
@new_resource.device_type :uuid
68+
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
69+
status_findfs = mock("Status", :exitstatus => 1)
70+
stdout_findfs = mock("STDOUT", :first => nil)
71+
@provider.should_receive(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,stdout_findfs,@stderr).and_return(status_findfs)
72+
::File.should_receive(:exists?).with("").and_return(false)
73+
lambda { @provider.load_current_resource() }.should raise_error(Chef::Exceptions::Mount)
74+
end
75+
5876
it "should raise an error if the mount point does not exist" do
5977
::File.stub!(:exists?).with("/tmp/foo").and_return false
6078
lambda { @provider.load_current_resource() }.should raise_error(Chef::Exceptions::Mount)
6179
end
6280

63-
6481
it "should set mounted true if the mount point is found in the mounts list" do
6582
@provider.stub!(:shell_out!).and_return(OpenStruct.new(:stdout => '/dev/sdz1 on /tmp/foo'))
6683
@provider.load_current_resource()
@@ -175,6 +192,16 @@
175192
@provider.should_receive(:shell_out!).with("mount -t ext3 -o rw,noexec,noauto /dev/sdz1 /tmp/foo")
176193
@provider.mount_fs()
177194
end
195+
196+
it "should mount the filesystem specified by uuid" do
197+
@new_resource.device "d21afe51-a0fe-4dc6-9152-ac733763ae0a"
198+
@new_resource.device_type :uuid
199+
@stdout_findfs = mock("STDOUT", :first => "/dev/sdz1")
200+
@provider.stub!(:popen4).with("/sbin/findfs UUID=d21afe51-a0fe-4dc6-9152-ac733763ae0a").and_yield(@pid,@stdin,@stdout_findfs,@stderr).and_return(@status)
201+
@stdout.stub!(:each).and_yield("#{@new_resource.device} on #{@new_resource.mount_point}")
202+
@provider.should_receive(:shell_out!).with("mount -t #{@new_resource.fstype} -o defaults -U #{@new_resource.device} #{@new_resource.mount_point}")
203+
@provider.mount_fs()
204+
end
178205

179206
it "should not mount the filesystem if it is mounted" do
180207
@current_resource.stub!(:mounted).and_return(true)

0 commit comments

Comments
 (0)