summaryrefslogtreecommitdiff
path: root/lib/chef/util/dsc/local_configuration_manager.rb
diff options
context:
space:
mode:
authorJay Mundrawala <jdmundrawala@gmail.com>2014-08-22 14:49:53 -0700
committerJay Mundrawala <jdmundrawala@gmail.com>2014-09-19 12:47:34 -0700
commit31f0e0a53d82d4cab7b607e367dec5ec6104847c (patch)
tree0e9125f44d2a004715261673878a055d2e8ef68a /lib/chef/util/dsc/local_configuration_manager.rb
parent7e5daa0ef8486275c82e694d1862d56b5a21f417 (diff)
downloadchef-31f0e0a53d82d4cab7b607e367dec5ec6104847c.tar.gz
Deal with LCM failing when a resource does not support WhatIf
Diffstat (limited to 'lib/chef/util/dsc/local_configuration_manager.rb')
-rw-r--r--lib/chef/util/dsc/local_configuration_manager.rb26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/chef/util/dsc/local_configuration_manager.rb b/lib/chef/util/dsc/local_configuration_manager.rb
index d7d532a686..79cfcd2996 100644
--- a/lib/chef/util/dsc/local_configuration_manager.rb
+++ b/lib/chef/util/dsc/local_configuration_manager.rb
@@ -26,12 +26,20 @@ class Chef::Util::DSC
@configuration_path = configuration_path
clear_execution_time
end
-
+
def test_configuration(configuration_document)
status = run_configuration_cmdlet(configuration_document)
+ unless status.succeeded?
+ # LCM returns an error if any of the resources do not support the opptional What-If
+ if status.stderr.gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/
+ Chef::Log::warn("Received error while testing configuration due to resource not supporting 'WhatIf'")
+ else
+ raise Chef::Exceptions::PowershellCmdletException, "Powershell Cmdlet failed: #{status.stderr.gsub(/\s+/, ' ')}"
+ end
+ end
configuration_update_required?(status.return_value)
end
-
+
def set_configuration(configuration_document)
run_configuration_cmdlet(configuration_document, true)
end
@@ -55,7 +63,11 @@ class Chef::Util::DSC
begin
save_configuration_document(configuration_document)
cmdlet = ::Chef::Util::Powershell::Cmdlet.new(@node, "#{command_code}")
- status = cmdlet.run
+ if apply_configuration
+ status = cmdlet.run!
+ else
+ status = cmdlet.run
+ end
ensure
end_operation_timing
remove_configuration_document
@@ -69,8 +81,12 @@ class Chef::Util::DSC
def configuration_update_required?(what_if_output)
Chef::Log.debug("DSC: DSC returned the following '-whatif' output from test operation:\n#{what_if_output}")
- #parse_what_if_output(what_if_output)
- Parser::parse(what_if_output)
+ begin
+ Parser::parse(what_if_output)
+ rescue Chef::Util::DSC::LocalConfigurationManager::Parser => e
+ Chef::Log::warn("Could not parse parse LCM output: #{e}")
+ [Chef::Util::DSC::ResourceInfo.new('Unknown DSC Resources', true, ['Unknown changes because LCM output was not parsable.'])]
+ end
end
def save_configuration_document(configuration_document)