Paired-with: Jesse Wolfe <[email protected]>
Signed-off-by: Paul Berry <[email protected]>
---
Local-branch: ticket/next/5743
lib/puppet/report.rb | 12 ++++++++----
lib/report_transformer.rb | 4 +++-
spec/lib/puppet/report_spec.rb | 18 ------------------
spec/lib/report_transformer_spec.rb | 7 +++++++
spec/models/report_spec.rb | 3 ++-
5 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/lib/puppet/report.rb b/lib/puppet/report.rb
index fd284ae..114bab5 100644
--- a/lib/puppet/report.rb
+++ b/lib/puppet/report.rb
@@ -93,11 +93,7 @@ module Puppet #:nodoc:
:out_of_sync
def to_hash
- resource =~ /^(.+?)\[(.+)\]$/
- resource_type, title = $1, $2
{
- "resource_type" => resource_type,
- "title" => title,
"evaluation_time" => evaluation_time,
"file" => file,
"line" => line,
@@ -223,6 +219,14 @@ module ReportExtensions #:nodoc:
module Resource
module Status
+ attr_reader :resource_type, :title
+
+ def to_hash
+ hash = super
+ hash["resource_type"] = resource_type
+ hash["title"] = title
+ hash
+ end
end
end
end
diff --git a/lib/report_transformer.rb b/lib/report_transformer.rb
index 7d0554f..6506f6b 100644
--- a/lib/report_transformer.rb
+++ b/lib/report_transformer.rb
@@ -53,7 +53,9 @@ class ReportTransformer::OneToTwo <
ReportTransformer::ReportTransformation
report["configuration_version"] =
configuration_version_from_resource_statuses(report) ||
configuration_version_from_log_objects(report) ||
configuration_version_from_log_message(report)
report["kind"] = "apply"
report["puppet_version"] ||= puppet_version(report) # If it started as a
v0 report, we've already filled in puppet_version
- report["resource_statuses"].values.each do |resource_status|
+ report["resource_statuses"].each do |key, resource_status|
+ key =~ /^(.+?)\[(.+)\]$/
+ resource_status["resource_type"], resource_status["title"] = $1, $2
resource_status["out_of_sync_count"] = resource_status["change_count"]
resource_status.delete("version")
end
diff --git a/spec/lib/puppet/report_spec.rb b/spec/lib/puppet/report_spec.rb
index b9309c5..24e1b94 100644
--- a/spec/lib/puppet/report_spec.rb
+++ b/spec/lib/puppet/report_spec.rb
@@ -209,8 +209,6 @@ describe Puppet::Transaction::Report do
"Schedule[monthly]" => {
"line" => nil,
"change_count" => 0,
- "resource_type" => "Schedule",
- "title" => "monthly",
"time" => Time.parse("2010-07-22 12:19:47.260865
-07:00"),
"evaluation_time" => 0.000432,
"tags" => [
@@ -226,8 +224,6 @@ describe Puppet::Transaction::Report do
"Filebucket[puppet]" => {
"line" => nil,
"change_count" => 0,
- "resource_type" => "Filebucket",
- "title" => "puppet",
"time" => Time.parse("2010-07-22 12:19:47.365218
-07:00"),
"evaluation_time" => 0.000237,
"tags" => [
@@ -243,8 +239,6 @@ describe Puppet::Transaction::Report do
"Service[mysqld]" => {
"line" => 8,
"change_count" => 1,
- "resource_type" => "Service",
- "title" => "mysqld",
"time" => Time.parse("2010-07-22 12:19:47.367360
-07:00"),
"evaluation_time" => 1.555161,
"tags" => [
@@ -273,8 +267,6 @@ describe Puppet::Transaction::Report do
"Schedule[never]" => {
"line" => nil,
"change_count" => 0,
- "resource_type" => "Schedule",
- "title" => "never",
"time" => Time.parse("2010-07-22 12:19:47.365927
-07:00"),
"evaluation_time" => 0.000196,
"tags" => [
@@ -290,8 +282,6 @@ describe Puppet::Transaction::Report do
"Schedule[weekly]" => {
"line" => nil,
"change_count" => 0,
- "resource_type" => "Schedule",
- "title" => "weekly",
"time" => Time.parse("2010-07-22 12:19:47.364377
-07:00"),
"evaluation_time" => 0.00033,
"tags" => [
@@ -307,8 +297,6 @@ describe Puppet::Transaction::Report do
"Exec[/bin/true]" => {
"line" => 9,
"change_count" => 1,
- "resource_type" => "Exec",
- "title" => "/bin/true",
"time" => Time.parse("2010-07-22 12:19:47.262652
-07:00"),
"evaluation_time" => 0.100309,
"tags" => [
@@ -336,8 +324,6 @@ describe Puppet::Transaction::Report do
"Schedule[puppet]" => {
"line" => nil,
"change_count" => 0,
- "resource_type" => "Schedule",
- "title" => "puppet",
"time" => Time.parse("2010-07-22 12:19:48.923135
-07:00"),
"evaluation_time" => 0.000243,
"tags" => [
@@ -353,8 +339,6 @@ describe Puppet::Transaction::Report do
"Schedule[daily]" => {
"line" => nil,
"change_count" => 0,
- "resource_type" => "Schedule",
- "title" => "daily",
"time" => Time.parse("2010-07-22 12:19:47.366606
-07:00"),
"evaluation_time" => 0.000216,
"tags" => [
@@ -370,8 +354,6 @@ describe Puppet::Transaction::Report do
"Schedule[hourly]" => {
"line" => nil,
"change_count" => 0,
- "resource_type" => "Schedule",
- "title" => "hourly",
"time" => Time.parse("2010-07-22 12:19:47.261846
-07:00"),
"evaluation_time" => 0.000255,
"tags" => [
diff --git a/spec/lib/report_transformer_spec.rb
b/spec/lib/report_transformer_spec.rb
index 88a20bb..1f05fbc 100644
--- a/spec/lib/report_transformer_spec.rb
+++ b/spec/lib/report_transformer_spec.rb
@@ -154,5 +154,12 @@ describe ReportTransformer do
resource_status["out_of_sync_count"].should ==
resource_status["change_count"]
end
end
+
+ it "should infer resource_type and title from the keys in the
resource_statuses hash" do
+ report = ReportTransformer::OneToTwo.apply(@report)
+ report["resource_statuses"].each do |key, resource_status|
+ key.should ==
"#{resource_status['resource_type']}[#{resource_status['title']}]"
+ end
+ end
end
end
diff --git a/spec/models/report_spec.rb b/spec/models/report_spec.rb
index b4b7e17..5139e3e 100644
--- a/spec/models/report_spec.rb
+++ b/spec/models/report_spec.rb
@@ -136,7 +136,8 @@ describe Report do
evaluation_time: 0.000868
file: &id001
/Users/matthewrobinson/work/puppet/test_data/genreportm/manifests/site.pp
line: 5
- resource: "File[#{resource_name}]"
+ resource_type: File
+ title: #{resource_name}
source_description: "/Stage[main]//Node[default]/File[#{resource_name}]"
tags:
- &id002 file
--
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.