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.

Files changed (185) hide show
  1. data/CHANGELOG +98 -0
  2. data/Rakefile +5 -1
  3. data/bin/puppet +1 -1
  4. data/bin/puppetca +25 -11
  5. data/bin/puppetd +189 -66
  6. data/bin/puppetdoc +79 -62
  7. data/bin/puppetmasterd +93 -49
  8. data/bin/puppetrun +385 -0
  9. data/conf/redhat/client.init +5 -2
  10. data/conf/redhat/fileserver.conf +1 -1
  11. data/conf/redhat/lsb-config.patch +51 -0
  12. data/conf/redhat/puppet.spec +45 -18
  13. data/conf/redhat/puppetd.conf +32 -4
  14. data/conf/redhat/server.init +5 -2
  15. data/conf/solaris/pkginfo +7 -0
  16. data/conf/solaris/smf/puppetd.xml +77 -0
  17. data/conf/solaris/smf/puppetmasterd.xml +77 -0
  18. data/conf/solaris/smf/svc-puppetd +66 -0
  19. data/conf/solaris/smf/svc-puppetmasterd +62 -0
  20. data/examples/code/failers/noobjectrvalue +1 -0
  21. data/examples/code/snippets/deepclassheirarchy.pp +23 -0
  22. data/examples/code/snippets/defineoverrides.pp +17 -0
  23. data/examples/code/snippets/emptyexec.pp +3 -0
  24. data/examples/code/snippets/selectorvalues.pp +6 -1
  25. data/examples/code/snippets/tagged.pp +35 -0
  26. data/ext/ldap/puppet.schema +2 -2
  27. data/install.rb +4 -2
  28. data/lib/puppet.rb +206 -15
  29. data/lib/puppet/client.rb +30 -20
  30. data/lib/puppet/client/ca.rb +2 -2
  31. data/lib/puppet/client/dipper.rb +5 -9
  32. data/lib/puppet/client/master.rb +224 -44
  33. data/lib/puppet/client/pelement.rb +54 -9
  34. data/lib/puppet/client/proxy.rb +3 -2
  35. data/lib/puppet/client/reporter.rb +34 -0
  36. data/lib/puppet/client/runner.rb +17 -0
  37. data/lib/puppet/config.rb +136 -55
  38. data/lib/puppet/daemon.rb +59 -37
  39. data/lib/puppet/element.rb +2 -1
  40. data/lib/puppet/event.rb +14 -3
  41. data/lib/puppet/filetype.rb +28 -19
  42. data/lib/puppet/log.rb +297 -132
  43. data/lib/puppet/metric.rb +31 -131
  44. data/lib/puppet/networkclient.rb +73 -46
  45. data/lib/puppet/parameter.rb +49 -1
  46. data/lib/puppet/parsedfile.rb +32 -12
  47. data/lib/puppet/parser/ast.rb +6 -1
  48. data/lib/puppet/parser/ast/astarray.rb +32 -6
  49. data/lib/puppet/parser/ast/collection.rb +91 -0
  50. data/lib/puppet/parser/ast/compdef.rb +2 -2
  51. data/lib/puppet/parser/ast/component.rb +24 -11
  52. data/lib/puppet/parser/ast/function.rb +50 -0
  53. data/lib/puppet/parser/ast/hostclass.rb +70 -22
  54. data/lib/puppet/parser/ast/node.rb +17 -8
  55. data/lib/puppet/parser/ast/nodedef.rb +1 -1
  56. data/lib/puppet/parser/ast/objectdef.rb +28 -10
  57. data/lib/puppet/parser/ast/selector.rb +4 -1
  58. data/lib/puppet/parser/functions.rb +145 -0
  59. data/lib/puppet/parser/interpreter.rb +243 -86
  60. data/lib/puppet/parser/lexer.rb +5 -4
  61. data/lib/puppet/parser/parser.rb +586 -505
  62. data/lib/puppet/parser/scope.rb +337 -187
  63. data/lib/puppet/rails.rb +115 -0
  64. data/lib/puppet/rails/database.rb +40 -0
  65. data/lib/puppet/rails/host.rb +83 -0
  66. data/lib/puppet/rails/rails_object.rb +42 -0
  67. data/lib/puppet/rails/rails_parameter.rb +5 -0
  68. data/lib/puppet/reports/rrdgraph.rb +20 -0
  69. data/lib/puppet/reports/tagmail.rb +94 -0
  70. data/lib/puppet/server.rb +20 -4
  71. data/lib/puppet/server/authconfig.rb +14 -3
  72. data/lib/puppet/server/authstore.rb +2 -2
  73. data/lib/puppet/server/ca.rb +23 -11
  74. data/lib/puppet/server/filebucket.rb +10 -10
  75. data/lib/puppet/server/fileserver.rb +4 -8
  76. data/lib/puppet/server/master.rb +19 -22
  77. data/lib/puppet/server/pelement.rb +28 -16
  78. data/lib/puppet/server/report.rb +184 -0
  79. data/lib/puppet/server/runner.rb +62 -0
  80. data/lib/puppet/server/servlet.rb +23 -9
  81. data/lib/puppet/sslcertificates/ca.rb +25 -1
  82. data/lib/puppet/statechange.rb +34 -53
  83. data/lib/puppet/storage.rb +1 -2
  84. data/lib/puppet/transaction.rb +305 -133
  85. data/lib/puppet/transaction/report.rb +42 -0
  86. data/lib/puppet/transportable.rb +57 -33
  87. data/lib/puppet/type.rb +260 -127
  88. data/lib/puppet/type/component.rb +9 -21
  89. data/lib/puppet/type/cron.rb +367 -116
  90. data/lib/puppet/type/exec.rb +15 -16
  91. data/lib/puppet/type/group.rb +9 -1
  92. data/lib/puppet/type/nameservice.rb +2 -5
  93. data/lib/puppet/type/nameservice/netinfo.rb +3 -0
  94. data/lib/puppet/type/nameservice/objectadd.rb +23 -10
  95. data/lib/puppet/type/nameservice/pw.rb +16 -3
  96. data/lib/puppet/type/package.rb +25 -75
  97. data/lib/puppet/type/package/apple.rb +15 -1
  98. data/lib/puppet/type/package/apt.rb +37 -2
  99. data/lib/puppet/type/package/blastwave.rb +136 -0
  100. data/lib/puppet/type/package/dpkg.rb +4 -4
  101. data/lib/puppet/type/package/gem.rb +119 -0
  102. data/lib/puppet/type/package/openbsd.rb +7 -6
  103. data/lib/puppet/type/package/ports.rb +7 -2
  104. data/lib/puppet/type/package/rpm.rb +1 -1
  105. data/lib/puppet/type/package/sun.rb +23 -9
  106. data/lib/puppet/type/package/sunfreeware.rb +7 -0
  107. data/lib/puppet/type/package/yum.rb +16 -9
  108. data/lib/puppet/type/parsedtype.rb +7 -5
  109. data/lib/puppet/type/parsedtype/mount.rb +55 -34
  110. data/lib/puppet/type/parsedtype/port.rb +7 -1
  111. data/lib/puppet/type/parsedtype/sshkey.rb +6 -16
  112. data/lib/puppet/type/pfile.rb +115 -23
  113. data/lib/puppet/type/pfile/checksum.rb +18 -5
  114. data/lib/puppet/type/pfile/content.rb +2 -2
  115. data/lib/puppet/type/pfile/ensure.rb +3 -3
  116. data/lib/puppet/type/pfile/group.rb +2 -2
  117. data/lib/puppet/type/pfile/source.rb +28 -17
  118. data/lib/puppet/type/pfile/target.rb +25 -17
  119. data/lib/puppet/type/pfilebucket.rb +25 -6
  120. data/lib/puppet/type/schedule.rb +6 -6
  121. data/lib/puppet/type/service.rb +24 -14
  122. data/lib/puppet/type/service/debian.rb +1 -1
  123. data/lib/puppet/type/service/redhat.rb +13 -10
  124. data/lib/puppet/type/service/smf.rb +3 -3
  125. data/lib/puppet/type/state.rb +1 -2
  126. data/lib/puppet/type/symlink.rb +3 -4
  127. data/lib/puppet/type/user.rb +22 -10
  128. data/lib/puppet/type/yumrepo.rb +6 -1
  129. data/lib/puppet/type/zone.rb +595 -0
  130. data/lib/puppet/util.rb +58 -12
  131. data/test/client/client.rb +2 -2
  132. data/test/client/master.rb +92 -3
  133. data/test/client/pelement.rb +99 -0
  134. data/test/executables/puppetbin.rb +3 -4
  135. data/test/executables/puppetca.rb +3 -3
  136. data/test/executables/puppetd.rb +3 -3
  137. data/test/executables/puppetmasterd.rb +1 -5
  138. data/test/executables/puppetmodule.rb +2 -2
  139. data/test/language/ast.rb +200 -11
  140. data/test/language/functions.rb +245 -0
  141. data/test/language/interpreter.rb +155 -6
  142. data/test/language/lexer.rb +35 -2
  143. data/test/language/node.rb +48 -1
  144. data/test/language/parser.rb +250 -1
  145. data/test/language/rails.rb +105 -0
  146. data/test/language/scope.rb +304 -10
  147. data/test/language/snippets.rb +54 -5
  148. data/test/language/transportable.rb +60 -28
  149. data/test/other/config.rb +214 -1
  150. data/test/other/events.rb +67 -9
  151. data/test/other/log.rb +31 -5
  152. data/test/other/metrics.rb +23 -21
  153. data/test/other/parsedfile.rb +29 -2
  154. data/test/other/puppet.rb +79 -0
  155. data/test/other/report.rb +106 -0
  156. data/test/other/storage.rb +2 -2
  157. data/test/other/transactions.rb +128 -2
  158. data/test/puppet/utiltest.rb +10 -5
  159. data/test/puppettest.rb +193 -21
  160. data/test/server/authstore.rb +13 -4
  161. data/test/server/bucket.rb +33 -8
  162. data/test/server/ca.rb +44 -6
  163. data/test/server/master.rb +6 -7
  164. data/test/server/pelement.rb +15 -5
  165. data/test/server/report.rb +93 -0
  166. data/test/server/runner.rb +107 -0
  167. data/test/server/server.rb +28 -1
  168. data/test/types/cron.rb +339 -31
  169. data/test/types/file.rb +256 -24
  170. data/test/types/filebucket.rb +6 -2
  171. data/test/types/filesources.rb +41 -92
  172. data/test/types/group.rb +31 -1
  173. data/test/types/host.rb +2 -1
  174. data/test/types/mount.rb +18 -1
  175. data/test/types/package.rb +200 -18
  176. data/test/types/service.rb +5 -1
  177. data/test/types/sshkey.rb +2 -1
  178. data/test/types/symlink.rb +3 -2
  179. data/test/types/type.rb +180 -1
  180. data/test/types/user.rb +65 -27
  181. data/test/types/yumrepo.rb +15 -0
  182. data/test/types/zone.rb +437 -0
  183. metadata +43 -4
  184. data/bin/cf2puppet +0 -186
  185. data/conf/redhat/puppetmasterd.conf +0 -5
@@ -25,6 +25,7 @@ require 'puppettest'
25
25
 
26
26
  class TestSnippets < Test::Unit::TestCase
27
27
  include TestPuppet
28
+ include ObjectSpace
28
29
  $snippetbase = File.join($puppetbase, "examples", "code", "snippets")
29
30
 
30
31
  def file2ast(file)
@@ -186,7 +187,7 @@ class TestSnippets < Test::Unit::TestCase
186
187
  assert_nothing_raised {
187
188
  trans.rollback
188
189
  }
189
- assert(! FileTest.exists?(file))
190
+ assert(! FileTest.exists?(file), "%s still exists" % file)
190
191
  end
191
192
 
192
193
  def snippet_simpleselector(trans)
@@ -206,7 +207,7 @@ class TestSnippets < Test::Unit::TestCase
206
207
  trans.rollback
207
208
  }
208
209
  files.each { |file|
209
- assert(! FileTest.exists?(file))
210
+ assert(! FileTest.exists?(file), "%s still exists" % file)
210
211
  }
211
212
  end
212
213
 
@@ -231,7 +232,7 @@ class TestSnippets < Test::Unit::TestCase
231
232
  assert_nothing_raised {
232
233
  trans.rollback
233
234
  }
234
- assert(! FileTest.exists?(file))
235
+ assert(! FileTest.exists?(file), "%s still exists" % file)
235
236
  end
236
237
 
237
238
  def snippet_argumentdefaults(trans)
@@ -433,10 +434,45 @@ class TestSnippets < Test::Unit::TestCase
433
434
  @@tmpfiles << "/tmp/settestingness"
434
435
  end
435
436
 
437
+ # Make sure that set tags are correctly in place, yo.
438
+ def snippet_tagged(trans)
439
+ tags = {"testing" => true, "yayness" => false,
440
+ "both" => false, "bothtrue" => true, "define" => true}
441
+
442
+ tags.each do |tag, retval|
443
+ @@tmpfiles << "/tmp/tagged#{tag}true"
444
+ @@tmpfiles << "/tmp/tagged#{tag}false"
445
+
446
+ assert(FileTest.exists?("/tmp/tagged#{tag}#{retval.to_s}"),
447
+ "'tagged' did not return %s with %s" % [retval, tag])
448
+ end
449
+ end
450
+
451
+ def snippet_defineoverrides(trans)
452
+ file = "/tmp/defineoverrides1"
453
+ assert(FileTest.exists?(file), "File does not exist")
454
+ assert_equal(0755, filemode(file))
455
+ end
456
+
457
+ def snippet_deepclassheirarchy(trans)
458
+ 5.times { |i|
459
+ i += 1
460
+ file = "/tmp/deepclassheir%s" % i
461
+ assert(FileTest.exists?(file), "File %s does not exist" % file)
462
+ }
463
+ end
464
+
436
465
  def snippet_emptyclass(trans)
437
466
  # There's nothing to check other than that it works
438
467
  end
439
468
 
469
+ def snippet_emptyexec(trans)
470
+ assert(FileTest.exists?("/tmp/emptyexectest"),
471
+ "Empty exec was ignored")
472
+
473
+ @@tmpfiles << "/tmp/emptyexextest"
474
+ end
475
+
440
476
  def disabled_snippet_dirchmod(trans)
441
477
  dirs = %w{a b}.collect { |letter|
442
478
  "/tmp/dirchmodtest%s" % letter
@@ -480,6 +516,18 @@ class TestSnippets < Test::Unit::TestCase
480
516
  assert_nothing_raised {
481
517
  client.getconfig()
482
518
  }
519
+
520
+ client = Puppet::Client::MasterClient.new(
521
+ :Master => server,
522
+ :Cache => false
523
+ )
524
+
525
+ assert(client.local)
526
+ # Now do it again
527
+ Puppet::Type.allclear
528
+ assert_nothing_raised {
529
+ client.getconfig()
530
+ }
483
531
  trans = nil
484
532
  assert_nothing_raised {
485
533
  trans = client.apply()
@@ -495,16 +543,17 @@ class TestSnippets < Test::Unit::TestCase
495
543
  assert(obj.name)
496
544
 
497
545
  if obj.is_a?(Puppet.type(:file))
498
- @@tmpfiles << obj.name
546
+ @@tmpfiles << obj[:path]
499
547
  end
500
548
  }
501
549
  }
502
550
  assert_nothing_raised {
503
551
  self.send(mname, trans)
504
552
  }
553
+
554
+ client.clear
505
555
  }
506
556
  mname = mname.intern
507
- #eval("alias %s %s" % [testname, mname])
508
557
  end
509
558
  }
510
559
  end
@@ -13,34 +13,10 @@ require 'puppettest'
13
13
  require 'yaml'
14
14
 
15
15
  class TestTransportable < Test::Unit::TestCase
16
- include TestPuppet
17
-
18
- def mkobj(file = "/etc/passwd")
19
- obj = nil
20
- assert_nothing_raised {
21
- obj = Puppet::TransObject.new("file", file)
22
- obj["owner"] = "root"
23
- obj["mode"] = "644"
24
- }
25
-
26
- return obj
27
- end
28
-
29
- def mkbucket(*objects)
30
- bucket = nil
31
- assert_nothing_raised {
32
- bucket = Puppet::TransBucket.new
33
- bucket.name = "yayname"
34
- bucket.type = "yaytype"
35
- }
36
-
37
- objects.each { |o| bucket << o }
38
-
39
- return bucket
40
- end
16
+ include ParserTesting
41
17
 
42
18
  def test_yamldumpobject
43
- obj = mkobj
19
+ obj = mk_transobject
44
20
  obj.to_yaml_properties
45
21
  str = nil
46
22
  assert_nothing_raised {
@@ -58,9 +34,9 @@ class TestTransportable < Test::Unit::TestCase
58
34
 
59
35
  def test_yamldumpbucket
60
36
  objects = %w{/etc/passwd /etc /tmp /var /dev}.collect { |d|
61
- mkobj(d)
37
+ mk_transobject(d)
62
38
  }
63
- bucket = mkbucket(*objects)
39
+ bucket = mk_transbucket(*objects)
64
40
  str = nil
65
41
  assert_nothing_raised {
66
42
  str = YAML.dump(bucket)
@@ -74,4 +50,60 @@ class TestTransportable < Test::Unit::TestCase
74
50
  assert(newobj.name, "Bucket has no name")
75
51
  assert(newobj.type, "Bucket has no type")
76
52
  end
53
+
54
+ # Verify that we correctly strip out collectable objects, since they should
55
+ # not be sent to the client.
56
+ def test_collectstrip
57
+ top = mk_transtree do |object, depth, width|
58
+ if width % 2 == 1
59
+ object.collectable = true
60
+ end
61
+ end
62
+
63
+ assert(top.flatten.find_all { |o| o.collectable }.length > 0,
64
+ "Could not find any collectable objects")
65
+
66
+ # Now strip out the collectable objects
67
+ top.collectstrip!
68
+
69
+ # And make sure they're actually gone
70
+ assert_equal(0, top.flatten.find_all { |o| o.collectable }.length,
71
+ "Still found collectable objects")
72
+ end
73
+
74
+ # Make sure our 'delve' command is working
75
+ def test_delve
76
+ top = mk_transtree do |object, depth, width|
77
+ if width % 2 == 1
78
+ object.collectable = true
79
+ end
80
+ end
81
+
82
+ objects = []
83
+ buckets = []
84
+ collectable = []
85
+
86
+ count = 0
87
+ assert_nothing_raised {
88
+ top.delve do |object|
89
+ count += 1
90
+ if object.is_a? Puppet::TransBucket
91
+ buckets << object
92
+ else
93
+ objects << object
94
+ if object.collectable
95
+ collectable << object
96
+ end
97
+ end
98
+ end
99
+ }
100
+
101
+ top.flatten.each do |obj|
102
+ assert(objects.include?(obj), "Missing obj %s[%s]" % [obj.type, obj.name])
103
+ end
104
+
105
+ assert_equal(collectable.length,
106
+ top.flatten.find_all { |o| o.collectable }.length,
107
+ "Found incorrect number of collectable objects")
108
+ end
77
109
  end
data/test/other/config.rb CHANGED
@@ -594,6 +594,219 @@ yay = /a/path
594
594
  end
595
595
  end
596
596
  end
597
+
598
+ def test_booleans_and_integers
599
+ config = mkconfig
600
+ config.setdefaults(:mysection,
601
+ :booltest => [false, "yay"],
602
+ :inttest => [14, "yay"]
603
+ )
604
+
605
+ file = tempfile()
606
+
607
+ File.open(file, "w") do |f|
608
+ f.puts %{
609
+ [mysection]
610
+ booltest = true
611
+ inttest = 27
612
+ }
613
+ end
614
+
615
+ assert_nothing_raised {
616
+ config.parse(file)
617
+ }
618
+
619
+ assert_equal(true, config[:booltest], "Boolean was not converted")
620
+ assert_equal(27, config[:inttest], "Integer was not converted")
621
+
622
+ # Now make sure that they get converted through handlearg
623
+ config.handlearg("--inttest", "true")
624
+ assert_equal(true, config[:inttest], "Boolean was not converted")
625
+ config.handlearg("--no-booltest", "false")
626
+ assert_equal(false, config[:booltest], "Boolean was not converted")
627
+ end
628
+
629
+ # Make sure that tags are ignored when configuring
630
+ def test_configs_ignore_tags
631
+ config = mkconfig
632
+ file = tempfile()
633
+
634
+ config.setdefaults(:mysection,
635
+ :mydir => [file, "a file"]
636
+ )
637
+
638
+ Puppet[:tags] = "yayness"
639
+
640
+ assert_nothing_raised {
641
+ config.use(:mysection)
642
+ }
643
+
644
+ assert(FileTest.directory?(file), "Directory did not get created")
645
+
646
+ assert_equal("yayness", Puppet[:tags],
647
+ "Tags got changed during config")
648
+ end
649
+
650
+ def test_configs_replace_in_url
651
+ config = mkconfig
652
+
653
+ config.setdefaults(:mysection, :name => ["yayness", "yay"])
654
+ config.setdefaults(:mysection, :url => ["http://$name/rahness", "yay"])
655
+
656
+ val = nil
657
+ assert_nothing_raised {
658
+ val = config[:url]
659
+ }
660
+
661
+ assert_equal("http://yayness/rahness", val,
662
+ "Config got messed up")
663
+ end
664
+
665
+ def test_correct_type_assumptions
666
+ config = mkconfig
667
+
668
+ file = Puppet::Config::CFile
669
+ element = Puppet::Config::CElement
670
+ bool = Puppet::Config::CBoolean
671
+
672
+ # We have to keep these ordered, unfortunately.
673
+ [
674
+ ["/this/is/a/file", file],
675
+ ["true", bool],
676
+ [true, bool],
677
+ ["false", bool],
678
+ ["server", element],
679
+ ["http://$server/yay", element],
680
+ ["$server/yayness", file],
681
+ ["$server/yayness.conf", file]
682
+ ].each do |ary|
683
+ value, type = ary
684
+ elem = nil
685
+ assert_nothing_raised {
686
+ elem = config.newelement(
687
+ :name => value,
688
+ :default => value,
689
+ :section => :yayness
690
+ )
691
+ }
692
+
693
+ assert_instance_of(type, elem,
694
+ "%s got created as wrong type" % value.inspect)
695
+ end
696
+ end
697
+
698
+ # Make sure we correctly reparse our config files but don't lose CLI values.
699
+ def test_reparse
700
+ Puppet[:filetimeout] = 0
701
+
702
+ config = mkconfig()
703
+ config.setdefaults(:mysection, :default => ["default", "yay"])
704
+ config.setdefaults(:mysection, :clichange => ["clichange", "yay"])
705
+ config.setdefaults(:mysection, :filechange => ["filechange", "yay"])
706
+
707
+ file = tempfile()
708
+ # Set one parameter in the file
709
+ File.open(file, "w") { |f|
710
+ f.puts %{[mysection]\nfilechange = filevalue}
711
+ }
712
+ assert_nothing_raised {
713
+ config.parse(file)
714
+ }
715
+
716
+ # Set another "from the cli"
717
+ assert_nothing_raised {
718
+ config.handlearg("clichange", "clivalue")
719
+ }
720
+
721
+ # And leave the other unset
722
+ assert_equal("default", config[:default])
723
+ assert_equal("filevalue", config[:filechange])
724
+ assert_equal("clivalue", config[:clichange])
725
+
726
+ # Now rewrite the file
727
+ File.open(file, "w") { |f|
728
+ f.puts %{[mysection]\nfilechange = newvalue}
729
+ }
730
+
731
+ cfile = config.file
732
+ cfile.send("tstamp=".intern, Time.now - 50)
733
+
734
+ # And check all of the values
735
+ assert_equal("default", config[:default])
736
+ assert_equal("clivalue", config[:clichange])
737
+ assert_equal("newvalue", config[:filechange])
738
+ end
739
+
740
+ def test_parse_removes_quotes
741
+ config = mkconfig()
742
+ config.setdefaults(:mysection, :singleq => ["single", "yay"])
743
+ config.setdefaults(:mysection, :doubleq => ["double", "yay"])
744
+ config.setdefaults(:mysection, :none => ["noquote", "yay"])
745
+ config.setdefaults(:mysection, :middle => ["midquote", "yay"])
746
+
747
+ file = tempfile()
748
+ # Set one parameter in the file
749
+ File.open(file, "w") { |f|
750
+ f.puts %{[mysection]\n
751
+ singleq = 'one'
752
+ doubleq = "one"
753
+ none = one
754
+ middle = mid"quote
755
+ }
756
+ }
757
+
758
+ assert_nothing_raised {
759
+ config.parse(file)
760
+ }
761
+
762
+ %w{singleq doubleq none}.each do |p|
763
+ assert_equal("one", config[p], "%s did not match" % p)
764
+ end
765
+ assert_equal('mid"quote', config["middle"], "middle did not match")
766
+ end
767
+
768
+ def test_timer
769
+ Puppet[:filetimeout] = 0.1
770
+ origpath = tempfile()
771
+ config = mkconfig()
772
+ config.setdefaults(:mysection, :paramdir => [tempfile(), "yay"])
773
+
774
+ file = tempfile()
775
+ # Set one parameter in the file
776
+ File.open(file, "w") { |f|
777
+ f.puts %{[mysection]\n
778
+ paramdir = #{origpath}
779
+ }
780
+ }
781
+
782
+ assert_nothing_raised {
783
+ config.parse(file)
784
+ config.use(:mysection)
785
+ }
786
+
787
+ assert(FileTest.directory?(origpath), "dir did not get created")
788
+
789
+ # Now start the timer
790
+ assert_nothing_raised {
791
+ EventLoop.current.monitor_timer config.timer
792
+ }
793
+
794
+ newpath = tempfile()
795
+
796
+ File.open(file, "w") { |f|
797
+ f.puts %{[mysection]\n
798
+ paramdir = #{newpath}
799
+ }
800
+ }
801
+ config.file.send("tstamp=".intern, Time.now - 50)
802
+ sleep 1
803
+
804
+ assert_equal(newpath, config["paramdir"],
805
+ "File did not get reparsed from timer")
806
+ assert(FileTest.directory?(newpath), "new dir did not get created")
807
+
808
+
809
+ end
597
810
  end
598
811
 
599
- # $Id: config.rb 1077 2006-04-05 06:53:12Z luke $
812
+ # $Id: config.rb 1420 2006-07-21 21:16:09Z luke $
data/test/other/events.rb CHANGED
@@ -8,7 +8,7 @@ require 'puppet'
8
8
  require 'puppettest'
9
9
  require 'test/unit'
10
10
 
11
- # $Id: events.rb 965 2006-03-02 07:30:14Z luke $
11
+ # $Id: events.rb 1179 2006-05-05 19:47:15Z luke $
12
12
 
13
13
  class TestEvents < Test::Unit::TestCase
14
14
  include TestPuppet
@@ -66,6 +66,8 @@ class TestEvents < Test::Unit::TestCase
66
66
  assert_equal(0, trans.triggered?(exec, :refresh))
67
67
  end
68
68
 
69
+ # Verify that one component can subscribe to another component and the "right"
70
+ # thing happens
69
71
  def test_ladderrequire
70
72
  comps = {}
71
73
  objects = {}
@@ -81,21 +83,77 @@ class TestEvents < Test::Unit::TestCase
81
83
  :refreshonly => true
82
84
  )
83
85
 
84
- comps[:f] = newcomp(file)
85
- comps[:e] = newcomp(exec)
86
+ fcomp = newcomp(file)
87
+ ecomp = newcomp(exec)
88
+ comp = newcomp("laddercomp", fcomp, ecomp)
86
89
 
87
- comps[:e][:subscribe] = [[comps[:f].class.name, comps[:f].name]]
88
- comps.each { |l, c|
89
- c.finalize
90
- }
90
+ ecomp[:subscribe] = [[fcomp.class.name, fcomp.name]]
91
+
92
+ comp.finalize
91
93
 
92
- trans = comps[:f].evaluate
94
+ trans = comp.evaluate
93
95
  events = nil
94
96
  assert_nothing_raised {
95
97
  events = trans.evaluate
96
98
  }
97
99
 
98
- assert(FileTest.exists?(fname))
100
+ assert(FileTest.exists?(fname), "#{fname} does not exist")
99
101
  #assert_equal(events.length, trans.triggered?(objects[:b], :refresh))
100
102
  end
103
+
104
+ def test_multiplerefreshes
105
+ files = []
106
+
107
+ 4.times { |i|
108
+ files << Puppet.type(:file).create(
109
+ :name => tempfile(),
110
+ :ensure => "file"
111
+ )
112
+ }
113
+
114
+ fname = tempfile()
115
+ exec = Puppet.type(:exec).create(
116
+ :name => "touch %s" % fname,
117
+ :path => "/usr/bin:/bin",
118
+ :refreshonly => true
119
+ )
120
+
121
+ exec[:subscribe] = files.collect { |f|
122
+ ["file", f.name]
123
+ }
124
+
125
+ comp = newcomp(exec, *files)
126
+
127
+ assert_apply(comp)
128
+ assert(FileTest.exists?(fname), "Exec file did not get created")
129
+ end
130
+
131
+ def test_refreshordering
132
+ file = tempfile()
133
+
134
+ exec1 = Puppet.type(:exec).create(
135
+ :name => "echo one >> %s" % file,
136
+ :path => "/usr/bin:/bin"
137
+ )
138
+
139
+ exec2 = Puppet.type(:exec).create(
140
+ :name => "echo two >> %s" % file,
141
+ :path => "/usr/bin:/bin",
142
+ :refreshonly => true,
143
+ :subscribe => ["exec", exec1.name]
144
+ )
145
+
146
+ exec3 = Puppet.type(:exec).create(
147
+ :name => "echo three >> %s" % file,
148
+ :path => "/usr/bin:/bin"
149
+ )
150
+
151
+ comp = newcomp(exec1,exec2,exec3)
152
+
153
+ assert_apply(comp)
154
+
155
+ assert(FileTest.exists?(file), "File does not exist")
156
+
157
+ assert_equal("one\ntwo\nthree\n", File.read(file))
158
+ end
101
159
  end