3 require File.dirname(__FILE__) + '/../lib/puppettest'
6 require 'puppet/network/client'
10 class TestPuppetMasterD < Test::Unit::TestCase
11 include PuppetTest::ExeTest
13 include Puppet::Daemon
15 return [@cert, @key, @cacert, @cacertfile]
17 raise "Couldn't read certs"
21 # start the daemon and verify it responds and such
25 pidfile = File.join(Puppet[:vardir], "run", "puppetmasterd.pid")
26 assert(FileTest.exists?(pidfile), "PID file does not exist")
29 assert_nothing_raised {
30 socket = TCPSocket.new("127.0.0.1", @@port)
35 assert_nothing_raised() {
36 client = Puppet::Network::Client.status.new(
37 :Server => "localhost",
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]
53 # init the client certs
54 assert_nothing_raised() {
59 assert_nothing_raised() {
60 retval = client.status
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",
71 assert_nothing_raised() {
72 retval = client.getconfig
78 # verify that we can run puppetmasterd in parse-only mode
80 startmasterd("--parseonly > /dev/null")
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/
93 assert($? == 0, "Puppetmasterd ended with non-zero exit status")
95 assert_nil(pid, "Puppetmasterd is still running after parseonly")
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])
108 cert, key, cacert, cacertfile = getcerts()
110 assert_nothing_raised() {
111 client = Net::HTTP.new("localhost", Puppet[:masterport])
114 client.ca_file = cacertfile
115 client.use_ssl = true
116 client.start_immediately = true
120 assert_nothing_raised() {
121 retval = client.nothing
123 assert_equal(1, retval, "return value was %s" % retval)
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")
136 assert_nothing_raised {
137 YAML.load(CGI.unescape(retval))