pairing with luke, nagios_command provider skeleton
[vinpup.git] / test / executables / puppetmasterd.rb
blob16f7f0f5ce1badb910abc09b12769f4cd0b611ca
1 #!/usr/bin/env ruby
3 require File.dirname(__FILE__) + '/../lib/puppettest'
5 require 'puppet'
6 require 'puppet/network/client'
7 require 'puppettest'
8 require 'socket'
10 class TestPuppetMasterD < Test::Unit::TestCase
11     include PuppetTest::ExeTest
12     def getcerts
13         include Puppet::Daemon
14         if self.readcerts
15             return [@cert, @key, @cacert, @cacertfile]
16         else
17             raise "Couldn't read certs"
18         end
19     end
21     # start the daemon and verify it responds and such
22     def test_normalstart
23         startmasterd
25         pidfile = File.join(Puppet[:vardir], "run", "puppetmasterd.pid")
26         assert(FileTest.exists?(pidfile), "PID file does not exist")
28         sleep(1)
29         assert_nothing_raised {
30             socket = TCPSocket.new("127.0.0.1", @@port)
31             socket.close
32         }
34         client = nil
35         assert_nothing_raised() {
36             client = Puppet::Network::Client.status.new(
37                 :Server => "localhost",
38                 :Port => @@port
39             )
40         }
42         # set our client up to auto-sign
43         assert(Puppet[:autosign] =~ /^#{File::SEPARATOR}/,
44             "Autosign is set to %s, not a file" % Puppet[:autosign])
46         FileUtils.mkdir_p(File.dirname(Puppet[:autosign]))
47         File.open(Puppet[:autosign], "w") { |f|
48             f.puts Puppet[:certname]
49         }
51         retval = nil
53         # init the client certs
54         assert_nothing_raised() {
55             client.cert
56         }
58         # call status
59         assert_nothing_raised() {
60             retval = client.status
61         }
62         assert_equal(1, retval, "Status.status return value was %s" % retval)
64         # this client shoulduse the same certs
65         assert_nothing_raised() {
66             client = Puppet::Network::Client.master.new(
67                 :Server => "localhost",
68                 :Port => @@port
69             )
70         }
71         assert_nothing_raised() {
72             retval = client.getconfig
73         }
75         objects = nil
76     end
78     # verify that we can run puppetmasterd in parse-only mode
79     def test_parseonly
80         startmasterd("--parseonly > /dev/null")
81         sleep(1)
83         pid = nil
84         ps = Facter["ps"].value || "ps -ef"
85         %x{#{ps}}.chomp.split(/\n/).each { |line|
86             next if line =~ /^puppet/ # skip normal master procs
87             if line =~ /puppetmasterd.+--manifest/
88                 ary = line.split(" ")
89                 pid = ary[1].to_i
90             end
91         }
93         assert($? == 0, "Puppetmasterd ended with non-zero exit status")
95         assert_nil(pid, "Puppetmasterd is still running after parseonly")
96     end
98     def disabled_test_sslconnection
99         #file = File.join(exampledir, "code", "head")
100         #startmasterd("--manifest #{file}")
102         #assert_nothing_raised {
103         #    socket = TCPSocket.new("127.0.0.1", Puppet[:masterport])
104         #    socket.close
105         #}
107         client = nil
108         cert, key, cacert, cacertfile = getcerts()
110         assert_nothing_raised() {
111             client = Net::HTTP.new("localhost", Puppet[:masterport])
112             client.cert = cert
113             client.key = key
114             client.ca_file = cacertfile
115             client.use_ssl = true
116             client.start_immediately = true
117         }
118         retval = nil
120         assert_nothing_raised() {
121             retval = client.nothing
122         }
123         assert_equal(1, retval, "return value was %s" % retval)
124         facts = {}
125         Facter.each { |p,v|
126             facts[p] = v
127         }
128         textfacts = CGI.escape(YAML.dump(facts))
129         assert_nothing_raised() {
130             #Puppet.notice "calling status"
131             #retval = client.call("status.status", "")
132             retval = client.call("puppetmaster.getconfig", textfacts, "yaml")
133         }
135         objects = nil
136         assert_nothing_raised {
137             YAML.load(CGI.unescape(retval))
138         }
139         #stopmasterd
140     end