From 2c8d90c0eea2b014aba1699c677d9d42c850746b Mon Sep 17 00:00:00 2001 From: Jay Mundrawala Date: Thu, 3 Dec 2015 21:34:29 -0800 Subject: Add timeout attribute to dsc_resource `dsc_resource` was missing a timeout resource. Some resources, such as `xSQLServerSetup` were taking longer than the default of 10 minuites set by mixlib-shellout. Fixes #4232 --- lib/chef/provider/dsc_resource.rb | 2 +- lib/chef/resource/dsc_resource.rb | 10 +++++++++- spec/unit/resource/dsc_resource_spec.rb | 8 +++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/chef/provider/dsc_resource.rb b/lib/chef/provider/dsc_resource.rb index efbe4eccef..fd25a14ea5 100644 --- a/lib/chef/provider/dsc_resource.rb +++ b/lib/chef/provider/dsc_resource.rb @@ -154,7 +154,7 @@ class Chef "Invoke-DscResource #{switches}", output_format ) - cmdlet.run! + cmdlet.run!({}, {:timeout => new_resource.timeout}) end def return_dsc_resource_result(result, property_name) diff --git a/lib/chef/resource/dsc_resource.rb b/lib/chef/resource/dsc_resource.rb index 1dcde8de96..0664dc7d7f 100644 --- a/lib/chef/resource/dsc_resource.rb +++ b/lib/chef/resource/dsc_resource.rb @@ -89,7 +89,7 @@ class Chef # This property takes the action message for the reboot resource # If the set method of the DSC resource indicate that a reboot - # is necessary, reboot_action provides the mechanism for a reboot to + # is necessary, reboot_action provides the mechanism for a reboot to # be requested. def reboot_action(value=nil) if value @@ -98,6 +98,14 @@ class Chef @reboot_action end end + + def timeout(arg=nil) + set_or_return( + :timeout, + arg, + :kind_of => [ Integer ] + ) + end private def value_of(value) diff --git a/spec/unit/resource/dsc_resource_spec.rb b/spec/unit/resource/dsc_resource_spec.rb index 6fa74a139f..276aa74111 100644 --- a/spec/unit/resource/dsc_resource_spec.rb +++ b/spec/unit/resource/dsc_resource_spec.rb @@ -21,6 +21,7 @@ describe Chef::Resource::DscResource do let(:dsc_test_property_name) { :DSCTestProperty } let(:dsc_test_property_value) { 'DSCTestValue' } let(:dsc_test_reboot_action) { :reboot_now } + let(:dsc_test_timeout) { 101 } context 'when Powershell supports Dsc' do let(:dsc_test_run_context) { @@ -57,6 +58,11 @@ describe Chef::Resource::DscResource do expect(dsc_test_resource.reboot_action).to eq(dsc_test_reboot_action) end + it "allows the timeout attribute to be set" do + dsc_test_resource.timeout(dsc_test_timeout) + expect(dsc_test_resource.timeout).to eq(dsc_test_timeout) + end + context "when setting a dsc property" do it "allows setting a dsc property with a property name of type Symbol" do dsc_test_resource.property(dsc_test_property_name, dsc_test_property_value) @@ -87,4 +93,4 @@ describe Chef::Resource::DscResource do end end end -end \ No newline at end of file +end -- cgit v1.2.1