puppet 2.7.5 → 2.7.6

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 (140) hide show
  1. data/CHANGELOG +121 -0
  2. data/conf/redhat/puppet.spec +16 -7
  3. data/lib/puppet.rb +1 -1
  4. data/lib/puppet/application/cert.rb +17 -3
  5. data/lib/puppet/application/device.rb +1 -0
  6. data/lib/puppet/application/kick.rb +0 -2
  7. data/lib/puppet/application/resource.rb +73 -66
  8. data/lib/puppet/configurer/plugin_handler.rb +6 -2
  9. data/lib/puppet/defaults.rb +60 -5
  10. data/lib/puppet/face/ca.rb +11 -2
  11. data/lib/puppet/face/certificate.rb +33 -4
  12. data/lib/puppet/file_serving/fileset.rb +1 -1
  13. data/lib/puppet/file_serving/indirection_hooks.rb +2 -2
  14. data/lib/puppet/file_serving/metadata.rb +43 -4
  15. data/lib/puppet/indirector.rb +0 -1
  16. data/lib/puppet/indirector/request.rb +3 -4
  17. data/lib/puppet/indirector/resource/active_record.rb +3 -10
  18. data/lib/puppet/indirector/resource/ral.rb +2 -2
  19. data/lib/puppet/indirector/rest.rb +1 -1
  20. data/lib/puppet/network/handler/ca.rb +16 -106
  21. data/lib/puppet/network/handler/master.rb +0 -3
  22. data/lib/puppet/network/handler/runner.rb +1 -0
  23. data/lib/puppet/parser/scope.rb +10 -0
  24. data/lib/puppet/provider/file/posix.rb +72 -34
  25. data/lib/puppet/provider/file/windows.rb +100 -0
  26. data/lib/puppet/provider/group/windows_adsi.rb +2 -2
  27. data/lib/puppet/provider/user/windows_adsi.rb +19 -4
  28. data/lib/puppet/resource.rb +16 -0
  29. data/lib/puppet/resource/catalog.rb +1 -1
  30. data/lib/puppet/ssl/certificate.rb +2 -2
  31. data/lib/puppet/ssl/certificate_authority.rb +86 -10
  32. data/lib/puppet/ssl/certificate_authority/interface.rb +64 -19
  33. data/lib/puppet/ssl/certificate_factory.rb +112 -91
  34. data/lib/puppet/ssl/certificate_request.rb +88 -1
  35. data/lib/puppet/ssl/host.rb +20 -3
  36. data/lib/puppet/type/file.rb +15 -34
  37. data/lib/puppet/type/file/group.rb +11 -91
  38. data/lib/puppet/type/file/mode.rb +11 -41
  39. data/lib/puppet/type/file/owner.rb +18 -34
  40. data/lib/puppet/type/file/source.rb +22 -7
  41. data/lib/puppet/type/group.rb +4 -3
  42. data/lib/puppet/type/user.rb +4 -1
  43. data/lib/puppet/util.rb +59 -6
  44. data/lib/puppet/util/adsi.rb +11 -0
  45. data/lib/puppet/util/log.rb +4 -0
  46. data/lib/puppet/util/log/destinations.rb +7 -1
  47. data/lib/puppet/util/monkey_patches.rb +19 -0
  48. data/lib/puppet/util/network_device/config.rb +4 -5
  49. data/lib/puppet/util/settings.rb +5 -0
  50. data/lib/puppet/util/suidmanager.rb +0 -1
  51. data/lib/puppet/util/windows.rb +4 -0
  52. data/lib/puppet/util/windows/error.rb +16 -0
  53. data/lib/puppet/util/windows/security.rb +593 -0
  54. data/spec/integration/defaults_spec.rb +27 -0
  55. data/spec/integration/network/handler_spec.rb +1 -1
  56. data/spec/integration/type/file_spec.rb +382 -145
  57. data/spec/integration/util/windows/security_spec.rb +468 -0
  58. data/spec/shared_behaviours/file_serving.rb +4 -3
  59. data/spec/unit/application/agent_spec.rb +1 -0
  60. data/spec/unit/application/device_spec.rb +5 -0
  61. data/spec/unit/application/resource_spec.rb +62 -101
  62. data/spec/unit/configurer/downloader_spec.rb +2 -2
  63. data/spec/unit/configurer/plugin_handler_spec.rb +15 -8
  64. data/spec/unit/configurer_spec.rb +2 -2
  65. data/spec/unit/face/ca_spec.rb +34 -0
  66. data/spec/unit/face/certificate_spec.rb +168 -1
  67. data/spec/unit/file_serving/fileset_spec.rb +1 -1
  68. data/spec/unit/file_serving/indirection_hooks_spec.rb +1 -1
  69. data/spec/unit/file_serving/metadata_spec.rb +151 -107
  70. data/spec/unit/indirector/certificate_request/ca_spec.rb +0 -3
  71. data/spec/unit/indirector/direct_file_server_spec.rb +10 -9
  72. data/spec/unit/indirector/file_metadata/file_spec.rb +6 -4
  73. data/spec/unit/indirector/request_spec.rb +13 -3
  74. data/spec/unit/indirector/resource/active_record_spec.rb +4 -10
  75. data/spec/unit/indirector/resource/ral_spec.rb +6 -4
  76. data/spec/unit/indirector/rest_spec.rb +5 -6
  77. data/spec/unit/network/handler/ca_spec.rb +86 -0
  78. data/spec/unit/parser/collector_spec.rb +7 -7
  79. data/spec/unit/parser/scope_spec.rb +20 -0
  80. data/spec/unit/provider/file/posix_spec.rb +226 -0
  81. data/spec/unit/provider/file/windows_spec.rb +136 -0
  82. data/spec/unit/provider/group/windows_adsi_spec.rb +7 -2
  83. data/spec/unit/provider/user/windows_adsi_spec.rb +36 -3
  84. data/spec/unit/resource/catalog_spec.rb +20 -10
  85. data/spec/unit/resource_spec.rb +55 -8
  86. data/spec/unit/ssl/certificate_authority/interface_spec.rb +97 -54
  87. data/spec/unit/ssl/certificate_authority_spec.rb +133 -23
  88. data/spec/unit/ssl/certificate_factory_spec.rb +90 -70
  89. data/spec/unit/ssl/certificate_request_spec.rb +62 -1
  90. data/spec/unit/ssl/certificate_spec.rb +20 -14
  91. data/spec/unit/ssl/host_spec.rb +52 -6
  92. data/spec/unit/type/file/content_spec.rb +4 -4
  93. data/spec/unit/type/file/group_spec.rb +34 -96
  94. data/spec/unit/type/file/mode_spec.rb +88 -0
  95. data/spec/unit/type/file/owner_spec.rb +32 -123
  96. data/spec/unit/type/file/source_spec.rb +120 -41
  97. data/spec/unit/type/file_spec.rb +1033 -753
  98. data/spec/unit/type_spec.rb +19 -1
  99. data/spec/unit/util/adsi_spec.rb +19 -0
  100. data/spec/unit/util/log/destinations_spec.rb +75 -0
  101. data/spec/unit/util/log_spec.rb +15 -0
  102. data/spec/unit/util/network_device/config_spec.rb +7 -0
  103. data/spec/unit/util/settings_spec.rb +10 -0
  104. data/spec/unit/util_spec.rb +126 -13
  105. data/test/language/functions.rb +0 -1
  106. data/test/language/snippets.rb +0 -9
  107. data/test/lib/puppettest/exetest.rb +1 -1
  108. data/test/lib/puppettest/servertest.rb +0 -1
  109. data/test/rails/rails.rb +0 -1
  110. data/test/ral/type/filesources.rb +0 -60
  111. metadata +13 -33
  112. data/lib/puppet/network/client.rb +0 -174
  113. data/lib/puppet/network/client/ca.rb +0 -56
  114. data/lib/puppet/network/client/file.rb +0 -6
  115. data/lib/puppet/network/client/proxy.rb +0 -27
  116. data/lib/puppet/network/client/report.rb +0 -26
  117. data/lib/puppet/network/client/runner.rb +0 -10
  118. data/lib/puppet/network/client/status.rb +0 -4
  119. data/lib/puppet/network/http_server.rb +0 -3
  120. data/lib/puppet/network/http_server/mongrel.rb +0 -130
  121. data/lib/puppet/network/http_server/webrick.rb +0 -155
  122. data/lib/puppet/network/xmlrpc/client.rb +0 -211
  123. data/lib/puppet/provider/file/win32.rb +0 -72
  124. data/lib/puppet/sslcertificates.rb +0 -146
  125. data/lib/puppet/sslcertificates/ca.rb +0 -375
  126. data/lib/puppet/sslcertificates/certificate.rb +0 -255
  127. data/lib/puppet/sslcertificates/inventory.rb +0 -38
  128. data/lib/puppet/sslcertificates/support.rb +0 -146
  129. data/spec/integration/network/client_spec.rb +0 -18
  130. data/spec/unit/network/xmlrpc/client_spec.rb +0 -172
  131. data/spec/unit/sslcertificates/ca_spec.rb +0 -106
  132. data/test/certmgr/certmgr.rb +0 -308
  133. data/test/certmgr/inventory.rb +0 -69
  134. data/test/certmgr/support.rb +0 -105
  135. data/test/network/client/ca.rb +0 -69
  136. data/test/network/client/dipper.rb +0 -34
  137. data/test/network/handler/ca.rb +0 -273
  138. data/test/network/server/mongrel_test.rb +0 -99
  139. data/test/network/server/webrick.rb +0 -111
  140. data/test/network/xmlrpc/client.rb +0 -45
@@ -44,6 +44,17 @@ describe "Puppet defaults" do
44
44
  end
45
45
  end
46
46
 
47
+ describe "when :certdnsnames is set" do
48
+ it "should not fail" do
49
+ expect { Puppet[:certdnsnames] = 'fred:wilma' }.should_not raise_error
50
+ end
51
+
52
+ it "should warn the value is ignored" do
53
+ Puppet.expects(:warning).with {|msg| msg =~ /CVE-2011-3872/ }
54
+ Puppet[:certdnsnames] = 'fred:wilma'
55
+ end
56
+ end
57
+
47
58
  describe "when configuring the :crl" do
48
59
  it "should warn if :cacrl is set to false" do
49
60
  Puppet.expects(:warning)
@@ -282,4 +293,20 @@ describe "Puppet defaults" do
282
293
  Puppet.settings[:color].should == 'false'
283
294
  end
284
295
  end
296
+
297
+ describe "daemonize" do
298
+ it "should default to true", :unless => Puppet.features.microsoft_windows? do
299
+ Puppet.settings[:daemonize].should == true
300
+ end
301
+
302
+ describe "on Windows", :if => Puppet.features.microsoft_windows? do
303
+ it "should default to false" do
304
+ Puppet.settings[:daemonize].should == false
305
+ end
306
+
307
+ it "should raise an error if set to true" do
308
+ lambda { Puppet.settings[:daemonize] = true }.should raise_error(/Cannot daemonize on Windows/)
309
+ end
310
+ end
311
+ end
285
312
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env rspec
2
2
  require 'spec_helper'
3
3
 
4
- require 'puppet/network/client'
4
+ require 'puppet/network/handler'
5
5
 
6
6
  describe Puppet::Network::Handler do
7
7
  %w{ca filebucket fileserver master report runner status}.each do |name|
@@ -3,32 +3,103 @@ require 'spec_helper'
3
3
 
4
4
  require 'puppet_spec/files'
5
5
 
6
+ if Puppet.features.microsoft_windows?
7
+ require 'puppet/util/windows'
8
+ class WindowsSecurity
9
+ extend Puppet::Util::Windows::Security
10
+ end
11
+ end
12
+
6
13
  describe Puppet::Type.type(:file) do
7
14
  include PuppetSpec::Files
8
15
 
16
+ let(:catalog) { Puppet::Resource::Catalog.new }
17
+ let(:path) { tmpfile('file_testing') }
18
+
19
+ if Puppet.features.posix?
20
+ def get_mode(file)
21
+ File.lstat(file).mode
22
+ end
23
+
24
+ def get_owner(file)
25
+ File.lstat(file).uid
26
+ end
27
+
28
+ def get_group(file)
29
+ File.lstat(file).gid
30
+ end
31
+ else
32
+ class SecurityHelper
33
+ extend Puppet::Util::Windows::Security
34
+ end
35
+
36
+ def get_mode(file)
37
+ SecurityHelper.get_mode(file)
38
+ end
39
+
40
+ def get_owner(file)
41
+ SecurityHelper.get_owner(file)
42
+ end
43
+
44
+ def get_group(file)
45
+ SecurityHelper.get_group(file)
46
+ end
47
+ end
48
+
9
49
  before do
10
50
  # stub this to not try to create state.yaml
11
51
  Puppet::Util::Storage.stubs(:store)
12
52
  end
13
53
 
14
54
  it "should not attempt to manage files that do not exist if no means of creating the file is specified" do
15
- file = Puppet::Type.type(:file).new :path => make_absolute("/my/file"), :mode => "755"
16
- catalog = Puppet::Resource::Catalog.new
55
+ file = described_class.new :path => path, :mode => 0755
17
56
  catalog.add_resource file
18
57
 
19
58
  file.parameter(:mode).expects(:retrieve).never
20
59
 
21
- transaction = Puppet::Transaction.new(catalog)
22
- transaction.resource_harness.evaluate(file).should_not be_failed
60
+ report = catalog.apply.report
61
+ report.resource_statuses["File[#{path}]"].should_not be_failed
62
+ File.should_not be_exist(path)
63
+ end
64
+
65
+ describe "when setting permissions" do
66
+ it "should set the owner" do
67
+ FileUtils.touch(path)
68
+ owner = get_owner(path)
69
+
70
+ file = described_class.new(
71
+ :name => path,
72
+ :owner => owner
73
+ )
74
+
75
+ catalog.add_resource file
76
+ catalog.apply
77
+
78
+ get_owner(path).should == owner
79
+ end
80
+
81
+ it "should set the group" do
82
+ FileUtils.touch(path)
83
+ group = get_group(path)
84
+
85
+ file = described_class.new(
86
+ :name => path,
87
+ :group => group
88
+ )
89
+
90
+ catalog.add_resource file
91
+ catalog.apply
92
+
93
+ get_group(path).should == group
94
+ end
23
95
  end
24
96
 
25
97
  describe "when writing files" do
26
- it "should backup files to a filebucket when one is configured", :fails_on_windows => true do
27
- bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
28
- file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo"
29
- catalog = Puppet::Resource::Catalog.new
98
+ it "should backup files to a filebucket when one is configured" do
99
+ filebucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
100
+ file = described_class.new :path => path, :backup => "mybucket", :content => "foo"
30
101
  catalog.add_resource file
31
- catalog.add_resource bucket
102
+ catalog.add_resource filebucket
32
103
 
33
104
  File.open(file[:path], "w") { |f| f.puts "bar" }
34
105
 
@@ -36,12 +107,11 @@ describe Puppet::Type.type(:file) do
36
107
 
37
108
  catalog.apply
38
109
 
39
- bucket.bucket.getfile(md5).should == "bar\n"
110
+ filebucket.bucket.getfile(md5).should == "bar\n"
40
111
  end
41
112
 
42
113
  it "should backup files in the local directory when a backup string is provided" do
43
- file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => ".bak", :content => "foo"
44
- catalog = Puppet::Resource::Catalog.new
114
+ file = described_class.new :path => path, :backup => ".bak", :content => "foo"
45
115
  catalog.add_resource file
46
116
 
47
117
  File.open(file[:path], "w") { |f| f.puts "bar" }
@@ -56,12 +126,11 @@ describe Puppet::Type.type(:file) do
56
126
  it "should fail if no backup can be performed" do
57
127
  dir = tmpfile("backups")
58
128
  Dir.mkdir(dir)
59
- path = File.join(dir, "testfile")
60
- file = Puppet::Type.type(:file).new :path => path, :backup => ".bak", :content => "foo"
61
- catalog = Puppet::Resource::Catalog.new
129
+
130
+ file = described_class.new :path => File.join(dir, "testfile"), :backup => ".bak", :content => "foo"
62
131
  catalog.add_resource file
63
132
 
64
- File.open(file[:path], "w") { |f| f.puts "bar" }
133
+ File.open(file[:path], 'w') { |f| f.puts "bar" }
65
134
 
66
135
  # Create a directory where the backup should be so that writing to it fails
67
136
  Dir.mkdir(File.join(dir, "testfile.bak"))
@@ -78,8 +147,7 @@ describe Puppet::Type.type(:file) do
78
147
  dest1 = tmpfile("dest1")
79
148
  dest2 = tmpfile("dest2")
80
149
  bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
81
- file = Puppet::Type.type(:file).new :path => link, :target => dest2, :ensure => :link, :backup => "mybucket"
82
- catalog = Puppet::Resource::Catalog.new
150
+ file = described_class.new :path => link, :target => dest2, :ensure => :link, :backup => "mybucket"
83
151
  catalog.add_resource file
84
152
  catalog.add_resource bucket
85
153
 
@@ -95,25 +163,25 @@ describe Puppet::Type.type(:file) do
95
163
  end
96
164
 
97
165
  it "should backup directories to the local filesystem by copying the whole directory" do
98
- file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => ".bak", :content => "foo", :force => true
99
- catalog = Puppet::Resource::Catalog.new
166
+ file = described_class.new :path => path, :backup => ".bak", :content => "foo", :force => true
100
167
  catalog.add_resource file
101
168
 
102
- Dir.mkdir(file[:path])
103
- otherfile = File.join(file[:path], "foo")
169
+ Dir.mkdir(path)
170
+
171
+ otherfile = File.join(path, "foo")
104
172
  File.open(otherfile, "w") { |f| f.print "yay" }
105
173
 
106
174
  catalog.apply
107
175
 
108
- backup = file[:path] + ".bak"
176
+ backup = "#{path}.bak"
109
177
  FileTest.should be_directory(backup)
178
+
110
179
  File.read(File.join(backup, "foo")).should == "yay"
111
180
  end
112
181
 
113
- it "should backup directories to filebuckets by backing up each file separately", :fails_on_windows => true do
182
+ it "should backup directories to filebuckets by backing up each file separately" do
114
183
  bucket = Puppet::Type.type(:filebucket).new :path => tmpfile("filebucket"), :name => "mybucket"
115
- file = Puppet::Type.type(:file).new :path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo", :force => true
116
- catalog = Puppet::Resource::Catalog.new
184
+ file = described_class.new :path => tmpfile("bucket_backs"), :backup => "mybucket", :content => "foo", :force => true
117
185
  catalog.add_resource file
118
186
  catalog.add_resource bucket
119
187
 
@@ -134,18 +202,17 @@ describe Puppet::Type.type(:file) do
134
202
  end
135
203
 
136
204
  it "should propagate failures encountered when renaming the temporary file" do
137
- file = Puppet::Type.type(:file).new :path => tmpfile("fail_rename"), :content => "foo"
138
- file.stubs(:remove_existing) # because it tries to make a backup
205
+ file = described_class.new :path => path, :content => "foo"
206
+ file.stubs(:perform_backup).returns(true)
139
207
 
140
- catalog = Puppet::Resource::Catalog.new
141
208
  catalog.add_resource file
142
209
 
143
- File.open(file[:path], "w") { |f| f.print "bar" }
210
+ File.open(path, "w") { |f| f.print "bar" }
144
211
 
145
212
  File.expects(:rename).raises ArgumentError
146
213
 
147
- lambda { file.write(:content) }.should raise_error(Puppet::Error)
148
- File.read(file[:path]).should == "bar"
214
+ expect { file.write(:content) }.to raise_error(Puppet::Error, /Could not rename temporary file/)
215
+ File.read(path).should == "bar"
149
216
  end
150
217
  end
151
218
 
@@ -172,45 +239,43 @@ describe Puppet::Type.type(:file) do
172
239
  end
173
240
  end
174
241
 
175
- it "should be able to recurse over a nonexistent file", :fails_on_windows => true do
176
- @path = tmpfile("file_integration_tests")
177
-
178
- @file = Puppet::Type::File.new(
179
- :name => @path,
242
+ it "should be able to recurse over a nonexistent file" do
243
+ @file = described_class.new(
244
+ :name => path,
180
245
  :mode => 0644,
181
246
  :recurse => true,
182
247
  :backup => false
183
248
  )
184
249
 
185
- @catalog = Puppet::Resource::Catalog.new
186
- @catalog.add_resource @file
250
+ catalog.add_resource @file
187
251
 
188
252
  lambda { @file.eval_generate }.should_not raise_error
189
253
  end
190
254
 
191
255
  it "should be able to recursively set properties on existing files" do
192
- @path = tmpfile("file_integration_tests")
256
+ path = tmpfile("file_integration_tests")
193
257
 
194
- build_path(@path)
258
+ build_path(path)
195
259
 
196
- @file = Puppet::Type::File.new(
197
- :name => @path,
260
+ file = described_class.new(
261
+ :name => path,
198
262
  :mode => 0644,
199
263
  :recurse => true,
200
264
  :backup => false
201
265
  )
202
266
 
203
- @catalog = Puppet::Resource::Catalog.new
204
- @catalog.add_resource @file
267
+ catalog.add_resource file
205
268
 
206
- @catalog.apply
269
+ catalog.apply
207
270
 
271
+ @dirs.should_not be_empty
208
272
  @dirs.each do |path|
209
- (File.stat(path).mode & 007777).should == 0755
273
+ (get_mode(path) & 007777).should == 0755
210
274
  end
211
275
 
276
+ @files.should_not be_empty
212
277
  @files.each do |path|
213
- (File.stat(path).mode & 007777).should == 0644
278
+ (get_mode(path) & 007777).should == 0644
214
279
  end
215
280
  end
216
281
 
@@ -221,12 +286,11 @@ describe Puppet::Type.type(:file) do
221
286
 
222
287
  dest = tmpfile("file_link_integration_dest")
223
288
 
224
- @file = Puppet::Type::File.new(:name => dest, :target => source, :recurse => true, :ensure => :link, :backup => false)
289
+ @file = described_class.new(:name => dest, :target => source, :recurse => true, :ensure => :link, :backup => false)
225
290
 
226
- @catalog = Puppet::Resource::Catalog.new
227
- @catalog.add_resource @file
291
+ catalog.add_resource @file
228
292
 
229
- @catalog.apply
293
+ catalog.apply
230
294
 
231
295
  @dirs.each do |path|
232
296
  link_path = path.sub(source, dest)
@@ -241,19 +305,18 @@ describe Puppet::Type.type(:file) do
241
305
  end
242
306
  end
243
307
 
244
- it "should be able to recursively copy files", :fails_on_windows => true do
308
+ it "should be able to recursively copy files" do
245
309
  source = tmpfile("file_source_integration_source")
246
310
 
247
311
  build_path(source)
248
312
 
249
313
  dest = tmpfile("file_source_integration_dest")
250
314
 
251
- @file = Puppet::Type::File.new(:name => dest, :source => source, :recurse => true, :backup => false)
315
+ @file = described_class.new(:name => dest, :source => source, :recurse => true, :backup => false)
252
316
 
253
- @catalog = Puppet::Resource::Catalog.new
254
- @catalog.add_resource @file
317
+ catalog.add_resource @file
255
318
 
256
- @catalog.apply
319
+ catalog.apply
257
320
 
258
321
  @dirs.each do |path|
259
322
  newpath = path.sub(source, dest)
@@ -277,73 +340,260 @@ describe Puppet::Type.type(:file) do
277
340
  FileUtils.mkdir_p(subdir)
278
341
  File.open(file, "w") { |f| f.puts "" }
279
342
 
280
- base = Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => "755")
281
- sub = Puppet::Type::File.new(:name => subdir, :recurse => true, :backup => false, :mode => "644")
343
+ base = described_class.new(:name => dir, :recurse => true, :backup => false, :mode => "755")
344
+ sub = described_class.new(:name => subdir, :recurse => true, :backup => false, :mode => "644")
282
345
 
283
- @catalog = Puppet::Resource::Catalog.new
284
- @catalog.add_resource base
285
- @catalog.add_resource sub
346
+ catalog.add_resource base
347
+ catalog.add_resource sub
286
348
 
287
- @catalog.apply
349
+ catalog.apply
288
350
 
289
- (File.stat(file).mode & 007777).should == 0644
351
+ (get_mode(file) & 007777).should == 0644
290
352
  end
291
353
 
292
354
  it "should recursively manage files even if there is an explicit file whose name is a prefix of the managed file" do
293
- dir = tmpfile("recursion_vs_explicit_2")
355
+ managed = File.join(path, "file")
356
+ generated = File.join(path, "file_with_a_name_starting_with_the_word_file")
357
+ managed_mode = 0700
294
358
 
295
- managed = File.join(dir, "file")
296
- generated = File.join(dir, "file_with_a_name_starting_with_the_word_file")
297
- managed_mode = Puppet.features.microsoft_windows? ? 0444 : 0700
359
+ FileUtils.mkdir_p(path)
360
+ FileUtils.touch(managed)
361
+ FileUtils.touch(generated)
298
362
 
299
- FileUtils.mkdir_p(dir)
300
- File.open(managed, "w") { |f| f.puts "" }
301
- File.open(generated, "w") { |f| f.puts "" }
363
+ catalog.add_resource described_class.new(:name => path, :recurse => true, :backup => false, :mode => managed_mode)
364
+ catalog.add_resource described_class.new(:name => managed, :recurse => true, :backup => false, :mode => "644")
302
365
 
303
- @catalog = Puppet::Resource::Catalog.new
304
- @catalog.add_resource Puppet::Type::File.new(:name => dir, :recurse => true, :backup => false, :mode => managed_mode)
305
- @catalog.add_resource Puppet::Type::File.new(:name => managed, :recurse => true, :backup => false, :mode => "644")
366
+ catalog.apply
306
367
 
307
- @catalog.apply
368
+ (get_mode(generated) & 007777).should == managed_mode
369
+ end
308
370
 
309
- (File.stat(generated).mode & 007777).should == managed_mode
371
+ describe "when recursing remote directories" do
372
+ describe "when sourceselect first" do
373
+ describe "for a directory" do
374
+ it "should recursively copy the first directory that exists" do
375
+ one = File.expand_path('thisdoesnotexist')
376
+ two = tmpdir('two')
377
+
378
+ FileUtils.mkdir_p(File.join(two, 'three'))
379
+ FileUtils.touch(File.join(two, 'three', 'four'))
380
+
381
+ obj = Puppet::Type.newfile(
382
+ :path => path,
383
+ :ensure => :directory,
384
+ :backup => false,
385
+ :recurse => true,
386
+ :sourceselect => :first,
387
+ :source => [one, two]
388
+ )
389
+
390
+ catalog.add_resource obj
391
+ catalog.apply
392
+
393
+ File.should be_directory(path)
394
+ File.should_not be_exist(File.join(path, 'one'))
395
+ File.should be_exist(File.join(path, 'three', 'four'))
396
+ end
397
+
398
+ it "should recursively copy an empty directory" do
399
+ one = File.expand_path('thisdoesnotexist')
400
+ two = tmpdir('two')
401
+ three = tmpdir('three')
402
+
403
+ FileUtils.mkdir_p(two)
404
+ FileUtils.mkdir_p(three)
405
+ FileUtils.touch(File.join(three, 'a'))
406
+
407
+ obj = Puppet::Type.newfile(
408
+ :path => path,
409
+ :ensure => :directory,
410
+ :backup => false,
411
+ :recurse => true,
412
+ :sourceselect => :first,
413
+ :source => [one, two, three]
414
+ )
415
+
416
+ catalog.add_resource obj
417
+ catalog.apply
418
+
419
+ File.should be_directory(path)
420
+ File.should_not be_exist(File.join(path, 'a'))
421
+ end
422
+
423
+ it "should only recurse one level" do
424
+ one = tmpdir('one')
425
+ FileUtils.mkdir_p(File.join(one, 'a', 'b'))
426
+ FileUtils.touch(File.join(one, 'a', 'b', 'c'))
427
+
428
+ two = tmpdir('two')
429
+ FileUtils.mkdir_p(File.join(two, 'z'))
430
+ FileUtils.touch(File.join(two, 'z', 'y'))
431
+
432
+ obj = Puppet::Type.newfile(
433
+ :path => path,
434
+ :ensure => :directory,
435
+ :backup => false,
436
+ :recurse => true,
437
+ :recurselimit => 1,
438
+ :sourceselect => :first,
439
+ :source => [one, two]
440
+ )
441
+
442
+ catalog.add_resource obj
443
+ catalog.apply
444
+
445
+ File.should be_exist(File.join(path, 'a'))
446
+ File.should_not be_exist(File.join(path, 'a', 'b'))
447
+ File.should_not be_exist(File.join(path, 'z'))
448
+ end
449
+ end
450
+
451
+ describe "for a file" do
452
+ it "should copy the first file that exists" do
453
+ one = File.expand_path('thisdoesnotexist')
454
+ two = tmpfile('two')
455
+ File.open(two, "w") { |f| f.print 'yay' }
456
+ three = tmpfile('three')
457
+ File.open(three, "w") { |f| f.print 'no' }
458
+
459
+ obj = Puppet::Type.newfile(
460
+ :path => path,
461
+ :ensure => :file,
462
+ :backup => false,
463
+ :sourceselect => :first,
464
+ :source => [one, two, three]
465
+ )
466
+
467
+ catalog.add_resource obj
468
+ catalog.apply
469
+
470
+ File.read(path).should == 'yay'
471
+ end
472
+
473
+ it "should copy an empty file" do
474
+ one = File.expand_path('thisdoesnotexist')
475
+ two = tmpfile('two')
476
+ FileUtils.touch(two)
477
+ three = tmpfile('three')
478
+ File.open(three, "w") { |f| f.print 'no' }
479
+
480
+ obj = Puppet::Type.newfile(
481
+ :path => path,
482
+ :ensure => :file,
483
+ :backup => false,
484
+ :sourceselect => :first,
485
+ :source => [one, two, three]
486
+ )
487
+
488
+ catalog.add_resource obj
489
+ catalog.apply
490
+
491
+ File.read(path).should == ''
492
+ end
493
+ end
494
+ end
495
+
496
+ describe "when sourceselect all" do
497
+ describe "for a directory" do
498
+ it "should recursively copy all sources from the first valid source" do
499
+ one = tmpdir('one')
500
+ two = tmpdir('two')
501
+ three = tmpdir('three')
502
+ four = tmpdir('four')
503
+
504
+ [one, two, three, four].each {|dir| FileUtils.mkdir_p(dir)}
505
+
506
+ File.open(File.join(one, 'a'), "w") { |f| f.print one }
507
+ File.open(File.join(two, 'a'), "w") { |f| f.print two }
508
+ File.open(File.join(two, 'b'), "w") { |f| f.print two }
509
+ File.open(File.join(three, 'a'), "w") { |f| f.print three }
510
+ File.open(File.join(three, 'c'), "w") { |f| f.print three }
511
+
512
+ obj = Puppet::Type.newfile(
513
+ :path => path,
514
+ :ensure => :directory,
515
+ :backup => false,
516
+ :recurse => true,
517
+ :sourceselect => :all,
518
+ :source => [one, two, three, four]
519
+ )
520
+
521
+ catalog.add_resource obj
522
+ catalog.apply
523
+
524
+ File.read(File.join(path, 'a')).should == one
525
+ File.read(File.join(path, 'b')).should == two
526
+ File.read(File.join(path, 'c')).should == three
527
+ end
528
+
529
+ it "should only recurse one level from each valid source" do
530
+ one = tmpdir('one')
531
+ FileUtils.mkdir_p(File.join(one, 'a', 'b'))
532
+ FileUtils.touch(File.join(one, 'a', 'b', 'c'))
533
+
534
+ two = tmpdir('two')
535
+ FileUtils.mkdir_p(File.join(two, 'z'))
536
+ FileUtils.touch(File.join(two, 'z', 'y'))
537
+
538
+ obj = Puppet::Type.newfile(
539
+ :path => path,
540
+ :ensure => :directory,
541
+ :backup => false,
542
+ :recurse => true,
543
+ :recurselimit => 1,
544
+ :sourceselect => :all,
545
+ :source => [one, two]
546
+ )
547
+
548
+ catalog.add_resource obj
549
+ catalog.apply
550
+
551
+ File.should be_exist(File.join(path, 'a'))
552
+ File.should_not be_exist(File.join(path, 'a', 'b'))
553
+ File.should be_exist(File.join(path, 'z'))
554
+ File.should_not be_exist(File.join(path, 'z', 'y'))
555
+ end
556
+ end
557
+ end
310
558
  end
311
559
  end
312
560
 
313
- describe "when generating resources", :fails_on_windows => true do
561
+ describe "when generating resources" do
314
562
  before do
315
- @source = tmpfile("generating_in_catalog_source")
316
-
317
- @dest = tmpfile("generating_in_catalog_dest")
563
+ source = tmpfile("generating_in_catalog_source")
318
564
 
319
- Dir.mkdir(@source)
565
+ Dir.mkdir(source)
320
566
 
321
- s1 = File.join(@source, "one")
322
- s2 = File.join(@source, "two")
567
+ s1 = File.join(source, "one")
568
+ s2 = File.join(source, "two")
323
569
 
324
570
  File.open(s1, "w") { |f| f.puts "uno" }
325
571
  File.open(s2, "w") { |f| f.puts "dos" }
326
572
 
327
- @file = Puppet::Type::File.new(:name => @dest, :source => @source, :recurse => true, :backup => false)
573
+ @file = described_class.new(
574
+ :name => path,
575
+ :source => source,
576
+ :recurse => true,
577
+ :backup => false
578
+ )
328
579
 
329
- @catalog = Puppet::Resource::Catalog.new
330
- @catalog.add_resource @file
580
+ catalog.add_resource @file
331
581
  end
332
582
 
333
583
  it "should add each generated resource to the catalog" do
334
- @catalog.apply do |trans|
335
- @catalog.resource(:file, File.join(@dest, "one")).should be_instance_of(@file.class)
336
- @catalog.resource(:file, File.join(@dest, "two")).should be_instance_of(@file.class)
584
+ catalog.apply do |trans|
585
+ catalog.resource(:file, File.join(path, "one")).should be_a(described_class)
586
+ catalog.resource(:file, File.join(path, "two")).should be_a(described_class)
337
587
  end
338
588
  end
339
589
 
340
590
  it "should have an edge to each resource in the relationship graph" do
341
- @catalog.apply do |trans|
342
- one = @catalog.resource(:file, File.join(@dest, "one"))
343
- @catalog.relationship_graph.edge?(@file, one).should be
591
+ catalog.apply do |trans|
592
+ one = catalog.resource(:file, File.join(path, "one"))
593
+ catalog.relationship_graph.should be_edge(@file, one)
344
594
 
345
- two = @catalog.resource(:file, File.join(@dest, "two"))
346
- @catalog.relationship_graph.edge?(@file, two).should be
595
+ two = catalog.resource(:file, File.join(path, "two"))
596
+ catalog.relationship_graph.should be_edge(@file, two)
347
597
  end
348
598
  end
349
599
  end
@@ -357,9 +607,8 @@ describe Puppet::Type.type(:file) do
357
607
 
358
608
  File.open(source, "w") { |f| f.print "foo" }
359
609
 
360
- file = Puppet::Type::File.new(:name => dest, :source => source)
610
+ file = described_class.new(:name => dest, :source => source)
361
611
 
362
- catalog = Puppet::Resource::Catalog.new
363
612
  catalog.add_resource file
364
613
 
365
614
  catalog.apply
@@ -375,9 +624,8 @@ describe Puppet::Type.type(:file) do
375
624
  File.open(source, "w") { |f| f.print "foo" }
376
625
  File.chmod(0755, source)
377
626
 
378
- file = Puppet::Type::File.new(:path => dest, :source => source)
627
+ file = described_class.new(:path => dest, :source => source)
379
628
 
380
- catalog = Puppet::Resource::Catalog.new
381
629
  catalog.add_resource file
382
630
 
383
631
  catalog.apply
@@ -393,9 +641,8 @@ describe Puppet::Type.type(:file) do
393
641
 
394
642
  File.open(source, "w") { |f| f.print "foo" }
395
643
 
396
- file = Puppet::Type::File.new(:name => dest, :source => source, :recurse => true)
644
+ file = described_class.new(:name => dest, :source => source, :recurse => true)
397
645
 
398
- catalog = Puppet::Resource::Catalog.new
399
646
  catalog.add_resource file
400
647
  catalog.apply
401
648
 
@@ -403,108 +650,98 @@ describe Puppet::Type.type(:file) do
403
650
  end
404
651
  end
405
652
 
406
- it "should be able to create files when 'content' is specified but 'ensure' is not" do
407
- dest = tmpfile("files_with_content")
408
-
409
-
410
- file = Puppet::Type.type(:file).new(
411
- :name => dest,
653
+ it "should create a file with content if ensure is omitted" do
654
+ file = described_class.new(
655
+ :path => path,
412
656
  :content => "this is some content, yo"
413
657
  )
414
658
 
415
- catalog = Puppet::Resource::Catalog.new
416
659
  catalog.add_resource file
417
660
  catalog.apply
418
661
 
419
- File.read(dest).should == "this is some content, yo"
662
+ File.read(path).should == "this is some content, yo"
420
663
  end
421
664
 
422
- it "should create files with content if both 'content' and 'ensure' are set" do
423
- dest = tmpfile("files_with_content")
424
-
425
-
426
- file = Puppet::Type.type(:file).new(
427
- :name => dest,
665
+ it "should create files with content if both content and ensure are set" do
666
+ file = described_class.new(
667
+ :path => path,
428
668
  :ensure => "file",
429
669
  :content => "this is some content, yo"
430
670
  )
431
671
 
432
- catalog = Puppet::Resource::Catalog.new
433
672
  catalog.add_resource file
434
673
  catalog.apply
435
674
 
436
- File.read(dest).should == "this is some content, yo"
675
+ File.read(path).should == "this is some content, yo"
437
676
  end
438
677
 
439
678
  it "should delete files with sources but that are set for deletion" do
440
- dest = tmpfile("dest_source_with_ensure")
441
679
  source = tmpfile("source_source_with_ensure")
680
+
442
681
  File.open(source, "w") { |f| f.puts "yay" }
443
- File.open(dest, "w") { |f| f.puts "boo" }
682
+ File.open(path, "w") { |f| f.puts "boo" }
444
683
 
445
684
 
446
- file = Puppet::Type.type(:file).new(
447
- :name => make_absolute(dest),
685
+ file = described_class.new(
686
+ :path => path,
448
687
  :ensure => :absent,
449
688
  :source => source,
450
689
  :backup => false
451
690
  )
452
691
 
453
- catalog = Puppet::Resource::Catalog.new
454
692
  catalog.add_resource file
455
693
  catalog.apply
456
694
 
457
- File.should_not be_exist(dest)
695
+ File.should_not be_exist(path)
458
696
  end
459
697
 
460
698
  describe "when purging files" do
461
699
  before do
462
- @sourcedir = tmpfile("purge_source")
463
- @destdir = tmpfile("purge_dest")
464
- Dir.mkdir(@sourcedir)
465
- Dir.mkdir(@destdir)
466
- @sourcefile = File.join(@sourcedir, "sourcefile")
467
- @copiedfile = File.join(@destdir, "sourcefile")
468
- @localfile = File.join(@destdir, "localfile")
469
- @purgee = File.join(@destdir, "to_be_purged")
470
- File.open(@localfile, "w") { |f| f.puts "rahtest" }
471
- File.open(@sourcefile, "w") { |f| f.puts "funtest" }
700
+ sourcedir = tmpfile("purge_source")
701
+ destdir = tmpfile("purge_dest")
702
+ Dir.mkdir(sourcedir)
703
+ Dir.mkdir(destdir)
704
+ sourcefile = File.join(sourcedir, "sourcefile")
705
+
706
+ @copiedfile = File.join(destdir, "sourcefile")
707
+ @localfile = File.join(destdir, "localfile")
708
+ @purgee = File.join(destdir, "to_be_purged")
709
+
710
+ File.open(@localfile, "w") { |f| f.print "oldtest" }
711
+ File.open(sourcefile, "w") { |f| f.print "funtest" }
472
712
  # this file should get removed
473
- File.open(@purgee, "w") { |f| f.puts "footest" }
713
+ File.open(@purgee, "w") { |f| f.print "footest" }
474
714
 
475
- @lfobj = Puppet::Type.newfile(
715
+ lfobj = Puppet::Type.newfile(
476
716
  :title => "localfile",
477
717
  :path => @localfile,
478
- :content => "rahtest\n",
718
+ :content => "rahtest",
479
719
  :ensure => :file,
480
720
  :backup => false
481
721
  )
482
722
 
483
- @destobj = Puppet::Type.newfile(
723
+ destobj = Puppet::Type.newfile(
484
724
  :title => "destdir",
485
- :path => @destdir,
486
- :source => @sourcedir,
725
+ :path => destdir,
726
+ :source => sourcedir,
487
727
  :backup => false,
488
728
  :purge => true,
489
729
  :recurse => true
490
730
  )
491
731
 
492
- @catalog = Puppet::Resource::Catalog.new
493
- @catalog.add_resource @lfobj, @destobj
732
+ catalog.add_resource lfobj, destobj
733
+ catalog.apply
494
734
  end
495
735
 
496
736
  it "should still copy remote files" do
497
- @catalog.apply
498
- FileTest.should be_exist(@copiedfile)
737
+ File.read(@copiedfile).should == 'funtest'
499
738
  end
500
739
 
501
740
  it "should not purge managed, local files" do
502
- @catalog.apply
503
- FileTest.should be_exist(@localfile)
741
+ File.read(@localfile).should == 'rahtest'
504
742
  end
505
743
 
506
744
  it "should purge files that are neither remote nor otherwise managed" do
507
- @catalog.apply
508
745
  FileTest.should_not be_exist(@purgee)
509
746
  end
510
747
  end