blob: c0ad7562f226d448677d7c34160f7967ad323c41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
#!/usr/bin/env ruby
#
# Created by Luke Kanies on 2007-11-12.
# Copyright (c) 2007. All rights reserved.
require File.dirname(__FILE__) + '/../../../spec_helper'
require 'puppet/network/client/master'
describe Puppet::Network::Client::Master, " when retrieving the catalog" do
before do
@master = mock 'master'
@client = Puppet::Network::Client.master.new(
:Master => @master
)
@facts = {"one" => "two", "three" => "four"}
end
it "should initialize the metadata store" do
@client.class.stubs(:facts).returns(@facts)
@client.expects(:dostorage)
@master.stubs(:getconfig).returns(nil)
@client.getconfig
end
it "should collect facts to use for catalog retrieval" do
@client.stubs(:dostorage)
@client.class.expects(:facts).returns(@facts)
@master.stubs(:getconfig).returns(nil)
@client.getconfig
end
it "should fail if no facts could be collected" do
@client.stubs(:dostorage)
@client.class.expects(:facts).returns({})
@master.stubs(:getconfig).returns(nil)
proc { @client.getconfig }.should raise_error(Puppet::Network::ClientError)
end
it "should retrieve plugins if :pluginsync is enabled" do
file = "/path/to/cachefile"
@client.stubs(:cachefile).returns(file)
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
Puppet.settings.expects(:value).with(:pluginsync).returns(true)
@client.expects(:getplugins)
@client.stubs(:get_actual_config).returns(nil)
FileTest.stubs(:exist?).with(file).returns(true)
@client.stubs(:use_cached_config).returns(true)
@client.class.stubs(:facts).returns(@facts)
@client.getconfig
end
it "should use the cached catalog if no catalog could be retrieved" do
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
@master.stubs(:getconfig).raises(ArgumentError.new("whev"))
@client.expects(:use_cached_config).with(true)
@client.getconfig
end
it "should load the retrieved catalog using YAML" do
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
@master.stubs(:getconfig).returns("myconfig")
config = mock 'config'
YAML.expects(:load).with("myconfig").returns(config)
@client.stubs(:setclasses)
config.stubs(:classes)
config.stubs(:to_catalog).returns(config)
config.stubs(:host_config=)
config.stubs(:from_cache).returns(true)
@client.getconfig
end
it "should use the cached catalog if the retrieved catalog cannot be converted from YAML" do
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
@master.stubs(:getconfig).returns("myconfig")
YAML.expects(:load).with("myconfig").raises(ArgumentError)
@client.expects(:use_cached_config).with(true)
@client.getconfig
end
it "should set the classes.txt file with the classes listed in the retrieved catalog" do
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
@master.stubs(:getconfig).returns("myconfig")
config = mock 'config'
YAML.expects(:load).with("myconfig").returns(config)
config.expects(:classes).returns(:myclasses)
@client.expects(:setclasses).with(:myclasses)
config.stubs(:to_catalog).returns(config)
config.stubs(:host_config=)
config.stubs(:from_cache).returns(true)
@client.getconfig
end
it "should convert the retrieved catalog to a RAL catalog" do
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
@master.stubs(:getconfig).returns("myconfig")
yamlconfig = mock 'yaml config'
YAML.stubs(:load).returns(yamlconfig)
@client.stubs(:setclasses)
config = mock 'config'
yamlconfig.stubs(:classes)
yamlconfig.expects(:to_catalog).returns(config)
config.stubs(:host_config=)
config.stubs(:from_cache).returns(true)
@client.getconfig
end
it "should use the cached catalog if the retrieved catalog cannot be converted to a RAL catalog" do
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
@master.stubs(:getconfig).returns("myconfig")
yamlconfig = mock 'yaml config'
YAML.stubs(:load).returns(yamlconfig)
@client.stubs(:setclasses)
config = mock 'config'
yamlconfig.stubs(:classes)
yamlconfig.expects(:to_catalog).raises(ArgumentError)
@client.expects(:use_cached_config).with(true)
@client.getconfig
end
it "should clear the failed catalog if using the cached catalog after failing to instantiate the retrieved catalog" do
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
@master.stubs(:getconfig).returns("myconfig")
yamlconfig = mock 'yaml config'
YAML.stubs(:load).returns(yamlconfig)
@client.stubs(:setclasses)
config = mock 'config'
yamlconfig.stubs(:classes)
yamlconfig.stubs(:to_catalog).raises(ArgumentError)
@client.stubs(:use_cached_config).with(true)
@client.expects(:clear)
@client.getconfig
end
it "should cache the retrieved yaml catalog if it is not from the cache and is valid" do
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
@master.stubs(:getconfig).returns("myconfig")
yamlconfig = mock 'yaml config'
YAML.stubs(:load).returns(yamlconfig)
@client.stubs(:setclasses)
config = mock 'config'
yamlconfig.stubs(:classes)
yamlconfig.expects(:to_catalog).returns(config)
config.stubs(:host_config=)
config.expects(:from_cache).returns(false)
@client.expects(:cache).with("myconfig")
@client.getconfig
end
it "should mark the catalog as a host catalog" do
@client.stubs(:dostorage)
@client.class.stubs(:facts).returns(@facts)
@master.stubs(:getconfig).returns("myconfig")
yamlconfig = mock 'yaml config'
YAML.stubs(:load).returns(yamlconfig)
@client.stubs(:setclasses)
config = mock 'config'
yamlconfig.stubs(:classes)
yamlconfig.expects(:to_catalog).returns(config)
config.stubs(:from_cache).returns(true)
config.expects(:host_config=).with(true)
@client.getconfig
end
end
describe Puppet::Network::Client::Master, " when using the cached catalog" do
before do
@master = mock 'master'
@client = Puppet::Network::Client.master.new(
:Master => @master
)
@facts = {"one" => "two", "three" => "four"}
end
it "should return do nothing and true if there is already an in-memory catalog" do
@client.catalog = :whatever
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config.should be_true
end
end
it "should return do nothing and false if it has been told there is a failure and :nocacheonfailure is enabled" do
Puppet.settings.expects(:value).with(:usecacheonfailure).returns(false)
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config(true).should be_false
end
end
it "should return false if no cached catalog can be found" do
@client.expects(:retrievecache).returns(nil)
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config().should be_false
end
end
it "should return false if the cached catalog cannot be instantiated" do
YAML.expects(:load).raises(ArgumentError)
@client.expects(:retrievecache).returns("whatever")
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config().should be_false
end
end
it "should warn if the cached catalog cannot be instantiated" do
YAML.stubs(:load).raises(ArgumentError)
@client.stubs(:retrievecache).returns("whatever")
Puppet.expects(:warning).with { |m| m.include?("Could not load cache") }
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config().should be_false
end
end
it "should clear the client if the cached catalog cannot be instantiated" do
YAML.stubs(:load).raises(ArgumentError)
@client.stubs(:retrievecache).returns("whatever")
@client.expects(:clear)
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config().should be_false
end
end
it "should return true if the cached catalog can be instantiated" do
config = mock 'config'
YAML.stubs(:load).returns(config)
ral_config = mock 'ral config'
ral_config.stubs(:from_cache=)
ral_config.stubs(:host_config=)
config.expects(:to_catalog).returns(ral_config)
@client.stubs(:retrievecache).returns("whatever")
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config().should be_true
end
end
it "should set the catalog instance variable if the cached catalog can be instantiated" do
config = mock 'config'
YAML.stubs(:load).returns(config)
ral_config = mock 'ral config'
ral_config.stubs(:from_cache=)
ral_config.stubs(:host_config=)
config.expects(:to_catalog).returns(ral_config)
@client.stubs(:retrievecache).returns("whatever")
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config()
end
@client.catalog.should equal(ral_config)
end
it "should mark the catalog as a host_config if valid" do
config = mock 'config'
YAML.stubs(:load).returns(config)
ral_config = mock 'ral config'
ral_config.stubs(:from_cache=)
ral_config.expects(:host_config=).with(true)
config.expects(:to_catalog).returns(ral_config)
@client.stubs(:retrievecache).returns("whatever")
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config()
end
@client.catalog.should equal(ral_config)
end
it "should mark the catalog as from the cache if valid" do
config = mock 'config'
YAML.stubs(:load).returns(config)
ral_config = mock 'ral config'
ral_config.expects(:from_cache=).with(true)
ral_config.stubs(:host_config=)
config.expects(:to_catalog).returns(ral_config)
@client.stubs(:retrievecache).returns("whatever")
Puppet::Network::Client::Master.publicize_methods :use_cached_config do
@client.use_cached_config()
end
@client.catalog.should equal(ral_config)
end
end
|