Skip to content
This repository has been archived by the owner on Jan 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #491 from ripienaar/446
Browse files Browse the repository at this point in the history
(#446) Compensate for inconsistent result shape from Puppet Server
  • Loading branch information
ripienaar committed May 5, 2018
2 parents 76c2a12 + a94f0cb commit b2e5eb2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/mcollective/util/tasks_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,13 @@ def task_metadata(task, environment)

raise("Failed to request task metadata: %s: %s" % [resp.code, resp.body]) unless resp.code == "200"

JSON.parse(resp.body)
result = JSON.parse(resp.body)

result["metadata"] ||= {}
result["metadata"]["parameters"] ||= {}
result["files"] ||= []

result
end

# Validates that the inputs would be acceptable to the task
Expand Down
7 changes: 7 additions & 0 deletions spec/unit/mcollective/util/tasks_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,13 @@ module Util
ts.task_metadata("choria::ls", "production")
end.to raise_error("Failed to request task metadata: 404: Could not find module 'choria'")
end

it "should normalize results" do
stub_request(:get, "https://stubpuppet:8140/puppet/v3/tasks/choria/ls?environment=production")
.to_return(:status => 200, :body => {}.to_json)

expect(ts.task_metadata("choria::ls", "production")).to eq("files" => [], "metadata" => {"parameters" => {}})
end
end

describe "#http_get" do
Expand Down

0 comments on commit b2e5eb2

Please sign in to comment.