puppet 2.6.4 → 2.6.5

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 (221) hide show
  1. data/CHANGELOG +147 -0
  2. data/LICENSE +2 -2
  3. data/Rakefile +3 -4
  4. data/lib/puppet.rb +1 -1
  5. data/lib/puppet/application.rb +22 -5
  6. data/lib/puppet/application/apply.rb +2 -18
  7. data/lib/puppet/application/doc.rb +1 -4
  8. data/lib/puppet/application/inspect.rb +178 -0
  9. data/lib/puppet/configurer.rb +9 -11
  10. data/lib/puppet/configurer/plugin_handler.rb +0 -2
  11. data/lib/puppet/defaults.rb +12 -3
  12. data/lib/puppet/external/pson/pure/generator.rb +1 -22
  13. data/lib/puppet/file_bucket/dipper.rb +9 -3
  14. data/lib/puppet/file_bucket/file.rb +14 -94
  15. data/lib/puppet/indirector.rb +4 -0
  16. data/lib/puppet/indirector/catalog/active_record.rb +1 -1
  17. data/lib/puppet/indirector/file_bucket_file/file.rb +64 -75
  18. data/lib/puppet/indirector/indirection.rb +18 -8
  19. data/lib/puppet/indirector/resource/ral.rb +7 -2
  20. data/lib/puppet/indirector/rest.rb +19 -2
  21. data/lib/puppet/network/http/api/v1.rb +3 -0
  22. data/lib/puppet/network/http/handler.rb +16 -1
  23. data/lib/puppet/network/http/rack/rest.rb +1 -3
  24. data/lib/puppet/network/rest_authconfig.rb +4 -12
  25. data/lib/puppet/network/rights.rb +28 -14
  26. data/lib/puppet/parser/ast.rb +4 -0
  27. data/lib/puppet/parser/compiler.rb +18 -3
  28. data/lib/puppet/parser/functions/defined.rb +28 -6
  29. data/lib/puppet/parser/functions/fqdn_rand.rb +6 -3
  30. data/lib/puppet/parser/templatewrapper.rb +1 -0
  31. data/lib/puppet/property.rb +16 -1
  32. data/lib/puppet/property/keyvalue.rb +0 -2
  33. data/lib/puppet/property/list.rb +0 -2
  34. data/lib/puppet/provider/file/posix.rb +1 -3
  35. data/lib/puppet/provider/file/win32.rb +1 -3
  36. data/lib/puppet/provider/maillist/mailman.rb +3 -5
  37. data/lib/puppet/provider/mount.rb +2 -0
  38. data/lib/puppet/provider/nameservice/directoryservice.rb +2 -2
  39. data/lib/puppet/provider/package/freebsd.rb +2 -2
  40. data/lib/puppet/provider/zone/solaris.rb +1 -1
  41. data/lib/puppet/reference/configuration.rb +2 -2
  42. data/lib/puppet/reference/function.rb +4 -0
  43. data/lib/puppet/relationship.rb +4 -0
  44. data/lib/puppet/reports/store.rb +1 -19
  45. data/lib/puppet/resource.rb +11 -2
  46. data/lib/puppet/resource/status.rb +24 -3
  47. data/lib/puppet/resource/type.rb +24 -16
  48. data/lib/puppet/resource/type_collection.rb +4 -1
  49. data/lib/puppet/simple_graph.rb +4 -0
  50. data/lib/puppet/transaction.rb +1 -28
  51. data/lib/puppet/transaction/event.rb +9 -4
  52. data/lib/puppet/transaction/report.rb +42 -22
  53. data/lib/puppet/transaction/resource_harness.rb +99 -71
  54. data/lib/puppet/type.rb +22 -9
  55. data/lib/puppet/type/cron.rb +1 -5
  56. data/lib/puppet/type/exec.rb +4 -34
  57. data/lib/puppet/type/file.rb +19 -26
  58. data/lib/puppet/type/file/checksum.rb +1 -1
  59. data/lib/puppet/type/file/content.rb +2 -1
  60. data/lib/puppet/type/file/ctime.rb +18 -0
  61. data/lib/puppet/type/file/ensure.rb +1 -1
  62. data/lib/puppet/type/file/mode.rb +10 -44
  63. data/lib/puppet/type/file/mtime.rb +17 -0
  64. data/lib/puppet/type/file/owner.rb +1 -1
  65. data/lib/puppet/type/file/source.rb +0 -1
  66. data/lib/puppet/type/file/target.rb +1 -1
  67. data/lib/puppet/type/file/type.rb +5 -12
  68. data/lib/puppet/type/host.rb +1 -1
  69. data/lib/puppet/type/mount.rb +2 -2
  70. data/lib/puppet/type/package.rb +0 -2
  71. data/lib/puppet/type/service.rb +11 -5
  72. data/lib/puppet/type/user.rb +7 -9
  73. data/lib/puppet/type/yumrepo.rb +2 -2
  74. data/lib/puppet/type/zpool.rb +0 -4
  75. data/lib/puppet/util/checksums.rb +24 -1
  76. data/lib/puppet/util/command_line.rb +6 -2
  77. data/lib/puppet/util/command_line/puppet +5 -1
  78. data/lib/puppet/util/command_line/puppetca +2 -2
  79. data/lib/puppet/util/command_line/puppetd +11 -9
  80. data/lib/puppet/util/command_line/puppetdoc +2 -2
  81. data/lib/puppet/util/command_line/puppetmasterd +5 -0
  82. data/lib/puppet/util/log.rb +15 -8
  83. data/lib/puppet/util/log/destinations.rb +2 -0
  84. data/lib/puppet/util/log_paths.rb +1 -1
  85. data/lib/puppet/util/logging.rb +1 -1
  86. data/lib/puppet/util/metric.rb +1 -0
  87. data/lib/puppet/util/reference.rb +1 -10
  88. data/lib/puppet/util/settings.rb +1 -1
  89. data/lib/puppet/util/zaml.rb +30 -31
  90. data/spec/fixtures/unit/provider/mount/mount-output.aix.txt +7 -0
  91. data/spec/integration/application/apply_spec.rb +1 -2
  92. data/spec/integration/defaults_spec.rb +1 -0
  93. data/spec/integration/indirector/catalog/queue_spec.rb +1 -4
  94. data/spec/integration/indirector/report/rest_spec.rb +13 -17
  95. data/spec/integration/network/formats_spec.rb +2 -5
  96. data/spec/integration/network/server/mongrel_spec.rb +1 -2
  97. data/spec/integration/provider/mailalias/aliases_spec.rb +0 -1
  98. data/spec/integration/provider/package_spec.rb +1 -3
  99. data/spec/integration/provider/service/init_spec.rb +3 -9
  100. data/spec/integration/reference/providers_spec.rb +2 -2
  101. data/spec/integration/resource/catalog_spec.rb +1 -2
  102. data/spec/integration/transaction/report_spec.rb +1 -1
  103. data/spec/monkey_patches/alias_should_to_must.rb +2 -0
  104. data/spec/shared_behaviours/file_server_terminus.rb +1 -1
  105. data/spec/shared_behaviours/file_serving.rb +1 -1
  106. data/spec/shared_behaviours/memory_terminus.rb +1 -1
  107. data/spec/spec_helper.rb +8 -6
  108. data/spec/unit/application/agent_spec.rb +1 -0
  109. data/spec/unit/application/apply_spec.rb +7 -7
  110. data/spec/unit/application/doc_spec.rb +2 -2
  111. data/spec/unit/application/filebucket_spec.rb +1 -0
  112. data/spec/unit/application/inspect_spec.rb +278 -0
  113. data/spec/unit/application/kick_spec.rb +1 -3
  114. data/spec/unit/application/master_spec.rb +1 -3
  115. data/spec/unit/application/queue_spec.rb +1 -0
  116. data/spec/unit/application_spec.rb +63 -5
  117. data/spec/unit/configurer/plugin_handler_spec.rb +5 -1
  118. data/spec/unit/configurer_spec.rb +33 -49
  119. data/spec/unit/file_bucket/dipper_spec.rb +69 -77
  120. data/spec/unit/file_bucket/file_spec.rb +12 -127
  121. data/spec/unit/file_serving/fileset_spec.rb +1 -0
  122. data/spec/unit/file_serving/metadata_spec.rb +4 -4
  123. data/spec/unit/indirector/active_record_spec.rb +1 -0
  124. data/spec/unit/indirector/catalog/active_record_spec.rb +29 -13
  125. data/spec/unit/indirector/facts/active_record_spec.rb +2 -3
  126. data/spec/unit/indirector/facts/couch_spec.rb +1 -2
  127. data/spec/unit/indirector/file_bucket_file/file_spec.rb +202 -218
  128. data/spec/unit/indirector/file_server_spec.rb +6 -7
  129. data/spec/unit/indirector/indirection_spec.rb +71 -2
  130. data/spec/unit/indirector/ldap_spec.rb +2 -6
  131. data/spec/unit/indirector/node/active_record_spec.rb +1 -3
  132. data/spec/unit/indirector/queue_spec.rb +1 -3
  133. data/spec/unit/indirector/rest_spec.rb +37 -1
  134. data/spec/unit/indirector/ssl_file_spec.rb +5 -5
  135. data/spec/unit/indirector_spec.rb +6 -1
  136. data/spec/unit/module_spec.rb +1 -3
  137. data/spec/unit/network/formats_spec.rb +2 -5
  138. data/spec/unit/network/http/api/v1_spec.rb +4 -0
  139. data/spec/unit/network/http/compression_spec.rb +1 -3
  140. data/spec/unit/network/http/handler_spec.rb +39 -0
  141. data/spec/unit/network/http/mongrel/rest_spec.rb +1 -2
  142. data/spec/unit/network/http/mongrel_spec.rb +3 -9
  143. data/spec/unit/network/http/rack/rest_spec.rb +1 -3
  144. data/spec/unit/network/http/rack/xmlrpc_spec.rb +2 -3
  145. data/spec/unit/network/http/rack_spec.rb +2 -3
  146. data/spec/unit/network/http/webrick_spec.rb +1 -0
  147. data/spec/unit/network/rest_authconfig_spec.rb +1 -1
  148. data/spec/unit/network/rights_spec.rb +43 -23
  149. data/spec/unit/network/xmlrpc/client_spec.rb +1 -0
  150. data/spec/unit/parameter_spec.rb +1 -2
  151. data/spec/unit/parser/collector_spec.rb +3 -6
  152. data/spec/unit/parser/compiler_spec.rb +90 -5
  153. data/spec/unit/parser/lexer_spec.rb +3 -2
  154. data/spec/unit/parser/templatewrapper_spec.rb +1 -0
  155. data/spec/unit/property/keyvalue_spec.rb +5 -5
  156. data/spec/unit/property/list_spec.rb +7 -7
  157. data/spec/unit/provider/mount/parsed_spec.rb +1 -2
  158. data/spec/unit/provider/mount_spec.rb +8 -0
  159. data/spec/unit/provider/nameservice/directoryservice_spec.rb +38 -0
  160. data/spec/unit/provider/package/freebsd_spec.rb +55 -0
  161. data/spec/unit/provider/service/init_spec.rb +2 -0
  162. data/spec/unit/rails/host_spec.rb +1 -3
  163. data/spec/unit/rails/param_value_spec.rb +2 -3
  164. data/spec/unit/rails/resource_spec.rb +2 -3
  165. data/spec/unit/rails_spec.rb +5 -15
  166. data/spec/unit/relationship_spec.rb +2 -6
  167. data/spec/unit/reports/http_spec.rb +1 -1
  168. data/spec/unit/reports/store_spec.rb +31 -0
  169. data/spec/unit/reports/tagmail_spec.rb +1 -1
  170. data/spec/unit/resource/catalog_spec.rb +2 -6
  171. data/spec/unit/resource/status_spec.rb +53 -3
  172. data/spec/unit/resource/type_collection_spec.rb +0 -8
  173. data/spec/unit/resource/type_spec.rb +50 -4
  174. data/spec/unit/resource_spec.rb +10 -6
  175. data/spec/unit/ssl/certificate_authority/interface_spec.rb +1 -1
  176. data/spec/unit/transaction/event_spec.rb +21 -2
  177. data/spec/unit/transaction/report_spec.rb +91 -35
  178. data/spec/unit/transaction/resource_harness_spec.rb +289 -208
  179. data/spec/unit/transaction_spec.rb +1 -6
  180. data/spec/unit/type/augeas_spec.rb +1 -3
  181. data/spec/unit/type/file/content_spec.rb +63 -10
  182. data/spec/unit/type/file/ctime.rb +35 -0
  183. data/spec/unit/type/file/ensure_spec.rb +8 -7
  184. data/spec/unit/type/file/group_spec.rb +5 -5
  185. data/spec/unit/type/file/mtime.rb +35 -0
  186. data/spec/unit/type/file/owner_spec.rb +7 -7
  187. data/spec/unit/type/file/selinux_spec.rb +2 -2
  188. data/spec/unit/type/file/source_spec.rb +3 -3
  189. data/spec/unit/type/file/type.rb +20 -0
  190. data/spec/unit/type/file_spec.rb +131 -8
  191. data/spec/unit/type/mount_spec.rb +4 -4
  192. data/spec/unit/type/package_spec.rb +3 -3
  193. data/spec/unit/type/ssh_authorized_key_spec.rb +1 -1
  194. data/spec/unit/type/user_spec.rb +31 -3
  195. data/spec/unit/type/zpool_spec.rb +12 -12
  196. data/spec/unit/type_spec.rb +2 -2
  197. data/spec/unit/util/checksums_spec.rb +9 -1
  198. data/spec/unit/util/command_line_spec.rb +29 -0
  199. data/spec/unit/util/log/destinations_spec.rb +13 -0
  200. data/spec/unit/util/log_spec.rb +24 -12
  201. data/spec/unit/util/logging_spec.rb +1 -1
  202. data/spec/unit/util/metric_spec.rb +7 -7
  203. data/spec/unit/util/pson_spec.rb +15 -0
  204. data/spec/unit/util/queue/stomp_spec.rb +2 -6
  205. data/spec/unit/util/settings/file_setting_spec.rb +1 -3
  206. data/spec/unit/util/zaml_spec.rb +51 -0
  207. data/test/language/snippets.rb +3 -0
  208. data/test/lib/puppettest/fileparsing.rb +2 -0
  209. data/test/lib/puppettest/reporttesting.rb +1 -1
  210. data/test/lib/puppettest/support/utils.rb +1 -1
  211. data/test/network/server/mongrel_test.rb +0 -6
  212. data/test/other/report.rb +1 -1
  213. data/test/ral/providers/cron/crontab.rb +4 -1
  214. data/test/ral/type/file.rb +1 -1
  215. data/test/ral/type/filesources.rb +1 -4
  216. metadata +1119 -1113
  217. data/lib/puppet/transaction/change.rb +0 -87
  218. data/spec/Rakefile +0 -91
  219. data/spec/monkey_patches/add_confine_and_runnable_to_rspec_dsl.rb +0 -46
  220. data/spec/spec_specs/runnable_spec.rb +0 -95
  221. data/spec/unit/transaction/change_spec.rb +0 -193
@@ -58,11 +58,6 @@ describe Puppet::Transaction do
58
58
  @transaction.report.resource_statuses[resource.to_s].should equal(status)
59
59
  end
60
60
 
61
- it "should calculate metrics on and report the report when asked to generate a report" do
62
- @transaction.report.expects(:calculate_metrics)
63
- @transaction.generate_report.should equal(@transaction.report)
64
- end
65
-
66
61
  it "should consider a resource to be failed if a status instance exists for that resource and indicates it is failed" do
67
62
  resource = Puppet::Type.type(:notify).new :name => "yayness"
68
63
  status = Puppet::Resource::Status.new(resource)
@@ -94,7 +89,7 @@ describe Puppet::Transaction do
94
89
  end
95
90
 
96
91
  it "should be possible to replace the report object" do
97
- report = Puppet::Transaction::Report.new
92
+ report = Puppet::Transaction::Report.new("apply")
98
93
  @transaction.report = report
99
94
 
100
95
  @transaction.report.should == report
@@ -5,9 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
5
5
  augeas = Puppet::Type.type(:augeas)
6
6
 
7
7
  describe augeas do
8
- describe "when augeas is present" do
9
- confine "Augeas is unavailable" => Puppet.features.augeas?
10
-
8
+ describe "when augeas is present", :if => Puppet.features.augeas? do
11
9
  it "should have a default provider inheriting from Puppet::Provider" do
12
10
  augeas.defaultprovider.ancestors.should be_include(Puppet::Provider)
13
11
  end
@@ -141,17 +141,20 @@ describe content do
141
141
 
142
142
  it "should return true if the resource shouldn't be a regular file" do
143
143
  @resource.expects(:should_be_file?).returns false
144
- @content.must be_insync("whatever")
144
+ @content.should = "foo"
145
+ @content.must be_safe_insync("whatever")
145
146
  end
146
147
 
147
148
  it "should return false if the current content is :absent" do
148
- @content.should_not be_insync(:absent)
149
+ @content.should = "foo"
150
+ @content.should_not be_safe_insync(:absent)
149
151
  end
150
152
 
151
153
  it "should return false if the file should be a file but is not present" do
152
154
  @resource.expects(:should_be_file?).returns true
155
+ @content.should = "foo"
153
156
 
154
- @content.should_not be_insync(:absent)
157
+ @content.should_not be_safe_insync(:absent)
155
158
  end
156
159
 
157
160
  describe "and the file exists" do
@@ -161,12 +164,12 @@ describe content do
161
164
 
162
165
  it "should return false if the current contents are different from the desired content" do
163
166
  @content.should = "some content"
164
- @content.should_not be_insync("other content")
167
+ @content.should_not be_safe_insync("other content")
165
168
  end
166
169
 
167
170
  it "should return true if the sum for the current contents is the same as the sum for the desired content" do
168
171
  @content.should = "some content"
169
- @content.must be_insync("{md5}" + Digest::MD5.hexdigest("some content"))
172
+ @content.must be_safe_insync("{md5}" + Digest::MD5.hexdigest("some content"))
170
173
  end
171
174
 
172
175
  describe "and Puppet[:show_diff] is set" do
@@ -179,14 +182,14 @@ describe content do
179
182
  @content.expects(:diff).returns("my diff").once
180
183
  @content.expects(:print).with("my diff").once
181
184
 
182
- @content.insync?("other content")
185
+ @content.safe_insync?("other content")
183
186
  end
184
187
 
185
188
  it "should not display a diff if the sum for the current contents is the same as the sum for the desired content" do
186
189
  @content.should = "some content"
187
190
  @content.expects(:diff).never
188
191
 
189
- @content.insync?("{md5}" + Digest::MD5.hexdigest("some content"))
192
+ @content.safe_insync?("{md5}" + Digest::MD5.hexdigest("some content"))
190
193
  end
191
194
  end
192
195
  end
@@ -199,17 +202,18 @@ describe content do
199
202
  it "should be insync if the file exists and the content is different" do
200
203
  @resource.stubs(:stat).returns mock('stat')
201
204
 
202
- @content.must be_insync("whatever")
205
+ @content.must be_safe_insync("whatever")
203
206
  end
204
207
 
205
208
  it "should be insync if the file exists and the content is right" do
206
209
  @resource.stubs(:stat).returns mock('stat')
207
210
 
208
- @content.must be_insync("something")
211
+ @content.must be_safe_insync("something")
209
212
  end
210
213
 
211
214
  it "should not be insync if the file does not exist" do
212
- @content.should_not be_insync(:absent)
215
+ @content.should = "foo"
216
+ @content.should_not be_safe_insync(:absent)
213
217
  end
214
218
  end
215
219
  end
@@ -457,5 +461,54 @@ describe content do
457
461
 
458
462
  describe "from a filebucket" do
459
463
  end
464
+
465
+ # These are testing the implementation rather than the desired behaviour; while that bites, there are a whole
466
+ # pile of other methods in the File type that depend on intimate details of this implementation and vice-versa.
467
+ # If these blow up, you are gonna have to review the callers to make sure they don't explode! --daniel 2011-02-01
468
+ describe "each_chunk_from should work" do
469
+ before do
470
+ @content = content.new(:resource => @resource)
471
+ end
472
+
473
+ it "when content is a string" do
474
+ @content.each_chunk_from('i_am_a_string') { |chunk| chunk.should == 'i_am_a_string' }
475
+ end
476
+
477
+ it "when no content, source, but ensure present" do
478
+ @resource[:ensure] = :present
479
+ @content.each_chunk_from(nil) { |chunk| chunk.should == '' }
480
+ end
481
+
482
+ it "when no content, source, but ensure file" do
483
+ @resource[:ensure] = :file
484
+ @content.each_chunk_from(nil) { |chunk| chunk.should == '' }
485
+ end
486
+
487
+ it "when no content or source" do
488
+ @content.expects(:read_file_from_filebucket).once.returns('im_a_filebucket')
489
+ @content.each_chunk_from(nil) { |chunk| chunk.should == 'im_a_filebucket' }
490
+ end
491
+
492
+ it "when running as puppet apply" do
493
+ @content.class.expects(:standalone?).returns true
494
+ source_or_content = stubs('source_or_content')
495
+ source_or_content.expects(:content).once.returns :whoo
496
+ @content.each_chunk_from(source_or_content) { |chunk| chunk.should == :whoo }
497
+ end
498
+
499
+ it "when running from source with a local file" do
500
+ source_or_content = stubs('source_or_content')
501
+ source_or_content.expects(:local?).returns true
502
+ @content.expects(:chunk_file_from_disk).with(source_or_content).once.yields 'woot'
503
+ @content.each_chunk_from(source_or_content) { |chunk| chunk.should == 'woot' }
504
+ end
505
+
506
+ it "when running from source with a remote file" do
507
+ source_or_content = stubs('source_or_content')
508
+ source_or_content.expects(:local?).returns false
509
+ @content.expects(:chunk_file_from_source).with(source_or_content).once.yields 'woot'
510
+ @content.each_chunk_from(source_or_content) { |chunk| chunk.should == 'woot' }
511
+ end
512
+ end
460
513
  end
461
514
  end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
4
+
5
+ describe Puppet::Type.type(:file).attrclass(:ctime) do
6
+ require 'puppet_spec/files'
7
+ include PuppetSpec::Files
8
+
9
+ before do
10
+ @filename = tmpfile('ctime')
11
+ @resource = Puppet::Type.type(:file).new({:name => @filename})
12
+ end
13
+
14
+ it "should be able to audit the file's ctime" do
15
+ File.open(@filename, "w"){ }
16
+
17
+ @resource[:audit] = [:ctime]
18
+
19
+ # this .to_resource audit behavior is magical :-(
20
+ @resource.to_resource[:ctime].should == File.stat(@filename).ctime
21
+ end
22
+
23
+ it "should return absent if auditing an absent file" do
24
+ @resource[:audit] = [:ctime]
25
+
26
+ @resource.to_resource[:ctime].should == :absent
27
+ end
28
+
29
+ it "should prevent the user from trying to set the ctime" do
30
+ lambda {
31
+ @resource[:ctime] = Time.now.to_s
32
+ }.should raise_error(Puppet::Error, /ctime is read-only/)
33
+ end
34
+
35
+ end
@@ -41,44 +41,45 @@ describe property do
41
41
  end
42
42
 
43
43
  it "should always be in sync if replace is 'false' unless the file is missing" do
44
+ @ensure.should = :file
44
45
  @resource.expects(:replace?).returns false
45
- @ensure.insync?(:link).should be_true
46
+ @ensure.safe_insync?(:link).should be_true
46
47
  end
47
48
 
48
49
  it "should be in sync if :ensure is set to :absent and the file does not exist" do
49
50
  @ensure.should = :absent
50
51
 
51
- @ensure.must be_insync(:absent)
52
+ @ensure.must be_safe_insync(:absent)
52
53
  end
53
54
 
54
55
  it "should not be in sync if :ensure is set to :absent and the file exists" do
55
56
  @ensure.should = :absent
56
57
 
57
- @ensure.should_not be_insync(:file)
58
+ @ensure.should_not be_safe_insync(:file)
58
59
  end
59
60
 
60
61
  it "should be in sync if a normal file exists and :ensure is set to :present" do
61
62
  @ensure.should = :present
62
63
 
63
- @ensure.must be_insync(:file)
64
+ @ensure.must be_safe_insync(:file)
64
65
  end
65
66
 
66
67
  it "should be in sync if a directory exists and :ensure is set to :present" do
67
68
  @ensure.should = :present
68
69
 
69
- @ensure.must be_insync(:directory)
70
+ @ensure.must be_safe_insync(:directory)
70
71
  end
71
72
 
72
73
  it "should be in sync if a symlink exists and :ensure is set to :present" do
73
74
  @ensure.should = :present
74
75
 
75
- @ensure.must be_insync(:link)
76
+ @ensure.must be_safe_insync(:link)
76
77
  end
77
78
 
78
79
  it "should not be in sync if :ensure is set to :file and a directory exists" do
79
80
  @ensure.should = :file
80
81
 
81
- @ensure.should_not be_insync(:directory)
82
+ @ensure.should_not be_safe_insync(:directory)
82
83
  end
83
84
  end
84
85
  end
@@ -56,19 +56,19 @@ describe property do
56
56
  describe "when determining if the file is in sync" do
57
57
  it "should directly compare the group values if the desired group is an integer" do
58
58
  @group.should = [10]
59
- @group.must be_insync(10)
59
+ @group.must be_safe_insync(10)
60
60
  end
61
61
 
62
62
  it "should treat numeric strings as integers" do
63
63
  @group.should = ["10"]
64
- @group.must be_insync(10)
64
+ @group.must be_safe_insync(10)
65
65
  end
66
66
 
67
67
  it "should convert the group name to an integer if the desired group is a string" do
68
68
  @group.expects(:gid).with("foo").returns 10
69
69
  @group.should = %w{foo}
70
70
 
71
- @group.must be_insync(10)
71
+ @group.must be_safe_insync(10)
72
72
  end
73
73
 
74
74
  it "should not validate that groups exist when a group is specified as an integer" do
@@ -80,12 +80,12 @@ describe property do
80
80
  @group.expects(:gid).with("foo").returns nil
81
81
  @group.should = %w{foo}
82
82
 
83
- lambda { @group.insync?(10) }.should raise_error(Puppet::Error)
83
+ lambda { @group.safe_insync?(10) }.should raise_error(Puppet::Error)
84
84
  end
85
85
 
86
86
  it "should return false if the groups are not equal" do
87
87
  @group.should = [10]
88
- @group.should_not be_insync(20)
88
+ @group.should_not be_safe_insync(20)
89
89
  end
90
90
  end
91
91
 
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
4
+
5
+ describe Puppet::Type.type(:file).attrclass(:mtime) do
6
+ require 'puppet_spec/files'
7
+ include PuppetSpec::Files
8
+
9
+ before do
10
+ @filename = tmpfile('mtime')
11
+ @resource = Puppet::Type.type(:file).new({:name => @filename})
12
+ end
13
+
14
+ it "should be able to audit the file's mtime" do
15
+ File.open(@filename, "w"){ }
16
+
17
+ @resource[:audit] = [:mtime]
18
+
19
+ # this .to_resource audit behavior is magical :-(
20
+ @resource.to_resource[:mtime].should == File.stat(@filename).mtime
21
+ end
22
+
23
+ it "should return absent if auditing an absent file" do
24
+ @resource[:audit] = [:mtime]
25
+
26
+ @resource.to_resource[:mtime].should == :absent
27
+ end
28
+
29
+ it "should prevent the user from trying to set the mtime" do
30
+ lambda {
31
+ @resource[:mtime] = Time.now.to_s
32
+ }.should raise_error(Puppet::Error, /mtime is read-only/)
33
+ end
34
+
35
+ end
@@ -68,7 +68,7 @@ describe property do
68
68
  @provider.expects(:warnonce)
69
69
 
70
70
  @owner.should = [10]
71
- @owner.must be_insync(20)
71
+ @owner.must be_safe_insync(20)
72
72
  end
73
73
  end
74
74
 
@@ -77,24 +77,24 @@ describe property do
77
77
  end
78
78
 
79
79
  it "should be in sync if 'should' is not provided" do
80
- @owner.must be_insync(10)
80
+ @owner.must be_safe_insync(10)
81
81
  end
82
82
 
83
83
  it "should directly compare the owner values if the desired owner is an integer" do
84
84
  @owner.should = [10]
85
- @owner.must be_insync(10)
85
+ @owner.must be_safe_insync(10)
86
86
  end
87
87
 
88
88
  it "should treat numeric strings as integers" do
89
89
  @owner.should = ["10"]
90
- @owner.must be_insync(10)
90
+ @owner.must be_safe_insync(10)
91
91
  end
92
92
 
93
93
  it "should convert the owner name to an integer if the desired owner is a string" do
94
94
  @provider.expects(:uid).with("foo").returns 10
95
95
  @owner.should = %w{foo}
96
96
 
97
- @owner.must be_insync(10)
97
+ @owner.must be_safe_insync(10)
98
98
  end
99
99
 
100
100
  it "should not validate that users exist when a user is specified as an integer" do
@@ -106,12 +106,12 @@ describe property do
106
106
  @provider.expects(:uid).with("foo").returns nil
107
107
  @owner.should = %w{foo}
108
108
 
109
- lambda { @owner.insync?(10) }.should raise_error(Puppet::Error)
109
+ lambda { @owner.safe_insync?(10) }.should raise_error(Puppet::Error)
110
110
  end
111
111
 
112
112
  it "should return false if the owners are not equal" do
113
113
  @owner.should = [10]
114
- @owner.should_not be_insync(20)
114
+ @owner.should_not be_safe_insync(20)
115
115
  end
116
116
  end
117
117
 
@@ -73,10 +73,10 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f
73
73
  @sel.sync
74
74
  end
75
75
 
76
- it "should do nothing for insync? if no SELinux support" do
76
+ it "should do nothing for safe_insync? if no SELinux support" do
77
77
  @sel.should = %{newcontext}
78
78
  @sel.expects(:selinux_support?).returns false
79
- @sel.insync?("oldcontext").should == true
79
+ @sel.safe_insync?("oldcontext").should == true
80
80
  end
81
81
  end
82
82
  end
@@ -6,7 +6,7 @@ source = Puppet::Type.type(:file).attrclass(:source)
6
6
  describe Puppet::Type.type(:file).attrclass(:source) do
7
7
  before do
8
8
  # Wow that's a messy interface to the resource.
9
- @resource = stub 'resource', :[]= => nil, :property => nil, :catalog => stub("catalog", :dependent_data_expired? => false)
9
+ @resource = stub 'resource', :[]= => nil, :property => nil, :catalog => stub("catalog", :dependent_data_expired? => false), :line => 0, :file => ''
10
10
  end
11
11
 
12
12
  it "should be a subclass of Parameter" do
@@ -154,7 +154,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do
154
154
 
155
155
  @resource[:owner].must == 100
156
156
  @resource[:group].must == 200
157
- @resource[:mode].must == 123
157
+ @resource[:mode].must == "173"
158
158
 
159
159
  # Metadata calls it checksum, we call it content.
160
160
  @resource[:content].must == @metadata.checksum
@@ -170,7 +170,7 @@ describe Puppet::Type.type(:file).attrclass(:source) do
170
170
 
171
171
  @resource[:owner].must == 1
172
172
  @resource[:group].must == 2
173
- @resource[:mode].must == 3
173
+ @resource[:mode].must == "3"
174
174
  @resource[:content].should_not == @metadata.checksum
175
175
  end
176
176
 
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f) : Dir.chdir("..") { s.call(f) } }).call("spec/spec_helper.rb") }
4
+
5
+ describe Puppet::Type.type(:file).attrclass(:type) do
6
+ require 'puppet_spec/files'
7
+ include PuppetSpec::Files
8
+
9
+ before do
10
+ @filename = tmpfile('type')
11
+ @resource = Puppet::Type.type(:file).new({:name => @filename})
12
+ end
13
+
14
+ it "should prevent the user from trying to set the type" do
15
+ lambda {
16
+ @resource[:type] = "fifo"
17
+ }.should raise_error(Puppet::Error, /type is read-only/)
18
+ end
19
+
20
+ end
@@ -71,7 +71,7 @@ describe Puppet::Type.type(:file) do
71
71
  before { @file.stubs(:validate_checksum?).returns(true) }
72
72
 
73
73
  it "should fail if the checksum parameter and content checksums do not match" do
74
- checksum = stub('checksum_parameter', :sum => 'checksum_b')
74
+ checksum = stub('checksum_parameter', :sum => 'checksum_b', :sum_file => 'checksum_b')
75
75
  @file.stubs(:parameter).with(:checksum).returns(checksum)
76
76
 
77
77
  property = stub('content_property', :actual_content => "something", :length => "something".length, :write => 'checksum_a')
@@ -194,6 +194,23 @@ describe Puppet::Type.type(:file) do
194
194
  file = Puppet::Type::File.new(:path => "/")
195
195
  file[:path].should == "/"
196
196
  end
197
+
198
+ it "should accept a double-slash at the start of the path" do
199
+ expect {
200
+ file = Puppet::Type::File.new(:path => "//tmp/xxx")
201
+ # REVISIT: This should be wrong, later. See the next test.
202
+ # --daniel 2011-01-31
203
+ file[:path].should == '/tmp/xxx'
204
+ }.should_not raise_error
205
+ end
206
+
207
+ # REVISIT: This is pending, because I don't want to try and audit the
208
+ # entire codebase to make sure we get this right. POSIX treats two (and
209
+ # exactly two) '/' characters at the start of the path specially.
210
+ #
211
+ # See sections 3.2 and 4.11, which allow DomainOS to be all special like
212
+ # and still have the POSIX branding and all. --daniel 2011-01-31
213
+ it "should preserve the double-slash at the start of the path"
197
214
  end
198
215
 
199
216
  describe "on Microsoft Windows systems" do
@@ -208,8 +225,7 @@ describe Puppet::Type.type(:file) do
208
225
  end
209
226
  end
210
227
 
211
- describe "when using Microsoft Windows filenames" do
212
- confine "Only works on Microsoft Windows" => Puppet.features.microsoft_windows?
228
+ describe "when using Microsoft Windows filenames", :if => Puppet.features.microsoft_windows? do
213
229
  describe "on Microsoft Windows systems" do
214
230
  before do
215
231
  Puppet.features.stubs(:posix?).returns(false)
@@ -271,8 +287,7 @@ describe Puppet::Type.type(:file) do
271
287
  end
272
288
 
273
289
  describe "when using UNC filenames" do
274
- describe "on Microsoft Windows systems" do
275
- confine "Only works on Microsoft Windows" => Puppet.features.microsoft_windows?
290
+ describe "on Microsoft Windows systems", :if => Puppet.features.microsoft_windows? do
276
291
  before do
277
292
  Puppet.features.stubs(:posix?).returns(false)
278
293
  Puppet.features.stubs(:microsoft_windows?).returns(true)
@@ -381,9 +396,9 @@ describe Puppet::Type.type(:file) do
381
396
 
382
397
 
383
398
  @resource = Puppet::Type.type(:file).new(
384
-
399
+
385
400
  :path => @link,
386
-
401
+
387
402
  :mode => "755"
388
403
  )
389
404
  @catalog.add_resource @resource
@@ -808,6 +823,73 @@ describe Puppet::Type.type(:file) do
808
823
  end
809
824
  end
810
825
 
826
+ describe "when specifying both source, and content properties" do
827
+ before do
828
+ @file[:source] = '/one'
829
+ @file[:content] = 'file contents'
830
+ end
831
+
832
+ it "should raise an exception" do
833
+ lambda {@file.validate }.should raise_error(/You cannot specify more than one of/)
834
+ end
835
+ end
836
+
837
+ describe "when using source" do
838
+ before do
839
+ @file[:source] = '/one'
840
+ end
841
+ Puppet::Type::File::ParameterChecksum.value_collection.values.reject {|v| v == :none}.each do |checksum_type|
842
+ describe "with checksum '#{checksum_type}'" do
843
+ before do
844
+ @file[:checksum] = checksum_type
845
+ end
846
+
847
+ it 'should validate' do
848
+
849
+ lambda { @file.validate }.should_not raise_error
850
+ end
851
+ end
852
+ end
853
+
854
+ describe "with checksum 'none'" do
855
+ before do
856
+ @file[:checksum] = :none
857
+ end
858
+
859
+ it 'should raise an exception when validating' do
860
+ lambda { @file.validate }.should raise_error(/You cannot specify source when using checksum 'none'/)
861
+ end
862
+ end
863
+ end
864
+
865
+ describe "when using content" do
866
+ before do
867
+ @file[:content] = 'file contents'
868
+ end
869
+
870
+ (Puppet::Type::File::ParameterChecksum.value_collection.values - SOURCE_ONLY_CHECKSUMS).each do |checksum_type|
871
+ describe "with checksum '#{checksum_type}'" do
872
+ before do
873
+ @file[:checksum] = checksum_type
874
+ end
875
+
876
+ it 'should validate' do
877
+ lambda { @file.validate }.should_not raise_error
878
+ end
879
+ end
880
+ end
881
+
882
+ SOURCE_ONLY_CHECKSUMS.each do |checksum_type|
883
+ describe "with checksum '#{checksum_type}'" do
884
+ it 'should raise an exception when validating' do
885
+ @file[:checksum] = checksum_type
886
+
887
+ lambda { @file.validate }.should raise_error(/You cannot specify content when using checksum '#{checksum_type}'/)
888
+ end
889
+ end
890
+ end
891
+ end
892
+
811
893
  describe "when returning resources with :eval_generate" do
812
894
  before do
813
895
  @graph = stub 'graph', :add_edge => nil
@@ -1058,7 +1140,7 @@ describe Puppet::Type.type(:file) do
1058
1140
  before do
1059
1141
  @type_class = Puppet::Type.type(:file)
1060
1142
  end
1061
-
1143
+
1062
1144
  it "should have a regexp that captures the entire string, except for a terminating slash" do
1063
1145
  patterns = @type_class.title_patterns
1064
1146
  string = "abc/\n\tdef/"
@@ -1067,4 +1149,45 @@ describe Puppet::Type.type(:file) do
1067
1149
  end
1068
1150
  end
1069
1151
 
1152
+ describe "when auditing" do
1153
+ it "should not fail if creating a new file if group is not set" do
1154
+ File.exists?(@path).should == false
1155
+ file = Puppet::Type::File.new(:name => @path, :audit => "all", :content => "content")
1156
+ catalog = Puppet::Resource::Catalog.new
1157
+ catalog.add_resource(file)
1158
+
1159
+ Puppet::Util::Storage.stubs(:store) # to prevent the catalog from trying to write state.yaml
1160
+ transaction = catalog.apply
1161
+
1162
+ transaction.report.resource_statuses["File[#{@path}]"].failed.should == false
1163
+ File.exists?(@path).should == true
1164
+ end
1165
+
1166
+ it "should not log errors if creating a new file with ensure present and no content" do
1167
+ File.exists?(@path).should == false
1168
+ file = Puppet::Type::File.new(:name => @path, :audit => "content", :ensure => "present")
1169
+ catalog = Puppet::Resource::Catalog.new
1170
+ catalog.add_resource(file)
1171
+
1172
+ Puppet::Util::Storage.stubs(:store) # to prevent the catalog from trying to write state.yaml
1173
+
1174
+ catalog.apply
1175
+ @logs.reject {|l| l.level == :notice }.should be_empty
1176
+ end
1177
+ end
1178
+
1179
+ describe "when specifying both source and checksum" do
1180
+ it 'should use the specified checksum when source is first' do
1181
+ @file[:source] = '/foo'
1182
+ @file[:checksum] = :md5lite
1183
+
1184
+ @file[:checksum].should be :md5lite
1185
+ end
1186
+ it 'should use the specified checksum when source is last' do
1187
+ @file[:checksum] = :md5lite
1188
+ @file[:source] = '/foo'
1189
+
1190
+ @file[:checksum].should be :md5lite
1191
+ end
1192
+ end
1070
1193
  end