summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2005-08-29 20:36:49 +0000
committerLuke Kanies <luke@madstop.com>2005-08-29 20:36:49 +0000
commitcc483678d3b89979286475745b325ae8f348afef (patch)
tree28abbb1f7ebfe529be350498dc2d33070ba0b4bb
parent65d13753127cac85a57274e89b0d5d616e63bcb4 (diff)
downloadpuppet-cc483678d3b89979286475745b325ae8f348afef.tar.gz
puppet-cc483678d3b89979286475745b325ae8f348afef.tar.xz
puppet-cc483678d3b89979286475745b325ae8f348afef.zip
I did not have good puppetd tests, so I missed the fact that I was calling the wrong class in puppetd. Fixed.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@597 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-xbin/puppetd8
-rw-r--r--lib/puppet/client.rb145
-rw-r--r--test/client/tc_client.rb22
-rwxr-xr-xtest/executables/tc_puppetd.rb46
4 files changed, 128 insertions, 93 deletions
diff --git a/bin/puppetd b/bin/puppetd
index d65240c7c..7b757093e 100755
--- a/bin/puppetd
+++ b/bin/puppetd
@@ -156,7 +156,7 @@ args[:Server] = server
if fqdn
args[:FQDN] = fqdn
end
-client = Puppet::Client.new(args)
+client = Puppet::Client::MasterClient.new(args)
unless client.readcert
begin
@@ -171,11 +171,13 @@ unless client.readcert
end
if bg
- Puppet[:logdest] = Puppet[:logfile]
+ unless Puppet[:logdest] == :file
+ Puppet[:logdest] = Puppet[:logfile]
+ end
client.daemonize
end
#client.start
client.getconfig
-client.config
+client.apply
# $Id$
diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb
index 868c86f58..cd95a8510 100644
--- a/lib/puppet/client.rb
+++ b/lib/puppet/client.rb
@@ -88,7 +88,6 @@ module Puppet
)
if hash[:Certificate]
- Puppet.info "adding cert to @http"
@http.cert = hash[:Certificate]
end
@@ -126,6 +125,7 @@ module Puppet
# FIXME the cert stuff should only come up with networking, so it
# should be in the network client, not the normal client
+ # but if i do that, it's hard to tell whether the certs have been initialized
include Puppet::Daemon
attr_reader :local, :secureinit
@@ -133,6 +133,23 @@ module Puppet
attr_reader :drivername
end
+ def initcerts
+ unless self.readcert
+ unless self.requestcert
+ return nil
+ end
+ end
+
+ unless @driver
+ return true
+ end
+
+ Puppet.info "setting cert and key and such"
+ @driver.cert = @cert
+ @driver.key = @key
+ @driver.ca_file = @cacertfile
+ end
+
def initialize(hash)
# to whom do we connect?
@server = nil
@@ -194,6 +211,60 @@ module Puppet
facts
end
+ # this method is how the client receives the tree of Transportable
+ # objects
+ # for now, just descend into the tree and perform and necessary
+ # manipulations
+ def apply
+ unless defined? @objects
+ raise Puppet::Error, "Cannot apply; objects not defined"
+ end
+
+ # XXX this is kind of a problem; if the user changes the state file
+ # after this, then we have to reload the file and everything...
+ begin
+ Puppet::Storage.init
+ Puppet::Storage.load
+ rescue => detail
+ Puppet.err "Corrupt state file %s" % Puppet[:checksumfile]
+ begin
+ File.unlink(Puppet[:checksumfile])
+ retry
+ rescue => detail
+ raise Puppet::Error.new("Cannot remove %s: %s" %
+ [Puppet[statefile], detail])
+ end
+ end
+
+ container = @objects.to_type
+ #if @local
+ # container = @objects.to_type
+ #else
+ # container = Marshal::load(@objects).to_type
+ #end
+
+ # this is a gross hack... but i don't see a good way around it
+ # set all of the variables to empty
+ Puppet::Transaction.init
+
+ # for now we just evaluate the top-level container, but eventually
+ # there will be schedules and such associated with each object,
+ # and probably with the container itself
+ transaction = container.evaluate
+ #transaction = Puppet::Transaction.new(objects)
+ transaction.toplevel = true
+ transaction.evaluate
+ Puppet::Metric.gather
+ Puppet::Metric.tally
+ if Puppet[:rrdgraph] == true
+ Metric.store
+ Metric.graph
+ end
+ Puppet::Storage.store
+
+ return transaction
+ end
+
def getconfig
#client.loadproperty('files/sslclient.properties')
Puppet.debug("getting config")
@@ -264,78 +335,6 @@ module Puppet
raise NetworkClientError.new(objects.class)
end
end
-
- # this method is how the client receives the tree of Transportable
- # objects
- # for now, just descend into the tree and perform and necessary
- # manipulations
- def config
- unless defined? @objects
- raise Puppet::Error, "Cannot config; objects not defined"
- end
- Puppet.debug("Calling config")
-
- # XXX this is kind of a problem; if the user changes the state file
- # after this, then we have to reload the file and everything...
- begin
- Puppet::Storage.init
- Puppet::Storage.load
- rescue => detail
- Puppet.err "Corrupt state file %s" % Puppet[:checksumfile]
- begin
- File.unlink(Puppet[:checksumfile])
- retry
- rescue => detail
- raise Puppet::Error.new("Cannot remove %s: %s" %
- [Puppet[statefile], detail])
- end
- end
-
- container = @objects.to_type
- #if @local
- # container = @objects.to_type
- #else
- # container = Marshal::load(@objects).to_type
- #end
-
- # this is a gross hack... but i don't see a good way around it
- # set all of the variables to empty
- Puppet::Transaction.init
-
- # for now we just evaluate the top-level container, but eventually
- # there will be schedules and such associated with each object,
- # and probably with the container itself
- transaction = container.evaluate
- #transaction = Puppet::Transaction.new(objects)
- transaction.toplevel = true
- transaction.evaluate
- Puppet::Metric.gather
- Puppet::Metric.tally
- if Puppet[:rrdgraph] == true
- Metric.store
- Metric.graph
- end
- Puppet::Storage.store
-
- return transaction
- end
-
- def initcerts
- unless self.readcert
- unless self.requestcert
- return nil
- end
- end
-
- unless @driver
- return true
- end
-
- Puppet.info "setting cert and key and such"
- @driver.cert = @cert
- @driver.key = @key
- @driver.ca_file = @cacertfile
- end
end
class Dipper < Puppet::Client
diff --git a/test/client/tc_client.rb b/test/client/tc_client.rb
index 5823e6e32..2c67c35c8 100644
--- a/test/client/tc_client.rb
+++ b/test/client/tc_client.rb
@@ -36,9 +36,16 @@ class TestClient < Test::Unit::TestCase
Puppet[:autosign] = true
Puppet[:ssldir] = "/tmp/puppetclientcertests"
@@tmpfiles.push Puppet[:ssldir]
- port = 8085
+ @@tmpfiles.push "/tmp/puppetclienttesting"
+ file = "/tmp/testingmanifest.pp"
+ File.open(file, "w") { |f|
+ f.puts '
+file { "/tmp/puppetclienttesting": create => true, mode => 755 }
+'
+ }
- file = File.join($puppetbase, "examples", "code", "head")
+ @@tmpfiles << file
+ port = 8085
server = nil
assert_nothing_raised {
@@ -77,6 +84,17 @@ class TestClient < Test::Unit::TestCase
assert(File.exists?(keyfile))
assert(File.exists?(certfile))
assert(File.exists?(publickeyfile))
+
+ assert_nothing_raised("Client could not retrieve configuration") {
+ client.getconfig
+ }
+
+ assert_nothing_raised("Client could not apply configuration") {
+ client.apply
+ }
+
+ assert(FileTest.exists?("/tmp/puppetclienttesting"),
+ "Applied file does not exist")
end
# disabled because the server needs to have its certs in place
diff --git a/test/executables/tc_puppetd.rb b/test/executables/tc_puppetd.rb
index 38e382392..0a0556c41 100755
--- a/test/executables/tc_puppetd.rb
+++ b/test/executables/tc_puppetd.rb
@@ -37,15 +37,17 @@ class TestPuppetDExe < Test::Unit::TestCase
}
@@tmppids.each { |pid|
- %x{kill -INT #{pid} 2>/dev/null}
+ %x{kill #{pid} 2>/dev/null}
}
+ stopmaster
end
- def startmaster
- file = File.join($puppetbase, "examples", "code", "head")
+ def startmaster(file, port)
output = nil
+ ssldir = "/tmp/puppetmasterdpuppetdssldirtesting"
+ @@tmpfiles << ssldir
assert_nothing_raised {
- output = %x{puppetmasterd --port #{Puppet[:masterport]} --manifest #{file}}.chomp
+ output = %x{puppetmasterd --port #{port} -a --ssldir #{ssldir} --manifest #{file}}.chomp
}
assert($? == 0, "Puppetmasterd return status was %s" % $?)
@@tmppids << $?.pid
@@ -62,26 +64,40 @@ class TestPuppetDExe < Test::Unit::TestCase
pid = ary[1].to_i
end
}
- assert(pid, "No puppetmasterd pid")
-
- assert_nothing_raised {
- Process.kill("-INT", pid)
- }
+ if pid
+ assert_nothing_raised {
+ Process.kill("-TERM", pid)
+ }
+ end
end
def test_normalstart
- startmaster
+ file = "/tmp/testingmanifest.pp"
+ File.open(file, "w") { |f|
+ f.puts '
+file { "/tmp/puppetdtesting": create => true, mode => 755 }
+'
+ }
+
+ @@tmpfiles << file
+ @@tmpfiles << "/tmp/puppetdtesting"
+ port = 8235
+ startmaster(file, port)
output = nil
+ ssldir = "/tmp/puppetdssldirtesting"
+ @@tmpfiles << ssldir
+ client = Puppet::Client.new(:Server => "localhost")
+ fqdn = client.fqdn.sub(/^\w+\./, "testing.")
assert_nothing_raised {
- output = %x{puppetd --server localhost}.chomp
+ output = %x{puppetd --fqdn #{fqdn} --port #{port} --ssldir #{ssldir} --server localhost}.chomp
}
+ sleep 1
assert($? == 0, "Puppetd exited with code %s" % $?)
+ #puts output
assert_equal("", output, "Puppetd produced output %s" % output)
- assert_nothing_raised {
- socket = TCPSocket.new("127.0.0.1", Puppet[:masterport])
- socket.close
- }
+ assert(FileTest.exists?("/tmp/puppetdtesting"),
+ "Failed to create config'ed file")
stopmaster
end
end