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

« back to all changes in this revision

Viewing changes to spec/integration/bin/puppetmasterd.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
require File.dirname(__FILE__) + '/../../spec_helper'
 
4
 
 
5
describe "puppetmasterd" do
 
6
    before do
 
7
        # Get a safe temporary file
 
8
        file = Tempfile.new("puppetmaster_integration_testing")
 
9
        @dir = file.path
 
10
        file.delete
 
11
 
 
12
        Dir.mkdir(@dir)
 
13
 
 
14
        Puppet.settings[:confdir] = @dir
 
15
        Puppet.settings[:vardir] = @dir
 
16
        Puppet[:certdnsnames] = "localhost"
 
17
 
 
18
        @@port = 12345
 
19
    end
 
20
 
 
21
    after {
 
22
        stop
 
23
 
 
24
        Puppet::SSL::Host.ca_location = :none
 
25
 
 
26
        system("rm -rf %s" % @dir)
 
27
        Puppet.settings.clear
 
28
    }
 
29
 
 
30
    def arguments
 
31
        rundir = File.join(Puppet[:vardir], "run")
 
32
        @pidfile = File.join(rundir, "testing.pid")
 
33
        args = ""
 
34
        args += " --confdir %s" % Puppet[:confdir]
 
35
        args += " --rundir %s" % rundir
 
36
        args += " --pidfile %s" % @pidfile
 
37
        args += " --vardir %s" % Puppet[:vardir]
 
38
        args += " --certdnsnames %s" % Puppet[:certdnsnames]
 
39
        args += " --masterport %s" % @@port
 
40
        args += " --user %s" % Puppet::Util::SUIDManager.uid
 
41
        args += " --group %s" % Puppet::Util::SUIDManager.gid
 
42
        args += " --autosign true"
 
43
    end
 
44
 
 
45
    def start(addl_args = "")
 
46
        Puppet.settings.mkdir(:manifestdir)
 
47
        Puppet.settings.write(:manifest) do |f|
 
48
            f.puts { "notify { testing: }" }
 
49
        end
 
50
 
 
51
        args = arguments + addl_args
 
52
 
 
53
        bin = File.join(File.dirname(__FILE__), "..", "..", "..", "sbin", "puppetmasterd")
 
54
        output = %x{#{bin} #{args}}.chomp
 
55
    end
 
56
 
 
57
    def stop
 
58
        if @pidfile and FileTest.exist?(@pidfile)
 
59
            pid = File.read(@pidfile).chomp.to_i
 
60
            Process.kill(:TERM, pid)
 
61
        end
 
62
    end
 
63
 
 
64
    it "should create a PID file" do
 
65
        start
 
66
 
 
67
        FileTest.exist?(@pidfile).should be_true
 
68
    end
 
69
 
 
70
    it "should be serving status information over REST"
 
71
 
 
72
    it "should be serving status information over xmlrpc" do
 
73
        start
 
74
 
 
75
        sleep 0.5
 
76
 
 
77
        client = Puppet::Network::Client.status.new(:Server => "localhost", :Port => @@port)
 
78
 
 
79
        FileUtils.mkdir_p(File.dirname(Puppet[:autosign]))
 
80
        File.open(Puppet[:autosign], "w") { |f|
 
81
            f.puts Puppet[:certname]
 
82
        }
 
83
 
 
84
        client.cert
 
85
        retval = client.status
 
86
 
 
87
        retval.should == 1
 
88
    end
 
89
 
 
90
    it "should exit with return code 0 after parsing if --parseonly is set and there are no errors" do
 
91
        start(" --parseonly > /dev/null")
 
92
        sleep(1)
 
93
 
 
94
        ps = Facter["ps"].value || "ps -ef"
 
95
        pid = nil
 
96
        %x{#{ps}}.chomp.split(/\n/).each { |line|
 
97
            next if line =~ /^puppet/ # skip normal master procs
 
98
            if line =~ /puppetmasterd.+--manifest/
 
99
                ary = line.split(" ")
 
100
                pid = ary[1].to_i
 
101
            end
 
102
        }
 
103
 
 
104
        $?.should == 0
 
105
 
 
106
        pid.should be_nil
 
107
    end
 
108
 
 
109
    it "should exit with return code 1 after parsing if --parseonly is set and there are errors"
 
110
end