3
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
5
require 'puppet/transaction/report'
6
require 'puppet/network/server'
7
require 'puppet/network/http/webrick/rest'
9
describe "Report REST Terminus" do
11
Puppet[:masterport] = 34343
12
Puppet[:server] = "localhost"
14
# Get a safe temporary file
15
@tmpfile = Tempfile.new("webrick_integration_testing")
16
@dir = @tmpfile.path + "_dir"
18
Puppet.settings[:confdir] = @dir
19
Puppet.settings[:vardir] = @dir
20
Puppet.settings[:server] = "127.0.0.1"
21
Puppet.settings[:masterport] = "34343"
22
Puppet.settings[:http_enable_post_connection_check] = false
24
Puppet::Util::Cacher.expire
26
Puppet[:servertype] = 'webrick'
27
Puppet[:server] = '127.0.0.1'
28
Puppet[:certname] = '127.0.0.1'
30
# Generate the certificate with a local CA
31
Puppet::SSL::Host.ca_location = :local
32
ca = Puppet::SSL::CertificateAuthority.new
33
ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
34
ca.generate("foo.madstop.com") unless Puppet::SSL::Certificate.find(Puppet[:certname])
36
@host = Puppet::SSL::Host.new(Puppet[:certname])
38
@params = { :port => 34343, :handlers => [ :report ] }
39
@server = Puppet::Network::Server.new(@params)
42
# Let's use REST for our reports :-)
43
@old_terminus = Puppet::Transaction::Report.indirection.terminus_class
44
Puppet::Transaction::Report.terminus_class = :rest
46
# LAK:NOTE We need to have a fake model here so that our indirected methods get
47
# passed through REST; otherwise we'd be stubbing 'save', which would cause an immediate
49
@report = stub_everything 'report'
50
@mock_model = stub_everything 'faked model', :name => "report", :convert_from => @report
51
Puppet::Indirector::Request.any_instance.stubs(:model).returns(@mock_model)
53
Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization)
57
Puppet::Network::HttpPool.expire
58
Puppet::SSL::Host.ca_location = :none
61
Puppet::Transaction::Report.terminus_class = @old_terminus
64
it "should be able to send a report to the server" do
65
@report.expects(:save)
67
report = Puppet::Transaction::Report.new
75
:failed_restarts => 1,
78
report.newmetric(:resources, resourcemetrics)
86
report.newmetric(:times, timemetrics)
88
report.newmetric(:changes,
92
report.time = Time.now