[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Jesse Wolfe
jes5199 at gmail.com
Tue May 10 07:58:53 UTC 2011
The following commit has been merged in the experimental branch:
commit 16f701edd89a320ad73b5468d883dfb017fe6e96
Merge: 3c090de39897d85a5d5be20254efcddea14ad8ad 4da88fb4cd57871f16649d50572240ac3f7420f0
Author: Jesse Wolfe <jes5199 at gmail.com>
Date: Tue Aug 17 12:02:05 2010 -0700
Merge remote branch 'paul/4472-4483-4496-4521-4522'
a.k.a. "make_taller_trees"
diff --combined spec/unit/parser/ast/resource_spec.rb
index 5c94ac0,4e5549b..6dbfc1f
--- a/spec/unit/parser/ast/resource_spec.rb
+++ b/spec/unit/parser/ast/resource_spec.rb
@@@ -89,9 -89,9 +89,9 @@@ describe Puppet::Parser::AST::Resource
before do
@scope = Puppet::Parser::Scope.new :compiler => Puppet::Parser::Compiler.new(Puppet::Node.new("mynode"))
@parser = Puppet::Parser::Parser.new(Puppet::Node::Environment.new)
- @parser.newdefine "one"
- @parser.newdefine "one::two"
- @parser.newdefine "three"
+ ["one", "one::two", "three"].each do |name|
+ @parser.environment.known_resource_types.add(Puppet::Resource::Type.new(:definition, name, {}))
+ end
@twoscope = @scope.newscope(:namespace => "one")
@twoscope.resource = @scope.resource
end
@@@ -113,13 -113,6 +113,13 @@@
resource("file").evaluate(@twoscope)[0].type.should == "File"
end
+ it "should correctly generate resources that can look up defined classes by title" do
+ @scope.known_resource_types.add_hostclass Puppet::Resource::Type.new(:hostclass, "Myresource", {})
+ res = resource("class").evaluate(@twoscope)[0]
+ res.type.should == "Class"
+ res.title.should == "Myresource"
+ end
+
it "should fail for resource types that do not exist" do
lambda { resource("nosuchtype").evaluate(@twoscope) }.should raise_error(Puppet::ParseError)
end
diff --combined spec/unit/parser/type_loader_spec.rb
index 83006b3,b062516..58c386d
--- a/spec/unit/parser/type_loader_spec.rb
+++ b/spec/unit/parser/type_loader_spec.rb
@@@ -28,92 -28,26 +28,26 @@@ describe Puppet::Parser::TypeLoader d
describe "when loading names from namespaces" do
it "should do nothing if the name to import is an empty string" do
@loader.expects(:name2files).never
- @loader.load_until(["foo"], "") { |f| false }.should be_nil
- end
-
- it "should turn the provided namespaces and name into a list of files" do
- @loader.expects(:name2files).with(["foo"], "bar").returns []
- @loader.load_until(["foo"], "bar") { |f| false }
+ @loader.try_load_fqname(:hostclass, "") { |filename, modname| raise :should_not_occur }.should be_nil
end
it "should attempt to import each generated name" do
- @loader.expects(:name2files).returns %w{foo bar}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.load_until(["foo"], "bar") { |f| false }
- end
-
- it "should yield after each import" do
- yielded = []
- @loader.expects(:name2files).returns %w{foo bar}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.load_until(["foo"], "bar") { |f| yielded << f; false }
- yielded.should == %w{foo bar}
- end
-
- it "should stop importing when the yielded block returns true" do
- yielded = []
- @loader.expects(:name2files).returns %w{foo bar baz}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.expects(:import).with("baz",nil).never
- @loader.load_until(["foo"], "bar") { |f| true if f == "bar" }
- end
-
- it "should return the result of the block" do
- yielded = []
- @loader.expects(:name2files).returns %w{foo bar baz}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.expects(:import).with("baz",nil).never
- @loader.load_until(["foo"], "bar") { |f| 10 if f == "bar" }.should == 10
- end
-
- it "should return nil if the block never returns true" do
- @loader.expects(:name2files).returns %w{foo bar}
- @loader.expects(:import).with("foo",nil)
- @loader.expects(:import).with("bar",nil)
- @loader.load_until(["foo"], "bar") { |f| false }.should be_nil
+ @loader.expects(:import).with("foo/bar",nil).returns([])
+ @loader.expects(:import).with("foo",nil).returns([])
+ @loader.try_load_fqname(:hostclass, "foo::bar") { |f| false }
end
it "should know when a given name has been loaded" do
- @loader.expects(:name2files).returns %w{file}
- @loader.expects(:import).with("file",nil)
- @loader.load_until(["foo"], "bar") { |f| true }
+ @loader.expects(:import).with("file",nil).returns([])
+ @loader.try_load_fqname(:hostclass, "file") { |f| true }
@loader.should be_loaded("file")
end
-
- it "should set the module name on any created resource types" do
- type = Puppet::Resource::Type.new(:hostclass, "mytype")
-
- Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}]
- @loader.stubs(:parse_file)
- @loader.load_until(["foo"], "one") { |f| type }
-
- type.module_name.should == "modname"
- end
- end
-
- describe "when mapping names to files" do
- {
- [["foo"], "::bar::baz"] => %w{bar/baz},
- [[""], "foo::bar"] => %w{foo foo/bar},
- [%w{foo}, "bar"] => %w{foo foo/bar bar},
- [%w{a b}, "bar"] => %w{a a/bar b b/bar bar},
- [%w{a::b::c}, "bar"] => %w{a a/b/c/bar bar},
- [%w{a::b}, "foo::bar"] => %w{a a/b/foo/bar foo/bar}
- }.each do |inputs, outputs|
- it "should produce #{outputs.inspect} from the #{inputs[0].inspect} namespace and #{inputs[1]} name" do
- @loader.name2files(*inputs).should == outputs
- end
- end
end
describe "when importing" do
before do
Puppet::Parser::Files.stubs(:find_manifests).returns ["modname", %w{file}]
- @loader.stubs(:parse_file)
+ @loader.stubs(:parse_file).returns(Puppet::Parser::AST::Hostclass.new(''))
end
it "should return immediately when imports are being ignored" do
@@@ -144,13 -78,13 +78,13 @@@
it "should parse each found file" do
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
- @loader.expects(:parse_file).with("/one")
+ @loader.expects(:parse_file).with("/one").returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.import("myfile")
end
it "should make each file qualified before attempting to parse it" do
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{one}]
- @loader.expects(:parse_file).with("/current/one")
+ @loader.expects(:parse_file).with("/current/one").returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.import("myfile", "/current/file")
end
@@@ -163,7 -97,7 +97,7 @@@
it "should not attempt to import files that have already been imported" do
Puppet::Parser::Files.expects(:find_manifests).returns ["modname", %w{/one}]
- @loader.expects(:parse_file).once
+ @loader.expects(:parse_file).once.returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.import("myfile")
# This will fail if it tries to reimport the file.
@@@ -174,7 -108,7 +108,7 @@@
describe "when parsing a file" do
before do
@parser = Puppet::Parser::Parser.new(@loader.environment)
- @parser.stubs(:parse)
+ @parser.stubs(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
@parser.stubs(:file=)
Puppet::Parser::Parser.stubs(:new).with(@loader.environment).returns @parser
end
@@@ -186,16 -120,27 +120,27 @@@
it "should assign the parser its file and parse" do
@parser.expects(:file=).with("/my/file")
- @parser.expects(:parse)
+ @parser.expects(:parse).returns(Puppet::Parser::AST::Hostclass.new(''))
@loader.parse_file("/my/file")
end
end
it "should be able to add classes to the current resource type collection" do
- file = tmpfile("simple_file")
+ file = tmpfile("simple_file.pp")
File.open(file, "w") { |f| f.puts "class foo {}" }
@loader.import(file)
@loader.known_resource_types.hostclass("foo").should be_instance_of(Puppet::Resource::Type)
end
+
+ describe "when deciding where to look for files" do
+ { 'foo' => ['foo'],
+ 'foo::bar' => ['foo/bar', 'foo'],
+ 'foo::bar::baz' => ['foo/bar/baz', 'foo/bar', 'foo']
+ }.each do |fqname, expected_paths|
+ it "should look for #{fqname.inspect} in #{expected_paths.inspect}" do
+ @loader.instance_eval { name2files(fqname) }.should == expected_paths
+ end
+ end
+ end
end
diff --combined test/language/parser.rb
index 8cda8ee,330dacb..6599757
--- a/test/language/parser.rb
+++ b/test/language/parser.rb
@@@ -39,9 -39,8 +39,8 @@@ class TestParser < Test::Unit::TestCas
failers { |file|
parser = mkparser
Puppet.debug("parsing failer #{file}") if __FILE__ == $0
- assert_raise(Puppet::ParseError, "Did not fail while parsing #{file}") {
- parser.file = file
- ast = parser.parse
+ assert_raise(Puppet::ParseError, Puppet::Error, "Did not fail while parsing #{file}") {
+ Puppet[:manifest] = file
config = mkcompiler(parser)
config.compile
#ast.hostclass("").evaluate config.topscope
@@@ -97,7 -96,7 +96,7 @@@
}
4.times { |i|
- path = File.join(basedir, subdir, "subfile#{i}")
+ path = File.join(basedir, subdir, "subfile#{i}.pp")
mkmanifest(path)
}
@@@ -137,8 -136,8 +136,8 @@@
end
def test_importedclasses
- imported = tempfile
- importer = tempfile
+ imported = tempfile '.pp'
+ importer = tempfile '.pp'
made = tempfile
@@@ -288,7 -287,7 +287,7 @@@
ret = parser.parse
}
- ret.hostclass("").code.each do |obj|
+ ret.code.each do |obj|
assert_instance_of(AST::Collection, obj)
end
end
@@@ -362,12 -361,12 +361,12 @@@ file { "/tmp/yayness"
assert_raise(Puppet::ParseError) {
- parser.parse %{define mydef($schedule) {}}
+ parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule) {}}), '')
}
assert_nothing_raised {
- parser.parse %{define adef($schedule = false) {}}
- parser.parse %{define mydef($schedule = daily) {}}
+ parser.known_resource_types.import_ast(parser.parse(%{define adef($schedule = false) {}}), '')
+ parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule = daily) {}}), '')
}
end
@@@ -379,12 -378,12 +378,12 @@@
str1 = %{if true { #{exec.call("true")} }}
ret = nil
assert_nothing_raised {
- ret = parser.parse(str1).hostclass("").code[0]
+ ret = parser.parse(str1).code[0]
}
assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
parser = mkparser
str2 = %{if true { #{exec.call("true")} } else { #{exec.call("false")} }}
- ret = parser.parse(str2).hostclass("").code[0]
+ ret = parser.parse(str2).code[0]
assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
assert_instance_of(Puppet::Parser::AST::Else, ret.else)
end
@@@ -393,23 -392,23 +392,23 @@@
parser = mkparser
assert_nothing_raised {
- parser.parse %{class myclass { class other {} }}
+ parser.known_resource_types.import_ast(parser.parse(%{class myclass { class other {} }}), '')
}
assert(parser.hostclass("myclass"), "Could not find myclass")
assert(parser.hostclass("myclass::other"), "Could not find myclass::other")
assert_nothing_raised {
- parser.parse "class base {}
+ parser.known_resource_types.import_ast(parser.parse("class base {}
class container {
class deep::sub inherits base {}
- }"
+ }"), '')
}
sub = parser.hostclass("container::deep::sub")
assert(sub, "Could not find sub")
# Now try it with a parent class being a fq class
assert_nothing_raised {
- parser.parse "class container::one inherits container::deep::sub {}"
+ parser.known_resource_types.import_ast(parser.parse("class container::one inherits container::deep::sub {}"), '')
}
sub = parser.hostclass("container::one")
assert(sub, "Could not find one")
@@@ -417,7 -416,7 +416,7 @@@
# Finally, try including a qualified class
assert_nothing_raised("Could not include fully qualified class") {
- parser.parse "include container::deep::sub"
+ parser.known_resource_types.import_ast(parser.parse("include container::deep::sub"), '')
}
end
@@@ -426,20 -425,11 +425,11 @@@
# Make sure we put the top-level code into a class called "" in
# the "" namespace
- assert_nothing_raised do
- out = parser.parse ""
-
- assert_instance_of(Puppet::Resource::TypeCollection, out)
- assert_nil(parser.hostclass(""), "Got a 'main' class when we had no code")
- end
-
- # Now try something a touch more complicated
parser.initvars
assert_nothing_raised do
- out = parser.parse "Exec { path => '/usr/bin:/usr/sbin' }"
- assert_instance_of(Puppet::Resource::TypeCollection, out)
- assert_equal("", parser.hostclass("").name)
- assert_equal("", parser.hostclass("").namespace)
+ parser.known_resource_types.import_ast(parser.parse("Exec { path => '/usr/bin:/usr/sbin' }"), '')
+ assert_equal("", parser.known_resource_types.hostclass("").name)
+ assert_equal("", parser.known_resource_types.hostclass("").namespace)
end
end
@@@ -482,11 -472,12 +472,12 @@@
ret = nil
assert_nothing_raised do
- ret = parser.parse("#{at}file { '/tmp/testing': owner => root }")
+ parser.known_resource_types.import_ast(parser.parse("#{at}file { '/tmp/testing': owner => root }"), '')
+ ret = parser.known_resource_types
end
assert_instance_of(AST::ASTArray, ret.hostclass("").code)
- resdef = ret.hostclass("").code[0]
+ resdef = ret.hostclass("").code[0][0]
assert_instance_of(AST::Resource, resdef)
assert_equal("/tmp/testing", resdef.title.value)
# We always get an astarray back, so...
@@@ -494,10 -485,11 +485,11 @@@
# Now let's try it with multiple resources in the same spec
assert_nothing_raised do
- ret = parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }")
+ parser.known_resource_types.import_ast(parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }"), '')
+ ret = parser.known_resource_types
end
- ret.hostclass("").code.each do |res|
+ ret.hostclass("").code[0].each do |res|
assert_instance_of(AST::Resource, res)
check.call(res, "multiresource")
end
@@@ -537,7 -529,7 +529,7 @@@
ret = parser.parse("File #{arrow}")
end
- coll = ret.hostclass("").code[0]
+ coll = ret.code[0]
assert_instance_of(AST::Collection, coll)
assert_equal(form, coll.form)
end
@@@ -560,7 -552,7 +552,7 @@@
res = nil
assert_nothing_raised do
- res = parser.parse(str).hostclass("").code[0]
+ res = parser.parse(str).code[0]
end
assert_instance_of(AST::Collection, res)
@@@ -583,7 -575,7 +575,7 @@@
res = nil
assert_nothing_raised do
- res = parser.parse(str).hostclass("").code[0]
+ res = parser.parse(str).code[0]
end
assert_instance_of(AST::Collection, res)
@@@ -607,7 -599,7 +599,7 @@@
res = nil
assert_nothing_raised("Could not parse '#{test}'") do
- res = parser.parse(str).hostclass("").code[0]
+ res = parser.parse(str).code[0]
end
assert_instance_of(AST::Collection, res)
@@@ -624,15 -616,11 +616,11 @@@
def test_fully_qualified_definitions
parser = mkparser
+ types = parser.known_resource_types
assert_nothing_raised("Could not parse fully-qualified definition") {
- parser.parse %{define one::two { }}
+ types.import_ast(parser.parse(%{define one::two { }}), '')
}
assert(parser.definition("one::two"), "Could not find one::two with no namespace")
-
- # Now try using the definition
- assert_nothing_raised("Could not parse fully-qualified definition usage") {
- parser.parse %{one::two { yayness: }}
- }
end
# #524
@@@ -655,9 -643,9 +643,9 @@@
end
def test_multiple_imports_on_one_line
- one = tempfile
- two = tempfile
- base = tempfile
+ one = tempfile '.pp'
+ two = tempfile '.pp'
+ base = tempfile '.pp'
File.open(one, "w") { |f| f.puts "$var = value" }
File.open(two, "w") { |f| f.puts "$var = value" }
File.open(base, "w") { |f| f.puts "import '#{one}', '#{two}'" }
@@@ -691,7 -679,7 +679,7 @@@
result = parser.parse %{$variable = undef}
}
- main = result.hostclass("").code
+ main = result.code
children = main.children
assert_instance_of(AST::VarDef, main.children[0])
assert_instance_of(AST::Undef, main.children[0].value)
@@@ -704,7 -692,8 +692,8 @@@
str = "file { '/tmp/yay': ensure => file }\nclass yay {}\nnode foo {}\ndefine bar {}\n"
result = nil
assert_nothing_raised("Could not parse") do
- result = parser.parse(str)
+ parser.known_resource_types.import_ast(parser.parse(str), '')
+ result = parser.known_resource_types
end
assert_instance_of(Puppet::Resource::TypeCollection, result, "Did not get a ASTSet back from parsing")
@@@ -734,12 -723,14 +723,14 @@@
result = nil
assert_nothing_raised do
- result = parser.newclass "Yayness"
+ parser.known_resource_types.import_ast(parser.parse("class yayness { }"), '')
+ result = parser.known_resource_types.hostclass('yayness')
end
assert_equal(result, parser.find_hostclass("", "yayNess"))
assert_nothing_raised do
- result = parser.newdefine "FunTest"
+ parser.known_resource_types.import_ast(parser.parse("define funtest { }"), '')
+ result = parser.known_resource_types.definition('funtest')
end
assert_equal(result, parser.find_definition("", "fUntEst"), "#{"fUntEst"} was not matched")
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list