diff options
author | Luke Kanies <luke@madstop.com> | 2007-10-05 00:07:38 -0500 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2007-10-05 00:07:38 -0500 |
commit | 0e336bf62b818aaa31fcc323ab5d31e5eb92eb46 (patch) | |
tree | 2f29d3e668aad2cade6059c74cbba60d60873561 /lib/puppet/indirector/code | |
parent | 1fa591287a4ab921cec628aa0c5bf58d61fbdef2 (diff) | |
download | puppet-0e336bf62b818aaa31fcc323ab5d31e5eb92eb46.tar.gz puppet-0e336bf62b818aaa31fcc323ab5d31e5eb92eb46.tar.xz puppet-0e336bf62b818aaa31fcc323ab5d31e5eb92eb46.zip |
This commit is focused on getting the 'puppet' executable
to work. As a result, it involves a lot of integration-level
testing, and a lot of small design changes to make the code
actually work.
In particular, indirections can now have default termini,
so that configurations and facts default to their code terminus
Also, I've removed the ability to manually control whether
ast nodes are used. I might need to add it back in later,
but if so it will be in the form of a global setting,
rather than the previous system of passing it through 10 different
classes. Instead, the parser detects whether there are AST nodes
defined and requires them if so or ignores them if not.
About 75 tests are still failing in the main set of tests,
but it's going to be a long slog to get them working --
there are significant design issues around them, as most of
the failures are a result of tests trying to emulate both the
client and server sides of a connection, which normally would
have different fact termini but in this case must have the same
terminus just because they're in the same process and are global.
The next step, then, is to figure that process out, thus finding a way
to make this all work.
Diffstat (limited to 'lib/puppet/indirector/code')
-rw-r--r-- | lib/puppet/indirector/code/configuration.rb | 60 |
1 files changed, 36 insertions, 24 deletions
diff --git a/lib/puppet/indirector/code/configuration.rb b/lib/puppet/indirector/code/configuration.rb index 6d0317204..b3a4c67dd 100644 --- a/lib/puppet/indirector/code/configuration.rb +++ b/lib/puppet/indirector/code/configuration.rb @@ -15,21 +15,12 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code # Compile a node's configuration. def find(key, client = nil, clientip = nil) - # If we want to use the cert name as our key - if Puppet[:node_name] == 'cert' and client - key = client - end - - # Note that this is reasonable, because either their node source should actually - # know about the node, or they should be using the ``none`` node source, which - # will always return data. - unless node = Puppet::Node.search(key) - raise Puppet::Error, "Could not find node '%s'" % key + if key.is_a?(Puppet::Node) + node = key + else + node = find_node(key) end - # Add any external data to the node. - add_node_data(node) - configuration = compile(node) return configuration @@ -47,6 +38,11 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code @interpreter end + # Is our compiler part of a network, or are we just local? + def networked? + $0 =~ /puppetmasterd/ + end + # Return the configuration version. def version(client = nil, clientip = nil) if client and node = Puppet::Node.search(client) @@ -76,22 +72,17 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code end config = nil + loglevel = networked? ? :notice : :none + # LAK:FIXME This should log at :none when our client is # local, since we don't want 'puppet' (vs. puppetmasterd) to # log compile times. - benchmark(:notice, "Compiled configuration for %s" % node.name) do + benchmark(loglevel, "Compiled configuration for %s" % node.name) do begin config = interpreter.compile(node) rescue Puppet::Error => detail - if Puppet[:trace] - puts detail.backtrace - end - unless local? - Puppet.err detail.to_s - end - raise XMLRPC::FaultException.new( - 1, detail.to_s - ) + Puppet.err(detail.to_s) if networked? + raise end end @@ -117,6 +108,27 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code return Puppet::Parser::Interpreter.new(args) end + # Turn our host name into a node object. + def find_node(key) + # If we want to use the cert name as our key + # LAK:FIXME This needs to be figured out somehow, but it requires the routing. + #if Puppet[:node_name] == 'cert' and client + # key = client + #end + + # Note that this is reasonable, because either their node source should actually + # know about the node, or they should be using the ``none`` node source, which + # will always return data. + unless node = Puppet::Node.search(key) + raise Puppet::Error, "Could not find node '%s'" % key + end + + # Add any external data to the node. + add_node_data(node) + + node + end + # Initialize our server fact hash; we add these to each client, and they # won't change while we're running, so it's safe to cache the values. def set_server_facts @@ -150,7 +162,7 @@ class Puppet::Indirector::Code::Configuration < Puppet::Indirector::Code # LAK:FIXME This method should probably be part of the protocol, but it # shouldn't be here. def translate(config) - if local? + unless networked? config else CGI.escape(config.to_yaml(:UseBlock => true)) |