summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/provider/dsc_script.rb16
-rw-r--r--lib/chef/util/dsc/local_configuration_manager.rb14
-rw-r--r--spec/unit/util/dsc/local_configuration_manager_spec.rb10
3 files changed, 23 insertions, 17 deletions
diff --git a/lib/chef/provider/dsc_script.rb b/lib/chef/provider/dsc_script.rb
index d1f62d7f0d..c183f871e9 100644
--- a/lib/chef/provider/dsc_script.rb
+++ b/lib/chef/provider/dsc_script.rb
@@ -32,11 +32,11 @@ class Chef
@dsc_resource = dsc_resource
@resource_converged = false
@operations = {
- :set => Proc.new { |config_manager, document|
- config_manager.set_configuration(document)
+ :set => Proc.new { |config_manager, document, shellout_flags|
+ config_manager.set_configuration(document, shellout_flags)
},
- :test => Proc.new { |config_manager, document|
- config_manager.test_configuration(document)
+ :test => Proc.new { |config_manager, document, shellout_flags|
+ config_manager.test_configuration(document, shellout_flags)
}}
end
@@ -89,9 +89,15 @@ class Chef
config_manager = Chef::Util::DSC::LocalConfigurationManager.new(@run_context.node, config_directory)
+ shellout_flags = {
+ :cwd => @dsc_resource.cwd,
+ :environment => @dsc_resource.environment,
+ :timeout => @dsc_resource.timeout
+ }
+
begin
configuration_document = generate_configuration_document(config_directory, configuration_flags)
- @operations[operation].call(config_manager, configuration_document)
+ @operations[operation].call(config_manager, configuration_document, shellout_flags)
rescue Exception => e
Chef::Log.error("DSC operation failed: #{e.message.to_s}")
raise e
diff --git a/lib/chef/util/dsc/local_configuration_manager.rb b/lib/chef/util/dsc/local_configuration_manager.rb
index c3149429f9..f8398341e5 100644
--- a/lib/chef/util/dsc/local_configuration_manager.rb
+++ b/lib/chef/util/dsc/local_configuration_manager.rb
@@ -27,14 +27,14 @@ class Chef::Util::DSC
clear_execution_time
end
- def test_configuration(configuration_document)
- status = run_configuration_cmdlet(configuration_document)
+ def test_configuration(configuration_document, shellout_flags)
+ status = run_configuration_cmdlet(configuration_document, false, shellout_flags)
log_what_if_exception(status.stderr) unless status.succeeded?
configuration_update_required?(status.return_value)
end
- def set_configuration(configuration_document)
- run_configuration_cmdlet(configuration_document, true)
+ def set_configuration(configuration_document, shellout_flags)
+ run_configuration_cmdlet(configuration_document, true, shellout_flags)
end
def last_operation_execution_time_seconds
@@ -45,7 +45,7 @@ class Chef::Util::DSC
private
- def run_configuration_cmdlet(configuration_document, apply_configuration = false)
+ def run_configuration_cmdlet(configuration_document, apply_configuration, shellout_flags)
Chef::Log.debug("DSC: Calling DSC Local Config Manager to #{apply_configuration ? "set" : "test"} configuration document.")
test_only_parameters = ! apply_configuration ? '-whatif; if (! $?) { exit 1 }' : ''
@@ -57,9 +57,9 @@ class Chef::Util::DSC
save_configuration_document(configuration_document)
cmdlet = ::Chef::Util::Powershell::Cmdlet.new(@node, "#{command_code}")
if apply_configuration
- status = cmdlet.run!
+ status = cmdlet.run!({}, shellout_flags)
else
- status = cmdlet.run
+ status = cmdlet.run({}, shellout_flags)
end
ensure
end_operation_timing
diff --git a/spec/unit/util/dsc/local_configuration_manager_spec.rb b/spec/unit/util/dsc/local_configuration_manager_spec.rb
index 1281862e67..1cff9e445b 100644
--- a/spec/unit/util/dsc/local_configuration_manager_spec.rb
+++ b/spec/unit/util/dsc/local_configuration_manager_spec.rb
@@ -65,7 +65,7 @@ EOH
let(:lcm_cmdlet_success) { true }
it 'should successfully return resource information for normally formatted output when cmdlet the cmdlet succeeds' do
- test_configuration_result = lcm.test_configuration('config')
+ test_configuration_result = lcm.test_configuration('config', {})
expect(test_configuration_result.class).to be(Array)
expect(test_configuration_result.length).to be > 0
expect(Chef::Log).not_to receive(:warn)
@@ -85,7 +85,7 @@ EOH
expect(Chef::Log).to receive(:warn).at_least(:once)
expect(lcm).to receive(:whatif_not_supported?).and_call_original
test_configuration_result = nil
- expect {test_configuration_result = lcm.test_configuration('config')}.not_to raise_error
+ expect {test_configuration_result = lcm.test_configuration('config', {})}.not_to raise_error
expect(test_configuration_result.class).to be(Array)
end
end
@@ -99,13 +99,13 @@ EOH
expect(Chef::Log).to receive(:warn).at_least(:once)
expect(lcm).to receive(:dsc_module_import_failure?).and_call_original
test_configuration_result = nil
- expect {test_configuration_result = lcm.test_configuration('config')}.not_to raise_error
+ expect {test_configuration_result = lcm.test_configuration('config', {})}.not_to raise_error
end
it 'should return a (possibly empty) array of ResourceInfo instances' do
expect(Chef::Log).to receive(:warn).at_least(:once)
test_configuration_result = nil
- expect {test_configuration_result = lcm.test_configuration('config')}.not_to raise_error
+ expect {test_configuration_result = lcm.test_configuration('config', {})}.not_to raise_error
expect(test_configuration_result.class).to be(Array)
end
end
@@ -118,7 +118,7 @@ EOH
it 'should log a warning' do
expect(Chef::Log).to receive(:warn).at_least(:once)
expect(lcm).to receive(:dsc_module_import_failure?).and_call_original
- expect {lcm.test_configuration('config')}.not_to raise_error
+ expect {lcm.test_configuration('config', {})}.not_to raise_error
end
end
end