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.
- data/CHANGELOG +41 -0
- data/{README.rst → README.md} +17 -10
- data/conf/redhat/puppet.spec +93 -22
- data/ext/vim/README +2 -1
- data/ext/vim/ftplugin/puppet.vim +94 -0
- data/ext/vim/indent/puppet.vim +76 -0
- data/lib/puppet.rb +2 -3
- data/lib/puppet/application/agent.rb +3 -3
- data/lib/puppet/application/apply.rb +16 -5
- data/lib/puppet/configurer.rb +60 -56
- data/lib/puppet/configurer/fact_handler.rb +6 -1
- data/lib/puppet/defaults.rb +19 -0
- data/lib/puppet/file_serving/fileset.rb +1 -1
- data/lib/puppet/indirector/exec.rb +3 -3
- data/lib/puppet/indirector/queue.rb +1 -1
- data/lib/puppet/metatype/manager.rb +7 -20
- data/lib/puppet/parser/compiler.rb +17 -16
- data/lib/puppet/parser/resource.rb +18 -1
- data/lib/puppet/parser/scope.rb +2 -2
- data/lib/puppet/provider/mount/parsed.rb +1 -1
- data/lib/puppet/provider/naginator.rb +9 -1
- data/lib/puppet/provider/nameservice/directoryservice.rb +11 -8
- data/lib/puppet/provider/package/aptitude.rb +1 -0
- data/lib/puppet/rails/host.rb +7 -0
- data/lib/puppet/resource/catalog.rb +9 -3
- data/lib/puppet/transaction.rb +15 -26
- data/lib/puppet/transaction/report.rb +3 -3
- data/lib/puppet/type.rb +13 -24
- data/lib/puppet/util/queue.rb +1 -1
- data/lib/puppet/util/queue/stomp.rb +2 -2
- data/lib/puppet/util/settings/file_setting.rb +1 -0
- data/spec/integration/defaults_spec.rb +22 -0
- data/spec/integration/indirector/catalog/queue_spec.rb +2 -2
- data/spec/integration/type_spec.rb +11 -0
- data/spec/unit/application/agent_spec.rb +2 -2
- data/spec/unit/application/apply_spec.rb +62 -50
- data/spec/unit/configurer/fact_handler_spec.rb +43 -37
- data/spec/unit/configurer_spec.rb +404 -327
- data/spec/unit/file_serving/fileset_spec.rb +7 -0
- data/spec/unit/indirector/exec_spec.rb +4 -4
- data/spec/unit/indirector/node/exec_spec.rb +1 -1
- data/spec/unit/indirector/queue_spec.rb +4 -4
- data/spec/unit/node_spec.rb +1 -0
- data/spec/unit/parser/compiler_spec.rb +8 -46
- data/spec/unit/parser/resource_spec.rb +61 -3
- data/spec/unit/parser/scope_spec.rb +9 -3
- data/spec/unit/provider/nameservice/directoryservice_spec.rb +60 -0
- data/spec/unit/rails/host_spec.rb +8 -0
- data/spec/unit/resource/catalog_spec.rb +1 -1
- data/spec/unit/transaction/report_spec.rb +3 -3
- data/spec/unit/transaction_spec.rb +8 -2
- data/spec/unit/type_spec.rb +66 -0
- data/spec/unit/util/queue/stomp_spec.rb +10 -10
- data/spec/unit/util/settings/file_setting_spec.rb +4 -0
- metadata +1229 -1232
- data/README +0 -31
- data/lib/puppet/provider/nameservice/#directoryservice.rb# +0 -519
- data/lib/puppet/reference/#providers.rb# +0 -123
- data/spec/unit/indirector/certificate_status/#file_spec.rb# +0 -188
- 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
|
-
|
56
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
65
|
-
end
|
61
|
+
@facthandler.find_facts.should == bar_facts
|
62
|
+
end
|
66
63
|
|
67
|
-
|
68
|
-
|
69
|
-
|
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
|
-
|
75
|
-
|
68
|
+
@facthandler.find_facts.name.should == 'other_node_name'
|
69
|
+
end
|
76
70
|
|
77
|
-
|
78
|
-
|
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
|
-
|
81
|
-
end
|
75
|
+
@facthandler.find_facts
|
82
76
|
|
83
|
-
|
84
|
-
|
77
|
+
Puppet[:node_name_value].should == 'other_node_name'
|
78
|
+
end
|
85
79
|
|
86
|
-
|
87
|
-
|
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
|
-
|
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
|
94
|
-
|
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
|
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
|
46
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
46
47
|
|
47
|
-
|
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
|
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
|
69
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
69
70
|
|
70
|
-
|
71
|
+
@agent.execute_postrun_command.should be_false
|
71
72
|
end
|
72
73
|
end
|
73
|
-
end
|
74
74
|
|
75
|
-
describe
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
-
|
91
|
-
|
93
|
+
it "should prepare for the run" do
|
94
|
+
@agent.expects(:prepare)
|
92
95
|
|
93
|
-
|
94
|
-
|
96
|
+
@agent.run
|
97
|
+
end
|
95
98
|
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
101
|
-
|
103
|
+
@agent.run
|
104
|
+
end
|
102
105
|
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
109
|
-
|
110
|
+
@agent.run.host.should == 'node_name_from_fact'
|
111
|
+
end
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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
|
-
|
117
|
-
|
118
|
+
@agent.run
|
119
|
+
end
|
118
120
|
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
-
|
126
|
+
@agent.run(:report => report)
|
127
|
+
end
|
124
128
|
|
125
|
-
|
126
|
-
|
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
|
-
|
129
|
-
|
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
|
-
|
132
|
-
|
137
|
+
@agent.run
|
138
|
+
end
|
133
139
|
|
134
|
-
|
135
|
-
|
140
|
+
it "should retrieve the catalog" do
|
141
|
+
@agent.expects(:retrieve_catalog)
|
136
142
|
|
137
|
-
|
143
|
+
@agent.run
|
144
|
+
end
|
138
145
|
|
139
|
-
|
140
|
-
|
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
|
-
|
143
|
-
@agent.expects(:retrieve_catalog).returns @catalog
|
149
|
+
Puppet.expects(:err).with "Could not retrieve catalog; skipping run"
|
144
150
|
|
145
|
-
|
146
|
-
|
147
|
-
end
|
151
|
+
@agent.run
|
152
|
+
end
|
148
153
|
|
149
|
-
|
150
|
-
|
154
|
+
it "should apply the catalog with all options to :run" do
|
155
|
+
@agent.expects(:retrieve_catalog).returns @catalog
|
151
156
|
|
152
|
-
|
153
|
-
|
154
|
-
|
157
|
+
@catalog.expects(:apply).with { |args| args[:one] == true }
|
158
|
+
@agent.run :one => true
|
159
|
+
end
|
155
160
|
|
156
|
-
|
157
|
-
|
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
|
-
|
164
|
+
@catalog.expects(:apply)
|
165
|
+
@agent.run :one => true, :catalog => @catalog
|
166
|
+
end
|
160
167
|
|
161
|
-
|
162
|
-
|
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
|
-
|
166
|
-
@agent.expects(:execute_postrun_command)
|
171
|
+
@agent.expects(:retrieve_catalog).returns @catalog
|
167
172
|
|
168
|
-
|
169
|
-
|
173
|
+
@catalog.expects(:apply).never # because we're not yielding
|
174
|
+
@agent.run
|
175
|
+
end
|
170
176
|
|
171
|
-
|
172
|
-
|
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
|
-
|
177
|
-
|
180
|
+
@agent.run
|
181
|
+
end
|
178
182
|
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
-
|
184
|
-
|
188
|
+
@agent.run
|
189
|
+
end
|
185
190
|
|
186
|
-
|
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
|
-
|
189
|
-
|
194
|
+
report = Puppet::Transaction::Report.new("apply")
|
195
|
+
Puppet::Transaction::Report.expects(:new).returns(report)
|
196
|
+
@agent.expects(:send_report)
|
190
197
|
|
191
|
-
|
192
|
-
|
198
|
+
@agent.run
|
199
|
+
end
|
193
200
|
|
194
|
-
report
|
195
|
-
|
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
|
-
|
199
|
-
|
204
|
+
report = Puppet::Transaction::Report.new("apply")
|
205
|
+
Puppet::Transaction::Report.expects(:new).returns(report)
|
206
|
+
@agent.expects(:send_report)
|
200
207
|
|
201
|
-
|
202
|
-
|
208
|
+
@agent.run.should be_nil
|
209
|
+
end
|
203
210
|
|
204
|
-
report
|
205
|
-
|
206
|
-
|
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
|
-
|
209
|
-
end
|
215
|
+
Puppet::Util::Log.expects(:close).with(report)
|
210
216
|
|
211
|
-
|
212
|
-
|
213
|
-
Puppet::Transaction::Report.expects(:new).returns(report)
|
217
|
+
@agent.run
|
218
|
+
end
|
214
219
|
|
215
|
-
|
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
|
-
|
218
|
-
|
224
|
+
@agent.run.should equal(report)
|
225
|
+
end
|
219
226
|
|
220
|
-
|
221
|
-
|
222
|
-
|
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
|
-
|
225
|
-
|
226
|
-
|
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
|
-
|
229
|
-
|
235
|
+
@agent.run.should be_nil
|
236
|
+
end
|
230
237
|
|
231
|
-
|
232
|
-
|
233
|
-
|
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
|
-
|
237
|
-
|
238
|
-
end
|
242
|
+
Puppet.settings[:prerun_command] = "/my/command"
|
243
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
239
244
|
|
240
|
-
|
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
|
-
|
246
|
-
|
247
|
+
@agent.run.should be_nil
|
248
|
+
end
|
247
249
|
|
248
|
-
|
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
|
-
|
251
|
-
|
252
|
-
|
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
|
-
|
255
|
-
|
258
|
+
@agent.run.should be_nil
|
259
|
+
end
|
256
260
|
|
257
|
-
|
258
|
-
|
259
|
-
|
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
|
-
|
262
|
-
|
265
|
+
Puppet.settings[:postrun_command] = "/my/command"
|
266
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
263
267
|
|
264
|
-
|
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
|
-
|
269
|
-
|
270
|
+
@agent.run.should be_nil
|
271
|
+
end
|
270
272
|
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
276
|
-
|
279
|
+
@agent.run.should be_nil
|
280
|
+
end
|
277
281
|
|
278
|
-
|
279
|
-
|
280
|
-
|
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
|
-
|
283
|
-
|
286
|
+
report.expects(:finalize_report)
|
287
|
+
@agent.run
|
288
|
+
end
|
284
289
|
|
285
|
-
|
286
|
-
|
287
|
-
|
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
|
-
|
290
|
-
|
294
|
+
Puppet.settings[:prerun_command] = "/my/command"
|
295
|
+
Puppet::Util.expects(:execute).with(["/my/command"]).raises(Puppet::ExecutionFailure, "Failed")
|
291
296
|
|
292
|
-
|
297
|
+
@catalog.expects(:apply).never()
|
298
|
+
@agent.expects(:send_report)
|
293
299
|
|
294
|
-
|
295
|
-
|
296
|
-
end
|
297
|
-
end
|
300
|
+
@agent.run.should be_nil
|
301
|
+
end
|
298
302
|
|
299
|
-
|
300
|
-
|
301
|
-
|
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
|
-
|
305
|
-
|
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
|
-
|
311
|
-
|
312
|
-
@configurer.save_last_run_summary(@report)
|
313
|
-
end
|
310
|
+
@catalog.expects(:apply)
|
311
|
+
@agent.expects(:send_report)
|
314
312
|
|
315
|
-
|
316
|
-
|
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
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
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
|
-
|
341
|
+
describe "when sending a report" do
|
342
|
+
include PuppetSpec::Files
|
328
343
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
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
|
-
|
349
|
+
@report = Puppet::Transaction::Report.new("apply")
|
350
|
+
end
|
336
351
|
|
337
|
-
|
338
|
-
|
352
|
+
it "should print a report summary if configured to do so" do
|
353
|
+
Puppet.settings[:summarize] = true
|
339
354
|
|
340
|
-
|
341
|
-
end
|
355
|
+
@report.expects(:summary).returns "stuff"
|
342
356
|
|
343
|
-
|
344
|
-
|
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
|
349
|
-
Puppet
|
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
|
-
@
|
364
|
+
@configurer.expects(:puts).never
|
365
|
+
@configurer.send_report(@report)
|
353
366
|
end
|
354
367
|
|
355
|
-
it "should
|
356
|
-
Puppet
|
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
|
-
@
|
371
|
+
@report.expects(:save)
|
372
|
+
@configurer.send_report(@report)
|
360
373
|
end
|
361
|
-
end
|
362
374
|
|
363
|
-
|
364
|
-
|
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
|
-
@
|
378
|
+
@report.expects(:save).never
|
379
|
+
@configurer.send_report(@report)
|
371
380
|
end
|
372
|
-
end
|
373
381
|
|
374
|
-
|
375
|
-
|
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
|
-
@
|
385
|
+
@configurer.expects(:save_last_run_summary).with(@report)
|
386
|
+
@configurer.send_report(@report)
|
382
387
|
end
|
383
|
-
end
|
384
388
|
|
385
|
-
|
386
|
-
|
389
|
+
it "should save the last run summary if reporting is disabled" do
|
390
|
+
Puppet.settings[:report] = false
|
387
391
|
|
388
|
-
|
389
|
-
|
392
|
+
@configurer.expects(:save_last_run_summary).with(@report)
|
393
|
+
@configurer.send_report(@report)
|
394
|
+
end
|
390
395
|
|
391
|
-
|
392
|
-
|
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
|
-
|
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
|
-
|
400
|
-
|
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
|
-
|
403
|
-
|
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
|
-
|
406
|
-
|
407
|
-
|
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
|
-
|
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
|
-
|
415
|
-
|
416
|
-
|
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
|
-
|
419
|
-
end
|
441
|
+
@catalog = Puppet::Resource::Catalog.new
|
420
442
|
|
421
|
-
|
422
|
-
|
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
|
-
|
426
|
-
|
446
|
+
@agent.stubs(:convert_catalog).returns @catalog
|
447
|
+
end
|
427
448
|
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
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
|
-
|
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
|
-
|
436
|
-
|
458
|
+
@agent.retrieve_catalog({}).should == @catalog
|
459
|
+
end
|
437
460
|
|
438
|
-
|
439
|
-
|
440
|
-
|
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
|
-
|
443
|
-
|
465
|
+
@agent.retrieve_catalog({}).should == @catalog
|
466
|
+
end
|
467
|
+
end
|
444
468
|
|
445
|
-
|
446
|
-
|
469
|
+
it "should use the Catalog class to get its catalog" do
|
470
|
+
Puppet::Resource::Catalog.expects(:find).returns @catalog
|
447
471
|
|
448
|
-
|
449
|
-
|
450
|
-
end
|
472
|
+
@agent.retrieve_catalog({})
|
473
|
+
end
|
451
474
|
|
452
|
-
|
453
|
-
|
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
|
-
|
456
|
-
|
457
|
-
end
|
480
|
+
@agent.retrieve_catalog({})
|
481
|
+
end
|
458
482
|
|
459
|
-
|
460
|
-
|
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
|
-
|
465
|
-
|
466
|
-
end
|
486
|
+
@agent.retrieve_catalog({}).should == @catalog
|
487
|
+
end
|
467
488
|
|
468
|
-
|
469
|
-
|
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
|
-
|
472
|
-
end
|
493
|
+
Puppet.expects(:notice)
|
473
494
|
|
474
|
-
|
475
|
-
|
495
|
+
@agent.retrieve_catalog({}).should == @catalog
|
496
|
+
end
|
476
497
|
|
477
|
-
|
478
|
-
|
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
|
-
|
481
|
-
|
502
|
+
@agent.retrieve_catalog({}).should == @catalog
|
503
|
+
end
|
482
504
|
|
483
|
-
|
484
|
-
|
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
|
-
|
487
|
-
|
509
|
+
@agent.retrieve_catalog({}).should == @catalog
|
510
|
+
end
|
488
511
|
|
489
|
-
|
490
|
-
|
491
|
-
|
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
|
-
|
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
|
-
|
505
|
-
|
506
|
-
@agent.expects(:dostorage)
|
507
|
-
@agent.prepare({})
|
508
|
-
end
|
519
|
+
@agent.retrieve_catalog({}).should be_nil
|
520
|
+
end
|
509
521
|
|
510
|
-
|
511
|
-
|
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
|
-
|
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
|
-
|
517
|
-
|
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
|
-
|
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
|
-
|
523
|
-
|
524
|
-
|
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
|