puppet 0.9.2 → 0.13.0

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 (213) hide show
  1. data/CHANGELOG +58 -0
  2. data/README +21 -18
  3. data/Rakefile +176 -36
  4. data/bin/puppet +34 -48
  5. data/bin/puppetca +41 -28
  6. data/bin/puppetd +87 -65
  7. data/bin/puppetdoc +99 -23
  8. data/bin/puppetmasterd +72 -91
  9. data/conf/redhat/client.init +80 -0
  10. data/conf/redhat/client.sysconfig +11 -0
  11. data/conf/redhat/fileserver.conf +12 -0
  12. data/conf/redhat/puppet.spec +130 -0
  13. data/conf/redhat/server.init +89 -0
  14. data/conf/redhat/server.sysconfig +9 -0
  15. data/examples/code/allatonce +2 -2
  16. data/examples/code/assignments +1 -1
  17. data/examples/code/classing +2 -2
  18. data/examples/code/components +2 -2
  19. data/examples/code/file.bl +5 -5
  20. data/examples/code/filedefaults +2 -2
  21. data/examples/code/fileparsing +1 -1
  22. data/examples/code/filerecursion +1 -1
  23. data/examples/code/functions +1 -1
  24. data/examples/code/groups +1 -1
  25. data/examples/code/importing +1 -1
  26. data/examples/code/nodes +1 -1
  27. data/examples/code/one +1 -1
  28. data/examples/code/relationships +2 -2
  29. data/examples/code/simpletests +5 -5
  30. data/examples/code/snippets/argumentdefaults +2 -2
  31. data/examples/code/snippets/casestatement +16 -8
  32. data/examples/code/snippets/classheirarchy.pp +4 -4
  33. data/examples/code/snippets/classincludes.pp +4 -4
  34. data/examples/code/snippets/classpathtest +2 -2
  35. data/examples/code/snippets/componentmetaparams.pp +11 -0
  36. data/examples/code/snippets/dirchmod +5 -5
  37. data/examples/code/snippets/emptyclass.pp +9 -0
  38. data/examples/code/snippets/failmissingexecpath.pp +1 -1
  39. data/examples/code/snippets/falsevalues.pp +1 -1
  40. data/examples/code/snippets/filecreate +5 -5
  41. data/examples/code/snippets/implicititeration +5 -5
  42. data/examples/code/snippets/multipleinstances +4 -4
  43. data/examples/code/snippets/namevartest +3 -3
  44. data/examples/code/snippets/scopetest +1 -1
  45. data/examples/code/snippets/selectorvalues.pp +3 -3
  46. data/examples/code/snippets/simpledefaults +2 -2
  47. data/examples/code/snippets/simpleselector +5 -5
  48. data/examples/code/snippets/singleary.pp +19 -0
  49. data/examples/root/etc/init.d/sleeper +3 -2
  50. data/ext/emacs/puppet-mode-init.el +6 -0
  51. data/ext/emacs/puppet-mode.el +189 -0
  52. data/ext/ldap/puppet.schema +17 -0
  53. data/ext/{module:puppet → module_puppet} +30 -31
  54. data/ext/vim/filetype.vim +9 -0
  55. data/ext/vim/puppet.vim +87 -0
  56. data/install.rb +63 -30
  57. data/lib/puppet.rb +216 -122
  58. data/lib/puppet/client.rb +51 -416
  59. data/lib/puppet/client/ca.rb +17 -0
  60. data/lib/puppet/client/dipper.rb +78 -0
  61. data/lib/puppet/client/file.rb +20 -0
  62. data/lib/puppet/client/log.rb +17 -0
  63. data/lib/puppet/client/master.rb +246 -0
  64. data/lib/puppet/client/proxy.rb +27 -0
  65. data/lib/puppet/client/status.rb +7 -0
  66. data/lib/puppet/config.rb +563 -13
  67. data/lib/puppet/daemon.rb +50 -22
  68. data/lib/puppet/element.rb +4 -4
  69. data/lib/puppet/event-loop.rb +1 -0
  70. data/lib/puppet/event-loop/better-definers.rb +367 -0
  71. data/lib/puppet/event-loop/event-loop.rb +355 -0
  72. data/lib/puppet/event-loop/signal-system.rb +220 -0
  73. data/lib/puppet/event.rb +9 -11
  74. data/lib/puppet/filetype.rb +195 -0
  75. data/lib/puppet/log.rb +35 -12
  76. data/lib/puppet/metric.rb +2 -2
  77. data/lib/puppet/networkclient.rb +145 -0
  78. data/lib/puppet/parameter.rb +335 -0
  79. data/lib/puppet/parser/ast.rb +42 -1453
  80. data/lib/puppet/parser/ast/astarray.rb +88 -0
  81. data/lib/puppet/parser/ast/branch.rb +47 -0
  82. data/lib/puppet/parser/ast/caseopt.rb +66 -0
  83. data/lib/puppet/parser/ast/casestatement.rb +78 -0
  84. data/lib/puppet/parser/ast/classdef.rb +78 -0
  85. data/lib/puppet/parser/ast/compdef.rb +111 -0
  86. data/lib/puppet/parser/ast/component.rb +105 -0
  87. data/lib/puppet/parser/ast/hostclass.rb +82 -0
  88. data/lib/puppet/parser/ast/leaf.rb +86 -0
  89. data/lib/puppet/parser/ast/node.rb +103 -0
  90. data/lib/puppet/parser/ast/nodedef.rb +68 -0
  91. data/lib/puppet/parser/ast/objectdef.rb +336 -0
  92. data/lib/puppet/parser/ast/objectparam.rb +30 -0
  93. data/lib/puppet/parser/ast/objectref.rb +76 -0
  94. data/lib/puppet/parser/ast/selector.rb +60 -0
  95. data/lib/puppet/parser/ast/typedefaults.rb +45 -0
  96. data/lib/puppet/parser/ast/vardef.rb +44 -0
  97. data/lib/puppet/parser/interpreter.rb +31 -14
  98. data/lib/puppet/parser/lexer.rb +2 -4
  99. data/lib/puppet/parser/parser.rb +332 -242
  100. data/lib/puppet/parser/scope.rb +55 -38
  101. data/lib/puppet/server.rb +43 -44
  102. data/lib/puppet/server/authstore.rb +3 -6
  103. data/lib/puppet/server/ca.rb +5 -2
  104. data/lib/puppet/server/filebucket.rb +2 -4
  105. data/lib/puppet/server/fileserver.rb +28 -12
  106. data/lib/puppet/server/logger.rb +15 -4
  107. data/lib/puppet/server/master.rb +62 -7
  108. data/lib/puppet/sslcertificates.rb +41 -607
  109. data/lib/puppet/sslcertificates/ca.rb +291 -0
  110. data/lib/puppet/sslcertificates/certificate.rb +283 -0
  111. data/lib/puppet/statechange.rb +6 -1
  112. data/lib/puppet/storage.rb +67 -56
  113. data/lib/puppet/transaction.rb +25 -9
  114. data/lib/puppet/transportable.rb +102 -22
  115. data/lib/puppet/type.rb +1096 -315
  116. data/lib/puppet/type/component.rb +30 -21
  117. data/lib/puppet/type/cron.rb +409 -448
  118. data/lib/puppet/type/exec.rb +234 -174
  119. data/lib/puppet/type/group.rb +65 -82
  120. data/lib/puppet/type/nameservice.rb +247 -3
  121. data/lib/puppet/type/nameservice/netinfo.rb +29 -40
  122. data/lib/puppet/type/nameservice/objectadd.rb +52 -66
  123. data/lib/puppet/type/nameservice/posix.rb +6 -194
  124. data/lib/puppet/type/package.rb +447 -295
  125. data/lib/puppet/type/package/apt.rb +51 -50
  126. data/lib/puppet/type/package/bsd.rb +82 -0
  127. data/lib/puppet/type/package/dpkg.rb +85 -88
  128. data/lib/puppet/type/package/rpm.rb +67 -63
  129. data/lib/puppet/type/package/sun.rb +119 -98
  130. data/lib/puppet/type/package/yum.rb +41 -37
  131. data/lib/puppet/type/parsedtype.rb +295 -0
  132. data/lib/puppet/type/parsedtype/host.rb +143 -0
  133. data/lib/puppet/type/parsedtype/port.rb +232 -0
  134. data/lib/puppet/type/parsedtype/sshkey.rb +129 -0
  135. data/lib/puppet/type/pfile.rb +484 -460
  136. data/lib/puppet/type/pfile/checksum.rb +237 -181
  137. data/lib/puppet/type/pfile/content.rb +67 -0
  138. data/lib/puppet/type/pfile/ensure.rb +212 -0
  139. data/lib/puppet/type/pfile/group.rb +106 -105
  140. data/lib/puppet/type/pfile/mode.rb +98 -101
  141. data/lib/puppet/type/pfile/source.rb +228 -209
  142. data/lib/puppet/type/pfile/type.rb +18 -21
  143. data/lib/puppet/type/pfile/uid.rb +127 -130
  144. data/lib/puppet/type/pfilebucket.rb +68 -63
  145. data/lib/puppet/type/schedule.rb +341 -0
  146. data/lib/puppet/type/service.rb +351 -255
  147. data/lib/puppet/type/service/base.rb +9 -14
  148. data/lib/puppet/type/service/debian.rb +32 -38
  149. data/lib/puppet/type/service/init.rb +130 -130
  150. data/lib/puppet/type/service/smf.rb +48 -20
  151. data/lib/puppet/type/state.rb +229 -16
  152. data/lib/puppet/type/symlink.rb +51 -63
  153. data/lib/puppet/type/tidy.rb +105 -102
  154. data/lib/puppet/type/user.rb +118 -180
  155. data/lib/puppet/util.rb +100 -6
  156. data/test/certmgr/certmgr.rb +0 -1
  157. data/test/client/client.rb +4 -4
  158. data/test/executables/puppetbin.rb +7 -14
  159. data/test/executables/puppetca.rb +18 -24
  160. data/test/executables/puppetd.rb +7 -16
  161. data/test/executables/puppetmasterd.rb +7 -9
  162. data/test/executables/puppetmodule.rb +11 -16
  163. data/test/language/ast.rb +11 -7
  164. data/test/language/interpreter.rb +1 -1
  165. data/test/language/scope.rb +2 -0
  166. data/test/language/snippets.rb +30 -5
  167. data/test/language/transportable.rb +77 -0
  168. data/test/other/config.rb +316 -0
  169. data/test/other/events.rb +22 -21
  170. data/test/other/log.rb +14 -14
  171. data/test/other/metrics.rb +4 -8
  172. data/test/other/overrides.rb +5 -5
  173. data/test/other/relationships.rb +4 -2
  174. data/test/other/storage.rb +64 -3
  175. data/test/other/transactions.rb +20 -20
  176. data/test/parser/parser.rb +7 -4
  177. data/test/puppet/conffiles.rb +12 -12
  178. data/test/puppet/defaults.rb +13 -11
  179. data/test/puppet/utiltest.rb +14 -11
  180. data/test/puppettest.rb +156 -48
  181. data/test/server/bucket.rb +2 -2
  182. data/test/server/fileserver.rb +6 -6
  183. data/test/server/logger.rb +19 -11
  184. data/test/server/master.rb +33 -4
  185. data/test/server/server.rb +2 -7
  186. data/test/types/basic.rb +5 -7
  187. data/test/types/component.rb +22 -18
  188. data/test/types/cron.rb +111 -44
  189. data/test/types/exec.rb +116 -59
  190. data/test/types/file.rb +262 -137
  191. data/test/types/filebucket.rb +13 -15
  192. data/test/types/fileignoresource.rb +12 -16
  193. data/test/types/filesources.rb +73 -48
  194. data/test/types/filetype.rb +13 -15
  195. data/test/types/group.rb +15 -13
  196. data/test/types/host.rb +146 -0
  197. data/test/types/package.rb +74 -63
  198. data/test/types/port.rb +139 -0
  199. data/test/types/query.rb +8 -8
  200. data/test/types/schedule.rb +335 -0
  201. data/test/types/service.rb +137 -21
  202. data/test/types/sshkey.rb +140 -0
  203. data/test/types/symlink.rb +3 -5
  204. data/test/types/tidy.rb +5 -14
  205. data/test/types/type.rb +67 -11
  206. data/test/types/user.rb +25 -23
  207. metadata +186 -122
  208. data/lib/puppet/type/pfile/create.rb +0 -108
  209. data/lib/puppet/type/pprocess.rb +0 -97
  210. data/lib/puppet/type/typegen.rb +0 -149
  211. data/lib/puppet/type/typegen/filerecord.rb +0 -243
  212. data/lib/puppet/type/typegen/filetype.rb +0 -316
  213. data/test/other/state.rb +0 -106
@@ -8,11 +8,18 @@ end
8
8
 
9
9
  require 'puppettest'
10
10
  require 'puppet'
11
- require 'puppet/type/cron'
12
11
  require 'test/unit'
13
12
  require 'facter'
14
13
 
15
- class TestExec < Test::Unit::TestCase
14
+
15
+ # Here we just want to unit-test our cron type, to verify that
16
+ #class TestCronType < Test::Unit::TestCase
17
+ # include TestPuppet
18
+ #
19
+ #
20
+ #end
21
+
22
+ class TestCron < Test::Unit::TestCase
16
23
  include TestPuppet
17
24
  def setup
18
25
  super
@@ -26,15 +33,24 @@ class TestExec < Test::Unit::TestCase
26
33
  unless defined? @me
27
34
  raise "Could not retrieve user name; 'id' did not work"
28
35
  end
36
+
29
37
  # god i'm lazy
30
- @crontype = Puppet::Type::Cron
38
+ @crontype = Puppet.type(:cron)
39
+ @oldfiletype = @crontype.filetype
40
+ @fakefiletype = Puppet::FileType.filetype(:ram)
41
+ @crontype.filetype = @fakefiletype
42
+ end
43
+
44
+ def teardown
45
+ @crontype.filetype = @oldfiletype
46
+ super
31
47
  end
32
48
 
33
49
  # Back up the user's existing cron tab if they have one.
34
50
  def cronback
35
51
  tab = nil
36
52
  assert_nothing_raised {
37
- tab = Puppet::Type::Cron.crontype.read(@me)
53
+ tab = Puppet.type(:cron).filetype.read(@me)
38
54
  }
39
55
 
40
56
  if $? == 0
@@ -48,9 +64,9 @@ class TestExec < Test::Unit::TestCase
48
64
  def cronrestore
49
65
  assert_nothing_raised {
50
66
  if @currenttab
51
- @crontype.crontype.write(@me, @currenttab)
67
+ @crontype.filetype.new(@me).write(@currenttab)
52
68
  else
53
- @crontype.crontype.remove(@me)
69
+ @crontype.filetype.new(@me).remove
54
70
  end
55
71
  }
56
72
  end
@@ -78,17 +94,21 @@ class TestExec < Test::Unit::TestCase
78
94
  name = cron.name
79
95
  comp = newcomp(name, cron)
80
96
 
81
- trans = assert_events(comp, [:cron_created], name)
97
+ assert_events([:cron_created], comp)
98
+ cron.retrieve
99
+
100
+ assert(cron.insync?)
101
+
102
+ assert_events([], comp)
103
+
104
+ cron[:ensure] = :absent
105
+
106
+ assert_events([:cron_removed], comp)
107
+
82
108
  cron.retrieve
109
+
83
110
  assert(cron.insync?)
84
- trans = assert_events(comp, [], name)
85
- cron[:command] = :notfound
86
- trans = assert_events(comp, [:cron_deleted], name)
87
- # the cron should no longer exist, not even in the comp
88
- trans = assert_events(comp, [], name)
89
-
90
- assert(!comp.include?(cron),
91
- "Cron is still a member of comp, after being deleted")
111
+ assert_events([], comp)
92
112
  end
93
113
 
94
114
  # A simple test to see if we can load the cron from disk.
@@ -107,18 +127,66 @@ class TestExec < Test::Unit::TestCase
107
127
  assert_nothing_raised {
108
128
  cron = @crontype.create(
109
129
  :name => name,
110
- :command => "date",
130
+ :command => "date > /dev/null",
111
131
  :user => @me
112
132
  )
113
133
  }
114
134
  str = nil
115
135
  # generate the text
116
136
  assert_nothing_raised {
117
- str = cron.to_cron
137
+ str = cron.to_record
118
138
  }
119
- assert_equal(str, "# Puppet Name: #{name}\n* * * * * date",
139
+
140
+ assert_equal(str, "# Puppet Name: #{name}\n* * * * * date > /dev/null",
120
141
  "Cron did not generate correctly")
121
142
  end
143
+
144
+ # Test that changing any field results in the cron tab being rewritten.
145
+ # it directly
146
+ def test_any_field_changes
147
+ cron = nil
148
+ # make the cron
149
+ name = "yaytest"
150
+ assert_nothing_raised {
151
+ cron = @crontype.create(
152
+ :name => name,
153
+ :command => "date > /dev/null",
154
+ :month => "May",
155
+ :user => @me
156
+ )
157
+ }
158
+ assert(cron, "Cron did not get created")
159
+ comp = newcomp(cron)
160
+ assert_events([:cron_created], comp)
161
+
162
+ assert_nothing_raised {
163
+ cron[:month] = "June"
164
+ }
165
+
166
+ cron.retrieve
167
+
168
+ assert_events([:cron_changed], comp)
169
+ end
170
+
171
+ # Test that a cron job with spaces at the end doesn't get rewritten
172
+ def test_trailingspaces
173
+ cron = nil
174
+ # make the cron
175
+ name = "yaytest"
176
+ assert_nothing_raised {
177
+ cron = @crontype.create(
178
+ :name => name,
179
+ :command => "date > /dev/null ",
180
+ :month => "May",
181
+ :user => @me
182
+ )
183
+ }
184
+ comp = newcomp(cron)
185
+
186
+ assert_events([:cron_created], comp, "did not create cron job")
187
+ cron.retrieve
188
+ assert_events([], comp, "cron job got rewritten")
189
+ end
122
190
 
123
191
  # Test that comments are correctly retained
124
192
  def test_retain_comments
@@ -130,7 +198,7 @@ class TestExec < Test::Unit::TestCase
130
198
 
131
199
  assert_nothing_raised {
132
200
  newstr = @crontype.tab(user)
133
- assert_equal(str, newstr, "Cron comments were changed or lost")
201
+ assert(newstr.include?(str), "Comments were lost")
134
202
  }
135
203
  end
136
204
 
@@ -156,62 +224,59 @@ class TestExec < Test::Unit::TestCase
156
224
 
157
225
  assert_nothing_raised {
158
226
  newstr = @crontype.tab(@me)
159
- assert_equal(modstr, newstr, "Cron was not correctly matched")
227
+ assert(newstr.include?(modstr),
228
+ "Cron was not correctly matched")
160
229
  }
161
230
  end
162
231
 
163
232
  # Test adding a cron when there is currently no file.
164
233
  def test_mkcronwithnotab
165
- cronback
166
- Puppet::Type::Cron.crontype.remove(@me)
234
+ tab = @fakefiletype.new(@me)
235
+ tab.remove
167
236
 
168
237
  cron = mkcron("testwithnotab")
169
238
  cyclecron(cron)
170
- cronrestore
171
239
  end
172
240
 
173
241
  def test_mkcronwithtab
174
- cronback
175
- Puppet::Type::Cron.crontype.remove(@me)
176
- Puppet::Type::Cron.crontype.write(@me,
177
- "1 1 1 1 * date > %s/crontesting\n" % testdir()
242
+ tab = @fakefiletype.new(@me)
243
+ tab.remove
244
+ tab.write(
245
+ "1 1 1 1 * date > %s/crontesting\n" % tstdir()
178
246
  )
179
247
 
180
248
  cron = mkcron("testwithtab")
181
249
  cyclecron(cron)
182
- cronrestore
183
250
  end
184
251
 
185
252
  def test_makeandretrievecron
186
- cronback
187
- Puppet::Type::Cron.crontype.remove(@me)
253
+ tab = @fakefiletype.new(@me)
254
+ tab.remove
188
255
 
189
256
  name = "storeandretrieve"
190
257
  cron = mkcron(name)
191
258
  comp = newcomp(name, cron)
192
- trans = assert_events(comp, [:cron_created], name)
259
+ trans = assert_events([:cron_created], comp, name)
193
260
 
194
261
  cron = nil
195
262
 
196
- Puppet::Type::Cron.clear
197
- Puppet::Type::Cron.retrieve(@me)
263
+ Puppet.type(:cron).retrieve(@me)
198
264
 
199
- assert(cron = Puppet::Type::Cron[name], "Could not retrieve named cron")
200
- assert_instance_of(Puppet::Type::Cron, cron)
201
- cronrestore
265
+ assert(cron = Puppet.type(:cron)[name], "Could not retrieve named cron")
266
+ assert_instance_of(Puppet.type(:cron), cron)
202
267
  end
203
268
 
204
269
  # Do input validation testing on all of the parameters.
205
270
  def test_arguments
206
271
  values = {
207
272
  :monthday => {
208
- :valid => [ 1, 13, "1,30" ],
273
+ :valid => [ 1, 13, "1" ],
209
274
  :invalid => [ -1, 0, 32 ]
210
275
  },
211
276
  :weekday => {
212
- :valid => [ 0, 3, 6, "1,2", "tue", "wed",
277
+ :valid => [ 0, 3, 6, "1", "tue", "wed",
213
278
  "Wed", "MOnday", "SaTurday" ],
214
- :invalid => [ -1, 7, "1, 3", "tues", "teusday", "thurs" ]
279
+ :invalid => [ -1, 7, "13", "tues", "teusday", "thurs" ]
215
280
  },
216
281
  :hour => {
217
282
  :valid => [ 0, 21, 23 ],
@@ -223,14 +288,16 @@ class TestExec < Test::Unit::TestCase
223
288
  },
224
289
  :month => {
225
290
  :valid => [ 1, 11, 12, "mar", "March", "apr", "October", "DeCeMbEr" ],
226
- :invalid => [ 0, 13, "marc", "sept" ]
291
+ :invalid => [ -1, 0, 13, "marc", "sept" ]
227
292
  }
228
293
  }
229
294
 
230
295
  cron = mkcron("valtesting")
231
296
  values.each { |param, hash|
232
- hash.each { |type, values|
233
- values.each { |value|
297
+ # We have to test the valid ones first, because otherwise the
298
+ # state will fail to create at all.
299
+ [:valid, :invalid].each { |type|
300
+ hash[type].each { |value|
234
301
  case type
235
302
  when :valid:
236
303
  assert_nothing_raised {
@@ -238,7 +305,7 @@ class TestExec < Test::Unit::TestCase
238
305
  }
239
306
 
240
307
  if value.is_a?(Integer)
241
- assert_equal([value], cron[param],
308
+ assert_equal(value.to_s, cron.should(param),
242
309
  "Cron value was not set correctly")
243
310
  end
244
311
  when :invalid:
@@ -258,4 +325,4 @@ class TestExec < Test::Unit::TestCase
258
325
  end
259
326
  end
260
327
 
261
- # $Id: cron.rb 742 2005-11-16 17:12:11Z luke $
328
+ # $Id: cron.rb 831 2006-01-16 20:01:20Z luke $
@@ -9,7 +9,7 @@ require 'puppettest'
9
9
  require 'test/unit'
10
10
  require 'facter'
11
11
 
12
- # $Id: exec.rb 742 2005-11-16 17:12:11Z luke $
12
+ # $Id: exec.rb 832 2006-01-17 07:11:50Z luke $
13
13
 
14
14
  class TestExec < Test::Unit::TestCase
15
15
  include TestPuppet
@@ -17,46 +17,29 @@ class TestExec < Test::Unit::TestCase
17
17
  command = nil
18
18
  output = nil
19
19
  assert_nothing_raised {
20
- command = Puppet::Type::Exec.create(
20
+ command = Puppet.type(:exec).create(
21
21
  :command => "/bin/echo"
22
22
  )
23
23
  }
24
24
  assert_nothing_raised {
25
25
  command.evaluate
26
26
  }
27
- assert_nothing_raised {
28
- output = command.sync
29
- }
30
- assert_equal([:executed_command],output)
27
+ assert_events([:executed_command], command)
31
28
  end
32
29
 
33
30
  def test_numvsstring
34
- command = nil
35
- output = nil
36
- assert_nothing_raised {
37
- command = Puppet::Type::Exec.create(
38
- :command => "/bin/echo",
39
- :returns => 0
40
- )
41
- }
42
- assert_nothing_raised {
43
- command.evaluate
44
- }
45
- assert_nothing_raised {
46
- output = command.sync
47
- }
48
- Puppet::Type::Exec.clear
49
- assert_nothing_raised {
50
- command = Puppet::Type::Exec.create(
51
- :command => "/bin/echo",
52
- :returns => "0"
53
- )
54
- }
55
- assert_nothing_raised {
56
- command.evaluate
57
- }
58
- assert_nothing_raised {
59
- output = command.sync
31
+ [0, "0"].each { |val|
32
+ Puppet.type(:exec).clear
33
+ Puppet.type(:component).clear
34
+ command = nil
35
+ output = nil
36
+ assert_nothing_raised {
37
+ command = Puppet.type(:exec).create(
38
+ :command => "/bin/echo",
39
+ :returns => val
40
+ )
41
+ }
42
+ assert_events([:executed_command], command)
60
43
  }
61
44
  end
62
45
 
@@ -64,27 +47,27 @@ class TestExec < Test::Unit::TestCase
64
47
  command = nil
65
48
  output = nil
66
49
  assert_nothing_raised {
67
- command = Puppet::Type::Exec.create(
50
+ command = Puppet.type(:exec).create(
68
51
  :command => "echo"
69
52
  )
70
53
  assert_nil(command)
71
54
  }
72
- Puppet::Type::Exec.clear
55
+ Puppet.type(:exec).clear
73
56
  assert_nothing_raised {
74
- command = Puppet::Type::Exec.create(
57
+ command = Puppet.type(:exec).create(
75
58
  :command => "echo",
76
59
  :path => "/usr/bin:/bin:/usr/sbin:/sbin"
77
60
  )
78
61
  }
79
- Puppet::Type::Exec.clear
62
+ Puppet.type(:exec).clear
80
63
  assert_nothing_raised {
81
- command = Puppet::Type::Exec.create(
64
+ command = Puppet.type(:exec).create(
82
65
  :command => "/bin/echo"
83
66
  )
84
67
  }
85
- Puppet::Type::Exec.clear
68
+ Puppet.type(:exec).clear
86
69
  assert_nothing_raised {
87
- command = Puppet::Type::Exec.create(
70
+ command = Puppet.type(:exec).create(
88
71
  :command => "/bin/echo",
89
72
  :path => "/usr/bin:/bin:/usr/sbin:/sbin"
90
73
  )
@@ -93,21 +76,21 @@ class TestExec < Test::Unit::TestCase
93
76
 
94
77
  def test_nonzero_returns
95
78
  assert_nothing_raised {
96
- command = Puppet::Type::Exec.create(
79
+ command = Puppet.type(:exec).create(
97
80
  :command => "mkdir /this/directory/does/not/exist",
98
81
  :path => "/usr/bin:/bin:/usr/sbin:/sbin",
99
82
  :returns => 1
100
83
  )
101
84
  }
102
85
  assert_nothing_raised {
103
- command = Puppet::Type::Exec.create(
86
+ command = Puppet.type(:exec).create(
104
87
  :command => "touch /etc",
105
88
  :path => "/usr/bin:/bin:/usr/sbin:/sbin",
106
89
  :returns => 1
107
90
  )
108
91
  }
109
92
  assert_nothing_raised {
110
- command = Puppet::Type::Exec.create(
93
+ command = Puppet.type(:exec).create(
111
94
  :command => "thiscommanddoesnotexist",
112
95
  :path => "/usr/bin:/bin:/usr/sbin:/sbin",
113
96
  :returns => 127
@@ -122,37 +105,33 @@ class TestExec < Test::Unit::TestCase
122
105
  Dir.getwd
123
106
  }
124
107
  assert_nothing_raised {
125
- command = Puppet::Type::Exec.create(
108
+ command = Puppet.type(:exec).create(
126
109
  :command => "pwd",
127
110
  :cwd => dir,
128
111
  :path => "/usr/bin:/bin:/usr/sbin:/sbin",
129
112
  :returns => 0
130
113
  )
131
114
  }
132
- assert_nothing_raised {
133
- command.evaluate
134
- }
135
- assert_nothing_raised {
136
- command.sync
137
- }
115
+ assert_events([:executed_command], command)
138
116
  assert_equal(wd,command.output.chomp)
139
117
  end
140
118
 
141
119
  def test_refreshonly
142
120
  file = nil
143
121
  cmd = nil
144
- tmpfile = "/tmp/exectesting"
122
+ tmpfile = tempfile()
145
123
  @@tmpfiles.push tmpfile
146
124
  trans = nil
147
125
  File.open(tmpfile, File::WRONLY|File::CREAT|File::TRUNC) { |of|
148
126
  of.puts rand(100)
149
127
  }
150
- file = Puppet::Type::PFile.create(
128
+ file = Puppet.type(:file).create(
151
129
  :path => tmpfile,
152
130
  :checksum => "md5"
153
131
  )
132
+ assert_instance_of(Puppet.type(:file), file)
154
133
  assert_nothing_raised {
155
- cmd = Puppet::Type::Exec.create(
134
+ cmd = Puppet.type(:exec).create(
156
135
  :command => "pwd",
157
136
  :path => "/usr/bin:/bin:/usr/sbin:/sbin",
158
137
  :subscribe => [[file.class.name,file.name]],
@@ -160,7 +139,9 @@ class TestExec < Test::Unit::TestCase
160
139
  )
161
140
  }
162
141
 
163
- comp = Puppet::Type::Component.create(:name => "RefreshTest")
142
+ assert_instance_of(Puppet.type(:exec), cmd)
143
+
144
+ comp = Puppet.type(:component).create(:name => "RefreshTest")
164
145
  [file,cmd].each { |obj|
165
146
  comp.push obj
166
147
  }
@@ -190,7 +171,7 @@ class TestExec < Test::Unit::TestCase
190
171
  # verify that only the file_changed event was kicked off, not the
191
172
  # command_executed
192
173
  assert_equal(
193
- [:file_modified],
174
+ [:file_changed],
194
175
  events
195
176
  )
196
177
  end
@@ -198,8 +179,9 @@ class TestExec < Test::Unit::TestCase
198
179
  def test_creates
199
180
  file = tempfile()
200
181
  exec = nil
182
+ assert(! FileTest.exists?(file), "File already exists")
201
183
  assert_nothing_raised {
202
- exec = Puppet::Type::Exec.create(
184
+ exec = Puppet.type(:exec).create(
203
185
  :command => "touch %s" % file,
204
186
  :path => "/usr/bin:/bin:/usr/sbin:/sbin",
205
187
  :creates => file
@@ -207,8 +189,83 @@ class TestExec < Test::Unit::TestCase
207
189
  }
208
190
 
209
191
  comp = newcomp("createstest", exec)
210
- assert_events(comp, [:executed_command], "creates")
211
- assert_events(comp, [], "creates")
192
+ assert_events([:executed_command], comp, "creates")
193
+ assert_events([], comp, "creates")
194
+ end
195
+
196
+ # Verify that we can download the file that we're going to execute.
197
+ def test_retrievethenmkexe
198
+ exe = tempfile()
199
+ oexe = tempfile()
200
+ sh = %x{which sh}
201
+ File.open(exe, "w") { |f| f.puts "#!#{sh}\necho yup" }
202
+
203
+ file = Puppet.type(:file).create(
204
+ :name => oexe,
205
+ :source => exe,
206
+ :mode => 0755
207
+ )
208
+
209
+ exec = Puppet.type(:exec).create(
210
+ :name => oexe,
211
+ :require => [:file, oexe]
212
+ )
213
+
214
+ comp = newcomp("Testing", file, exec)
215
+
216
+ assert_events([:file_created, :executed_command], comp)
217
+ end
218
+
219
+ # Verify that we auto-require any managed scripts.
220
+ def test_autorequire
221
+ exe = tempfile()
222
+ oexe = tempfile()
223
+ sh = %x{which sh}
224
+ File.open(exe, "w") { |f| f.puts "#!#{sh}\necho yup" }
225
+
226
+ file = Puppet.type(:file).create(
227
+ :name => oexe,
228
+ :source => exe,
229
+ :mode => 755
230
+ )
231
+
232
+ basedir = File.dirname(oexe)
233
+ baseobj = Puppet.type(:file).create(
234
+ :name => basedir,
235
+ :source => exe,
236
+ :mode => 755
237
+ )
238
+
239
+ ofile = Puppet.type(:file).create(
240
+ :name => exe,
241
+ :mode => 755
242
+ )
243
+
244
+ exec = Puppet.type(:exec).create(
245
+ :name => oexe,
246
+ :path => ENV["PATH"],
247
+ :cwd => basedir
248
+ )
249
+
250
+ cat = Puppet.type(:exec).create(
251
+ :name => "cat %s %s" % [exe, oexe],
252
+ :path => ENV["PATH"]
253
+ )
254
+
255
+ Puppet::Type.finalize
256
+
257
+ # Verify we get the script itself
258
+ assert(exec.requires?(file), "Exec did not autorequire file")
259
+
260
+ # Verify we catch the cwd
261
+ assert(exec.requires?(baseobj), "Exec did not autorequire cwd")
262
+
263
+ # Verify we don't require ourselves
264
+ assert(!exec.requires?(ofile), "Exec incorrectly required file")
265
+
266
+ # Verify that we catch inline files
267
+ assert(cat.requires?(ofile), "Exec did not catch second inline file")
268
+ assert(cat.requires?(file), "Exec did not catch inline file")
212
269
  end
213
270
 
214
271
  if Process.uid == 0
@@ -239,11 +296,11 @@ class TestExec < Test::Unit::TestCase
239
296
  end
240
297
  exec = nil
241
298
  assert_nothing_raised {
242
- exec = Puppet::Type::Exec.create(args)
299
+ exec = Puppet.type(:exec).create(args)
243
300
  }
244
301
 
245
302
  comp = newcomp("usertest", exec)
246
- assert_events(comp, [:executed_command], "usertest")
303
+ assert_events([:executed_command], comp, "usertest")
247
304
 
248
305
  assert(FileTest.exists?(file), "File does not exist")
249
306
  if user