puppet 0.24.1 → 0.24.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 (266) hide show
  1. data/CHANGELOG +94 -0
  2. data/Rakefile +0 -4
  3. data/bin/puppet +18 -10
  4. data/bin/puppetd +1 -1
  5. data/bin/puppetdoc +14 -4
  6. data/bin/puppetmasterd +1 -1
  7. data/bin/puppetrun +3 -8
  8. data/bin/ralsh +12 -11
  9. data/conf/freebsd/puppetd +1 -1
  10. data/conf/freebsd/puppetmasterd +1 -1
  11. data/conf/gentoo/puppet/puppet.conf +29 -0
  12. data/conf/namespaceauth.conf +20 -0
  13. data/conf/redhat/puppet.spec +4 -1
  14. data/conf/solaris/smf/puppetd.xml +1 -1
  15. data/conf/solaris/smf/puppetmasterd.xml +1 -1
  16. data/conf/suse/puppet.spec +10 -8
  17. data/examples/root/etc/puppet/{puppetmasterd.conf → puppet.conf} +6 -3
  18. data/ext/logcheck/puppet +7 -0
  19. data/ext/puppet-test +28 -5
  20. data/lib/puppet.rb +2 -1
  21. data/lib/puppet/defaults.rb +12 -5
  22. data/lib/puppet/dsl.rb +43 -45
  23. data/lib/puppet/external/{gratr/rdot.rb → dot.rb} +0 -0
  24. data/lib/puppet/external/nagios.rb +50 -0
  25. data/lib/puppet/external/nagios/base.rb +421 -0
  26. data/lib/puppet/external/nagios/parser.rb +816 -0
  27. data/lib/puppet/file_serving/file_base.rb +16 -3
  28. data/lib/puppet/file_serving/metadata.rb +29 -11
  29. data/lib/puppet/indirector/terminus.rb +1 -0
  30. data/lib/puppet/metatype/closure.rb +4 -0
  31. data/lib/puppet/metatype/evaluation.rb +2 -17
  32. data/lib/puppet/metatype/metaparams.rb +1 -1
  33. data/lib/puppet/network.rb +3 -0
  34. data/lib/puppet/network/client.rb +4 -5
  35. data/lib/puppet/network/client/master.rb +10 -7
  36. data/lib/puppet/network/handler/fileserver.rb +22 -45
  37. data/lib/puppet/network/http_pool.rb +3 -0
  38. data/lib/puppet/network/http_server/mongrel.rb +7 -1
  39. data/lib/puppet/network/http_server/webrick.rb +4 -3
  40. data/lib/puppet/network/xmlrpc/client.rb +12 -1
  41. data/lib/puppet/node/catalog.rb +51 -40
  42. data/lib/puppet/parser/ast.rb +27 -49
  43. data/lib/puppet/parser/ast/astarray.rb +5 -24
  44. data/lib/puppet/parser/ast/caseopt.rb +4 -4
  45. data/lib/puppet/parser/ast/casestatement.rb +4 -5
  46. data/lib/puppet/parser/ast/collection.rb +3 -5
  47. data/lib/puppet/parser/ast/collexpr.rb +3 -5
  48. data/lib/puppet/parser/ast/definition.rb +148 -159
  49. data/lib/puppet/parser/ast/else.rb +2 -3
  50. data/lib/puppet/parser/ast/function.rb +3 -10
  51. data/lib/puppet/parser/ast/hostclass.rb +66 -59
  52. data/lib/puppet/parser/ast/ifstatement.rb +4 -5
  53. data/lib/puppet/parser/ast/leaf.rb +6 -6
  54. data/lib/puppet/parser/ast/node.rb +26 -58
  55. data/lib/puppet/parser/ast/resource.rb +5 -7
  56. data/lib/puppet/parser/ast/resource_defaults.rb +2 -4
  57. data/lib/puppet/parser/ast/resource_override.rb +4 -6
  58. data/lib/puppet/parser/ast/resource_reference.rb +2 -4
  59. data/lib/puppet/parser/ast/resourceparam.rb +2 -4
  60. data/lib/puppet/parser/ast/selector.rb +5 -6
  61. data/lib/puppet/parser/ast/tag.rb +2 -4
  62. data/lib/puppet/parser/ast/vardef.rb +3 -4
  63. data/lib/puppet/parser/collector.rb +5 -5
  64. data/lib/puppet/parser/{compile.rb → compiler.rb} +69 -107
  65. data/lib/puppet/parser/functions.rb +3 -3
  66. data/lib/puppet/parser/interpreter.rb +32 -23
  67. data/lib/puppet/parser/lexer.rb +391 -282
  68. data/lib/puppet/parser/parser.rb +5 -4
  69. data/lib/puppet/parser/parser_support.rb +3 -6
  70. data/lib/puppet/parser/resource.rb +24 -36
  71. data/lib/puppet/parser/resource/param.rb +1 -1
  72. data/lib/puppet/parser/resource/reference.rb +7 -3
  73. data/lib/puppet/parser/scope.rb +12 -7
  74. data/lib/puppet/parser/templatewrapper.rb +1 -1
  75. data/lib/puppet/pgraph.rb +9 -98
  76. data/lib/puppet/provider/interface/redhat.rb +65 -65
  77. data/lib/puppet/provider/mount/parsed.rb +1 -1
  78. data/lib/puppet/provider/naginator.rb +55 -0
  79. data/lib/puppet/provider/nameservice/directoryservice.rb +6 -7
  80. data/lib/puppet/provider/package/fink.rb +0 -2
  81. data/lib/puppet/provider/package/gem.rb +9 -5
  82. data/lib/puppet/provider/package/openbsd.rb +1 -1
  83. data/lib/puppet/provider/package/pkgdmg.rb +3 -8
  84. data/lib/puppet/provider/package/portage.rb +4 -4
  85. data/lib/puppet/provider/package/yumhelper.py +8 -6
  86. data/lib/puppet/provider/parsedfile.rb +7 -1
  87. data/lib/puppet/provider/service/debian.rb +2 -0
  88. data/lib/puppet/provider/service/gentoo.rb +4 -0
  89. data/lib/puppet/provider/service/init.rb +1 -1
  90. data/lib/puppet/provider/sshkey/parsed.rb +2 -0
  91. data/lib/puppet/provider/user/useradd.rb +1 -1
  92. data/lib/puppet/rails.rb +4 -0
  93. data/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb +17 -0
  94. data/lib/puppet/rails/fact_value.rb +4 -0
  95. data/lib/puppet/rails/host.rb +1 -2
  96. data/lib/puppet/rails/param_value.rb +4 -0
  97. data/lib/puppet/rails/resource_tag.rb +4 -0
  98. data/lib/puppet/rails/source_file.rb +4 -1
  99. data/lib/puppet/relationship.rb +5 -1
  100. data/lib/puppet/reports/tagmail.rb +12 -1
  101. data/lib/puppet/resource_reference.rb +1 -1
  102. data/lib/puppet/simple_graph.rb +78 -11
  103. data/lib/puppet/sslcertificates.rb +1 -1
  104. data/lib/puppet/sslcertificates/ca.rb +3 -3
  105. data/lib/puppet/transaction.rb +7 -4
  106. data/lib/puppet/transportable.rb +1 -1
  107. data/lib/puppet/type.rb +3 -10
  108. data/lib/puppet/type/cron.rb +18 -0
  109. data/lib/puppet/type/exec.rb +18 -12
  110. data/lib/puppet/type/{pfile.rb → file.rb} +66 -84
  111. data/lib/puppet/type/file/checksum.rb +271 -0
  112. data/lib/puppet/type/{pfile → file}/content.rb +10 -15
  113. data/lib/puppet/type/{pfile → file}/ensure.rb +15 -8
  114. data/lib/puppet/type/{pfile → file}/group.rb +0 -0
  115. data/lib/puppet/type/{pfile → file}/mode.rb +0 -0
  116. data/lib/puppet/type/{pfile → file}/owner.rb +0 -0
  117. data/lib/puppet/type/{pfile → file}/source.rb +34 -48
  118. data/lib/puppet/type/{pfile → file}/target.rb +0 -0
  119. data/lib/puppet/type/{pfile → file}/type.rb +0 -0
  120. data/lib/puppet/type/{pfilebucket.rb → filebucket.rb} +0 -0
  121. data/lib/puppet/type/host.rb +13 -0
  122. data/lib/puppet/type/mailalias.rb +1 -1
  123. data/lib/puppet/type/nagios_command.rb +3 -0
  124. data/lib/puppet/type/nagios_contact.rb +3 -0
  125. data/lib/puppet/type/nagios_contactgroup.rb +3 -0
  126. data/lib/puppet/type/nagios_host.rb +3 -0
  127. data/lib/puppet/type/nagios_hostextinfo.rb +3 -0
  128. data/lib/puppet/type/nagios_hostgroup.rb +3 -0
  129. data/lib/puppet/type/nagios_hostgroupescalation.rb +3 -0
  130. data/lib/puppet/type/nagios_service.rb +3 -0
  131. data/lib/puppet/type/nagios_servicedependency.rb +3 -0
  132. data/lib/puppet/type/nagios_serviceescalation.rb +3 -0
  133. data/lib/puppet/type/nagios_serviceextinfo.rb +3 -0
  134. data/lib/puppet/type/nagios_timeperiod.rb +3 -0
  135. data/lib/puppet/type/package.rb +4 -12
  136. data/lib/puppet/type/service.rb +9 -0
  137. data/lib/puppet/type/sshkey.rb +3 -3
  138. data/lib/puppet/util/autoload.rb +5 -5
  139. data/lib/puppet/util/checksums.rb +51 -13
  140. data/lib/puppet/util/constant_inflector.rb +14 -0
  141. data/lib/puppet/util/filetype.rb +1 -1
  142. data/lib/puppet/util/graph.rb +3 -9
  143. data/lib/puppet/util/nagios_maker.rb +57 -0
  144. data/lib/puppet/util/settings.rb +19 -16
  145. data/lib/puppet/util/tagging.rb +39 -0
  146. data/test/executables/puppetbin.rb +17 -0
  147. data/test/language/ast.rb +8 -58
  148. data/test/language/ast/casestatement.rb +3 -3
  149. data/test/language/ast/resource.rb +6 -7
  150. data/test/language/ast/resource_reference.rb +12 -12
  151. data/test/language/ast/selector.rb +2 -2
  152. data/test/language/ast/variable.rb +2 -2
  153. data/test/language/functions.rb +24 -24
  154. data/test/language/parser.rb +20 -8
  155. data/test/language/resource.rb +5 -42
  156. data/test/language/scope.rb +21 -37
  157. data/test/language/snippets.rb +7 -0
  158. data/test/lib/puppettest.rb +28 -14
  159. data/test/lib/puppettest/parsertesting.rb +10 -10
  160. data/test/lib/puppettest/support/resources.rb +1 -1
  161. data/test/network/client/master.rb +10 -0
  162. data/test/network/handler/fileserver.rb +51 -49
  163. data/test/network/server/webrick.rb +1 -1
  164. data/test/other/dsl.rb +3 -4
  165. data/test/other/transactions.rb +6 -4
  166. data/test/rails/ast.rb +2 -2
  167. data/test/rails/configuration.rb +1 -1
  168. data/test/rails/railsparameter.rb +2 -0
  169. data/test/rails/railsresource.rb +1 -0
  170. data/test/ral/manager/type.rb +4 -4
  171. data/test/ral/providers/cron/crontab.rb +3 -1
  172. data/test/ral/providers/package.rb +1 -1
  173. data/test/ral/{types → type}/basic.rb +2 -2
  174. data/test/ral/{types → type}/cron.rb +0 -0
  175. data/test/ral/{types → type}/exec.rb +42 -2
  176. data/test/ral/{types → type}/file.rb +34 -79
  177. data/test/ral/{types → type}/file/target.rb +0 -0
  178. data/test/ral/{types → type}/filebucket.rb +0 -0
  179. data/test/ral/{types → type}/fileignoresource.rb +0 -0
  180. data/test/ral/{types → type}/filesources.rb +8 -27
  181. data/test/ral/{types → type}/group.rb +0 -0
  182. data/test/ral/{types → type}/host.rb +16 -0
  183. data/test/ral/{types → type}/mailalias.rb +0 -0
  184. data/test/ral/{types → type}/parameter.rb +0 -0
  185. data/test/ral/{types → type}/port.rb +0 -0
  186. data/test/ral/{types → type}/property.rb +0 -0
  187. data/test/ral/{types → type}/resources.rb +0 -0
  188. data/test/ral/{types → type}/service.rb +0 -0
  189. data/test/ral/{types → type}/sshkey.rb +0 -0
  190. data/test/ral/{types → type}/tidy.rb +1 -0
  191. data/test/ral/{types → type}/user.rb +0 -0
  192. data/test/ral/{types → type}/yumrepo.rb +0 -0
  193. data/test/ral/{types → type}/zone.rb +0 -0
  194. data/test/util/autoload.rb +24 -5
  195. metadata +60 -107
  196. data/conf/gentoo/puppet/puppetca.conf +0 -29
  197. data/conf/gentoo/puppet/puppetd.conf +0 -29
  198. data/conf/gentoo/puppet/puppetmasterd.conf +0 -29
  199. data/examples/root/etc/puppet/puppetd.conf +0 -4
  200. data/lib/puppet/external/gratr.rb +0 -33
  201. data/lib/puppet/external/gratr/adjacency_graph.rb +0 -257
  202. data/lib/puppet/external/gratr/base.rb +0 -34
  203. data/lib/puppet/external/gratr/biconnected.rb +0 -116
  204. data/lib/puppet/external/gratr/chinese_postman.rb +0 -123
  205. data/lib/puppet/external/gratr/common.rb +0 -73
  206. data/lib/puppet/external/gratr/comparability.rb +0 -92
  207. data/lib/puppet/external/gratr/digraph.rb +0 -116
  208. data/lib/puppet/external/gratr/digraph_distance.rb +0 -185
  209. data/lib/puppet/external/gratr/dot.rb +0 -90
  210. data/lib/puppet/external/gratr/edge.rb +0 -145
  211. data/lib/puppet/external/gratr/graph.rb +0 -303
  212. data/lib/puppet/external/gratr/graph_api.rb +0 -83
  213. data/lib/puppet/external/gratr/import.rb +0 -44
  214. data/lib/puppet/external/gratr/labels.rb +0 -90
  215. data/lib/puppet/external/gratr/maximum_flow.rb +0 -64
  216. data/lib/puppet/external/gratr/search.rb +0 -409
  217. data/lib/puppet/external/gratr/strong_components.rb +0 -127
  218. data/lib/puppet/external/gratr/undirected_graph.rb +0 -153
  219. data/lib/puppet/rails/external/tagging/acts_as_taggable.rb +0 -62
  220. data/lib/puppet/rails/external/tagging/init.rb +0 -5
  221. data/lib/puppet/rails/external/tagging/tag.rb +0 -50
  222. data/lib/puppet/rails/external/tagging/tagging.rb +0 -12
  223. data/lib/puppet/rails/puppet_class.rb +0 -6
  224. data/lib/puppet/reference/node_source.rb +0 -9
  225. data/lib/puppet/reference/report.rb +0 -21
  226. data/lib/puppet/type/pfile/checksum.rb +0 -326
  227. data/test/language/ast/definition.rb +0 -166
  228. data/test/language/ast/hostclass.rb +0 -184
  229. data/test/language/compile.rb +0 -569
  230. data/test/language/lexer.rb +0 -276
  231. data/test/lib/mocha.rb +0 -19
  232. data/test/lib/mocha/any_instance_method.rb +0 -35
  233. data/test/lib/mocha/auto_verify.rb +0 -113
  234. data/test/lib/mocha/central.rb +0 -35
  235. data/test/lib/mocha/class_method.rb +0 -62
  236. data/test/lib/mocha/deprecation.rb +0 -22
  237. data/test/lib/mocha/exception_raiser.rb +0 -17
  238. data/test/lib/mocha/expectation.rb +0 -378
  239. data/test/lib/mocha/expectation_error.rb +0 -6
  240. data/test/lib/mocha/infinite_range.rb +0 -25
  241. data/test/lib/mocha/inspect.rb +0 -39
  242. data/test/lib/mocha/instance_method.rb +0 -8
  243. data/test/lib/mocha/is_a.rb +0 -9
  244. data/test/lib/mocha/metaclass.rb +0 -7
  245. data/test/lib/mocha/missing_expectation.rb +0 -27
  246. data/test/lib/mocha/mock.rb +0 -207
  247. data/test/lib/mocha/multiple_yields.rb +0 -20
  248. data/test/lib/mocha/no_yields.rb +0 -11
  249. data/test/lib/mocha/object.rb +0 -110
  250. data/test/lib/mocha/parameter_matchers.rb +0 -9
  251. data/test/lib/mocha/parameter_matchers/all_of.rb +0 -39
  252. data/test/lib/mocha/parameter_matchers/any_of.rb +0 -44
  253. data/test/lib/mocha/parameter_matchers/anything.rb +0 -30
  254. data/test/lib/mocha/parameter_matchers/has_entry.rb +0 -39
  255. data/test/lib/mocha/parameter_matchers/has_key.rb +0 -39
  256. data/test/lib/mocha/parameter_matchers/has_value.rb +0 -39
  257. data/test/lib/mocha/parameter_matchers/includes.rb +0 -37
  258. data/test/lib/mocha/pretty_parameters.rb +0 -28
  259. data/test/lib/mocha/return_values.rb +0 -31
  260. data/test/lib/mocha/setup_and_teardown.rb +0 -23
  261. data/test/lib/mocha/single_return_value.rb +0 -24
  262. data/test/lib/mocha/single_yield.rb +0 -18
  263. data/test/lib/mocha/standalone.rb +0 -32
  264. data/test/lib/mocha/stub.rb +0 -18
  265. data/test/lib/mocha/test_case_adapter.rb +0 -49
  266. data/test/lib/mocha/yield_parameters.rb +0 -31
@@ -1,184 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # Created by Luke A. Kanies on 2006-02-20.
4
- # Copyright (c) 2006. All rights reserved.
5
-
6
- require File.dirname(__FILE__) + '/../../lib/puppettest'
7
-
8
- require 'puppettest'
9
- require 'puppettest/parsertesting'
10
- require 'puppettest/resourcetesting'
11
- require 'mocha'
12
-
13
- class TestASTHostClass < Test::Unit::TestCase
14
- include PuppetTest
15
- include PuppetTest::ParserTesting
16
- include PuppetTest::ResourceTesting
17
- AST = Puppet::Parser::AST
18
-
19
- def test_hostclass
20
- scope = mkscope
21
- parser = scope.compile.parser
22
-
23
- # Create the class we're testing, first with no parent
24
- klass = parser.newclass "first",
25
- :code => AST::ASTArray.new(
26
- :children => [resourcedef("file", "/tmp",
27
- "owner" => "nobody", "mode" => "755")]
28
- )
29
-
30
- resource = Puppet::Parser::Resource.new(:type => "class", :title => "first", :scope => scope)
31
- assert_nothing_raised do
32
- klass.evaluate(:scope => scope, :resource => resource)
33
- end
34
-
35
- # Then try it again
36
- assert_nothing_raised do
37
- klass.evaluate(:scope => scope, :resource => resource)
38
- end
39
-
40
- assert(scope.compile.class_scope(klass), "Class was not considered evaluated")
41
-
42
- tmp = scope.findresource("File[/tmp]")
43
- assert(tmp, "Could not find file /tmp")
44
- assert_equal("nobody", tmp[:owner])
45
- assert_equal("755", tmp[:mode])
46
-
47
- # Now create a couple more classes.
48
- newbase = parser.newclass "newbase",
49
- :code => AST::ASTArray.new(
50
- :children => [resourcedef("file", "/tmp/other",
51
- "owner" => "nobody", "mode" => "644")]
52
- )
53
-
54
- newsub = parser.newclass "newsub",
55
- :parent => "newbase",
56
- :code => AST::ASTArray.new(
57
- :children => [resourcedef("file", "/tmp/yay",
58
- "owner" => "nobody", "mode" => "755"),
59
- resourceoverride("file", "/tmp/other",
60
- "owner" => "daemon")
61
- ]
62
- )
63
-
64
- # Override a different variable in the top scope.
65
- moresub = parser.newclass "moresub",
66
- :parent => "newbase",
67
- :code => AST::ASTArray.new(
68
- :children => [resourceoverride("file", "/tmp/other",
69
- "mode" => "755")]
70
- )
71
-
72
- assert_nothing_raised do
73
- newsub.evaluate(:scope => scope, :resource => resource)
74
- end
75
-
76
- assert_nothing_raised do
77
- moresub.evaluate(:scope => scope, :resource => resource)
78
- end
79
-
80
- assert(scope.compile.class_scope(newbase), "Did not eval newbase")
81
- assert(scope.compile.class_scope(newsub), "Did not eval newsub")
82
-
83
- yay = scope.findresource("File[/tmp/yay]")
84
- assert(yay, "Did not find file /tmp/yay")
85
- assert_equal("nobody", yay[:owner])
86
- assert_equal("755", yay[:mode])
87
-
88
- other = scope.findresource("File[/tmp/other]")
89
- assert(other, "Did not find file /tmp/other")
90
- assert_equal("daemon", other[:owner])
91
- assert_equal("755", other[:mode])
92
- end
93
-
94
- # Make sure that classes set their namespaces to themselves. This
95
- # way they start looking for definitions in their own namespace.
96
- def test_hostclass_namespace
97
- scope = mkscope
98
- parser = scope.compile.parser
99
-
100
- # Create a new class
101
- klass = nil
102
- assert_nothing_raised do
103
- klass = parser.newclass "funtest"
104
- end
105
-
106
- # Now define a definition in that namespace
107
-
108
- define = nil
109
- assert_nothing_raised do
110
- define = parser.newdefine "funtest::mydefine"
111
- end
112
-
113
- assert_equal("funtest", klass.namespace,
114
- "component namespace was not set in the class")
115
-
116
- assert_equal("funtest", define.namespace,
117
- "component namespace was not set in the definition")
118
-
119
- newscope = klass.subscope(scope, mock("resource"))
120
-
121
- assert_equal(["funtest"], newscope.namespaces,
122
- "Scope did not inherit namespace")
123
-
124
- # Now make sure we can find the define
125
- assert(newscope.finddefine("mydefine"),
126
- "Could not find definition in my enclosing class")
127
- end
128
-
129
- # Make sure that our scope is a subscope of the parentclass's scope.
130
- # At the same time, make sure definitions in the parent class can be
131
- # found within the subclass (#517).
132
- def test_parent_scope_from_parentclass
133
- scope = mkscope
134
- parser = scope.compile.parser
135
-
136
- source = parser.newclass ""
137
- parser.newclass("base")
138
- fun = parser.newdefine("base::fun")
139
- parser.newclass("middle", :parent => "base")
140
- parser.newclass("sub", :parent => "middle")
141
- scope = mkscope :parser => parser
142
-
143
- ret = nil
144
- assert_nothing_raised do
145
- ret = scope.compile.evaluate_classes(["sub"], scope)
146
- end
147
- scope.compile.send(:evaluate_generators)
148
-
149
- subscope = scope.compile.class_scope(scope.findclass("sub"))
150
- assert(subscope, "could not find sub scope")
151
- mscope = scope.compile.class_scope(scope.findclass("middle"))
152
- assert(mscope, "could not find middle scope")
153
- pscope = scope.compile.class_scope(scope.findclass("base"))
154
- assert(pscope, "could not find parent scope")
155
-
156
- assert(pscope == mscope.parent, "parent scope of middle was not set correctly")
157
- assert(mscope == subscope.parent, "parent scope of sub was not set correctly")
158
-
159
- result = mscope.finddefine("fun")
160
- assert(result, "could not find parent-defined definition from middle")
161
- assert(fun == result, "found incorrect parent-defined definition from middle")
162
-
163
- result = subscope.finddefine("fun")
164
- assert(result, "could not find parent-defined definition from sub")
165
- assert(fun == result, "found incorrect parent-defined definition from sub")
166
- end
167
-
168
- # #795 - make sure the subclass's tags get set before we
169
- # evaluate the parent class, so we can be sure that the parent
170
- # class can switch based on the sub classes.
171
- def test_tags_set_before_parent_is_evaluated
172
- scope = mkscope
173
- parser = scope.compile.parser
174
- base = parser.newclass "base"
175
- sub = parser.newclass "sub", :parent => "base"
176
-
177
- base.expects(:safeevaluate).with do |args|
178
- assert(scope.compile.catalog.tags.include?("sub"), "Did not tag with sub class name before evaluating base class")
179
- base.evaluate(args)
180
- true
181
- end
182
- sub.evaluate :scope => scope, :resource => scope.resource
183
- end
184
- end
@@ -1,569 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require File.dirname(__FILE__) + '/../lib/puppettest'
4
-
5
- require 'mocha'
6
- require 'puppettest'
7
- require 'puppettest/parsertesting'
8
- require 'puppet/parser/compile'
9
-
10
- # Test our compile object.
11
- class TestCompile < Test::Unit::TestCase
12
- include PuppetTest
13
- include PuppetTest::ParserTesting
14
-
15
- Compile = Puppet::Parser::Compile
16
- Scope = Puppet::Parser::Scope
17
- Node = Puppet::Network::Handler.handler(:node)
18
- SimpleNode = Puppet::Node
19
-
20
- def mknode(name = "foo")
21
- @node = SimpleNode.new(name)
22
- end
23
-
24
- def mkparser
25
- # This should mock an interpreter
26
- @parser = stub 'parser', :version => "1.0", :nodes => {}
27
- end
28
-
29
- def mkcompile(options = {})
30
- if node = options[:node]
31
- options.delete(:node)
32
- else
33
- node = mknode
34
- end
35
- @compile = Compile.new(node, mkparser, options)
36
- end
37
-
38
- def test_initialize
39
- compile = nil
40
- node = stub 'node', :name => "foo"
41
- parser = stub 'parser', :version => "1.0", :nodes => {}
42
- assert_nothing_raised("Could not init compile with all required options") do
43
- compile = Compile.new(node, parser)
44
- end
45
-
46
- assert_equal(node, compile.node, "Did not set node correctly")
47
- assert_equal(parser, compile.parser, "Did not set parser correctly")
48
-
49
- # We're not testing here whether we call initvars, because it's too difficult to
50
- # mock.
51
-
52
- # Now try it with some options
53
- assert_nothing_raised("Could not init compile with extra options") do
54
- compile = Compile.new(node, parser)
55
- end
56
-
57
- assert_equal(false, compile.ast_nodes?, "Did not set ast_nodes? correctly")
58
- end
59
-
60
- def test_initvars
61
- compile = mkcompile
62
- [:class_scopes, :resource_table, :exported_resources, :resource_overrides].each do |table|
63
- assert_instance_of(Hash, compile.send(:instance_variable_get, "@#{table}"), "Did not set %s table correctly" % table)
64
- end
65
- assert_instance_of(Scope, compile.topscope, "Did not create a topscope")
66
- graph = compile.instance_variable_get("@scope_graph")
67
- assert_instance_of(GRATR::Digraph, graph, "Did not create scope graph")
68
- assert(graph.vertex?(compile.topscope), "Did not add top scope as a vertex in the graph")
69
- end
70
-
71
- # Make sure we store and can retrieve references to classes and their scopes.
72
- def test_class_set_and_class_scope
73
- klass = mock 'ast_class'
74
- klass.expects(:classname).returns("myname")
75
-
76
- compile = mkcompile
77
- compile.catalog.expects(:tag).with("myname")
78
-
79
- assert_nothing_raised("Could not set class") do
80
- compile.class_set "myname", "myscope"
81
- end
82
- # First try to retrieve it by name.
83
- assert_equal("myscope", compile.class_scope("myname"), "Could not retrieve class scope by name")
84
-
85
- # Then by object
86
- assert_equal("myscope", compile.class_scope(klass), "Could not retrieve class scope by object")
87
- end
88
-
89
- def test_classlist
90
- compile = mkcompile
91
-
92
- compile.class_set "", "empty"
93
- compile.class_set "one", "yep"
94
- compile.class_set "two", "nope"
95
-
96
- # Make sure our class list is correct
97
- assert_equal(%w{one two}.sort, compile.classlist.sort, "Did not get correct class list")
98
- end
99
-
100
- # Make sure collections get added to our internal array
101
- def test_add_collection
102
- compile = mkcompile
103
- assert_nothing_raised("Could not add collection") do
104
- compile.add_collection "nope"
105
- end
106
- assert_equal(%w{nope}, compile.instance_variable_get("@collections"), "Did not add collection")
107
- end
108
-
109
- # Make sure we create a graph of scopes.
110
- def test_newscope
111
- compile = mkcompile
112
- graph = compile.instance_variable_get("@scope_graph")
113
- assert_instance_of(Scope, compile.topscope, "Did not create top scope")
114
- assert_instance_of(GRATR::Digraph, graph, "Did not create graph")
115
-
116
- assert(graph.vertex?(compile.topscope), "The top scope is not a vertex in the graph")
117
-
118
- # Now that we've got the top scope, create a new, subscope
119
- subscope = nil
120
- assert_nothing_raised("Could not create subscope") do
121
- subscope = compile.newscope(compile.topscope)
122
- end
123
- assert_instance_of(Scope, subscope, "Did not create subscope")
124
- assert(graph.edge?(compile.topscope, subscope), "An edge between top scope and subscope was not added")
125
-
126
- # Make sure a scope can find its parent.
127
- assert(compile.parent(subscope), "Could not look up parent scope on compile")
128
- assert_equal(compile.topscope.object_id, compile.parent(subscope).object_id, "Did not get correct parent scope from compile")
129
- assert_equal(compile.topscope.object_id, subscope.parent.object_id, "Scope did not correctly retrieve its parent scope")
130
-
131
- # Now create another, this time specifying options
132
- another = nil
133
- assert_nothing_raised("Could not create subscope") do
134
- another = compile.newscope(subscope, :level => 5)
135
- end
136
- assert_equal(5, another.level, "did not set scope option correctly")
137
- assert_instance_of(Scope, another, "Did not create second subscope")
138
- assert(graph.edge?(subscope, another), "An edge between parent scope and second subscope was not added")
139
-
140
- # Make sure it can find its parent.
141
- assert(compile.parent(another), "Could not look up parent scope of second subscope on compile")
142
- assert_equal(subscope.object_id, compile.parent(another).object_id, "Did not get correct parent scope of second subscope from compile")
143
- assert_equal(subscope.object_id, another.parent.object_id, "Second subscope did not correctly retrieve its parent scope")
144
-
145
- # And make sure both scopes show up in the right order in the search path
146
- assert_equal([another.object_id, subscope.object_id, compile.topscope.object_id], another.scope_path.collect { |p| p.object_id },
147
- "Did not get correct scope path")
148
- end
149
-
150
- # The heart of the action.
151
- def test_compile
152
- compile = mkcompile
153
- [:set_node_parameters, :evaluate_main, :evaluate_ast_node, :evaluate_node_classes, :evaluate_generators, :fail_on_unevaluated, :finish].each do |method|
154
- compile.expects(method)
155
- end
156
- assert_instance_of(Puppet::Node::Catalog, compile.compile, "Did not return the catalog")
157
- end
158
-
159
- # Test setting the node's parameters into the top scope.
160
- def test_set_node_parameters
161
- compile = mkcompile
162
- @node.parameters = {"a" => "b", "c" => "d"}
163
- scope = compile.topscope
164
- @node.parameters.each do |param, value|
165
- scope.expects(:setvar).with(param, value)
166
- end
167
-
168
- assert_nothing_raised("Could not call 'set_node_parameters'") do
169
- compile.send(:set_node_parameters)
170
- end
171
- end
172
-
173
- # Test that we can evaluate the main class, which is the one named "" in namespace
174
- # "".
175
- def test_evaluate_main
176
- compile = mkcompile
177
- main_class = mock 'main_class'
178
- compile.topscope.expects(:source=).with(main_class)
179
- @parser.expects(:findclass).with("", "").returns(main_class)
180
-
181
- main_resource = mock 'main resource'
182
- Puppet::Parser::Resource.expects(:new).with { |args| args[:title] == :main }.returns(main_resource)
183
-
184
- main_resource.expects(:evaluate)
185
-
186
- assert_nothing_raised("Could not call evaluate_main") do
187
- compile.send(:evaluate_main)
188
- end
189
- end
190
-
191
- def test_evaluate_node_classes
192
- compile = mkcompile
193
- @node.classes = %w{one two three four}
194
- compile.expects(:evaluate_classes).with(%w{one two three four}, compile.topscope)
195
- assert_nothing_raised("could not call evaluate_node_classes") do
196
- compile.send(:evaluate_node_classes)
197
- end
198
- end
199
-
200
- def test_evaluate_collections
201
- compile = mkcompile
202
-
203
- colls = []
204
-
205
- # Make sure we return false when there's nothing there.
206
- assert(! compile.send(:evaluate_collections), "Returned true when there were no collections")
207
-
208
- # And when the collections fail to evaluate.
209
- colls << mock("coll1-false")
210
- colls << mock("coll2-false")
211
- colls.each { |c| c.expects(:evaluate).returns(false) }
212
-
213
- compile.instance_variable_set("@collections", colls)
214
- assert(! compile.send(:evaluate_collections), "Returned true when collections both evaluated nothing")
215
-
216
- # Now have one of the colls evaluate
217
- colls.clear
218
- colls << mock("coll1-one-true")
219
- colls << mock("coll2-one-true")
220
- colls[0].expects(:evaluate).returns(true)
221
- colls[1].expects(:evaluate).returns(false)
222
- assert(compile.send(:evaluate_collections), "Did not return true when one collection evaluated true")
223
-
224
- # And have them both eval true
225
- colls.clear
226
- colls << mock("coll1-both-true")
227
- colls << mock("coll2-both-true")
228
- colls[0].expects(:evaluate).returns(true)
229
- colls[1].expects(:evaluate).returns(true)
230
- assert(compile.send(:evaluate_collections), "Did not return true when both collections evaluated true")
231
- end
232
-
233
- def test_unevaluated_resources
234
- compile = mkcompile
235
- resources = {}
236
- compile.instance_variable_set("@resource_table", resources)
237
-
238
- # First test it when the table is empty
239
- assert_nil(compile.send(:unevaluated_resources), "Somehow found unevaluated resources in an empty table")
240
-
241
- # Then add a builtin resources
242
- resources["one"] = mock("builtin only")
243
- resources["one"].expects(:builtin?).returns(true)
244
- assert_nil(compile.send(:unevaluated_resources), "Considered a builtin resource unevaluated")
245
-
246
- # And do both builtin and non-builtin but already evaluated
247
- resources.clear
248
- resources["one"] = mock("builtin (with eval)")
249
- resources["one"].expects(:builtin?).returns(true)
250
- resources["two"] = mock("evaled (with builtin)")
251
- resources["two"].expects(:builtin?).returns(false)
252
- resources["two"].expects(:evaluated?).returns(true)
253
- assert_nil(compile.send(:unevaluated_resources), "Considered either a builtin or evaluated resource unevaluated")
254
-
255
- # Now a single unevaluated resource.
256
- resources.clear
257
- resources["one"] = mock("unevaluated")
258
- resources["one"].expects(:builtin?).returns(false)
259
- resources["one"].expects(:evaluated?).returns(false)
260
- assert_equal([resources["one"]], compile.send(:unevaluated_resources), "Did not find unevaluated resource")
261
-
262
- # With two uneval'ed resources, and an eval'ed one thrown in
263
- resources.clear
264
- resources["one"] = mock("unevaluated one")
265
- resources["one"].expects(:builtin?).returns(false)
266
- resources["one"].expects(:evaluated?).returns(false)
267
- resources["two"] = mock("unevaluated two")
268
- resources["two"].expects(:builtin?).returns(false)
269
- resources["two"].expects(:evaluated?).returns(false)
270
- resources["three"] = mock("evaluated")
271
- resources["three"].expects(:builtin?).returns(false)
272
- resources["three"].expects(:evaluated?).returns(true)
273
-
274
- result = compile.send(:unevaluated_resources)
275
- %w{one two}.each do |name|
276
- assert(result.include?(resources[name]), "Did not find %s in the unevaluated list" % name)
277
- end
278
- end
279
-
280
- def test_evaluate_definitions
281
- # First try the case where there's nothing to return
282
- compile = mkcompile
283
- compile.expects(:unevaluated_resources).returns(nil)
284
-
285
- assert_nothing_raised("Could not test for unevaluated resources") do
286
- assert(! compile.send(:evaluate_definitions), "evaluate_definitions returned true when no resources were evaluated")
287
- end
288
-
289
- # Now try it with resources left to evaluate
290
- resources = []
291
- res1 = mock("resource1")
292
- res1.expects(:evaluate)
293
- res2 = mock("resource2")
294
- res2.expects(:evaluate)
295
- resources << res1 << res2
296
- compile = mkcompile
297
- compile.expects(:unevaluated_resources).returns(resources)
298
-
299
- assert_nothing_raised("Could not test for unevaluated resources") do
300
- assert(compile.send(:evaluate_definitions), "evaluate_definitions returned false when resources were evaluated")
301
- end
302
- end
303
-
304
- def test_evaluate_generators
305
- # First try the case where we have nothing to do
306
- compile = mkcompile
307
- compile.expects(:evaluate_definitions).returns(false)
308
- compile.expects(:evaluate_collections).returns(false)
309
-
310
- assert_nothing_raised("Could not call :eval_iterate") do
311
- compile.send(:evaluate_generators)
312
- end
313
-
314
- # FIXME I could not get this test to work, but the code is short
315
- # enough that I'm ok with it.
316
- # It's important that collections are evaluated before definitions,
317
- # so make sure that's the case by verifying that collections get tested
318
- # twice but definitions only once.
319
- #compile = mkcompile
320
- #compile.expects(:evaluate_collections).returns(true).returns(false)
321
- #compile.expects(:evaluate_definitions).returns(false)
322
- #compile.send(:eval_iterate)
323
- end
324
-
325
- def test_store
326
- compile = mkcompile
327
- Puppet.features.expects(:rails?).returns(true)
328
- Puppet::Rails.expects(:connect)
329
-
330
- node = mock 'node'
331
- resource_table = mock 'resources'
332
- resource_table.expects(:values).returns(:resources)
333
- compile.instance_variable_set("@node", node)
334
- compile.instance_variable_set("@resource_table", resource_table)
335
- compile.expects(:store_to_active_record).with(node, :resources)
336
- compile.send(:store)
337
- end
338
-
339
- def test_store_to_active_record
340
- compile = mkcompile
341
- node = mock 'node'
342
- node.expects(:name).returns("myname")
343
- Puppet::Rails::Host.stubs(:transaction).yields
344
- Puppet::Rails::Host.expects(:store).with(node, :resources)
345
- compile.send(:store_to_active_record, node, :resources)
346
- end
347
-
348
- # Make sure that 'finish' gets called on all of our resources.
349
- def test_finish
350
- compile = mkcompile
351
- table = compile.instance_variable_get("@resource_table")
352
-
353
- # Add a resource that does respond to :finish
354
- yep = mock("finisher")
355
- yep.expects(:respond_to?).with(:finish).returns(true)
356
- yep.expects(:finish)
357
- table["yep"] = yep
358
-
359
- # And one that does not
360
- dnf = mock("dnf")
361
- dnf.expects(:respond_to?).with(:finish).returns(false)
362
- table["dnf"] = dnf
363
-
364
- compile.send(:finish)
365
- end
366
-
367
- def test_verify_uniqueness
368
- compile = mkcompile
369
-
370
- resources = compile.instance_variable_get("@resource_table")
371
- resource = mock("noconflict")
372
- resource.expects(:ref).returns("File[yay]")
373
- assert_nothing_raised("Raised an exception when there should have been no conflict") do
374
- compile.send(:verify_uniqueness, resource)
375
- end
376
-
377
- # Now try the case where our type is isomorphic
378
- resources["thing"] = true
379
-
380
- isoconflict = mock("isoconflict")
381
- isoconflict.expects(:ref).returns("thing")
382
- isoconflict.expects(:type).returns("testtype")
383
- faketype = mock("faketype")
384
- faketype.expects(:isomorphic?).returns(false)
385
- faketype.expects(:name).returns("whatever")
386
- Puppet::Type.expects(:type).with("testtype").returns(faketype)
387
- assert_nothing_raised("Raised an exception when was a conflict in non-isomorphic types") do
388
- compile.send(:verify_uniqueness, isoconflict)
389
- end
390
-
391
- # Now test for when we actually have an exception
392
- initial = mock("initial")
393
- resources["thing"] = initial
394
- initial.expects(:file).returns(false)
395
-
396
- conflict = mock("conflict")
397
- conflict.expects(:ref).returns("thing").times(2)
398
- conflict.expects(:type).returns("conflict")
399
- conflict.expects(:file).returns(false)
400
- conflict.expects(:line).returns(false)
401
-
402
- faketype = mock("faketype")
403
- faketype.expects(:isomorphic?).returns(true)
404
- Puppet::Type.expects(:type).with("conflict").returns(faketype)
405
- assert_raise(Puppet::ParseError, "Did not fail when two isomorphic resources conflicted") do
406
- compile.send(:verify_uniqueness, conflict)
407
- end
408
- end
409
-
410
- def test_store_resource
411
- # Run once when there's no conflict
412
- compile = mkcompile
413
- table = compile.instance_variable_get("@resource_table")
414
- resource = mock("resource")
415
- resource.expects(:ref).returns("yay")
416
- compile.expects(:verify_uniqueness).with(resource)
417
- scope = stub("scope", :resource => mock('resource'))
418
-
419
- compile.catalog.expects(:add_edge!).with(scope.resource, resource)
420
-
421
- assert_nothing_raised("Could not store resource") do
422
- compile.store_resource(scope, resource)
423
- end
424
- assert_equal(resource, table["yay"], "Did not store resource in table")
425
-
426
- # Now for conflicts
427
- compile = mkcompile
428
- table = compile.instance_variable_get("@resource_table")
429
- resource = mock("resource")
430
- compile.expects(:verify_uniqueness).with(resource).raises(ArgumentError)
431
-
432
- assert_raise(ArgumentError, "Did not raise uniqueness exception") do
433
- compile.store_resource(scope, resource)
434
- end
435
- assert(table.empty?, "Conflicting resource was stored in table")
436
- end
437
-
438
- def test_fail_on_unevaluated
439
- compile = mkcompile
440
- compile.expects(:fail_on_unevaluated_overrides)
441
- compile.expects(:fail_on_unevaluated_resource_collections)
442
- compile.send :fail_on_unevaluated
443
- end
444
-
445
- def test_store_override
446
- # First test the case when the resource is not present.
447
- compile = mkcompile
448
- overrides = compile.instance_variable_get("@resource_overrides")
449
- override = Object.new
450
- override.expects(:ref).returns(:myref).times(2)
451
- override.expects(:override=).with(true)
452
-
453
- assert_nothing_raised("Could not call store_override") do
454
- compile.store_override(override)
455
- end
456
- assert_instance_of(Array, overrides[:myref], "Overrides table is not a hash of arrays")
457
- assert_equal(override, overrides[:myref][0], "Did not store override in appropriately named array")
458
-
459
- # And when the resource already exists.
460
- resource = mock 'resource'
461
- resources = compile.instance_variable_get("@resource_table")
462
- resources[:resref] = resource
463
-
464
- override = mock 'override'
465
- resource.expects(:merge).with(override)
466
- override.expects(:override=).with(true)
467
- override.expects(:ref).returns(:resref)
468
- assert_nothing_raised("Could not call store_override when the resource already exists.") do
469
- compile.store_override(override)
470
- end
471
- end
472
-
473
- def test_resource_overrides
474
- compile = mkcompile
475
- overrides = compile.instance_variable_get("@resource_overrides")
476
- overrides[:test] = :yay
477
- resource = mock 'resource'
478
- resource.expects(:ref).returns(:test)
479
-
480
- assert_equal(:yay, compile.resource_overrides(resource), "Did not return overrides from table")
481
- end
482
-
483
- def test_fail_on_unevaluated_resource_collections
484
- compile = mkcompile
485
- collections = compile.instance_variable_get("@collections")
486
-
487
- # Make sure we're fine when the list is empty
488
- assert_nothing_raised("Failed when no collections were present") do
489
- compile.send :fail_on_unevaluated_resource_collections
490
- end
491
-
492
- # And that we're fine when we've got collections but with no resources
493
- collections << mock('coll')
494
- collections[0].expects(:resources).returns(nil)
495
- assert_nothing_raised("Failed when no resource collections were present") do
496
- compile.send :fail_on_unevaluated_resource_collections
497
- end
498
-
499
- # But that we do fail when we've got resource collections left.
500
- collections.clear
501
-
502
- # return both an array and a string, because that's tested internally
503
- collections << mock('coll returns one')
504
- collections[0].expects(:resources).returns(:something)
505
-
506
- collections << mock('coll returns many')
507
- collections[1].expects(:resources).returns([:one, :two])
508
-
509
- assert_raise(Puppet::ParseError, "Did not fail on unevaluated resource collections") do
510
- compile.send :fail_on_unevaluated_resource_collections
511
- end
512
- end
513
-
514
- def test_fail_on_unevaluated_overrides
515
- compile = mkcompile
516
- overrides = compile.instance_variable_get("@resource_overrides")
517
-
518
- # Make sure we're fine when the list is empty
519
- assert_nothing_raised("Failed when no collections were present") do
520
- compile.send :fail_on_unevaluated_overrides
521
- end
522
-
523
- # But that we fail if there are any overrides left in the table.
524
- overrides[:yay] = []
525
- overrides[:foo] = []
526
- overrides[:bar] = [mock("override")]
527
- overrides[:bar][0].expects(:ref).returns("yay")
528
- assert_raise(Puppet::ParseError, "Failed to fail when overrides remain") do
529
- compile.send :fail_on_unevaluated_overrides
530
- end
531
- end
532
-
533
- def test_find_resource
534
- compile = mkcompile
535
- resources = compile.instance_variable_get("@resource_table")
536
-
537
- assert_nothing_raised("Could not call findresource when the resource table was empty") do
538
- assert_nil(compile.findresource("yay", "foo"), "Returned a non-existent resource")
539
- assert_nil(compile.findresource("yay[foo]"), "Returned a non-existent resource")
540
- end
541
-
542
- resources["Foo[bar]"] = :yay
543
- assert_nothing_raised("Could not call findresource when the resource table was not empty") do
544
- assert_equal(:yay, compile.findresource("foo", "bar"), "Returned a non-existent resource")
545
- assert_equal(:yay, compile.findresource("Foo[bar]"), "Returned a non-existent resource")
546
- end
547
- end
548
-
549
- # #620 - Nodes and classes should conflict, else classes don't get evaluated
550
- def test_nodes_and_classes_name_conflict
551
- # Test node then class
552
- compile = mkcompile
553
- node = stub :nodescope? => true
554
- klass = stub :nodescope? => false
555
- compile.class_set("one", node)
556
- assert_raise(Puppet::ParseError, "Did not fail when replacing node with class") do
557
- compile.class_set("one", klass)
558
- end
559
-
560
- # and class then node
561
- compile = mkcompile
562
- node = stub :nodescope? => true
563
- klass = stub :nodescope? => false
564
- compile.class_set("two", klass)
565
- assert_raise(Puppet::ParseError, "Did not fail when replacing node with class") do
566
- compile.class_set("two", node)
567
- end
568
- end
569
- end