Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle REXML exception #528

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading