summaryrefslogtreecommitdiff
path: root/lib/chef/util/dsc
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
parent7e5daa0ef8486275c82e694d1862d56b5a21f417 (diff)
downloadchef-31f0e0a53d82d4cab7b607e367dec5ec6104847c.tar.gz
Deal with LCM failing when a resource does not support WhatIf
Diffstat (limited to 'lib/chef/util/dsc')
-rw-r--r--lib/chef/util/dsc/configuration_generator.rb2
-rw-r--r--lib/chef/util/dsc/lcm_output_parser.rb10
-rw-r--r--lib/chef/util/dsc/local_configuration_manager.rb26
3 files changed, 30 insertions, 8 deletions
diff --git a/lib/chef/util/dsc/configuration_generator.rb b/lib/chef/util/dsc/configuration_generator.rb
index 98b4a8bbf4..9f8c0e7309 100644
--- a/lib/chef/util/dsc/configuration_generator.rb
+++ b/lib/chef/util/dsc/configuration_generator.rb
@@ -44,7 +44,7 @@ class Chef::Util::DSC
merged_configuration_flags = get_merged_configuration_flags!(configuration_flags, configuration_name)
- document_generation_cmdlet.run(merged_configuration_flags, shellout_flags)
+ document_generation_cmdlet.run!(merged_configuration_flags, shellout_flags)
configuration_document_location = find_configuration_document(configuration_name)
if ! configuration_document_location
diff --git a/lib/chef/util/dsc/lcm_output_parser.rb b/lib/chef/util/dsc/lcm_output_parser.rb
index 420901bcfa..6532d79d6f 100644
--- a/lib/chef/util/dsc/lcm_output_parser.rb
+++ b/lib/chef/util/dsc/lcm_output_parser.rb
@@ -16,6 +16,7 @@
# limitations under the License.
#
+require 'chef/log'
require 'chef/util/dsc/resource_info'
class Chef
@@ -110,6 +111,10 @@ class Chef
when :test
stack[-1].add_test(new_op)
when :resource
+ while stack[-1].op_type != :set
+ Chef::Log.warn("Can't add resource to set...popping until it is allowed.")
+ popped_op = stack.pop
+ end
stack[-1].add_resource(new_op)
else
Chef::Log.warn("Unknown op_action #{op_action}: Read line #{line}")
@@ -118,8 +123,9 @@ class Chef
when :end
popped_op = stack.pop
popped_op.add_info(info)
- if popped_op.op_type != op_type
- raise LCMOutputParseException, "Unmatching end for op_type. Expected op_type=#{op_type}, found op_type=#{popped_op.op_type}"
+ while popped_op.op_type != op_type
+ Chef::Log::warn("Unmatching end for op_type. Expected op_type=#{op_type}, found op_type=#{popped_op.op_type}. From output:\n#{lcm_output}")
+ popped_op = stack.pop
end
when :skip
# We don't really have anything to do here
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)