From f7328804d00d8a82d7ab3a955ff579ff956ef3d0 Mon Sep 17 00:00:00 2001 From: luke Date: Sat, 22 Oct 2005 22:27:20 +0000 Subject: Getting rid of the tc_ prefix to test cases git-svn-id: https://reductivelabs.com/svn/puppet/trunk@724 980ebf18-57e1-0310-9a29-db15c13687c0 --- test/executables/puppetbin.rb | 46 +++++++++++ test/executables/puppetca.rb | 79 +++++++++++++++++++ test/executables/puppetd.rb | 70 +++++++++++++++++ test/executables/puppetmasterd.rb | 148 +++++++++++++++++++++++++++++++++++ test/executables/tc_puppetbin.rb | 46 ----------- test/executables/tc_puppetca.rb | 79 ------------------- test/executables/tc_puppetd.rb | 70 ----------------- test/executables/tc_puppetmasterd.rb | 148 ----------------------------------- 8 files changed, 343 insertions(+), 343 deletions(-) create mode 100755 test/executables/puppetbin.rb create mode 100755 test/executables/puppetca.rb create mode 100755 test/executables/puppetd.rb create mode 100755 test/executables/puppetmasterd.rb delete mode 100755 test/executables/tc_puppetbin.rb delete mode 100755 test/executables/tc_puppetca.rb delete mode 100755 test/executables/tc_puppetd.rb delete mode 100755 test/executables/tc_puppetmasterd.rb (limited to 'test/executables') diff --git a/test/executables/puppetbin.rb b/test/executables/puppetbin.rb new file mode 100755 index 000000000..4a3eb7946 --- /dev/null +++ b/test/executables/puppetbin.rb @@ -0,0 +1,46 @@ +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '..' + $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 + include ServerTest + def test_version + output = nil + assert_nothing_raised { + output = %x{puppet --version}.chomp + } + assert(output == Puppet.version) + end + + def test_execution + file = mktestmanifest() + @@tmpfiles << "/tmp/puppetbintesting" + + output = nil + assert_nothing_raised { + system("puppet --logdest /dev/null %s" % file) + } + assert($? == 0, "Puppet exited with code %s" % $?.to_i) + + assert(FileTest.exists?(@createdfile), "Failed to create config'ed file") + end +end diff --git a/test/executables/puppetca.rb b/test/executables/puppetca.rb new file mode 100755 index 000000000..2fed58557 --- /dev/null +++ b/test/executables/puppetca.rb @@ -0,0 +1,79 @@ +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '..' + $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 + include ServerTest + 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::Server::CA.new() + } + #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] + #system("find %s" % Puppet[:ssldir]) + + cert = mkcert("host.test.com") + resp = nil + assert_nothing_raised { + # We need to use a fake name so it doesn't think the cert is from + # itself. + resp = ca.getcert(cert.csr.to_pem, "fakename", "127.0.0.1") + } + 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").reject { |line| line =~ /warning:/ } # stupid ssl.rb + } + #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/puppetd.rb b/test/executables/puppetd.rb new file mode 100755 index 000000000..72cf1f031 --- /dev/null +++ b/test/executables/puppetd.rb @@ -0,0 +1,70 @@ +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '..' + $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 + include ExeTest + def test_normalstart + # start the master + file = startmasterd + + # create the client + client = Puppet::Client.new(:Server => "localhost", :Port => @@port) + + # make a new fqdn + fqdn = client.fqdn.sub(/^\w+\./, "testing.") + + cmd = "puppetd" + cmd += " --verbose" + #cmd += " --fqdn %s" % fqdn + cmd += " --port %s" % @@port + cmd += " --ssldir %s" % Puppet[:ssldir] + cmd += " --server localhost" + + # and verify our daemon runs + assert_nothing_raised { + output = %x{#{cmd}}.chomp + puts output + } + sleep 1 + assert($? == 0, "Puppetd exited with code %s" % $?) + + assert(FileTest.exists?(@createdfile), + "Failed to create config'ed file") + + # now verify that --noop works + File.unlink(@createdfile) + + cmd += " --noop" + assert_nothing_raised { + output = %x{#{cmd}}.chomp + } + sleep 1 + assert($? == 0, "Puppetd exited with code %s" % $?) + + assert(! FileTest.exists?(@createdfile), + "Noop created config'ed file") + + stopmasterd + end +end diff --git a/test/executables/puppetmasterd.rb b/test/executables/puppetmasterd.rb new file mode 100755 index 000000000..7051f02a7 --- /dev/null +++ b/test/executables/puppetmasterd.rb @@ -0,0 +1,148 @@ +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '..' + $puppetbase = "../.." +end + +require 'puppet' +require 'puppet/server' +require 'puppet/daemon' +require 'test/unit' +require 'puppettest.rb' +require 'socket' +require 'facter' + +# $Id$ + +class TestPuppetMasterD < Test::Unit::TestCase + include 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 + + 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() { + #Puppet.notice "calling status" + #retval = client.call("status.status", "") + retval = client.getconfig + } + + objects = nil + 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 + startmasterd("--parseonly") + sleep(1) + + pid = nil + ps = Facter["ps"].value || "ps -ef" + %x{#{ps}}.chomp.split(/\n/).each { |line| + 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($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, "return value was %s" % 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 diff --git a/test/executables/tc_puppetbin.rb b/test/executables/tc_puppetbin.rb deleted file mode 100755 index 4a3eb7946..000000000 --- a/test/executables/tc_puppetbin.rb +++ /dev/null @@ -1,46 +0,0 @@ -if __FILE__ == $0 - $:.unshift '../../lib' - $:.unshift '..' - $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 - include ServerTest - def test_version - output = nil - assert_nothing_raised { - output = %x{puppet --version}.chomp - } - assert(output == Puppet.version) - end - - def test_execution - file = mktestmanifest() - @@tmpfiles << "/tmp/puppetbintesting" - - output = nil - assert_nothing_raised { - system("puppet --logdest /dev/null %s" % file) - } - assert($? == 0, "Puppet exited with code %s" % $?.to_i) - - 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 deleted file mode 100755 index 2fed58557..000000000 --- a/test/executables/tc_puppetca.rb +++ /dev/null @@ -1,79 +0,0 @@ -if __FILE__ == $0 - $:.unshift '../../lib' - $:.unshift '..' - $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 - include ServerTest - 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::Server::CA.new() - } - #Puppet.warning "SSLDir is %s" % Puppet[:ssldir] - #system("find %s" % Puppet[:ssldir]) - - cert = mkcert("host.test.com") - resp = nil - assert_nothing_raised { - # We need to use a fake name so it doesn't think the cert is from - # itself. - resp = ca.getcert(cert.csr.to_pem, "fakename", "127.0.0.1") - } - 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").reject { |line| line =~ /warning:/ } # stupid ssl.rb - } - #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 deleted file mode 100755 index 72cf1f031..000000000 --- a/test/executables/tc_puppetd.rb +++ /dev/null @@ -1,70 +0,0 @@ -if __FILE__ == $0 - $:.unshift '../../lib' - $:.unshift '..' - $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 - include ExeTest - def test_normalstart - # start the master - file = startmasterd - - # create the client - client = Puppet::Client.new(:Server => "localhost", :Port => @@port) - - # make a new fqdn - fqdn = client.fqdn.sub(/^\w+\./, "testing.") - - cmd = "puppetd" - cmd += " --verbose" - #cmd += " --fqdn %s" % fqdn - cmd += " --port %s" % @@port - cmd += " --ssldir %s" % Puppet[:ssldir] - cmd += " --server localhost" - - # and verify our daemon runs - assert_nothing_raised { - output = %x{#{cmd}}.chomp - puts output - } - sleep 1 - assert($? == 0, "Puppetd exited with code %s" % $?) - - assert(FileTest.exists?(@createdfile), - "Failed to create config'ed file") - - # now verify that --noop works - File.unlink(@createdfile) - - cmd += " --noop" - assert_nothing_raised { - output = %x{#{cmd}}.chomp - } - sleep 1 - assert($? == 0, "Puppetd exited with code %s" % $?) - - assert(! FileTest.exists?(@createdfile), - "Noop created config'ed file") - - stopmasterd - end -end diff --git a/test/executables/tc_puppetmasterd.rb b/test/executables/tc_puppetmasterd.rb deleted file mode 100755 index 7051f02a7..000000000 --- a/test/executables/tc_puppetmasterd.rb +++ /dev/null @@ -1,148 +0,0 @@ -if __FILE__ == $0 - $:.unshift '../../lib' - $:.unshift '..' - $puppetbase = "../.." -end - -require 'puppet' -require 'puppet/server' -require 'puppet/daemon' -require 'test/unit' -require 'puppettest.rb' -require 'socket' -require 'facter' - -# $Id$ - -class TestPuppetMasterD < Test::Unit::TestCase - include 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 - - 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() { - #Puppet.notice "calling status" - #retval = client.call("status.status", "") - retval = client.getconfig - } - - objects = nil - 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 - startmasterd("--parseonly") - sleep(1) - - pid = nil - ps = Facter["ps"].value || "ps -ef" - %x{#{ps}}.chomp.split(/\n/).each { |line| - 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($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, "return value was %s" % 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 -- cgit