summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet.rb7
-rw-r--r--lib/puppet/client.rb162
-rw-r--r--lib/puppet/type/pfile.rb8
-rw-r--r--test/client/tc_client.rb37
-rw-r--r--test/other/tc_transactions.rb3
-rw-r--r--test/puppettest.rb4
-rwxr-xr-xtest/test2
7 files changed, 145 insertions, 78 deletions
diff --git a/lib/puppet.rb b/lib/puppet.rb
index af633e6b7..99ab48860 100644
--- a/lib/puppet.rb
+++ b/lib/puppet.rb
@@ -24,7 +24,12 @@ module Puppet
end
def to_s
- return @message
+ if @file and @line
+ return "%s at file %s, line %s" %
+ [@message, @file, @line]
+ else
+ return @message
+ end
end
end
diff --git a/lib/puppet/client.rb b/lib/puppet/client.rb
index 325a6d71e..1e3b0f4a2 100644
--- a/lib/puppet/client.rb
+++ b/lib/puppet/client.rb
@@ -12,17 +12,46 @@ require 'facter'
require 'puppet/transaction'
require 'puppet/transportable'
require 'puppet/metric'
-require 'http-access2'
-require 'soap/rpc/driver'
-require 'soap/rpc/httpserver'
-#require 'webrick/https'
-require 'logger'
+
+begin
+ require 'webrick'
+ require 'cgi'
+ require 'xmlrpc/client'
+ require 'xmlrpc/server'
+rescue LoadError => detail
+ $nonetworking = detail
+end
module Puppet
+ class NetworkClientError < RuntimeError; end
class ClientError < RuntimeError; end
#---------------------------------------------------------------
- class Client < SOAP::RPC::HTTPServer
+ unless $nonetworking
+ class NetworkClient < XMLRPC::Client
+ @@methods = [ :getconfig ]
+
+ @@methods.each { |method|
+ self.send(:define_method,method) { |*args|
+ begin
+ call("puppetmaster.%s" % method.to_s,*args)
+ rescue => detail
+ raise NetworkClientError.new(detail)
+ end
+ }
+ }
+
+ def initialize(hash)
+ hash[:Path] ||= "/RPC2"
+ hash[:Server] ||= "localhost"
+ hash[:Port] ||= 8080
+ super(hash[:Server],hash[:Path],hash[:Port])
+ end
+ end
+ end
+
+ class Client
include Puppet
+ attr_accessor :local
def Client.facts
facts = {}
Facter.each { |name,fact|
@@ -36,47 +65,64 @@ module Puppet
# to whom do we connect?
@server = nil
@nil = nil
- @url = hash[:Server]
- if hash.include?(:Listen) and hash[:Listen] == false
- Puppet.debug "We're a local client"
- @localonly = true
- @driver = @url
+ if hash.include?(:Server)
+ case hash[:Server]
+ when String:
+ if $nonetworking
+ raise NetworkClientError.new("Networking not available: %s" %
+ $nonetworking)
+ end
+
+ args = {}
+ [:Port, :Server].each { |arg|
+ if hash.include?(:Port)
+ args[arg] = hash[arg]
+ end
+ }
+ @driver = Puppet::NetworkClient.new(args)
+ @local = false
+ when Puppet::Master:
+ @driver = hash[:Server]
+ @local = true
+ else
+ raise ClientError.new("Server must be a hostname or a " +
+ "Puppet::Master object")
+ end
else
- Puppet.debug "We're a networked client"
- @localonly = false
- @driver = SOAP::RPC::Driver.new(@url, 'urn:puppet-server')
- @driver.add_method("getconfig", "name", "facts")
- end
- unless @localonly
- hash.delete(:Server)
-
- Puppet.debug "Server is %s" % @url
-
- hash[:BindAddress] ||= "0.0.0.0"
- hash[:Port] ||= 17444
- #hash[:Debug] ||= true
- hash[:AccessLog] ||= []
-
- super(hash)
+ raise ClientError.new("Must pass :Server to client")
end
end
def getconfig
- Puppet.debug "server is %s" % @url
#client.loadproperty('files/sslclient.properties')
Puppet.debug("getting config")
- objects = nil
facts = Client.facts
- #Puppet.info "Facts are %s" % facts.inspect
- textfacts = Marshal::dump(facts)
- if @localonly
- objects = @driver.getconfig(self,facts)
+ unless facts.length > 0
+ raise Puppet::ClientError.new(
+ "Could not retrieve any facts"
+ )
+ end
+
+ objects = nil
+ if @local
+ objects = @driver.getconfig(facts)
+ else
+ textfacts = CGI.escape(Marshal::dump(facts))
+ textobjects = CGI.unescape(@driver.getconfig(textfacts))
+ begin
+ objects = Marshal::load(textobjects)
+ rescue => detail
+ raise Puppet::Error.new("Could not understand configuration")
+ end
+ end
+ if objects.is_a?(Puppet::TransBucket)
+ self.config(objects)
else
- objects = @driver.getconfig(facts["hostname"],textfacts)
+ Puppet.warning objects.inspect
+ raise NetworkClientError.new(objects.class)
end
- self.config(objects)
end
# this method is how the client receives the tree of Transportable
@@ -95,17 +141,19 @@ module Puppet
Puppet.err "Corrupt state file %s" % Puppet[:statefile]
begin
File.unlink(Puppet[:statefile])
+ retry
rescue => detail
raise Puppet::Error.new("Cannot remove %s: %s" %
[Puppet[statefile], detail])
end
end
- if @localonly
- container = tree.to_type
- else
- container = Marshal::load(tree).to_type
- end
+ container = tree.to_type
+ #if @local
+ # container = tree.to_type
+ #else
+ # container = Marshal::load(tree).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
@@ -125,28 +173,28 @@ module Puppet
Metric.graph
end
Puppet::Storage.store
- self.shutdown
+ #self.shutdown
end
- def callfunc(name,args)
- Puppet.debug("Calling callfunc on %s" % name)
- if function = Puppet::Function[name]
- #debug("calling function %s" % function)
- value = function.call(args)
- #debug("from %s got %s" % [name,value])
- return value
- else
- raise "Function '%s' not found" % name
- end
- end
+ #def callfunc(name,args)
+ # Puppet.debug("Calling callfunc on %s" % name)
+ # if function = Puppet::Function[name]
+ # #debug("calling function %s" % function)
+ # value = function.call(args)
+ # #debug("from %s got %s" % [name,value])
+ # return value
+ # else
+ # raise "Function '%s' not found" % name
+ # end
+ #end
private
- def on_init
- @default_namespace = 'urn:puppet-client'
- add_method(self, 'config', 'config')
- add_method(self, 'callfunc', 'name', 'arguments')
- end
+ #def on_init
+ # @default_namespace = 'urn:puppet-client'
+ # add_method(self, 'config', 'config')
+ # add_method(self, 'callfunc', 'name', 'arguments')
+ #end
def cert(filename)
OpenSSL::X509::Certificate.new(File.open(File.join(@dir, filename)) { |f|
diff --git a/lib/puppet/type/pfile.rb b/lib/puppet/type/pfile.rb
index f47806ebf..52ae06b67 100644
--- a/lib/puppet/type/pfile.rb
+++ b/lib/puppet/type/pfile.rb
@@ -339,9 +339,11 @@ module Puppet
def sync
unless Process.uid == 0
- raise Puppet::Error.new(
- "Got told to sync owner as non-root user"
- )
+ # there's a possibility that we never got retrieve() called
+ # e.g., if the file didn't exist
+ # thus, just delete ourselves now and don't do any work
+ @parent.delete(self.name)
+ return nil
end
if @is == -1
diff --git a/test/client/tc_client.rb b/test/client/tc_client.rb
index 17cee1c9b..33f40dcf0 100644
--- a/test/client/tc_client.rb
+++ b/test/client/tc_client.rb
@@ -1,11 +1,13 @@
if __FILE__ == $0
$:.unshift '..'
$:.unshift '../../lib'
+ $:.unshift '../../../../language/trunk/lib'
$puppetbase = "../../../../language/trunk/"
end
require 'puppet'
require 'puppet/client'
+#require 'puppet/server'
require 'puppet/fact'
require 'test/unit'
require 'puppettest.rb'
@@ -13,20 +15,27 @@ require 'puppettest.rb'
# $Id$
class TestClient < Test::Unit::TestCase
- def test_local
- client = nil
- assert_nothing_raised() {
- client = Puppet::Client.new(:Listen => false)
- }
-
- facts = %w{operatingsystem operatingsystemrelease}
- facts.each { |fact|
- assert_equal(
- Puppet::Fact[fact],
- client.callfunc("fact",fact)
- )
- }
- end
+# def test_local
+# client = nil
+# server = nil
+# assert_nothing_raised() {
+# server = Puppet::Master.new(
+# :File => file,
+# :Local => true
+# )
+# }
+# assert_nothing_raised() {
+# client = Puppet::Client.new(:Server => server)
+# }
+#
+# facts = %w{operatingsystem operatingsystemrelease}
+# facts.each { |fact|
+# assert_equal(
+# Puppet::Fact[fact],
+# client.callfunc("fact",fact)
+# )
+# }
+# end
def test_files
end
diff --git a/test/other/tc_transactions.rb b/test/other/tc_transactions.rb
index 06dc8d8e2..8b0ab1f93 100644
--- a/test/other/tc_transactions.rb
+++ b/test/other/tc_transactions.rb
@@ -11,6 +11,7 @@ require 'test/unit'
# $Id$
class TestTransactions < Test::Unit::TestCase
+ include FileTesting
def cycle(comp)
assert_nothing_raised {
trans = comp.evaluate
@@ -50,7 +51,7 @@ class TestTransactions < Test::Unit::TestCase
end
def newfile(hash = {})
- tmpfile = PuppetTestSuite.tempfile()
+ tmpfile = tempfile()
File.open(tmpfile, "w") { |f| f.puts rand(100) }
@@tmpfiles.push tmpfile
hash[:name] = tmpfile
diff --git a/test/puppettest.rb b/test/puppettest.rb
index 23ff7fe97..471a58521 100644
--- a/test/puppettest.rb
+++ b/test/puppettest.rb
@@ -149,9 +149,9 @@ unless defined? PuppetTestSuite
FileUtils.cd(fromdir) {
fromlist = %x{find . 2>/dev/null}.chomp.split(/\n/).reject { |file|
! FileTest.readable?(file)
- }
+ }.sort
}
- tolist = file_list(todir)
+ tolist = file_list(todir).sort
assert_equal(fromlist,tolist)
diff --git a/test/test b/test/test
index 54a527f76..b10d78121 100755
--- a/test/test
+++ b/test/test
@@ -7,10 +7,12 @@
$:.unshift '.'
$:.unshift '../lib'
+$:.unshift '../../../language/trunk/lib/'
# if we're not in the library trunk, then add that to the lib search path
if Dir.getwd !~ %r{puppet/library}
$:.unshift '../../../library/trunk/lib/'
+ $:.unshift '../../../language/trunk/lib/'
$:.unshift '../../../library/trunk/test/'
end