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
data/test/other/log.rb CHANGED
@@ -4,12 +4,12 @@ if __FILE__ == $0
4
4
  $puppetbase = "../.."
5
5
  end
6
6
 
7
- require 'puppet/log'
8
7
  require 'puppet'
8
+ require 'puppet/log'
9
9
  require 'puppettest'
10
10
  require 'test/unit'
11
11
 
12
- # $Id: log.rb 1120 2006-04-19 23:38:25Z luke $
12
+ # $Id: log.rb 1315 2006-06-27 05:15:51Z luke $
13
13
 
14
14
  class TestLog < Test::Unit::TestCase
15
15
  include TestPuppet
@@ -17,12 +17,14 @@ class TestLog < Test::Unit::TestCase
17
17
  def setup
18
18
  super
19
19
  @oldloglevel = Puppet::Log.level
20
+ Puppet::Log.close
20
21
  end
21
22
 
22
23
  def teardown
23
24
  super
24
25
  Puppet::Log.close
25
26
  Puppet::Log.level = @oldloglevel
27
+ Puppet::Log.newdestination(:console)
26
28
  end
27
29
 
28
30
  def getlevels
@@ -51,10 +53,10 @@ class TestLog < Test::Unit::TestCase
51
53
  def test_logfile
52
54
  fact = nil
53
55
  levels = nil
54
- oldlevel = Puppet::Log.level
55
56
  Puppet::Log.level = :debug
56
57
  levels = getlevels
57
58
  logfile = tempfile()
59
+ fact = nil
58
60
  assert_nothing_raised() {
59
61
  Puppet::Log.newdestination(logfile)
60
62
  }
@@ -62,6 +64,9 @@ class TestLog < Test::Unit::TestCase
62
64
  assert(msgs.length == levels.length)
63
65
  Puppet::Log.close
64
66
  count = 0
67
+
68
+ assert(FileTest.exists?(logfile), "Did not create logfile")
69
+
65
70
  assert_nothing_raised() {
66
71
  File.open(logfile) { |of|
67
72
  count = of.readlines.length
@@ -108,10 +113,10 @@ class TestLog < Test::Unit::TestCase
108
113
  end
109
114
 
110
115
  def test_output
111
- Puppet.debug = false
116
+ Puppet::Log.level = :notice
112
117
  assert(Puppet.err("This is an error").is_a?(Puppet::Log))
113
118
  assert(Puppet.debug("This is debugging").nil?)
114
- Puppet.debug = true
119
+ Puppet::Log.level = :debug
115
120
  assert(Puppet.err("This is an error").is_a?(Puppet::Log))
116
121
  assert(Puppet.debug("This is debugging").is_a?(Puppet::Log))
117
122
  end
@@ -200,4 +205,25 @@ class TestLog < Test::Unit::TestCase
200
205
  assert_equal(:warning, file[:loglevel])
201
206
  }
202
207
  end
208
+
209
+ def test_destination_matching
210
+ dest = nil
211
+ assert_nothing_raised {
212
+ dest = Puppet::Log.newdesttype("Destine") do
213
+ def handle(msg)
214
+ puts msg
215
+ end
216
+ end
217
+ }
218
+
219
+ [:destine, "Destine", "destine"].each do |name|
220
+ assert(dest.match?(name), "Did not match %s" % name.inspect)
221
+ end
222
+
223
+ assert_nothing_raised {
224
+ dest.match(:yayness)
225
+ }
226
+ assert(dest.match("Yayness"), "Did not match yayness")
227
+ Puppet::Log.close(dest)
228
+ end
203
229
  end
@@ -36,21 +36,27 @@ if $haverrd
36
36
  typehash[type] = Hash.new(0)
37
37
  }
38
38
  eventdata = Hash.new(0)
39
- types.each { |type|
40
- name = type.name
41
- typedata[type] = {}
42
- typedata[type][:total] = rand(totalmax)
43
- typedata[type][:managed] = rand(typedata[type][:total])
44
- typedata[type][:outofsync] = rand(typedata[type][:managed])
45
- typedata[type][:changed] = rand(typedata[type][:outofsync])
46
- typedata[type][:totalchanges] = rand(changemax)
47
- }
39
+ typedata = {}
40
+ typedata[:total] = rand(totalmax)
41
+ typedata[:managed] = rand(typedata[:total])
42
+ typedata[:outofsync] = rand(typedata[:managed])
43
+ typedata[:changed] = rand(typedata[:outofsync])
44
+ typedata[:totalchanges] = rand(changemax)
48
45
 
49
46
  events.each { |event|
50
47
  eventdata[event] = rand(eventmax)
51
48
  }
52
49
 
53
- return [typedata,eventdata]
50
+ return {:typedata => typedata, :eventdata => eventdata}
51
+ end
52
+
53
+ def rundata(report, time)
54
+ assert_nothing_raised {
55
+ gendata.each do |name, data|
56
+ report.newmetric(name, data)
57
+ end
58
+ report.metrics.each { |n, m| m.store(time) }
59
+ }
54
60
  end
55
61
 
56
62
  def setup
@@ -59,24 +65,20 @@ if $haverrd
59
65
  end
60
66
 
61
67
  def test_fakedata
62
- assert_nothing_raised { Puppet::Metric.init }
68
+ report = Puppet::Transaction::Report.new
63
69
  time = Time.now.to_i
64
70
  start = time
65
71
  10.times {
66
- assert_nothing_raised { Puppet::Metric.load(gendata) }
67
- assert_nothing_raised { Puppet::Metric.tally }
68
- assert_nothing_raised { Puppet::Metric.store(time) }
69
- assert_nothing_raised { Puppet::Metric.clear }
72
+ rundata(report, time)
70
73
  time += 300
71
74
  }
72
- assert_nothing_raised { Puppet::Metric.load(gendata) }
73
- assert_nothing_raised { Puppet::Metric.tally }
74
- assert_nothing_raised { Puppet::Metric.store(time) }
75
- assert_nothing_raised { Puppet::Metric.graph([start,time]) }
75
+ rundata(report, time)
76
+
77
+ report.metrics.each do |n, m| m.graph end
76
78
 
77
79
  File.open(File.join(Puppet[:rrddir],"index.html"),"w") { |of|
78
80
  of.puts "<html><body>"
79
- Puppet::Metric.each { |metric|
81
+ report.metrics.each { |name, metric|
80
82
  of.puts "<img src=%s.png><br>" % metric.name
81
83
  }
82
84
  }
@@ -86,4 +88,4 @@ else
86
88
  $stderr.puts "Missing RRD library -- skipping metric tests"
87
89
  end
88
90
 
89
- # $Id: metrics.rb 965 2006-03-02 07:30:14Z luke $
91
+ # $Id: metrics.rb 1350 2006-06-30 22:30:27Z luke $
@@ -12,6 +12,7 @@ require 'test/unit'
12
12
  class TestParsedFile < Test::Unit::TestCase
13
13
  include TestPuppet
14
14
  def test_file
15
+ Puppet[:filetimeout] = 0
15
16
  file = nil
16
17
  path = tempfile()
17
18
  File.open(path, "w") { |f| f.puts "yayness" }
@@ -21,11 +22,37 @@ class TestParsedFile < Test::Unit::TestCase
21
22
 
22
23
  assert(!file.changed?, "File incorrectly returned changed")
23
24
 
24
- sleep(1)
25
+ #sleep(1)
25
26
  File.open(path, "w") { |f| f.puts "booness" }
27
+ file.send("tstamp=".intern, File.stat(path).ctime - 5)
26
28
 
27
29
  assert(file.changed?, "File did not catch change")
28
30
  end
31
+
32
+ def test_timeout
33
+ Puppet[:filetimeout] = 50
34
+ path = tempfile()
35
+
36
+ File.open(path, "w") { |f| f.puts "yay" }
37
+ file = nil
38
+ assert_nothing_raised {
39
+ file = Puppet::ParsedFile.new(path)
40
+ }
41
+
42
+ assert_nothing_raised { file.changed? }
43
+
44
+ File.open(path, "w") { |f| f.puts "yay" }
45
+ file.send("tstamp=".intern, File.stat(path).ctime - 5)
46
+
47
+ assert(!file.changed?,
48
+ "File was marked as changed too soon")
49
+
50
+ Puppet[:filetimeout] = 0
51
+ assert(file.changed?,
52
+ "File was not marked as changed soon enough")
53
+
54
+
55
+ end
29
56
  end
30
57
 
31
- # $Id: parsedfile.rb 724 2005-10-22 22:27:20Z luke $
58
+ # $Id: parsedfile.rb 1419 2006-07-21 20:11:13Z luke $
@@ -0,0 +1,79 @@
1
+ if __FILE__ == $0
2
+ $:.unshift '..'
3
+ $:.unshift '../../lib'
4
+ $puppetbase = "../.."
5
+ end
6
+
7
+ require 'puppet'
8
+ require 'puppet/parsedfile'
9
+ require 'puppettest'
10
+ require 'test/unit'
11
+
12
+ # Test the different features of the main puppet module
13
+ class TestPuppetModule < Test::Unit::TestCase
14
+ include TestPuppet
15
+ include SignalObserver
16
+
17
+ def mkfakeclient
18
+ Class.new(Puppet::Client) do
19
+ def initialize
20
+ end
21
+
22
+ def runnow
23
+ Puppet.info "fake client has run"
24
+ end
25
+ end
26
+ end
27
+
28
+ def mktestclass
29
+ Class.new do
30
+ def initialize(file)
31
+ @file = file
32
+ end
33
+
34
+ def started?
35
+ FileTest.exists?(@file)
36
+ end
37
+
38
+ def start
39
+ File.open(@file, "w") do |f| f.puts "" end
40
+ end
41
+
42
+ def shutdown
43
+ File.unlink(@file)
44
+ end
45
+ end
46
+ end
47
+
48
+ # Make sure that services get correctly started and stopped
49
+ def test_servicehandling
50
+ file = tempfile()
51
+ testclass = mktestclass()
52
+
53
+ obj = testclass.new(file)
54
+
55
+ assert_nothing_raised {
56
+ Puppet.newservice(obj)
57
+ }
58
+
59
+ assert_nothing_raised {
60
+ Puppet.start(false)
61
+ }
62
+
63
+ # Give it a sec or so
64
+ sleep 0.3
65
+
66
+ assert(obj.started?, "Object was not started")
67
+
68
+ assert_nothing_raised {
69
+ Puppet.shutdown(false)
70
+ }
71
+ # Give it a sec or so
72
+ sleep 0.3
73
+
74
+ assert(!obj.started?, "Object is still running")
75
+
76
+ end
77
+ end
78
+
79
+ # $Id: puppet.rb 1315 2006-06-27 05:15:51Z luke $
@@ -0,0 +1,106 @@
1
+ if __FILE__ == $0
2
+ $:.unshift '..'
3
+ $:.unshift '../../lib'
4
+ $puppetbase = "../.."
5
+ end
6
+
7
+ require 'puppet'
8
+ require 'puppet/transaction/report'
9
+ require 'puppettest'
10
+ require 'test/unit'
11
+
12
+ class TestReports < Test::Unit::TestCase
13
+ include TestPuppet
14
+
15
+ # Make sure we can use reports as log destinations.
16
+ def test_reports_as_log_destinations
17
+ report = nil
18
+ assert_nothing_raised {
19
+ report = Puppet::Transaction::Report.new
20
+ }
21
+
22
+ assert_nothing_raised {
23
+ Puppet::Log.newdestination(report)
24
+ }
25
+
26
+ # Now make a file for testing logging
27
+ file = Puppet::Type.newfile(:path => tempfile(), :ensure => "file")
28
+
29
+ log = nil
30
+ assert_nothing_raised {
31
+ log = file.log "This is a message, yo"
32
+ }
33
+
34
+ assert(report.logs.include?(log), "Report did not get log message")
35
+
36
+ log = Puppet.info "This is a non-sourced message"
37
+
38
+ assert(! report.logs.include?(log), "Report got log message")
39
+
40
+ assert_nothing_raised {
41
+ Puppet::Log.close(report)
42
+ }
43
+
44
+ log = file.log "This is another message, yo"
45
+
46
+ assert(! report.logs.include?(log), "Report got log message after close")
47
+ end
48
+
49
+ def test_newmetric
50
+ report = nil
51
+ assert_nothing_raised {
52
+ report = Puppet::Transaction::Report.new
53
+ }
54
+
55
+ assert_nothing_raised {
56
+ report.newmetric(:mymetric,
57
+ :total => 12,
58
+ :done => 6
59
+ )
60
+ }
61
+ end
62
+
63
+ if Puppet::Metric.haverrd?
64
+ def test_rrdgraph_report
65
+ Puppet.config.use(:metrics)
66
+ # First do some work
67
+ objects = []
68
+ 25.times do |i|
69
+ file = tempfile()
70
+
71
+ # Make every third file
72
+ File.open(file, "w") { |f| f.puts "" } if i % 3 == 0
73
+
74
+ objects << Puppet::Type.newfile(
75
+ :path => file,
76
+ :ensure => "file"
77
+ )
78
+ end
79
+
80
+ comp = newcomp(*objects)
81
+
82
+ trans = nil
83
+ assert_nothing_raised("Failed to create transaction") {
84
+ trans = comp.evaluate
85
+ }
86
+
87
+ assert_nothing_raised("Failed to evaluate transaction") {
88
+ trans.evaluate
89
+ }
90
+
91
+ method = Puppet::Server::Report.report("rrdgraph")
92
+ server = nil
93
+ assert_nothing_raised {
94
+ server = Puppet::Server::Report.new()
95
+ }
96
+
97
+ assert_nothing_raised {
98
+ server.report_rrdgraph(trans.report)
99
+ }
100
+ end
101
+ else
102
+ $stderr.puts "Install RRD for metric reporting tests"
103
+ end
104
+ end
105
+
106
+ # $Id: report.rb 1359 2006-07-04 16:27:35Z luke $
@@ -8,7 +8,7 @@ require 'puppet'
8
8
  require 'puppettest'
9
9
  require 'test/unit'
10
10
 
11
- class TestParsedFile < Test::Unit::TestCase
11
+ class TestStorage < Test::Unit::TestCase
12
12
  include TestPuppet
13
13
 
14
14
  def mkfile
@@ -97,4 +97,4 @@ class TestParsedFile < Test::Unit::TestCase
97
97
  end
98
98
  end
99
99
 
100
- # $Id: storage.rb 847 2006-01-23 22:38:39Z luke $
100
+ # $Id: storage.rb 1349 2006-06-30 20:46:07Z luke $
@@ -8,10 +8,60 @@ require 'puppet'
8
8
  require 'puppettest'
9
9
  require 'test/unit'
10
10
 
11
- # $Id: transactions.rb 1113 2006-04-17 16:15:33Z luke $
11
+ # $Id: transactions.rb 1358 2006-07-04 16:07:47Z luke $
12
12
 
13
13
  class TestTransactions < Test::Unit::TestCase
14
14
  include FileTesting
15
+
16
+ # In case they're not in more than one group
17
+ def test_nothing
18
+ end
19
+
20
+ def test_reports
21
+ path1 = tempfile()
22
+ path2 = tempfile()
23
+ objects = []
24
+ objects << Puppet::Type.newfile(
25
+ :path => path1,
26
+ :content => "yayness"
27
+ )
28
+ objects << Puppet::Type.newfile(
29
+ :path => path2,
30
+ :content => "booness"
31
+ )
32
+
33
+ trans = assert_events([:file_created, :file_created], *objects)
34
+
35
+ report = nil
36
+
37
+ assert_nothing_raised {
38
+ report = trans.report
39
+ }
40
+
41
+ # First test the report logs
42
+ assert(report.logs.length > 0, "Did not get any report logs")
43
+
44
+ report.logs.each do |obj|
45
+ assert_instance_of(Puppet::Log, obj)
46
+ end
47
+
48
+ # Then test the metrics
49
+ metrics = report.metrics
50
+
51
+ assert(metrics, "Did not get any metrics")
52
+ assert(metrics.length > 0, "Did not get any metrics")
53
+
54
+ assert(metrics.has_key?("objects"), "Did not get object metrics")
55
+ assert(metrics.has_key?("changes"), "Did not get change metrics")
56
+
57
+ metrics.each do |name, metric|
58
+ assert_instance_of(Puppet::Metric, metric)
59
+ end
60
+ end
61
+
62
+ unless %x{groups}.chomp.split(/ /).length > 1
63
+ $stderr.puts "You must be a member of more than one group to test transactions"
64
+ else
15
65
  def ingroup(gid)
16
66
  require 'etc'
17
67
  begin
@@ -182,7 +232,7 @@ class TestTransactions < Test::Unit::TestCase
182
232
  file[:mode] = "755"
183
233
  }
184
234
 
185
- trans = assert_events( [:file_changed], component)
235
+ trans = assert_events([:file_changed], component)
186
236
 
187
237
  assert(FileTest.exists?(execfile), "Execfile does not exist")
188
238
  File.unlink(execfile)
@@ -277,4 +327,80 @@ class TestTransactions < Test::Unit::TestCase
277
327
  assert(FileTest.exists?(path), "File did not get created")
278
328
  assert(FileTest.exists?(newfile), "Refresh file did not get created")
279
329
  end
330
+
331
+ # Make sure that unscheduled and untagged objects still respond to events
332
+ def test_unscheduledanduntaggedresponse
333
+ Puppet::Type.type(:schedule).mkdefaultschedules
334
+ Puppet[:ignoreschedules] = false
335
+ file = Puppet.type(:file).create(
336
+ :name => tempfile(),
337
+ :ensure => "file"
338
+ )
339
+
340
+ fname = tempfile()
341
+ exec = Puppet.type(:exec).create(
342
+ :name => "touch %s" % fname,
343
+ :path => "/usr/bin:/bin",
344
+ :schedule => "monthly",
345
+ :subscribe => ["file", file.name]
346
+ )
347
+
348
+ comp = newcomp(file,exec)
349
+ comp.finalize
350
+
351
+ # Run it once
352
+ assert_apply(comp)
353
+ assert(FileTest.exists?(fname), "File did not get created")
354
+
355
+ assert(!exec.scheduled?, "Exec is somehow scheduled")
356
+
357
+ # Now remove it, so it can get created again
358
+ File.unlink(fname)
359
+
360
+ file[:content] = "some content"
361
+
362
+ assert_events([:file_changed], comp)
363
+ assert(FileTest.exists?(fname), "File did not get recreated")
364
+
365
+ # Now remove it, so it can get created again
366
+ File.unlink(fname)
367
+
368
+ # And tag our exec
369
+ exec.tag("testrun")
370
+
371
+ # And our file, so it runs
372
+ file.tag("norun")
373
+
374
+ Puppet[:tags] = "norun"
375
+
376
+ file[:content] = "totally different content"
377
+
378
+ assert(! file.insync?, "Uh, file is in sync?")
379
+
380
+ assert_events([:file_changed], comp)
381
+ assert(FileTest.exists?(fname), "File did not get recreated")
382
+ end
383
+
384
+ def test_failed_reqs_mean_no_run
385
+ exec = Puppet::Type.type(:exec).create(
386
+ :command => "/bin/mkdir /this/path/cannot/possibly/exit",
387
+ :name => "mkdir"
388
+ )
389
+
390
+ file = Puppet::Type.type(:file).create(
391
+ :path => tempfile(),
392
+ :require => ["exec", "mkdir"],
393
+ :ensure => :file
394
+ )
395
+
396
+ comp = newcomp(exec, file)
397
+
398
+ comp.finalize
399
+
400
+ assert_apply(comp)
401
+
402
+ assert(! FileTest.exists?(file[:path]),
403
+ "File got created even tho its dependency failed")
404
+ end
405
+ end
280
406
  end