summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-05-03 05:57:52 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-05-03 05:57:52 +0000
commit44f15795d5cc1d5c4cd43b585441212d75d25c81 (patch)
tree12eda01827c172e59dbcd6a6958ebf501b0ba47a
parenta9df49d3ee02ed11b82107ea035b9089ca7a2a56 (diff)
Fixing a stupid bug i managed to introduce in 0.16.2 (probably) involving importing files with classes in them. This is a better solution than what I had before the bug, anyway. Also, some documentation fixes.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1167 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/parser/ast/astarray.rb17
-rw-r--r--lib/puppet/parser/grammar.ra33
-rw-r--r--lib/puppet/parser/parser.rb77
-rw-r--r--lib/puppet/type.rb2
-rwxr-xr-xlib/puppet/type/exec.rb4
-rw-r--r--test/language/parser.rb94
-rwxr-xr-xtest/language/scope.rb3
-rw-r--r--test/puppettest.rb23
8 files changed, 209 insertions, 44 deletions
diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb
index f8f88b816..ab24fa86c 100644
--- a/lib/puppet/parser/ast/astarray.rb
+++ b/lib/puppet/parser/ast/astarray.rb
@@ -35,7 +35,24 @@ class Puppet::Parser::AST
definers = []
settors = []
others = []
+
+ # Make a new array, so we don't have to deal with the details of
+ # flattening and such
+ items = []
+
+ # First clean out any AST::ASTArrays
@children.each { |child|
+ if child.instance_of?(AST::ASTArray)
+ child.each do |ac|
+ items << ac
+ end
+ else
+ items << child
+ end
+ }
+
+ # Now sort them all according to the type of action
+ items.each { |child|
if definelist.include?(child.class)
definers << child
elsif setlist.include?(child.class)
diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra
index 9d1d4bb52..c3b694534 100644
--- a/lib/puppet/parser/grammar.ra
+++ b/lib/puppet/parser/grammar.ra
@@ -458,31 +458,41 @@ import: IMPORT quotedtext {
" variables are not interpolated for imports " +
"in file #{@lexer.file} at line #{@lexer.line}"
)
- end
+ end
files = Dir.glob(pat)
if files.size == 0
- raise Puppet::ImportError.new("No file(s) found for import " +
- "of '#{pat}'")
+ files = Dir.glob(pat + ".pp")
+ if files.size == 0
+ raise Puppet::ImportError.new("No file(s) found for import " +
+ "of '#{pat}'")
+ end
end
files.each { |file|
parser = Puppet::Parser::Parser.new()
parser.files = self.files
Puppet.debug("importing '%s'" % file)
+
+ unless file =~ /^#{File::SEPARATOR}/
+ file = File.join(dir, file)
+ end
begin
- parser.file = File.join(dir, file)
+ parser.file = file
rescue Puppet::ImportError
Puppet.warning(
"Importing %s would result in an import loop" %
File.join(dir, file)
)
- result = AST::ASTArray.new(
- :file => @lexer.file,
- :line => @lexer.line
- )
+# result = AST::ASTArray.new(
+# :file => @lexer.file,
+# :line => @lexer.line
+# )
next
end
# push the results into the main result array
- result.push parser.parse
+ #result.push parser.parse
+ parser.parse.each do |child|
+ result.push child
+ end
}
}
}
@@ -747,7 +757,10 @@ end
def file=(file)
unless FileTest.exists?(file)
- raise Puppet::Error, "Could not find file %s" % file
+ file = file + ".pp"
+ unless FileTest.exists?(file)
+ raise Puppet::Error, "Could not find file %s" % file
+ end
end
if @files.detect { |f| f.file == file }
raise Puppet::ImportError.new("Import loop detected")
diff --git a/lib/puppet/parser/parser.rb b/lib/puppet/parser/parser.rb
index c548e926b..7a5fd7c55 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..idfae53df579', 'grammar.ra', 727
+module_eval <<'..end grammar.ra modeval..id81e5fd5119', 'grammar.ra', 737
require 'puppet/parser/functions'
attr_reader :file
@@ -53,7 +53,10 @@ end
def file=(file)
unless FileTest.exists?(file)
- raise Puppet::Error, "Could not find file %s" % file
+ file = file + ".pp"
+ unless FileTest.exists?(file)
+ raise Puppet::Error, "Could not find file %s" % file
+ end
end
if @files.detect { |f| f.file == file }
raise Puppet::ImportError.new("Import loop detected")
@@ -152,7 +155,7 @@ end
# $Id$
-..end grammar.ra modeval..idfae53df579
+..end grammar.ra modeval..id81e5fd5119
##### racc 1.4.4 generates ###
@@ -1181,7 +1184,7 @@ module_eval <<'.,.,', 'grammar.ra', 436
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 488
+module_eval <<'.,.,', 'grammar.ra', 498
def _reduce_76( val, _values, result )
# importing files
# yuk, i hate keywords
@@ -1205,38 +1208,48 @@ module_eval <<'.,.,', 'grammar.ra', 488
" variables are not interpolated for imports " +
"in file #{@lexer.file} at line #{@lexer.line}"
)
- end
+ end
files = Dir.glob(pat)
if files.size == 0
- raise Puppet::ImportError.new("No file(s) found for import " +
- "of '#{pat}'")
+ files = Dir.glob(pat + ".pp")
+ if files.size == 0
+ raise Puppet::ImportError.new("No file(s) found for import " +
+ "of '#{pat}'")
+ end
end
files.each { |file|
parser = Puppet::Parser::Parser.new()
parser.files = self.files
Puppet.debug("importing '%s'" % file)
+
+ unless file =~ /^#{File::SEPARATOR}/
+ file = File.join(dir, file)
+ end
begin
- parser.file = File.join(dir, file)
+ parser.file = file
rescue Puppet::ImportError
Puppet.warning(
"Importing %s would result in an import loop" %
File.join(dir, file)
)
- result = AST::ASTArray.new(
- :file => @lexer.file,
- :line => @lexer.line
- )
+# result = AST::ASTArray.new(
+# :file => @lexer.file,
+# :line => @lexer.line
+# )
next
end
# push the results into the main result array
- result.push parser.parse
+ #result.push parser.parse
+ parser.parse.each do |child|
+ result.push child
+ end
}
}
result
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 499
+module_eval <<'.,.,', 'grammar.ra', 509
def _reduce_77( val, _values, result )
result = AST::CompDef.new(
:type => AST::Name.new(:value => val[1], :line => @lexer.line),
@@ -1250,7 +1263,7 @@ module_eval <<'.,.,', 'grammar.ra', 499
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 512
+module_eval <<'.,.,', 'grammar.ra', 522
def _reduce_78( val, _values, result )
result = AST::CompDef.new(
:type => AST::Name.new(:value => val[1], :line => @lexer.line),
@@ -1268,7 +1281,7 @@ module_eval <<'.,.,', 'grammar.ra', 512
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 529
+module_eval <<'.,.,', 'grammar.ra', 539
def _reduce_79( val, _values, result )
#:args => val[2],
args = {
@@ -1287,7 +1300,7 @@ module_eval <<'.,.,', 'grammar.ra', 529
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 546
+module_eval <<'.,.,', 'grammar.ra', 556
def _reduce_80( val, _values, result )
args = {
:type => AST::Name.new(:value => val[1], :line => @lexer.line),
@@ -1309,7 +1322,7 @@ module_eval <<'.,.,', 'grammar.ra', 546
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 567
+module_eval <<'.,.,', 'grammar.ra', 577
def _reduce_81( val, _values, result )
unless val[1].instance_of?(AST::ASTArray)
val[1] = AST::ASTArray.new(
@@ -1333,7 +1346,7 @@ module_eval <<'.,.,', 'grammar.ra', 567
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 590
+module_eval <<'.,.,', 'grammar.ra', 600
def _reduce_82( val, _values, result )
unless val[1].instance_of?(AST::ASTArray)
val[1] = AST::ASTArray.new(
@@ -1363,7 +1376,7 @@ module_eval <<'.,.,', 'grammar.ra', 590
# reduce 83 omitted
-module_eval <<'.,.,', 'grammar.ra', 604
+module_eval <<'.,.,', 'grammar.ra', 614
def _reduce_84( val, _values, result )
if val[0].instance_of?(AST::ASTArray)
result = val[0]
@@ -1379,7 +1392,7 @@ module_eval <<'.,.,', 'grammar.ra', 604
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 612
+module_eval <<'.,.,', 'grammar.ra', 622
def _reduce_85( val, _values, result )
result = AST::HostName.new(
:line => @lexer.line,
@@ -1390,7 +1403,7 @@ module_eval <<'.,.,', 'grammar.ra', 612
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 618
+module_eval <<'.,.,', 'grammar.ra', 628
def _reduce_86( val, _values, result )
result = AST::HostName.new(
:line => @lexer.line,
@@ -1401,7 +1414,7 @@ module_eval <<'.,.,', 'grammar.ra', 618
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 626
+module_eval <<'.,.,', 'grammar.ra', 636
def _reduce_87( val, _values, result )
result = AST::ASTArray.new(
:line => @lexer.line,
@@ -1414,14 +1427,14 @@ module_eval <<'.,.,', 'grammar.ra', 626
# reduce 88 omitted
-module_eval <<'.,.,', 'grammar.ra', 631
+module_eval <<'.,.,', 'grammar.ra', 641
def _reduce_89( val, _values, result )
result = val[1]
result
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 642
+module_eval <<'.,.,', 'grammar.ra', 652
def _reduce_90( val, _values, result )
if val[1].instance_of?(AST::ASTArray)
result = val[1]
@@ -1438,7 +1451,7 @@ module_eval <<'.,.,', 'grammar.ra', 642
# reduce 91 omitted
-module_eval <<'.,.,', 'grammar.ra', 656
+module_eval <<'.,.,', 'grammar.ra', 666
def _reduce_92( val, _values, result )
if val[0].instance_of?(AST::ASTArray)
val[0].push(val[2])
@@ -1454,7 +1467,7 @@ module_eval <<'.,.,', 'grammar.ra', 656
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 664
+module_eval <<'.,.,', 'grammar.ra', 674
def _reduce_93( val, _values, result )
result = AST::CompArgument.new(
:line => @lexer.line,
@@ -1465,7 +1478,7 @@ module_eval <<'.,.,', 'grammar.ra', 664
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 671
+module_eval <<'.,.,', 'grammar.ra', 681
def _reduce_94( val, _values, result )
result = AST::CompArgument.new(
:line => @lexer.line,
@@ -1478,7 +1491,7 @@ module_eval <<'.,.,', 'grammar.ra', 671
# reduce 95 omitted
-module_eval <<'.,.,', 'grammar.ra', 680
+module_eval <<'.,.,', 'grammar.ra', 690
def _reduce_96( val, _values, result )
result = AST::Name.new(
:value => val[1],
@@ -1489,7 +1502,7 @@ module_eval <<'.,.,', 'grammar.ra', 680
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 689
+module_eval <<'.,.,', 'grammar.ra', 699
def _reduce_97( val, _values, result )
name = val[0].sub(/^\$/,'')
result = AST::Variable.new(
@@ -1501,7 +1514,7 @@ module_eval <<'.,.,', 'grammar.ra', 689
end
.,.,
-module_eval <<'.,.,', 'grammar.ra', 701
+module_eval <<'.,.,', 'grammar.ra', 711
def _reduce_98( val, _values, result )
if val[1].instance_of?(AST::ASTArray)
result = val[1]
@@ -1522,7 +1535,7 @@ module_eval <<'.,.,', 'grammar.ra', 701
# reduce 101 omitted
-module_eval <<'.,.,', 'grammar.ra', 706
+module_eval <<'.,.,', 'grammar.ra', 716
def _reduce_102( val, _values, result )
result = nil
result
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 1490c1528..d525a9f25 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -2177,7 +2177,7 @@ class Type < Puppet::Element
service { nagios:
running => true,
- require => file[nagconf]
+ subscribe => file[nagconf]
}
}
"
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 51133297f..2e455e7de 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -278,10 +278,12 @@ module Puppet
# Rebuild the database, but only when the file changes
exec { newaliases:
path => [\"/usr/bin\", \"/usr/sbin\"],
- require => file[\"/etc/aliases\"],
+ subscribe => file[\"/etc/aliases\"],
refreshonly => true
}
+ Note that only ``subscribe`` can trigger actions, not ``require``,
+ so it only makes sense to use ``refreshonly`` with ``subscribe``.
"
newvalues(:true, :false)
diff --git a/test/language/parser.rb b/test/language/parser.rb
index a9b2631f1..81d3c21cf 100644
--- a/test/language/parser.rb
+++ b/test/language/parser.rb
@@ -207,6 +207,100 @@ class TestParser < Test::Unit::TestCase
parser.parse
}
end
+
+ def test_importedclasses
+ imported = tempfile()
+ importer = tempfile()
+
+ made = tempfile()
+
+ File.open(imported, "w") do |f|
+ f.puts %{class foo { file { "#{made}": ensure => file }}}
+ end
+
+ File.open(importer, "w") do |f|
+ f.puts %{import "#{imported}"\ninclude foo}
+ end
+
+ parser = Puppet::Parser::Parser.new
+ parser.file = importer
+
+ # Make sure it parses fine
+ assert_nothing_raised {
+ parser.parse
+ }
+
+ # Now make sure it actually does the work
+ assert_creates(importer, made)
+ end
+
+ # Make sure fully qualified and unqualified files can be imported
+ def test_fqfilesandlocalfiles
+ dir = tempfile()
+ Dir.mkdir(dir)
+ importer = File.join(dir, "site.pp")
+ fullfile = File.join(dir, "full.pp")
+ localfile = File.join(dir, "local.pp")
+
+ files = []
+
+ File.open(importer, "w") do |f|
+ f.puts %{import "#{fullfile}"\ninclude full\nimport "local.pp"\ninclude local}
+ end
+
+ file = tempfile()
+ files << file
+
+ File.open(fullfile, "w") do |f|
+ f.puts %{class full { file { "#{file}": ensure => file }}}
+ end
+
+ file = tempfile()
+ files << file
+
+ File.open(localfile, "w") do |f|
+ f.puts %{class local { file { "#{file}": ensure => file }}}
+ end
+
+ parser = Puppet::Parser::Parser.new
+ parser.file = importer
+
+ # Make sure it parses
+ assert_nothing_raised {
+ parser.parse
+ }
+
+ # Now make sure it actually does the work
+ assert_creates(importer, *files)
+ end
+
+ # Make sure the parser adds '.pp' when necessary
+ def test_addingpp
+ dir = tempfile()
+ Dir.mkdir(dir)
+ importer = File.join(dir, "site.pp")
+ localfile = File.join(dir, "local.pp")
+
+ files = []
+
+ File.open(importer, "w") do |f|
+ f.puts %{import "local"\ninclude local}
+ end
+
+ file = tempfile()
+ files << file
+
+ File.open(localfile, "w") do |f|
+ f.puts %{class local { file { "#{file}": ensure => file }}}
+ end
+
+ parser = Puppet::Parser::Parser.new
+ parser.file = importer
+
+ assert_nothing_raised {
+ parser.parse
+ }
+ end
end
# $Id$
diff --git a/test/language/scope.rb b/test/language/scope.rb
index 62cded121..ff108f63b 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -659,4 +659,7 @@ class TestScope < Test::Unit::TestCase
end
+
+ def test_defineandinclude
+ end
end
diff --git a/test/puppettest.rb b/test/puppettest.rb
index 733f1ae71..34bcb8abd 100644
--- a/test/puppettest.rb
+++ b/test/puppettest.rb
@@ -938,6 +938,29 @@ module ParserTesting
return func
end
+
+ # This assumes no nodes
+ def assert_creates(manifest, *files)
+ interp = nil
+ assert_nothing_raised {
+ interp = Puppet::Parser::Interpreter.new(
+ :Manifest => manifest,
+ :UseNodes => false
+ )
+ }
+
+ config = nil
+ assert_nothing_raised {
+ config = interp.run(Facter["hostname"].value, {})
+ }
+
+ comp = nil
+ assert_nothing_raised {
+ comp = config.to_type
+ }
+
+ assert_apply(comp)
+ end
end
class PuppetTestSuite