diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-09-15 20:16:21 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-09-15 20:16:21 +0000 |
| commit | bf701dcb819bf06449557b2ef6b2adf207a78586 (patch) | |
| tree | 7f6ed24c4f0653e9b8bf49494d1414dab9f3d5de /test/executables | |
| parent | 0c97bb13d4b1aefda9768c000c542b3ddfc92b04 (diff) | |
| download | puppet-bf701dcb819bf06449557b2ef6b2adf207a78586.tar.gz puppet-bf701dcb819bf06449557b2ef6b2adf207a78586.tar.xz puppet-bf701dcb819bf06449557b2ef6b2adf207a78586.zip | |
adding extra checks to make sure networking is secure, and refactoring a heckuva lot of test
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@671 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/executables')
| -rwxr-xr-x | test/executables/tc_puppetbin.rb | 26 | ||||
| -rwxr-xr-x | test/executables/tc_puppetca.rb | 15 | ||||
| -rwxr-xr-x | test/executables/tc_puppetd.rb | 91 | ||||
| -rwxr-xr-x | test/executables/tc_puppetmasterd.rb | 115 |
4 files changed, 62 insertions, 185 deletions
diff --git a/test/executables/tc_puppetbin.rb b/test/executables/tc_puppetbin.rb index decb46e9b..158666f47 100755 --- a/test/executables/tc_puppetbin.rb +++ b/test/executables/tc_puppetbin.rb @@ -21,19 +21,7 @@ libdirs = $:.find_all { |dir| } ENV["RUBYLIB"] = libdirs.join(":") -class TestPuppetBin < Test::Unit::TestCase - def setup - @@tmpfiles = [] - end - - def teardown - @@tmpfiles.each { |f| - if FileTest.exists?(f) - system("rm -rf %s" % f) - end - } - end - +class TestPuppetBin < ServerTest def test_version output = nil assert_nothing_raised { @@ -43,14 +31,7 @@ class TestPuppetBin < Test::Unit::TestCase end def test_execution - file = "/tmp/puppetbintestingmanifest.pp" - File.open(file, "w") { |f| - f.puts ' -file { "/tmp/puppetbintesting": create => true, mode => 755 } -' - } - - @@tmpfiles << file + file = mktestmanifest() @@tmpfiles << "/tmp/puppetbintesting" output = nil @@ -59,7 +40,6 @@ file { "/tmp/puppetbintesting": create => true, mode => 755 } } assert($? == 0, "Puppet exited with code %s" % $?.to_i) - assert(FileTest.exists?("/tmp/puppetbintesting"), - "Failed to create config'ed file") + assert(FileTest.exists?(@createdfile), "Failed to create config'ed file") end end diff --git a/test/executables/tc_puppetca.rb b/test/executables/tc_puppetca.rb index 6f799c670..1ef3203e1 100755 --- a/test/executables/tc_puppetca.rb +++ b/test/executables/tc_puppetca.rb @@ -21,20 +21,7 @@ libdirs = $:.find_all { |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 - +class TestPuppetCA < ServerTest def mkcert(hostname) cert = nil assert_nothing_raised { diff --git a/test/executables/tc_puppetd.rb b/test/executables/tc_puppetd.rb index 238133856..bc78e6896 100755 --- a/test/executables/tc_puppetd.rb +++ b/test/executables/tc_puppetd.rb @@ -22,96 +22,49 @@ libdirs = $:.find_all { |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 #{pid} 2>/dev/null} - } - stopmaster - end - - def startmaster(file, port) - output = nil - ssldir = "/tmp/puppetmasterdpuppetdssldirtesting" - @@tmpfiles << ssldir - assert_nothing_raised { - output = %x{puppetmasterd --port #{port} -a --ssldir #{ssldir} --manifest #{file}}.chomp - } - assert($? == 0, "Puppetmasterd return status was %s" % $?) - @@tmppids << $?.pid - assert_equal("", output) - end +class TestPuppetDExe < ExeTest + def test_normalstart + # start the master + file = startmasterd - def stopmaster - ps = Facter["ps"].value || "ps -ef" + # create the client + client = Puppet::Client.new(:Server => "localhost", :Port => @@port) - pid = nil - %x{#{ps}}.chomp.split(/\n/).each { |line| - if line =~ /puppetmasterd/ - ary = line.split(" ") - pid = ary[1].to_i - end - } - if pid - assert_nothing_raised { - Process.kill("-TERM", pid) - } - end - end + # make a new fqdn + fqdn = client.fqdn.sub(/^\w+\./, "testing.") - def test_normalstart - file = "/tmp/testingmanifest.pp" - mkfile = "/tmp/puppetdtesting" - File.open(file, "w") { |f| - f.puts %{ -file { "#{mkfile}": create => true, mode => 755 } -} - } + cmd = "puppetd" + cmd += " --verbose" + cmd += " --fqdn %s" % fqdn + cmd += " --port %s" % @@port + cmd += " --ssldir %s" % Puppet[:ssldir] + cmd += " --server localhost" - @@tmpfiles << file - @@tmpfiles << mkfile - port = 8235 - startmaster(file, port) - output = nil - ssldir = "/tmp/puppetdssldirtesting" - @@tmpfiles << ssldir - client = Puppet::Client.new(:Server => "localhost") - fqdn = client.fqdn.sub(/^\w+\./, "testing.") + # and verify our daemon runs assert_nothing_raised { - output = %x{puppetd --verbose --fqdn #{fqdn} --port #{port} --ssldir #{ssldir} --server localhost}.chomp + output = %x{#{cmd}}.chomp } sleep 1 assert($? == 0, "Puppetd exited with code %s" % $?) #puts output #assert_equal("", output, "Puppetd produced output %s" % output) - assert(FileTest.exists?(mkfile), + assert(FileTest.exists?(@createdfile), "Failed to create config'ed file") # now verify that --noop works - File.unlink(mkfile) + File.unlink(@createdfile) + cmd += " --noop" assert_nothing_raised { - output = %x{puppetd --noop --fqdn #{fqdn} --port #{port} --ssldir #{ssldir} --server localhost}.chomp + output = %x{#{cmd}}.chomp } sleep 1 assert($? == 0, "Puppetd exited with code %s" % $?) - assert(! FileTest.exists?(mkfile), + assert(! FileTest.exists?(@createdfile), "Noop created config'ed file") - stopmaster + stopmasterd end end diff --git a/test/executables/tc_puppetmasterd.rb b/test/executables/tc_puppetmasterd.rb index 6d4a58b7b..9367cce80 100755 --- a/test/executables/tc_puppetmasterd.rb +++ b/test/executables/tc_puppetmasterd.rb @@ -14,16 +14,7 @@ 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 +class TestPuppetMasterD < ExeTest def getcerts include Puppet::Daemon if self.readcerts @@ -33,102 +24,68 @@ class TestPuppetMasterD < Test::Unit::TestCase end end - def setup - if __FILE__ == $0 - Puppet[:loglevel] = :debug - end - @@tmpfiles = [] - @port = 8320 - end + # start the daemon and verify it responds and such + def test_normalstart + startmasterd - 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 --port #{@port} #{args}}.chomp + socket = TCPSocket.new("127.0.0.1", @@port) + socket.close } - assert($? == 0, "Puppetmasterd exit status was %s" % $?) - assert_equal("", output, "Puppetmasterd produced output %s" % output) - end - def stopmasterd(running = true) - ps = Facter["ps"].value || "ps -ef" - - pid = nil - %x{#{ps}}.chomp.split(/\n/).each { |line| - if line =~ /ruby.+puppetmasterd/ - next if line =~ /tc_/ # skip the test script itself - ary = line.split(" ") - pid = ary[1].to_i - end + client = nil + assert_nothing_raised() { + client = Puppet::Client::StatusClient.new( + :Server => "localhost", + :Port => @@port + ) } - # we default to mandating that it's running, but teardown - # doesn't require that - if running or pid - assert(pid) + # set our client up to auto-sign + assert(Puppet[:autosign] =~ /^#{File::SEPARATOR}/, + "Autosign is set to %s, not a file" % Puppet[:autosign]) - 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 + FileUtils.mkdir_p(File.dirname(Puppet[:autosign])) + File.open(Puppet[:autosign], "w") { |f| + f.puts client.fqdn } - 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", @port) - socket.close - } + retval = nil - client = nil + # init the client certs assert_nothing_raised() { - client = XMLRPC::Client.new("localhost", "/RPC2", @port, - nil, nil, nil, nil, true, 5) + client.initcerts } - retval = nil + # call status assert_nothing_raised() { - retval = client.call("status.status", "") + retval = client.status } assert_equal(1, retval, "Status.status return value was %s" % retval) - facts = {} - Facter.each { |p,v| - facts[p] = v + + # this client shoulduse the same certs + assert_nothing_raised() { + client = Puppet::Client::MasterClient.new( + :Server => "localhost", + :Port => @@port + ) } - textfacts = CGI.escape(Marshal::dump(facts)) assert_nothing_raised() { #Puppet.notice "calling status" #retval = client.call("status.status", "") - retval = client.call("puppetmaster.getconfig", textfacts) + retval = client.getconfig } objects = nil - assert_nothing_raised { - Marshal::load(CGI.unescape(retval)) - } + assert_instance_of(Puppet::TransBucket, retval, + "Retrieved non-transportable object") stopmasterd end + # verify that we can run puppetmasterd in parse-only mode def test_parseonly - file = File.join($puppetbase, "examples", "code", "head") - startmasterd("--parseonly --manifest #{file}") + startmasterd("--parseonly") + sleep(1) pid = nil ps = Facter["ps"].value || "ps -ef" |
