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/types/type.rb CHANGED
@@ -285,6 +285,185 @@ class TestType < Test::Unit::TestCase
285
285
  assert_nil(klass[obj.name], "object %s was not removed" % obj.name)
286
286
  end
287
287
  end
288
+
289
+ # Verify that objects can't be their own children.
290
+ def test_object_recursion
291
+ comp = Puppet.type(:component).create(:name => "top")
292
+
293
+ file = Puppet.type(:file).create(:path => tempfile, :ensure => :file)
294
+
295
+ assert_raise(Puppet::DevError) do
296
+ comp.push(comp)
297
+ end
298
+
299
+ assert_raise(Puppet::DevError) do
300
+ file.push(file)
301
+ end
302
+
303
+ assert_raise(Puppet::DevError) do
304
+ comp.parent = comp
305
+ end
306
+
307
+ assert_raise(Puppet::DevError) do
308
+ file.parent = file
309
+ end
310
+
311
+ assert_nothing_raised {
312
+ comp.push(file)
313
+ }
314
+
315
+ assert_raise(Puppet::DevError) do
316
+ file.push(comp)
317
+ end
318
+
319
+ assert_raise(Puppet::DevError) do
320
+ comp.parent = file
321
+ end
322
+ end
323
+
324
+ def test_loadplugins
325
+ names = %w{loadedplugin1 loadplugin2 loadplugin3}
326
+ dirs = []
327
+ 3.times { dirs << tempfile() }
328
+ # Set plugindest to something random
329
+ Puppet[:plugindest] = tempfile()
330
+
331
+ Puppet[:pluginpath] = dirs.join(":")
332
+
333
+ names.each do |name|
334
+ dir = dirs.shift
335
+ Dir.mkdir(dir)
336
+
337
+ # Create an extra file for later
338
+ [name, name + "2ness"].each do |n|
339
+ file = File.join(dir, n + ".rb")
340
+ File.open(file, "w") do |f|
341
+ f.puts %{Puppet::Type.newtype('#{n}') do
342
+ newparam(:argument) do
343
+ isnamevar
344
+ end
345
+ end
346
+ }
347
+ end
348
+ end
349
+
350
+ assert(Puppet::Type.type(name),
351
+ "Did not get loaded plugin")
352
+
353
+ assert_nothing_raised {
354
+ Puppet::Type.type(name).create(
355
+ :name => "myname"
356
+ )
357
+ }
358
+ end
359
+
360
+ # Now make sure the plugindest got added to our pluginpath
361
+ assert(Puppet[:pluginpath].split(":").include?(Puppet[:plugindest]),
362
+ "Plugin dest did not get added to plugin path")
363
+
364
+ # Now make sure it works with just a single path, using the extra files
365
+ # created above.
366
+ Puppet[:pluginpath] = Puppet[:pluginpath].split(":")[0]
367
+ assert(Puppet::Type.type("loadedplugin12ness"),
368
+ "Did not get loaded plugin")
369
+
370
+ end
371
+
372
+ def test_newtype_methods
373
+ assert_nothing_raised {
374
+ Puppet::Type.newtype(:mytype) do
375
+ newparam(:wow) do isnamevar end
376
+ end
377
+ }
378
+
379
+ assert(Puppet::Type.respond_to?(:newmytype),
380
+ "new<type> method did not get created")
381
+
382
+ obj = nil
383
+ assert_nothing_raised {
384
+ obj = Puppet::Type.newmytype(:wow => "yay")
385
+ }
386
+
387
+ assert(obj.is_a?(Puppet::Type.type(:mytype)),
388
+ "Obj is not the correct type")
389
+
390
+ # Now make the type again, just to make sure it works on refreshing.
391
+ assert_nothing_raised {
392
+ Puppet::Type.newtype(:mytype) do
393
+ newparam(:yay) do isnamevar end
394
+ end
395
+ }
396
+
397
+ obj = nil
398
+ # Make sure the old class was thrown away and only the new one is sitting
399
+ # around.
400
+ assert_raise(Puppet::Error) {
401
+ obj = Puppet::Type.newmytype(:wow => "yay")
402
+ }
403
+ assert_nothing_raised {
404
+ obj = Puppet::Type.newmytype(:yay => "yay")
405
+ }
406
+
407
+ # Now make sure that we don't replace existing, non-type methods
408
+ parammethod = Puppet::Type.method(:newparam)
409
+
410
+ assert_nothing_raised {
411
+ Puppet::Type.newtype(:param) do
412
+ newparam(:rah) do isnamevar end
413
+ end
414
+ }
415
+ assert_equal(parammethod, Puppet::Type.method(:newparam),
416
+ "newparam method got replaced by newtype")
417
+ end
418
+
419
+ def test_notify_metaparam
420
+ file = Puppet::Type.newfile(
421
+ :path => tempfile(),
422
+ :notify => ["exec", "notifytest"],
423
+ :ensure => :file
424
+ )
425
+
426
+ path = tempfile()
427
+ exec = Puppet::Type.newexec(
428
+ :name => "notifytest",
429
+ :path => "/usr/bin:/bin",
430
+ :command => "touch #{path}",
431
+ :refreshonly => true
432
+ )
433
+
434
+ assert_apply(file, exec)
435
+
436
+ assert(exec.requires?(file),
437
+ "Notify did not correctly set up the requirement chain.")
438
+
439
+ assert(FileTest.exists?(path),
440
+ "Exec path did not get created.")
441
+ end
442
+
443
+ def test_before_metaparam
444
+ file = Puppet::Type.newfile(
445
+ :path => tempfile(),
446
+ :before => ["exec", "beforetest"],
447
+ :content => "yaytest"
448
+ )
449
+
450
+ path = tempfile()
451
+ exec = Puppet::Type.newexec(
452
+ :name => "beforetest",
453
+ :command => "/bin/cp #{file[:path]} #{path}"
454
+ )
455
+
456
+ assert_apply(file, exec)
457
+
458
+ assert(exec.requires?(file),
459
+ "Before did not correctly set up the requirement chain.")
460
+
461
+ assert(FileTest.exists?(path),
462
+ "Exec path did not get created.")
463
+
464
+ assert_equal("yaytest", File.read(path),
465
+ "Exec did not correctly copy file.")
466
+ end
288
467
  end
289
468
 
290
- # $Id: type.rb 1053 2006-04-02 23:39:02Z luke $
469
+ # $Id: type.rb 1422 2006-07-22 03:32:56Z luke $
data/test/types/user.rb CHANGED
@@ -4,7 +4,7 @@ if __FILE__ == $0
4
4
  $puppetbase = "../../../../language/trunk"
5
5
  end
6
6
 
7
- # $Id: user.rb 1042 2006-03-22 21:56:49Z luke $
7
+ # $Id: user.rb 1422 2006-07-22 03:32:56Z luke $
8
8
 
9
9
  require 'etc'
10
10
  require 'puppet/type'
@@ -340,15 +340,22 @@ class TestUser < Test::Unit::TestCase
340
340
  user.retrieve
341
341
  }
342
342
 
343
- assert(user.state(:groups).is, "Did not retrieve group list")
343
+ # Some tests to verify that groups work correctly startig from nothing
344
+ # Remove our user
345
+ user[:ensure] = :absent
346
+ assert_apply(user)
344
347
 
345
- assert(!user.insync?, "User is incorrectly in sync")
348
+ assert_nothing_raised do
349
+ user.retrieve
350
+ end
346
351
 
347
- assert_events([:user_modified], user)
352
+ # And add it again
353
+ user[:ensure] = :present
354
+ assert_apply(user)
348
355
 
349
- assert_nothing_raised {
350
- user.retrieve
351
- }
356
+ user.retrieve
357
+
358
+ assert(user.state(:groups).is, "Did not retrieve group list")
352
359
 
353
360
  list = user.state(:groups).is
354
361
  assert_equal(extra.sort, list.sort, "Group list is not equal")
@@ -366,7 +373,7 @@ class TestUser < Test::Unit::TestCase
366
373
 
367
374
  assert(!user.insync?, "User is incorrectly in sync")
368
375
 
369
- assert_events([:user_modified], user)
376
+ assert_apply(user)
370
377
 
371
378
  assert_nothing_raised {
372
379
  user.retrieve
@@ -444,6 +451,33 @@ class TestUser < Test::Unit::TestCase
444
451
  assert_equal(Process.uid, user.is(:uid), "Retrieved UID does not match")
445
452
  end
446
453
 
454
+ def test_autorequire
455
+ file = tempfile()
456
+ user = Puppet.type(:user).create(
457
+ :name => "pptestu",
458
+ :home => file,
459
+ :gid => "pptestg",
460
+ :groups => "yayness"
461
+ )
462
+ home = Puppet.type(:file).create(
463
+ :path => file,
464
+ :ensure => "directory"
465
+ )
466
+ group = Puppet.type(:group).create(
467
+ :name => "pptestg"
468
+ )
469
+ ogroup = Puppet.type(:group).create(
470
+ :name => "yayness"
471
+ )
472
+ comp = newcomp(user, group, home, ogroup)
473
+ comp.finalize
474
+ comp.retrieve
475
+
476
+ assert(user.requires?(group), "User did not require group")
477
+ assert(user.requires?(home), "User did not require home dir")
478
+ assert(user.requires?(ogroup), "User did not require other groups")
479
+ end
480
+
447
481
  if Process.uid == 0
448
482
  def test_simpleuser
449
483
  name = "pptest"
@@ -487,6 +521,7 @@ class TestUser < Test::Unit::TestCase
487
521
  tests = Puppet.type(:user).validstates
488
522
 
489
523
  tests.each { |test|
524
+ next unless test.to_s =~ /groups/
490
525
  if self.respond_to?("attrtest_%s" % test)
491
526
  self.send("attrtest_%s" % test, user)
492
527
  else
@@ -498,26 +533,29 @@ class TestUser < Test::Unit::TestCase
498
533
  assert_apply(user)
499
534
  end
500
535
 
501
- def test_autorequire
502
- file = tempfile()
503
- user = Puppet.type(:user).create(
504
- :name => "pptestu",
505
- :home => file,
506
- :gid => "pptestg"
507
- )
508
- home = Puppet.type(:file).create(
509
- :path => file,
510
- :ensure => "directory"
511
- )
512
- group = Puppet.type(:group).create(
513
- :name => "pptestg"
514
- )
515
- comp = newcomp(user, group)
516
- comp.finalize
517
- comp.retrieve
536
+ def test_duplicateIDs
537
+ user1 = mkuser("user1")
538
+ user1[:uid] = 125
539
+ user2 = mkuser("user2")
540
+ user2[:uid] = 125
541
+
542
+ cleanup do
543
+ user1[:ensure] = :absent
544
+ user2[:ensure] = :absent
545
+ assert_apply(user1, user2)
546
+ end
518
547
 
519
- assert(user.requires?(group), "User did not require group")
520
- assert(user.requires?(home), "User did not require home dir")
548
+ assert_apply(user1)
549
+
550
+ # Not all OSes fail here, so we can't test that it doesn't work with
551
+ # it off, only that it does work with it on.
552
+ assert_nothing_raised {
553
+ user2[:allowdupe] = true
554
+ }
555
+ assert_apply(user2)
556
+ user2.retrieve
557
+ assert_equal(:present, user2.state(:ensure).is,
558
+ "User did not get created")
521
559
  end
522
560
  else
523
561
  $stderr.puts "Not root; skipping user creation/modification tests"
@@ -63,6 +63,21 @@ class TestYumRepo < Test::Unit::TestCase
63
63
  assert_equal(CREATE_EXP, text)
64
64
  end
65
65
 
66
+ # Delete mirrorlist by setting it to :absent and enable baseurl
67
+ def test_absent
68
+ copy_datafiles
69
+ baseurl = 'http://example.com/'
70
+ devel = make_repo("development",
71
+ { :mirrorlist => 'absent',
72
+ :baseurl => baseurl })
73
+ devel.retrieve
74
+ assert_apply(devel)
75
+ inifile = Puppet.type(:yumrepo).read()
76
+ sec = inifile["development"]
77
+ assert_nil(sec["mirrorlist"])
78
+ assert_equal(baseurl, sec["baseurl"])
79
+ end
80
+
66
81
  def make_repo(name, hash={})
67
82
  hash[:name] = name
68
83
  Puppet.type(:yumrepo).create(hash)
@@ -0,0 +1,437 @@
1
+ # Test host job creation, modification, and destruction
2
+
3
+ if __FILE__ == $0
4
+ $:.unshift '..'
5
+ $:.unshift '../../lib'
6
+ $puppetbase = "../.."
7
+ end
8
+
9
+ require 'puppettest'
10
+ require 'puppet'
11
+ require 'puppet/type/zone'
12
+ require 'test/unit'
13
+ require 'facter'
14
+
15
+ class TestZone < Test::Unit::TestCase
16
+ include TestPuppet
17
+
18
+ def test_nothing
19
+ end
20
+
21
+ # Zones can only be tested on solaris.
22
+ if Facter["operatingsystem"].value == "Solaris"
23
+
24
+ def setup
25
+ super
26
+ @@zones = []
27
+ end
28
+
29
+ def teardown
30
+ current = %x{zoneadm list -cp}.split("\n").inject({}) { |h, line|
31
+ ary = line.split(":")
32
+ h[ary[1]] = ary[2]
33
+ h
34
+ }
35
+
36
+ Puppet::Type.type(:zone).clear
37
+
38
+ # Get rid of any lingering zones
39
+ @@zones.each do |zone|
40
+ next unless current.include? zone
41
+
42
+ obj = Puppet::Type.type(:zone).create(:name => zone)
43
+ obj[:ensure] = :absent
44
+ assert_apply(obj)
45
+ end
46
+
47
+ # We can't delete the temp files until the zones are stopped and removed.
48
+ super
49
+ end
50
+
51
+ def mkzone(name)
52
+ zone = nil
53
+
54
+ base = tempfile()
55
+ Dir.mkdir(base)
56
+ File.chmod(0700, base)
57
+ root = File.join(base, "zonebase")
58
+ assert_nothing_raised {
59
+ zone = Puppet::Type.type(:zone).create(
60
+ :name => name,
61
+ :path => root,
62
+ :ensure => "configured" # don't want to install zones automatically
63
+ )
64
+ }
65
+
66
+ @@zones << name
67
+
68
+ return zone
69
+ end
70
+
71
+ def test_list
72
+ list = nil
73
+ assert_nothing_raised {
74
+ list = Puppet::Type.type(:zone).list
75
+ }
76
+
77
+ assert(! list.empty?, "Got no zones back")
78
+
79
+ assert(list.find { |z| z[:name] == "global" }, "Could not find global zone")
80
+ end
81
+
82
+ def test_valueslice
83
+ zone = mkzone("slicetest")
84
+
85
+ state = zone.state(:ensure)
86
+
87
+ slice = nil
88
+ assert_nothing_raised {
89
+ slice = state.class.valueslice(:absent, :installed).collect do |o|
90
+ o[:name]
91
+ end
92
+ }
93
+
94
+
95
+ assert_equal([:configured, :installed], slice)
96
+
97
+ assert_nothing_raised {
98
+ slice = state.class.valueslice(:running, :installed).collect do |o|
99
+ o[:name]
100
+ end
101
+ }
102
+
103
+
104
+ assert_equal(slice, [:installed])
105
+
106
+ end
107
+
108
+ # Make sure the ensure stuff behaves as we expect
109
+ def test_zoneensure
110
+ zone = mkzone("ensurezone")
111
+
112
+ state = zone.state(:ensure)
113
+
114
+ assert(state, "Did not get ensure state")
115
+
116
+ assert_nothing_raised {
117
+ zone.retrieve
118
+ }
119
+
120
+ assert(! state.insync?, "State is somehow in sync")
121
+
122
+ assert(state.up?, "State incorrectly thinks it is not moving up")
123
+
124
+ zone.is = [:ensure, :configured]
125
+ zone[:ensure] = :installed
126
+ assert(state.up?, "State incorrectly thinks it is not moving up")
127
+ zone[:ensure] = :absent
128
+ assert(! state.up?, "State incorrectly thinks it is moving up")
129
+ end
130
+
131
+ # Make sure all mentioned methods actually exist.
132
+ def test_zonemethods_exist
133
+ methods = []
134
+ zone = mkzone("methodtest")
135
+
136
+ state = zone.state(:ensure)
137
+ assert_nothing_raised {
138
+ state.class.valueslice(:absent, :running).each do |st|
139
+ [:up, :down].each do |m|
140
+ if st[m]
141
+ methods << st[m]
142
+ end
143
+ end
144
+ end
145
+ }
146
+
147
+ methods.each do |m|
148
+ assert(Puppet::Type.type(:zone).method_defined?(m),
149
+ "Zones do not define method %s" % m)
150
+ end
151
+
152
+ end
153
+
154
+ # Make sure our state generates the correct text.
155
+ def test_inherit_state
156
+ zone = mkzone("configtesting")
157
+ zone[:ensure] = :configured
158
+
159
+ assert_nothing_raised {
160
+ zone[:inherit] = "/usr"
161
+ }
162
+ state = zone.state(:inherit)
163
+ assert(zone, "Did not get 'inherit' state")
164
+
165
+ assert_equal("add inherit-pkg-dir\nset dir=/usr\nend", state.configtext,
166
+ "Got incorrect config text")
167
+
168
+ state.is = "/usr"
169
+
170
+ assert_equal("", state.configtext,
171
+ "Got incorrect config text")
172
+
173
+ # Now we want multiple directories
174
+ state.should = %w{/usr /sbin /lib}
175
+
176
+ # The statements are sorted
177
+ text = "add inherit-pkg-dir
178
+ set dir=/lib
179
+ end
180
+ add inherit-pkg-dir
181
+ set dir=/sbin
182
+ end"
183
+
184
+ assert_equal(text, state.configtext,
185
+ "Got incorrect config text")
186
+
187
+ state.is = %w{/usr /sbin /lib}
188
+ state.should = %w{/usr /sbin}
189
+
190
+ text = "remove inherit-pkg-dir dir=/lib"
191
+
192
+ assert_equal(text, state.configtext,
193
+ "Got incorrect config text")
194
+ end
195
+
196
+ if Process.uid == 0
197
+ # Make sure our ensure process actually works.
198
+ def test_ensure_sync
199
+ zone = mkzone("ensuretesting")
200
+
201
+ zone[:ensure] = :configured
202
+
203
+ zone.retrieve
204
+ assert_apply(zone)
205
+
206
+ zone.retrieve
207
+
208
+ assert(zone.insync?, "Zone is not insync")
209
+ end
210
+
211
+ def test_getconfig
212
+ zone = mkzone("configtesting")
213
+
214
+ base = tempfile()
215
+ zone[:path] = base
216
+
217
+ ip = "192.168.0.1"
218
+ interface = "bge0"
219
+ zone[:ip] = "#{interface}:#{ip}"
220
+
221
+ IO.popen("zonecfg -z configtesting -f -", "w") do |f|
222
+ f.puts %{create -b
223
+ set zonepath=#{tempfile()}
224
+ set autoboot=true
225
+ add inherit-pkg-dir
226
+ set dir=/lib
227
+ end
228
+ add inherit-pkg-dir
229
+ set dir=/platform
230
+ end
231
+ add inherit-pkg-dir
232
+ set dir=/sbin
233
+ end
234
+ add inherit-pkg-dir
235
+ set dir=/opt/csw
236
+ end
237
+ add inherit-pkg-dir
238
+ set dir=/usr
239
+ end
240
+ add net
241
+ set address=#{ip}
242
+ set physical=bge0
243
+ end
244
+ }
245
+ end
246
+
247
+ assert_equal(0, $?, "Did not successfully create zone")
248
+
249
+ #@@zones << "configtesting"
250
+
251
+ assert_nothing_raised {
252
+ zone.send(:getconfig)
253
+ }
254
+
255
+ # Now, make sure everything is right.
256
+ assert_equal(%w{/sbin /usr /opt/csw /lib /platform}.sort,
257
+ zone.is(:inherit).sort, "Inherited dirs did not get collected correctly."
258
+ )
259
+
260
+ assert_equal(["#{interface}:#{ip}"], zone.is(:ip),
261
+ "IP addresses did not get collected correctly.")
262
+
263
+ assert_equal(:true, zone.is(:autoboot),
264
+ "Autoboot did not get collected correctly.")
265
+ end
266
+
267
+ # Make sure we can do all the various and sundry configuring things.
268
+ def test_configuring_zones
269
+ zone = mkzone("configtesting")
270
+
271
+ assert_nothing_raised {
272
+ zone[:inherit] = "/usr"
273
+ }
274
+
275
+ zone[:ensure] = :configured
276
+
277
+ zone.retrieve
278
+ assert_apply(zone)
279
+
280
+ zone.retrieve
281
+
282
+ assert(zone.insync?, "Zone is not insync")
283
+
284
+ # Now add a new directory to inherit
285
+ assert_nothing_raised {
286
+ zone[:inherit] = ["/sbin", "/usr"]
287
+ }
288
+ assert_apply(zone)
289
+
290
+ zone.retrieve
291
+
292
+ assert(zone.insync?, "Zone is not insync")
293
+
294
+ assert(%x{/usr/sbin/zonecfg -z #{zone[:name]} info} =~ /dir: \/sbin/,
295
+ "sbin was not added")
296
+
297
+ # And then remove it.
298
+ assert_nothing_raised {
299
+ zone[:inherit] = "/usr"
300
+ }
301
+ assert_apply(zone)
302
+
303
+ zone.retrieve
304
+
305
+ assert(zone.insync?, "Zone is not insync")
306
+
307
+ assert(%x{/usr/sbin/zonecfg -z #{zone[:name]} info} !~ /dir: \/sbin/,
308
+ "sbin was not removed")
309
+
310
+ # Now add an ip adddress. Fortunately (or not), zonecfg doesn't verify
311
+ # that the interface exists.
312
+ zone[:ip] = "hme0:192.168.0.1"
313
+
314
+ zone.retrieve
315
+ assert(! zone.insync?, "Zone is marked as in sync")
316
+
317
+ assert_apply(zone)
318
+ zone.retrieve
319
+ assert(zone.insync?, "Zone is not in sync")
320
+ assert(%x{/usr/sbin/zonecfg -z #{zone[:name]} info} =~ /192.168.0.1/,
321
+ "ip was not added")
322
+ zone[:ip] = ["hme1:192.168.0.2", "hme0:192.168.0.1"]
323
+ assert_apply(zone)
324
+ zone.retrieve
325
+ assert(zone.insync?, "Zone is not in sync")
326
+ assert(%x{/usr/sbin/zonecfg -z #{zone[:name]} info} =~ /192.168.0.2/,
327
+ "ip was not added")
328
+ zone[:ip] = ["hme1:192.168.0.2"]
329
+ assert_apply(zone)
330
+ zone.retrieve
331
+ assert(%x{/usr/sbin/zonecfg -z #{zone[:name]} info} !~ /192.168.0.1/,
332
+ "ip was not removed")
333
+ end
334
+
335
+ # Test creating and removing a zone, but only up to the configured state,
336
+ # so it's faster.
337
+ def test_smallcreate
338
+ zone = mkzone("smallcreate")
339
+ # Include a bunch of stuff so the zone isn't as large
340
+ dirs = %w{/usr /sbin /lib /platform}
341
+
342
+ %w{/opt/csw}.each do |dir|
343
+ dirs << dir if FileTest.exists? dir
344
+ end
345
+ zone[:inherit] = dirs
346
+
347
+ assert(zone, "Did not make zone")
348
+
349
+ zone[:ensure] = :configured
350
+
351
+ assert(! zone.insync?, "Zone is incorrectly in sync")
352
+
353
+ assert_apply(zone)
354
+
355
+ assert_nothing_raised {
356
+ zone.retrieve
357
+ }
358
+ assert(zone.insync?, "Zone is incorrectly out of sync")
359
+
360
+ zone[:ensure] = :absent
361
+
362
+ assert_apply(zone)
363
+
364
+ zone.retrieve
365
+
366
+ assert_equal(:absent, zone.is(:ensure), "Zone is not absent")
367
+ end
368
+
369
+ # Just go through each method linearly and make sure it works.
370
+ def test_each_method
371
+ zone = mkzone("methodtesting")
372
+ dirs = %w{/usr /sbin /lib /platform}
373
+
374
+ %w{/opt/csw}.each do |dir|
375
+ dirs << dir if FileTest.exists? dir
376
+ end
377
+ zone[:inherit] = dirs
378
+
379
+ [[:configure, :configured],
380
+ [:install, :installed],
381
+ [:start, :running],
382
+ [:stop, :installed],
383
+ [:uninstall, :configured],
384
+ [:unconfigure, :absent]
385
+ ].each do |method, state|
386
+ Puppet.info "Testing %s" % method
387
+ assert_nothing_raised {
388
+ zone.retrieve
389
+ }
390
+ assert_nothing_raised {
391
+ zone.send(method)
392
+ }
393
+ assert_nothing_raised {
394
+ zone.retrieve
395
+ }
396
+ assert_equal(state, zone.is(:ensure),
397
+ "Method %s did not correctly set state %s" %
398
+ [method, state])
399
+ end
400
+ end
401
+
402
+ def test_mkzone
403
+ zone = mkzone("testmaking")
404
+ # Include a bunch of stuff so the zone isn't as large
405
+ dirs = %w{/usr /sbin /lib /platform}
406
+
407
+ %w{/opt/csw}.each do |dir|
408
+ dirs << dir if FileTest.exists? dir
409
+ end
410
+ zone[:inherit] = dirs
411
+
412
+ assert(zone, "Did not make zone")
413
+
414
+
415
+ [:configured, :installed, :running, :installed, :absent].each do |value|
416
+ assert_nothing_raised {
417
+ zone[:ensure] = value
418
+ }
419
+ assert(! zone.insync?, "Zone is incorrectly in sync")
420
+
421
+ assert_apply(zone)
422
+
423
+ assert_nothing_raised {
424
+ zone.retrieve
425
+ }
426
+ assert(zone.insync?, "Zone is incorrectly out of sync")
427
+ end
428
+
429
+ zone.retrieve
430
+
431
+ assert_equal(:absent, zone.is(:ensure), "Zone is not absent")
432
+ end
433
+ end
434
+ end
435
+ end
436
+
437
+ # $Id: zone.rb 1329 2006-06-28 18:51:11Z luke $