Paired-with: Jesse Wolfe <[email protected]>
Signed-off-by: Paul Berry <[email protected]>
---
Local-branch: ticket/next/5743
app/models/report.rb | 16 +++++++++-------
lib/puppet/report.rb | 5 ++++-
lib/report_transformer.rb | 4 ++--
spec/lib/puppet/report_spec.rb | 24 ++++++++++++------------
spec/lib/report_transformer_spec.rb | 4 ++--
5 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/app/models/report.rb b/app/models/report.rb
index fa12ecd..364d239 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -95,16 +95,18 @@ class Report < ActiveRecord::Base
end
def self.create_from_yaml(report_yaml)
- raw_report = YAML.load(report_yaml)
+ raw_report = YAML.load(report_yaml)
- unless raw_report.is_a? Puppet::Transaction::Report
- raise ArgumentError, "The supplied report is in invalid format
'#{raw_report.class}', expected 'Puppet::Transaction::Report'"
- end
+ unless raw_report.is_a? Puppet::Transaction::Report
+ raise ArgumentError, "The supplied report is in invalid format
'#{raw_report.class}', expected 'Puppet::Transaction::Report'"
+ end
+
+ raw_report.extend(ReportExtensions)
+ report_hash = ReportTransformer.apply(raw_report.to_hash)
- raw_report.extend(ReportExtensions)
- report_hash = ReportTransformer.apply(raw_report.to_hash)
+ report_hash["resource_statuses"] = report_hash["resource_statuses"].values
- Report.create!(Report.attribute_hash_from(report_hash))
+ Report.create!(Report.attribute_hash_from(report_hash))
end
def assign_to_node
diff --git a/lib/puppet/report.rb b/lib/puppet/report.rb
index 376e544..5eab787 100644
--- a/lib/puppet/report.rb
+++ b/lib/puppet/report.rb
@@ -142,7 +142,10 @@ module ReportExtensions #:nodoc:
def to_hash
hash = super
- hash["resource_statuses"] = resource_statuses.values.map(&:to_hash)
+ hash["resource_statuses"] = {}
+ resource_statuses.each do |key, value|
+ hash["resource_statuses"][key] = value.to_hash
+ end
hash
end
diff --git a/lib/report_transformer.rb b/lib/report_transformer.rb
index f6b5096..b326347 100644
--- a/lib/report_transformer.rb
+++ b/lib/report_transformer.rb
@@ -30,7 +30,7 @@ class ReportTransformer::ZeroToOne <
ReportTransformer::ReportTransformation
end
def self.transform(report)
- report["resource_statuses"] = []
+ report["resource_statuses"] = {}
report["kind"] = "apply"
report["configuration_version"] =
configuration_version_from_log_objects(report) ||
configuration_version_from_log_message(report)
report["puppet_version"] = "0.25.x"
@@ -67,7 +67,7 @@ class ReportTransformer::OneToTwo <
ReportTransformer::ReportTransformation
end
report["status"] = failed_resources?(report) ? 'failed' :
changed_resources?(report) ? 'changed' : 'unchanged'
- report["resource_statuses"].each do |resource_status|
+ report["resource_statuses"].values.each do |resource_status|
resource_status.delete("version")
end
report["logs"].each do |log|
diff --git a/spec/lib/puppet/report_spec.rb b/spec/lib/puppet/report_spec.rb
index c499048..ce1b97c 100644
--- a/spec/lib/puppet/report_spec.rb
+++ b/spec/lib/puppet/report_spec.rb
@@ -215,10 +215,10 @@ describe Puppet::Transaction::Report do
it "should include the resource statuses and events" do
hash = @report.to_hash
- hash["resource_statuses"].should be_an(Array)
+ hash["resource_statuses"].should be_a(Hash)
resource_statuses = hash["resource_statuses"]
- resource_statuses.should =~ [
- {
+ resource_statuses.should == {
+ "Schedule[monthly]" => {
"line" => nil,
"change_count" => 0,
"resource_type" => "Schedule",
@@ -235,7 +235,7 @@ describe Puppet::Transaction::Report do
"events" => [],
"version" => 1279826342
},
- {
+ "Filebucket[puppet]" => {
"line" => nil,
"change_count" => 0,
"resource_type" => "Filebucket",
@@ -252,7 +252,7 @@ describe Puppet::Transaction::Report do
"events" => [],
"version" => 1279826342
},
- {
+ "Service[mysqld]" => {
"line" => 8,
"change_count" => 1,
"resource_type" => "Service",
@@ -282,7 +282,7 @@ describe Puppet::Transaction::Report do
}],
"version" => 1279826342
},
- {
+ "Schedule[never]" => {
"line" => nil,
"change_count" => 0,
"resource_type" => "Schedule",
@@ -299,7 +299,7 @@ describe Puppet::Transaction::Report do
"events" => [],
"version" => 1279826342
},
- {
+ "Schedule[weekly]" => {
"line" => nil,
"change_count" => 0,
"resource_type" => "Schedule",
@@ -316,7 +316,7 @@ describe Puppet::Transaction::Report do
"events" => [],
"version" => 1279826342
},
- {
+ "Exec[/bin/true]" => {
"line" => 9,
"change_count" => 1,
"resource_type" => "Exec",
@@ -345,7 +345,7 @@ describe Puppet::Transaction::Report do
}],
"version" => 1279826342
},
- {
+ "Schedule[puppet]" => {
"line" => nil,
"change_count" => 0,
"resource_type" => "Schedule",
@@ -362,7 +362,7 @@ describe Puppet::Transaction::Report do
"events" => [],
"version" => 1279826342
},
- {
+ "Schedule[daily]" => {
"line" => nil,
"change_count" => 0,
"resource_type" => "Schedule",
@@ -379,7 +379,7 @@ describe Puppet::Transaction::Report do
"events" => [],
"version" => 1279826342
},
- {
+ "Schedule[hourly]" => {
"line" => nil,
"change_count" => 0,
"resource_type" => "Schedule",
@@ -396,7 +396,7 @@ describe Puppet::Transaction::Report do
"events" => [],
"version" => 1279826342
}
- ]
+ }
end
describe "#configuration_version_from_log_objects" do
diff --git a/spec/lib/report_transformer_spec.rb
b/spec/lib/report_transformer_spec.rb
index 8c0fdc3..7a8d0f5 100644
--- a/spec/lib/report_transformer_spec.rb
+++ b/spec/lib/report_transformer_spec.rb
@@ -33,9 +33,9 @@ describe ReportTransformer do
before do
@report = {"report_format" => 0, "logs" => []}
end
- it "should add an empty array for resource_statuses" do
+ it "should add an empty hash for resource_statuses" do
report = ReportTransformer::ZeroToOne.apply(@report)
- report["resource_statuses"].should == []
+ report["resource_statuses"].should == {}
end
end
--
1.7.2
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.