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