summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-05-27 11:36:03 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2014-05-28 16:59:27 -0700
commit29b0fb81525b5f5a1d198f0c3efae4357abf2d3a (patch)
tree4839cc590c3663ba5654e71f0c3964a98c25886e
parentd8f99d114fc1f8dd2968d353e9aadd82e78fede7 (diff)
downloadchef-29b0fb81525b5f5a1d198f0c3efae4357abf2d3a.tar.gz
spec test the retry failure loop
- create an accessor for dependency injection - make sure that it raises when it runs out of retries
-rw-r--r--lib/chef/provider/mount.rb13
-rw-r--r--spec/unit/provider/mount_spec.rb7
2 files changed, 17 insertions, 3 deletions
diff --git a/lib/chef/provider/mount.rb b/lib/chef/provider/mount.rb
index c80855c5a7..b46604260e 100644
--- a/lib/chef/provider/mount.rb
+++ b/lib/chef/provider/mount.rb
@@ -27,6 +27,8 @@ class Chef
include Chef::Mixin::Command
+ attr_accessor :unmount_retries
+
def whyrun_supported?
true
end
@@ -35,6 +37,11 @@ class Chef
true
end
+ def initialize(new_resource, run_context)
+ super
+ self.unmount_retries = 20
+ end
+
def action_mount
unless current_resource.mounted
converge_by("mount #{current_resource.device} to #{current_resource.mount_point}") do
@@ -69,7 +76,7 @@ class Chef
umount_fs
Chef::Log.info("#{new_resource} unmounted")
end
- wait_until_unmounted
+ wait_until_unmounted(unmount_retries)
converge_by("mount #{current_resource.device}") do
mount_fs
Chef::Log.info("#{new_resource} mounted")
@@ -150,9 +157,9 @@ class Chef
private
- def wait_until_unmounted(tries = 20)
+ def wait_until_unmounted(tries)
while mounted?
- if (tries -= 1) == 0
+ if (tries -= 1) < 0
raise Chef::Exceptions::Mount, "Retries exceeded waiting for filesystem to unmount"
end
sleep 0.1
diff --git a/spec/unit/provider/mount_spec.rb b/spec/unit/provider/mount_spec.rb
index 9181595c7f..e9fe3fa050 100644
--- a/spec/unit/provider/mount_spec.rb
+++ b/spec/unit/provider/mount_spec.rb
@@ -120,7 +120,14 @@ describe Chef::Provider::Mount do
expect(new_resource).to be_updated_by_last_action
end
+ it "should fail when it runs out of remounts" do
+ provider.unmount_retries = 1
+ expect(provider).to receive(:umount_fs)
+ expect(provider).to receive(:mounted?).and_return(true, true)
+ expect{ provider.run_action(:remount) }.to raise_error(Chef::Exceptions::Mount)
+ end
end
+
describe "when enabling the filesystem to be mounted" do
it "should enable the mount if it isn't enable" do
allow(current_resource).to receive(:enabled).and_return(false)