diff --git a/Gemfile b/Gemfile index 638548b1..810a5a3d 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,10 @@ if ENV["GEMFILE_MOD"] puts "GEMFILE_MOD: #{ENV["GEMFILE_MOD"]}" instance_eval(ENV["GEMFILE_MOD"]) else - gem "ohai", git: "https://github.com/chef/ohai", branch: "main" + # changed to 18-stable given that it's the newest compatible with + # the latest knife (and knife is embedded in chef so can't just point at + # GitHub) + gem "ohai", git: "https://github.com/chef/ohai", branch: "18-stable" gem "knife" end diff --git a/lib/chef/knife/wsman_test.rb b/lib/chef/knife/wsman_test.rb index 23eb08dc..3932cb8d 100644 --- a/lib/chef/knife/wsman_test.rb +++ b/lib/chef/knife/wsman_test.rb @@ -98,12 +98,16 @@ def parse_response(node, response) if response.nil? || response.status_code != 200 output_object.error_message = "No valid WSMan endoint listening at #{node.endpoint}." else - doc = REXML::Document.new(response.body) - output_object.protocol_version = search_xpath(doc, "//wsmid:ProtocolVersion") - output_object.product_version = search_xpath(doc, "//wsmid:ProductVersion") - output_object.product_vendor = search_xpath(doc, "//wsmid:ProductVendor") - if output_object.protocol_version.to_s.strip.length == 0 - output_object.error_message = "Endpoint #{node.endpoint} on #{node.host} does not appear to be a WSMAN endpoint. Response body was #{response.body}" + begin + doc = REXML::Document.new(response.body) + output_object.protocol_version = search_xpath(doc, "//wsmid:ProtocolVersion") + output_object.product_version = search_xpath(doc, "//wsmid:ProductVersion") + output_object.product_vendor = search_xpath(doc, "//wsmid:ProductVendor") + if output_object.protocol_version.to_s.strip.length == 0 + output_object.error_message = "Endpoint #{node.endpoint} on #{node.host} does not appear to be a WSMAN endpoint. Response body was #{response.body}" + end + rescue REXML::ParseException => e + output_object.error_message = e.message end end output_object