puppet 0.16.0 → 0.18.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puppet might be problematic. Click here for more details.
- data/CHANGELOG +98 -0
- data/Rakefile +5 -1
- data/bin/puppet +1 -1
- data/bin/puppetca +25 -11
- data/bin/puppetd +189 -66
- data/bin/puppetdoc +79 -62
- data/bin/puppetmasterd +93 -49
- data/bin/puppetrun +385 -0
- data/conf/redhat/client.init +5 -2
- data/conf/redhat/fileserver.conf +1 -1
- data/conf/redhat/lsb-config.patch +51 -0
- data/conf/redhat/puppet.spec +45 -18
- data/conf/redhat/puppetd.conf +32 -4
- data/conf/redhat/server.init +5 -2
- data/conf/solaris/pkginfo +7 -0
- data/conf/solaris/smf/puppetd.xml +77 -0
- data/conf/solaris/smf/puppetmasterd.xml +77 -0
- data/conf/solaris/smf/svc-puppetd +66 -0
- data/conf/solaris/smf/svc-puppetmasterd +62 -0
- data/examples/code/failers/noobjectrvalue +1 -0
- data/examples/code/snippets/deepclassheirarchy.pp +23 -0
- data/examples/code/snippets/defineoverrides.pp +17 -0
- data/examples/code/snippets/emptyexec.pp +3 -0
- data/examples/code/snippets/selectorvalues.pp +6 -1
- data/examples/code/snippets/tagged.pp +35 -0
- data/ext/ldap/puppet.schema +2 -2
- data/install.rb +4 -2
- data/lib/puppet.rb +206 -15
- data/lib/puppet/client.rb +30 -20
- data/lib/puppet/client/ca.rb +2 -2
- data/lib/puppet/client/dipper.rb +5 -9
- data/lib/puppet/client/master.rb +224 -44
- data/lib/puppet/client/pelement.rb +54 -9
- data/lib/puppet/client/proxy.rb +3 -2
- data/lib/puppet/client/reporter.rb +34 -0
- data/lib/puppet/client/runner.rb +17 -0
- data/lib/puppet/config.rb +136 -55
- data/lib/puppet/daemon.rb +59 -37
- data/lib/puppet/element.rb +2 -1
- data/lib/puppet/event.rb +14 -3
- data/lib/puppet/filetype.rb +28 -19
- data/lib/puppet/log.rb +297 -132
- data/lib/puppet/metric.rb +31 -131
- data/lib/puppet/networkclient.rb +73 -46
- data/lib/puppet/parameter.rb +49 -1
- data/lib/puppet/parsedfile.rb +32 -12
- data/lib/puppet/parser/ast.rb +6 -1
- data/lib/puppet/parser/ast/astarray.rb +32 -6
- data/lib/puppet/parser/ast/collection.rb +91 -0
- data/lib/puppet/parser/ast/compdef.rb +2 -2
- data/lib/puppet/parser/ast/component.rb +24 -11
- data/lib/puppet/parser/ast/function.rb +50 -0
- data/lib/puppet/parser/ast/hostclass.rb +70 -22
- data/lib/puppet/parser/ast/node.rb +17 -8
- data/lib/puppet/parser/ast/nodedef.rb +1 -1
- data/lib/puppet/parser/ast/objectdef.rb +28 -10
- data/lib/puppet/parser/ast/selector.rb +4 -1
- data/lib/puppet/parser/functions.rb +145 -0
- data/lib/puppet/parser/interpreter.rb +243 -86
- data/lib/puppet/parser/lexer.rb +5 -4
- data/lib/puppet/parser/parser.rb +586 -505
- data/lib/puppet/parser/scope.rb +337 -187
- data/lib/puppet/rails.rb +115 -0
- data/lib/puppet/rails/database.rb +40 -0
- data/lib/puppet/rails/host.rb +83 -0
- data/lib/puppet/rails/rails_object.rb +42 -0
- data/lib/puppet/rails/rails_parameter.rb +5 -0
- data/lib/puppet/reports/rrdgraph.rb +20 -0
- data/lib/puppet/reports/tagmail.rb +94 -0
- data/lib/puppet/server.rb +20 -4
- data/lib/puppet/server/authconfig.rb +14 -3
- data/lib/puppet/server/authstore.rb +2 -2
- data/lib/puppet/server/ca.rb +23 -11
- data/lib/puppet/server/filebucket.rb +10 -10
- data/lib/puppet/server/fileserver.rb +4 -8
- data/lib/puppet/server/master.rb +19 -22
- data/lib/puppet/server/pelement.rb +28 -16
- data/lib/puppet/server/report.rb +184 -0
- data/lib/puppet/server/runner.rb +62 -0
- data/lib/puppet/server/servlet.rb +23 -9
- data/lib/puppet/sslcertificates/ca.rb +25 -1
- data/lib/puppet/statechange.rb +34 -53
- data/lib/puppet/storage.rb +1 -2
- data/lib/puppet/transaction.rb +305 -133
- data/lib/puppet/transaction/report.rb +42 -0
- data/lib/puppet/transportable.rb +57 -33
- data/lib/puppet/type.rb +260 -127
- data/lib/puppet/type/component.rb +9 -21
- data/lib/puppet/type/cron.rb +367 -116
- data/lib/puppet/type/exec.rb +15 -16
- data/lib/puppet/type/group.rb +9 -1
- data/lib/puppet/type/nameservice.rb +2 -5
- data/lib/puppet/type/nameservice/netinfo.rb +3 -0
- data/lib/puppet/type/nameservice/objectadd.rb +23 -10
- data/lib/puppet/type/nameservice/pw.rb +16 -3
- data/lib/puppet/type/package.rb +25 -75
- data/lib/puppet/type/package/apple.rb +15 -1
- data/lib/puppet/type/package/apt.rb +37 -2
- data/lib/puppet/type/package/blastwave.rb +136 -0
- data/lib/puppet/type/package/dpkg.rb +4 -4
- data/lib/puppet/type/package/gem.rb +119 -0
- data/lib/puppet/type/package/openbsd.rb +7 -6
- data/lib/puppet/type/package/ports.rb +7 -2
- data/lib/puppet/type/package/rpm.rb +1 -1
- data/lib/puppet/type/package/sun.rb +23 -9
- data/lib/puppet/type/package/sunfreeware.rb +7 -0
- data/lib/puppet/type/package/yum.rb +16 -9
- data/lib/puppet/type/parsedtype.rb +7 -5
- data/lib/puppet/type/parsedtype/mount.rb +55 -34
- data/lib/puppet/type/parsedtype/port.rb +7 -1
- data/lib/puppet/type/parsedtype/sshkey.rb +6 -16
- data/lib/puppet/type/pfile.rb +115 -23
- data/lib/puppet/type/pfile/checksum.rb +18 -5
- data/lib/puppet/type/pfile/content.rb +2 -2
- data/lib/puppet/type/pfile/ensure.rb +3 -3
- data/lib/puppet/type/pfile/group.rb +2 -2
- data/lib/puppet/type/pfile/source.rb +28 -17
- data/lib/puppet/type/pfile/target.rb +25 -17
- data/lib/puppet/type/pfilebucket.rb +25 -6
- data/lib/puppet/type/schedule.rb +6 -6
- data/lib/puppet/type/service.rb +24 -14
- data/lib/puppet/type/service/debian.rb +1 -1
- data/lib/puppet/type/service/redhat.rb +13 -10
- data/lib/puppet/type/service/smf.rb +3 -3
- data/lib/puppet/type/state.rb +1 -2
- data/lib/puppet/type/symlink.rb +3 -4
- data/lib/puppet/type/user.rb +22 -10
- data/lib/puppet/type/yumrepo.rb +6 -1
- data/lib/puppet/type/zone.rb +595 -0
- data/lib/puppet/util.rb +58 -12
- data/test/client/client.rb +2 -2
- data/test/client/master.rb +92 -3
- data/test/client/pelement.rb +99 -0
- data/test/executables/puppetbin.rb +3 -4
- data/test/executables/puppetca.rb +3 -3
- data/test/executables/puppetd.rb +3 -3
- data/test/executables/puppetmasterd.rb +1 -5
- data/test/executables/puppetmodule.rb +2 -2
- data/test/language/ast.rb +200 -11
- data/test/language/functions.rb +245 -0
- data/test/language/interpreter.rb +155 -6
- data/test/language/lexer.rb +35 -2
- data/test/language/node.rb +48 -1
- data/test/language/parser.rb +250 -1
- data/test/language/rails.rb +105 -0
- data/test/language/scope.rb +304 -10
- data/test/language/snippets.rb +54 -5
- data/test/language/transportable.rb +60 -28
- data/test/other/config.rb +214 -1
- data/test/other/events.rb +67 -9
- data/test/other/log.rb +31 -5
- data/test/other/metrics.rb +23 -21
- data/test/other/parsedfile.rb +29 -2
- data/test/other/puppet.rb +79 -0
- data/test/other/report.rb +106 -0
- data/test/other/storage.rb +2 -2
- data/test/other/transactions.rb +128 -2
- data/test/puppet/utiltest.rb +10 -5
- data/test/puppettest.rb +193 -21
- data/test/server/authstore.rb +13 -4
- data/test/server/bucket.rb +33 -8
- data/test/server/ca.rb +44 -6
- data/test/server/master.rb +6 -7
- data/test/server/pelement.rb +15 -5
- data/test/server/report.rb +93 -0
- data/test/server/runner.rb +107 -0
- data/test/server/server.rb +28 -1
- data/test/types/cron.rb +339 -31
- data/test/types/file.rb +256 -24
- data/test/types/filebucket.rb +6 -2
- data/test/types/filesources.rb +41 -92
- data/test/types/group.rb +31 -1
- data/test/types/host.rb +2 -1
- data/test/types/mount.rb +18 -1
- data/test/types/package.rb +200 -18
- data/test/types/service.rb +5 -1
- data/test/types/sshkey.rb +2 -1
- data/test/types/symlink.rb +3 -2
- data/test/types/type.rb +180 -1
- data/test/types/user.rb +65 -27
- data/test/types/yumrepo.rb +15 -0
- data/test/types/zone.rb +437 -0
- metadata +43 -4
- data/bin/cf2puppet +0 -186
- data/conf/redhat/puppetmasterd.conf +0 -5
@@ -44,7 +44,7 @@ class TestPuppetModule < Test::Unit::TestCase
|
|
44
44
|
ENV["CFALLCLASSES"] = "yaytest:all"
|
45
45
|
|
46
46
|
assert_nothing_raised {
|
47
|
-
|
47
|
+
%x{#{cmd + " " + file} 2>&1}
|
48
48
|
}
|
49
49
|
assert($? == 0, "Puppet module exited with code %s" % $?.to_i)
|
50
50
|
|
@@ -52,4 +52,4 @@ class TestPuppetModule < Test::Unit::TestCase
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
# $Id: puppetmodule.rb
|
55
|
+
# $Id: puppetmodule.rb 1256 2006-06-13 15:57:06Z luke $
|
data/test/language/ast.rb
CHANGED
@@ -53,13 +53,20 @@ class TestAST < Test::Unit::TestCase
|
|
53
53
|
}
|
54
54
|
|
55
55
|
scope = nil
|
56
|
+
objects = nil
|
56
57
|
assert_nothing_raised("Could not evaluate") {
|
57
58
|
scope = Puppet::Parser::Scope.new()
|
58
|
-
objects =
|
59
|
+
objects = scope.evaluate(:ast => top)
|
59
60
|
}
|
60
61
|
|
62
|
+
assert_instance_of(Puppet::TransBucket, objects)
|
63
|
+
|
61
64
|
assert_equal(1, scope.find_all { |child|
|
62
|
-
child.
|
65
|
+
if child.is_a? Puppet::Parser::Scope
|
66
|
+
child.lookupobject(:name => "/parent", :type => "file")
|
67
|
+
else
|
68
|
+
nil
|
69
|
+
end
|
63
70
|
}.length, "Found incorrect number of '/parent' objects")
|
64
71
|
|
65
72
|
assert_equal(classes.sort, scope.classlist.sort)
|
@@ -127,7 +134,7 @@ class TestAST < Test::Unit::TestCase
|
|
127
134
|
scope = nil
|
128
135
|
assert_raise(Puppet::ParseError, "Invalid parent type was allowed") {
|
129
136
|
scope = Puppet::Parser::Scope.new()
|
130
|
-
objects =
|
137
|
+
objects = scope.evaluate(:ast => top)
|
131
138
|
}
|
132
139
|
end
|
133
140
|
|
@@ -240,8 +247,7 @@ class TestAST < Test::Unit::TestCase
|
|
240
247
|
end
|
241
248
|
assert(Puppet::Type.type(:file)["/#{name}"], "Could not find '#{name}'")
|
242
249
|
end
|
243
|
-
|
244
|
-
Puppet::Type.type(:file).clear
|
250
|
+
Puppet::Type.allclear
|
245
251
|
end
|
246
252
|
end
|
247
253
|
|
@@ -417,13 +423,16 @@ class TestAST < Test::Unit::TestCase
|
|
417
423
|
objects = scope.evaluate(:names => [name], :facts => {}, :ast => top)
|
418
424
|
}
|
419
425
|
assert(objects, "Could not retrieve short node definition")
|
426
|
+
assert_instance_of(Puppet::TransBucket, objects)
|
420
427
|
|
421
428
|
# And now verify that we got both the top and node objects
|
422
429
|
assert_nothing_raised("Could not find top-declared object") {
|
423
430
|
assert_equal("/testing", objects[0].name)
|
424
431
|
}
|
425
432
|
|
426
|
-
assert_nothing_raised("Could not find node-declared object"
|
433
|
+
assert_nothing_raised("Could not find node-declared object %s" %
|
434
|
+
"/%s" % name
|
435
|
+
) {
|
427
436
|
assert_equal("/%s" % name, objects[1][0].name)
|
428
437
|
}
|
429
438
|
end
|
@@ -454,19 +463,19 @@ class TestAST < Test::Unit::TestCase
|
|
454
463
|
|
455
464
|
# Evaluate the parse tree
|
456
465
|
scope = nil
|
466
|
+
objects = nil
|
457
467
|
assert_nothing_raised("Could not evaluate node") {
|
458
468
|
scope = Puppet::Parser::Scope.new()
|
459
|
-
|
469
|
+
objects = scope.evaluate(:ast => top)
|
460
470
|
}
|
461
471
|
|
462
472
|
# Verify we get the right classlist back
|
463
473
|
assert_equal(classes.sort, scope.classlist.sort)
|
464
474
|
|
465
475
|
# Verify we can find the node via a search list
|
466
|
-
objects
|
467
|
-
|
468
|
-
|
469
|
-
}
|
476
|
+
#assert_nothing_raised("Could not retrieve objects") {
|
477
|
+
# objects = scope.to_trans
|
478
|
+
#}
|
470
479
|
assert(objects, "Could not retrieve objects")
|
471
480
|
|
472
481
|
assert_nothing_raised("Could not find top-declared object") {
|
@@ -701,4 +710,184 @@ class TestAST < Test::Unit::TestCase
|
|
701
710
|
"Node's long name got set")
|
702
711
|
assert(scope.classlist.include?("node"), "Node's name did not get set")
|
703
712
|
end
|
713
|
+
|
714
|
+
# Make sure that deep class parentage works
|
715
|
+
def test_classparentage
|
716
|
+
children = []
|
717
|
+
files = []
|
718
|
+
base = classobj("base")
|
719
|
+
files << "/base"
|
720
|
+
|
721
|
+
children << base
|
722
|
+
|
723
|
+
parent = "base"
|
724
|
+
5.times { |i|
|
725
|
+
name = "child%s" % i
|
726
|
+
files << "/%s" % name
|
727
|
+
children << classobj(name, :parentclass => nameobj(parent))
|
728
|
+
|
729
|
+
parent = name
|
730
|
+
}
|
731
|
+
|
732
|
+
children << functionobj("include", parent)
|
733
|
+
|
734
|
+
top = nil
|
735
|
+
assert_nothing_raised("Could not create top object") {
|
736
|
+
top = AST::ASTArray.new(
|
737
|
+
:children => children
|
738
|
+
)
|
739
|
+
}
|
740
|
+
|
741
|
+
objects = nil
|
742
|
+
assert_nothing_raised("Could not evaluate") {
|
743
|
+
scope = Puppet::Parser::Scope.new()
|
744
|
+
objects = scope.evaluate(:ast => top)
|
745
|
+
}
|
746
|
+
|
747
|
+
objects = objects.flatten
|
748
|
+
|
749
|
+
files.each do |file|
|
750
|
+
assert(objects.find { |o| o.name == file },
|
751
|
+
"Could not find file %s" % file)
|
752
|
+
end
|
753
|
+
end
|
754
|
+
|
755
|
+
# Make sure we catch names that are specified like parameters.
|
756
|
+
def test_name_or_param
|
757
|
+
obj = nil
|
758
|
+
assert_nothing_raised {
|
759
|
+
obj = AST::ObjectDef.new(
|
760
|
+
:type => nameobj("file"),
|
761
|
+
:params => astarray(AST::ObjectParam.new(
|
762
|
+
:param => stringobj("name"),
|
763
|
+
:value => stringobj("yayness")
|
764
|
+
))
|
765
|
+
)
|
766
|
+
}
|
767
|
+
|
768
|
+
scope = Puppet::Parser::Scope.new
|
769
|
+
|
770
|
+
trans = nil
|
771
|
+
assert_nothing_raised {
|
772
|
+
trans = scope.evaluate(:ast => obj, :facts => {})
|
773
|
+
}
|
774
|
+
|
775
|
+
transobj = trans.shift
|
776
|
+
assert(transobj.name, "Name did not convert from param to name")
|
777
|
+
end
|
778
|
+
|
779
|
+
if defined? ActiveRecord
|
780
|
+
# Verify that our collection stuff works.
|
781
|
+
def test_collection
|
782
|
+
collectable = []
|
783
|
+
non = []
|
784
|
+
# First put some objects into the database.
|
785
|
+
bucket = mk_transtree do |object, depth, width|
|
786
|
+
# and mark some of them collectable
|
787
|
+
if width % 2 == 1
|
788
|
+
object.collectable = true
|
789
|
+
collectable << object
|
790
|
+
else
|
791
|
+
non << object
|
792
|
+
end
|
793
|
+
end
|
794
|
+
|
795
|
+
# Now collect our facts
|
796
|
+
facts = {}
|
797
|
+
Facter.each do |fact, value| facts[fact] = value end
|
798
|
+
|
799
|
+
assert_nothing_raised {
|
800
|
+
Puppet::Rails.init
|
801
|
+
}
|
802
|
+
|
803
|
+
# Now try storing our crap
|
804
|
+
assert_nothing_raised {
|
805
|
+
host = Puppet::Rails::Host.store(
|
806
|
+
:objects => bucket,
|
807
|
+
:facts => facts,
|
808
|
+
:host => facts["hostname"]
|
809
|
+
)
|
810
|
+
}
|
811
|
+
|
812
|
+
# Now create an ast tree that collects that. They should all be files.
|
813
|
+
coll = nil
|
814
|
+
assert_nothing_raised {
|
815
|
+
coll = AST::Collection.new(
|
816
|
+
:type => nameobj("file")
|
817
|
+
)
|
818
|
+
}
|
819
|
+
|
820
|
+
top = nil
|
821
|
+
assert_nothing_raised("Could not create top object") {
|
822
|
+
top = AST::ASTArray.new(
|
823
|
+
:children => [coll]
|
824
|
+
)
|
825
|
+
}
|
826
|
+
|
827
|
+
objects = nil
|
828
|
+
assert_nothing_raised("Could not evaluate") {
|
829
|
+
scope = Puppet::Parser::Scope.new()
|
830
|
+
objects = scope.evaluate(:ast => top).flatten
|
831
|
+
}
|
832
|
+
|
833
|
+
assert(objects.length > 0, "Did not receive any collected objects")
|
834
|
+
end
|
835
|
+
else
|
836
|
+
$stderr.puts "No ActiveRecord -- skipping collection tests"
|
837
|
+
end
|
838
|
+
|
839
|
+
# To fix #140. Currently non-functional.
|
840
|
+
def disabled_test_classreuse
|
841
|
+
children = []
|
842
|
+
|
843
|
+
# Create the parent class, with a definition in it.
|
844
|
+
children << classobj("parent", :code => AST::ASTArray.new(
|
845
|
+
:file => __FILE__,
|
846
|
+
:line => __LINE__,
|
847
|
+
:children => [
|
848
|
+
compobj("foo", :args => AST::ASTArray.new(
|
849
|
+
:children => [nameobj("arg")]
|
850
|
+
),
|
851
|
+
:code => AST::ASTArray.new(
|
852
|
+
:file => __FILE__,
|
853
|
+
:line => __LINE__,
|
854
|
+
:children => [fileobj("/$arg")]
|
855
|
+
)
|
856
|
+
),
|
857
|
+
objectdef("foo", "ptest", {"arg" => "parentfoo"})
|
858
|
+
]
|
859
|
+
))
|
860
|
+
|
861
|
+
# Create child class, also trying to use that definition
|
862
|
+
children << classobj("child1", :parentclass => nameobj("parent"),
|
863
|
+
:code => AST::ASTArray.new(
|
864
|
+
:file => __FILE__,
|
865
|
+
:line => __LINE__,
|
866
|
+
:children => [
|
867
|
+
objectdef("foo", "ctest", {"arg" => "childfoo"})
|
868
|
+
]
|
869
|
+
)
|
870
|
+
)
|
871
|
+
|
872
|
+
# Call the parent first
|
873
|
+
children << functionobj("include", "parent")
|
874
|
+
|
875
|
+
# Then call the child, and make sure it can look up the definition
|
876
|
+
children << functionobj("include", "child1")
|
877
|
+
|
878
|
+
top = nil
|
879
|
+
assert_nothing_raised("Could not create top object") {
|
880
|
+
top = AST::ASTArray.new(
|
881
|
+
:children => children
|
882
|
+
)
|
883
|
+
}
|
884
|
+
|
885
|
+
objects = nil
|
886
|
+
assert_nothing_raised("Could not evaluate") {
|
887
|
+
scope = Puppet::Parser::Scope.new()
|
888
|
+
objects = scope.evaluate(:ast => top)
|
889
|
+
}
|
890
|
+
end
|
704
891
|
end
|
892
|
+
|
893
|
+
# $Id: ast.rb 1256 2006-06-13 15:57:06Z luke $
|
@@ -0,0 +1,245 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
if __FILE__ == $0
|
4
|
+
$:.unshift '../../lib'
|
5
|
+
$:.unshift '..'
|
6
|
+
$puppetbase = "../.."
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'puppet'
|
10
|
+
require 'puppet/parser/interpreter'
|
11
|
+
require 'puppet/parser/parser'
|
12
|
+
require 'puppet/client'
|
13
|
+
require 'test/unit'
|
14
|
+
require 'puppettest'
|
15
|
+
|
16
|
+
class TestLangFunctions < Test::Unit::TestCase
|
17
|
+
include ParserTesting
|
18
|
+
def test_functions
|
19
|
+
assert_raise(Puppet::ParseError) do
|
20
|
+
Puppet::Parser::AST::Function.new(
|
21
|
+
:name => "fakefunction",
|
22
|
+
:arguments => AST::ASTArray.new(
|
23
|
+
:children => [nameobj("avalue")]
|
24
|
+
)
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
assert_nothing_raised do
|
29
|
+
Puppet::Parser::Functions.newfunction(:fakefunction, :rvalue) do |input|
|
30
|
+
return "output %s" % input[0]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
func = nil
|
35
|
+
assert_nothing_raised do
|
36
|
+
func = Puppet::Parser::AST::Function.new(
|
37
|
+
:name => "fakefunction",
|
38
|
+
:ftype => :rvalue,
|
39
|
+
:arguments => AST::ASTArray.new(
|
40
|
+
:children => [nameobj("avalue")]
|
41
|
+
)
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
scope = Puppet::Parser::Scope.new()
|
46
|
+
val = nil
|
47
|
+
assert_nothing_raised do
|
48
|
+
val = func.evaluate(:scope => scope)
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_equal("output avalue", val)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_taggedfunction
|
55
|
+
scope = Puppet::Parser::Scope.new()
|
56
|
+
|
57
|
+
tag = "yayness"
|
58
|
+
scope.setclass(tag.object_id, tag)
|
59
|
+
|
60
|
+
{"yayness" => true, "booness" => false}.each do |tag, retval|
|
61
|
+
func = taggedobj(tag, :rvalue)
|
62
|
+
|
63
|
+
val = nil
|
64
|
+
assert_nothing_raised do
|
65
|
+
val = func.evaluate(:scope => scope)
|
66
|
+
end
|
67
|
+
|
68
|
+
assert_equal(retval, val, "'tagged' returned %s for %s" % [val, tag])
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_failfunction
|
73
|
+
func = nil
|
74
|
+
assert_nothing_raised do
|
75
|
+
func = Puppet::Parser::AST::Function.new(
|
76
|
+
:name => "fail",
|
77
|
+
:ftype => :statement,
|
78
|
+
:arguments => AST::ASTArray.new(
|
79
|
+
:children => [stringobj("this is a failure"),
|
80
|
+
stringobj("and another")]
|
81
|
+
)
|
82
|
+
)
|
83
|
+
end
|
84
|
+
|
85
|
+
scope = Puppet::Parser::Scope.new()
|
86
|
+
val = nil
|
87
|
+
assert_raise(Puppet::ParseError) do
|
88
|
+
val = func.evaluate(:scope => scope)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_multipletemplates
|
93
|
+
Dir.mkdir(Puppet[:templatedir])
|
94
|
+
onep = File.join(Puppet[:templatedir], "one")
|
95
|
+
twop = File.join(Puppet[:templatedir], "two")
|
96
|
+
|
97
|
+
File.open(onep, "w") do |f|
|
98
|
+
f.puts "template <%= one %>"
|
99
|
+
end
|
100
|
+
|
101
|
+
File.open(twop, "w") do |f|
|
102
|
+
f.puts "template <%= two %>"
|
103
|
+
end
|
104
|
+
func = nil
|
105
|
+
assert_nothing_raised do
|
106
|
+
func = Puppet::Parser::AST::Function.new(
|
107
|
+
:name => "template",
|
108
|
+
:ftype => :rvalue,
|
109
|
+
:arguments => AST::ASTArray.new(
|
110
|
+
:children => [stringobj("one"),
|
111
|
+
stringobj("two")]
|
112
|
+
)
|
113
|
+
)
|
114
|
+
end
|
115
|
+
ast = varobj("output", func)
|
116
|
+
|
117
|
+
scope = Puppet::Parser::Scope.new()
|
118
|
+
assert_raise(Puppet::ParseError) do
|
119
|
+
ast.evaluate(:scope => scope)
|
120
|
+
end
|
121
|
+
|
122
|
+
scope.setvar("one", "One")
|
123
|
+
assert_raise(Puppet::ParseError) do
|
124
|
+
ast.evaluate(:scope => scope)
|
125
|
+
end
|
126
|
+
scope.setvar("two", "Two")
|
127
|
+
assert_nothing_raised do
|
128
|
+
ast.evaluate(:scope => scope)
|
129
|
+
end
|
130
|
+
|
131
|
+
assert_equal("template One\ntemplate Two\n", scope.lookupvar("output"),
|
132
|
+
"Templates were not handled correctly")
|
133
|
+
end
|
134
|
+
|
135
|
+
# Now make sure we can fully qualify files, and specify just one
|
136
|
+
def test_singletemplates
|
137
|
+
template = tempfile()
|
138
|
+
|
139
|
+
File.open(template, "w") do |f|
|
140
|
+
f.puts "template <%= yayness %>"
|
141
|
+
end
|
142
|
+
|
143
|
+
func = nil
|
144
|
+
assert_nothing_raised do
|
145
|
+
func = Puppet::Parser::AST::Function.new(
|
146
|
+
:name => "template",
|
147
|
+
:ftype => :rvalue,
|
148
|
+
:arguments => AST::ASTArray.new(
|
149
|
+
:children => [stringobj(template)]
|
150
|
+
)
|
151
|
+
)
|
152
|
+
end
|
153
|
+
ast = varobj("output", func)
|
154
|
+
|
155
|
+
scope = Puppet::Parser::Scope.new()
|
156
|
+
assert_raise(Puppet::ParseError) do
|
157
|
+
ast.evaluate(:scope => scope)
|
158
|
+
end
|
159
|
+
|
160
|
+
scope.setvar("yayness", "this is yayness")
|
161
|
+
|
162
|
+
assert_nothing_raised do
|
163
|
+
ast.evaluate(:scope => scope)
|
164
|
+
end
|
165
|
+
|
166
|
+
assert_equal("template this is yayness\n", scope.lookupvar("output"),
|
167
|
+
"Templates were not handled correctly")
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_tempatefunction_cannot_see_scopes
|
172
|
+
template = tempfile()
|
173
|
+
|
174
|
+
File.open(template, "w") do |f|
|
175
|
+
f.puts "<%= lookupvar('myvar') %>"
|
176
|
+
end
|
177
|
+
|
178
|
+
func = nil
|
179
|
+
assert_nothing_raised do
|
180
|
+
func = Puppet::Parser::AST::Function.new(
|
181
|
+
:name => "template",
|
182
|
+
:ftype => :rvalue,
|
183
|
+
:arguments => AST::ASTArray.new(
|
184
|
+
:children => [stringobj(template)]
|
185
|
+
)
|
186
|
+
)
|
187
|
+
end
|
188
|
+
ast = varobj("output", func)
|
189
|
+
|
190
|
+
scope = Puppet::Parser::Scope.new()
|
191
|
+
scope.setvar("myvar", "this is yayness")
|
192
|
+
assert_raise(Puppet::ParseError) do
|
193
|
+
ast.evaluate(:scope => scope)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
def test_template_reparses
|
198
|
+
template = tempfile()
|
199
|
+
|
200
|
+
File.open(template, "w") do |f|
|
201
|
+
f.puts "original text"
|
202
|
+
end
|
203
|
+
|
204
|
+
manifest = tempfile()
|
205
|
+
file = tempfile()
|
206
|
+
File.open(manifest, "w") do |f|
|
207
|
+
f.puts %{file { "#{file}": content => template("#{template}") }}
|
208
|
+
end
|
209
|
+
|
210
|
+
interpreter = Puppet::Parser::Interpreter.new(
|
211
|
+
:Manifest => manifest,
|
212
|
+
:UseNodes => false
|
213
|
+
)
|
214
|
+
|
215
|
+
parsedate = interpreter.parsedate()
|
216
|
+
|
217
|
+
objects = nil
|
218
|
+
assert_nothing_raised {
|
219
|
+
objects = interpreter.run("myhost", {})
|
220
|
+
}
|
221
|
+
|
222
|
+
fileobj = objects[0]
|
223
|
+
|
224
|
+
assert_equal("original text\n", fileobj["content"],
|
225
|
+
"Template did not work")
|
226
|
+
|
227
|
+
Puppet[:filetimeout] = 0
|
228
|
+
# Have to sleep because one second is the fs's time granularity.
|
229
|
+
sleep(1)
|
230
|
+
|
231
|
+
# Now modify the template
|
232
|
+
File.open(template, "w") do |f|
|
233
|
+
f.puts "new text"
|
234
|
+
end
|
235
|
+
|
236
|
+
assert_nothing_raised {
|
237
|
+
objects = interpreter.run("myhost", {})
|
238
|
+
}
|
239
|
+
newdate = interpreter.parsedate()
|
240
|
+
|
241
|
+
assert(parsedate != newdate, "Parse date did not change")
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
# $Id: functions.rb 1421 2006-07-21 23:12:51Z luke $
|