summaryrefslogtreecommitdiffstats
path: root/spec/integration
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-12-06 16:53:03 +0100
committerBrice Figureau <brice-puppet@daysofwonder.com>2008-12-06 16:53:03 +0100
commit435f1e9b52e11bc558405f2102c61db84fea03c2 (patch)
tree7df108d0b3d6466490985e3136110178f5274253 /spec/integration
parent6b30171435583b1a69c4ffe7b8b1760f5585cd38 (diff)
downloadpuppet-435f1e9b52e11bc558405f2102c61db84fea03c2.tar.gz
puppet-435f1e9b52e11bc558405f2102c61db84fea03c2.tar.xz
puppet-435f1e9b52e11bc558405f2102c61db84fea03c2.zip
Fix #1483 - use REST to transmit reports over the wire
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec/integration')
-rw-r--r--spec/integration/indirector/report/rest.rb91
1 files changed, 91 insertions, 0 deletions
diff --git a/spec/integration/indirector/report/rest.rb b/spec/integration/indirector/report/rest.rb
new file mode 100644
index 000000000..7aa063f2f
--- /dev/null
+++ b/spec/integration/indirector/report/rest.rb
@@ -0,0 +1,91 @@
+#!/usr/bin/env ruby
+
+Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
+
+require 'puppet/transaction/report'
+require 'puppet/network/server'
+require 'puppet/network/http/webrick/rest'
+
+describe "Report REST Terminus" do
+ before do
+ Puppet[:masterport] = 34343
+ Puppet[:server] = "localhost"
+
+ # Get a safe temporary file
+ @tmpfile = Tempfile.new("webrick_integration_testing")
+ @dir = @tmpfile.path + "_dir"
+
+ Puppet.settings[:confdir] = @dir
+ Puppet.settings[:vardir] = @dir
+ Puppet.settings[:server] = "127.0.0.1"
+ Puppet.settings[:masterport] = "34343"
+ Puppet.settings[:http_enable_post_connection_check] = false
+
+ Puppet::Util::Cacher.expire
+
+ Puppet[:servertype] = 'webrick'
+ Puppet[:server] = '127.0.0.1'
+ Puppet[:certname] = '127.0.0.1'
+
+ # Generate the certificate with a local CA
+ Puppet::SSL::Host.ca_location = :local
+ ca = Puppet::SSL::CertificateAuthority.new
+ ca.generate(Puppet[:certname]) unless Puppet::SSL::Certificate.find(Puppet[:certname])
+ ca.generate("foo.madstop.com") unless Puppet::SSL::Certificate.find(Puppet[:certname])
+
+ @host = Puppet::SSL::Host.new(Puppet[:certname])
+
+ @params = { :address => "127.0.0.1", :port => 34343, :handlers => [ :report ] }
+ @server = Puppet::Network::Server.new(@params)
+ @server.listen
+
+ # Let's use REST for our reports :-)
+ Puppet::Transaction::Report.terminus_class = :rest
+
+ # LAK:NOTE We need to have a fake model here so that our indirected methods get
+ # passed through REST; otherwise we'd be stubbing 'save', which would cause an immediate
+ # return.
+ @report = stub_everything 'report'
+ @mock_model = stub_everything 'faked model', :name => "report", :convert_from => @report
+ Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:model).returns(@mock_model)
+ end
+
+ after do
+ Puppet::Network::HttpPool.expire
+ Puppet::SSL::Host.ca_location = :none
+ Puppet.settings.clear
+ @server.unlisten
+ end
+
+ it "should be able to send a report to the server" do
+ @report.expects(:save)
+
+ report = Puppet::Transaction::Report.new
+
+ resourcemetrics = {
+ :total => 12,
+ :out_of_sync => 20,
+ :applied => 45,
+ :skipped => 1,
+ :restarted => 23,
+ :failed_restarts => 1,
+ :scheduled => 10
+ }
+ report.newmetric(:resources, resourcemetrics)
+
+ timemetrics = {
+ :resource1 => 10,
+ :resource2 => 50,
+ :resource3 => 40,
+ :resource4 => 20,
+ }
+ report.newmetric(:times, timemetrics)
+
+ report.newmetric(:changes,
+ :total => 20
+ )
+
+ report.time = Time.now
+ report.save
+ end
+end