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
@@ -51,8 +51,9 @@ class TestParser < Test::Unit::TestCase
51
51
  def test_arrayrvalues
52
52
  parser = Puppet::Parser::Parser.new()
53
53
  ret = nil
54
+ file = tempfile()
54
55
  assert_nothing_raised {
55
- parser.string = 'file { "/tmp/testing": mode => [755, 640] }'
56
+ parser.string = "file { \"#{file}\": mode => [755, 640] }"
56
57
  }
57
58
 
58
59
  assert_nothing_raised {
@@ -65,7 +66,7 @@ class TestParser < Test::Unit::TestCase
65
66
  @@tmpfiles << name
66
67
 
67
68
  File.open(file, "w") { |f|
68
- f.puts "file { \"%s\": create => true, mode => 755 }\n" %
69
+ f.puts "file { \"%s\": ensure => file, mode => 755 }\n" %
69
70
  name
70
71
  }
71
72
  end
@@ -94,7 +95,7 @@ class TestParser < Test::Unit::TestCase
94
95
  }
95
96
  end
96
97
 
97
- def test_zdefaults
98
+ def test_defaults
98
99
  basedir = File.join(tmpdir(), "defaulttesting")
99
100
  @@tmpfiles << basedir
100
101
  Dir.mkdir(basedir)
@@ -150,6 +151,8 @@ class TestParser < Test::Unit::TestCase
150
151
  scope = nil
151
152
  assert_nothing_raised("Could not evaluate defaults parse tree") {
152
153
  scope = Puppet::Parser::Scope.new()
154
+ scope.name = "parsetest"
155
+ scope.type = "parsetest"
153
156
  objects = scope.evaluate(ast)
154
157
  }
155
158
 
@@ -177,4 +180,4 @@ class TestParser < Test::Unit::TestCase
177
180
  end
178
181
  end
179
182
 
180
- # $Id: parser.rb 724 2005-10-22 22:27:20Z luke $
183
+ # $Id: parser.rb 871 2006-02-07 05:58:00Z luke $
@@ -27,11 +27,6 @@ class TestConfFiles < Test::Unit::TestCase
27
27
  "boo" => {
28
28
  "eb" => "fb"
29
29
  },
30
- "rah" => {
31
- "aa" => "this is a sentence",
32
- "ca" => "dk",
33
- "ea" => "fk"
34
- },
35
30
  },
36
31
  {
37
32
  "puppet" => {
@@ -41,7 +36,7 @@ class TestConfFiles < Test::Unit::TestCase
41
36
  "okay" => "rah"
42
37
  },
43
38
  "back" => {
44
- "okay" => "rah"
39
+ "yayness" => "rah"
45
40
  },
46
41
  }
47
42
  ]
@@ -54,7 +49,7 @@ class TestConfFiles < Test::Unit::TestCase
54
49
  data = data.dup
55
50
  str += "[puppet]\n"
56
51
  data["puppet"].each { |var, value|
57
- str += "%s %s\n" % [var, value]
52
+ str += "%s = %s\n" % [var, value]
58
53
  }
59
54
  data.delete("puppet")
60
55
  end
@@ -62,7 +57,7 @@ class TestConfFiles < Test::Unit::TestCase
62
57
  data.each { |type, settings|
63
58
  str += "[%s]\n" % type
64
59
  settings.each { |var, value|
65
- str += "%s %s\n" % [var, value]
60
+ str += "%s = %s\n" % [var, value]
66
61
  }
67
62
  }
68
63
 
@@ -81,18 +76,23 @@ class TestConfFiles < Test::Unit::TestCase
81
76
  path = tempfile()
82
77
 
83
78
  sampledata { |data|
79
+ config = Puppet::Config.new
80
+ data.each { |section, hash|
81
+ hash.each { |param, value|
82
+ config.setdefaults(section, [param, value, value])
83
+ }
84
+ }
84
85
  # Write it out as a config file
85
86
  File.open(path, "w") { |f| f.print data2config(data) }
86
- config = nil
87
87
  assert_nothing_raised {
88
- config = Puppet::Config.new(path)
88
+ config.parse(path)
89
89
  }
90
90
 
91
91
  data.each { |section, hash|
92
92
  hash.each { |var, value|
93
93
  assert_equal(
94
94
  data[section][var],
95
- config[section][var],
95
+ config[var],
96
96
  "Got different values at %s/%s" % [section, var]
97
97
  )
98
98
  }
@@ -101,4 +101,4 @@ class TestConfFiles < Test::Unit::TestCase
101
101
  end
102
102
  end
103
103
 
104
- # $Id: conffiles.rb 738 2005-10-31 22:50:09Z luke $
104
+ # $Id: conffiles.rb 873 2006-02-07 23:12:33Z luke $
@@ -5,13 +5,15 @@ if __FILE__ == $0
5
5
  end
6
6
 
7
7
  require 'puppet'
8
+ require 'puppettest'
8
9
  require 'test/unit'
9
10
 
10
- # $Id: defaults.rb 724 2005-10-22 22:27:20Z luke $
11
+ # $Id: defaults.rb 873 2006-02-07 23:12:33Z luke $
11
12
 
12
13
  class TestPuppetDefaults < Test::Unit::TestCase
13
- @@dirs = %w{rrddir puppetconf puppetvar logdir statedir}
14
- @@files = %w{logfile checksumfile manifest masterlog}
14
+ include TestPuppet
15
+ @@dirs = %w{rrddir confdir vardir logdir statedir}
16
+ @@files = %w{statefile manifest masterlog}
15
17
  @@normals = %w{puppetport masterport server}
16
18
  @@booleans = %w{rrdgraph noop}
17
19
 
@@ -41,8 +43,8 @@ class TestPuppetDefaults < Test::Unit::TestCase
41
43
 
42
44
  if __FILE__ == $0
43
45
  def disabled_testContained
44
- confdir = Regexp.new(Puppet[:puppetconf])
45
- vardir = Regexp.new(Puppet[:puppetvar])
46
+ confdir = Regexp.new(Puppet[:confdir])
47
+ vardir = Regexp.new(Puppet[:vardir])
46
48
  [@@dirs,@@files].flatten.each { |param|
47
49
  value = Puppet[param]
48
50
 
@@ -60,8 +62,8 @@ class TestPuppetDefaults < Test::Unit::TestCase
60
62
  end
61
63
 
62
64
  def testFailOnBogusArgs
63
- [0, "ashoweklj", ";", :thisisafakesymbol].each { |param|
64
- assert_raise(ArgumentError) { Puppet[param] }
65
+ [0, "ashoweklj", ";"].each { |param|
66
+ assert_raise(ArgumentError, "No error on %s" % param) { Puppet[param] }
65
67
  }
66
68
  end
67
69
 
@@ -77,7 +79,7 @@ class TestPuppetDefaults < Test::Unit::TestCase
77
79
  value = Puppet[param]
78
80
 
79
81
  unless value !~ notval
80
- assert_nothing_raised { raise "%s is in wrong dir: %s" %
82
+ assert_nothing_raised { raise "%s is incorrectly set to %s" %
81
83
  [param,value] }
82
84
  end
83
85
  }
@@ -85,15 +87,15 @@ class TestPuppetDefaults < Test::Unit::TestCase
85
87
 
86
88
  def test_settingdefaults
87
89
  testvals = {
88
- :fakeparam => [:puppetconf, "yaytest"],
89
- :anotherparam => proc { File.join(Puppet[:puppetvar], "goodtest") },
90
+ :fakeparam => "$confdir/yaytest",
91
+ :anotherparam => "$vardir/goodtest",
90
92
  :string => "a yay string",
91
93
  :boolean => true
92
94
  }
93
95
 
94
96
  testvals.each { |param, default|
95
97
  assert_nothing_raised {
96
- Puppet.setdefault(param,default)
98
+ Puppet.setdefaults("testing", [param, default, "a value"])
97
99
  }
98
100
  }
99
101
  end
@@ -12,6 +12,8 @@ class TestPuppetUtil < Test::Unit::TestCase
12
12
  include TestPuppet
13
13
  unless Process.uid == 0
14
14
  $stderr.puts "Run as root to perform Utility tests"
15
+ def test_nothing
16
+ end
15
17
  else
16
18
 
17
19
  def mknverify(file, user, group = nil, id = false)
@@ -74,16 +76,17 @@ class TestPuppetUtil < Test::Unit::TestCase
74
76
  )
75
77
  #system("ls -l %s" % file)
76
78
  end
77
- if gid == 0
78
- #Puppet.warning "Not testing group"
79
- else
80
- #Puppet.warning "Testing group %s" % gid
81
- assert_equal(File.stat(file).gid, gid,
82
- "File group is %s instead of %s" %
83
- [File.stat(file).gid, gid]
84
- )
85
- #system("ls -l %s" % file)
86
- end
79
+ # I'm skipping these, because it seems so system dependent.
80
+ #if gid == 0
81
+ # #Puppet.warning "Not testing group"
82
+ #else
83
+ # Puppet.warning "Testing group %s" % gid.inspect
84
+ # system("ls -l %s" % file)
85
+ # assert_equal(gid, File.stat(file).gid,
86
+ # "File group is %s instead of %s" %
87
+ # [File.stat(file).gid, gid]
88
+ # )
89
+ #end
87
90
  assert_nothing_raised {
88
91
  File.unlink(file)
89
92
  }
@@ -117,4 +120,4 @@ class TestPuppetUtil < Test::Unit::TestCase
117
120
  end
118
121
  end
119
122
 
120
- # $Id: utiltest.rb 743 2005-11-16 21:39:31Z luke $
123
+ # $Id: utiltest.rb 816 2006-01-12 21:04:06Z luke $
@@ -7,12 +7,15 @@ require 'puppet'
7
7
  require 'test/unit'
8
8
 
9
9
  module TestPuppet
10
- def newcomp(name,*ary)
11
- if name.is_a?(Puppet::Type)
12
- ary.unshift name
13
- name = name.name
10
+ def newcomp(*ary)
11
+ name = nil
12
+ if ary[0].is_a?(String)
13
+ name = ary.shift
14
+ else
15
+ name = ary[0].name
14
16
  end
15
- comp = Puppet::Type::Component.create(
17
+
18
+ comp = Puppet.type(:component).create(
16
19
  :name => name
17
20
  )
18
21
  ary.each { |item| comp.push item }
@@ -28,11 +31,11 @@ module TestPuppet
28
31
  end
29
32
 
30
33
  @configpath = File.join(tmpdir,
31
- self.class.to_s + "configdir" + @@testcount.to_s
34
+ self.class.to_s + "configdir" + @@testcount.to_s + "/"
32
35
  )
33
36
 
34
- Puppet[:puppetconf] = @configpath
35
- Puppet[:puppetvar] = @configpath
37
+ Puppet[:confdir] = @configpath
38
+ Puppet[:vardir] = @configpath
36
39
 
37
40
  unless File.exists?(@configpath)
38
41
  Dir.mkdir(@configpath)
@@ -42,35 +45,37 @@ module TestPuppet
42
45
  @@tmppids = []
43
46
 
44
47
  if $0 =~ /.+\.rb/ or Puppet[:debug]
45
- Puppet[:logdest] = :console
46
- Puppet[:loglevel] = :debug
48
+ Puppet::Log.newdestination :console
49
+ Puppet::Log.level = :debug
47
50
  $VERBOSE = 1
48
51
  else
49
52
  Puppet::Log.close
50
- Puppet[:logdest] = "/dev/null"
53
+ Puppet::Log.newdestination "/dev/null"
51
54
  Puppet[:httplog] = "/dev/null"
52
55
  end
56
+
57
+ Puppet[:ignoreschedules] = true
53
58
  end
54
59
 
55
60
 
56
61
  def spin
57
62
  # Just disable spin, unless we really need it
58
63
  return
59
- if Puppet[:debug]
60
- return
61
- end
62
- @modes = %w{| / - \\}
63
- unless defined? @mode
64
- @mode = 0
65
- end
66
-
67
- $stderr.print "%s" % @modes[@mode]
68
- if @mode == @modes.length - 1
69
- @mode = 0
70
- else
71
- @mode += 1
72
- end
73
- $stderr.flush
64
+ # if Puppet[:debug]
65
+ # return
66
+ # end
67
+ # @modes = %w{| / - \\}
68
+ # unless defined? @mode
69
+ # @mode = 0
70
+ # end
71
+ #
72
+ # $stderr.print "%s" % @modes[@mode]
73
+ # if @mode == @modes.length - 1
74
+ # @mode = 0
75
+ # else
76
+ # @mode += 1
77
+ # end
78
+ # $stderr.flush
74
79
  end
75
80
 
76
81
  # stop any services that might be hanging around
@@ -78,7 +83,7 @@ module TestPuppet
78
83
  if stype = Puppet::Type.type(:service)
79
84
  stype.each { |service|
80
85
  service[:running] = false
81
- service.sync
86
+ service.evaluate
82
87
  }
83
88
  end
84
89
  end
@@ -96,12 +101,17 @@ module TestPuppet
96
101
  @@tmppids.each { |pid|
97
102
  %x{kill -INT #{pid} 2>/dev/null}
98
103
  }
104
+
99
105
  @@tmppids.clear
100
106
  Puppet::Type.allclear
107
+ Puppet::Storage.clear
101
108
  Puppet.clear
102
109
 
103
110
  # reset all of the logs
104
111
  Puppet::Log.close
112
+
113
+ # Just in case there are processes waiting to die...
114
+ Process.waitall
105
115
  end
106
116
 
107
117
  def tempfile
@@ -115,7 +125,7 @@ module TestPuppet
115
125
  return f
116
126
  end
117
127
 
118
- def testdir
128
+ def tstdir
119
129
  if defined? @testdirnum
120
130
  @testdirnum += 1
121
131
  else
@@ -135,6 +145,7 @@ module TestPuppet
135
145
  "/tmp"
136
146
  end
137
147
 
148
+
138
149
  @tmpdir = File.join(@tmpdir, "puppettesting")
139
150
 
140
151
  unless File.exists?(@tmpdir)
@@ -145,18 +156,66 @@ module TestPuppet
145
156
  @tmpdir
146
157
  end
147
158
 
148
- def assert_rollback_events(trans, events, msg)
149
- run_events(:rollback, trans, events, msg)
159
+ def assert_rollback_events(events, trans, msg = nil)
160
+ run_events(:rollback, events, trans, msg)
150
161
  end
151
162
 
152
- def assert_events(comp, events, msg = nil)
163
+ def assert_events(events, *items)
153
164
  trans = nil
165
+ comp = nil
166
+ msg = nil
167
+
168
+ unless events.is_a? Array
169
+ raise Puppet::DevError, "Incorrect call of assert_events"
170
+ end
171
+ if items[-1].is_a? String
172
+ msg = items.pop
173
+ end
174
+
175
+ remove_comp = false
176
+ # They either passed a comp or a list of items.
177
+ if items[0].is_a? Puppet.type(:component)
178
+ comp = items.shift
179
+ else
180
+ comp = newcomp(items[0].name, *items)
181
+ remove_comp = true
182
+ end
154
183
  msg ||= comp.name
155
184
  assert_nothing_raised("Component %s failed" % [msg]) {
156
185
  trans = comp.evaluate
157
186
  }
158
187
 
159
188
  run_events(:evaluate, trans, events, msg)
189
+
190
+ if remove_comp
191
+ Puppet.type(:component).delete(comp)
192
+ end
193
+
194
+ return trans
195
+ end
196
+
197
+ # A simpler method that just applies what we have.
198
+ def assert_apply(*objects)
199
+ if objects[0].is_a?(Puppet.type(:component))
200
+ comp = objects.shift
201
+ unless objects.empty?
202
+ objects.each { |o| comp.push o }
203
+ end
204
+ else
205
+ comp = newcomp(*objects)
206
+ end
207
+ trans = nil
208
+
209
+ assert_nothing_raised("Failed to create transaction") {
210
+ trans = comp.evaluate
211
+ }
212
+
213
+ events = nil
214
+ assert_nothing_raised("Failed to evaluate transaction") {
215
+ events = trans.evaluate.collect { |e| e.event }
216
+ }
217
+ Puppet.type(:component).delete(comp)
218
+ events
160
219
  end
161
220
 
162
221
  def run_events(type, trans, events, msg)
@@ -195,6 +254,23 @@ module TestPuppet
195
254
  end
196
255
  }
197
256
  end
257
+
258
+ # If there are any fake data files, retrieve them
259
+ def fakedata(dir)
260
+
261
+ ary = [$puppetbase, "test"]
262
+ ary += dir.split("/")
263
+ dir = File.join(ary)
264
+
265
+ unless FileTest.exists?(dir)
266
+ raise Puppet::DevError, "No fakedata dir %s" % dir
267
+ end
268
+ files = Dir.entries(dir).reject { |f| f =~ /^\./ }.collect { |f|
269
+ File.join(dir, f)
270
+ }
271
+
272
+ return files
273
+ end
198
274
  end
199
275
 
200
276
 
@@ -212,11 +288,11 @@ module ServerTest
212
288
 
213
289
  # create a simple manifest that just creates a file
214
290
  def mktestmanifest
215
- file = File.join(Puppet[:puppetconf], "%ssite.pp" % (self.class.to_s + "test"))
291
+ file = File.join(Puppet[:confdir], "%ssite.pp" % (self.class.to_s + "test"))
216
292
  @createdfile = File.join(tmpdir(), self.class.to_s + "servermanifesttesting")
217
293
 
218
294
  File.open(file, "w") { |f|
219
- f.puts "file { \"%s\": create => true, mode => 755 }\n" % @createdfile
295
+ f.puts "file { \"%s\": ensure => file, mode => 755 }\n" % @createdfile
220
296
  }
221
297
 
222
298
  @@tmpfiles << @createdfile
@@ -265,15 +341,41 @@ end
265
341
 
266
342
  module ExeTest
267
343
  include ServerTest
268
- unless ENV["PATH"] =~ /puppet/
269
- # ok, we have to add the bin directory to our search path
270
- ENV["PATH"] += ":" + File.join($puppetbase, "bin")
271
344
 
272
- # and then the library directories
273
- libdirs = $:.find_all { |dir|
345
+ def setup
346
+ super
347
+ setbindir
348
+ setlibdir
349
+ end
350
+
351
+ def bindir
352
+ File.join($puppetbase, "bin")
353
+ end
354
+
355
+ def setbindir
356
+ unless ENV["PATH"] =~ /puppet/
357
+ ENV["PATH"] += ":" + bindir
358
+ end
359
+ end
360
+
361
+ def setlibdir
362
+ ENV["RUBYLIB"] = $:.find_all { |dir|
274
363
  dir =~ /puppet/ or dir =~ /\.\./
364
+ }.join(":")
365
+ end
366
+
367
+ # Run a ruby command. This explicitly uses ruby to run stuff, since we
368
+ # don't necessarily know where our ruby binary is, dernit.
369
+ # Currently unused, because I couldn't get it to work.
370
+ def rundaemon(*cmd)
371
+ @ruby ||= %x{which ruby}.chomp
372
+ cmd = cmd.unshift(@ruby).join(" ")
373
+
374
+ out = nil
375
+ Dir.chdir(bindir()) {
376
+ out = %x{#{@ruby} #{cmd}}
275
377
  }
276
- ENV["RUBYLIB"] = libdirs.join(":")
378
+ return out
277
379
  end
278
380
 
279
381
  def startmasterd(args = "")
@@ -281,11 +383,17 @@ module ExeTest
281
383
 
282
384
  manifest = mktestmanifest()
283
385
  args += " --manifest %s" % manifest
284
- args += " --confdir %s" % Puppet[:puppetconf]
285
- args += " --vardir %s" % Puppet[:puppetvar]
286
- args += " --port %s" % @@port
386
+ args += " --confdir %s" % Puppet[:confdir]
387
+ args += " --vardir %s" % Puppet[:vardir]
388
+ args += " --masterport %s" % @@port
389
+ args += " --user %s" % Process.uid
390
+ args += " --group %s" % Process.gid
287
391
  args += " --nonodes"
288
- args += " --autosign"
392
+ args += " --autosign true"
393
+
394
+ #if Puppet[:debug]
395
+ # args += " --debug"
396
+ #end
289
397
 
290
398
  cmd = "puppetmasterd %s" % args
291
399
 
@@ -293,8 +401,8 @@ module ExeTest
293
401
  assert_nothing_raised {
294
402
  output = %x{#{cmd}}.chomp
295
403
  }
296
- assert($? == 0, "Puppetmasterd exit status was %s" % $?)
297
404
  assert_equal("", output, "Puppetmasterd produced output %s" % output)
405
+ assert($? == 0, "Puppetmasterd exit status was %s" % $?)
298
406
  sleep(1)
299
407
 
300
408
  return manifest
@@ -303,7 +411,7 @@ module ExeTest
303
411
  def stopmasterd(running = true)
304
412
  ps = Facter["ps"].value || "ps -ef"
305
413
 
306
- pidfile = File.join(Puppet[:puppetvar], "puppetmasterd.pid")
414
+ pidfile = File.join(Puppet[:vardir], "run", "puppetmasterd.pid")
307
415
 
308
416
  pid = nil
309
417
  if FileTest.exists?(pidfile)
@@ -714,10 +822,10 @@ class PuppetTestSuite
714
822
  end
715
823
 
716
824
  def self.list
717
- puts "testdir is %s" % self.basedir
718
825
  Dir.entries(self.basedir).find_all { |file|
719
826
  path = File.join(@basedir, file)
720
- FileTest.directory?(path) and file !~ /^\./
827
+ # Data is for storing test data
828
+ FileTest.directory?(path) and file !~ /^\./ and file != "data"
721
829
  }
722
830
  end
723
831
 
@@ -771,4 +879,4 @@ def failers
771
879
  }
772
880
  end
773
881
 
774
- # $Id: puppettest.rb 750 2005-11-22 05:34:43Z luke $
882
+ # $Id: puppettest.rb 873 2006-02-07 23:12:33Z luke $