summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-13 17:52:06 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-13 17:52:06 -0500
commit8c935deed405299c304ccbe370c9240fda63cafb (patch)
treeba75be429bf71195cf7c4e6fc379a9e94d61912c
parente90191af9300fda00cd29d609ac80daff00332cc (diff)
parent694f98b4d9e7172cec58d407bc5aeae7861e1a06 (diff)
Merge branch 'master' of git://reductivelabs.com/puppet into routing
-rw-r--r--lib/puppet/indirector.rb4
-rw-r--r--lib/puppet/indirector/code/configuration.rb20
-rw-r--r--lib/puppet/indirector/code/report.rb49
-rw-r--r--lib/puppet/indirector/indirection.rb6
-rwxr-xr-xlib/puppet/network/handler/report.rb70
-rw-r--r--lib/puppet/node/configuration.rb6
-rwxr-xr-xlib/puppet/reports.rb51
-rw-r--r--lib/puppet/reports/log.rb4
-rw-r--r--lib/puppet/reports/rrdgraph.rb4
-rw-r--r--lib/puppet/reports/store.rb6
-rw-r--r--lib/puppet/reports/tagmail.rb2
-rw-r--r--lib/puppet/transaction/report.rb5
-rw-r--r--lib/puppet/transportable.rb2
-rwxr-xr-xspec/integration/reports.rb14
-rwxr-xr-xspec/unit/indirector/code/configuration.rb68
-rwxr-xr-xspec/unit/indirector/code/report.rb73
-rwxr-xr-xspec/unit/indirector/indirection.rb5
-rwxr-xr-xspec/unit/indirector/indirector.rb5
-rwxr-xr-xspec/unit/node/configuration.rb6
-rwxr-xr-xspec/unit/reports.rb61
-rwxr-xr-xspec/unit/transaction/report.rb34
-rwxr-xr-xtest/network/handler/report.rb103
-rwxr-xr-xtest/other/report.rb13
-rwxr-xr-xtest/rails/host.rb3
-rwxr-xr-xtest/ral/providers/service/debian.rb21
25 files changed, 411 insertions, 224 deletions
diff --git a/lib/puppet/indirector.rb b/lib/puppet/indirector.rb
index a2eb41763..6009a7ba7 100644
--- a/lib/puppet/indirector.rb
+++ b/lib/puppet/indirector.rb
@@ -59,6 +59,10 @@ module Puppet::Indirector
def search(*args)
indirection.search(*args)
end
+
+ def version(*args)
+ indirection.version(*args)
+ end
end
module InstanceMethods
diff --git a/lib/puppet/indirector/code/configuration.rb b/lib/puppet/indirector/code/configuration.rb
index 949926a3c..50728757c 100644
--- a/lib/puppet/indirector/code/configuration.rb
+++ b/lib/puppet/indirector/code/configuration.rb
@@ -47,15 +47,19 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code
$0 =~ /puppetmasterd/
end
- # Return the configuration version.
- def version(client = nil, clientip = nil)
- if client and node = Puppet::Node.search(client)
- update_node_check(node)
- return interpreter.configuration_version(node)
+ # Return the configuration version. Here we're returning the
+ # latest of the node, fact, or parse date. These are the
+ # three things that go into compiling a client configuration,
+ # so changes in any of them result in changes.
+ # LAK:FIXME Note that this only works when all three sources
+ # use timestamps; once one of them moves to using real versions,
+ # the comparison stops working.
+ def version(key)
+ if node = Puppet::Node.search(key)
+ return [Puppet::Node.version(key).to_f, Puppet::Node::Facts.version(key).to_f, interpreter.configuration_version(node).to_f].sort[-1]
else
- # Just return something that will always result in a recompile, because
- # this is local.
- return (Time.now + 1000).to_i
+ # This is the standard for "got nothing for ya".
+ 0
end
end
diff --git a/lib/puppet/indirector/code/report.rb b/lib/puppet/indirector/code/report.rb
new file mode 100644
index 000000000..a3c3a6df5
--- /dev/null
+++ b/lib/puppet/indirector/code/report.rb
@@ -0,0 +1,49 @@
+require 'puppet/indirector/code'
+require 'puppet/reports'
+
+class Puppet::Indirector::Code::Report < Puppet::Indirector::Code
+ desc "Puppet's report processor. Processes the report with each of
+ the report types listed in the 'reports' setting."
+
+ def initialize
+ Puppet.settings.use(:reporting, :metrics)
+ end
+
+ def save(report)
+ process(report)
+ end
+
+ private
+
+ # Process the report with each of the configured report types.
+ # LAK:NOTE This isn't necessarily the best design, but it's backward
+ # compatible and that's good enough for now.
+ def process(report)
+ return if Puppet[:reports] == "none"
+
+ reports().each do |name|
+ if mod = Puppet::Reports.report(name)
+ # We have to use a dup because we're including a module in the
+ # report.
+ newrep = report.dup
+ begin
+ newrep.extend(mod)
+ newrep.process
+ rescue => detail
+ if Puppet[:trace]
+ puts detail.backtrace
+ end
+ Puppet.err "Report %s failed: %s" %
+ [name, detail]
+ end
+ else
+ Puppet.warning "No report named '%s'" % name
+ end
+ end
+ end
+
+ # Handle the parsing of the reports attribute.
+ def reports
+ Puppet[:reports].gsub(/(^\s+)|(\s+$)/, '').split(/\s*,\s*/)
+ end
+end
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 5f7baa3da..efa8819bb 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -92,6 +92,7 @@ class Puppet::Indirector::Indirection
def find(key, *args)
if cache? and cache.has_most_recent?(key, terminus.version(key))
+ Puppet.info "Using cached %s %s" % [self.name, key]
return cache.find(key, *args)
end
if result = terminus.find(key, *args)
@@ -117,10 +118,15 @@ class Puppet::Indirector::Indirection
instance.version ||= Time.now.utc
dest = cache? ? cache : terminus
return if dest.has_most_recent?(instance.name, instance.version)
+ Puppet.info "Caching %s %s" % [self.name, instance.name] if cache?
cache.save(instance, *args) if cache?
terminus.save(instance, *args)
end
+ def version(*args)
+ terminus.version(*args)
+ end
+
private
# Create a new terminus instance.
diff --git a/lib/puppet/network/handler/report.rb b/lib/puppet/network/handler/report.rb
index e202d4e2a..12abc9b15 100755
--- a/lib/puppet/network/handler/report.rb
+++ b/lib/puppet/network/handler/report.rb
@@ -1,78 +1,24 @@
require 'puppet/util/instance_loader'
+require 'puppet/reports'
# A simple server for triggering a new run on a Puppet client.
class Puppet::Network::Handler
class Report < Handler
desc "Accepts a Puppet transaction report and processes it."
- extend Puppet::Util::ClassGen
- extend Puppet::Util::InstanceLoader
-
- module ReportBase
- include Puppet::Util::Docs
- attr_writer :useyaml
-
- def useyaml?
- if defined? @useyaml
- @useyaml
- else
- false
- end
- end
- end
-
@interface = XMLRPC::Service::Interface.new("puppetreports") { |iface|
iface.add_method("string report(array)")
}
- # Set up autoloading and retrieving of reports.
- instance_load :report, 'puppet/reports'
-
- class << self
- attr_reader :hooks
- end
-
# Add a new report type.
def self.newreport(name, options = {}, &block)
- name = symbolize(name)
-
- mod = genmodule(name, :extend => ReportBase, :hash => instance_hash(:report), :block => block)
-
- if options[:useyaml]
- mod.useyaml = true
- end
-
- mod.send(:define_method, :report_name) do
- name
- end
- end
-
- # Collect the docs for all of our reports.
- def self.reportdocs
- docs = ""
-
- # Use this method so they all get loaded
- instance_loader(:report).loadall
- loaded_instances(:report).sort { |a,b| a.to_s <=> b.to_s }.each do |name|
- mod = self.report(name)
- docs += "%s\n%s\n" % [name, "-" * name.to_s.length]
-
- docs += Puppet::Util::Docs.scrub(mod.doc) + "\n\n"
- end
-
- docs
- end
-
- # List each of the reports.
- def self.reports
- instance_loader(:report).loadall
- loaded_instances(:report)
+ Puppet.warning "The interface for registering report types has changed; use Puppet::Reports.register_report for report type %s" % name
+ Puppet::Reports.register_report(name, options, &block)
end
def initialize(*args)
super
- Puppet.settings.use(:reporting)
- Puppet.settings.use(:metrics)
+ Puppet.settings.use(:reporting, :metrics)
end
# Accept a report from a client.
@@ -111,17 +57,13 @@ class Puppet::Network::Handler
client = report.host
reports().each do |name|
- if mod = self.class.report(name)
+ if mod = Puppet::Reports.report(name)
# We have to use a dup because we're including a module in the
# report.
newrep = report.dup
begin
newrep.extend(mod)
- if mod.useyaml?
- newrep.process(yaml)
- else
- newrep.process
- end
+ newrep.process
rescue => detail
if Puppet[:trace]
puts detail.backtrace
diff --git a/lib/puppet/node/configuration.rb b/lib/puppet/node/configuration.rb
index da8dc3a9a..9adf9aea3 100644
--- a/lib/puppet/node/configuration.rb
+++ b/lib/puppet/node/configuration.rb
@@ -388,8 +388,12 @@ class Puppet::Node::Configuration < Puppet::PGraph
# dumped by default, nor does yaml-dumping # the edge-labels work at this point (I don't
# know why).
# Neither of these matters right now, but I suppose it could at some point.
+ # We also have to have the vertex_dict dumped after the resource table, because yaml can't
+ # seem to handle the output of yaml-dumping the vertex_dict.
def to_yaml_properties
- instance_variables.reject { |v| %w{@edgelist_class @edge_labels}.include?(v) }
+ props = instance_variables.reject { |v| %w{@edgelist_class @edge_labels @vertex_dict}.include?(v) }
+ props << "@vertex_dict"
+ props
end
private
diff --git a/lib/puppet/reports.rb b/lib/puppet/reports.rb
new file mode 100755
index 000000000..df992d46c
--- /dev/null
+++ b/lib/puppet/reports.rb
@@ -0,0 +1,51 @@
+require 'puppet/util/instance_loader'
+
+# A simple mechanism for loading and returning reports.
+class Puppet::Reports
+ extend Puppet::Util::ClassGen
+ extend Puppet::Util::InstanceLoader
+
+ # Set up autoloading and retrieving of reports.
+ instance_load :report, 'puppet/reports'
+
+ class << self
+ attr_reader :hooks
+ end
+
+ # Add a new report type.
+ def self.register_report(name, options = {}, &block)
+ name = symbolize(name)
+
+ mod = genmodule(name, :extend => Puppet::Util::Docs, :hash => instance_hash(:report), :block => block)
+
+ if options[:useyaml]
+ mod.useyaml = true
+ end
+
+ mod.send(:define_method, :report_name) do
+ name
+ end
+ end
+
+ # Collect the docs for all of our reports.
+ def self.reportdocs
+ docs = ""
+
+ # Use this method so they all get loaded
+ instance_loader(:report).loadall
+ loaded_instances(:report).sort { |a,b| a.to_s <=> b.to_s }.each do |name|
+ mod = self.report(name)
+ docs += "%s\n%s\n" % [name, "-" * name.to_s.length]
+
+ docs += Puppet::Util::Docs.scrub(mod.doc) + "\n\n"
+ end
+
+ docs
+ end
+
+ # List each of the reports.
+ def self.reports
+ instance_loader(:report).loadall
+ loaded_instances(:report)
+ end
+end
diff --git a/lib/puppet/reports/log.rb b/lib/puppet/reports/log.rb
index 8f7b95f8b..8dfeedb07 100644
--- a/lib/puppet/reports/log.rb
+++ b/lib/puppet/reports/log.rb
@@ -1,6 +1,6 @@
-require 'puppet'
+require 'puppet/reports'
-Puppet::Network::Handler.report.newreport(:log) do
+Puppet::Reports.register_report(:log) do
desc "Send all received logs to the local log destinations. Usually
the log destination is syslog."
diff --git a/lib/puppet/reports/rrdgraph.rb b/lib/puppet/reports/rrdgraph.rb
index 9ab1f4b17..2611f0369 100644
--- a/lib/puppet/reports/rrdgraph.rb
+++ b/lib/puppet/reports/rrdgraph.rb
@@ -1,6 +1,4 @@
-require 'puppet'
-
-Puppet::Network::Handler.report.newreport(:rrdgraph) do
+Puppet::Reports.register_report(:rrdgraph) do
desc "Graph all available data about hosts using the RRD library. You
must have the Ruby RRDtool library installed to use this report, which
you can get from `the RubyRRDTool RubyForge page`_. This package requires
diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb
index 0c3e86f37..dfc992820 100644
--- a/lib/puppet/reports/store.rb
+++ b/lib/puppet/reports/store.rb
@@ -1,6 +1,6 @@
require 'puppet'
-Puppet::Network::Handler.report.newreport(:store, :useyaml => true) do
+Puppet::Reports.register_report(:store) do
Puppet.settings.use(:reporting)
desc "Store the yaml report on disk. Each host sends its report as a YAML dump
@@ -24,7 +24,7 @@ Puppet::Network::Handler.report.newreport(:store, :useyaml => true) do
config.use("reportclient-#{client}")
end
- def process(yaml)
+ def process
# We don't want any tracking back in the fs. Unlikely, but there
# you go.
client = self.host.gsub("..",".")
@@ -46,7 +46,7 @@ Puppet::Network::Handler.report.newreport(:store, :useyaml => true) do
begin
File.open(file, "w", 0640) do |f|
- f.print yaml
+ f.print to_yaml
end
rescue => detail
if Puppet[:trace]
diff --git a/lib/puppet/reports/tagmail.rb b/lib/puppet/reports/tagmail.rb
index fd9126a1a..a2c973f8f 100644
--- a/lib/puppet/reports/tagmail.rb
+++ b/lib/puppet/reports/tagmail.rb
@@ -3,7 +3,7 @@ require 'pp'
require 'net/smtp'
-Puppet::Network::Handler.report.newreport(:tagmail) do
+Puppet::Reports.register_report(:tagmail) do
desc "This report sends specific log messages to specific email addresses
based on the tags in the log messages. See the
`UsingTags tag documentation`:trac: for more information
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index 19dd1b629..f73c6a9fb 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -1,10 +1,15 @@
require 'puppet'
+require 'puppet/indirector'
# A class for reporting what happens on each client. Reports consist of
# two types of data: Logs and Metrics. Logs are the output that each
# change produces, and Metrics are all of the numerical data involved
# in the transaction.
class Puppet::Transaction::Report
+ extend Puppet::Indirector
+
+ indirects :report, :terminus_class => :code
+
attr_accessor :logs, :metrics, :time, :host
def <<(msg)
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 2a600b50e..281ad00d3 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -126,7 +126,7 @@ module Puppet
# Return the type fully capitalized correctly.
def type_capitalized
- type.split("::").collect { |s| s.capitalize }.join("::")
+ type.to_s.split("::").collect { |s| s.capitalize }.join("::")
end
end
diff --git a/spec/integration/reports.rb b/spec/integration/reports.rb
new file mode 100755
index 000000000..7351c3da1
--- /dev/null
+++ b/spec/integration/reports.rb
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-12.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../spec_helper'
+
+require 'puppet/reports'
+
+describe Puppet::Reports, " when using report types" do
+ it "should load report types as modules" do
+ Puppet::Reports.report(:store).should be_instance_of(Module)
+ end
+end
diff --git a/spec/unit/indirector/code/configuration.rb b/spec/unit/indirector/code/configuration.rb
index 0038a038e..b2a23ac19 100755
--- a/spec/unit/indirector/code/configuration.rb
+++ b/spec/unit/indirector/code/configuration.rb
@@ -8,16 +8,6 @@ require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/indirector/code/configuration'
describe Puppet::Indirector::Code::Configuration do
- # LAK:TODO I have no idea how to do this, or even if it should be in this class or test or what.
- # This is used for determining if the client should recompile its configuration, so it's not sufficient
- # to recompile and compare versions.
- # It might be that the right solution is to require configuration caching, and then compare the cached
- # configuration version to the current version, via some querying mechanism (i.e., the client asks for just
- # the configuration's 'up-to-date' attribute, rather than the whole configuration).
- it "should provide a mechanism for determining if the client's configuration is up to date"
-end
-
-describe Puppet::Indirector::Code::Configuration do
before do
Puppet.expects(:version).returns(1)
Facter.expects(:value).with('fqdn').returns("my.server.com")
@@ -48,6 +38,8 @@ end
describe Puppet::Indirector::Code::Configuration, " when creating the interpreter" do
before do
+ # This gets pretty annoying on a plane where we have no IP address
+ Facter.stubs(:value).returns("whatever")
@compiler = Puppet::Indirector::Code::Configuration.new
end
@@ -67,6 +59,7 @@ end
describe Puppet::Indirector::Code::Configuration, " when finding nodes" do
before do
+ Facter.stubs(:value).returns("whatever")
@compiler = Puppet::Indirector::Code::Configuration.new
@name = "me"
@node = mock 'node'
@@ -117,11 +110,14 @@ describe Puppet::Indirector::Code::Configuration, " after finding nodes" do
# LAK:TODO This is going to be difficult, because this whole process is so
# far removed from the actual connection that the certificate information
# will be quite hard to come by, dum by, gum by.
- it "should search for the name using the client certificate's DN if the :node_name setting is set to 'cert'"
+ it "should search for the name using the client certificate's DN if the :node_name setting is set to 'cert'" do
+ pending "Probably will end up in the REST work"
+ end
end
describe Puppet::Indirector::Code::Configuration, " when creating configurations" do
before do
+ Facter.stubs(:value).returns("whatever")
@compiler = Puppet::Indirector::Code::Configuration.new
@name = "me"
@node = Puppet::Node.new @name, :environment => "yay"
@@ -158,3 +154,53 @@ describe Puppet::Indirector::Code::Configuration, " when creating configurations
@compiler.find(@name)
end
end
+
+describe Puppet::Indirector::Code::Configuration, " when determining a client's available configuration version" do
+ before do
+ Puppet::Node::Facts.stubs(:find).returns(nil)
+ Facter.stubs(:value).returns("whatever")
+ @configuration = Puppet::Indirector::Code::Configuration.new
+ @name = "johnny"
+ end
+
+ it "should provide a mechanism for providing the version of a given client's configuration" do
+ @configuration.should respond_to(:version)
+ end
+
+ it "should use the client's Facts version as the available configuration version if it is the most recent" do
+ Puppet::Node::Facts.expects(:version).with(@name).returns(5)
+ Puppet::Node.expects(:version).with(@name).returns(3)
+ @configuration.interpreter.stubs(:configuration_version).returns(4)
+
+ @configuration.version(@name).should == 5
+ end
+
+ it "should use the client's Node version as the available configuration version if it is the most recent" do
+ Puppet::Node::Facts.expects(:version).with(@name).returns(3)
+ Puppet::Node.expects(:version).with(@name).returns(5)
+ @configuration.interpreter.stubs(:configuration_version).returns(4)
+
+ @configuration.version(@name).should == 5
+ end
+
+ it "should use the last parse date as the available configuration version if it is the most recent" do
+ Puppet::Node::Facts.expects(:version).with(@name).returns(3)
+ Puppet::Node.expects(:version).with(@name).returns(4)
+ @configuration.interpreter.stubs(:configuration_version).returns(5)
+
+ @configuration.version(@name).should == 5
+ end
+
+ it "should return a version of 0 if no information on the node can be found" do
+ Puppet::Node.stubs(:search).returns(nil)
+ @configuration.version(@name).should == 0
+ end
+
+ it "should indicate when an update is available even if an input has clock skew" do
+ pending "Unclear how to implement this"
+ end
+
+ it "should not indicate an available update when apparent updates are a result of clock skew" do
+ pending "Unclear how to implement this"
+ end
+end
diff --git a/spec/unit/indirector/code/report.rb b/spec/unit/indirector/code/report.rb
new file mode 100755
index 000000000..a27eaa297
--- /dev/null
+++ b/spec/unit/indirector/code/report.rb
@@ -0,0 +1,73 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-9-23.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/code/report'
+
+describe Puppet::Indirector::Code::Report do
+ it "should provide a method for saving reports" do
+ Puppet::Indirector::Code::Report.new.should respond_to(:save)
+ end
+end
+
+
+describe Puppet::Indirector::Code::Report, " when saving a report" do
+ before do
+ Puppet.settings.stubs(:use)
+ @reporter = Puppet::Indirector::Code::Report.new
+ end
+
+ it "should not process the report if reports are set to 'none'" do
+ Puppet::Reports.expects(:report).never
+ Puppet.settings.expects(:value).with(:reports).returns("none")
+
+ @reporter.save(:whatever)
+ end
+
+ it "should process the report with each configured report type" do
+ Puppet.settings.stubs(:value).with(:reports).returns("one,two")
+ @reporter.send(:reports).should == %w{one two}
+ end
+end
+
+describe Puppet::Indirector::Code::Report, " when processing a report" do
+ before do
+ Puppet.settings.stubs(:value).with(:reports).returns("one")
+ Puppet.settings.stubs(:use)
+ @reporter = Puppet::Indirector::Code::Report.new
+
+ @report_type = mock 'one'
+ @dup_report = mock 'dupe report'
+ @dup_report.stubs(:process)
+ @report = mock 'report'
+ @report.expects(:dup).returns(@dup_report)
+ Puppet::Reports.expects(:report).with("one").returns(@report_type)
+
+ @dup_report.expects(:extend).with(@report_type)
+ end
+
+ # LAK:NOTE This is stupid, because the code is so short it doesn't
+ # make sense to split it out, which means I just do the same test
+ # three times so the spec looks right.
+ it "should process a duplicate of the report, not the original" do
+ @reporter.save(@report)
+ end
+
+ it "should extend the report with the report type's module" do
+ @reporter.save(@report)
+ end
+
+ it "should call the report type's :process method" do
+ @dup_report.expects(:process)
+ @reporter.save(@report)
+ end
+
+ it "should not raise exceptions" do
+ Puppet.settings.stubs(:value).with(:trace).returns(false)
+ @dup_report.expects(:process).raises(ArgumentError)
+ proc { @reporter.save(@report) }.should_not raise_error
+ end
+end
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index 7a1c4531c..25152d123 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -37,6 +37,11 @@ describe Puppet::Indirector::Indirection do
@terminus.expects(:save).with(@instance).returns(@instance)
@indirection.save(@instance).should == @instance
end
+
+ it "should handle version lookups by letting the appropriate terminus perform the lookup" do
+ @terminus.expects(:version).with(@name).returns(5)
+ @indirection.version(@name).should == 5
+ end
it "should add versions to found instances that do not already have them" do
@terminus.expects(:find).with(@name).returns(@instance)
diff --git a/spec/unit/indirector/indirector.rb b/spec/unit/indirector/indirector.rb
index 78c8c614a..1f63da30d 100755
--- a/spec/unit/indirector/indirector.rb
+++ b/spec/unit/indirector/indirector.rb
@@ -95,6 +95,11 @@ describe Puppet::Indirector, " when redirecting a model" do
thing.save
end
+ it "should give the model the ability to look up an instance's version by letting the indirection perform the lookup" do
+ @indirection.expects(:version).with(:thing)
+ @thingie.version(:thing)
+ end
+
it "should give the model the ability to set the indirection terminus class" do
@indirection.expects(:terminus_class=).with(:myterm)
@thingie.terminus_class = :myterm
diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb
index ee3834ef3..62d8e343d 100755
--- a/spec/unit/node/configuration.rb
+++ b/spec/unit/node/configuration.rb
@@ -250,11 +250,11 @@ describe Puppet::Node::Configuration, " when converting to a RAL configuration"
@original.tag(*%w{one two three})
@original.add_class *%w{four five six}
- @top = Puppet::TransObject.new 'Class[top]', "component"
+ @top = Puppet::TransObject.new 'top', "class"
@topobject = Puppet::TransObject.new '/topobject', "file"
- @middle = Puppet::TransObject.new 'Class[middle]', "component"
+ @middle = Puppet::TransObject.new 'middle', "class"
@middleobject = Puppet::TransObject.new '/middleobject', "file"
- @bottom = Puppet::TransObject.new 'Class[bottom]', "component"
+ @bottom = Puppet::TransObject.new 'bottom', "class"
@bottomobject = Puppet::TransObject.new '/bottomobject', "file"
@resources = [@top, @topobject, @middle, @middleobject, @bottom, @bottomobject]
diff --git a/spec/unit/reports.rb b/spec/unit/reports.rb
new file mode 100755
index 000000000..f12f0d717
--- /dev/null
+++ b/spec/unit/reports.rb
@@ -0,0 +1,61 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../spec_helper'
+
+require 'puppet/reports'
+
+describe Puppet::Reports do
+ it "should instance-load report types" do
+ Puppet::Reports.instance_loader(:report).should be_instance_of(Puppet::Util::Autoload)
+ end
+
+ it "should have a method for registering report types" do
+ Puppet::Reports.should respond_to(:register_report)
+ end
+
+ it "should have a method for retrieving report types by name" do
+ Puppet::Reports.should respond_to(:report)
+ end
+
+ it "should provide a method for returning documentation for all reports" do
+ Puppet::Reports.expects(:loaded_instances).with(:report).returns([:one, :two])
+ one = mock 'one', :doc => "onedoc"
+ two = mock 'two', :doc => "twodoc"
+ Puppet::Reports.expects(:report).with(:one).returns(one)
+ Puppet::Reports.expects(:report).with(:two).returns(two)
+
+ doc = Puppet::Reports.reportdocs
+ doc.include?("onedoc").should be_true
+ doc.include?("twodoc").should be_true
+ end
+end
+
+
+describe Puppet::Reports, " when loading report types" do
+ it "should use the instance loader to retrieve report types" do
+ Puppet::Reports.expects(:loaded_instance).with(:report, :myreporttype)
+ Puppet::Reports.report(:myreporttype)
+ end
+end
+
+describe Puppet::Reports, " when registering report types" do
+ it "should evaluate the supplied block as code for a module" do
+ Puppet::Reports.expects(:genmodule).returns(Module.new)
+ Puppet::Reports.register_report(:testing) { }
+ end
+
+ it "should extend the report type with the Puppet::Util::Docs module" do
+ mod = stub 'module', :define_method => true
+
+ Puppet::Reports.expects(:genmodule).with { |name, options, block| options[:extend] == Puppet::Util::Docs }.returns(mod)
+ Puppet::Reports.register_report(:testing) { }
+ end
+
+ it "should define a :report_name method in the module that returns the name of the report" do
+ mod = mock 'module'
+ mod.expects(:define_method).with(:report_name)
+
+ Puppet::Reports.expects(:genmodule).returns(mod)
+ Puppet::Reports.register_report(:testing) { }
+ end
+end
diff --git a/spec/unit/transaction/report.rb b/spec/unit/transaction/report.rb
new file mode 100755
index 000000000..ce8c4038d
--- /dev/null
+++ b/spec/unit/transaction/report.rb
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+#
+# Created by Luke Kanies on 2007-10-12.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/transaction/report'
+
+describe Puppet::Transaction::Report, " when being indirect" do
+ it "should redirect :find to the indirection" do
+ @indirection = mock 'indirection'
+ Puppet::Transaction::Report.stubs(:indirection).returns(@indirection)
+ @indirection.expects(:find).with(:report)
+ Puppet::Transaction::Report.find(:report)
+ end
+
+ it "should redirect :save to the indirection" do
+ Facter.stubs(:value).returns("eh")
+ @indirection = mock 'indirection'
+ Puppet::Transaction::Report.stubs(:indirection).returns(@indirection)
+ report = Puppet::Transaction::Report.new
+ @indirection.expects(:save).with(report)
+ report.save
+ end
+
+ it "should default to the 'code' terminus" do
+ Puppet::Transaction::Report.indirection.terminus_class.should == :code
+ end
+
+ after do
+ Puppet::Indirector::Indirection.clear_cache
+ end
+end
diff --git a/test/network/handler/report.rb b/test/network/handler/report.rb
index ac8cf6fac..76326bce6 100755
--- a/test/network/handler/report.rb
+++ b/test/network/handler/report.rb
@@ -31,46 +31,13 @@ class TestReportServer < Test::Unit::TestCase
client
end
- def test_report_autoloading
- # Create a fake report
- fakedir = tempfile()
- $: << fakedir
- cleanup do $:.delete(fakedir) end
-
- libdir = File.join(fakedir, "puppet", "reports")
- FileUtils.mkdir_p(libdir)
-
- $myreportrun = false
- file = File.join(libdir, "myreport.rb")
- File.open(file, "w") { |f| f.puts %{
- Puppet::Network::Handler.report.newreport(:myreport) do
- def process(report)
- $myreportrun = true
- return report
- end
- end
- }
- }
- Puppet[:reports] = "myreport"
-
- # Create a server
- server = Puppet::Network::Handler.report.new
-
- report = nil
- assert_nothing_raised {
- report = Puppet::Network::Handler.report.report(:myreport)
- }
- assert(report, "Did not get report")
-
- end
-
def test_process
server = Puppet::Network::Handler.report.new
# We have to run multiple reports to make sure there's no conflict
reports = []
$run = []
- 5.times do |i|
+ 2.times do |i|
name = "processtest%s" % i
reports << name
@@ -100,35 +67,6 @@ class TestReportServer < Test::Unit::TestCase
}
end
- # Make sure reports can specify whether to use yaml or not
- def test_useyaml
- server = Puppet::Network::Handler.report.new
-
- Report.newreport(:yamlyes, :useyaml => true) do
- def process(report)
- $yamlyes = :yesyaml
- end
- end
-
- Report.newreport(:yamlno) do
- def process
- $yamlno = :noyaml
- end
- end
-
- Puppet[:reports] = "yamlyes, yamlno"
-
- report = fakereport
- yaml = YAML.dump(report)
-
- assert_nothing_raised do
- server.send(:process, yaml)
- end
-
- assert_equal(:noyaml, $yamlno, "YAML was used for non-yaml report")
- assert_equal(:yesyaml, $yamlyes, "YAML was not used for yaml report")
- end
-
def test_reports
Puppet[:reports] = "myreport"
@@ -142,43 +80,4 @@ class TestReportServer < Test::Unit::TestCase
assert_equal(ary, server.send(:reports))
end
end
-
- def test_newreport
- name = :newreporttest
- assert_nothing_raised do
- Report.newreport(name) do
- attr_accessor :processed
-
- def process(report)
- @processed = report
- end
- end
- end
-
- assert(Report.report(name), "Did not get report")
- assert_instance_of(Module, Report.report(name))
-
- obj = "yay"
- obj.extend(Report.report(name))
-
- assert_nothing_raised do
- obj.process("yay")
- end
-
- assert_equal("yay", obj.processed)
- end
-
- # Make sure we get a list of all reports
- def test_report_list
- list = nil
- assert_nothing_raised do
- list = Puppet::Network::Handler.report.reports
- end
-
- [:rrdgraph, :store, :tagmail].each do |name|
- assert(list.include?(name), "Did not load %s" % name)
- end
- end
end
-
-
diff --git a/test/other/report.rb b/test/other/report.rb
index 8f33a7166..bed510f2f 100755
--- a/test/other/report.rb
+++ b/test/other/report.rb
@@ -3,6 +3,7 @@
$:.unshift("../lib").unshift("../../lib") if __FILE__ =~ /\.rb$/
require 'puppet'
+require 'puppet/reports'
require 'puppet/transaction/report'
require 'puppettest'
require 'puppettest/reporttesting'
@@ -97,14 +98,14 @@ class TestReports < Test::Unit::TestCase
}
assert_nothing_raised do
- report.extend(Puppet::Network::Handler.report.report(:store))
+ report.extend(Puppet::Reports.report(:store))
end
yaml = YAML.dump(report)
file = nil
assert_nothing_raised {
- file = report.process(yaml)
+ file = report.process
}
assert(FileTest.exists?(file), "report file did not get created")
@@ -119,7 +120,7 @@ class TestReports < Test::Unit::TestCase
assert(! report.metrics.empty?, "Did not receive any metrics")
assert_nothing_raised do
- report.extend(Puppet::Network::Handler.report.report(:rrdgraph))
+ report.extend(Puppet::Reports.report(:rrdgraph))
end
assert_nothing_raised {
@@ -154,7 +155,7 @@ class TestReports < Test::Unit::TestCase
def test_tagmail_parsing
report = Object.new
- report.extend(Puppet::Network::Handler.report.report(:tagmail))
+ report.extend(Puppet::Reports.report(:tagmail))
passers = File.join(datadir, "reports", "tagmail_passers.conf")
assert(FileTest.exists?(passers), "no passers file %s" % passers)
@@ -178,7 +179,7 @@ class TestReports < Test::Unit::TestCase
def test_tagmail_parsing_results
report = Object.new
- report.extend(Puppet::Network::Handler.report.report(:tagmail))
+ report.extend(Puppet::Reports.report(:tagmail))
# Now test a few specific lines to make sure we get the results we want
{
"tag: abuse@domain.com" => [%w{abuse@domain.com}, %w{tag}, []],
@@ -206,7 +207,7 @@ class TestReports < Test::Unit::TestCase
list = report.logs.collect { |l| l.to_report }
- report.extend(Puppet::Network::Handler.report.report(:tagmail))
+ report.extend(Puppet::Reports.report(:tagmail))
{
[%w{abuse@domain.com}, %w{all}, []] => list,
diff --git a/test/rails/host.rb b/test/rails/host.rb
index 4d9c64932..0d97e0ffa 100755
--- a/test/rails/host.rb
+++ b/test/rails/host.rb
@@ -155,10 +155,9 @@ class TestRailsHost < PuppetTest::TestCase
Puppet::Rails.init
Puppet[:storeconfigs] = true
+ Puppet[:code] = " "
# this is the default server setup
master = Puppet::Network::Handler.configuration.new(
- :Code => "",
- :UseNodes => true,
:Local => true
)
diff --git a/test/ral/providers/service/debian.rb b/test/ral/providers/service/debian.rb
index f74141f9e..ed90f8fef 100755
--- a/test/ral/providers/service/debian.rb
+++ b/test/ral/providers/service/debian.rb
@@ -12,22 +12,11 @@ class TestDebianServiceProvider < Test::Unit::TestCase
include Puppet::Util
def prepare_provider(servicename, output)
- service = Puppet::Type.type(:service).create(
- :name => servicename, :provider => :debian
- )
+ @resource = mock 'resource'
+ @resource.stubs(:[]).with(:name).returns("myresource")
+ provider = Puppet::Type.type(:service).provider(:debian).new(@resource)
- provider = service.provider
- assert(provider, "did not get debian provider")
-
- metaclass = class << provider
- self
- end
-
- metaclass.instance_eval do
- define_method :update do |*args|
- return output
- end
- end
+ provider.stubs(:update).returns(output)
provider
end
@@ -67,5 +56,3 @@ class TestDebianServiceProvider < Test::Unit::TestCase
assert_disabled("test4", " Removing any system startup links for /etc/init.d/test4 ...\n")
end
end
-
-# $Id$