summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-08-25 17:14:13 -0500
committerLuke Kanies <luke@madstop.com>2007-08-25 17:14:13 -0500
commit9df4fd1f2188c90190e33e165206e7931938607b (patch)
tree071a42fa559ffd800a4d0e586a8bd05f0e31f3a1
parentba3a861af2e5c30fd9bbbe0e1666fa316139113b (diff)
And we have multiple environment support in the parser. The only remaining piece to make this complete is to add multiple environment support to the fileserver. I also renamed Configuration.rb to Compile.rb (that is, I fixed all the classes that used to know it as a configuration).
-rw-r--r--lib/puppet/module.rb20
-rw-r--r--lib/puppet/parser/compile.rb3
-rw-r--r--lib/puppet/parser/interpreter.rb4
-rw-r--r--lib/puppet/parser/parser.rb4
-rw-r--r--lib/puppet/parser/parser_support.rb18
-rwxr-xr-xspec/unit/other/modules.rb8
-rwxr-xr-xtest/language/ast.rb4
-rwxr-xr-xtest/language/ast/hostclass.rb8
-rwxr-xr-xtest/language/ast/resourceref.rb2
-rwxr-xr-xtest/language/collector.rb18
-rwxr-xr-xtest/language/functions.rb26
-rwxr-xr-xtest/language/parser.rb6
-rwxr-xr-xtest/language/resource.rb8
13 files changed, 68 insertions, 61 deletions
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 34b13edb7..924958bbe 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -43,17 +43,25 @@ class Puppet::Module
# param.
# In all cases, an absolute path is returned, which does not
# necessarily refer to an existing file
- def self.find_template(file, environment = nil)
- if file =~ /^#{File::SEPARATOR}/
- return file
+ def self.find_template(template, environment = nil)
+ if template =~ /^#{File::SEPARATOR}/
+ return template
end
- path, file = split_path(file)
- mod = find(path, environment)
+ path, file = split_path(template)
+
+ # Because templates don't have an assumed template name, like manifests do,
+ # we treat templates with no name as being templates in the main template
+ # directory.
+ if file.nil?
+ mod = nil
+ else
+ mod = find(path, environment)
+ end
if mod
return mod.template(file)
else
- return File.join(Puppet.config.value(:templatedir, environment), path, file)
+ return File.join(Puppet.config.value(:templatedir, environment), template)
end
end
diff --git a/lib/puppet/parser/compile.rb b/lib/puppet/parser/compile.rb
index 6cfe66fce..710f90273 100644
--- a/lib/puppet/parser/compile.rb
+++ b/lib/puppet/parser/compile.rb
@@ -102,6 +102,8 @@ class Puppet::Parser::Compile
unless defined? @environment
if node.environment and node.environment != ""
@environment = node.environment
+ else
+ @environment = nil
end
end
@environment
@@ -232,7 +234,6 @@ class Puppet::Parser::Compile
# Now see if we can find the node.
astnode = nil
- #nodes = @parser.nodes
@node.names.each do |name|
break if astnode = @parser.nodes[name.to_s.downcase]
end
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index c0f9d32a7..b6c61d202 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -25,7 +25,7 @@ class Puppet::Parser::Interpreter
# evaluate our whole tree
def compile(node)
- return Puppet::Parser::Configuration.new(node, parser(node.environment), :ast_nodes => usenodes?).compile
+ return Puppet::Parser::Compile.new(node, parser(node.environment), :ast_nodes => usenodes?).compile
end
# create our interpreter
@@ -62,7 +62,7 @@ class Puppet::Parser::Interpreter
# Create a new parser object and pre-parse the configuration.
def create_parser(environment)
begin
- parser = Puppet::Parser::Parser.new(environment)
+ parser = Puppet::Parser::Parser.new(:environment => environment)
if self.code
parser.string = self.code
elsif self.file
diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb
index 21a054223..aaffa816e 100644
--- a/lib/puppet/parser/parser.rb
+++ b/lib/puppet/parser/parser.rb
@@ -29,7 +29,7 @@ module Puppet
class Parser < Racc::Parser
-module_eval <<'..end grammar.ra modeval..idc5e5087e93', 'grammar.ra', 640
+module_eval <<'..end grammar.ra modeval..idc3bb85ed76', 'grammar.ra', 640
# It got too annoying having code in a file that needs to be compiled.
require 'puppet/parser/parser_support'
@@ -41,7 +41,7 @@ require 'puppet/parser/parser_support'
# $Id$
-..end grammar.ra modeval..idc5e5087e93
+..end grammar.ra modeval..idc3bb85ed76
##### racc 1.4.5 generates ###
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index dfc91ba12..401b5b1c0 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -176,14 +176,14 @@ class Puppet::Parser::Parser
"in file #{@lexer.file} at line #{@lexer.line}"
)
end
- files = Puppet::Module::find_manifests(pat, dir)
+ files = Puppet::Module::find_manifests(pat, :cwd => dir)
if files.size == 0
raise Puppet::ImportError.new("No file(s) found for import " +
"of '#{pat}'")
end
files.collect { |file|
- parser = Puppet::Parser::Parser.new(@astset)
+ parser = Puppet::Parser::Parser.new(:astset => @astset, :environment => @environment)
parser.files = self.files
Puppet.debug("importing '%s'" % file)
@@ -202,8 +202,9 @@ class Puppet::Parser::Parser
}
end
- def initialize(environment)
- @environment = environment
+ def initialize(options = {})
+ @astset = options[:astset] || ASTSet.new({}, {}, {})
+ @environment = options[:environment]
initvars()
end
@@ -212,15 +213,6 @@ class Puppet::Parser::Parser
@lexer = Puppet::Parser::Lexer.new()
@files = []
@loaded = []
-
- # This is where we store our classes and definitions and nodes.
- # Clear each hash, just to help the GC a bit.
- if defined?(@astset)
- [:classes, :definitions, :nodes].each do |name|
- @astset.send(name).clear
- end
- end
- @astset = ASTSet.new({}, {}, {})
end
# Try to load a class, since we could not find it.
diff --git a/spec/unit/other/modules.rb b/spec/unit/other/modules.rb
index 1afd3d863..0ab37aa9e 100755
--- a/spec/unit/other/modules.rb
+++ b/spec/unit/other/modules.rb
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../spec_helper'
+require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Module, " when building its search path" do
include PuppetTest
@@ -87,6 +87,12 @@ describe Puppet::Module, " when searching for templates" do
Puppet::Module.find_template("mymod/mytemplate").should == "/my/templates/mymod/mytemplate"
end
+ it "should return unqualified templates directly in the template dir" do
+ Puppet.config.expects(:value).with(:templatedir, nil).returns("/my/templates")
+ Puppet::Module.expects(:find).never
+ Puppet::Module.find_template("mytemplate").should == "/my/templates/mytemplate"
+ end
+
it "should use the environment templatedir if no module is found and an environment is specified" do
Puppet.config.expects(:value).with(:templatedir, "myenv").returns("/myenv/templates")
Puppet::Module.expects(:find).with("mymod", "myenv").returns(nil)
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 38e658edb..847d24660 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -95,7 +95,7 @@ class TestAST < Test::Unit::TestCase
def test_node
scope = mkscope
- parser = scope.configuration.parser
+ parser = scope.compile.parser
# Define a base node
basenode = parser.newnode "basenode", :code => AST::ASTArray.new(:children => [
@@ -161,7 +161,7 @@ class TestAST < Test::Unit::TestCase
assert_instance_of(Puppet::Parser::Collector, ret)
# Now make sure we get it back from the scope
- colls = scope.configuration.instance_variable_get("@collections")
+ colls = scope.compile.instance_variable_get("@collections")
assert_equal([ret], colls, "Did not store collector in config's collection list")
end
diff --git a/test/language/ast/hostclass.rb b/test/language/ast/hostclass.rb
index f093504ec..a91d4bb97 100755
--- a/test/language/ast/hostclass.rb
+++ b/test/language/ast/hostclass.rb
@@ -18,7 +18,7 @@ class TestASTHostClass < Test::Unit::TestCase
def test_hostclass
scope = mkscope
- parser = scope.configuration.parser
+ parser = scope.compile.parser
# Create the class we're testing, first with no parent
klass = parser.newclass "first",
@@ -94,7 +94,7 @@ class TestASTHostClass < Test::Unit::TestCase
# way they start looking for definitions in their own namespace.
def test_hostclass_namespace
scope = mkscope
- parser = scope.configuration.parser
+ parser = scope.compile.parser
# Create a new class
klass = nil
@@ -130,7 +130,7 @@ class TestASTHostClass < Test::Unit::TestCase
# found within the subclass (#517).
def test_parent_scope_from_parentclass
scope = mkscope
- parser = scope.configuration.parser
+ parser = scope.compile.parser
parser.newclass("base")
fun = parser.newdefine("base::fun")
@@ -140,7 +140,7 @@ class TestASTHostClass < Test::Unit::TestCase
ret = nil
assert_nothing_raised do
- ret = scope.configuration.evaluate_classes(["sub"])
+ ret = scope.compile.evaluate_classes(["sub"])
end
subscope = scope.class_scope(scope.findclass("sub"))
diff --git a/test/language/ast/resourceref.rb b/test/language/ast/resourceref.rb
index a3d6775a2..1145e5125 100755
--- a/test/language/ast/resourceref.rb
+++ b/test/language/ast/resourceref.rb
@@ -20,7 +20,7 @@ class TestASTResourceRef < Test::Unit::TestCase
def setup
super
@scope = mkscope
- @parser = @scope.configuration.parser
+ @parser = @scope.compile.parser
end
def test_evaluate
diff --git a/test/language/collector.rb b/test/language/collector.rb
index a4119929f..18d88a2c4 100755
--- a/test/language/collector.rb
+++ b/test/language/collector.rb
@@ -17,7 +17,7 @@ class TestCollector < Test::Unit::TestCase
super
Puppet[:trace] = false
@scope = mkscope
- @config = @scope.configuration
+ @compile = @scope.compile
end
# Test just collecting a specific resource. This is used by the 'realize'
@@ -33,7 +33,7 @@ class TestCollector < Test::Unit::TestCase
assert_nothing_raised do
coll.resources = ["File[/tmp/virtual1]", "File[/tmp/virtual3]"]
end
- @config.add_collection(coll)
+ @compile.add_collection(coll)
# Evaluate the collector and make sure it doesn't fail with no resources
# found yet
@@ -63,7 +63,7 @@ class TestCollector < Test::Unit::TestCase
"Resource got realized")
# Make sure that the collection is still there
- assert(@config.collections.include?(coll), "collection was deleted too soon")
+ assert(@compile.collections.include?(coll), "collection was deleted too soon")
# Now add our third resource
three = mkresource(:type => "file", :title => "/tmp/virtual3",
@@ -77,7 +77,7 @@ class TestCollector < Test::Unit::TestCase
assert(! three.virtual?, "three is still virtual")
# And make sure that the collection got deleted from the scope's list
- assert(@config.collections.empty?, "collection was not deleted")
+ assert(@compile.collections.empty?, "collection was not deleted")
end
def test_virtual
@@ -103,10 +103,10 @@ class TestCollector < Test::Unit::TestCase
end
# Set it in our scope
- @config.add_collection(coll)
+ @compile.add_collection(coll)
# Make sure it's in the collections
- assert(@config.collections.include?(coll), "collection was not added")
+ assert(@compile.collections.include?(coll), "collection was not added")
# And try to collect the virtual resources.
ret = nil
@@ -149,7 +149,7 @@ class TestCollector < Test::Unit::TestCase
coll = Puppet::Parser::Collector.new(@scope, "file", nil, nil, :virtual)
end
- @config.add_collection(coll)
+ @compile.add_collection(coll)
# run the collection and make sure it doesn't get deleted, since it
# didn't return anything
@@ -158,7 +158,7 @@ class TestCollector < Test::Unit::TestCase
"Evaluate returned incorrect value")
end
- assert_equal([coll], @config.collections, "Collection was deleted")
+ assert_equal([coll], @compile.collections, "Collection was deleted")
# Make a resource
one = mkresource(:type => "file", :title => "/tmp/virtual1",
@@ -171,7 +171,7 @@ class TestCollector < Test::Unit::TestCase
"Evaluate returned incorrect value")
end
- assert_equal([coll], @config.collections, "Collection was deleted")
+ assert_equal([coll], @compile.collections, "Collection was deleted")
assert_equal(false, one.virtual?, "One was not realized")
end
diff --git a/test/language/functions.rb b/test/language/functions.rb
index 9314df179..dbb66e95e 100755
--- a/test/language/functions.rb
+++ b/test/language/functions.rb
@@ -212,7 +212,7 @@ class TestLangFunctions < Test::Unit::TestCase
Puppet[:environment] = "yay"
- version = interp.configuration_version(node)
+ version = interp.compile(node)
objects = nil
assert_nothing_raised {
@@ -236,7 +236,7 @@ class TestLangFunctions < Test::Unit::TestCase
assert_nothing_raised {
objects = interp.compile(node)
}
- newversion = interp.configuration_version(node)
+ newversion = interp.compile(node)
assert(version != newversion, "Parse date did not change")
end
@@ -310,7 +310,7 @@ class TestLangFunctions < Test::Unit::TestCase
def test_realize
scope = mkscope
- parser = scope.configuration.parser
+ parser = scope.compile.parser
# Make a definition
parser.newdefine("mytype")
@@ -332,13 +332,13 @@ class TestLangFunctions < Test::Unit::TestCase
end
# Make sure it created a collection
- assert_equal(1, scope.configuration.collections.length,
+ assert_equal(1, scope.compile.collections.length,
"Did not set collection")
assert_nothing_raised do
- scope.configuration.collections.each do |coll| coll.evaluate end
+ scope.compile.collections.each do |coll| coll.evaluate end
end
- scope.configuration.collections.clear
+ scope.compile.collections.clear
# Now make sure the virtual resource is no longer virtual
assert(! virtual.virtual?, "Did not make virtual resource real")
@@ -356,17 +356,17 @@ class TestLangFunctions < Test::Unit::TestCase
end
# Make sure it created a collection
- assert_equal(1, scope.configuration.collections.length,
+ assert_equal(1, scope.compile.collections.length,
"Did not set collection")
# And the collection has our resource in it
- assert_equal([none.to_s], scope.configuration.collections[0].resources,
+ assert_equal([none.to_s], scope.compile.collections[0].resources,
"Did not set resources in collection")
end
def test_defined
scope = mkscope
- parser = scope.configuration.parser
+ parser = scope.compile.parser
parser.newclass("yayness")
parser.newdefine("rahness")
@@ -422,7 +422,7 @@ class TestLangFunctions < Test::Unit::TestCase
def test_include
scope = mkscope
- parser = scope.configuration.parser
+ parser = scope.compile.parser
assert_raise(Puppet::ParseError, "did not throw error on missing class") do
scope.function_include("nosuchclass")
@@ -434,7 +434,7 @@ class TestLangFunctions < Test::Unit::TestCase
scope.function_include "myclass"
end
- assert(scope.configuration.classlist.include?("myclass"),
+ assert(scope.compile.classlist.include?("myclass"),
"class was not evaluated")
# Now try multiple classes at once
@@ -445,7 +445,7 @@ class TestLangFunctions < Test::Unit::TestCase
end
classes.each do |c|
- assert(scope.configuration.classlist.include?(c),
+ assert(scope.compile.classlist.include?(c),
"class %s was not evaluated" % c)
end
@@ -502,7 +502,7 @@ class TestLangFunctions < Test::Unit::TestCase
assert_equal("yay-foo\n", %x{#{command} foo}, "command did not work")
scope = mkscope
- parser = scope.configuration.parser
+ parser = scope.compile.parser
val = nil
assert_nothing_raised("Could not call generator with no args") do
diff --git a/test/language/parser.rb b/test/language/parser.rb
index c172aafca..7c43746e7 100755
--- a/test/language/parser.rb
+++ b/test/language/parser.rb
@@ -371,7 +371,7 @@ file { "/tmp/yayness":
ret = parser.parse(str1).classes[""].code[0]
}
assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
- parser.clear
+ parser = mkparser
str2 = %{if true { #{exec.call("true")} } else { #{exec.call("false")} }}
assert_nothing_raised {
ret = parser.parse(str2).classes[""].code[0]
@@ -672,7 +672,7 @@ file { "/tmp/yayness":
targets << target
txt = %[ file { '#{target}': content => "#{fname}" } ]
if fname == "init.pp"
- txt = %[import 'mani1' \nimport '#{modname}/mani2'\nimport '#{modname}/sub/*.pp' ] + txt
+ txt = %[import 'mani1' \nimport '#{modname}/mani2'\nimport '#{modname}/sub/*.pp'\n ] + txt
end
File::open(File::join(manipath, fname), "w") do |f|
f.puts txt
@@ -872,7 +872,7 @@ file { "/tmp/yayness":
def test_newclass
scope = mkscope
- parser = scope.configuration.parser
+ parser = scope.compile.parser
mkcode = proc do |ary|
classes = ary.collect do |string|
diff --git a/test/language/resource.rb b/test/language/resource.rb
index 50d58cf32..37b0b7e1e 100755
--- a/test/language/resource.rb
+++ b/test/language/resource.rb
@@ -251,7 +251,7 @@ class TestResource < PuppetTest::TestCase
res.expects(:finish)
res.scope = mock("scope")
config = mock("config")
- res.scope.expects(:configuration).returns(config)
+ res.scope.expects(:compile).returns(config)
config.expects(:delete_resource).with(res)
args = {:scope => res.scope, :arguments => res.to_hash}
@@ -269,7 +269,7 @@ class TestResource < PuppetTest::TestCase
res = mkresource
res.scope = mock('scope')
config = mock("config")
- res.scope.expects(:configuration).returns(config)
+ res.scope.expects(:compile).returns(config)
config.expects(:resource_overrides).with(res).returns(nil)
res.expects(:merge).never
res.send(:add_overrides)
@@ -278,7 +278,7 @@ class TestResource < PuppetTest::TestCase
res = mkresource
res.scope = mock('scope')
config = mock("config")
- res.scope.expects(:configuration).returns(config)
+ res.scope.expects(:compile).returns(config)
config.expects(:resource_overrides).with(res).returns([])
res.expects(:merge).never
res.send(:add_overrides)
@@ -287,7 +287,7 @@ class TestResource < PuppetTest::TestCase
res = mkresource
res.scope = mock('scope')
config = mock("config")
- res.scope.expects(:configuration).returns(config)
+ res.scope.expects(:compile).returns(config)
returns = %w{a b}
config.expects(:resource_overrides).with(res).returns(returns)
res.expects(:merge).with("a")