puppet 2.6.8 → 2.6.9

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 (60) hide show
  1. data/CHANGELOG +41 -0
  2. data/{README.rst → README.md} +17 -10
  3. data/conf/redhat/puppet.spec +93 -22
  4. data/ext/vim/README +2 -1
  5. data/ext/vim/ftplugin/puppet.vim +94 -0
  6. data/ext/vim/indent/puppet.vim +76 -0
  7. data/lib/puppet.rb +2 -3
  8. data/lib/puppet/application/agent.rb +3 -3
  9. data/lib/puppet/application/apply.rb +16 -5
  10. data/lib/puppet/configurer.rb +60 -56
  11. data/lib/puppet/configurer/fact_handler.rb +6 -1
  12. data/lib/puppet/defaults.rb +19 -0
  13. data/lib/puppet/file_serving/fileset.rb +1 -1
  14. data/lib/puppet/indirector/exec.rb +3 -3
  15. data/lib/puppet/indirector/queue.rb +1 -1
  16. data/lib/puppet/metatype/manager.rb +7 -20
  17. data/lib/puppet/parser/compiler.rb +17 -16
  18. data/lib/puppet/parser/resource.rb +18 -1
  19. data/lib/puppet/parser/scope.rb +2 -2
  20. data/lib/puppet/provider/mount/parsed.rb +1 -1
  21. data/lib/puppet/provider/naginator.rb +9 -1
  22. data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
  23. data/lib/puppet/provider/package/aptitude.rb +1 -0
  24. data/lib/puppet/rails/host.rb +7 -0
  25. data/lib/puppet/resource/catalog.rb +9 -3
  26. data/lib/puppet/transaction.rb +15 -26
  27. data/lib/puppet/transaction/report.rb +3 -3
  28. data/lib/puppet/type.rb +13 -24
  29. data/lib/puppet/util/queue.rb +1 -1
  30. data/lib/puppet/util/queue/stomp.rb +2 -2
  31. data/lib/puppet/util/settings/file_setting.rb +1 -0
  32. data/spec/integration/defaults_spec.rb +22 -0
  33. data/spec/integration/indirector/catalog/queue_spec.rb +2 -2
  34. data/spec/integration/type_spec.rb +11 -0
  35. data/spec/unit/application/agent_spec.rb +2 -2
  36. data/spec/unit/application/apply_spec.rb +62 -50
  37. data/spec/unit/configurer/fact_handler_spec.rb +43 -37
  38. data/spec/unit/configurer_spec.rb +404 -327
  39. data/spec/unit/file_serving/fileset_spec.rb +7 -0
  40. data/spec/unit/indirector/exec_spec.rb +4 -4
  41. data/spec/unit/indirector/node/exec_spec.rb +1 -1
  42. data/spec/unit/indirector/queue_spec.rb +4 -4
  43. data/spec/unit/node_spec.rb +1 -0
  44. data/spec/unit/parser/compiler_spec.rb +8 -46
  45. data/spec/unit/parser/resource_spec.rb +61 -3
  46. data/spec/unit/parser/scope_spec.rb +9 -3
  47. data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
  48. data/spec/unit/rails/host_spec.rb +8 -0
  49. data/spec/unit/resource/catalog_spec.rb +1 -1
  50. data/spec/unit/transaction/report_spec.rb +3 -3
  51. data/spec/unit/transaction_spec.rb +8 -2
  52. data/spec/unit/type_spec.rb +66 -0
  53. data/spec/unit/util/queue/stomp_spec.rb +10 -10
  54. data/spec/unit/util/settings/file_setting_spec.rb +4 -0
  55. metadata +1229 -1232
  56. data/README +0 -31
  57. data/lib/puppet/provider/nameservice/#directoryservice.rb# +0 -519
  58. data/lib/puppet/reference/#providers.rb# +0 -123
  59. data/spec/unit/indirector/certificate_status/#file_spec.rb# +0 -188
  60. data/spec/unit/resource/#type_collection_spec.rb# +0 -463
@@ -13,14 +13,6 @@ describe Puppet::Configurer::FactHandler do
13
13
  @facthandler = FactHandlerTester.new
14
14
  end
15
15
 
16
- it "should have a method for downloading fact plugins" do
17
- @facthandler.should respond_to(:download_fact_plugins)
18
- end
19
-
20
- it "should have a boolean method for determining whether fact plugins should be downloaded" do
21
- @facthandler.should respond_to(:download_fact_plugins?)
22
- end
23
-
24
16
  it "should download fact plugins when :factsync is true" do
25
17
  Puppet.settings.expects(:value).with(:factsync).returns true
26
18
  @facthandler.should be_download_fact_plugins
@@ -52,46 +44,60 @@ describe Puppet::Configurer::FactHandler do
52
44
  @facthandler.download_fact_plugins
53
45
  end
54
46
 
55
- it "should warn about factsync deprecation when factsync is enabled" do
56
- Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil)
47
+ describe "when finding facts" do
48
+ before :each do
49
+ @facthandler.stubs(:reload_facter)
50
+ Puppet::Node::Facts.terminus_class = :memory
51
+ end
57
52
 
58
- @facthandler.expects(:download_fact_plugins?).returns true
59
- Puppet.expects(:warning)
60
- @facthandler.download_fact_plugins
61
- end
53
+ it "should use the node name value to retrieve the facts" do
54
+ foo_facts = Puppet::Node::Facts.new('foo')
55
+ bar_facts = Puppet::Node::Facts.new('bar')
56
+ foo_facts.save
57
+ bar_facts.save
58
+ Puppet[:certname] = 'foo'
59
+ Puppet[:node_name_value] = 'bar'
62
60
 
63
- it "should have a method for retrieving facts" do
64
- @facthandler.should respond_to(:find_facts)
65
- end
61
+ @facthandler.find_facts.should == bar_facts
62
+ end
66
63
 
67
- it "should use the Facts class with the :certname to find the facts" do
68
- Puppet.settings.expects(:value).with(:certname).returns "foo"
69
- Puppet::Node::Facts.expects(:find).with("foo").returns "myfacts"
70
- @facthandler.stubs(:reload_facter)
71
- @facthandler.find_facts.should == "myfacts"
72
- end
64
+ it "should set the facts name based on the node_name_fact" do
65
+ Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name').save
66
+ Puppet[:node_name_fact] = 'my_name_fact'
73
67
 
74
- it "should reload Facter and find local facts when asked to find facts" do
75
- @facthandler.expects(:reload_facter)
68
+ @facthandler.find_facts.name.should == 'other_node_name'
69
+ end
76
70
 
77
- Puppet.settings.expects(:value).with(:certname).returns "myhost"
78
- Puppet::Node::Facts.expects(:find).with("myhost")
71
+ it "should set the node_name_value based on the node_name_fact" do
72
+ Puppet::Node::Facts.new(Puppet[:node_name_value], 'my_name_fact' => 'other_node_name').save
73
+ Puppet[:node_name_fact] = 'my_name_fact'
79
74
 
80
- @facthandler.find_facts
81
- end
75
+ @facthandler.find_facts
82
76
 
83
- it "should fail if finding facts fails" do
84
- @facthandler.stubs(:reload_facter)
77
+ Puppet[:node_name_value].should == 'other_node_name'
78
+ end
85
79
 
86
- Puppet.settings.stubs(:value).with(:trace).returns false
87
- Puppet.settings.stubs(:value).with(:certname).returns "myhost"
88
- Puppet::Node::Facts.expects(:find).raises RuntimeError
80
+ it "should reload Facter before finding facts" do
81
+ @facthandler.expects(:reload_facter)
89
82
 
90
- lambda { @facthandler.find_facts }.should raise_error(Puppet::Error)
83
+ @facthandler.find_facts
84
+ end
85
+
86
+ it "should fail if finding facts fails" do
87
+ Puppet[:trace] = false
88
+ Puppet[:certname] = "myhost"
89
+ Puppet::Node::Facts.expects(:find).raises RuntimeError
90
+
91
+ lambda { @facthandler.find_facts }.should raise_error(Puppet::Error)
92
+ end
91
93
  end
92
94
 
93
- it "should have a method to prepare the facts for uploading" do
94
- @facthandler.should respond_to(:facts_for_uploading)
95
+ it "should warn about factsync deprecation when factsync is enabled" do
96
+ Puppet::Configurer::Downloader.stubs(:new).returns mock("downloader", :evaluate => nil)
97
+
98
+ @facthandler.expects(:download_fact_plugins?).returns true
99
+ Puppet.expects(:warning)
100
+ @facthandler.download_fact_plugins
95
101
  end
96
102
 
97
103
  # I couldn't get marshal to work for this, only yaml, so we hard-code yaml.
@@ -10,6 +10,7 @@ describe Puppet::Configurer do
10
10
  before do
11
11
  Puppet.settings.stubs(:use).returns(true)
12
12
  @agent = Puppet::Configurer.new
13
+ Puppet::Util::Storage.stubs(:store)
13
14
  end
14
15
 
15
16
  it "should include the Plugin Handler module" do
@@ -35,16 +36,16 @@ describe Puppet::Configurer do
35
36
 
36
37
  it "should execute any pre-run command provided via the 'prerun_command' setting" do
37
38
  Puppet.settings[:prerun_command] = "/my/command"
38
- Puppet::Util.expects(:execute).with { |args| args[0] == "/my/command" }
39
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
39
40
 
40
41
  @agent.execute_prerun_command
41
42
  end
42
43
 
43
44
  it "should fail if the command fails" do
44
45
  Puppet.settings[:prerun_command] = "/my/command"
45
- Puppet::Util.expects(:execute).raises Puppet::ExecutionFailure
46
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
46
47
 
47
- lambda { @agent.execute_prerun_command }.should raise_error(Puppet::Configurer::CommandHookError)
48
+ @agent.execute_prerun_command.should be_false
48
49
  end
49
50
  end
50
51
 
@@ -58,469 +59,545 @@ describe Puppet::Configurer do
58
59
 
59
60
  it "should execute any post-run command provided via the 'postrun_command' setting" do
60
61
  Puppet.settings[:postrun_command] = "/my/command"
61
- Puppet::Util.expects(:execute).with { |args| args[0] == "/my/command" }
62
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
62
63
 
63
64
  @agent.execute_postrun_command
64
65
  end
65
66
 
66
67
  it "should fail if the command fails" do
67
68
  Puppet.settings[:postrun_command] = "/my/command"
68
- Puppet::Util.expects(:execute).raises Puppet::ExecutionFailure
69
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
69
70
 
70
- lambda { @agent.execute_postrun_command }.should raise_error(Puppet::Configurer::CommandHookError)
71
+ @agent.execute_postrun_command.should be_false
71
72
  end
72
73
  end
73
- end
74
74
 
75
- describe Puppet::Configurer, "when executing a catalog run" do
76
- before do
77
- Puppet.settings.stubs(:use).returns(true)
78
- @agent = Puppet::Configurer.new
79
- @agent.stubs(:prepare)
80
- @agent.stubs(:facts_for_uploading).returns({})
81
- @catalog = Puppet::Resource::Catalog.new
82
- @catalog.stubs(:apply)
83
- @agent.stubs(:retrieve_catalog).returns @catalog
84
- @agent.stubs(:save_last_run_summary)
85
-
86
- Puppet::Util::Log.stubs(:newdestination)
87
- Puppet::Util::Log.stubs(:close)
88
- end
75
+ describe "when executing a catalog run" do
76
+ before do
77
+ Puppet.settings.stubs(:use).returns(true)
78
+ @agent.stubs(:prepare)
79
+ Puppet::Node::Facts.terminus_class = :memory
80
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
81
+ @facts.save
82
+
83
+ @catalog = Puppet::Resource::Catalog.new
84
+ @catalog.stubs(:to_ral).returns(@catalog)
85
+ Puppet::Resource::Catalog.terminus_class = :rest
86
+ Puppet::Resource::Catalog.stubs(:find).returns(@catalog)
87
+ @agent.stubs(:send_report)
88
+ @agent.stubs(:save_last_run_summary)
89
+
90
+ Puppet::Util::Log.stubs(:close)
91
+ end
89
92
 
90
- it "should prepare for the run" do
91
- @agent.expects(:prepare)
93
+ it "should prepare for the run" do
94
+ @agent.expects(:prepare)
92
95
 
93
- @agent.run
94
- end
96
+ @agent.run
97
+ end
95
98
 
96
- it "should initialize a transaction report if one is not provided" do
97
- report = Puppet::Transaction::Report.new("apply")
98
- Puppet::Transaction::Report.expects(:new).returns report
99
+ it "should initialize a transaction report if one is not provided" do
100
+ report = Puppet::Transaction::Report.new("apply")
101
+ Puppet::Transaction::Report.expects(:new).returns report
99
102
 
100
- @agent.run
101
- end
103
+ @agent.run
104
+ end
102
105
 
103
- it "should pass the new report to the catalog" do
104
- report = Puppet::Transaction::Report.new("apply")
105
- Puppet::Transaction::Report.stubs(:new).returns report
106
- @catalog.expects(:apply).with{|options| options[:report] == report}
106
+ it "should respect node_name_fact when setting the host on a report" do
107
+ Puppet[:node_name_fact] = 'my_name_fact'
108
+ @facts.values = {'my_name_fact' => 'node_name_from_fact'}
107
109
 
108
- @agent.run
109
- end
110
+ @agent.run.host.should == 'node_name_from_fact'
111
+ end
110
112
 
111
- it "should use the provided report if it was passed one" do
112
- report = Puppet::Transaction::Report.new("apply")
113
- Puppet::Transaction::Report.expects(:new).never
114
- @catalog.expects(:apply).with{|options| options[:report] == report}
113
+ it "should pass the new report to the catalog" do
114
+ report = Puppet::Transaction::Report.new("apply")
115
+ Puppet::Transaction::Report.stubs(:new).returns report
116
+ @catalog.expects(:apply).with{|options| options[:report] == report}
115
117
 
116
- @agent.run(:report => report)
117
- end
118
+ @agent.run
119
+ end
118
120
 
119
- it "should set the report as a log destination" do
120
- report = Puppet::Transaction::Report.new("apply")
121
- Puppet::Transaction::Report.expects(:new).returns report
121
+ it "should use the provided report if it was passed one" do
122
+ report = Puppet::Transaction::Report.new("apply")
123
+ Puppet::Transaction::Report.expects(:new).never
124
+ @catalog.expects(:apply).with{|options| options[:report] == report}
122
125
 
123
- Puppet::Util::Log.expects(:newdestination).with(report)
126
+ @agent.run(:report => report)
127
+ end
124
128
 
125
- @agent.run
126
- end
129
+ it "should set the report as a log destination" do
130
+ report = Puppet::Transaction::Report.new("apply")
131
+ Puppet::Transaction::Report.expects(:new).returns report
127
132
 
128
- it "should retrieve the catalog" do
129
- @agent.expects(:retrieve_catalog)
133
+ Puppet::Util::Log.expects(:newdestination).with(report)
134
+ Puppet::Util::Log.expects(:close).with(report)
135
+ Puppet::Util::Log.expects(:close).with([])
130
136
 
131
- @agent.run
132
- end
137
+ @agent.run
138
+ end
133
139
 
134
- it "should log a failure and do nothing if no catalog can be retrieved" do
135
- @agent.expects(:retrieve_catalog).returns nil
140
+ it "should retrieve the catalog" do
141
+ @agent.expects(:retrieve_catalog)
136
142
 
137
- Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
143
+ @agent.run
144
+ end
138
145
 
139
- @agent.run
140
- end
146
+ it "should log a failure and do nothing if no catalog can be retrieved" do
147
+ @agent.expects(:retrieve_catalog).returns nil
141
148
 
142
- it "should apply the catalog with all options to :run" do
143
- @agent.expects(:retrieve_catalog).returns @catalog
149
+ Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
144
150
 
145
- @catalog.expects(:apply).with { |args| args[:one] == true }
146
- @agent.run :one => true
147
- end
151
+ @agent.run
152
+ end
148
153
 
149
- it "should accept a catalog and use it instead of retrieving a different one" do
150
- @agent.expects(:retrieve_catalog).never
154
+ it "should apply the catalog with all options to :run" do
155
+ @agent.expects(:retrieve_catalog).returns @catalog
151
156
 
152
- @catalog.expects(:apply)
153
- @agent.run :one => true, :catalog => @catalog
154
- end
157
+ @catalog.expects(:apply).with { |args| args[:one] == true }
158
+ @agent.run :one => true
159
+ end
155
160
 
156
- it "should benchmark how long it takes to apply the catalog" do
157
- @agent.expects(:benchmark).with(:notice, "Finished catalog run")
161
+ it "should accept a catalog and use it instead of retrieving a different one" do
162
+ @agent.expects(:retrieve_catalog).never
158
163
 
159
- @agent.expects(:retrieve_catalog).returns @catalog
164
+ @catalog.expects(:apply)
165
+ @agent.run :one => true, :catalog => @catalog
166
+ end
160
167
 
161
- @catalog.expects(:apply).never # because we're not yielding
162
- @agent.run
163
- end
168
+ it "should benchmark how long it takes to apply the catalog" do
169
+ @agent.expects(:benchmark).with(:notice, "Finished catalog run")
164
170
 
165
- it "should execute post-run hooks after the run" do
166
- @agent.expects(:execute_postrun_command)
171
+ @agent.expects(:retrieve_catalog).returns @catalog
167
172
 
168
- @agent.run
169
- end
173
+ @catalog.expects(:apply).never # because we're not yielding
174
+ @agent.run
175
+ end
170
176
 
171
- it "should send the report" do
172
- report = Puppet::Transaction::Report.new("apply")
173
- Puppet::Transaction::Report.expects(:new).returns(report)
174
- @agent.expects(:send_report).with { |r, trans| r == report }
177
+ it "should execute post-run hooks after the run" do
178
+ @agent.expects(:execute_postrun_command)
175
179
 
176
- @agent.run
177
- end
180
+ @agent.run
181
+ end
178
182
 
179
- it "should send the transaction report with a reference to the transaction if a run was actually made" do
180
- report = Puppet::Transaction::Report.new("apply")
181
- Puppet::Transaction::Report.expects(:new).returns(report)
183
+ it "should send the report" do
184
+ report = Puppet::Transaction::Report.new("apply")
185
+ Puppet::Transaction::Report.expects(:new).returns(report)
186
+ @agent.expects(:send_report).with(report)
182
187
 
183
- trans = stub 'transaction'
184
- @catalog.expects(:apply).returns trans
188
+ @agent.run
189
+ end
185
190
 
186
- @agent.expects(:send_report).with { |r, t| t == trans }
191
+ it "should send the transaction report even if the catalog could not be retrieved" do
192
+ @agent.expects(:retrieve_catalog).returns nil
187
193
 
188
- @agent.run :catalog => @catalog
189
- end
194
+ report = Puppet::Transaction::Report.new("apply")
195
+ Puppet::Transaction::Report.expects(:new).returns(report)
196
+ @agent.expects(:send_report)
190
197
 
191
- it "should send the transaction report even if the catalog could not be retrieved" do
192
- @agent.expects(:retrieve_catalog).returns nil
198
+ @agent.run
199
+ end
193
200
 
194
- report = Puppet::Transaction::Report.new("apply")
195
- Puppet::Transaction::Report.expects(:new).returns(report)
196
- @agent.expects(:send_report)
201
+ it "should send the transaction report even if there is a failure" do
202
+ @agent.expects(:retrieve_catalog).raises "whatever"
197
203
 
198
- @agent.run
199
- end
204
+ report = Puppet::Transaction::Report.new("apply")
205
+ Puppet::Transaction::Report.expects(:new).returns(report)
206
+ @agent.expects(:send_report)
200
207
 
201
- it "should send the transaction report even if there is a failure" do
202
- @agent.expects(:retrieve_catalog).raises "whatever"
208
+ @agent.run.should be_nil
209
+ end
203
210
 
204
- report = Puppet::Transaction::Report.new("apply")
205
- Puppet::Transaction::Report.expects(:new).returns(report)
206
- @agent.expects(:send_report)
211
+ it "should remove the report as a log destination when the run is finished" do
212
+ report = Puppet::Transaction::Report.new("apply")
213
+ Puppet::Transaction::Report.expects(:new).returns(report)
207
214
 
208
- lambda { @agent.run }.should raise_error
209
- end
215
+ Puppet::Util::Log.expects(:close).with(report)
210
216
 
211
- it "should remove the report as a log destination when the run is finished" do
212
- report = Puppet::Transaction::Report.new("apply")
213
- Puppet::Transaction::Report.expects(:new).returns(report)
217
+ @agent.run
218
+ end
214
219
 
215
- Puppet::Util::Log.expects(:close).with(report)
220
+ it "should return the report as the result of the run" do
221
+ report = Puppet::Transaction::Report.new("apply")
222
+ Puppet::Transaction::Report.expects(:new).returns(report)
216
223
 
217
- @agent.run
218
- end
224
+ @agent.run.should equal(report)
225
+ end
219
226
 
220
- it "should return the report as the result of the run" do
221
- report = Puppet::Transaction::Report.new("apply")
222
- Puppet::Transaction::Report.expects(:new).returns(report)
227
+ it "should send the transaction report even if the pre-run command fails" do
228
+ report = Puppet::Transaction::Report.new("apply")
229
+ Puppet::Transaction::Report.expects(:new).returns(report)
223
230
 
224
- @agent.run.should equal(report)
225
- end
226
- end
231
+ Puppet.settings[:prerun_command] = "/my/command"
232
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
233
+ @agent.expects(:send_report)
227
234
 
228
- describe Puppet::Configurer, "when sending a report" do
229
- include PuppetSpec::Files
235
+ @agent.run.should be_nil
236
+ end
230
237
 
231
- before do
232
- Puppet.settings.stubs(:use).returns(true)
233
- @configurer = Puppet::Configurer.new
234
- Puppet[:lastrunfile] = tmpfile('last_run_file')
238
+ it "should include the pre-run command failure in the report" do
239
+ report = Puppet::Transaction::Report.new("apply")
240
+ Puppet::Transaction::Report.expects(:new).returns(report)
235
241
 
236
- @report = Puppet::Transaction::Report.new("apply")
237
- @trans = stub 'transaction'
238
- end
242
+ Puppet.settings[:prerun_command] = "/my/command"
243
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
239
244
 
240
- it "should finalize the report" do
241
- @report.expects(:finalize_report)
242
- @configurer.send_report(@report, @trans)
243
- end
245
+ report.expects(:<<).with { |log| log.message.start_with?("Could not run command from prerun_command") }
244
246
 
245
- it "should print a report summary if configured to do so" do
246
- Puppet.settings[:summarize] = true
247
+ @agent.run.should be_nil
248
+ end
247
249
 
248
- @report.expects(:summary).returns "stuff"
250
+ it "should send the transaction report even if the post-run command fails" do
251
+ report = Puppet::Transaction::Report.new("apply")
252
+ Puppet::Transaction::Report.expects(:new).returns(report)
249
253
 
250
- @configurer.expects(:puts).with("stuff")
251
- @configurer.send_report(@report, nil)
252
- end
254
+ Puppet.settings[:postrun_command] = "/my/command"
255
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
256
+ @agent.expects(:send_report)
253
257
 
254
- it "should not print a report summary if not configured to do so" do
255
- Puppet.settings[:summarize] = false
258
+ @agent.run.should be_nil
259
+ end
256
260
 
257
- @configurer.expects(:puts).never
258
- @configurer.send_report(@report, nil)
259
- end
261
+ it "should include the post-run command failure in the report" do
262
+ report = Puppet::Transaction::Report.new("apply")
263
+ Puppet::Transaction::Report.expects(:new).returns(report)
260
264
 
261
- it "should save the report if reporting is enabled" do
262
- Puppet.settings[:report] = true
265
+ Puppet.settings[:postrun_command] = "/my/command"
266
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
263
267
 
264
- @report.expects(:save)
265
- @configurer.send_report(@report, nil)
266
- end
268
+ report.expects(:<<).with { |log| log.message.start_with?("Could not run command from postrun_command") }
267
269
 
268
- it "should not save the report if reporting is disabled" do
269
- Puppet.settings[:report] = false
270
+ @agent.run.should be_nil
271
+ end
270
272
 
271
- @report.expects(:save).never
272
- @configurer.send_report(@report, nil)
273
- end
273
+ it "should execute post-run command even if the pre-run command fails" do
274
+ Puppet.settings[:prerun_command] = "/my/precommand"
275
+ Puppet.settings[:postrun_command] = "/my/postcommand"
276
+ Puppet::Util.expects(:execute).with(["/my/precommand"]).raises(Puppet::ExecutionFailure, "Failed")
277
+ Puppet::Util.expects(:execute).with(["/my/postcommand"])
274
278
 
275
- it "should save the last run summary if reporting is enabled" do
276
- Puppet.settings[:report] = true
279
+ @agent.run.should be_nil
280
+ end
277
281
 
278
- @configurer.expects(:save_last_run_summary).with(@report)
279
- @configurer.send_report(@report, nil)
280
- end
282
+ it "should finalize the report" do
283
+ report = Puppet::Transaction::Report.new("apply")
284
+ Puppet::Transaction::Report.expects(:new).returns(report)
281
285
 
282
- it "should save the last run summary if reporting is disabled" do
283
- Puppet.settings[:report] = false
286
+ report.expects(:finalize_report)
287
+ @agent.run
288
+ end
284
289
 
285
- @configurer.expects(:save_last_run_summary).with(@report)
286
- @configurer.send_report(@report, nil)
287
- end
290
+ it "should not apply the catalog if the pre-run command fails" do
291
+ report = Puppet::Transaction::Report.new("apply")
292
+ Puppet::Transaction::Report.expects(:new).returns(report)
288
293
 
289
- it "should log but not fail if saving the report fails" do
290
- Puppet.settings[:report] = true
294
+ Puppet.settings[:prerun_command] = "/my/command"
295
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
291
296
 
292
- @report.expects(:save).raises "whatever"
297
+ @catalog.expects(:apply).never()
298
+ @agent.expects(:send_report)
293
299
 
294
- Puppet.expects(:err)
295
- lambda { @configurer.send_report(@report, nil) }.should_not raise_error
296
- end
297
- end
300
+ @agent.run.should be_nil
301
+ end
298
302
 
299
- describe Puppet::Configurer, "when saving the summary report file" do
300
- before do
301
- Puppet.settings.stubs(:use).returns(true)
302
- @configurer = Puppet::Configurer.new
303
+ it "should apply the catalog, send the report, and return nil if the post-run command fails" do
304
+ report = Puppet::Transaction::Report.new("apply")
305
+ Puppet::Transaction::Report.expects(:new).returns(report)
303
306
 
304
- @report = stub 'report'
305
- @trans = stub 'transaction'
306
- @lastrunfd = stub 'lastrunfd'
307
- Puppet::Util::FileLocking.stubs(:writelock).yields(@lastrunfd)
308
- end
307
+ Puppet.settings[:postrun_command] = "/my/command"
308
+ Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
309
309
 
310
- it "should write the raw summary to the lastrunfile setting value" do
311
- Puppet::Util::FileLocking.expects(:writelock).with(Puppet[:lastrunfile], 0660)
312
- @configurer.save_last_run_summary(@report)
313
- end
310
+ @catalog.expects(:apply)
311
+ @agent.expects(:send_report)
314
312
 
315
- it "should write the raw summary as yaml" do
316
- @report.expects(:raw_summary).returns("summary")
317
- @lastrunfd.expects(:print).with(YAML.dump("summary"))
318
- @configurer.save_last_run_summary(@report)
319
- end
313
+ @agent.run.should be_nil
314
+ end
320
315
 
321
- it "should log but not fail if saving the last run summary fails" do
322
- Puppet::Util::FileLocking.expects(:writelock).raises "exception"
323
- Puppet.expects(:err)
324
- lambda { @configurer.save_last_run_summary(@report) }.should_not raise_error
316
+ describe "when not using a REST terminus for catalogs" do
317
+ it "should not pass any facts when retrieving the catalog" do
318
+ Puppet::Resource::Catalog.terminus_class = :compiler
319
+ @agent.expects(:facts_for_uploading).never
320
+ Puppet::Resource::Catalog.expects(:find).with { |name, options|
321
+ options[:facts].nil?
322
+ }.returns @catalog
323
+
324
+ @agent.run
325
+ end
326
+ end
327
+
328
+ describe "when using a REST terminus for catalogs" do
329
+ it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do
330
+ Puppet::Resource::Catalog.terminus_class = :rest
331
+ @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo)
332
+ Puppet::Resource::Catalog.expects(:find).with { |name, options|
333
+ options[:facts] == "myfacts" and options[:facts_format] == :foo
334
+ }.returns @catalog
335
+
336
+ @agent.run
337
+ end
338
+ end
325
339
  end
326
340
 
327
- end
341
+ describe "when sending a report" do
342
+ include PuppetSpec::Files
328
343
 
329
- describe Puppet::Configurer, "when retrieving a catalog" do
330
- before do
331
- Puppet.settings.stubs(:use).returns(true)
332
- @agent = Puppet::Configurer.new
333
- @agent.stubs(:facts_for_uploading).returns({})
344
+ before do
345
+ Puppet.settings.stubs(:use).returns(true)
346
+ @configurer = Puppet::Configurer.new
347
+ Puppet[:lastrunfile] = tmpfile('last_run_file')
334
348
 
335
- @catalog = Puppet::Resource::Catalog.new
349
+ @report = Puppet::Transaction::Report.new("apply")
350
+ end
336
351
 
337
- # this is the default when using a Configurer instance
338
- Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest
352
+ it "should print a report summary if configured to do so" do
353
+ Puppet.settings[:summarize] = true
339
354
 
340
- @agent.stubs(:convert_catalog).returns @catalog
341
- end
355
+ @report.expects(:summary).returns "stuff"
342
356
 
343
- describe "and configured to only retrieve a catalog from the cache" do
344
- before do
345
- Puppet.settings[:use_cached_catalog] = true
357
+ @configurer.expects(:puts).with("stuff")
358
+ @configurer.send_report(@report)
346
359
  end
347
360
 
348
- it "should first look in the cache for a catalog" do
349
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
350
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
361
+ it "should not print a report summary if not configured to do so" do
362
+ Puppet.settings[:summarize] = false
351
363
 
352
- @agent.retrieve_catalog.should == @catalog
364
+ @configurer.expects(:puts).never
365
+ @configurer.send_report(@report)
353
366
  end
354
367
 
355
- it "should compile a new catalog if none is found in the cache" do
356
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
357
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
368
+ it "should save the report if reporting is enabled" do
369
+ Puppet.settings[:report] = true
358
370
 
359
- @agent.retrieve_catalog.should == @catalog
371
+ @report.expects(:save)
372
+ @configurer.send_report(@report)
360
373
  end
361
- end
362
374
 
363
- describe "when not using a REST terminus for catalogs" do
364
- it "should not pass any facts when retrieving the catalog" do
365
- @agent.expects(:facts_for_uploading).never
366
- Puppet::Resource::Catalog.expects(:find).with { |name, options|
367
- options[:facts].nil?
368
- }.returns @catalog
375
+ it "should not save the report if reporting is disabled" do
376
+ Puppet.settings[:report] = false
369
377
 
370
- @agent.retrieve_catalog
378
+ @report.expects(:save).never
379
+ @configurer.send_report(@report)
371
380
  end
372
- end
373
381
 
374
- describe "when using a REST terminus for catalogs" do
375
- it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do
376
- @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo)
377
- Puppet::Resource::Catalog.expects(:find).with { |name, options|
378
- options[:facts] == "myfacts" and options[:facts_format] == :foo
379
- }.returns @catalog
382
+ it "should save the last run summary if reporting is enabled" do
383
+ Puppet.settings[:report] = true
380
384
 
381
- @agent.retrieve_catalog
385
+ @configurer.expects(:save_last_run_summary).with(@report)
386
+ @configurer.send_report(@report)
382
387
  end
383
- end
384
388
 
385
- it "should use the Catalog class to get its catalog" do
386
- Puppet::Resource::Catalog.expects(:find).returns @catalog
389
+ it "should save the last run summary if reporting is disabled" do
390
+ Puppet.settings[:report] = false
387
391
 
388
- @agent.retrieve_catalog
389
- end
392
+ @configurer.expects(:save_last_run_summary).with(@report)
393
+ @configurer.send_report(@report)
394
+ end
390
395
 
391
- it "should use its certname to retrieve the catalog" do
392
- Facter.stubs(:value).returns "eh"
393
- Puppet.settings[:certname] = "myhost.domain.com"
394
- Puppet::Resource::Catalog.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
396
+ it "should log but not fail if saving the report fails" do
397
+ Puppet.settings[:report] = true
395
398
 
396
- @agent.retrieve_catalog
399
+ @report.expects(:save).raises "whatever"
400
+
401
+ Puppet.expects(:err)
402
+ lambda { @configurer.send_report(@report) }.should_not raise_error
403
+ end
397
404
  end
398
405
 
399
- it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
400
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
406
+ describe "when saving the summary report file" do
407
+ before do
408
+ Puppet.settings.stubs(:use).returns(true)
409
+ @configurer = Puppet::Configurer.new
401
410
 
402
- @agent.retrieve_catalog.should == @catalog
403
- end
411
+ @report = stub 'report'
412
+ @trans = stub 'transaction'
413
+ @lastrunfd = stub 'lastrunfd'
414
+ Puppet::Util::FileLocking.stubs(:writelock).yields(@lastrunfd)
415
+ end
404
416
 
405
- it "should log and return the cached catalog when no catalog can be retrieved from the server" do
406
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
407
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
417
+ it "should write the raw summary to the lastrunfile setting value" do
418
+ Puppet::Util::FileLocking.expects(:writelock).with(Puppet[:lastrunfile], 0660)
419
+ @configurer.save_last_run_summary(@report)
420
+ end
408
421
 
409
- Puppet.expects(:notice)
422
+ it "should write the raw summary as yaml" do
423
+ @report.expects(:raw_summary).returns("summary")
424
+ @lastrunfd.expects(:print).with(YAML.dump("summary"))
425
+ @configurer.save_last_run_summary(@report)
426
+ end
427
+
428
+ it "should log but not fail if saving the last run summary fails" do
429
+ Puppet::Util::FileLocking.expects(:writelock).raises "exception"
430
+ Puppet.expects(:err)
431
+ lambda { @configurer.save_last_run_summary(@report) }.should_not raise_error
432
+ end
410
433
 
411
- @agent.retrieve_catalog.should == @catalog
412
434
  end
413
435
 
414
- it "should not look in the cache for a catalog if one is returned from the server" do
415
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
416
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never
436
+ describe "when retrieving a catalog" do
437
+ before do
438
+ Puppet.settings.stubs(:use).returns(true)
439
+ @agent.stubs(:facts_for_uploading).returns({})
417
440
 
418
- @agent.retrieve_catalog.should == @catalog
419
- end
441
+ @catalog = Puppet::Resource::Catalog.new
420
442
 
421
- it "should return the cached catalog when retrieving the remote catalog throws an exception" do
422
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
423
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
443
+ # this is the default when using a Configurer instance
444
+ Puppet::Resource::Catalog.indirection.stubs(:terminus_class).returns :rest
424
445
 
425
- @agent.retrieve_catalog.should == @catalog
426
- end
446
+ @agent.stubs(:convert_catalog).returns @catalog
447
+ end
427
448
 
428
- it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
429
- Puppet.stubs(:[])
430
- Puppet.expects(:[]).with(:usecacheonfailure).returns false
431
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
449
+ describe "and configured to only retrieve a catalog from the cache" do
450
+ before do
451
+ Puppet.settings[:use_cached_catalog] = true
452
+ end
432
453
 
433
- Puppet.expects(:warning)
454
+ it "should first look in the cache for a catalog" do
455
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
456
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
434
457
 
435
- @agent.retrieve_catalog.should be_nil
436
- end
458
+ @agent.retrieve_catalog({}).should == @catalog
459
+ end
437
460
 
438
- it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
439
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
440
- Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
461
+ it "should compile a new catalog if none is found in the cache" do
462
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
463
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
441
464
 
442
- @agent.retrieve_catalog.should be_nil
443
- end
465
+ @agent.retrieve_catalog({}).should == @catalog
466
+ end
467
+ end
444
468
 
445
- it "should convert the catalog before returning" do
446
- Puppet::Resource::Catalog.stubs(:find).returns @catalog
469
+ it "should use the Catalog class to get its catalog" do
470
+ Puppet::Resource::Catalog.expects(:find).returns @catalog
447
471
 
448
- @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
449
- @agent.retrieve_catalog.should == "converted catalog"
450
- end
472
+ @agent.retrieve_catalog({})
473
+ end
451
474
 
452
- it "should return nil if there is an error while retrieving the catalog" do
453
- Puppet::Resource::Catalog.expects(:find).at_least_once.raises "eh"
475
+ it "should use its node_name_value to retrieve the catalog" do
476
+ Facter.stubs(:value).returns "eh"
477
+ Puppet.settings[:node_name_value] = "myhost.domain.com"
478
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
454
479
 
455
- @agent.retrieve_catalog.should be_nil
456
- end
457
- end
480
+ @agent.retrieve_catalog({})
481
+ end
458
482
 
459
- describe Puppet::Configurer, "when converting the catalog" do
460
- before do
461
- Puppet.settings.stubs(:use).returns(true)
462
- @agent = Puppet::Configurer.new
483
+ it "should default to returning a catalog retrieved directly from the server, skipping the cache" do
484
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
463
485
 
464
- @catalog = Puppet::Resource::Catalog.new
465
- @oldcatalog = stub 'old_catalog', :to_ral => @catalog
466
- end
486
+ @agent.retrieve_catalog({}).should == @catalog
487
+ end
467
488
 
468
- it "should convert the catalog to a RAL-formed catalog" do
469
- @oldcatalog.expects(:to_ral).returns @catalog
489
+ it "should log and return the cached catalog when no catalog can be retrieved from the server" do
490
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
491
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
470
492
 
471
- @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog)
472
- end
493
+ Puppet.expects(:notice)
473
494
 
474
- it "should finalize the catalog" do
475
- @catalog.expects(:finalize)
495
+ @agent.retrieve_catalog({}).should == @catalog
496
+ end
476
497
 
477
- @agent.convert_catalog(@oldcatalog, 10)
478
- end
498
+ it "should not look in the cache for a catalog if one is returned from the server" do
499
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
500
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never
479
501
 
480
- it "should record the passed retrieval time with the RAL catalog" do
481
- @catalog.expects(:retrieval_duration=).with 10
502
+ @agent.retrieve_catalog({}).should == @catalog
503
+ end
482
504
 
483
- @agent.convert_catalog(@oldcatalog, 10)
484
- end
505
+ it "should return the cached catalog when retrieving the remote catalog throws an exception" do
506
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
507
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
485
508
 
486
- it "should write the RAL catalog's class file" do
487
- @catalog.expects(:write_class_file)
509
+ @agent.retrieve_catalog({}).should == @catalog
510
+ end
488
511
 
489
- @agent.convert_catalog(@oldcatalog, 10)
490
- end
491
- end
512
+ it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
513
+ Puppet.stubs(:[])
514
+ Puppet.expects(:[]).with(:usecacheonfailure).returns false
515
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
492
516
 
493
- describe Puppet::Configurer, "when preparing for a run" do
494
- before do
495
- Puppet.settings.stubs(:use).returns(true)
496
- @agent = Puppet::Configurer.new
497
- @agent.stubs(:dostorage)
498
- @agent.stubs(:download_fact_plugins)
499
- @agent.stubs(:download_plugins)
500
- @agent.stubs(:execute_prerun_command)
501
- @facts = {"one" => "two", "three" => "four"}
502
- end
517
+ Puppet.expects(:warning)
503
518
 
504
- it "should initialize the metadata store" do
505
- @agent.class.stubs(:facts).returns(@facts)
506
- @agent.expects(:dostorage)
507
- @agent.prepare({})
508
- end
519
+ @agent.retrieve_catalog({}).should be_nil
520
+ end
509
521
 
510
- it "should download fact plugins" do
511
- @agent.expects(:download_fact_plugins)
522
+ it "should return nil if no cached catalog is available and no catalog can be retrieved from the server" do
523
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
524
+ Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
512
525
 
513
- @agent.prepare({})
526
+ @agent.retrieve_catalog({}).should be_nil
527
+ end
528
+
529
+ it "should convert the catalog before returning" do
530
+ Puppet::Resource::Catalog.stubs(:find).returns @catalog
531
+
532
+ @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
533
+ @agent.retrieve_catalog({}).should == "converted catalog"
534
+ end
535
+
536
+ it "should return nil if there is an error while retrieving the catalog" do
537
+ Puppet::Resource::Catalog.expects(:find).at_least_once.raises "eh"
538
+
539
+ @agent.retrieve_catalog({}).should be_nil
540
+ end
514
541
  end
515
542
 
516
- it "should download plugins" do
517
- @agent.expects(:download_plugins)
543
+ describe "when converting the catalog" do
544
+ before do
545
+ Puppet.settings.stubs(:use).returns(true)
546
+
547
+ @catalog = Puppet::Resource::Catalog.new
548
+ @oldcatalog = stub 'old_catalog', :to_ral => @catalog
549
+ end
550
+
551
+ it "should convert the catalog to a RAL-formed catalog" do
552
+ @oldcatalog.expects(:to_ral).returns @catalog
553
+
554
+ @agent.convert_catalog(@oldcatalog, 10).should equal(@catalog)
555
+ end
556
+
557
+ it "should finalize the catalog" do
558
+ @catalog.expects(:finalize)
559
+
560
+ @agent.convert_catalog(@oldcatalog, 10)
561
+ end
518
562
 
519
- @agent.prepare({})
563
+ it "should record the passed retrieval time with the RAL catalog" do
564
+ @catalog.expects(:retrieval_duration=).with 10
565
+
566
+ @agent.convert_catalog(@oldcatalog, 10)
567
+ end
568
+
569
+ it "should write the RAL catalog's class file" do
570
+ @catalog.expects(:write_class_file)
571
+
572
+ @agent.convert_catalog(@oldcatalog, 10)
573
+ end
520
574
  end
521
575
 
522
- it "should perform the pre-run commands" do
523
- @agent.expects(:execute_prerun_command)
524
- @agent.prepare({})
576
+ describe "when preparing for a run" do
577
+ before do
578
+ Puppet.settings.stubs(:use).returns(true)
579
+ @agent.stubs(:dostorage)
580
+ @agent.stubs(:download_fact_plugins)
581
+ @agent.stubs(:download_plugins)
582
+ @facts = {"one" => "two", "three" => "four"}
583
+ end
584
+
585
+ it "should initialize the metadata store" do
586
+ @agent.class.stubs(:facts).returns(@facts)
587
+ @agent.expects(:dostorage)
588
+ @agent.prepare({})
589
+ end
590
+
591
+ it "should download fact plugins" do
592
+ @agent.expects(:download_fact_plugins)
593
+
594
+ @agent.prepare({})
595
+ end
596
+
597
+ it "should download plugins" do
598
+ @agent.expects(:download_plugins)
599
+
600
+ @agent.prepare({})
601
+ end
525
602
  end
526
603
  end