puppet 3.3.0 → 3.3.1.rc1

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 (47) hide show
  1. checksums.yaml +7 -0
  2. data/lib/puppet/configurer.rb +1 -7
  3. data/lib/puppet/defaults.rb +18 -6
  4. data/lib/puppet/file_bucket/file.rb +10 -1
  5. data/lib/puppet/forge/repository.rb +8 -2
  6. data/lib/puppet/graph/simple_graph.rb +1 -1
  7. data/lib/puppet/indirector/request.rb +18 -0
  8. data/lib/puppet/indirector/rest.rb +22 -1
  9. data/lib/puppet/indirector/status/local.rb +3 -1
  10. data/lib/puppet/indirector/yaml.rb +4 -18
  11. data/lib/puppet/network/http.rb +1 -0
  12. data/lib/puppet/network/http/handler.rb +11 -6
  13. data/lib/puppet/parser/yaml_trimmer.rb +1 -3
  14. data/lib/puppet/provider/package/dpkg.rb +2 -1
  15. data/lib/puppet/provider/package/rpm.rb +4 -2
  16. data/lib/puppet/provider/parsedfile.rb +9 -6
  17. data/lib/puppet/resource/status.rb +1 -1
  18. data/lib/puppet/status.rb +8 -0
  19. data/lib/puppet/transaction/additional_resource_generator.rb +1 -1
  20. data/lib/puppet/transaction/event.rb +1 -1
  21. data/lib/puppet/transaction/report.rb +6 -2
  22. data/lib/puppet/util/monkey_patches.rb +0 -52
  23. data/lib/puppet/util/storage.rb +5 -8
  24. data/lib/puppet/util/yaml.rb +23 -0
  25. data/lib/puppet/util/zaml.rb +14 -2
  26. data/lib/puppet/version.rb +1 -1
  27. data/spec/unit/agent_spec.rb +2 -0
  28. data/spec/unit/file_bucket/file_spec.rb +19 -13
  29. data/spec/unit/indirector/certificate/rest_spec.rb +1 -0
  30. data/spec/unit/indirector/report/rest_spec.rb +1 -0
  31. data/spec/unit/indirector/request_spec.rb +9 -0
  32. data/spec/unit/indirector/rest_spec.rb +22 -2
  33. data/spec/unit/indirector/run/local_spec.rb +3 -1
  34. data/spec/unit/indirector/status/local_spec.rb +11 -0
  35. data/spec/unit/indirector/status/rest_spec.rb +1 -1
  36. data/spec/unit/indirector/yaml_spec.rb +16 -40
  37. data/spec/unit/network/http/handler_spec.rb +17 -3
  38. data/spec/unit/pops/adaptable_spec.rb +0 -2
  39. data/spec/unit/provider/package/dpkg_spec.rb +31 -23
  40. data/spec/unit/provider/package/rpm_spec.rb +16 -8
  41. data/spec/unit/provider/parsedfile_spec.rb +86 -47
  42. data/spec/unit/transaction/report_spec.rb +5 -1
  43. data/spec/unit/transaction/resource_harness_spec.rb +1 -1
  44. data/spec/unit/util/monkey_patches_spec.rb +0 -13
  45. data/spec/unit/util/storage_spec.rb +49 -49
  46. data/spec/unit/util/yaml_spec.rb +41 -0
  47. metadata +2746 -2749
@@ -146,7 +146,11 @@ describe Puppet::Network::HTTP::Handler do
146
146
  end
147
147
 
148
148
  describe "when processing a request" do
149
- let(:response) { mock('http response') }
149
+ let(:response) do
150
+ obj = stub "http 200 ok"
151
+ obj.stubs(:[]=).with(Puppet::Network::HTTP::HEADER_PUPPET_VERSION, Puppet.version)
152
+ obj
153
+ end
150
154
 
151
155
  before do
152
156
  handler.stubs(:check_authorization)
@@ -230,13 +234,13 @@ describe Puppet::Network::HTTP::Handler do
230
234
  it "should set the format to text/plain when serializing an exception" do
231
235
  handler.expects(:set_content_type).with(response, "text/plain")
232
236
 
233
- handler.do_exception(response, "A test", 404)
237
+ handler.do_exception(response, Exception.new("A test"), 404)
234
238
  end
235
239
 
236
240
  it "sends an exception string with the given status" do
237
241
  handler.expects(:set_response).with(response, "A test", 404)
238
242
 
239
- handler.do_exception(response, "A test", 404)
243
+ handler.do_exception(response, Exception.new("A test"), 404)
240
244
  end
241
245
 
242
246
  it "sends an exception error with the exception's status" do
@@ -249,6 +253,16 @@ describe Puppet::Network::HTTP::Handler do
249
253
  handler.process(request, response)
250
254
  end
251
255
 
256
+ it "logs an HTTP response exception at info level (most are harmless)" do
257
+ data = Puppet::TestModel.new("not_found", "not found")
258
+ error = Puppet::Network::HTTP::Handler::HTTPNotFoundError.new("Could not find test_model not_found")
259
+
260
+ request = a_request_that_finds(data, :accept_header => "pson")
261
+ Puppet.expects(:info).with(error.message)
262
+
263
+ handler.process(request, response)
264
+ end
265
+
252
266
  it "should raise an error if the request is formatted in an unknown format" do
253
267
  handler.stubs(:content_type_header).returns "unknown format"
254
268
  lambda { handler.request_format(request) }.should raise_error
@@ -92,8 +92,6 @@ describe Puppet::Pops::Adaptable::Adapter do
92
92
  a.value = 10
93
93
  b = Farm::FarmAdapter.get(d)
94
94
  b.value.should == 10
95
- # Test implementation detail
96
- d.instance_variables.include?(:@Farm_FarmAdapter).should == true
97
95
  end
98
96
 
99
97
  it "should be able to clear the adapter" do
@@ -49,7 +49,7 @@ install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi edi
49
49
  end
50
50
 
51
51
  it "should have documentation" do
52
- provider_class.doc.should be_instance_of(String)
52
+ expect(provider_class.doc).to be_instance_of(String)
53
53
  end
54
54
 
55
55
  describe "when listing all instances" do
@@ -66,7 +66,7 @@ install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi edi
66
66
  installed = mock 'bash'
67
67
  provider_class.expects(:new).with(:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :description => "GNU Bourne Again SHell", :provider => :dpkg).returns installed
68
68
 
69
- provider_class.instances.should == [installed]
69
+ expect(provider_class.instances).to eq([installed])
70
70
  end
71
71
 
72
72
  it "should parse multiple dpkg-query multi-line entries in the output" do
@@ -77,7 +77,7 @@ install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi edi
77
77
  vim = mock 'vim'
78
78
  provider_class.expects(:new).with(:ensure => "2:7.3.547-6ubuntu5", :error => "ok", :desired => "install", :name => "vim", :status => "installed", :description => "Vi IMproved - enhanced vi editor", :provider => :dpkg).returns vim
79
79
 
80
- provider_class.instances.should == [bash, vim]
80
+ expect(provider_class.instances).to eq([bash, vim])
81
81
  end
82
82
 
83
83
  it "should warn on and ignore any lines it does not understand" do
@@ -86,7 +86,7 @@ install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi edi
86
86
  Puppet.expects(:warning)
87
87
  provider_class.expects(:new).never
88
88
 
89
- provider_class.instances.should == []
89
+ expect(provider_class.instances).to eq([])
90
90
  end
91
91
 
92
92
  it "should not warn on extra multiline description lines which we are ignoring" do
@@ -105,7 +105,7 @@ install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi edi
105
105
  vim = mock 'vim'
106
106
  provider_class.expects(:new).twice.returns(bash, vim)
107
107
 
108
- provider_class.instances.should == [bash, vim]
108
+ expect(provider_class.instances).to eq([bash, vim])
109
109
  end
110
110
 
111
111
  it "should warn on a broken entry while still parsing a good one" do
@@ -122,7 +122,7 @@ install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi edi
122
122
  saved = mock('saved')
123
123
  provider_class.expects(:new).twice.returns(bash, vim)
124
124
 
125
- provider_class.instances.should == [bash, vim]
125
+ expect(provider_class.instances).to eq([bash, vim])
126
126
  end
127
127
  end
128
128
 
@@ -148,25 +148,25 @@ install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi edi
148
148
  it "should consider the package purged if dpkg-query fails" do
149
149
  Puppet::Util::Execution.expects(:execpipe).with(query_args).raises Puppet::ExecutionFailure.new("eh")
150
150
 
151
- provider.query[:ensure].should == :purged
151
+ expect(provider.query[:ensure]).to eq(:purged)
152
152
  end
153
153
 
154
154
  it "should return a hash of the found package status for an installed package" do
155
155
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields bash_installed_io
156
156
 
157
- provider.query.should == {:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg, :description => "GNU Bourne Again SHell"}
157
+ expect(provider.query).to eq({:ensure => "4.2-5ubuntu3", :error => "ok", :desired => "install", :name => "bash", :status => "installed", :provider => :dpkg, :description => "GNU Bourne Again SHell"})
158
158
  end
159
159
 
160
160
  it "should consider the package absent if the dpkg-query result cannot be interpreted" do
161
161
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields StringIO.new("somebaddata")
162
162
 
163
- provider.query[:ensure].should == :absent
163
+ expect(provider.query[:ensure]).to eq(:absent)
164
164
  end
165
165
 
166
166
  it "should fail if an error is discovered" do
167
167
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields replace_in_bash_output("ok", "error")
168
168
 
169
- lambda { provider.query }.should raise_error(Puppet::Error)
169
+ expect { provider.query }.to raise_error(Puppet::Error)
170
170
  end
171
171
 
172
172
  it "should consider the package purged if it is marked 'not-installed'" do
@@ -174,32 +174,32 @@ install ok installed vim 2:7.3.547-6ubuntu5 :DESC: Vi IMproved - enhanced vi edi
174
174
  not_installed_bash.gsub!(bash_version, "")
175
175
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields StringIO.new(not_installed_bash)
176
176
 
177
- provider.query[:ensure].should == :purged
177
+ expect(provider.query[:ensure]).to eq(:purged)
178
178
  end
179
179
 
180
180
  it "should consider the package absent if it is marked 'config-files'" do
181
181
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields replace_in_bash_output("installed", "config-files")
182
- provider.query[:ensure].should == :absent
182
+ expect(provider.query[:ensure]).to eq(:absent)
183
183
  end
184
184
 
185
185
  it "should consider the package absent if it is marked 'half-installed'" do
186
186
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields replace_in_bash_output("installed", "half-installed")
187
- provider.query[:ensure].should == :absent
187
+ expect(provider.query[:ensure]).to eq(:absent)
188
188
  end
189
189
 
190
190
  it "should consider the package absent if it is marked 'unpacked'" do
191
191
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields replace_in_bash_output("installed", "unpacked")
192
- provider.query[:ensure].should == :absent
192
+ expect(provider.query[:ensure]).to eq(:absent)
193
193
  end
194
194
 
195
195
  it "should consider the package absent if it is marked 'half-configured'" do
196
196
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields replace_in_bash_output("installed", "half-configured")
197
- provider.query[:ensure].should == :absent
197
+ expect(provider.query[:ensure]).to eq(:absent)
198
198
  end
199
199
 
200
200
  it "should consider the package held if its state is 'hold'" do
201
201
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields replace_in_bash_output("install", "hold")
202
- provider.query[:ensure].should == :held
202
+ expect(provider.query[:ensure]).to eq(:held)
203
203
  end
204
204
  end
205
205
 
@@ -233,12 +233,12 @@ desired ok status next-pkg ensure :DESC: next summary
233
233
  Puppet.expects(:warning).times(4)
234
234
 
235
235
  pipe = StringIO.new(broken_description)
236
- provider_class.parse_multi_line(pipe).should == package_hash
236
+ expect(provider_class.parse_multi_line(pipe)).to eq(package_hash)
237
237
 
238
238
  next_package = package_hash.merge(:name => 'next-pkg', :description => 'next summary')
239
239
 
240
240
  hash = provider_class.parse_multi_line(pipe) until hash # warn about bad lines
241
- hash.should == next_package
241
+ expect(hash).to eq(next_package)
242
242
  end
243
243
 
244
244
  def parser_test(dpkg_output_string, gold_hash)
@@ -246,7 +246,7 @@ desired ok status next-pkg ensure :DESC: next summary
246
246
  Puppet::Util::Execution.expects(:execpipe).with(query_args).yields pipe
247
247
  Puppet.expects(:warning).never
248
248
 
249
- provider.query.should == gold_hash
249
+ expect(provider.query).to eq(gold_hash)
250
250
  end
251
251
 
252
252
  it "should parse properly even if delimiter is in version" do
@@ -289,10 +289,18 @@ desired ok status name ensure :DESC: summary text
289
289
  no_description = "desired ok status name ensure :DESC: \n:DESC:"
290
290
  parser_test(no_description, package_hash.merge(:description => ''))
291
291
  end
292
+
293
+ it "parses dpkg reporting that package does not exist without warning about a failed match (#22529)" do
294
+ Puppet.expects(:warning).never
295
+ pipe = StringIO.new("No packages found matching non-existent-package")
296
+ Puppet::Util::Execution.expects(:execpipe).with(query_args).yields(pipe).raises(Puppet::ExecutionFailure.new('no package found'))
297
+
298
+ expect(provider.query).to eq({:ensure=>:purged, :status=>"missing", :name=>"name", :error=>"ok"})
299
+ end
292
300
  end
293
301
 
294
302
  it "should be able to install" do
295
- provider.should respond_to(:install)
303
+ expect(provider).to respond_to(:install)
296
304
  end
297
305
 
298
306
  describe "when installing" do
@@ -303,7 +311,7 @@ desired ok status name ensure :DESC: summary text
303
311
  it "should fail to install if no source is specified in the resource" do
304
312
  resource.expects(:[]).with(:source).returns nil
305
313
 
306
- lambda { provider.install }.should raise_error(ArgumentError)
314
+ expect { provider.install }.to raise_error(ArgumentError)
307
315
  end
308
316
 
309
317
  it "should use 'dpkg -i' to install the package" do
@@ -373,7 +381,7 @@ desired ok status name ensure :DESC: summary text
373
381
  it "should return the version found by dpkg-deb" do
374
382
  resource.expects(:[]).with(:source).returns "myfile"
375
383
  provider.expects(:dpkg_deb).with { |*command| command[-1] == "myfile" }.returns "package\t1.0"
376
- provider.latest.should == "1.0"
384
+ expect(provider.latest).to eq("1.0")
377
385
  end
378
386
 
379
387
  it "should warn if the package file contains a different package" do
@@ -386,7 +394,7 @@ desired ok status name ensure :DESC: summary text
386
394
  resource = stub 'resource', :[] => "package++"
387
395
  provider = provider_class.new(resource)
388
396
  provider.expects(:dpkg_deb).returns "package++\t1.0"
389
- provider.latest.should == "1.0"
397
+ expect(provider.latest).to eq("1.0")
390
398
  end
391
399
  end
392
400
 
@@ -76,7 +76,7 @@ describe provider_class do
76
76
 
77
77
  installed_packages = subject.instances
78
78
 
79
- installed_packages[0].properties.should ==
79
+ expect(installed_packages[0].properties).to eq(
80
80
  {
81
81
  :provider => :rpm,
82
82
  :name => "cracklib-dicts",
@@ -87,7 +87,8 @@ describe provider_class do
87
87
  :ensure => "2.8.9-3.3",
88
88
  :description => "The standard CrackLib dictionaries",
89
89
  }
90
- installed_packages[1].properties.should ==
90
+ )
91
+ expect(installed_packages[1].properties).to eq(
91
92
  {
92
93
  :provider => :rpm,
93
94
  :name => "basesystem",
@@ -98,7 +99,8 @@ describe provider_class do
98
99
  :ensure => "8.0-5.1.1.el5.centos",
99
100
  :description => "The skeleton package which defines a simple Red Hat Enterprise Linux system",
100
101
  }
101
- installed_packages[2].properties.should ==
102
+ )
103
+ expect(installed_packages[2].properties).to eq(
102
104
  {
103
105
  :provider => :rpm,
104
106
  :name => "chkconfig",
@@ -109,7 +111,8 @@ describe provider_class do
109
111
  :ensure => "1.3.30.2-2.el5",
110
112
  :description => "A system tool for maintaining the /etc/rc*.d hierarchy",
111
113
  }
112
- installed_packages.last.properties.should ==
114
+ )
115
+ expect(installed_packages.last.properties).to eq(
113
116
  {
114
117
  :provider => :rpm,
115
118
  :name => "mysummaryless",
@@ -120,6 +123,7 @@ describe provider_class do
120
123
  :ensure => "1.2.3.4-5.el4",
121
124
  :description => "",
122
125
  }
126
+ )
123
127
  end
124
128
  end
125
129
 
@@ -157,7 +161,7 @@ describe provider_class do
157
161
  it "should retrieve version string after querying rpm for version from source file" do
158
162
  resource.expects(:[]).with(:source).returns('source-string')
159
163
  Puppet::Util::Execution.expects(:execfail).with(["/bin/rpm", "-q", "--qf", nevra_format, "-p", "source-string"], Puppet::Error).returns("myresource 0 1.2.3.4 5.el4 noarch :DESC:\n")
160
- provider.latest.should == "1.2.3.4-5.el4"
164
+ expect(provider.latest).to eq("1.2.3.4-5.el4")
161
165
  end
162
166
  end
163
167
 
@@ -201,7 +205,7 @@ describe provider_class do
201
205
  def parser_test(rpm_output_string, gold_hash, number_of_warnings = 0)
202
206
  Puppet.expects(:warning).times(number_of_warnings)
203
207
  Puppet::Util::Execution.expects(:execute).with(["/bin/rpm", "-q", resource_name, "--nosignature", "--nodigest", "--qf", nevra_format], execute_options).returns(rpm_output_string)
204
- provider.query.should == gold_hash
208
+ expect(provider.query).to eq(gold_hash)
205
209
  end
206
210
 
207
211
  let(:resource_name) { 'name' }
@@ -258,6 +262,10 @@ describe provider_class do
258
262
  it "should warn but not fail if line is unparseable" do
259
263
  parser_test('bad data', {}, 1)
260
264
  end
265
+
266
+ it "should not warn and not fail if rpm returns package not found" do
267
+ parser_test('package foo is not installed', {}, 0)
268
+ end
261
269
  end
262
270
 
263
271
  describe ".nodigest" do
@@ -271,7 +279,7 @@ describe provider_class do
271
279
  describe "when current version is #{version}" do
272
280
  it "should return #{expected.inspect}" do
273
281
  subject.stubs(:current_version).returns(version)
274
- subject.nodigest.should == expected
282
+ expect(subject.nodigest).to eq(expected)
275
283
  end
276
284
  end
277
285
  end
@@ -287,7 +295,7 @@ describe provider_class do
287
295
  describe "when current version is #{version}" do
288
296
  it "should return #{expected.inspect}" do
289
297
  subject.stubs(:current_version).returns(version)
290
- subject.nosignature.should == expected
298
+ expect(subject.nosignature).to eq(expected)
291
299
  end
292
300
  end
293
301
  end
@@ -2,8 +2,14 @@
2
2
  require 'spec_helper'
3
3
  require 'puppet_spec/files'
4
4
 
5
+ require 'puppet'
5
6
  require 'puppet/provider/parsedfile'
6
7
 
8
+ Puppet::Type.newtype(:parsedfile_type) do
9
+ newparam(:name)
10
+ newproperty(:target)
11
+ end
12
+
7
13
  # Most of the tests for this are still in test/ral/provider/parsedfile.rb.
8
14
  describe Puppet::Provider::ParsedFile do
9
15
  # The ParsedFile provider class is meant to be used as an abstract base class
@@ -11,64 +17,68 @@ describe Puppet::Provider::ParsedFile do
11
17
  # sharing data between classes we construct an anonymous class that inherits
12
18
  # the ParsedFile provider instead of directly working with the ParsedFile
13
19
  # provider itself.
14
- subject { Puppet::Type.newtype(:parsedfile_type).provide(:parsedfile_provider, :parent => described_class) }
20
+ let(:parsed_type) do
21
+ Puppet::Type.type(:parsedfile_type)
22
+ end
23
+
24
+ let!(:provider) { parsed_type.provide(:parsedfile_provider, :parent => described_class) }
15
25
 
16
26
  describe "when looking up records loaded from disk" do
17
27
  it "should return nil if no records have been loaded" do
18
- subject.record?("foo").should be_nil
28
+ provider.record?("foo").should be_nil
19
29
  end
20
30
  end
21
31
 
22
32
  describe "when generating a list of instances" do
23
33
  it "should return an instance for each record parsed from all of the registered targets" do
24
- subject.expects(:targets).returns %w{/one /two}
25
- subject.stubs(:skip_record?).returns false
34
+ provider.expects(:targets).returns %w{/one /two}
35
+ provider.stubs(:skip_record?).returns false
26
36
  one = [:uno1, :uno2]
27
37
  two = [:dos1, :dos2]
28
- subject.expects(:prefetch_target).with("/one").returns one
29
- subject.expects(:prefetch_target).with("/two").returns two
38
+ provider.expects(:prefetch_target).with("/one").returns one
39
+ provider.expects(:prefetch_target).with("/two").returns two
30
40
 
31
41
  results = []
32
42
  (one + two).each do |inst|
33
43
  results << inst.to_s + "_instance"
34
- subject.expects(:new).with(inst).returns(results[-1])
44
+ provider.expects(:new).with(inst).returns(results[-1])
35
45
  end
36
46
 
37
- subject.instances.should == results
47
+ provider.instances.should == results
38
48
  end
39
49
 
40
50
  it "should ignore target when retrieve fails" do
41
- subject.expects(:targets).returns %w{/one /two /three}
42
- subject.stubs(:skip_record?).returns false
43
- subject.expects(:retrieve).with("/one").returns [
51
+ provider.expects(:targets).returns %w{/one /two /three}
52
+ provider.stubs(:skip_record?).returns false
53
+ provider.expects(:retrieve).with("/one").returns [
44
54
  {:name => 'target1_record1'},
45
55
  {:name => 'target1_record2'}
46
56
  ]
47
- subject.expects(:retrieve).with("/two").raises Puppet::Util::FileType::FileReadError, "some error"
48
- subject.expects(:retrieve).with("/three").returns [
57
+ provider.expects(:retrieve).with("/two").raises Puppet::Util::FileType::FileReadError, "some error"
58
+ provider.expects(:retrieve).with("/three").returns [
49
59
  {:name => 'target3_record1'},
50
60
  {:name => 'target3_record2'}
51
61
  ]
52
62
  Puppet.expects(:err).with('Could not prefetch parsedfile_type provider \'parsedfile_provider\' target \'/two\': some error. Treating as empty')
53
- subject.expects(:new).with(:name => 'target1_record1', :on_disk => true, :target => '/one', :ensure => :present).returns 'r1'
54
- subject.expects(:new).with(:name => 'target1_record2', :on_disk => true, :target => '/one', :ensure => :present).returns 'r2'
55
- subject.expects(:new).with(:name => 'target3_record1', :on_disk => true, :target => '/three', :ensure => :present).returns 'r3'
56
- subject.expects(:new).with(:name => 'target3_record2', :on_disk => true, :target => '/three', :ensure => :present).returns 'r4'
63
+ provider.expects(:new).with(:name => 'target1_record1', :on_disk => true, :target => '/one', :ensure => :present).returns 'r1'
64
+ provider.expects(:new).with(:name => 'target1_record2', :on_disk => true, :target => '/one', :ensure => :present).returns 'r2'
65
+ provider.expects(:new).with(:name => 'target3_record1', :on_disk => true, :target => '/three', :ensure => :present).returns 'r3'
66
+ provider.expects(:new).with(:name => 'target3_record2', :on_disk => true, :target => '/three', :ensure => :present).returns 'r4'
57
67
 
58
- subject.instances.should == %w{r1 r2 r3 r4}
68
+ provider.instances.should == %w{r1 r2 r3 r4}
59
69
  end
60
70
 
61
71
  it "should skip specified records" do
62
- subject.expects(:targets).returns %w{/one}
63
- subject.expects(:skip_record?).with(:uno).returns false
64
- subject.expects(:skip_record?).with(:dos).returns true
72
+ provider.expects(:targets).returns %w{/one}
73
+ provider.expects(:skip_record?).with(:uno).returns false
74
+ provider.expects(:skip_record?).with(:dos).returns true
65
75
  one = [:uno, :dos]
66
- subject.expects(:prefetch_target).returns one
76
+ provider.expects(:prefetch_target).returns one
67
77
 
68
- subject.expects(:new).with(:uno).returns "eh"
69
- subject.expects(:new).with(:dos).never
78
+ provider.expects(:new).with(:uno).returns "eh"
79
+ provider.expects(:new).with(:dos).never
70
80
 
71
- subject.instances
81
+ provider.instances
72
82
  end
73
83
  end
74
84
 
@@ -80,22 +90,22 @@ describe Puppet::Provider::ParsedFile do
80
90
 
81
91
  it "returns a resource if the record name matches the resource name" do
82
92
  record = {:name => :one}
83
- subject.resource_for_record(record, resources).should be first_resource
93
+ provider.resource_for_record(record, resources).should be first_resource
84
94
  end
85
95
 
86
96
  it "doesn't return a resource if the record name doesn't match any resource names" do
87
97
  record = {:name => :three}
88
- subject.resource_for_record(record, resources).should be_nil
98
+ provider.resource_for_record(record, resources).should be_nil
89
99
  end
90
100
  end
91
101
 
92
102
  describe "when flushing a file's records to disk" do
93
103
  before do
94
104
  # This way we start with some @records, like we would in real life.
95
- subject.stubs(:retrieve).returns []
96
- subject.default_target = "/foo/bar"
97
- subject.initvars
98
- subject.prefetch
105
+ provider.stubs(:retrieve).returns []
106
+ provider.default_target = "/foo/bar"
107
+ provider.initvars
108
+ provider.prefetch
99
109
 
100
110
  @filetype = Puppet::Util::FileType.filetype(:flat).new("/my/file")
101
111
  Puppet::Util::FileType.filetype(:flat).stubs(:new).with("/my/file").returns @filetype
@@ -106,7 +116,7 @@ describe Puppet::Provider::ParsedFile do
106
116
  it "should back up the file being written if the filetype can be backed up" do
107
117
  @filetype.expects(:backup)
108
118
 
109
- subject.flush_target("/my/file")
119
+ provider.flush_target("/my/file")
110
120
  end
111
121
 
112
122
  it "should not try to back up the file if the filetype cannot be backed up" do
@@ -115,22 +125,51 @@ describe Puppet::Provider::ParsedFile do
115
125
 
116
126
  @filetype.stubs(:write)
117
127
 
118
- subject.flush_target("/my/file")
128
+ provider.flush_target("/my/file")
119
129
  end
120
130
 
121
131
  it "should not back up the file more than once between calls to 'prefetch'" do
122
132
  @filetype.expects(:backup).once
123
133
 
124
- subject.flush_target("/my/file")
125
- subject.flush_target("/my/file")
134
+ provider.flush_target("/my/file")
135
+ provider.flush_target("/my/file")
126
136
  end
127
137
 
128
138
  it "should back the file up again once the file has been reread" do
129
139
  @filetype.expects(:backup).times(2)
130
140
 
131
- subject.flush_target("/my/file")
132
- subject.prefetch
133
- subject.flush_target("/my/file")
141
+ provider.flush_target("/my/file")
142
+ provider.prefetch
143
+ provider.flush_target("/my/file")
144
+ end
145
+ end
146
+
147
+ describe "when flushing multiple files" do
148
+ describe "and an error is encountered" do
149
+ it "the other file does not fail" do
150
+ provider.stubs(:backup_target)
151
+
152
+ bad_file = 'broken'
153
+ good_file = 'writable'
154
+
155
+ bad_writer = mock 'bad'
156
+ bad_writer.expects(:write).raises(Exception, "Failed to write to bad file")
157
+
158
+ good_writer = mock 'good'
159
+ good_writer.expects(:write).returns(nil)
160
+
161
+ provider.stubs(:target_object).with(bad_file).returns(bad_writer)
162
+ provider.stubs(:target_object).with(good_file).returns(good_writer)
163
+
164
+ bad_resource = parsed_type.new(:name => 'one', :target => bad_file)
165
+ good_resource = parsed_type.new(:name => 'two', :target => good_file)
166
+
167
+ expect {
168
+ bad_resource.flush
169
+ }.to raise_error(Exception, "Failed to write to bad file")
170
+
171
+ good_resource.flush
172
+ end
134
173
  end
135
174
  end
136
175
  end
@@ -141,7 +180,7 @@ describe "A very basic provider based on ParsedFile" do
141
180
  let(:input_text) { File.read(my_fixture('simple.txt')) }
142
181
  let(:target) { tmpfile('parsedfile_spec') }
143
182
 
144
- subject do
183
+ let(:provider) do
145
184
  example_provider_class = Class.new(Puppet::Provider::ParsedFile)
146
185
  example_provider_class.default_target = target
147
186
  # Setup some record rules
@@ -158,31 +197,31 @@ describe "A very basic provider based on ParsedFile" do
158
197
 
159
198
  context "writing file contents back to disk" do
160
199
  it "should not change anything except from adding a header" do
161
- input_records = subject.parse(input_text)
162
- subject.to_file(input_records).
163
- should match subject.header + input_text
200
+ input_records = provider.parse(input_text)
201
+ provider.to_file(input_records).
202
+ should match provider.header + input_text
164
203
  end
165
204
  end
166
205
 
167
206
  context "rewriting a file containing a native header" do
168
207
  let(:regex) { %r/^# HEADER.*third party\.\n/ }
169
- let(:input_records) { subject.parse(input_text) }
208
+ let(:input_records) { provider.parse(input_text) }
170
209
 
171
210
  before :each do
172
- subject.stubs(:native_header_regex).returns(regex)
211
+ provider.stubs(:native_header_regex).returns(regex)
173
212
  end
174
213
 
175
214
  it "should move the native header to the top" do
176
- subject.to_file(input_records).should_not match /\A#{subject.header}/
215
+ provider.to_file(input_records).should_not match /\A#{provider.header}/
177
216
  end
178
217
 
179
218
  context "and dropping native headers found in input" do
180
219
  before :each do
181
- subject.stubs(:drop_native_header).returns(true)
220
+ provider.stubs(:drop_native_header).returns(true)
182
221
  end
183
222
 
184
223
  it "should not include the native header in the output" do
185
- subject.to_file(input_records).should_not match regex
224
+ provider.to_file(input_records).should_not match regex
186
225
  end
187
226
  end
188
227
  end