puppet 0.13.1 → 0.13.2

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 (44) hide show
  1. data/CHANGELOG +4 -0
  2. data/Rakefile +2 -2
  3. data/bin/puppet +29 -0
  4. data/bin/puppetd +35 -1
  5. data/conf/redhat/puppet.spec +1 -1
  6. data/lib/puppet.rb +1 -1
  7. data/lib/puppet/client/master.rb +34 -3
  8. data/lib/puppet/filetype.rb +6 -2
  9. data/lib/puppet/networkclient.rb +4 -1
  10. data/lib/puppet/parameter.rb +35 -38
  11. data/lib/puppet/parser/ast/node.rb +1 -0
  12. data/lib/puppet/parser/interpreter.rb +129 -2
  13. data/lib/puppet/parser/scope.rb +44 -6
  14. data/lib/puppet/type.rb +47 -37
  15. data/lib/puppet/type/cron.rb +25 -10
  16. data/lib/puppet/type/exec.rb +165 -71
  17. data/lib/puppet/type/nameservice.rb +2 -17
  18. data/lib/puppet/type/package.rb +31 -7
  19. data/lib/puppet/type/package/sun.rb +11 -6
  20. data/lib/puppet/type/parsedtype.rb +94 -60
  21. data/lib/puppet/type/parsedtype/host.rb +5 -12
  22. data/lib/puppet/type/parsedtype/port.rb +53 -32
  23. data/lib/puppet/type/parsedtype/sshkey.rb +8 -4
  24. data/lib/puppet/type/pfile.rb +6 -4
  25. data/lib/puppet/type/pfile/ensure.rb +1 -6
  26. data/lib/puppet/type/state.rb +34 -74
  27. data/lib/puppet/type/symlink.rb +30 -19
  28. data/lib/puppet/type/user.rb +63 -11
  29. data/lib/puppet/util.rb +54 -60
  30. data/test/client/master.rb +72 -0
  31. data/test/language/interpreter.rb +94 -0
  32. data/test/other/log.rb +8 -1
  33. data/test/puppet/utiltest.rb +101 -1
  34. data/test/test +12 -5
  35. data/test/types/cron.rb +21 -1
  36. data/test/types/exec.rb +46 -2
  37. data/test/types/group.rb +15 -3
  38. data/test/types/host.rb +43 -4
  39. data/test/types/port.rb +67 -6
  40. data/test/types/sshkey.rb +45 -4
  41. data/test/types/symlink.rb +4 -4
  42. data/test/types/type.rb +41 -3
  43. data/test/types/user.rb +23 -2
  44. metadata +3 -2
data/test/test CHANGED
@@ -16,31 +16,38 @@ require 'getoptlong'
16
16
  #[ "--size", "-s", GetoptLong::REQUIRED_ARGUMENT ],
17
17
  result = GetoptLong.new(
18
18
  [ "--debug", "-d", GetoptLong::NO_ARGUMENT ],
19
+ [ "-n", GetoptLong::REQUIRED_ARGUMENT ],
19
20
  [ "--help", "-h", GetoptLong::NO_ARGUMENT ]
20
21
  )
21
22
 
22
23
  usage = "USAGE: %s [--help] <testsuite> <testsuite> .." % $0
23
24
 
25
+ opts = []
26
+
24
27
  result.each { |opt,arg|
25
28
  case opt
26
29
  when "--debug"
27
- Puppet[:debug] = true
30
+ Puppet::Log.level = :debug
28
31
  when "--help"
29
32
  puts usage
30
33
  exit
31
34
  else
32
- raise "Invalid option '#{opt}'"
35
+ opts << opt << arg
36
+ #raise "Invalid option '#{opt}'"
33
37
  end
34
38
  }
35
-
36
39
  suites = nil
37
40
 
38
41
  if ARGV.length != 0
39
- suites = ARGV
42
+ suites = ARGV.dup
40
43
  else
41
44
  suites = PuppetTestSuite.list
42
45
  end
43
46
 
47
+ ARGV.clear
48
+
49
+ opts.each { |o| ARGV << o }
50
+
44
51
  suites.each { |suite|
45
52
  PuppetTestSuite.new(suite)
46
53
  }
@@ -48,4 +55,4 @@ suites.each { |suite|
48
55
  # This damn problem just doesn't seem to want to go away
49
56
  system("%s/etc/init.d/sleeper stop 2>/dev/null 1>/dev/null" % $puppetbase)
50
57
 
51
- # $Id: test 750 2005-11-22 05:34:43Z luke $
58
+ # $Id: test 915 2006-02-15 21:56:54Z luke $
data/test/types/cron.rb CHANGED
@@ -362,6 +362,26 @@ class TestCron < Test::Unit::TestCase
362
362
  cron.retrieve
363
363
  assert_events([], cron)
364
364
  end
365
+
366
+ def test_fieldremoval
367
+ cron = nil
368
+ assert_nothing_raised {
369
+ cron = Puppet.type(:cron).create(
370
+ :command => "/bin/date > /dev/null",
371
+ :minute => [0, 30],
372
+ :name => "crontest"
373
+ )
374
+ }
375
+
376
+ assert_events([:cron_created], cron)
377
+
378
+ cron[:minute] = :absent
379
+ assert_events([:cron_changed], cron)
380
+ assert_nothing_raised {
381
+ cron.retrieve
382
+ }
383
+ assert_equal(:absent, cron.is(:minute))
384
+ end
365
385
  end
366
386
 
367
- # $Id: cron.rb 899 2006-02-13 17:48:33Z luke $
387
+ # $Id: cron.rb 910 2006-02-15 07:20:36Z luke $
data/test/types/exec.rb CHANGED
@@ -9,7 +9,7 @@ require 'puppettest'
9
9
  require 'test/unit'
10
10
  require 'facter'
11
11
 
12
- # $Id: exec.rb 832 2006-01-17 07:11:50Z luke $
12
+ # $Id: exec.rb 907 2006-02-13 21:58:40Z luke $
13
13
 
14
14
  class TestExec < Test::Unit::TestCase
15
15
  include TestPuppet
@@ -255,7 +255,7 @@ class TestExec < Test::Unit::TestCase
255
255
  Puppet::Type.finalize
256
256
 
257
257
  # Verify we get the script itself
258
- assert(exec.requires?(file), "Exec did not autorequire file")
258
+ assert(exec.requires?(file), "Exec did not autorequire %s" % file)
259
259
 
260
260
  # Verify we catch the cwd
261
261
  assert(exec.requires?(baseobj), "Exec did not autorequire cwd")
@@ -268,6 +268,50 @@ class TestExec < Test::Unit::TestCase
268
268
  assert(cat.requires?(file), "Exec did not catch inline file")
269
269
  end
270
270
 
271
+ def test_ifonly
272
+ afile = tempfile()
273
+ bfile = tempfile()
274
+
275
+ exec = nil
276
+ assert_nothing_raised {
277
+ exec = Puppet.type(:exec).create(
278
+ :command => "touch %s" % bfile,
279
+ :onlyif => "test -f %s" % afile,
280
+ :path => ENV['PATH']
281
+ )
282
+ }
283
+
284
+ assert_events([], exec)
285
+ system("touch %s" % afile)
286
+ assert_events([:executed_command], exec)
287
+ assert_events([:executed_command], exec)
288
+ system("rm %s" % afile)
289
+ assert_events([], exec)
290
+ end
291
+
292
+ def test_unless
293
+ afile = tempfile()
294
+ bfile = tempfile()
295
+
296
+ exec = nil
297
+ assert_nothing_raised {
298
+ exec = Puppet.type(:exec).create(
299
+ :command => "touch %s" % bfile,
300
+ :unless => "test -f %s" % afile,
301
+ :path => ENV['PATH']
302
+ )
303
+ }
304
+
305
+ assert_events([:executed_command], exec)
306
+ assert_events([:executed_command], exec)
307
+ system("touch %s" % afile)
308
+ assert_events([], exec)
309
+ assert_events([], exec)
310
+ system("rm %s" % afile)
311
+ assert_events([:executed_command], exec)
312
+ assert_events([:executed_command], exec)
313
+ end
314
+
271
315
  if Process.uid == 0
272
316
  # Verify that we can execute commands as a special user
273
317
  def mknverify(file, user, group = nil, id = true)
data/test/types/group.rb CHANGED
@@ -4,7 +4,7 @@ if __FILE__ == $0
4
4
  $puppetbase = "../../../../language/trunk"
5
5
  end
6
6
 
7
- # $Id: group.rb 831 2006-01-16 20:01:20Z luke $
7
+ # $Id: group.rb 914 2006-02-15 21:04:14Z luke $
8
8
 
9
9
  require 'etc'
10
10
  require 'puppet/type'
@@ -214,6 +214,18 @@ class TestGroup < Test::Unit::TestCase
214
214
  assert_equal(Process.gid, user.is(:gid), "Retrieved UID does not match")
215
215
  end
216
216
 
217
+ def test_ensurevals
218
+ gobj = nil
219
+ assert_nothing_raised {
220
+ gobj = Puppet.type(:group).create(
221
+ :name => name,
222
+ :ensure => :exists
223
+ )
224
+ }
225
+
226
+ assert_equal(false, gobj.state(:ensure))
227
+ end
228
+
217
229
  if Process.uid == 0
218
230
  def test_mkgroup
219
231
  gobj = nil
@@ -234,10 +246,10 @@ class TestGroup < Test::Unit::TestCase
234
246
  #}
235
247
  #end
236
248
  assert(missing?(name), "Group %s is still present" % name)
237
-
238
249
  assert_nothing_raised {
239
250
  gobj = Puppet.type(:group).create(
240
- :name => name
251
+ :name => name,
252
+ :ensure => :present
241
253
  )
242
254
 
243
255
  comp = newcomp("groupmaker %s" % name, gobj)
data/test/types/host.rb CHANGED
@@ -33,12 +33,17 @@ class TestHost < Test::Unit::TestCase
33
33
  end
34
34
 
35
35
  def mkhost
36
+ if defined? @hcount
37
+ @hcount += 1
38
+ else
39
+ @hcount = 1
40
+ end
36
41
  host = nil
37
42
  assert_nothing_raised {
38
43
  host = Puppet.type(:host).create(
39
- :name => "culain",
40
- :ip => "192.168.0.3",
41
- :alias => "puppet"
44
+ :name => "fakehost%s" % @hcount,
45
+ :ip => "192.168.27.%s" % @hcount,
46
+ :alias => "alias%s" % @hcount
42
47
  )
43
48
  }
44
49
 
@@ -141,6 +146,40 @@ class TestHost < Test::Unit::TestCase
141
146
  host.retrieve
142
147
  assert_events([], host)
143
148
  end
149
+
150
+ def test_modifyingfile
151
+ hostfile = tempfile()
152
+ Puppet.type(:host).path = hostfile
153
+
154
+ hosts = []
155
+ names = []
156
+ 3.times {
157
+ h = mkhost()
158
+ #h[:ensure] = :present
159
+ #h.retrieve
160
+ hosts << h
161
+ names << h.name
162
+ }
163
+ assert_apply(*hosts)
164
+ hosts.clear
165
+ Puppet.type(:host).clear
166
+ newhost = mkhost()
167
+ #newhost[:ensure] = :present
168
+ names << newhost.name
169
+ assert_apply(newhost)
170
+ Puppet.type(:host).clear
171
+ # Verify we can retrieve that info
172
+ assert_nothing_raised("Could not retrieve after second write") {
173
+ newhost.retrieve
174
+ }
175
+
176
+ # And verify that we have data for everything
177
+ names.each { |name|
178
+ host = Puppet.type(:host)[name]
179
+ assert(host)
180
+ assert(host[:ip])
181
+ }
182
+ end
144
183
  end
145
184
 
146
- # $Id: host.rb 831 2006-01-16 20:01:20Z luke $
185
+ # $Id: host.rb 910 2006-02-15 07:20:36Z luke $
data/test/types/port.rb CHANGED
@@ -29,19 +29,25 @@ class TestPort < Test::Unit::TestCase
29
29
  # Here we just create a fake host type that answers to all of the methods
30
30
  # but does not modify our actual system.
31
31
  def mkfaketype
32
- @faketype = Puppet::FileType.filetype(:ram)
33
- @porttype.filetype = @faketype
32
+ pfile = tempfile()
33
+ @porttype.path = pfile
34
34
  end
35
35
 
36
36
  def mkport
37
37
  port = nil
38
+
39
+ if defined? @pcount
40
+ @pcount += 1
41
+ else
42
+ @pcount = 1
43
+ end
38
44
  assert_nothing_raised {
39
45
  port = Puppet.type(:port).create(
40
- :name => "puppet",
41
- :number => "8139",
46
+ :name => "puppet%s" % @pcount,
47
+ :number => "813%s" % @pcount,
42
48
  :protocols => "tcp",
43
49
  :description => "The port that Puppet runs on",
44
- :alias => "coolness"
50
+ :alias => "coolness%s" % @pcount
45
51
  )
46
52
  }
47
53
 
@@ -134,6 +140,61 @@ class TestPort < Test::Unit::TestCase
134
140
  port.retrieve
135
141
  assert_events([], port)
136
142
  end
143
+
144
+ def test_modifyingfile
145
+ mkfaketype()
146
+
147
+ ports = []
148
+ names = []
149
+ 3.times {
150
+ k = mkport()
151
+ ports << k
152
+ names << k.name
153
+ }
154
+ assert_apply(*ports)
155
+ ports.clear
156
+ Puppet.type(:port).clear
157
+ newport = mkport()
158
+ #newport[:ensure] = :present
159
+ names << newport.name
160
+ assert_apply(newport)
161
+ Puppet.type(:port).clear
162
+ # Verify we can retrieve that info
163
+ assert_nothing_raised("Could not retrieve after second write") {
164
+ newport.retrieve
165
+ }
166
+
167
+ # And verify that we have data for everything
168
+ names.each { |name|
169
+ port = Puppet.type(:port)[name]
170
+ assert(port)
171
+ port.retrieve
172
+ assert(port[:number], "port %s has no number" % name)
173
+ }
174
+ end
175
+
176
+ def test_addingstates
177
+ mkfaketype
178
+
179
+ port = mkport()
180
+ assert_events([:port_created], port)
181
+
182
+ port.delete(:alias)
183
+ assert(! port.state(:alias))
184
+ assert_events([:port_changed], port)
185
+ assert_nothing_raised {
186
+ port.retrieve
187
+ }
188
+
189
+ assert_equal(:present, port.is(:ensure))
190
+
191
+ assert(port.state(:alias).is == :absent)
192
+
193
+ port[:alias] = "yaytest"
194
+ assert_events([:port_changed], port)
195
+ port.retrieve
196
+ assert(port.state(:alias).is == ["yaytest"])
197
+ end
137
198
  end
138
199
 
139
- # $Id: port.rb 831 2006-01-16 20:01:20Z luke $
200
+ # $Id: port.rb 915 2006-02-15 21:56:54Z luke $
data/test/types/sshkey.rb CHANGED
@@ -35,12 +35,19 @@ class TestSSHKey < Test::Unit::TestCase
35
35
 
36
36
  def mkkey
37
37
  key = nil
38
+
39
+ if defined? @kcount
40
+ @kcount += 1
41
+ else
42
+ @kcount = 1
43
+ end
44
+
38
45
  assert_nothing_raised {
39
46
  key = @sshtype.create(
40
- :name => "culain.madstop.com",
41
- :key => "AAAAB3NzaC1kc3MAAACBAMnhSiku76y3EGkNCDsUlvpO8tRgS9wL4Eh54WZfQ2lkxqfd2uT/RTT9igJYDtm/+UHuBRdNGpJYW1Nw2i2JUQgQEEuitx4QKALJrBotejGOAWxxVk6xsh9xA0OW8Q3ZfuX2DDitfeC8ZTCl4xodUMD8feLtP+zEf8hxaNamLlt/AAAAFQDYJyf3vMCWRLjTWnlxLtOyj/bFpwAAAIEAmRxxXb4jjbbui9GYlZAHK00689DZuX0EabHNTl2yGO5KKxGC6Esm7AtjBd+onfu4Rduxut3jdI8GyQCIW8WypwpJofCIyDbTUY4ql0AQUr3JpyVytpnMijlEyr41FfIb4tnDqnRWEsh2H7N7peW+8DWZHDFnYopYZJ9Yu4/jHRYAAACAERG50e6aRRb43biDr7Ab9NUCgM9bC0SQscI/xdlFjac0B/kSWJYTGVARWBDWug705hTnlitY9cLC5Ey/t/OYOjylTavTEfd/bh/8FkAYO+pWdW3hx6p97TBffK0b6nrc6OORT2uKySbbKOn0681nNQh4a6ueR3JRppNkRPnTk5c=",
47
+ :name => "host%s.madstop.com" % @kcount,
48
+ :key => "%sAAAAB3NzaC1kc3MAAACBAMnhSiku76y3EGkNCDsUlvpO8tRgS9wL4Eh54WZfQ2lkxqfd2uT/RTT9igJYDtm/+UHuBRdNGpJYW1Nw2i2JUQgQEEuitx4QKALJrBotejGOAWxxVk6xsh9xA0OW8Q3ZfuX2DDitfeC8ZTCl4xodUMD8feLtP+zEf8hxaNamLlt/AAAAFQDYJyf3vMCWRLjTWnlxLtOyj/bFpwAAAIEAmRxxXb4jjbbui9GYlZAHK00689DZuX0EabHNTl2yGO5KKxGC6Esm7AtjBd+onfu4Rduxut3jdI8GyQCIW8WypwpJofCIyDbTUY4ql0AQUr3JpyVytpnMijlEyr41FfIb4tnDqnRWEsh2H7N7peW+8DWZHDFnYopYZJ9Yu4/jHRYAAACAERG50e6aRRb43biDr7Ab9NUCgM9bC0SQscI/xdlFjac0B/kSWJYTGVARWBDWug705hTnlitY9cLC5Ey/t/OYOjylTavTEfd/bh/8FkAYO+pWdW3hx6p97TBffK0b6nrc6OORT2uKySbbKOn0681nNQh4a6ueR3JRppNkRPnTk5c=" % @kcount,
42
49
  :type => "ssh-dss",
43
- :alias => ["192.168.0.3"]
50
+ :alias => ["192.168.0.%s" % @kcount]
44
51
  )
45
52
  }
46
53
 
@@ -135,6 +142,40 @@ class TestSSHKey < Test::Unit::TestCase
135
142
  sshkey.retrieve
136
143
  assert_events([], sshkey)
137
144
  end
145
+
146
+ def test_modifyingfile
147
+ keyfile = tempfile()
148
+ Puppet.type(:sshkey).path = keyfile
149
+
150
+ keys = []
151
+ names = []
152
+ 3.times {
153
+ k = mkkey()
154
+ #h[:ensure] = :present
155
+ #h.retrieve
156
+ keys << k
157
+ names << k.name
158
+ }
159
+ assert_apply(*keys)
160
+ keys.clear
161
+ Puppet.type(:sshkey).clear
162
+ newkey = mkkey()
163
+ #newkey[:ensure] = :present
164
+ names << newkey.name
165
+ assert_apply(newkey)
166
+ Puppet.type(:sshkey).clear
167
+ # Verify we can retrieve that info
168
+ assert_nothing_raised("Could not retrieve after second write") {
169
+ newkey.retrieve
170
+ }
171
+
172
+ # And verify that we have data for everything
173
+ names.each { |name|
174
+ key = Puppet.type(:sshkey)[name]
175
+ assert(key)
176
+ assert(key[:type])
177
+ }
178
+ end
138
179
  end
139
180
 
140
- # $Id: sshkey.rb 831 2006-01-16 20:01:20Z luke $
181
+ # $Id: sshkey.rb 910 2006-02-15 07:20:36Z luke $
@@ -8,7 +8,7 @@ require 'puppet'
8
8
  require 'puppettest'
9
9
  require 'test/unit'
10
10
 
11
- # $Id: symlink.rb 787 2006-01-08 00:02:23Z luke $
11
+ # $Id: symlink.rb 905 2006-02-13 21:49:25Z luke $
12
12
 
13
13
  class TestSymlink < Test::Unit::TestCase
14
14
  include FileTesting
@@ -38,8 +38,8 @@ class TestSymlink < Test::Unit::TestCase
38
38
 
39
39
  def newlink(hash = {})
40
40
  hash[:name] = tmplink()
41
- unless hash.include?(:target)
42
- hash[:target] = mktmpfile()
41
+ unless hash.include?(:ensure)
42
+ hash[:ensure] = mktmpfile()
43
43
  end
44
44
  link = Puppet.type(:symlink).create(hash)
45
45
  return link
@@ -71,7 +71,7 @@ class TestSymlink < Test::Unit::TestCase
71
71
 
72
72
  link = nil
73
73
  assert_nothing_raised {
74
- link = newlink(:target => source, :recurse => true)
74
+ link = newlink(:ensure => source, :recurse => true)
75
75
  }
76
76
  comp = newcomp("linktest",link)
77
77
  cycle(comp)
data/test/types/type.rb CHANGED
@@ -190,7 +190,14 @@ class TestType < Test::Unit::TestCase
190
190
  # Verify that names are aliases, not equivalents
191
191
  def test_nameasalias
192
192
  file = nil
193
- path = tempfile()
193
+ # Create the parent dir, so we make sure autorequiring the parent dir works
194
+ parentdir = tempfile()
195
+ dir = Puppet.type(:file).create(
196
+ :name => parentdir,
197
+ :ensure => "directory"
198
+ )
199
+ assert_apply(dir)
200
+ path = File.join(parentdir, "subdir")
194
201
  name = "a test file"
195
202
  transport = Puppet::TransObject.new(name, "file")
196
203
  transport[:path] = path
@@ -209,8 +216,39 @@ class TestType < Test::Unit::TestCase
209
216
  assert_apply(file)
210
217
 
211
218
  assert(Puppet.type(:file)[name], "Could not look up object by name")
212
- #assert(Puppet.type(:file)[path], "Could not look up object by path")
219
+ end
220
+
221
+ def test_ensuredefault
222
+ user = nil
223
+ assert_nothing_raised {
224
+ user = Puppet.type(:user).create(
225
+ :name => "pptestAA",
226
+ :check => [:uid]
227
+ )
228
+ }
229
+
230
+ # make sure we don't get :ensure for unmanaged files
231
+ assert(! user.state(:ensure), "User got an ensure state")
232
+
233
+ assert_nothing_raised {
234
+ user = Puppet.type(:user).create(
235
+ :name => "pptestAA",
236
+ :comment => "Testingness"
237
+ )
238
+ }
239
+ # but make sure it gets added once we manage them
240
+ assert(user.state(:ensure), "User did not add ensure state")
241
+
242
+ assert_nothing_raised {
243
+ user = Puppet.type(:user).create(
244
+ :name => "pptestBB",
245
+ :comment => "A fake user"
246
+ )
247
+ }
248
+
249
+ # and make sure managed objects start with them
250
+ assert(user.state(:ensure), "User did not get an ensure state")
213
251
  end
214
252
  end
215
253
 
216
- # $Id: type.rb 896 2006-02-10 22:00:30Z luke $
254
+ # $Id: type.rb 915 2006-02-15 21:56:54Z luke $