Skip to content

Commit

Permalink
Merge pull request #528 from chef/tp/handle-3.3.4-exception
Browse files Browse the repository at this point in the history
Handle REXML exception
  • Loading branch information
tpowell-progress authored Aug 12, 2024
2 parents f7b2972 + d2a3138 commit dd1de21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 10 additions & 6 deletions lib/chef/knife/wsman_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dd1de21

Please sign in to comment.