[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Nick Lewis
nick at puppetlabs.com
Tue May 10 08:03:25 UTC 2011
The following commit has been merged in the experimental branch:
commit 480c399f183627f5f588e9dc9f5f86f683c0e468
Merge: 73397a24db7e715c7712def75612dc4a5071ca7f 52ca8c78c270b93ce997217900a3d333ad8154cc
Author: Nick Lewis <nick at puppetlabs.com>
Date: Thu Dec 16 11:30:51 2010 -0800
Merge branch '2.6.x' into next
Manually Resolved Conflicts:
lib/puppet/resource/type_collection.rb
spec/unit/configurer_spec.rb
spec/unit/indirector/catalog/active_record_spec.rb
spec/unit/resource/type_collection_spec.rb
spec/unit/transaction/resource_harness_spec.rb
diff --combined lib/puppet/application/inspect.rb
index 0000000,c28fef3..c76f9e4
mode 000000,100644..100644
--- a/lib/puppet/application/inspect.rb
+++ b/lib/puppet/application/inspect.rb
@@@ -1,0 -1,80 +1,80 @@@
+ require 'puppet/application'
+
+ class Puppet::Application::Inspect < Puppet::Application
+
+ should_parse_config
+ run_mode :agent
+
+ option("--debug","-d")
+ option("--verbose","-v")
+
+ option("--logdest LOGDEST", "-l") do |arg|
+ begin
+ Puppet::Util::Log.newdestination(arg)
+ options[:logset] = true
+ rescue => detail
+ $stderr.puts detail.to_s
+ end
+ end
+
+ def setup
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
+
+ raise "Inspect requires reporting to be enabled. Set report=true in puppet.conf to enable reporting." unless Puppet[:report]
+
+ @report = Puppet::Transaction::Report.new("inspect")
+
+ Puppet::Util::Log.newdestination(@report)
+ Puppet::Util::Log.newdestination(:console) unless options[:logset]
+
+ trap(:INT) do
+ $stderr.puts "Exiting"
+ exit(1)
+ end
+
+ if options[:debug]
+ Puppet::Util::Log.level = :debug
+ elsif options[:verbose]
+ Puppet::Util::Log.level = :info
+ end
+
- Puppet::Transaction::Report.terminus_class = :rest
- Puppet::Resource::Catalog.terminus_class = :yaml
++ Puppet::Transaction::Report.indirection.terminus_class = :rest
++ Puppet::Resource::Catalog.indirection.terminus_class = :yaml
+ end
+
+ def run_command
+ retrieval_starttime = Time.now
+
- unless catalog = Puppet::Resource::Catalog.find(Puppet[:certname])
++ unless catalog = Puppet::Resource::Catalog.indirection.find(Puppet[:certname])
+ raise "Could not find catalog for #{Puppet[:certname]}"
+ end
+
+ retrieval_time = Time.now - retrieval_starttime
+ @report.add_times("config_retrieval", retrieval_time)
+
+ starttime = Time.now
+
+ catalog.to_ral.resources.each do |ral_resource|
+ audited_attributes = ral_resource[:audit]
+ next unless audited_attributes
+
+ audited_resource = ral_resource.to_resource
+
+ status = Puppet::Resource::Status.new(ral_resource)
+ audited_attributes.each do |name|
+ event = ral_resource.event(:previous_value => audited_resource[name], :property => name, :status => "audit", :message => "inspected value is #{audited_resource[name].inspect}")
+ status.add_event(event)
+ end
+ @report.add_resource_status(status)
+ end
+
+ @report.add_metric(:time, {"config_retrieval" => retrieval_time, "inspect" => Time.now - starttime})
+
+ begin
- @report.save
++ Puppet::Transaction::Report.indirection.save(@report)
+ rescue => detail
+ puts detail.backtrace if Puppet[:trace]
+ Puppet.err "Could not send report: #{detail}"
+ end
+ end
+ end
diff --combined lib/puppet/indirector/catalog/active_record.rb
index 5157fb5,f814f4a..365cdfe
--- a/lib/puppet/indirector/catalog/active_record.rb
+++ b/lib/puppet/indirector/catalog/active_record.rb
@@@ -30,9 -30,9 +30,9 @@@ class Puppet::Resource::Catalog::Active
host.merge_resources(catalog.vertices)
host.last_compile = Time.now
- if node = Puppet::Node.find(catalog.name)
+ if node = Puppet::Node.indirection.find(catalog.name)
host.ip = node.parameters["ipaddress"]
- host.environment = node.environment
+ host.environment = node.environment.to_s
end
host.save
diff --combined lib/puppet/transaction/report.rb
index 1d30914,75c08fc..492d15d
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@@ -10,7 -10,7 +10,7 @@@ class Puppet::Transaction::Repor
indirects :report, :terminus_class => :processor
- attr_reader :resource_statuses, :logs, :metrics, :host, :time
+ attr_reader :resource_statuses, :logs, :metrics, :host, :time, :kind
# This is necessary since Marshall doesn't know how to
# dump hash with default proc (see below @records)
@@@ -49,62 -49,44 +49,63 @@@
calculate_event_metrics
end
- def initialize
+ def initialize(kind = "apply")
@metrics = {}
@logs = []
@resource_statuses = {}
@external_times ||= {}
@host = Puppet[:certname]
@time = Time.now
+ @kind = kind
end
def name
host
end
- # Provide a summary of this report.
+ # Provide a human readable textual summary of this report.
def summary
+ report = raw_summary
+
ret = ""
+ report.keys.sort { |a,b| a.to_s <=> b.to_s }.each do |key|
+ ret += "#{Puppet::Util::Metric.labelize(key)}:\n"
- @metrics.sort { |a,b| a[1].label <=> b[1].label }.each do |name, metric|
- ret += "#{metric.label}:\n"
- metric.values.sort { |a,b|
+ report[key].keys.sort { |a,b|
# sort by label
- if a[0] == :total
+ if a == :total
1
- elsif b[0] == :total
+ elsif b == :total
-1
else
- a[1] <=> b[1]
+ report[key][a].to_s <=> report[key][b].to_s
end
- }.each do |name, label, value|
+ }.each do |label|
+ value = report[key][label]
next if value == 0
value = "%0.2f" % value if value.is_a?(Float)
- ret += " %15s %s\n" % [label + ":", value]
+ ret += " %15s %s\n" % [Puppet::Util::Metric.labelize(label) + ":", value]
end
end
ret
end
+ # Provide a raw hash summary of this report.
+ def raw_summary
+ report = {}
+
+ @metrics.each do |name, metric|
+ key = metric.name.to_s
+ report[key] = {}
+ metric.values.each do |name, label, value|
+ report[key][name.to_s] = value
+ end
+ report[key]["total"] = 0 unless key == "time" or report[key].include?("total")
+ end
+ (report["time"] ||= {})["last_run"] = Time.now.tv_sec
+ report
+ end
+
# Based on the contents of this report's metrics, compute a single number
# that represents the report. The resulting number is a bitmask where
# individual bits represent the presence of different metrics.
@@@ -122,6 -104,7 +123,6 @@@
resource_statuses.each do |name, status|
metrics[:total] += status.change_count if status.change_count
end
-
add_metric(:changes, metrics)
end
@@@ -142,6 -125,7 +143,6 @@@
metrics[:total] = resource_statuses.length
resource_statuses.each do |name, status|
-
Puppet::Resource::Status::STATES.each do |state|
metrics[state] += 1 if status.send(state)
end
diff --combined lib/puppet/type/file.rb
index 0a07b67,6523c99..b346127
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@@ -587,7 -587,7 +587,7 @@@ Puppet::Type.newtype(:file) d
def perform_recursion(path)
- Puppet::FileServing::Metadata.search(
+ Puppet::FileServing::Metadata.indirection.search(
path,
:links => self[:links],
@@@ -718,8 -718,9 +718,9 @@@
mode = self.should(:mode) # might be nil
umask = mode ? 000 : 022
+ mode_int = mode ? mode.to_i(8) : nil
- content_checksum = Puppet::Util.withumask(umask) { File.open(path, 'w', mode) { |f| write_content(f) } }
+ content_checksum = Puppet::Util.withumask(umask) { File.open(path, 'w', mode_int ) { |f| write_content(f) } }
# And put our new file in place
if use_temporary_file # This is only not true when our file is empty.
diff --combined lib/puppet/util/log.rb
index a5aacc2,7764dc1..9a9e291
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@@ -17,11 -17,12 +17,12 @@@ class Puppet::Util::Lo
# Create a new destination type.
def self.newdesttype(name, options = {}, &block)
- dest = genclass(
- name, :parent => Puppet::Util::Log::Destination, :prefix => "Dest",
- :block => block,
- :hash => @desttypes,
-
+ dest = genclass(
+ name,
+ :parent => Puppet::Util::Log::Destination,
+ :prefix => "Dest",
+ :block => block,
+ :hash => @desttypes,
:attributes => options
)
dest.match(dest.name)
@@@ -57,7 -58,6 +58,7 @@@
destinations.keys.each { |dest|
close(dest)
}
+ raise Puppet::DevError.new("Log.close_all failed to close #{@destinations.keys.inspect}") if !@destinations.empty?
end
# Flush any log destinations that support such operations.
diff --combined spec/unit/configurer/plugin_handler_spec.rb
index 27d5a9f,30b135e..04a4796
--- a/spec/unit/configurer/plugin_handler_spec.rb
+++ b/spec/unit/configurer/plugin_handler_spec.rb
@@@ -1,6 -1,6 +1,6 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/configurer'
require 'puppet/configurer/plugin_handler'
@@@ -11,6 -11,10 +11,10 @@@ en
describe Puppet::Configurer::PluginHandler do
before do
@pluginhandler = PluginHandlerTester.new
+
+ # PluginHandler#load_plugin has an extra-strong rescue clause
+ # this mock is to make sure that we don't silently ignore errors
+ Puppet.expects(:err).never
end
it "should have a method for downloading plugins" do
@@@ -80,7 -84,7 +84,7 @@@
end
it "should not try to load files that don't exist" do
- FileTest.expects(:exist?).with("foo").returns true
+ FileTest.expects(:exist?).with("foo").returns false
@pluginhandler.expects(:load).never
@pluginhandler.load_plugin("foo")
diff --combined spec/unit/configurer_spec.rb
index 9f88ee5,ebc5768..705417d
--- a/spec/unit/configurer_spec.rb
+++ b/spec/unit/configurer_spec.rb
@@@ -3,7 -3,7 +3,7 @@@
# Created by Luke Kanies on 2007-11-12.
# Copyright (c) 2007. All rights reserved.
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
require 'puppet/configurer'
describe Puppet::Configurer do
@@@ -89,7 -89,9 +89,7 @@@ describe Puppet::Configurer, "when exec
@catalog = Puppet::Resource::Catalog.new
@catalog.stubs(:apply)
@agent.stubs(:retrieve_catalog).returns @catalog
-
- Puppet::Util::Log.stubs(:newdestination)
- Puppet::Util::Log.stubs(:close)
+ @agent.stubs(:save_last_run_summary)
end
it "should prepare for the run" do
@@@ -99,14 -101,14 +99,14 @@@
end
it "should initialize a transaction report if one is not provided" do
- report = stub 'report'
+ report = Puppet::Transaction::Report.new
@agent.expects(:initialize_report).returns report
@agent.run
end
it "should pass the new report to the catalog" do
- report = stub 'report'
+ report = Puppet::Transaction::Report.new
@agent.stubs(:initialize_report).returns report
@catalog.expects(:apply).with{|options| options[:report] == report}
@@@ -114,7 -116,7 +114,7 @@@
end
it "should use the provided report if it was passed one" do
- report = stub 'report'
+ report = Puppet::Transaction::Report.new
@agent.expects(:initialize_report).never
@catalog.expects(:apply).with{|options| options[:report] == report}
@@@ -122,9 -124,9 +122,10 @@@
end
it "should set the report as a log destination" do
-- report = stub 'report'
++ report = Puppet::Transaction::Report.new
@agent.expects(:initialize_report).returns report
++ @agent.stubs(:send_report)
Puppet::Util::Log.expects(:newdestination).with(report)
@agent.run
@@@ -174,7 -176,7 +175,7 @@@
end
it "should send the report" do
- report = stub 'report'
+ report = Puppet::Transaction::Report.new
@agent.expects(:initialize_report).returns report
@agent.expects(:send_report).with { |r, trans| r == report }
@@@ -182,7 -184,7 +183,7 @@@
end
it "should send the transaction report with a reference to the transaction if a run was actually made" do
- report = stub 'report'
+ report = Puppet::Transaction::Report.new
@agent.expects(:initialize_report).returns report
trans = stub 'transaction'
@@@ -196,7 -198,7 +197,7 @@@
it "should send the transaction report even if the catalog could not be retrieved" do
@agent.expects(:retrieve_catalog).returns nil
- report = stub 'report'
+ report = Puppet::Transaction::Report.new
@agent.expects(:initialize_report).returns report
@agent.expects(:send_report)
@@@ -206,7 -208,7 +207,7 @@@
it "should send the transaction report even if there is a failure" do
@agent.expects(:retrieve_catalog).raises "whatever"
- report = stub 'report'
+ report = Puppet::Transaction::Report.new
@agent.expects(:initialize_report).returns report
@agent.expects(:send_report)
@@@ -214,16 -216,16 +215,16 @@@
end
it "should remove the report as a log destination when the run is finished" do
- report = stub 'report'
+ report = Puppet::Transaction::Report.new
@agent.expects(:initialize_report).returns report
-
- Puppet::Util::Log.expects(:close).with(report)
+ report.expects(:<<).at_least_once
@agent.run
+ Puppet::Util::Log.destinations.should_not include(report)
end
it "should return the report as the result of the run" do
- report = stub 'report'
+ report = Puppet::Transaction::Report.new
@agent.expects(:initialize_report).returns report
@agent.run.should equal(report)
@@@ -234,9 -236,8 +235,9 @@@ describe Puppet::Configurer, "when send
before do
Puppet.settings.stubs(:use).returns(true)
@configurer = Puppet::Configurer.new
+ @configurer.stubs(:save_last_run_summary)
- @report = stub 'report'
+ @report = Puppet::Transaction::Report.new
@trans = stub 'transaction'
end
@@@ -272,7 -273,7 +273,7 @@@
it "should save the report if reporting is enabled" do
Puppet.settings[:report] = true
- @report.expects(:save)
+ Puppet::Transaction::Report.indirection.expects(:save).with(@report)
@configurer.send_report(@report)
end
@@@ -283,60 -284,16 +284,60 @@@
@configurer.send_report(@report)
end
+ it "should save the last run summary if reporting is enabled" do
+ Puppet.settings[:report] = true
+
+ @configurer.expects(:save_last_run_summary).with(@report)
+ @configurer.send_report(@report)
+ end
+
+ it "should not save the last run summary if reporting is disabled" do
+ Puppet.settings[:report] = false
+
+ @configurer.expects(:save_last_run_summary).never
+ @configurer.send_report(@report)
+ end
+
it "should log but not fail if saving the report fails" do
Puppet.settings[:report] = true
- @report.expects(:save).raises "whatever"
+ Puppet::Transaction::Report.indirection.expects(:save).with(@report).raises "whatever"
Puppet.expects(:err)
lambda { @configurer.send_report(@report) }.should_not raise_error
end
end
+describe Puppet::Configurer, "when saving the summary report file" do
+ before do
+ Puppet.settings.stubs(:use).returns(true)
+ @configurer = Puppet::Configurer.new
+
+ @report = stub 'report'
+ @trans = stub 'transaction'
+ @lastrunfd = stub 'lastrunfd'
+ Puppet::Util::FileLocking.stubs(:writelock).yields(@lastrunfd)
+ end
+
+ it "should write the raw summary to the lastrunfile setting value" do
+ Puppet::Util::FileLocking.expects(:writelock).with(Puppet[:lastrunfile], 0660)
+ @configurer.save_last_run_summary(@report)
+ end
+
+ it "should write the raw summary as yaml" do
+ @report.expects(:raw_summary).returns("summary")
+ @lastrunfd.expects(:print).with(YAML.dump("summary"))
+ @configurer.save_last_run_summary(@report)
+ end
+
+ it "should log but not fail if saving the last run summary fails" do
+ Puppet::Util::FileLocking.expects(:writelock).raises "exception"
+ Puppet.expects(:err)
+ lambda { @configurer.save_last_run_summary(@report) }.should_not raise_error
+ end
+
+end
+
describe Puppet::Configurer, "when retrieving a catalog" do
before do
Puppet.settings.stubs(:use).returns(true)
@@@ -357,15 -314,15 +358,15 @@@
end
it "should first look in the cache for a catalog" do
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
@agent.retrieve_catalog.should == @catalog
end
it "should compile a new catalog if none is found in the cache" do
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
@agent.retrieve_catalog.should == @catalog
end
@@@ -374,7 -331,7 +375,7 @@@
describe "when not using a REST terminus for catalogs" do
it "should not pass any facts when retrieving the catalog" do
@agent.expects(:facts_for_uploading).never
- Puppet::Resource::Catalog.expects(:find).with { |name, options|
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
options[:facts].nil?
}.returns @catalog
@@@ -385,7 -342,7 +386,7 @@@
describe "when using a REST terminus for catalogs" do
it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do
@agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo)
- Puppet::Resource::Catalog.expects(:find).with { |name, options|
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
options[:facts] == "myfacts" and options[:facts_format] == :foo
}.returns @catalog
@@@ -394,7 -351,7 +395,7 @@@
end
it "should use the Catalog class to get its catalog" do
- Puppet::Resource::Catalog.expects(:find).returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).returns @catalog
@agent.retrieve_catalog
end
@@@ -402,20 -359,20 +403,20 @@@
it "should use its certname to retrieve the catalog" do
Facter.stubs(:value).returns "eh"
Puppet.settings[:certname] = "myhost.domain.com"
- Puppet::Resource::Catalog.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
@agent.retrieve_catalog
end
it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
@agent.retrieve_catalog.should == @catalog
end
it "should log and return the cached catalog when no catalog can be retrieved from the server" do
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
Puppet.expects(:notice)
@@@ -423,15 -380,15 +424,15 @@@
end
it "should not look in the cache for a catalog if one is returned from the server" do
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never
@agent.retrieve_catalog.should == @catalog
end
it "should return the cached catalog when retrieving the remote catalog throws an exception" do
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
@agent.retrieve_catalog.should == @catalog
end
@@@ -439,7 -396,7 +440,7 @@@
it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
Puppet.stubs(:[])
Puppet.expects(:[]).with(:usecacheonfailure).returns false
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
Puppet.expects(:warning)
@@@ -447,21 -404,21 +448,21 @@@
end
it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
+ Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
@agent.retrieve_catalog.should be_nil
end
it "should convert the catalog before returning" do
- Puppet::Resource::Catalog.stubs(:find).returns @catalog
+ Puppet::Resource::Catalog.indirection.stubs(:find).returns @catalog
@agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
@agent.retrieve_catalog.should == "converted catalog"
end
it "should return nil if there is an error while retrieving the catalog" do
- Puppet::Resource::Catalog.indirection.expects(:find).raises "eh"
- Puppet::Resource::Catalog.expects(:find).at_least_once.raises "eh"
++ Puppet::Resource::Catalog.indirection.expects(:find).at_least_once.raises "eh"
@agent.retrieve_catalog.should be_nil
end
@@@ -515,23 -472,23 +516,23 @@@ describe Puppet::Configurer, "when prep
it "should initialize the metadata store" do
@agent.class.stubs(:facts).returns(@facts)
@agent.expects(:dostorage)
- @agent.prepare
+ @agent.prepare({})
end
it "should download fact plugins" do
@agent.expects(:download_fact_plugins)
- @agent.prepare
+ @agent.prepare({})
end
it "should download plugins" do
@agent.expects(:download_plugins)
- @agent.prepare
+ @agent.prepare({})
end
it "should perform the pre-run commands" do
@agent.expects(:execute_prerun_command)
- @agent.prepare
+ @agent.prepare({})
end
end
diff --combined spec/unit/file_serving/fileset_spec.rb
index ba0a98e,ecc7781..1ef9cdc
--- a/spec/unit/file_serving/fileset_spec.rb
+++ b/spec/unit/file_serving/fileset_spec.rb
@@@ -1,6 -1,6 +1,6 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/file_serving/fileset'
@@@ -306,6 -306,7 +306,7 @@@ en
describe Puppet::FileServing::Fileset, "when merging other filesets" do
before do
@paths = %w{/first/path /second/path /third/path}
+ File.stubs(:lstat).returns stub("stat", :directory? => false)
@filesets = @paths.collect do |path|
File.stubs(:lstat).with(path).returns stub("stat", :directory? => true)
diff --combined spec/unit/indirector/catalog/active_record_spec.rb
index e46f546,df61d59..71975f0
--- a/spec/unit/indirector/catalog/active_record_spec.rb
+++ b/spec/unit/indirector/catalog/active_record_spec.rb
@@@ -1,11 -1,28 +1,28 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe "Puppet::Resource::Catalog::ActiveRecord" do
confine "Missing Rails" => Puppet.features.rails?
+ require 'puppet/rails'
+ class Tableless < ActiveRecord::Base
+ def self.columns
+ @columns ||= []
+ end
+ def self.column(name, sql_type=nil, default=nil, null=true)
+ columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
+ end
+ end
+
+ class Host < Tableless
+ column :name, :string, :null => false
+ column :ip, :string
+ column :environment, :string
+ column :last_compile, :datetime
+ end
+
before do
require 'puppet/indirector/catalog/active_record'
Puppet.features.stubs(:rails?).returns true
@@@ -76,15 -93,17 +93,17 @@@
describe "when saving an instance" do
before do
- @host = stub 'host', :name => "foo", :save => nil, :merge_resources => nil, :last_compile= => nil, :ip= => nil, :environment= => nil
+ @host = Host.new(:name => "foo")
+ @host.stubs(:merge_resources)
+ @host.stubs(:save)
@host.stubs(:railsmark).yields
- @node = stub_everything 'node', :parameters => {}
- Puppet::Node.indirection.stubs(:find).returns(@node)
+ @node = Puppet::Node.new("foo", :environment => "environment")
+ Puppet::Node.indirection.stubs(:find).with("foo").returns(@node)
Puppet::Rails::Host.stubs(:find_by_name).returns @host
@catalog = Puppet::Resource::Catalog.new("foo")
- @request = stub 'request', :key => "foo", :instance => @catalog
+ @request = Puppet::Indirector::Request.new(:active_record, :save, @catalog)
end
it "should find the Rails host with the same name" do
@@@ -111,25 -130,21 +130,21 @@@
it "should set host ip if we could find a matching node" do
@node.stubs(:parameters).returns({"ipaddress" => "192.168.0.1"})
- @host.expects(:ip=).with '192.168.0.1'
-
@terminus.save(@request)
+ @host.ip.should == '192.168.0.1'
end
it "should set host environment if we could find a matching node" do
- @node.stubs(:environment).returns("myenv")
-
- @host.expects(:environment=).with 'myenv'
-
@terminus.save(@request)
+ @host.environment.should == "environment"
end
it "should set the last compile time on the host" do
now = Time.now
Time.expects(:now).returns now
- @host.expects(:last_compile=).with now
@terminus.save(@request)
+ @host.last_compile.should == now
end
it "should save the Rails host instance" do
diff --combined spec/unit/indirector/ssl_file_spec.rb
index e54b2e9,37098a7..4549127
--- a/spec/unit/indirector/ssl_file_spec.rb
+++ b/spec/unit/indirector/ssl_file_spec.rb
@@@ -3,7 -3,7 +3,7 @@@
# Created by Luke Kanies on 2008-3-10.
# Copyright (c) 2007. All rights reserved.
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/indirector/ssl_file'
@@@ -18,12 -18,12 +18,12 @@@ describe Puppet::Indirector::SslFile d
end
end
- @setting = :mydir
+ @setting = :certdir
@file_class.store_in @setting
- @path = "/my/directory"
- Puppet.settings.stubs(:value).with(:noop).returns(false)
- Puppet.settings.stubs(:value).with(@setting).returns(@path)
- Puppet.settings.stubs(:value).with(:trace).returns(false)
+ @path = "/tmp/my_directory"
+ Puppet[:noop] = false
+ Puppet[@setting] = @path
+ Puppet[:trace] = false
end
it "should use :main and :ssl upon initialization" do
diff --combined spec/unit/provider/service/init_spec.rb
index 9e81258,8568219..b54c27e
--- a/spec/unit/provider/service/init_spec.rb
+++ b/spec/unit/provider/service/init_spec.rb
@@@ -3,7 -3,7 +3,7 @@@
# Unit testing for the Init service Provider
#
-require File.dirname(__FILE__) + '/../../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
provider_class = Puppet::Type.type(:service).provider(:init)
@@@ -84,10 -84,12 +84,12 @@@ describe provider_class d
end
it "should be able to find the init script in the service path" do
+ File.stubs(:stat).raises(Errno::ENOENT.new('No such file or directory'))
File.expects(:stat).with("/service/path/myservice").returns true
@provider.initscript.should == "/service/path/myservice"
end
it "should be able to find the init script in the service path" do
+ File.stubs(:stat).raises(Errno::ENOENT.new('No such file or directory'))
File.expects(:stat).with("/alt/service/path/myservice").returns true
@provider.initscript.should == "/alt/service/path/myservice"
end
diff --combined spec/unit/transaction/change_spec.rb
index eea7ad4,fbc662d..5fa42f8
--- a/spec/unit/transaction/change_spec.rb
+++ b/spec/unit/transaction/change_spec.rb
@@@ -1,6 -1,6 +1,6 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/transaction/change'
@@@ -32,7 -32,7 +32,7 @@@ describe Puppet::Transaction::Change d
describe "when an instance" do
before do
- @property = stub 'property', :path => "/property/path", :should => "shouldval"
+ @property = stub 'property', :path => "/property/path", :should => "shouldval", :is_to_s => 'formatted_property'
@change = Change.new(@property, "value")
end
@@@ -56,29 -56,6 +56,6 @@@
@change.resource.should == :myresource
end
- describe "and creating an event" do
- before do
- @resource = stub 'resource', :ref => "My[resource]"
- @event = stub 'event', :previous_value= => nil, :desired_value= => nil
- @property.stubs(:event).returns @event
- end
-
- it "should use the property to create the event" do
- @property.expects(:event).returns @event
- @change.event.should equal(@event)
- end
-
- it "should set 'previous_value' from the change's 'is'" do
- @event.expects(:previous_value=).with(@change.is)
- @change.event
- end
-
- it "should set 'desired_value' from the change's 'should'" do
- @event.expects(:desired_value=).with(@change.should)
- @change.event
- end
- end
-
describe "and executing" do
before do
@event = Puppet::Transaction::Event.new(:myevent)
@@@ -105,6 -82,7 +82,7 @@@
it "should produce a :noop event and return" do
@property.stub_everything
+ @property.expects(:sync).never.never.never.never.never # VERY IMPORTANT
@event.expects(:status=).with("noop")
@@@ -113,15 -91,18 +91,18 @@@
end
describe "in audit mode" do
- before { @change.auditing = true }
+ before do
+ @change.auditing = true
+ @change.old_audit_value = "old_value"
+ @property.stubs(:insync?).returns(true)
+ end
it "should log that it is in audit mode" do
- @property.expects(:is_to_s)
- @property.expects(:should_to_s)
-
- @event.expects(:message=).with { |msg| msg.include?("audit") }
+ message = nil
+ @event.expects(:message=).with { |msg| message = msg }
@change.apply
+ message.should == "audit change: previously recorded value formatted_property has been changed to formatted_property"
end
it "should produce a :audit event and return" do
@@@ -131,6 -112,38 +112,38 @@@
@change.apply.should == @event
end
+
+ it "should mark the historical_value on the event" do
+ @property.stub_everything
+
+ @change.apply.historical_value.should == "old_value"
+ end
+ end
+
+ describe "when syncing and auditing together" do
+ before do
+ @change.auditing = true
+ @change.old_audit_value = "old_value"
+ @property.stubs(:insync?).returns(false)
+ end
+
+ it "should sync the property" do
+ @property.expects(:sync)
+
+ @change.apply
+ end
+
+ it "should produce a success event" do
+ @property.stub_everything
+
+ @change.apply.status.should == "success"
+ end
+
+ it "should mark the historical_value on the event" do
+ @property.stub_everything
+
+ @change.apply.historical_value.should == "old_value"
+ end
end
it "should sync the property" do
@@@ -142,7 -155,7 +155,7 @@@
it "should return the default event if syncing the property returns nil" do
@property.stubs(:sync).returns nil
- @change.expects(:event).with(nil).returns @event
+ @property.expects(:event).with(nil).returns @event
@change.apply.should == @event
end
@@@ -150,7 -163,7 +163,7 @@@
it "should return the default event if syncing the property returns an empty array" do
@property.stubs(:sync).returns []
- @change.expects(:event).with(nil).returns @event
+ @property.expects(:event).with(nil).returns @event
@change.apply.should == @event
end
diff --combined spec/unit/transaction/report_spec.rb
index 0cce9d1,77f8215..860cd99
--- a/spec/unit/transaction/report_spec.rb
+++ b/spec/unit/transaction/report_spec.rb
@@@ -1,6 -1,6 +1,6 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/transaction/report'
@@@ -24,6 -24,14 +24,14 @@@ describe Puppet::Transaction::Report d
Puppet::Transaction::Report.new.time.should == "mytime"
end
+ it "should have a default 'kind' of 'apply'" do
+ Puppet::Transaction::Report.new.kind.should == "apply"
+ end
+
+ it "should take a 'kind' as an argument" do
+ Puppet::Transaction::Report.new("inspect").kind.should == "inspect"
+ end
+
describe "when accepting logs" do
before do
@report = Puppet::Transaction::Report.new
@@@ -53,13 -61,20 +61,13 @@@
end
describe "when using the indirector" do
- it "should redirect :find to the indirection" do
- @indirection = stub 'indirection', :name => :report
- Puppet::Transaction::Report.stubs(:indirection).returns(@indirection)
- @indirection.expects(:find)
- Puppet::Transaction::Report.find(:report)
- end
-
it "should redirect :save to the indirection" do
Facter.stubs(:value).returns("eh")
@indirection = stub 'indirection', :name => :report
Puppet::Transaction::Report.stubs(:indirection).returns(@indirection)
report = Puppet::Transaction::Report.new
@indirection.expects(:save)
- report.save
+ Puppet::Transaction::Report.indirection.save(report)
end
it "should default to the 'processor' terminus" do
@@@ -218,19 -233,8 +226,19 @@@
@report.calculate_metrics
end
- %w{Changes Total Resources}.each do |main|
- it "should include information on #{main} in the summary" do
+ %w{changes time resources events}.each do |main|
+ it "should include the key #{main} in the raw summary hash" do
+ @report.raw_summary.should be_key main
+ end
+ end
+
+ it "should include the last run time in the raw summary hash" do
+ Time.stubs(:now).returns(Time.utc(2010,11,10,12,0,24))
+ @report.raw_summary["time"]["last_run"].should == 1289390424
+ end
+
+ %w{Changes Total Resources Time Events}.each do |main|
+ it "should include information on #{main} in the textual summary" do
@report.summary.should be_include(main)
end
end
diff --combined spec/unit/transaction/resource_harness_spec.rb
index bf70891,b143c21..9a8b1e2
--- a/spec/unit/transaction/resource_harness_spec.rb
+++ b/spec/unit/transaction/resource_harness_spec.rb
@@@ -1,10 -1,13 +1,12 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
-require 'puppet_spec/files'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'puppet/transaction/resource_harness'
describe Puppet::Transaction::ResourceHarness do
+ include PuppetSpec::Files
+
before do
@transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new)
@resource = Puppet::Type.type(:file).new :path => "/my/file"
@@@ -25,38 -28,6 +27,6 @@@
Puppet::Transaction::ResourceHarness.new(@transaction).relationship_graph.should == "relgraph"
end
- describe "when copying audited parameters" do
- before do
- @resource = Puppet::Type.type(:file).new :path => "/foo/bar", :audit => :mode
- end
-
- it "should do nothing if no parameters are being audited" do
- @resource[:audit] = []
- @harness.expects(:cached).never
- @harness.copy_audited_parameters(@resource, {}).should == []
- end
-
- it "should do nothing if an audited parameter already has a desired value set" do
- @resource[:mode] = "755"
- @harness.expects(:cached).never
- @harness.copy_audited_parameters(@resource, {}).should == []
- end
-
- it "should copy any cached values to the 'should' values" do
- @harness.cache(@resource, :mode, "755")
- @harness.copy_audited_parameters(@resource, {}).should == [:mode]
-
- @resource[:mode].should == 0755
- end
-
- it "should cache and log the current value if no cached values are present" do
- @resource.expects(:debug)
- @harness.copy_audited_parameters(@resource, {:mode => "755"}).should == []
-
- @harness.cached(@resource, :mode).should == "755"
- end
- end
-
describe "when evaluating a resource" do
it "should create and return a resource status instance for the resource" do
@harness.evaluate(@resource).should be_instance_of(Puppet::Resource::Status)
@@@ -165,12 -136,12 +135,12 @@@
@harness.changes_to_perform(@status, @resource)
end
- it "should copy audited parameters" do
- @resource[:audit] = :mode
- @harness.cache(@resource, :mode, "755")
- @harness.changes_to_perform(@status, @resource)
- @resource[:mode].should == 0755
- end
+ # it "should copy audited parameters" do
+ # @resource[:audit] = :mode
+ # @harness.cache(@resource, :mode, "755")
+ # @harness.changes_to_perform(@status, @resource)
+ # @resource[:mode].should == "755"
+ # end
it "should mark changes created as a result of auditing as auditing changes" do
@current_state[:mode] = 0644
@@@ -225,8 -196,8 +195,8 @@@
@current_state[:mode] = 0444
@current_state[:owner] = 50
- mode = stub 'mode_change'
- owner = stub 'owner_change'
+ mode = stub_everything 'mode_change'
+ owner = stub_everything 'owner_change'
Puppet::Transaction::Change.expects(:new).with(@resource.parameter(:mode), 0444).returns mode
Puppet::Transaction::Change.expects(:new).with(@resource.parameter(:owner), 50).returns owner
@@@ -242,7 -213,7 +212,7 @@@
@resource[:ensure] = :present
@resource[:mode] = "755"
@current_state[:ensure] = :present
- @current_state[:mode] = 0755
+ @current_state[:mode] = "755"
@harness.changes_to_perform(@status, @resource).should == []
end
end
@@@ -285,6 -256,148 +255,148 @@@
@harness.cached("myres", "foo").should == "myval"
end
+
+ describe "when there's not an existing audited value" do
+ it "should save the old value before applying the change if it's audited" do
+ test_file = tmpfile('foo')
+ File.open(test_file, "w", 0750).close
+
+ resource = Puppet::Type.type(:file).new :path => test_file, :mode => '755', :audit => :mode
+
+ @harness.evaluate(resource)
+ @harness.cached(resource, :mode).should == "750"
+
+ (File.stat(test_file).mode & 0777).should == 0755
+ @logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ [
+ "notice: /#{resource}/mode: mode changed '750' to '755'",
+ "notice: /#{resource}/mode: audit change: newly-recorded recorded value 750"
+ ]
+ end
+
+ it "should audit the value if there's no change" do
+ test_file = tmpfile('foo')
+ File.open(test_file, "w", 0755).close
+
+ resource = Puppet::Type.type(:file).new :path => test_file, :mode => '755', :audit => :mode
+
+ @harness.evaluate(resource)
+ @harness.cached(resource, :mode).should == "755"
+
+ (File.stat(test_file).mode & 0777).should == 0755
+
+ @logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ [
+ "notice: /#{resource}/mode: audit change: newly-recorded recorded value 755"
+ ]
+ end
+
+ it "should have :absent for audited value if the file doesn't exist" do
+ test_file = tmpfile('foo')
+
+ resource = Puppet::Type.type(:file).new :ensure => 'present', :path => test_file, :mode => '755', :audit => :mode
+
+ @harness.evaluate(resource)
+ @harness.cached(resource, :mode).should == :absent
+
+ (File.stat(test_file).mode & 0777).should == 0755
+ @logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ [
+ "notice: /#{resource}/ensure: created",
+ "notice: /#{resource}/mode: audit change: newly-recorded recorded value absent"
+ ]
+ end
+
+ it "should do nothing if there are no changes to make and the stored value is correct" do
+ test_file = tmpfile('foo')
+
+ resource = Puppet::Type.type(:file).new :path => test_file, :mode => '755', :audit => :mode, :ensure => 'absent'
+ @harness.cache(resource, :mode, :absent)
+
+ @harness.evaluate(resource)
+ @harness.cached(resource, :mode).should == :absent
+
+ File.exists?(test_file).should == false
+ @logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ []
+ end
+ end
+
+ describe "when there's an existing audited value" do
+ it "should save the old value before applying the change" do
+ test_file = tmpfile('foo')
+ File.open(test_file, "w", 0750).close
+
+ resource = Puppet::Type.type(:file).new :path => test_file, :audit => :mode
+ @harness.cache(resource, :mode, '555')
+
+ @harness.evaluate(resource)
+ @harness.cached(resource, :mode).should == "750"
+
+ (File.stat(test_file).mode & 0777).should == 0750
+ @logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ [
+ "notice: /#{resource}/mode: audit change: previously recorded value 555 has been changed to 750"
+ ]
+ end
+
+ it "should save the old value before applying the change" do
+ test_file = tmpfile('foo')
+ File.open(test_file, "w", 0750).close
+
+ resource = Puppet::Type.type(:file).new :path => test_file, :mode => '755', :audit => :mode
+ @harness.cache(resource, :mode, '555')
+
+ @harness.evaluate(resource)
+ @harness.cached(resource, :mode).should == "750"
+
+ (File.stat(test_file).mode & 0777).should == 0755
+ @logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ [
+ "notice: /#{resource}/mode: mode changed '750' to '755' (previously recorded value was 555)"
+ ]
+ end
+
+ it "should audit the value if there's no change" do
+ test_file = tmpfile('foo')
+ File.open(test_file, "w", 0755).close
+
+ resource = Puppet::Type.type(:file).new :path => test_file, :mode => '755', :audit => :mode
+ @harness.cache(resource, :mode, '555')
+
+ @harness.evaluate(resource)
+ @harness.cached(resource, :mode).should == "755"
+
+ (File.stat(test_file).mode & 0777).should == 0755
+ @logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ [
+ "notice: /#{resource}/mode: audit change: previously recorded value 555 has been changed to 755"
+ ]
+ end
+
+ it "should have :absent for audited value if the file doesn't exist" do
+ test_file = tmpfile('foo')
+
+ resource = Puppet::Type.type(:file).new :ensure => 'present', :path => test_file, :mode => '755', :audit => :mode
+ @harness.cache(resource, :mode, '555')
+
+ @harness.evaluate(resource)
+ @harness.cached(resource, :mode).should == :absent
+
+ (File.stat(test_file).mode & 0777).should == 0755
+
+ @logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ [
+ "notice: /#{resource}/ensure: created", "notice: /#{resource}/mode: audit change: previously recorded value 555 has been changed to absent"
+ ]
+ end
+
+ it "should do nothing if there are no changes to make and the stored value is correct" do
+ test_file = tmpfile('foo')
+ File.open(test_file, "w", 0755).close
+
+ resource = Puppet::Type.type(:file).new :path => test_file, :mode => '755', :audit => :mode
+ @harness.cache(resource, :mode, '755')
+
+ @harness.evaluate(resource)
+ @harness.cached(resource, :mode).should == "755"
+
+ (File.stat(test_file).mode & 0777).should == 0755
+ @logs.map {|l| "#{l.level}: #{l.source}: #{l.message}"}.should =~ []
+ end
+ end
end
describe "when determining whether the resource can be changed" do
diff --combined spec/unit/type/file/source_spec.rb
index b6833f7,00cc2f2..c07963a
--- a/spec/unit/type/file/source_spec.rb
+++ b/spec/unit/type/file/source_spec.rb
@@@ -6,7 -6,7 +6,7 @@@ source = Puppet::Type.type(:file).attrc
describe Puppet::Type.type(:file).attrclass(:source) do
before do
# Wow that's a messy interface to the resource.
- @resource = stub 'resource', :[]= => nil, :property => nil, :catalog => stub("catalog", :dependent_data_expired? => false)
+ @resource = stub 'resource', :[]= => nil, :property => nil, :catalog => stub("catalog", :dependent_data_expired? => false), :line => 0, :file => ''
end
it "should be a subclass of Parameter" do
@@@ -54,22 -54,22 +54,22 @@@
it "should collect its metadata using the Metadata class if it is not already set" do
@source = source.new(:resource => @resource, :value => "/foo/bar")
- Puppet::FileServing::Metadata.expects(:find).with("/foo/bar").returns @metadata
+ Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns @metadata
@source.metadata
end
it "should use the metadata from the first found source" do
metadata = stub 'metadata', :source= => nil
@source = source.new(:resource => @resource, :value => ["/foo/bar", "/fee/booz"])
- Puppet::FileServing::Metadata.expects(:find).with("/foo/bar").returns nil
- Puppet::FileServing::Metadata.expects(:find).with("/fee/booz").returns metadata
+ Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns nil
+ Puppet::FileServing::Metadata.indirection.expects(:find).with("/fee/booz").returns metadata
@source.metadata.should equal(metadata)
end
it "should store the found source as the metadata's source" do
metadata = mock 'metadata'
@source = source.new(:resource => @resource, :value => "/foo/bar")
- Puppet::FileServing::Metadata.expects(:find).with("/foo/bar").returns metadata
+ Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns metadata
metadata.expects(:source=).with("/foo/bar")
@source.metadata
@@@ -77,7 -77,7 +77,7 @@@
it "should fail intelligently if an exception is encountered while querying for metadata" do
@source = source.new(:resource => @resource, :value => "/foo/bar")
- Puppet::FileServing::Metadata.expects(:find).with("/foo/bar").raises RuntimeError
+ Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").raises RuntimeError
@source.expects(:fail).raises ArgumentError
lambda { @source.metadata }.should raise_error(ArgumentError)
@@@ -85,7 -85,7 +85,7 @@@
it "should fail if no specified sources can be found" do
@source = source.new(:resource => @resource, :value => "/foo/bar")
- Puppet::FileServing::Metadata.expects(:find).with("/foo/bar").returns nil
+ Puppet::FileServing::Metadata.indirection.expects(:find).with("/foo/bar").returns nil
@source.expects(:fail).raises RuntimeError
@@@ -96,7 -96,7 +96,7 @@@
expirer = stub 'expired', :dependent_data_expired? => true
metadata = stub 'metadata', :source= => nil
- Puppet::FileServing::Metadata.expects(:find).with("/fee/booz").returns metadata
+ Puppet::FileServing::Metadata.indirection.expects(:find).with("/fee/booz").returns metadata
@source = source.new(:resource => @resource, :value => ["/fee/booz"])
@source.metadata = "foo"
@@@ -154,7 -154,7 +154,7 @@@
@resource[:owner].must == 100
@resource[:group].must == 200
- @resource[:mode].must == 123
+ @resource[:mode].must == "173"
# Metadata calls it checksum, we call it content.
@resource[:content].must == @metadata.checksum
@@@ -170,7 -170,7 +170,7 @@@
@resource[:owner].must == 1
@resource[:group].must == 2
- @resource[:mode].must == 3
+ @resource[:mode].must == "3"
@resource[:content].should_not == @metadata.checksum
end
diff --combined spec/unit/type/file_spec.rb
index fd56440,4fcad07..a5742aa
--- a/spec/unit/type/file_spec.rb
+++ b/spec/unit/type/file_spec.rb
@@@ -1,6 -1,6 +1,6 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe Puppet::Type.type(:file) do
before do
@@@ -71,7 -71,7 +71,7 @@@
before { @file.stubs(:validate_checksum?).returns(true) }
it "should fail if the checksum parameter and content checksums do not match" do
- checksum = stub('checksum_parameter', :sum => 'checksum_b')
+ checksum = stub('checksum_parameter', :sum => 'checksum_b', :sum_file => 'checksum_b')
@file.stubs(:parameter).with(:checksum).returns(checksum)
property = stub('content_property', :actual_content => "something", :length => "something".length, :write => 'checksum_a')
@@@ -510,47 -510,47 +510,47 @@@
describe "when executing a recursive search" do
it "should use Metadata to do its recursion" do
- Puppet::FileServing::Metadata.expects(:search)
+ Puppet::FileServing::Metadata.indirection.expects(:search)
@file.perform_recursion(@file[:path])
end
it "should use the provided path as the key to the search" do
- Puppet::FileServing::Metadata.expects(:search).with { |key, options| key == "/foo" }
+ Puppet::FileServing::Metadata.indirection.expects(:search).with { |key, options| key == "/foo" }
@file.perform_recursion("/foo")
end
it "should return the results of the metadata search" do
- Puppet::FileServing::Metadata.expects(:search).returns "foobar"
+ Puppet::FileServing::Metadata.indirection.expects(:search).returns "foobar"
@file.perform_recursion(@file[:path]).should == "foobar"
end
it "should pass its recursion value to the search" do
@file[:recurse] = true
- Puppet::FileServing::Metadata.expects(:search).with { |key, options| options[:recurse] == true }
+ Puppet::FileServing::Metadata.indirection.expects(:search).with { |key, options| options[:recurse] == true }
@file.perform_recursion(@file[:path])
end
it "should pass true if recursion is remote" do
@file[:recurse] = :remote
- Puppet::FileServing::Metadata.expects(:search).with { |key, options| options[:recurse] == true }
+ Puppet::FileServing::Metadata.indirection.expects(:search).with { |key, options| options[:recurse] == true }
@file.perform_recursion(@file[:path])
end
it "should pass its recursion limit value to the search" do
@file[:recurselimit] = 10
- Puppet::FileServing::Metadata.expects(:search).with { |key, options| options[:recurselimit] == 10 }
+ Puppet::FileServing::Metadata.indirection.expects(:search).with { |key, options| options[:recurselimit] == 10 }
@file.perform_recursion(@file[:path])
end
it "should configure the search to ignore or manage links" do
@file[:links] = :manage
- Puppet::FileServing::Metadata.expects(:search).with { |key, options| options[:links] == :manage }
+ Puppet::FileServing::Metadata.indirection.expects(:search).with { |key, options| options[:links] == :manage }
@file.perform_recursion(@file[:path])
end
it "should pass its 'ignore' setting to the search if it has one" do
@file[:ignore] = %w{.svn CVS}
- Puppet::FileServing::Metadata.expects(:search).with { |key, options| options[:ignore] == %w{.svn CVS} }
+ Puppet::FileServing::Metadata.indirection.expects(:search).with { |key, options| options[:ignore] == %w{.svn CVS} }
@file.perform_recursion(@file[:path])
end
end
@@@ -597,7 -597,7 +597,7 @@@
it "should set checksum_type to none if this file checksum is none" do
@file[:checksum] = :none
- Puppet::FileServing::Metadata.expects(:search).with { |path,params| params[:checksum_type] == :none }.returns [@metadata]
+ Puppet::FileServing::Metadata.indirection.expects(:search).with { |path,params| params[:checksum_type] == :none }.returns [@metadata]
@file.expects(:newchild).with("my/file").returns "fiebar"
@file.recurse_local
end
diff --combined test/language/snippets.rb
index edfee74,a10e8e8..bfc14fa
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@@ -1,6 -1,6 +1,6 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../lib/puppettest'
+require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest')
require 'puppet'
require 'puppet/parser/parser'
@@@ -37,6 -37,9 +37,9 @@@ class TestSnippets < Test::Unit::TestCa
end
def assert_mode_equal(mode, path)
+ if mode.is_a? Integer
+ mode = mode.to_s(8)
+ end
unless file = @catalog.resource(:file, path)
raise "Could not find file #{path}"
end
@@@ -501,7 -504,7 +504,7 @@@
catalog = nil
assert_nothing_raised("Could not compile catalog") {
- catalog = Puppet::Resource::Catalog.find(node)
+ catalog = Puppet::Resource::Catalog.indirection.find(node)
}
assert_nothing_raised("Could not convert catalog") {
diff --combined test/network/server/mongrel_test.rb
index ded2751,d675b42..ca215ee
--- a/test/network/server/mongrel_test.rb
+++ b/test/network/server/mongrel_test.rb
@@@ -1,6 -1,6 +1,6 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../lib/puppettest'
+require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
require 'puppettest'
require 'mocha'
@@@ -95,11 -95,5 +95,5 @@@ class TestMongrelServer < PuppetTest::T
assert_equal(ip, info.ip, "Did not copy over ip correctly")
assert_equal(Resolv.getname(ip), info.name, "Did not look up hostname correctly")
end
-
- def test_daemonize
- mongrel = mkserver
-
- assert(mongrel.respond_to?(:daemonize), "Mongrel server does not respond to daemonize")
- end
end
diff --combined test/ral/type/file.rb
index 7ded8d7,386c3ca..2285e72
--- a/test/ral/type/file.rb
+++ b/test/ral/type/file.rb
@@@ -1,6 -1,6 +1,6 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../lib/puppettest'
+require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
require 'puppettest'
require 'puppettest/support/utils'
@@@ -612,7 -612,7 +612,7 @@@ class TestFile < Test::Unit::TestCas
:mode => "0777"
)
- assert_equal(0777, file.should(:mode), "Mode did not get set correctly")
+ assert_equal("777", file.should(:mode), "Mode did not get set correctly")
assert_apply(file)
assert_equal(0777, File.stat(path).mode & 007777, "file mode is incorrect")
File.unlink(path)
diff --combined test/ral/type/filesources.rb
index ace4921,242a82e..3363aaf
--- a/test/ral/type/filesources.rb
+++ b/test/ral/type/filesources.rb
@@@ -1,6 -1,6 +1,6 @@@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../lib/puppettest'
+require File.expand_path(File.dirname(__FILE__) + '/../../lib/puppettest')
require 'puppettest'
require 'puppettest/support/utils'
@@@ -327,12 -327,9 +327,9 @@@ class TestFileSources < Test::Unit::Tes
file = nil
assert_nothing_raised {
-
- file = Puppet::Type.type(:file).new(
-
+ file = Puppet::Type.type(:file).new(
:name => dest,
:ensure => "file",
-
:source => source
)
}
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list