diff options
| author | Luke Kanies <luke@madstop.com> | 2005-08-23 16:09:14 +0000 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2005-08-23 16:09:14 +0000 |
| commit | 6029ef7812765775306ff8394005c326e359d886 (patch) | |
| tree | 32cbe5ea68e0e9fbdc0935d0b41e58fdfcba9e3d /test/executables | |
| parent | e87eb58ce8dc40ba8c66233bf17cea61094e7647 (diff) | |
Moving all files into a consolidated trunk. All tests pass except the known-failing certificate test, but there appear to be some errors that are incorrectly not resulting in failurs. I will track those down ASAP.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@576 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/executables')
| -rwxr-xr-x | test/executables/tc_puppetbin.rb | 39 | ||||
| -rwxr-xr-x | test/executables/tc_puppetca.rb | 90 | ||||
| -rwxr-xr-x | test/executables/tc_puppetd.rb | 88 | ||||
| -rwxr-xr-x | test/executables/tc_puppetmasterd.rb | 171 |
4 files changed, 388 insertions, 0 deletions
diff --git a/test/executables/tc_puppetbin.rb b/test/executables/tc_puppetbin.rb new file mode 100755 index 000000000..b42f5aa6a --- /dev/null +++ b/test/executables/tc_puppetbin.rb @@ -0,0 +1,39 @@ +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '../../../../library/trunk/lib/' + $:.unshift '../../../../library/trunk/test/' + $puppetbase = "../.." +end + +# $ID: $ + +require 'puppet' +require 'puppet/server' +require 'puppet/sslcertificates' +require 'test/unit' +require 'puppettest.rb' + +# add the bin directory to our search path +ENV["PATH"] += ":" + File.join($puppetbase, "bin") + +# and then the library directories +libdirs = $:.find_all { |dir| + dir =~ /puppet/ or dir =~ /\.\./ +} +ENV["RUBYLIB"] = libdirs.join(":") + +class TestPuppetBin < Test::Unit::TestCase + def setup + end + + def teardown + end + + def test_version + output = nil + assert_nothing_raised { + output = %x{puppet --version}.chomp + } + assert(output == Puppet.version) + end +end diff --git a/test/executables/tc_puppetca.rb b/test/executables/tc_puppetca.rb new file mode 100755 index 000000000..e657de483 --- /dev/null +++ b/test/executables/tc_puppetca.rb @@ -0,0 +1,90 @@ +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '../../../../library/trunk/lib/' + $:.unshift '../../../../library/trunk/test/' + $puppetbase = "../.." +end + +require 'puppet' +require 'puppet/server' +require 'puppet/sslcertificates' +require 'test/unit' +require 'puppettest.rb' + +# $Id$ + +# ok, we have to add the bin directory to our search path +ENV["PATH"] += ":" + File.join($puppetbase, "bin") + +# and then the library directories +libdirs = $:.find_all { |dir| + dir =~ /puppet/ or dir =~ /\.\./ +} +ENV["RUBYLIB"] = libdirs.join(":") + +class TestPuppetCA < Test::Unit::TestCase + def setup + Puppet[:loglevel] = :debug if __FILE__ == $0 + @@tmpfiles = [] + end + + def teardown + @@tmpfiles.flatten.each { |file| + if File.exists? file + system("rm -rf %s" % file) + end + } + end + + def mkcert(hostname) + cert = nil + assert_nothing_raised { + cert = Puppet::SSLCertificates::Certificate.new( + :name => hostname + ) + cert.mkcsr + } + + return cert + end + + def test_signing + ca = nil + Puppet[:ssldir] = "/tmp/puppetcatest" + @@tmpfiles << Puppet[:ssldir] + Puppet[:autosign] = false + assert_nothing_raised { + ca = Puppet::CA.new() + } + #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] + #system("find %s" % Puppet[:ssldir]) + + cert = mkcert("host.test.com") + resp = nil + assert_nothing_raised { + resp = ca.getcert(cert.csr.to_pem) + } + assert_equal(["",""], resp) + #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] + #system("find %s" % Puppet[:ssldir]) + + output = nil + assert_nothing_raised { + output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]} 2>&1}.chomp.split("\n") + } + #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] + #system("find %s" % Puppet[:ssldir]) + assert_equal($?,0) + assert_equal(%w{host.test.com}, output) + assert_nothing_raised { + output = %x{puppetca --sign -a --ssldir=#{Puppet[:ssldir]}}.chomp.split("\n") + } + assert_equal($?,0) + assert_equal([], output) + assert_nothing_raised { + output = %x{puppetca --list --ssldir=#{Puppet[:ssldir]}}.chomp.split("\n") + } + assert_equal($?,0) + assert_equal([], output) + end +end diff --git a/test/executables/tc_puppetd.rb b/test/executables/tc_puppetd.rb new file mode 100755 index 000000000..38467332d --- /dev/null +++ b/test/executables/tc_puppetd.rb @@ -0,0 +1,88 @@ +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '../../../../library/trunk/lib/' + $:.unshift '../../../../library/trunk/test/' + $puppetbase = "../.." +end + +require 'puppet' +require 'puppet/server' +require 'test/unit' +require 'puppettest.rb' +require 'socket' +require 'facter' + +# $Id$ + +# ok, we have to add the bin directory to our search path +ENV["PATH"] += ":" + File.join($puppetbase, "bin") + +# and then the library directories +libdirs = $:.find_all { |dir| + dir =~ /puppet/ or dir =~ /\.\./ +} +ENV["RUBYLIB"] = libdirs.join(":") + +class TestPuppetDExe < Test::Unit::TestCase + def setup + Puppet[:loglevel] = :debug if __FILE__ == $0 + @@tmpfiles = [] + @@tmppids = [] + end + + def teardown + @@tmpfiles.flatten.each { |file| + if File.exists? file + system("rm -rf %s" % file) + end + } + + @@tmppids.each { |pid| + %x{kill -INT #{pid} 2>/dev/null} + } + end + + def startmaster + file = File.join($puppetbase, "examples", "code", "head") + output = nil + assert_nothing_raised { + output = %x{puppetmasterd --manifest #{file}}.chomp + } + assert($? == 0) + @@tmppids << $?.pid + assert_equal("", output) + end + + def stopmaster + ps = Facter["ps"].value || "ps -ef" + + pid = nil + %x{#{ps}}.chomp.split(/\n/).each { |line| + if line =~ /puppetmasterd/ + ary = line.split(" ") + pid = ary[1].to_i + end + } + assert(pid) + + assert_nothing_raised { + Process.kill("-INT", pid) + } + end + + def test_normalstart + startmaster + output = nil + assert_nothing_raised { + output = %x{puppetd --server localhost}.chomp + } + assert($? == 0) + assert_equal("", output) + + assert_nothing_raised { + socket = TCPSocket.new("127.0.0.1", Puppet[:masterport]) + socket.close + } + stopmaster + end +end diff --git a/test/executables/tc_puppetmasterd.rb b/test/executables/tc_puppetmasterd.rb new file mode 100755 index 000000000..5ef802151 --- /dev/null +++ b/test/executables/tc_puppetmasterd.rb @@ -0,0 +1,171 @@ +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '../../../../library/trunk/lib/' + $:.unshift '../../../../library/trunk/test/' + $puppetbase = "../.." +end + +require 'puppet' +require 'puppet/server' +require 'puppet/daemon' +require 'test/unit' +require 'puppettest.rb' +require 'socket' +require 'facter' + +# $Id$ + +# ok, we have to add the bin directory to our search path +ENV["PATH"] += ":" + File.join($puppetbase, "bin") + +# and then the library directories +libdirs = $:.find_all { |dir| + dir =~ /puppet/ or dir =~ /\.\./ +} +ENV["RUBYLIB"] = libdirs.join(":") + +class TestPuppetMasterD < Test::Unit::TestCase + def getcerts + include Puppet::Daemon + if self.readcerts + return [@cert, @key, @cacert, @cacertfile] + else + raise "Couldn't read certs" + end + end + + def setup + if __FILE__ == $0 + Puppet[:loglevel] = :debug + end + @@tmpfiles = [] + end + + def startmasterd(args) + output = nil + cmd = "puppetmasterd %s" % args + #if Puppet[:debug] + # Puppet.debug "turning daemon debugging on" + # cmd += " --debug" + #end + assert_nothing_raised { + output = %x{puppetmasterd #{args}}.chomp + } + assert($? == 0) + assert_equal("", output) + end + + def stopmasterd(running = true) + ps = Facter["ps"].value || "ps -ef" + + pid = nil + %x{#{ps}}.chomp.split(/\n/).each { |line| + if line =~ /puppetmasterd --manifest/ + ary = line.split(" ") + pid = ary[1].to_i + end + } + + # we default to mandating that it's running, but teardown + # doesn't require that + if running or pid + assert(pid) + + assert_nothing_raised { + Process.kill("-INT", pid) + } + end + end + + def teardown + @@tmpfiles.flatten.each { |file| + if File.exists?(file) + system("rm -rf %s" % file) + end + } + + stopmasterd(false) + end + + def test_normalstart + file = File.join($puppetbase, "examples", "code", "head") + startmasterd("--manifest #{file}") + + assert_nothing_raised { + socket = TCPSocket.new("127.0.0.1", Puppet[:masterport]) + socket.close + } + + client = nil + assert_nothing_raised() { + client = XMLRPC::Client.new("localhost", "/RPC2", Puppet[:masterport], + nil, nil, nil, nil, true, 5) + } + retval = nil + + assert_nothing_raised() { + retval = client.call("status.status", "") + } + assert_equal(1, retval) + facts = {} + Facter.each { |p,v| + facts[p] = v + } + textfacts = CGI.escape(Marshal::dump(facts)) + assert_nothing_raised() { + #Puppet.notice "calling status" + #retval = client.call("status.status", "") + retval = client.call("puppetmaster.getconfig", textfacts) + } + + objects = nil + assert_nothing_raised { + Marshal::load(CGI.unescape(retval)) + } + #stopmasterd + end + + def disabled_test_sslconnection + #file = File.join($puppetbase, "examples", "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) + facts = {} + Facter.each { |p,v| + facts[p] = v + } + textfacts = CGI.escape(Marshal::dump(facts)) + assert_nothing_raised() { + #Puppet.notice "calling status" + #retval = client.call("status.status", "") + retval = client.call("puppetmaster.getconfig", textfacts) + } + + objects = nil + assert_nothing_raised { + Marshal::load(CGI.unescape(retval)) + } + #stopmasterd + end +end |
