summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/dsl.rb11
-rw-r--r--lib/puppet/network/client/master.rb1
-rw-r--r--lib/puppet/network/handler/configuration.rb45
-rw-r--r--lib/puppet/network/handler/master.rb15
-rwxr-xr-xtest/network/client/client.rb8
-rwxr-xr-xtest/network/client/master.rb6
-rwxr-xr-xtest/network/handler/runner.rb11
-rwxr-xr-xtest/rails/configuration.rb14
8 files changed, 34 insertions, 77 deletions
diff --git a/lib/puppet/dsl.rb b/lib/puppet/dsl.rb
index 75bc81b2b..97d06a4ec 100644
--- a/lib/puppet/dsl.rb
+++ b/lib/puppet/dsl.rb
@@ -251,12 +251,17 @@ module Puppet
def scope
unless defined?(@scope)
- @interp = Puppet::Parser::Interpreter.new :Code => ""
+ # Set the code to something innocuous; we just need the
+ # scopes, not the interpreter. Hackish, but true.
+ Puppet[:code] = " "
+ @interp = Puppet::Parser::Interpreter.new
require 'puppet/node'
@node = Puppet::Node.new(Facter.value(:hostname))
+ if env = Puppet[:environment] and env == ""
+ env = nil
+ end
@node.parameters = Facter.to_hash
- @interp = Puppet::Parser::Interpreter.new :Code => ""
- @compile = Puppet::Parser::Compile.new(@node, @interp.send(:parser, Puppet[:environment]))
+ @compile = Puppet::Parser::Compile.new(@node, @interp.send(:parser, env))
@scope = @compile.topscope
end
@scope
diff --git a/lib/puppet/network/client/master.rb b/lib/puppet/network/client/master.rb
index 989d6dca2..5408cabe4 100644
--- a/lib/puppet/network/client/master.rb
+++ b/lib/puppet/network/client/master.rb
@@ -266,6 +266,7 @@ class Puppet::Network::Client::Master < Puppet::Network::Client
self.getconfig
end
rescue => detail
+ puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not retrieve configuration: %s" % detail
end
diff --git a/lib/puppet/network/handler/configuration.rb b/lib/puppet/network/handler/configuration.rb
index 353693bdc..09c4b971a 100644
--- a/lib/puppet/network/handler/configuration.rb
+++ b/lib/puppet/network/handler/configuration.rb
@@ -49,10 +49,14 @@ class Puppet::Network::Handler
@local = false
end
- # Just store the options, rather than creating the interpreter
- # immediately. Mostly, this is so we can create the interpreter
- # on-demand, which is easier for testing.
- @options = options
+ options.each do |param, value|
+ case param
+ when :Classes: @classes = value
+ when :Local: self.local = true
+ else
+ raise ArgumentError, "Configuration handler does not accept %s" % param
+ end
+ end
set_server_facts
end
@@ -82,8 +86,8 @@ class Puppet::Network::Handler
node.merge(@server_facts)
# Add any specified classes to the node's class list.
- if classes = @options[:Classes]
- classes.each do |klass|
+ if @classes
+ @classes.each do |klass|
node.classes << klass
end
end
@@ -121,37 +125,14 @@ class Puppet::Network::Handler
end
# Create our interpreter object.
- def create_interpreter(options)
- args = {}
-
- # Allow specification of a code snippet or of a file
- if code = options[:Code]
- args[:Code] = code
- elsif options[:Manifest]
- args[:Manifest] = options[:Manifest]
- end
-
- args[:Local] = local?
-
- if options.include?(:UseNodes)
- args[:UseNodes] = options[:UseNodes]
- elsif @local
- args[:UseNodes] = false
- end
-
- # This is only used by the cfengine module, or if --loadclasses was
- # specified in +puppet+.
- if options.include?(:Classes)
- args[:Classes] = options[:Classes]
- end
-
- return Puppet::Parser::Interpreter.new(args)
+ def create_interpreter
+ return Puppet::Parser::Interpreter.new
end
# Create/return our interpreter.
def interpreter
unless defined?(@interpreter) and @interpreter
- @interpreter = create_interpreter(@options)
+ @interpreter = create_interpreter
end
@interpreter
end
diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb
index 25c4318b8..1c7f7310e 100644
--- a/lib/puppet/network/handler/master.rb
+++ b/lib/puppet/network/handler/master.rb
@@ -30,13 +30,6 @@ class Puppet::Network::Handler
def initialize(hash = {})
args = {}
- # Allow specification of a code snippet or of a file
- if code = hash[:Code]
- args[:Code] = code
- elsif man = hash[:Manifest]
- args[:Manifest] = man
- end
-
if hash[:Local]
@local = hash[:Local]
else
@@ -53,12 +46,6 @@ class Puppet::Network::Handler
Puppet.debug("Creating interpreter")
- if hash.include?(:UseNodes)
- args[:UseNodes] = hash[:UseNodes]
- elsif @local
- args[:UseNodes] = false
- end
-
# This is only used by the cfengine module, or if --loadclasses was
# specified in +puppet+.
if hash.include?(:Classes)
@@ -74,7 +61,7 @@ class Puppet::Network::Handler
client, clientip = clientname(client, clientip, facts)
# Pass the facts to the fact handler
- Puppet::Node::Facts.new(client, facts).save
+ Puppet::Node::Facts.new(client, facts).save unless local?
# And get the configuration from the config handler
config = config_handler.configuration(client)
diff --git a/test/network/client/client.rb b/test/network/client/client.rb
index 484c794e4..e08da357c 100755
--- a/test/network/client/client.rb
+++ b/test/network/client/client.rb
@@ -141,17 +141,11 @@ class TestClient < Test::Unit::TestCase
end
def test_classfile
- manifest = tempfile()
-
- File.open(manifest, "w") do |file|
- file.puts "class yaytest {}\n class bootest {}\n include yaytest, bootest"
- end
+ Puppet[:code] = "class yaytest {}\n class bootest {}\n include yaytest, bootest"
master = client = nil
assert_nothing_raised() {
master = Puppet::Network::Handler.master.new(
- :Manifest => manifest,
- :UseNodes => false,
:Local => false
)
}
diff --git a/test/network/client/master.rb b/test/network/client/master.rb
index 0a3b75b91..aaa38b223 100755
--- a/test/network/client/master.rb
+++ b/test/network/client/master.rb
@@ -48,8 +48,10 @@ class TestMasterClient < Test::Unit::TestCase
def mkmaster(options = {})
options[:UseNodes] = false
options[:Local] = true
- unless options[:Code]
- options[:Manifest] ||= mktestmanifest
+ if code = options[:Code]
+ Puppet[:code] = code
+ else
+ Puppet[:manifest] = options[:Manifest] || mktestmanifest
end
# create our master
# this is the default server setup
diff --git a/test/network/handler/runner.rb b/test/network/handler/runner.rb
index 23883a17c..50a00862a 100755
--- a/test/network/handler/runner.rb
+++ b/test/network/handler/runner.rb
@@ -7,15 +7,14 @@ require 'puppettest'
class TestHandlerRunner < Test::Unit::TestCase
include PuppetTest
- def mkclient(file)
+ def mkclient(code)
master = nil
client = nil
+ Puppet[:code] = code
# create our master
assert_nothing_raised() {
# this is the default server setup
master = Puppet::Network::Handler.master.new(
- :Manifest => file,
- :UseNodes => false,
:Local => true
)
}
@@ -38,8 +37,7 @@ class TestHandlerRunner < Test::Unit::TestCase
created = tempfile()
# We specify the schedule here, because I was having problems with
# using default schedules.
- File.open(file, "w") do |f|
- f.puts %{
+ code = %{
class yayness {
schedule { "yayness": period => weekly }
file { "#{created}": ensure => file, schedule => yayness }
@@ -47,9 +45,8 @@ class TestHandlerRunner < Test::Unit::TestCase
include yayness
}
- end
- client = mkclient(file)
+ client = mkclient(code)
runner = nil
assert_nothing_raised {
diff --git a/test/rails/configuration.rb b/test/rails/configuration.rb
index 07665d576..277753945 100755
--- a/test/rails/configuration.rb
+++ b/test/rails/configuration.rb
@@ -51,19 +51,9 @@ class ConfigurationRailsTests < PuppetTest::TestCase
Puppet[:storeconfigs] = true
}
- file = tempfile()
- File.open(file, "w") { |f|
- f.puts "file { \"/etc\": owner => root }"
- }
+ Puppet[:code] = "file { \"/etc\": owner => root }"
- interp = nil
- assert_nothing_raised {
- interp = Puppet::Parser::Interpreter.new(
- :Manifest => file,
- :UseNodes => false,
- :ForkSave => false
- )
- }
+ interp = Puppet::Parser::Interpreter.new
facts = {}
Facter.each { |fact, val| facts[fact] = val }