Permalink
Browse files

refs CHEF-2880 adds feature for warn on rc-policy.d, and error if

attribute is set on service resource.
  • Loading branch information...
1 parent 06362c1 commit 6c48d4e6f29dcf38587a79125362d6d31a8b4421 @gpapilion committed Jan 21, 2012
@@ -27,8 +27,26 @@ class Invokercd < Chef::Provider::Service::Init
def initialize(new_resource, run_context)
super
- @init_command = "/usr/sbin/invoke-rc.d #{@new_resource.service_name}"
+ # cause chef to fail for policy violations
+ if @new_resource.error_on_policy_violation
+ @init_command = "/usr/sbin/invoke-rc.d --disclose-deny #{@new_resource.service_name}"
+ else
+ @init_command = "/usr/sbin/invoke-rc.d #{@new_resource.service_name}"
+ end
+ @policy_command = "/usr/sbin/policy-rc.d #{@new_resource.service_name}"
+ if ::File.exists?("/usr/sbin/policy-rc.d")
+ test_policy()
+ end
end
+
+ def test_policy
+ policy_status = run_command(:command => "#{@policy_command} start", :ignore_failure => "true")
+ if policy_status != 0
+ Chef::Log.warn("#{@policy_command} returned non-zero(#{policy_status}) exit status")
+ Chef::Log.warn("#{@new_resource} will likely fail to start/stop silently")
+ end
+ end
+
end
end
end
@@ -38,8 +38,9 @@ def initialize(name, run_context=nil)
@action = "nothing"
@startup_type = :automatic
@supports = { :restart => false, :reload => false, :status => false }
+ @error_on_policy_violation = false
@allowed_actions.push(:enable, :disable, :start, :stop, :restart, :reload)
- end
+end
def service_name(arg=nil)
set_or_return(
@@ -119,6 +120,14 @@ def running(arg=nil)
:kind_of => [ TrueClass, FalseClass ]
)
end
+
+ def error_on_policy_violation(arg=nil)
+ set_or_return(
+ :error_on_policy_violation,
+ arg,
+ :kind_of => [ TrueClass, FalseClass ]
+ )
+ end
# Priority arguments can have two forms:
#
@@ -161,6 +161,7 @@
end
describe "when restarting a service" do
+
it "should call 'restart' on the service_name if the resource supports it" do
@new_resource.supports({:restart => true})
@provider.should_receive(:run_command).with({:command => "/usr/sbin/invoke-rc.d #{@new_resource.service_name} restart"}).and_return(0)
@@ -194,4 +195,16 @@
@provider.reload_service()
end
end
+
+ describe "when the error_on_policy_violation is set to true" do
+ it "should run with flag" do
+ @new_resource.error_on_policy_violation(true)
+ @provider = Chef::Provider::Service::Invokercd.new(@new_resource, @run_context)
+ @provider.load_current_resource
+ @provider.should_receive(:run_command).with({:command => "/usr/sbin/invoke-rc.d --disclose-deny #{@new_resource.service_name} start"}).and_return(0)
+ @provider.start_service()
+ end
+ end
+
+
end
@@ -108,7 +108,7 @@
}.should raise_error(ArgumentError)
end
- %w{enabled running}.each do |attrib|
+ %w{enabled running error_on_policy_violation}.each do |attrib|
it "should accept true for #{attrib}" do
@resource.send(attrib, true)
@resource.send(attrib).should eql(true)
@@ -140,5 +140,6 @@
@resource.supports(support_hash)
@resource.supports.should == support_hash
end
+
end
end

0 comments on commit 6c48d4e

Please sign in to comment.