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
@@ -12,11 +12,13 @@ require 'puppet'
12
12
  require 'puppet/parser/interpreter'
13
13
  require 'puppet/parser/parser'
14
14
  require 'puppet/client'
15
+ require 'puppet/rails'
15
16
  require 'test/unit'
16
17
  require 'puppettest'
17
18
 
18
19
  class TestInterpreter < Test::Unit::TestCase
19
20
  include TestPuppet
21
+ include ServerTest
20
22
  AST = Puppet::Parser::AST
21
23
 
22
24
  # create a simple manifest that uses nodes to create a file
@@ -71,6 +73,41 @@ class TestInterpreter < Test::Unit::TestCase
71
73
  assert(config != newconfig, "Configs are somehow the same")
72
74
  end
73
75
 
76
+ if defined? ActiveRecord
77
+ def test_hoststorage
78
+ assert_nothing_raised {
79
+ Puppet[:storeconfigs] = true
80
+ }
81
+
82
+ file = tempfile()
83
+ File.open(file, "w") { |f|
84
+ f.puts "file { \"/etc\": owner => root }"
85
+ }
86
+
87
+ interp = nil
88
+ assert_nothing_raised {
89
+ interp = Puppet::Parser::Interpreter.new(
90
+ :Manifest => file,
91
+ :UseNodes => false,
92
+ :ForkSave => false
93
+ )
94
+ }
95
+
96
+ facts = {}
97
+ Facter.each { |fact, val| facts[fact] = val }
98
+
99
+ objects = nil
100
+ assert_nothing_raised {
101
+ objects = interp.run(facts["hostname"], facts)
102
+ }
103
+
104
+ obj = Puppet::Rails::Host.find_by_name(facts["hostname"])
105
+ assert(obj, "Could not find host object")
106
+ end
107
+ else
108
+ $stderr.puts "No ActiveRecord -- skipping collection tests"
109
+ end
110
+
74
111
  if Facter["domain"].value == "madstop.com"
75
112
  begin
76
113
  require 'ldap'
@@ -99,7 +136,7 @@ class TestInterpreter < Test::Unit::TestCase
99
136
  "(&(objectclass=puppetclient)(cn=%s))" % node
100
137
  ) do |entry|
101
138
  parent = entry.vals("parentnode").shift
102
- classes = entry.vals("puppetclass")
139
+ classes = entry.vals("puppetclass") || []
103
140
  end
104
141
 
105
142
  return parent, classes
@@ -107,6 +144,7 @@ class TestInterpreter < Test::Unit::TestCase
107
144
 
108
145
  def test_ldapnodes
109
146
  Puppet[:ldapbase] = "ou=hosts, dc=madstop, dc=com"
147
+ Puppet[:ldapnodes] = true
110
148
 
111
149
  ldapconnect()
112
150
  file = tempfile()
@@ -130,17 +168,33 @@ class TestInterpreter < Test::Unit::TestCase
130
168
  interp = nil
131
169
  assert_nothing_raised {
132
170
  interp = Puppet::Parser::Interpreter.new(
133
- :Manifest => file,
134
- :NodeSources => [:ldap]
171
+ :Manifest => file
135
172
  )
136
173
  }
137
174
 
175
+ parent = nil
176
+ classes = nil
177
+ # First make sure we get the default node for unknown hosts
178
+ dparent, dclasses = ldaphost("default")
179
+
180
+ assert_nothing_raised {
181
+ parent, classes = interp.nodesearch("nosuchhostokay")
182
+ }
183
+
184
+ assert_equal(dparent, parent, "Default parent node did not match")
185
+ assert_equal(dclasses, classes, "Default parent class list did not match")
186
+
187
+ # Look for a host we know doesn't have a parent
188
+ npparent, npclasses = ldaphost("noparent")
138
189
  assert_nothing_raised {
139
- interp.setup_ldap
190
+ #parent, classes = interp.nodesearch_ldap("noparent")
191
+ parent, classes = interp.nodesearch("noparent")
140
192
  }
141
193
 
142
- parent = nil
143
- classes = nil
194
+ assert_equal(npparent, parent, "Parent node did not match")
195
+ assert_equal(npclasses, classes, "Class list did not match")
196
+
197
+ # Now look for our normal host
144
198
  assert_nothing_raised {
145
199
  parent, classes = interp.nodesearch_ldap(hostname)
146
200
  }
@@ -164,8 +218,103 @@ class TestInterpreter < Test::Unit::TestCase
164
218
  assert(FileTest.exists?(cfile), "Did not make %s" % cfile)
165
219
  }
166
220
  end
221
+
222
+ if Process.uid == 0 and Facter["hostname"].value == "culain"
223
+ def test_ldapreconnect
224
+ Puppet[:ldapbase] = "ou=hosts, dc=madstop, dc=com"
225
+ Puppet[:ldapnodes] = true
226
+
227
+ interp = nil
228
+ assert_nothing_raised {
229
+ interp = Puppet::Parser::Interpreter.new(
230
+ :Manifest => mktestmanifest()
231
+ )
232
+ }
233
+ hostname = "culain.madstop.com"
234
+
235
+ # look for our host
236
+ assert_nothing_raised {
237
+ parent, classes = interp.nodesearch_ldap(hostname)
238
+ }
239
+
240
+ # Now restart ldap
241
+ system("/etc/init.d/slapd restart 2>/dev/null >/dev/null")
242
+ sleep(1)
243
+
244
+ # and look again
245
+ assert_nothing_raised {
246
+ parent, classes = interp.nodesearch_ldap(hostname)
247
+ }
248
+
249
+ # Now stop ldap
250
+ system("/etc/init.d/slapd stop 2>/dev/null >/dev/null")
251
+ cleanup do
252
+ system("/etc/init.d/slapd start 2>/dev/null >/dev/null")
253
+ end
254
+
255
+ # And make sure we actually fail here
256
+ assert_raise(Puppet::Error) {
257
+ parent, classes = interp.nodesearch_ldap(hostname)
258
+ }
259
+ end
260
+ else
261
+ $stderr.puts "Run as root for ldap reconnect tests"
262
+ end
167
263
  end
168
264
  else
169
265
  $stderr.puts "Not in madstop.com; skipping ldap tests"
170
266
  end
267
+
268
+ # Make sure searchnode behaves as we expect.
269
+ def test_nodesearch
270
+ # First create a fake nodesearch algorithm
271
+ i = 0
272
+ bucket = []
273
+ Puppet::Parser::Interpreter.send(:define_method, "nodesearch_fake") do |node|
274
+ return nil, nil if node == "default"
275
+
276
+ return bucket[0], bucket[1]
277
+ end
278
+ text = %{
279
+ node nodeparent {}
280
+ node othernodeparent {}
281
+ class nodeclass {}
282
+ class nothernode {}
283
+ }
284
+ manifest = tempfile()
285
+ File.open(manifest, "w") do |f| f.puts text end
286
+ interp = nil
287
+ assert_nothing_raised {
288
+ interp = Puppet::Parser::Interpreter.new(
289
+ :Manifest => manifest,
290
+ :NodeSources => [:fake]
291
+ )
292
+ }
293
+ # Make sure it behaves correctly for all forms
294
+ [[nil, nil],
295
+ ["nodeparent", nil],
296
+ [nil, ["nodeclass"]],
297
+ [nil, ["nodeclass", "nothernode"]],
298
+ ["othernodeparent", ["nodeclass", "nothernode"]],].each do |ary|
299
+ # Set the return values
300
+ bucket = ary
301
+
302
+ # Look them back up
303
+ parent, classes = interp.nodesearch("mynode")
304
+
305
+ # Basically, just make sure that if we have either or both,
306
+ # we get a result back.
307
+ assert_equal(ary[0], parent,
308
+ "Parent is not %s" % parent)
309
+ assert_equal(ary[1], classes,
310
+ "Parent is not %s" % parent)
311
+
312
+ next if ary == [nil, nil]
313
+ # Now make sure we actually get the configuration. This will throw
314
+ # an exception if we don't.
315
+ assert_nothing_raised do
316
+ interp.run("mynode", {})
317
+ end
318
+ end
319
+ end
171
320
  end
@@ -69,7 +69,6 @@ class TestLexer < Test::Unit::TestCase
69
69
  def test_errors
70
70
  strings = %w{
71
71
  ^
72
- @
73
72
  }
74
73
  strings.each { |str|
75
74
  @lexer.string = str
@@ -122,7 +121,41 @@ class TestLexer < Test::Unit::TestCase
122
121
  assert_nothing_raised {
123
122
  @lexer.string = bit
124
123
  }
124
+
125
+ assert_nothing_raised {
126
+ @lexer.fullscan
127
+ }
128
+ end
129
+
130
+ def test_collectlexing
131
+ {"@" => :AT, "<|" => :LCOLLECT, "|>" => :RCOLLECT}.each do |string, token|
132
+ assert_nothing_raised {
133
+ @lexer.string = string
134
+ }
135
+
136
+ ret = nil
137
+ assert_nothing_raised {
138
+ ret = @lexer.fullscan
139
+ }
140
+
141
+ assert_equal([[token, string],[false, false]], ret)
142
+ end
143
+ end
144
+
145
+ def test_collectabletype
146
+ string = "@type {"
147
+
148
+ assert_nothing_raised {
149
+ @lexer.string = string
150
+ }
151
+
152
+ ret = nil
153
+ assert_nothing_raised {
154
+ ret = @lexer.fullscan
155
+ }
156
+
157
+ assert_equal([[:AT, "@"], [:NAME, "type"], [:LBRACE, "{"], [false,false]],ret)
125
158
  end
126
159
  end
127
160
 
128
- # $Id: lexer.rb 1070 2006-04-04 23:30:56Z luke $
161
+ # $Id: lexer.rb 1189 2006-05-13 18:27:22Z luke $
@@ -49,7 +49,7 @@ class TestParser < Test::Unit::TestCase
49
49
  hostnames = [ hostnames ]
50
50
  end
51
51
  assert_nothing_raised {
52
- @parser.string = "node #{hostnames.join(" ")} { }"
52
+ @parser.string = "node #{hostnames.join(", ")} { }"
53
53
  }
54
54
  # Strip quotes
55
55
  hostnames.map! { |s| s.sub(/^'(.*)'$/, "\\1") }
@@ -81,4 +81,51 @@ class TestParser < Test::Unit::TestCase
81
81
  @parser.parse
82
82
  }
83
83
  end
84
+
85
+ # Make sure we can find default nodes if there's no other entry
86
+ def test_default_node
87
+ Puppet[:parseonly] = false
88
+ @parser = Puppet::Parser::Parser.new()
89
+
90
+ fileA = tempfile()
91
+ fileB = tempfile()
92
+ @parser.string = %{
93
+ node mynode {
94
+ file { "#{fileA}": ensure => file }
95
+ }
96
+
97
+ node default {
98
+ file { "#{fileB}": ensure => file }
99
+ }
100
+ }
101
+
102
+ # First make sure it parses
103
+ ast = nil
104
+ assert_nothing_raised {
105
+ ast = @parser.parse
106
+ }
107
+
108
+ args = {
109
+ :ast => ast,
110
+ :facts => {},
111
+ :names => ["mynode"]
112
+ }
113
+ # Make sure we get a config for "mynode"
114
+
115
+ trans = nil
116
+ assert_nothing_raised {
117
+ trans = Puppet::Parser::Scope.new.evaluate(args)
118
+ }
119
+
120
+ assert(trans, "Did not get config for mynode")
121
+
122
+ args[:names] = ["othernode"]
123
+ # Now make sure the default node is used
124
+ trans = nil
125
+ assert_nothing_raised {
126
+ trans = Puppet::Parser::Scope.new.evaluate(args)
127
+ }
128
+
129
+ assert(trans, "Did not get config for default node")
130
+ end
84
131
  end
@@ -207,6 +207,255 @@ class TestParser < Test::Unit::TestCase
207
207
  parser.parse
208
208
  }
209
209
  end
210
+
211
+ def test_importedclasses
212
+ imported = tempfile()
213
+ importer = tempfile()
214
+
215
+ made = tempfile()
216
+
217
+ File.open(imported, "w") do |f|
218
+ f.puts %{class foo { file { "#{made}": ensure => file }}}
219
+ end
220
+
221
+ File.open(importer, "w") do |f|
222
+ f.puts %{import "#{imported}"\ninclude foo}
223
+ end
224
+
225
+ parser = Puppet::Parser::Parser.new
226
+ parser.file = importer
227
+
228
+ # Make sure it parses fine
229
+ assert_nothing_raised {
230
+ parser.parse
231
+ }
232
+
233
+ # Now make sure it actually does the work
234
+ assert_creates(importer, made)
235
+ end
236
+
237
+ # Make sure fully qualified and unqualified files can be imported
238
+ def test_fqfilesandlocalfiles
239
+ dir = tempfile()
240
+ Dir.mkdir(dir)
241
+ importer = File.join(dir, "site.pp")
242
+ fullfile = File.join(dir, "full.pp")
243
+ localfile = File.join(dir, "local.pp")
244
+
245
+ files = []
246
+
247
+ File.open(importer, "w") do |f|
248
+ f.puts %{import "#{fullfile}"\ninclude full\nimport "local.pp"\ninclude local}
249
+ end
250
+
251
+ file = tempfile()
252
+ files << file
253
+
254
+ File.open(fullfile, "w") do |f|
255
+ f.puts %{class full { file { "#{file}": ensure => file }}}
256
+ end
257
+
258
+ file = tempfile()
259
+ files << file
260
+
261
+ File.open(localfile, "w") do |f|
262
+ f.puts %{class local { file { "#{file}": ensure => file }}}
263
+ end
264
+
265
+ parser = Puppet::Parser::Parser.new
266
+ parser.file = importer
267
+
268
+ # Make sure it parses
269
+ assert_nothing_raised {
270
+ parser.parse
271
+ }
272
+
273
+ # Now make sure it actually does the work
274
+ assert_creates(importer, *files)
275
+ end
276
+
277
+ # Make sure the parser adds '.pp' when necessary
278
+ def test_addingpp
279
+ dir = tempfile()
280
+ Dir.mkdir(dir)
281
+ importer = File.join(dir, "site.pp")
282
+ localfile = File.join(dir, "local.pp")
283
+
284
+ files = []
285
+
286
+ File.open(importer, "w") do |f|
287
+ f.puts %{import "local"\ninclude local}
288
+ end
289
+
290
+ file = tempfile()
291
+ files << file
292
+
293
+ File.open(localfile, "w") do |f|
294
+ f.puts %{class local { file { "#{file}": ensure => file }}}
295
+ end
296
+
297
+ parser = Puppet::Parser::Parser.new
298
+ parser.file = importer
299
+
300
+ assert_nothing_raised {
301
+ parser.parse
302
+ }
303
+ end
304
+
305
+ # Make sure that file importing changes file relative names.
306
+ def test_changingrelativenames
307
+ dir = tempfile()
308
+ Dir.mkdir(dir)
309
+ Dir.mkdir(File.join(dir, "subdir"))
310
+ top = File.join(dir, "site.pp")
311
+ subone = File.join(dir, "subdir/subone")
312
+ subtwo = File.join(dir, "subdir/subtwo")
313
+
314
+ files = []
315
+ file = tempfile()
316
+ files << file
317
+
318
+ File.open(subone + ".pp", "w") do |f|
319
+ f.puts %{class one { file { "#{file}": ensure => file }}}
320
+ end
321
+
322
+ otherfile = tempfile()
323
+ files << otherfile
324
+ File.open(subtwo + ".pp", "w") do |f|
325
+ f.puts %{import "subone"\n class two inherits one {
326
+ file { "#{otherfile}": ensure => file }
327
+ }}
328
+ end
329
+
330
+ File.open(top, "w") do |f|
331
+ f.puts %{import "subdir/subtwo"}
332
+ end
333
+
334
+ parser = Puppet::Parser::Parser.new
335
+ parser.file = top
336
+
337
+ assert_nothing_raised {
338
+ parser.parse
339
+ }
340
+ end
341
+
342
+ # Verify that collectable objects are marked that way.
343
+ def test_collectable
344
+ Puppet[:storeconfigs] = true
345
+ ["@port { ssh: protocols => tcp, number => 22 }",
346
+ "@port { ssh: protocols => tcp, number => 22;
347
+ smtp: protocols => tcp, number => 25 }"].each do |text|
348
+ parser = Puppet::Parser::Parser.new
349
+ parser.string = text
350
+
351
+ ret = nil
352
+ assert_nothing_raised {
353
+ ret = parser.parse
354
+ }
355
+
356
+ assert_instance_of(AST::ASTArray, ret)
357
+
358
+ ret.each do |obj|
359
+ assert_instance_of(AST::ObjectDef, obj)
360
+ assert(obj.collectable, "Object was not marked collectable")
361
+ end
362
+ end
363
+ end
364
+
365
+ # Defaults are purely syntactical, so it doesn't make sense to be able to
366
+ # collect them.
367
+ def test_uncollectabledefaults
368
+ string = "@Port { protocols => tcp }"
369
+ parser = Puppet::Parser::Parser.new
370
+ parser.string = string
371
+
372
+ assert_raise(Puppet::ParseError) {
373
+ parser.parse
374
+ }
375
+ end
376
+
377
+ # Verify that we can parse collections
378
+ def test_collecting
379
+ Puppet[:storeconfigs] = true
380
+ text = "port <| |>"
381
+ parser = Puppet::Parser::Parser.new
382
+ parser.string = text
383
+
384
+ ret = nil
385
+ assert_nothing_raised {
386
+ ret = parser.parse
387
+ }
388
+
389
+ assert_instance_of(AST::ASTArray, ret)
390
+
391
+ ret.each do |obj|
392
+ assert_instance_of(AST::Collection, obj)
393
+ end
394
+ end
395
+
396
+ def test_emptyfile
397
+ file = tempfile()
398
+ File.open(file, "w") do |f|
399
+ f.puts %{}
400
+ end
401
+ parser = Puppet::Parser::Parser.new
402
+ parser.file = file
403
+ assert_nothing_raised {
404
+ parser.parse
405
+ }
406
+ end
407
+
408
+ def test_multiple_nodes_named
409
+ file = tempfile()
410
+ other = tempfile()
411
+
412
+ File.open(file, "w") do |f|
413
+ f.puts %{
414
+ node nodeA, nodeB {
415
+ file { "#{other}": ensure => file }
416
+
417
+ }
418
+ }
419
+ end
420
+
421
+ parser = Puppet::Parser::Parser.new
422
+ parser.file = file
423
+ ast = nil
424
+ assert_nothing_raised {
425
+ ast = parser.parse
426
+ }
427
+ end
428
+
429
+ def test_emptyarrays
430
+ str = %{$var = []\n}
431
+
432
+ parser = Puppet::Parser::Parser.new
433
+ parser.string = str
434
+
435
+ # Make sure it parses fine
436
+ assert_nothing_raised {
437
+ parser.parse
438
+ }
439
+ end
440
+
441
+ # Make sure function names aren't reserved words.
442
+ def test_functionnamecollision
443
+ str = %{tag yayness
444
+ tag(rahness)
445
+
446
+ file { "/tmp/yayness":
447
+ tag => "rahness",
448
+ ensure => exists
449
+ }
450
+ }
451
+ parser = Puppet::Parser::Parser.new
452
+ parser.string = str
453
+
454
+ # Make sure it parses fine
455
+ assert_nothing_raised {
456
+ parser.parse
457
+ }
458
+ end
210
459
  end
211
460
 
212
- # $Id: parser.rb 1070 2006-04-04 23:30:56Z luke $
461
+ # $Id: parser.rb 1245 2006-06-08 20:06:41Z luke $