summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Edwards <adamed@opscode.com>2014-08-30 22:11:48 -0700
committeradamedx <adamed@getchef.com>2014-09-10 20:28:59 -0700
commiteb918c554e37a61ae5115763a3d016c3918b99b6 (patch)
treeec6206ab39c2be0ce8a002654aae3491f2bdec05
parente6df4bd17a168445f19f70dfeb020f15478a30f8 (diff)
downloadchef-eb918c554e37a61ae5115763a3d016c3918b99b6.tar.gz
Set exit code from start-dscconfiguraiton to enable identification of DSC errors
-rw-r--r--lib/chef/util/dsc/local_configuration_manager.rb23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/chef/util/dsc/local_configuration_manager.rb b/lib/chef/util/dsc/local_configuration_manager.rb
index 79cfcd2996..959d5ef829 100644
--- a/lib/chef/util/dsc/local_configuration_manager.rb
+++ b/lib/chef/util/dsc/local_configuration_manager.rb
@@ -57,7 +57,7 @@ class Chef::Util::DSC
test_only_parameters = ! apply_configuration ? '-whatif; if (! $?) { exit 1 }' : ''
start_operation_timing
- command_code = "$ProgressPreference = 'SilentlyContinue';start-dscconfiguration -path #{@configuration_path} -wait -force #{test_only_parameters}"
+ command_code = lcm_command_code(@configuration_path, test_only_parameters)
status = nil
begin
@@ -79,6 +79,27 @@ class Chef::Util::DSC
status
end
+ def lcm_command_code(configuration_path, test_only_parameters)
+ <<-EOH
+try
+{
+ $ProgressPreference = 'SilentlyContinue';start-dscconfiguration -path #{@configuration_path} -wait -force #{test_only_parameters} -erroraction 'Stop'
+}
+catch [Microsoft.Management.Infrastructure.CimException]
+{
+ $exception = $_.Exception
+ write-error -Exception $exception
+ $StatusCode = 1
+ if ( $exception.HResult -ne 0 )
+ {
+ $StatusCode = $exception.HResult
+ }
+ $exception | format-table -property * -force
+ exit $StatusCode
+}
+EOH
+ end
+
def configuration_update_required?(what_if_output)
Chef::Log.debug("DSC: DSC returned the following '-whatif' output from test operation:\n#{what_if_output}")
begin