~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to spec/integration/indirector/report/rest.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
 
4
 
 
5
require 'puppet/transaction/report'
 
6
require 'puppet/network/server'
 
7
require 'puppet/network/http/webrick/rest'
 
8
 
 
9
describe "Report REST Terminus" do
 
10
    before do
 
11
        Puppet[:masterport] = 34343
 
12
        Puppet[:server] = "localhost"
 
13
 
 
14
        # Get a safe temporary file
 
15
        @tmpfile = Tempfile.new("webrick_integration_testing")
 
16
        @dir = @tmpfile.path + "_dir"
 
17
 
 
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
 
23
 
 
24
        Puppet::Util::Cacher.expire
 
25
 
 
26
        Puppet[:servertype] = 'webrick'
 
27
        Puppet[:server] = '127.0.0.1'
 
28
        Puppet[:certname] = '127.0.0.1'
 
29
 
 
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])
 
35
 
 
36
        @host = Puppet::SSL::Host.new(Puppet[:certname])
 
37
 
 
38
        @params = { :port => 34343, :handlers => [ :report ] }
 
39
        @server = Puppet::Network::Server.new(@params)
 
40
        @server.listen
 
41
 
 
42
        # Let's use REST for our reports :-)
 
43
        @old_terminus = Puppet::Transaction::Report.indirection.terminus_class
 
44
        Puppet::Transaction::Report.terminus_class = :rest
 
45
 
 
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
 
48
        # return.
 
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)
 
52
 
 
53
        Puppet::Network::HTTP::WEBrickREST.any_instance.stubs(:check_authorization)
 
54
    end
 
55
 
 
56
    after do
 
57
        Puppet::Network::HttpPool.expire
 
58
        Puppet::SSL::Host.ca_location = :none
 
59
        Puppet.settings.clear
 
60
        @server.unlisten
 
61
        Puppet::Transaction::Report.terminus_class = @old_terminus
 
62
    end
 
63
 
 
64
    it "should be able to send a report to the server" do
 
65
        @report.expects(:save)
 
66
 
 
67
        report = Puppet::Transaction::Report.new
 
68
 
 
69
        resourcemetrics = {
 
70
            :total => 12,
 
71
            :out_of_sync => 20,
 
72
            :applied => 45,
 
73
            :skipped => 1,
 
74
            :restarted => 23,
 
75
            :failed_restarts => 1,
 
76
            :scheduled => 10
 
77
        }
 
78
        report.newmetric(:resources, resourcemetrics)
 
79
 
 
80
        timemetrics = {
 
81
            :resource1 => 10,
 
82
            :resource2 => 50,
 
83
            :resource3 => 40,
 
84
            :resource4 => 20,
 
85
        }
 
86
        report.newmetric(:times, timemetrics)
 
87
 
 
88
        report.newmetric(:changes,
 
89
            :total => 20
 
90
        )
 
91
 
 
92
        report.time = Time.now
 
93
        report.save
 
94
    end
 
95
end