puppet 2.7.11 → 2.7.12

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 (220) hide show
  1. data/CHANGELOG +188 -0
  2. data/conf/osx/createpackage.sh +1 -0
  3. data/conf/redhat/puppet.spec +12 -9
  4. data/conf/suse/puppet.spec +4 -1
  5. data/install.rb +9 -22
  6. data/lib/puppet.rb +1 -31
  7. data/lib/puppet/agent.rb +3 -5
  8. data/lib/puppet/agent/locker.rb +15 -1
  9. data/lib/puppet/application.rb +7 -4
  10. data/lib/puppet/application/agent.rb +4 -25
  11. data/lib/puppet/application/apply.rb +3 -3
  12. data/lib/puppet/application/device.rb +2 -16
  13. data/lib/puppet/application/doc.rb +2 -2
  14. data/lib/puppet/application/face_base.rb +22 -5
  15. data/lib/puppet/application/filebucket.rb +2 -0
  16. data/lib/puppet/application/inspect.rb +2 -1
  17. data/lib/puppet/application/kick.rb +25 -9
  18. data/lib/puppet/application/queue.rb +0 -23
  19. data/lib/puppet/configurer.rb +1 -0
  20. data/lib/puppet/configurer/downloader.rb +7 -3
  21. data/lib/puppet/defaults.rb +34 -29
  22. data/lib/puppet/face/ca.rb +1 -1
  23. data/lib/puppet/face/catalog.rb +1 -0
  24. data/lib/puppet/face/file/store.rb +1 -1
  25. data/lib/puppet/face/module/list.rb +23 -3
  26. data/lib/puppet/face/module/search.rb +21 -32
  27. data/lib/puppet/face/module/uninstall.rb +56 -15
  28. data/lib/puppet/file_bucket/dipper.rb +2 -2
  29. data/lib/puppet/file_serving/base.rb +6 -5
  30. data/lib/puppet/file_serving/configuration/parser.rb +1 -1
  31. data/lib/puppet/file_serving/content.rb +1 -1
  32. data/lib/puppet/forge.rb +153 -0
  33. data/lib/puppet/{module_tool → forge}/cache.rb +1 -2
  34. data/lib/puppet/{module_tool → forge}/repository.rb +46 -4
  35. data/lib/puppet/indirector/exec.rb +1 -1
  36. data/lib/puppet/indirector/file_bucket_file/file.rb +3 -3
  37. data/lib/puppet/interface/action.rb +6 -2
  38. data/lib/puppet/module.rb +70 -10
  39. data/lib/puppet/module_tool.rb +2 -38
  40. data/lib/puppet/module_tool/applications.rb +15 -11
  41. data/lib/puppet/module_tool/applications/application.rb +2 -5
  42. data/lib/puppet/module_tool/applications/cleaner.rb +1 -1
  43. data/lib/puppet/module_tool/applications/installer.rb +10 -45
  44. data/lib/puppet/module_tool/applications/searcher.rb +2 -26
  45. data/lib/puppet/module_tool/applications/uninstaller.rb +39 -13
  46. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  47. data/lib/puppet/module_tool/dependency.rb +1 -1
  48. data/lib/puppet/network/authconfig.rb +1 -1
  49. data/lib/puppet/network/handler/fileserver.rb +1 -1
  50. data/lib/puppet/network/http/handler.rb +4 -1
  51. data/lib/puppet/network/http/webrick.rb +4 -2
  52. data/lib/puppet/node/environment.rb +32 -6
  53. data/lib/puppet/parameter/path.rb +0 -4
  54. data/lib/puppet/parser/ast/relationship.rb +3 -16
  55. data/lib/puppet/parser/collector.rb +5 -3
  56. data/lib/puppet/parser/compiler.rb +2 -1
  57. data/lib/puppet/parser/functions/file.rb +1 -1
  58. data/lib/puppet/parser/functions/generate.rb +8 -2
  59. data/lib/puppet/parser/grammar.ra +16 -15
  60. data/lib/puppet/parser/parser.rb +959 -881
  61. data/lib/puppet/parser/relationship.rb +32 -15
  62. data/lib/puppet/parser/resource.rb +0 -1
  63. data/lib/puppet/parser/type_loader.rb +1 -2
  64. data/lib/puppet/provider/augeas/augeas.rb +17 -29
  65. data/lib/puppet/provider/exec/windows.rb +25 -3
  66. data/lib/puppet/provider/file/posix.rb +1 -1
  67. data/lib/puppet/provider/file/windows.rb +1 -1
  68. data/lib/puppet/provider/group/windows_adsi.rb +1 -1
  69. data/lib/puppet/provider/package/aix.rb +1 -1
  70. data/lib/puppet/provider/package/appdmg.rb +1 -1
  71. data/lib/puppet/provider/package/dpkg.rb +1 -1
  72. data/lib/puppet/provider/package/gem.rb +21 -23
  73. data/lib/puppet/provider/package/macports.rb +1 -1
  74. data/lib/puppet/provider/package/msi.rb +7 -1
  75. data/lib/puppet/provider/package/openbsd.rb +13 -16
  76. data/lib/puppet/provider/package/pacman.rb +1 -1
  77. data/lib/puppet/provider/package/pip.rb +3 -0
  78. data/lib/puppet/provider/package/pkg.rb +1 -1
  79. data/lib/puppet/provider/package/pkgdmg.rb +1 -1
  80. data/lib/puppet/provider/package/pkgutil.rb +1 -1
  81. data/lib/puppet/provider/package/portage.rb +2 -2
  82. data/lib/puppet/provider/package/rpm.rb +1 -1
  83. data/lib/puppet/provider/package/sun.rb +1 -1
  84. data/lib/puppet/provider/package/zypper.rb +35 -3
  85. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +6 -2
  86. data/lib/puppet/provider/selmodule/semodule.rb +2 -2
  87. data/lib/puppet/provider/service/base.rb +1 -1
  88. data/lib/puppet/provider/service/launchd.rb +4 -0
  89. data/lib/puppet/provider/service/src.rb +2 -2
  90. data/lib/puppet/provider/service/upstart.rb +1 -1
  91. data/lib/puppet/provider/service/windows.rb +5 -4
  92. data/lib/puppet/provider/user/aix.rb +3 -3
  93. data/lib/puppet/provider/user/pw.rb +6 -0
  94. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  95. data/lib/puppet/resource/catalog.rb +6 -6
  96. data/lib/puppet/resource/type.rb +2 -0
  97. data/lib/puppet/ssl/certificate_request.rb +0 -70
  98. data/lib/puppet/transaction.rb +1 -1
  99. data/lib/puppet/transaction/report.rb +3 -2
  100. data/lib/puppet/type.rb +1 -1
  101. data/lib/puppet/type/cron.rb +5 -2
  102. data/lib/puppet/type/exec.rb +8 -0
  103. data/lib/puppet/type/file.rb +27 -18
  104. data/lib/puppet/type/file/checksum.rb +2 -2
  105. data/lib/puppet/type/file/content.rb +14 -9
  106. data/lib/puppet/type/file/ensure.rb +5 -4
  107. data/lib/puppet/type/file/group.rb +10 -2
  108. data/lib/puppet/type/file/mode.rb +46 -18
  109. data/lib/puppet/type/file/owner.rb +10 -2
  110. data/lib/puppet/type/file/source.rb +27 -40
  111. data/lib/puppet/type/file/target.rb +6 -6
  112. data/lib/puppet/type/group.rb +13 -9
  113. data/lib/puppet/type/k5login.rb +1 -1
  114. data/lib/puppet/type/package.rb +24 -8
  115. data/lib/puppet/type/scheduled_task.rb +77 -131
  116. data/lib/puppet/type/service.rb +22 -8
  117. data/lib/puppet/type/user.rb +29 -9
  118. data/lib/puppet/util.rb +24 -33
  119. data/lib/puppet/util/colors.rb +98 -0
  120. data/lib/puppet/util/diff.rb +3 -1
  121. data/lib/puppet/util/log.rb +5 -1
  122. data/lib/puppet/util/log/destinations.rb +37 -44
  123. data/lib/puppet/util/monkey_patches.rb +32 -0
  124. data/lib/puppet/util/pidlock.rb +70 -21
  125. data/lib/puppet/util/rdoc/parser.rb +4 -2
  126. data/lib/puppet/util/selinux.rb +1 -1
  127. data/lib/puppet/util/suidmanager.rb +2 -12
  128. data/lib/puppet/util/windows.rb +2 -0
  129. data/lib/puppet/util/windows/process.rb +33 -0
  130. data/lib/puppet/util/windows/security.rb +6 -4
  131. data/lib/puppet/util/windows/user.rb +44 -0
  132. data/lib/semver.rb +55 -4
  133. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.detail +19 -0
  134. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.list +10 -0
  135. data/spec/fixtures/unit/provider/package/openbsd/pkginfo.query +1 -0
  136. data/spec/fixtures/unit/provider/package/zypper/zypper-list-updates-SLES11sp1.out +369 -0
  137. data/spec/integration/defaults_spec.rb +10 -0
  138. data/spec/integration/indirector/direct_file_server_spec.rb +1 -1
  139. data/spec/integration/module_tool_spec.rb +10 -12
  140. data/spec/integration/parser/compiler_spec.rb +147 -0
  141. data/spec/integration/type/file_spec.rb +1 -1
  142. data/spec/integration/util/windows/user_spec.rb +59 -0
  143. data/spec/lib/puppet/face/basetest.rb +5 -0
  144. data/spec/lib/puppet_spec/modules.rb +26 -0
  145. data/spec/spec_helper.rb +25 -0
  146. data/spec/unit/agent/locker_spec.rb +12 -0
  147. data/spec/unit/agent_backward_compatibility_spec.rb +152 -0
  148. data/spec/unit/agent_spec.rb +28 -8
  149. data/spec/unit/application/agent_spec.rb +4 -36
  150. data/spec/unit/application/device_spec.rb +55 -10
  151. data/spec/unit/application/face_base_spec.rb +32 -10
  152. data/spec/unit/application/filebucket_spec.rb +5 -0
  153. data/spec/unit/application/kick_spec.rb +6 -0
  154. data/spec/unit/application_spec.rb +8 -1
  155. data/spec/unit/configurer/downloader_spec.rb +4 -5
  156. data/spec/unit/face/ca_spec.rb +15 -4
  157. data/spec/unit/file_bucket/dipper_spec.rb +1 -1
  158. data/spec/unit/file_serving/base_spec.rb +60 -42
  159. data/spec/unit/file_serving/configuration/parser_spec.rb +5 -3
  160. data/spec/unit/file_serving/content_spec.rb +26 -27
  161. data/spec/unit/file_serving/metadata_spec.rb +22 -21
  162. data/spec/unit/forge/repository_spec.rb +86 -0
  163. data/spec/unit/forge_spec.rb +114 -0
  164. data/spec/unit/indirector/exec_spec.rb +8 -6
  165. data/spec/unit/indirector/facts/inventory_active_record_spec.rb +0 -1
  166. data/spec/unit/indirector/file_bucket_file/file_spec.rb +1 -1
  167. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  168. data/spec/unit/indirector/resource/active_record_spec.rb +0 -4
  169. data/spec/unit/interface/action_builder_spec.rb +7 -5
  170. data/spec/unit/module_spec.rb +228 -9
  171. data/spec/unit/module_tool/application_spec.rb +3 -3
  172. data/spec/unit/module_tool/uninstaller_spec.rb +107 -27
  173. data/spec/unit/module_tool_spec.rb +0 -33
  174. data/spec/unit/network/authconfig_spec.rb +22 -21
  175. data/spec/unit/network/http/webrick_spec.rb +13 -9
  176. data/spec/unit/node/environment_spec.rb +159 -66
  177. data/spec/unit/parser/collector_spec.rb +16 -8
  178. data/spec/unit/parser/functions/generate_spec.rb +60 -18
  179. data/spec/unit/parser/resource_spec.rb +44 -0
  180. data/spec/unit/provider/augeas/augeas_spec.rb +160 -179
  181. data/spec/unit/provider/confine/feature_spec.rb +3 -5
  182. data/spec/unit/provider/package/dpkg_spec.rb +4 -2
  183. data/spec/unit/provider/package/gem_spec.rb +59 -43
  184. data/spec/unit/provider/package/openbsd_spec.rb +114 -0
  185. data/spec/unit/provider/package/pacman_spec.rb +1 -1
  186. data/spec/unit/provider/package/pip_spec.rb +10 -4
  187. data/spec/unit/provider/package/zypper_spec.rb +56 -14
  188. data/spec/unit/provider/selmodule_spec.rb +3 -3
  189. data/spec/unit/provider/service/launchd_spec.rb +22 -21
  190. data/spec/unit/provider/service/{upstart.rb → upstart_spec.rb} +7 -3
  191. data/spec/unit/provider/user/pw_spec.rb +19 -0
  192. data/spec/unit/resource/catalog_spec.rb +3 -3
  193. data/spec/unit/semver_spec.rb +117 -24
  194. data/spec/unit/transaction/report_spec.rb +11 -1
  195. data/spec/unit/type/cron_spec.rb +200 -213
  196. data/spec/unit/type/exec_spec.rb +7 -0
  197. data/spec/unit/type/file/content_spec.rb +2 -2
  198. data/spec/unit/type/file_spec.rb +12 -9
  199. data/spec/unit/type/package_spec.rb +25 -0
  200. data/spec/unit/type/schedule_spec.rb +31 -31
  201. data/spec/unit/util/diff_spec.rb +30 -0
  202. data/spec/unit/util/execution_stub_spec.rb +1 -2
  203. data/spec/unit/util/log/destinations_spec.rb +51 -0
  204. data/spec/unit/util/log_spec.rb +17 -1
  205. data/spec/unit/util/monkey_patches_spec.rb +119 -0
  206. data/spec/unit/util/rdoc/parser_spec.rb +25 -1
  207. data/spec/unit/util/selinux_spec.rb +2 -2
  208. data/spec/unit/util/suidmanager_spec.rb +6 -51
  209. data/spec/unit/util_spec.rb +82 -24
  210. data/test/lib/puppettest/certificates.rb +16 -0
  211. data/test/lib/puppettest/servertest.rb +4 -0
  212. data/test/util/pidlock.rb +125 -0
  213. metadata +23 -14
  214. data/ext/puppetstoredconfigclean.rb +0 -103
  215. data/lib/puppet/agent/disabler.rb +0 -27
  216. data/lib/puppet/util/anonymous_filelock.rb +0 -36
  217. data/spec/unit/agent/disabler_spec.rb +0 -60
  218. data/spec/unit/module_tool/repository_spec.rb +0 -52
  219. data/spec/unit/util/anonymous_filelock_spec.rb +0 -78
  220. data/spec/unit/util/pidlock_spec.rb +0 -208
@@ -309,4 +309,14 @@ describe "Puppet defaults" do
309
309
  end
310
310
  end
311
311
  end
312
+
313
+ describe "diff" do
314
+ it "should default to 'diff' on POSIX", :unless => Puppet.features.microsoft_windows? do
315
+ Puppet.settings[:diff].should == 'diff'
316
+ end
317
+
318
+ it "should default to '' on Windows", :if => Puppet.features.microsoft_windows? do
319
+ Puppet.settings[:diff].should == ''
320
+ end
321
+ end
312
322
  end
@@ -22,7 +22,7 @@ describe Puppet::Indirector::DirectFileServer, " when interacting with the files
22
22
  it "should return an instance capable of returning its content" do
23
23
  FileTest.expects(:exists?).with(@filepath).returns(true)
24
24
  File.stubs(:lstat).with(@filepath).returns(stub("stat", :ftype => "file"))
25
- Puppet::Util.expects(:binread).with(@filepath).returns("my content")
25
+ IO.expects(:binread).with(@filepath).returns("my content")
26
26
 
27
27
  instance = @terminus.find(@terminus.indirection.request(:find, "file://host#{@filepath}"))
28
28
 
@@ -8,7 +8,7 @@ def stub_repository_read(code, body)
8
8
  kind = Net::HTTPResponse.send(:response_class, code.to_s)
9
9
  response = kind.new('1.0', code.to_s, 'HTTP MESSAGE')
10
10
  response.stubs(:read_body).returns(body)
11
- Puppet::Module::Tool::Repository.any_instance.stubs(:read_response).returns(response)
11
+ Puppet::Forge::Repository.any_instance.stubs(:read_response).returns(response)
12
12
  end
13
13
 
14
14
  def stub_installer_read(body)
@@ -16,7 +16,7 @@ def stub_installer_read(body)
16
16
  end
17
17
 
18
18
  def stub_cache_read(body)
19
- Puppet::Module::Tool::Cache.any_instance.stubs(:read_retrieve).returns(body)
19
+ Puppet::Forge::Cache.any_instance.stubs(:read_retrieve).returns(body)
20
20
  end
21
21
 
22
22
  # Return path to temparory directory for testing.
@@ -98,11 +98,11 @@ describe "module_tool", :fails_on_windows => true do
98
98
 
99
99
  before :each do
100
100
  Puppet.settings.stubs(:parse)
101
- Puppet::Module::Tool::Cache.clean
101
+ Puppet::Forge::Cache.clean
102
102
  end
103
103
 
104
104
  after :each do
105
- Puppet::Module::Tool::Cache.clean
105
+ Puppet::Forge::Cache.clean
106
106
  end
107
107
 
108
108
  describe "generate" do
@@ -376,9 +376,8 @@ describe "module_tool", :fails_on_windows => true do
376
376
  stub_cache_read File.read("#{@full_module_name}/pkg/#{@release_name}.tar.gz")
377
377
  FileUtils.rm_rf(@full_module_name)
378
378
 
379
- stub_installer_read <<-HERE
380
- {"file": "/foo/bar/#{@release_name}.tar.gz", "version": "#{@version}"}
381
- HERE
379
+ release = {"file" => "/foo/bar/#{@release_name}.tar.gz", "version" => "#{@version}"}
380
+ Puppet::Forge::Forge.any_instance.stubs(:get_release).returns(release)
382
381
 
383
382
  Puppet::Module::Tool::Applications::Installer.run(@full_module_name, @options)
384
383
 
@@ -426,9 +425,8 @@ describe "module_tool", :fails_on_windows => true do
426
425
  stub_cache_read File.read("#{@full_module_name}/pkg/#{@release_name}.tar.gz")
427
426
  FileUtils.rm_rf(@full_module_name)
428
427
 
429
- stub_installer_read <<-HERE
430
- {"file": "/foo/bar/#{@release_name}.tar.gz", "version": "#{@version}"}
431
- HERE
428
+ release = {"file" => "/foo/bar/#{@release_name}.tar.gz", "version" => "#{@version}"}
429
+ Puppet::Forge::Forge.any_instance.stubs(:get_release).returns(release)
432
430
 
433
431
  Puppet::Module::Tool::Applications::Installer.run(@full_module_name, @options).should be_kind_of(Pathname)
434
432
  end
@@ -441,9 +439,9 @@ describe "module_tool", :fails_on_windows => true do
441
439
  it "should clean cache" do
442
440
  run do
443
441
  build_and_install_module
444
- Puppet::Module::Tool::Cache.base_path.directory?.should == true
442
+ Puppet::Forge::Cache.base_path.directory?.should == true
445
443
  Puppet::Module::Tool::Applications::Cleaner.run
446
- Puppet::Module::Tool::Cache.base_path.directory?.should == false
444
+ Puppet::Forge::Cache.base_path.directory?.should == false
447
445
  end
448
446
  end
449
447
 
@@ -131,4 +131,151 @@ describe Puppet::Parser::Compiler do
131
131
 
132
132
  lambda { Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) }.should raise_error(Puppet::Error)
133
133
  end
134
+
135
+ describe "when defining relationships" do
136
+ def extract_name(ref)
137
+ ref.sub(/File\[(\w+)\]/, '\1')
138
+ end
139
+
140
+ let(:node) { Puppet::Node.new('mynode') }
141
+ let(:code) do
142
+ <<-MANIFEST
143
+ file { [a,b,c]:
144
+ mode => 0644,
145
+ }
146
+ file { [d,e]:
147
+ mode => 0755,
148
+ }
149
+ MANIFEST
150
+ end
151
+ let(:expected_relationships) { [] }
152
+ let(:expected_subscriptions) { [] }
153
+
154
+ before :each do
155
+ Puppet[:code] = code
156
+ end
157
+
158
+ after :each do
159
+ catalog = described_class.compile(node)
160
+
161
+ resources = catalog.resources.select { |res| res.type == 'File' }
162
+
163
+ actual_relationships, actual_subscriptions = [:before, :notify].map do |relation|
164
+ resources.map do |res|
165
+ dependents = Array(res[relation])
166
+ dependents.map { |ref| [res.title, extract_name(ref)] }
167
+ end.inject(&:concat)
168
+ end
169
+
170
+ actual_relationships.should =~ expected_relationships
171
+ actual_subscriptions.should =~ expected_subscriptions
172
+ end
173
+
174
+ it "should create a relationship" do
175
+ code << "File[a] -> File[b]"
176
+
177
+ expected_relationships << ['a','b']
178
+ end
179
+
180
+ it "should create a subscription" do
181
+ code << "File[a] ~> File[b]"
182
+
183
+ expected_subscriptions << ['a', 'b']
184
+ end
185
+
186
+ it "should create relationships using title arrays" do
187
+ code << "File[a,b] -> File[c,d]"
188
+
189
+ expected_relationships.concat [
190
+ ['a', 'c'],
191
+ ['b', 'c'],
192
+ ['a', 'd'],
193
+ ['b', 'd'],
194
+ ]
195
+ end
196
+
197
+ it "should create relationships using collection expressions" do
198
+ code << "File <| mode == 0644 |> -> File <| mode == 0755 |>"
199
+
200
+ expected_relationships.concat [
201
+ ['a', 'd'],
202
+ ['b', 'd'],
203
+ ['c', 'd'],
204
+ ['a', 'e'],
205
+ ['b', 'e'],
206
+ ['c', 'e'],
207
+ ]
208
+ end
209
+
210
+ it "should create relationships using resource names" do
211
+ code << "'File[a]' -> 'File[b]'"
212
+
213
+ expected_relationships << ['a', 'b']
214
+ end
215
+
216
+ it "should create relationships using variables" do
217
+ code << <<-MANIFEST
218
+ $var = File[a]
219
+ $var -> File[b]
220
+ MANIFEST
221
+
222
+ expected_relationships << ['a', 'b']
223
+ end
224
+
225
+ it "should create relationships using case statements" do
226
+ code << <<-MANIFEST
227
+ $var = 10
228
+ case $var {
229
+ 10: {
230
+ file { s1: }
231
+ }
232
+ 12: {
233
+ file { s2: }
234
+ }
235
+ }
236
+ ->
237
+ case $var + 2 {
238
+ 10: {
239
+ file { t1: }
240
+ }
241
+ 12: {
242
+ file { t2: }
243
+ }
244
+ }
245
+ MANIFEST
246
+
247
+ expected_relationships << ['s1', 't2']
248
+ end
249
+
250
+ it "should create relationships using array members" do
251
+ code << <<-MANIFEST
252
+ $var = [ [ [ File[a], File[b] ] ] ]
253
+ $var[0][0][0] -> $var[0][0][1]
254
+ MANIFEST
255
+
256
+ expected_relationships << ['a', 'b']
257
+ end
258
+
259
+ it "should create relationships using hash members" do
260
+ code << <<-MANIFEST
261
+ $var = {'foo' => {'bar' => {'source' => File[a], 'target' => File[b]}}}
262
+ $var[foo][bar][source] -> $var[foo][bar][target]
263
+ MANIFEST
264
+
265
+ expected_relationships << ['a', 'b']
266
+ end
267
+
268
+ it "should create relationships using resource declarations" do
269
+ code << "file { l: } -> file { r: }"
270
+
271
+ expected_relationships << ['l', 'r']
272
+ end
273
+
274
+ it "should chain relationships" do
275
+ code << "File[a] -> File[b] ~> File[c] <- File[d] <~ File[e]"
276
+
277
+ expected_relationships << ['a', 'b'] << ['d', 'c']
278
+ expected_subscriptions << ['b', 'c'] << ['e', 'd']
279
+ end
280
+ end
134
281
  end
@@ -360,7 +360,7 @@ describe Puppet::Type.type(:file) do
360
360
 
361
361
  File.open(file[:path], "wb") { |f| f.puts "bar" }
362
362
 
363
- md5 = Digest::MD5.hexdigest(Puppet::Util.binread(file[:path]))
363
+ md5 = Digest::MD5.hexdigest(IO.binread(file[:path]))
364
364
 
365
365
  catalog.apply
366
366
 
@@ -0,0 +1,59 @@
1
+ #!/usr/bin/env ruby -- rspec
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "Puppet::Util::Windows::User", :if => Puppet.features.microsoft_windows? do
6
+ describe "2003 without UAC" do
7
+ before :each do
8
+ Facter.stubs(:value).with(:kernelmajversion).returns("5.2")
9
+ end
10
+
11
+ it "should be an admin if user's token contains the Administrators SID" do
12
+ Puppet::Util::Windows::User.expects(:check_token_membership).returns(true)
13
+ Win32::Security.expects(:elevated_security?).never
14
+
15
+ Puppet::Util::Windows::User.should be_admin
16
+ end
17
+
18
+ it "should not be an admin if user's token doesn't contain the Administrators SID" do
19
+ Puppet::Util::Windows::User.expects(:check_token_membership).returns(false)
20
+ Win32::Security.expects(:elevated_security?).never
21
+
22
+ Puppet::Util::Windows::User.should_not be_admin
23
+ end
24
+
25
+ it "should raise an exception if we can't check token membership" do
26
+ Puppet::Util::Windows::User.expects(:check_token_membership).raises(Win32::Security::Error, "Access denied.")
27
+ Win32::Security.expects(:elevated_security?).never
28
+
29
+ lambda { Puppet::Util::Windows::User.admin? }.should raise_error(Win32::Security::Error, /Access denied./)
30
+ end
31
+ end
32
+
33
+ describe "2008 with UAC" do
34
+ before :each do
35
+ Facter.stubs(:value).with(:kernelmajversion).returns("6.0")
36
+ end
37
+
38
+ it "should be an admin if user is running with elevated privileges" do
39
+ Win32::Security.stubs(:elevated_security?).returns(true)
40
+ Puppet::Util::Windows::User.expects(:check_token_membership).never
41
+
42
+ Puppet::Util::Windows::User.should be_admin
43
+ end
44
+
45
+ it "should not be an admin if user is not running with elevated privileges" do
46
+ Win32::Security.stubs(:elevated_security?).returns(false)
47
+ Puppet::Util::Windows::User.expects(:check_token_membership).never
48
+
49
+ Puppet::Util::Windows::User.should_not be_admin
50
+ end
51
+
52
+ it "should raise an exception if the process fails to open the process token" do
53
+ Win32::Security.stubs(:elevated_security?).raises(Win32::Security::Error, "Access denied.")
54
+ Puppet::Util::Windows::User.expects(:check_token_membership).never
55
+
56
+ lambda { Puppet::Util::Windows::User.admin? }.should raise_error(Win32::Security::Error, /Access denied./)
57
+ end
58
+ end
59
+ end
@@ -43,4 +43,9 @@ Puppet::Face.define(:basetest, '0.0.1') do
43
43
  summary "return the count of arguments given"
44
44
  when_invoked do |*args| args.length - 1 end
45
45
  end
46
+
47
+ action :with_specific_exit_code do
48
+ summary "just call exit with the desired exit code"
49
+ when_invoked do |options| exit(5) end
50
+ end
46
51
  end
@@ -0,0 +1,26 @@
1
+ module PuppetSpec::Modules
2
+ class << self
3
+ def create(name, dir, options = {})
4
+ module_dir = File.join(dir, name)
5
+ FileUtils.mkdir_p(module_dir)
6
+
7
+ environment = Puppet::Node::Environment.new(options[:environment])
8
+
9
+ if metadata = options[:metadata]
10
+ metadata[:source] ||= 'github'
11
+ metadata[:author] ||= 'puppetlabs'
12
+ metadata[:version] ||= '9.9.9'
13
+ metadata[:license] ||= 'to kill'
14
+ metadata[:dependencies] ||= []
15
+
16
+ metadata[:name] = "#{metadata[:author]}/#{name}"
17
+
18
+ File.open(File.join(module_dir, 'metadata.json'), 'w') do |f|
19
+ f.write(metadata.to_pson)
20
+ end
21
+ end
22
+
23
+ Puppet::Module.new(name, :environment => environment, :path => module_dir)
24
+ end
25
+ end
26
+ end
@@ -34,6 +34,9 @@ RSpec.configure do |config|
34
34
  config.mock_with :mocha
35
35
 
36
36
  config.before :each do
37
+ # Disabling garbage collection inside each test, and only running it at
38
+ # the end of each block, gives us an ~ 15 percent speedup, and more on
39
+ # some platforms *cough* windows *cough* that are a little slower.
37
40
  GC.disable
38
41
 
39
42
  # We need to preserve the current state of all our indirection cache and
@@ -67,6 +70,17 @@ RSpec.configure do |config|
67
70
  # I suck for letting this float. --daniel 2011-04-21
68
71
  Signal.stubs(:trap)
69
72
 
73
+ # Longer keys are secure, but they sure make for some slow testing - both
74
+ # in terms of generating keys, and in terms of anything the next step down
75
+ # the line doing validation or whatever. Most tests don't care how long
76
+ # or secure it is, just that it exists, so these are better and faster
77
+ # defaults, in testing only.
78
+ #
79
+ # I would make these even shorter, but OpenSSL doesn't support anything
80
+ # below 512 bits. Sad, really, because a 0 bit key would be just fine.
81
+ Puppet[:req_bits] = 512
82
+ Puppet[:keylength] = 512
83
+
70
84
  # Set the confdir and vardir to gibberish so that tests
71
85
  # have to be correctly mocked.
72
86
  Puppet[:confdir] = "/dev/null"
@@ -102,6 +116,17 @@ RSpec.configure do |config|
102
116
  end
103
117
  $saved_indirection_state = nil
104
118
 
119
+ # Some tests can cause us to connect, in which case the lingering
120
+ # connection is a resource that can cause unexpected failure in later
121
+ # tests, as well as sharing state accidentally.
122
+ # We're testing if ActiveRecord::Base is defined because some test cases
123
+ # may stub Puppet.features.rails? which is how we should normally
124
+ # introspect for this functionality.
125
+ ActiveRecord::Base.remove_connection if defined?(ActiveRecord::Base)
126
+
127
+ # This will perform a GC between tests, but only if actually required. We
128
+ # experimented with forcing a GC run, and that was less efficient than
129
+ # just letting it run all the time.
105
130
  GC.enable
106
131
  end
107
132
  end
@@ -29,6 +29,18 @@ describe Puppet::Agent::Locker do
29
29
  @locker.lockfile.should equal(@locker.lockfile)
30
30
  end
31
31
 
32
+ it "should use the lock file to anonymously lock the process when disabled" do
33
+ @locker.lockfile.expects(:lock).with(:anonymous => true)
34
+
35
+ @locker.disable
36
+ end
37
+
38
+ it "should use the lock file to anonymously unlock the process when enabled" do
39
+ @locker.lockfile.expects(:unlock).with(:anonymous => true)
40
+
41
+ @locker.enable
42
+ end
43
+
32
44
  it "should have a method that yields when a lock is attained" do
33
45
  @locker.lockfile.expects(:lock).returns true
34
46
 
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env rspec
2
+ require 'spec_helper'
3
+ require 'puppet/agent'
4
+
5
+
6
+ ############################################################################
7
+ # NOTE #
8
+ ############################################################################
9
+ # #
10
+ # This entire spec is only here for backwards compatibility from 2.7.12+ #
11
+ # with 2.7.10 and 2.7.11. The entire file should be able to be removed #
12
+ # for the 3.x series. #
13
+ # #
14
+ # For more info, see the comments on the #handle_2_7_10_disabled_lockfile #
15
+ # method in pidlock.rb #
16
+ # #
17
+ # --cprice 2012-03-01 #
18
+ ############################################################################
19
+
20
+ class AgentTestClient
21
+ def run
22
+ # no-op
23
+ end
24
+ def stop
25
+ # no-op
26
+ end
27
+ end
28
+
29
+ describe Puppet::Agent do
30
+ include PuppetSpec::Files
31
+
32
+ let(:agent) { Puppet::Agent.new(AgentTestClient) }
33
+
34
+ describe "in order to be backwards-compatibility with versions 2.7.10 and 2.7.11" do
35
+
36
+ describe "when the 2.7.10/2.7.11 'disabled' lockfile exists" do
37
+
38
+ # the "normal" lockfile
39
+ let(:lockfile_path) { tmpfile("agent_spec_lockfile") }
40
+
41
+ # the 2.7.10/2.7.11 "disabled" lockfile
42
+ # (can't use PuppetSpec::Files.tmpfile here because we need the ".disabled" file to have *exactly* the same
43
+ # path/name as the original file, plus the ".disabled" suffix.)
44
+ let(:disabled_lockfile_path) { lockfile_path + ".disabled" }
45
+
46
+ # some regexes to match log messages
47
+ let(:warning_regex) { /^Found special lockfile '#{disabled_lockfile_path}'.*renaming/ }
48
+ let(:disabled_regex) { /^Skipping run of .*; administratively disabled/ }
49
+
50
+ before(:each) do
51
+ # create the 2.7.10 "disable" lockfile.
52
+ FileUtils.touch(disabled_lockfile_path)
53
+
54
+ # stub in our temp lockfile path.
55
+ AgentTestClient.expects(:lockfile_path).returns lockfile_path
56
+ end
57
+
58
+ after(:each) do
59
+ # manually clean up the files that we didn't create via PuppetSpec::Files.tmpfile
60
+ begin
61
+ File.unlink(disabled_lockfile_path)
62
+ rescue Errno::ENOENT
63
+ # some of the tests expect for the agent code to take care of deleting this file,
64
+ # so it may (validly) not exist.
65
+ end
66
+ end
67
+
68
+ describe "when the 'regular' lockfile also exists" do
69
+ # the logic here is that if a 'regular' lockfile already exists, then there is some state that the
70
+ # current version of puppet is responsible for dealing with. All of the tests in this block are
71
+ # simply here to make sure that our backwards-compatibility hack does *not* interfere with this.
72
+ #
73
+ # Even if the ".disabled" lockfile exists--it can be dealt with at another time, when puppet is
74
+ # in *exactly* the state that we want it to be in (mostly meaning that the 'regular' lockfile
75
+ # does not exist.)
76
+
77
+ before(:each) do
78
+ # create the "regular" lockfile
79
+ FileUtils.touch(lockfile_path)
80
+ end
81
+
82
+ it "should be recognized as 'disabled'" do
83
+ agent.should be_disabled
84
+ end
85
+
86
+ it "should not try to start a new agent run" do
87
+ AgentTestClient.expects(:new).never
88
+ Puppet.expects(:notice).with(regexp_matches(disabled_regex))
89
+
90
+ agent.run
91
+ end
92
+
93
+ it "should not delete the 2.7.10/2.7.11 lockfile" do
94
+ agent.run
95
+
96
+ File.exists?(disabled_lockfile_path).should == true
97
+ end
98
+
99
+ it "should not print the warning message" do
100
+ Puppet.expects(:warning).with(regexp_matches(warning_regex)).never
101
+
102
+ agent.run
103
+ end
104
+ end
105
+
106
+ describe "when the 'regular' lockfile does not exist" do
107
+ # this block of tests is for actually testing the backwards compatibility hack. This
108
+ # is where we're in a clean state and we know it's safe(r) to muck with the lockfile
109
+ # situation.
110
+
111
+ it "should recognize that the agent is disabled" do
112
+ agent.should be_disabled
113
+ end
114
+
115
+ describe "when an agent run is requested" do
116
+ it "should not try to start a new agent run" do
117
+ AgentTestClient.expects(:new).never
118
+ Puppet.expects(:notice).with(regexp_matches(disabled_regex))
119
+
120
+ agent.run
121
+ end
122
+
123
+ it "should warn, remove the 2.7.10/2.7.11 lockfile, and create the 'normal' lockfile" do
124
+ Puppet.expects(:warning).with(regexp_matches(warning_regex))
125
+
126
+ agent.run
127
+
128
+ File.exists?(disabled_lockfile_path).should == false
129
+ File.exists?(lockfile_path).should == true
130
+ end
131
+ end
132
+
133
+ describe "when running --enable" do
134
+ it "should recognize that the agent is disabled" do
135
+ agent.should be_disabled
136
+ end
137
+
138
+ it "should warn and clean up the 2.7.10/2.7.11 lockfile" do
139
+ Puppet.expects(:warning).with(regexp_matches(warning_regex))
140
+
141
+ agent.enable
142
+
143
+ File.exists?(disabled_lockfile_path).should == false
144
+ File.exists?(lockfile_path).should == false
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+
152
+ end