puppet 0.25.0 → 0.25.1
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 +4772 -19114
- data/README +1 -1
- data/Rakefile +7 -25
- data/{sbin → bin}/puppetca +0 -0
- data/{sbin → bin}/puppetd +0 -0
- data/{sbin → bin}/puppetmasterd +0 -0
- data/{sbin → bin}/puppetqd +0 -0
- data/{sbin → bin}/puppetrun +0 -0
- data/conf/osx/createpackage.sh +1 -1
- data/conf/redhat/client.init +6 -3
- data/conf/redhat/puppet.spec +26 -14
- data/conf/redhat/server.init +3 -2
- data/ext/vim/syntax/puppet.vim +4 -1
- data/install.rb +25 -7
- data/lib/puppet.rb +1 -1
- data/lib/puppet/agent.rb +2 -2
- data/lib/puppet/application/puppet.rb +3 -3
- data/lib/puppet/application/puppetd.rb +0 -7
- data/lib/puppet/application/puppetdoc.rb +1 -0
- data/lib/puppet/application/puppetmasterd.rb +2 -2
- data/lib/puppet/configurer.rb +6 -1
- data/lib/puppet/configurer/fact_handler.rb +2 -2
- data/lib/puppet/defaults.rb +2 -2
- data/lib/puppet/external/nagios/base.rb +4 -3
- data/lib/puppet/external/pson/common.rb +367 -0
- data/lib/puppet/external/pson/pure.rb +77 -0
- data/lib/puppet/external/pson/pure/generator.rb +429 -0
- data/lib/puppet/external/pson/pure/parser.rb +269 -0
- data/lib/puppet/external/pson/version.rb +8 -0
- data/lib/puppet/feature/pson.rb +6 -0
- data/lib/puppet/feature/rails.rb +1 -5
- data/lib/puppet/file_serving/configuration.rb +2 -2
- data/lib/puppet/indirector/certificate/rest.rb +6 -0
- data/lib/puppet/indirector/facts/facter.rb +1 -1
- data/lib/puppet/indirector/ldap.rb +1 -1
- data/lib/puppet/indirector/queue.rb +3 -3
- data/lib/puppet/indirector/rest.rb +1 -1
- data/lib/puppet/network/authstore.rb +34 -53
- data/lib/puppet/network/formats.rb +59 -9
- data/lib/puppet/network/http/mongrel/rest.rb +10 -9
- data/lib/puppet/network/http/webrick.rb +8 -1
- data/lib/puppet/network/http/webrick/rest.rb +2 -5
- data/lib/puppet/network/http_server/webrick.rb +1 -4
- data/lib/puppet/parser/ast/leaf.rb +1 -3
- data/lib/puppet/parser/collector.rb +14 -8
- data/lib/puppet/parser/compiler.rb +7 -0
- data/lib/puppet/parser/functions/fqdn_rand.rb +4 -10
- data/lib/puppet/parser/functions/regsubst.rb +44 -30
- data/lib/puppet/parser/functions/require.rb +18 -3
- data/lib/puppet/parser/functions/versioncmp.rb +1 -1
- data/lib/puppet/parser/interpreter.rb +1 -1
- data/lib/puppet/parser/lexer.rb +29 -31
- data/lib/puppet/parser/loaded_code.rb +4 -0
- data/lib/puppet/parser/parser_support.rb +5 -2
- data/lib/puppet/parser/resource.rb +31 -6
- data/lib/puppet/property.rb +3 -2
- data/lib/puppet/provider/macauthorization/macauthorization.rb +14 -14
- data/lib/puppet/provider/package/dpkg.rb +1 -1
- data/lib/puppet/provider/package/portage.rb +15 -5
- data/lib/puppet/provider/package/rug.rb +1 -1
- data/lib/puppet/provider/package/up2date.rb +1 -1
- data/lib/puppet/provider/package/urpmi.rb +1 -1
- data/lib/puppet/provider/service/daemontools.rb +7 -10
- data/lib/puppet/provider/service/runit.rb +7 -17
- data/lib/puppet/provider/ssh_authorized_key/parsed.rb +7 -47
- data/lib/puppet/provider/zone/solaris.rb +12 -3
- data/lib/puppet/relationship.rb +12 -12
- data/lib/puppet/reports/rrdgraph.rb +1 -1
- data/lib/puppet/reports/store.rb +2 -2
- data/lib/puppet/reports/tagmail.rb +5 -16
- data/lib/puppet/resource.rb +15 -20
- data/lib/puppet/resource/catalog.rb +40 -29
- data/lib/puppet/ssl/certificate_revocation_list.rb +0 -2
- data/lib/puppet/ssl/host.rb +2 -3
- data/lib/puppet/sslcertificates/ca.rb +0 -5
- data/lib/puppet/type/cron.rb +1 -1
- data/lib/puppet/type/file/owner.rb +7 -4
- data/lib/puppet/type/resources.rb +17 -17
- data/lib/puppet/type/yumrepo.rb +10 -3
- data/lib/puppet/util.rb +6 -11
- data/lib/puppet/util/inifile.rb +8 -0
- data/lib/puppet/util/log.rb +2 -2
- data/lib/puppet/util/monkey_patches.rb +0 -43
- data/lib/puppet/util/{json.rb → pson.rb} +6 -6
- data/lib/puppet/util/rdoc.rb +5 -3
- data/lib/puppet/util/selinux.rb +12 -6
- data/lib/puppet/util/settings.rb +25 -16
- data/lib/puppet/util/settings/file_setting.rb +4 -2
- data/spec/integration/application/puppet.rb +4 -4
- data/spec/integration/defaults.rb +2 -2
- data/spec/integration/indirector/catalog/queue.rb +5 -5
- data/spec/integration/indirector/certificate/rest.rb +3 -1
- data/spec/integration/network/formats.rb +36 -36
- data/spec/integration/parser/functions/require.rb +5 -3
- data/spec/integration/provider/mailalias/aliases.rb +4 -4
- data/spec/integration/resource/catalog.rb +4 -4
- data/spec/unit/application/puppet.rb +16 -15
- data/spec/unit/application/puppetd.rb +1 -1
- data/spec/unit/application/puppetdoc.rb +6 -0
- data/spec/unit/application/puppetmasterd.rb +6 -6
- data/spec/unit/configurer/fact_handler.rb +3 -3
- data/spec/unit/file_serving/configuration.rb +16 -2
- data/spec/unit/indirector/certificate/rest.rb +34 -0
- data/spec/unit/indirector/queue.rb +15 -15
- data/spec/unit/indirector/rest.rb +31 -9
- data/spec/unit/network/authstore.rb +105 -26
- data/spec/unit/network/formats.rb +124 -39
- data/spec/unit/parser/ast/leaf.rb +15 -0
- data/spec/unit/parser/collector.rb +20 -9
- data/spec/unit/parser/compiler.rb +19 -0
- data/spec/unit/parser/functions/fqdn_rand.rb +62 -0
- data/spec/unit/parser/functions/regsubst.rb +80 -0
- data/spec/unit/parser/functions/require.rb +19 -7
- data/spec/unit/parser/interpreter.rb +2 -2
- data/spec/unit/parser/lexer.rb +32 -7
- data/spec/unit/parser/loaded_code.rb +18 -1
- data/spec/unit/parser/parser.rb +10 -2
- data/spec/unit/parser/resource.rb +53 -2
- data/spec/unit/parser/scope.rb +1 -1
- data/spec/unit/property.rb +14 -4
- data/spec/unit/provider/package/dpkg.rb +7 -0
- data/spec/unit/provider/service/daemontools.rb +19 -2
- data/spec/unit/provider/service/redhat.rb +2 -0
- data/spec/unit/provider/service/runit.rb +15 -4
- data/spec/unit/provider/ssh_authorized_key/parsed.rb +32 -55
- data/spec/unit/relationship.rb +21 -46
- data/spec/unit/resource.rb +30 -39
- data/spec/unit/resource/catalog.rb +66 -51
- data/spec/unit/ssl/certificate_revocation_list.rb +0 -12
- data/spec/unit/type/cron.rb +33 -0
- data/spec/unit/type/file/owner.rb +10 -4
- data/spec/unit/util/json.rb +9 -9
- data/spec/unit/util/log.rb +36 -0
- data/spec/unit/util/settings.rb +6 -0
- data/test/data/providers/ssh_authorized_key/parsed/authorized_keys2 +1 -0
- data/test/lib/puppettest/support/utils.rb +8 -16
- metadata +36 -13
- data/lib/puppet/feature/json.rb +0 -2
data/spec/unit/relationship.rb
CHANGED
@@ -155,68 +155,43 @@ describe Puppet::Relationship, " when matching edges with a non-standard event"
|
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
describe Puppet::Relationship, "when converting to
|
159
|
-
confine "Missing '
|
158
|
+
describe Puppet::Relationship, "when converting to pson" do
|
159
|
+
confine "Missing 'pson' library" => Puppet.features.pson?
|
160
160
|
|
161
161
|
before do
|
162
162
|
@edge = Puppet::Relationship.new(:a, :b, :event => :random, :callback => :whatever)
|
163
163
|
end
|
164
164
|
|
165
|
-
def json_output_should
|
166
|
-
@edge.class.expects(:json_create).with { |hash| yield hash }
|
167
|
-
end
|
168
|
-
|
169
|
-
# LAK:NOTE For all of these tests, we convert back to the edge so we can
|
170
|
-
# trap the actual data structure then.
|
171
|
-
it "should set the 'json_class' to Puppet::Relationship" do
|
172
|
-
json_output_should { |hash| hash['json_class'] == "Puppet::Relationship" }
|
173
|
-
|
174
|
-
JSON.parse @edge.to_json
|
175
|
-
end
|
176
|
-
|
177
165
|
it "should store the stringified source as the source in the data" do
|
178
|
-
|
179
|
-
|
180
|
-
JSON.parse @edge.to_json
|
166
|
+
PSON.parse(@edge.to_pson)["source"].should == "a"
|
181
167
|
end
|
182
168
|
|
183
169
|
it "should store the stringified target as the target in the data" do
|
184
|
-
|
185
|
-
|
186
|
-
JSON.parse @edge.to_json
|
170
|
+
PSON.parse(@edge.to_pson)['target'].should == "b"
|
187
171
|
end
|
188
172
|
|
189
|
-
it "should store the
|
190
|
-
@edge.event
|
191
|
-
json_output_should { |hash| hash['data']['event'] == "random" }
|
192
|
-
|
193
|
-
JSON.parse @edge.to_json
|
173
|
+
it "should store the psonified event as the event in the data" do
|
174
|
+
PSON.parse(@edge.to_pson)["event"].should == "random"
|
194
175
|
end
|
195
176
|
|
196
177
|
it "should not store an event when none is set" do
|
197
178
|
@edge.event = nil
|
198
|
-
|
199
|
-
|
200
|
-
JSON.parse @edge.to_json
|
179
|
+
PSON.parse(@edge.to_pson)["event"].should be_nil
|
201
180
|
end
|
202
181
|
|
203
|
-
it "should store the
|
182
|
+
it "should store the psonified callback as the callback in the data" do
|
204
183
|
@edge.callback = "whatever"
|
205
|
-
|
206
|
-
|
207
|
-
JSON.parse @edge.to_json
|
184
|
+
PSON.parse(@edge.to_pson)["callback"].should == "whatever"
|
208
185
|
end
|
209
186
|
|
210
187
|
it "should not store a callback when none is set in the edge" do
|
211
188
|
@edge.callback = nil
|
212
|
-
|
213
|
-
|
214
|
-
JSON.parse @edge.to_json
|
189
|
+
PSON.parse(@edge.to_pson)["callback"].should be_nil
|
215
190
|
end
|
216
191
|
end
|
217
192
|
|
218
|
-
describe Puppet::Relationship, "when converting from
|
219
|
-
confine "Missing '
|
193
|
+
describe Puppet::Relationship, "when converting from pson" do
|
194
|
+
confine "Missing 'pson' library" => Puppet.features.pson?
|
220
195
|
|
221
196
|
before do
|
222
197
|
@event = "random"
|
@@ -227,35 +202,35 @@ describe Puppet::Relationship, "when converting from json" do
|
|
227
202
|
"event" => @event,
|
228
203
|
"callback" => @callback
|
229
204
|
}
|
230
|
-
@
|
231
|
-
"
|
205
|
+
@pson = {
|
206
|
+
"type" => "Puppet::Relationship",
|
232
207
|
"data" => @data
|
233
208
|
}
|
234
209
|
end
|
235
210
|
|
236
|
-
def
|
211
|
+
def pson_result_should
|
237
212
|
Puppet::Relationship.expects(:new).with { |*args| yield args }
|
238
213
|
end
|
239
214
|
|
240
|
-
it "should be extended with the
|
241
|
-
Puppet::Relationship.metaclass.ancestors.should be_include(Puppet::Util::
|
215
|
+
it "should be extended with the PSON utility module" do
|
216
|
+
Puppet::Relationship.metaclass.ancestors.should be_include(Puppet::Util::Pson)
|
242
217
|
end
|
243
218
|
|
244
219
|
# LAK:NOTE For all of these tests, we convert back to the edge so we can
|
245
220
|
# trap the actual data structure then.
|
246
221
|
it "should pass the source in as the first argument" do
|
247
|
-
Puppet::Relationship.
|
222
|
+
Puppet::Relationship.from_pson("source" => "mysource", "target" => "mytarget").source.should == "mysource"
|
248
223
|
end
|
249
224
|
|
250
225
|
it "should pass the target in as the second argument" do
|
251
|
-
Puppet::Relationship.
|
226
|
+
Puppet::Relationship.from_pson("source" => "mysource", "target" => "mytarget").target.should == "mytarget"
|
252
227
|
end
|
253
228
|
|
254
229
|
it "should pass the event as an argument if it's provided" do
|
255
|
-
Puppet::Relationship.
|
230
|
+
Puppet::Relationship.from_pson("source" => "mysource", "target" => "mytarget", "event" => "myevent", "callback" => "eh").event.should == "myevent"
|
256
231
|
end
|
257
232
|
|
258
233
|
it "should pass the callback as an argument if it's provided" do
|
259
|
-
Puppet::Relationship.
|
234
|
+
Puppet::Relationship.from_pson("source" => "mysource", "target" => "mytarget", "callback" => "mycallback").callback.should == "mycallback"
|
260
235
|
end
|
261
236
|
end
|
data/spec/unit/resource.rb
CHANGED
@@ -354,63 +354,60 @@ describe Puppet::Resource do
|
|
354
354
|
end
|
355
355
|
end
|
356
356
|
|
357
|
-
describe "when converting to
|
358
|
-
confine "Missing '
|
357
|
+
describe "when converting to pson" do
|
358
|
+
confine "Missing 'pson' library" => Puppet.features.pson?
|
359
359
|
|
360
|
-
def
|
361
|
-
@resource.class.expects(:
|
360
|
+
def pson_output_should
|
361
|
+
@resource.class.expects(:pson_create).with { |hash| yield hash }
|
362
362
|
end
|
363
363
|
|
364
|
-
it "should include the
|
365
|
-
Puppet::Resource.metaclass.ancestors.should be_include(Puppet::Util::
|
364
|
+
it "should include the pson util module" do
|
365
|
+
Puppet::Resource.metaclass.ancestors.should be_include(Puppet::Util::Pson)
|
366
366
|
end
|
367
367
|
|
368
368
|
# LAK:NOTE For all of these tests, we convert back to the resource so we can
|
369
369
|
# trap the actual data structure then.
|
370
|
-
it "should set its json_class to 'Puppet::Resource'" do
|
371
|
-
JSON.parse(Puppet::Resource.new("file", "yay").to_json).should be_instance_of(Puppet::Resource)
|
372
|
-
end
|
373
370
|
|
374
371
|
it "should set its type to the provided type" do
|
375
|
-
|
372
|
+
Puppet::Resource.from_pson(PSON.parse(Puppet::Resource.new("File", "/foo").to_pson)).type.should == "File"
|
376
373
|
end
|
377
374
|
|
378
375
|
it "should set its title to the provided title" do
|
379
|
-
|
376
|
+
Puppet::Resource.from_pson(PSON.parse(Puppet::Resource.new("File", "/foo").to_pson)).title.should == "/foo"
|
380
377
|
end
|
381
378
|
|
382
379
|
it "should include all tags from the resource" do
|
383
380
|
resource = Puppet::Resource.new("File", "/foo")
|
384
381
|
resource.tag("yay")
|
385
382
|
|
386
|
-
|
383
|
+
Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).tags.should == resource.tags
|
387
384
|
end
|
388
385
|
|
389
386
|
it "should include the file if one is set" do
|
390
387
|
resource = Puppet::Resource.new("File", "/foo")
|
391
388
|
resource.file = "/my/file"
|
392
389
|
|
393
|
-
|
390
|
+
Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).file.should == "/my/file"
|
394
391
|
end
|
395
392
|
|
396
393
|
it "should include the line if one is set" do
|
397
394
|
resource = Puppet::Resource.new("File", "/foo")
|
398
395
|
resource.line = 50
|
399
396
|
|
400
|
-
|
397
|
+
Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).line.should == 50
|
401
398
|
end
|
402
399
|
|
403
400
|
it "should include the 'exported' value if one is set" do
|
404
401
|
resource = Puppet::Resource.new("File", "/foo")
|
405
402
|
resource.exported = true
|
406
403
|
|
407
|
-
|
404
|
+
Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).exported.should be_true
|
408
405
|
end
|
409
406
|
|
410
407
|
it "should set 'exported' to false if no value is set" do
|
411
408
|
resource = Puppet::Resource.new("File", "/foo")
|
412
409
|
|
413
|
-
|
410
|
+
Puppet::Resource.from_pson(PSON.parse(resource.to_pson)).exported.should be_false
|
414
411
|
end
|
415
412
|
|
416
413
|
it "should set all of its parameters as the 'parameters' entry" do
|
@@ -418,22 +415,16 @@ describe Puppet::Resource do
|
|
418
415
|
resource[:foo] = %w{bar eh}
|
419
416
|
resource[:fee] = %w{baz}
|
420
417
|
|
421
|
-
result =
|
418
|
+
result = Puppet::Resource.from_pson(PSON.parse(resource.to_pson))
|
422
419
|
result["foo"].should == %w{bar eh}
|
423
420
|
result["fee"].should == %w{baz}
|
424
421
|
end
|
425
|
-
|
426
|
-
it "should set all parameter values as arrays" do
|
427
|
-
resource = Puppet::Resource.new("File", "/foo")
|
428
|
-
resource[:foo] = "bar"
|
429
|
-
JSON.parse(resource.to_json)["foo"].should == %w{bar}
|
430
|
-
end
|
431
422
|
end
|
432
423
|
|
433
|
-
describe "when converting from
|
434
|
-
confine "Missing '
|
424
|
+
describe "when converting from pson" do
|
425
|
+
confine "Missing 'pson' library" => Puppet.features.pson?
|
435
426
|
|
436
|
-
def
|
427
|
+
def pson_result_should
|
437
428
|
Puppet::Resource.expects(:new).with { |hash| yield hash }
|
438
429
|
end
|
439
430
|
|
@@ -445,59 +436,59 @@ describe Puppet::Resource do
|
|
445
436
|
end
|
446
437
|
|
447
438
|
it "should set its type to the provided type" do
|
448
|
-
Puppet::Resource.
|
439
|
+
Puppet::Resource.from_pson(@data).type.should == "File"
|
449
440
|
end
|
450
441
|
|
451
442
|
it "should set its title to the provided title" do
|
452
|
-
Puppet::Resource.
|
443
|
+
Puppet::Resource.from_pson(@data).title.should == "yay"
|
453
444
|
end
|
454
445
|
|
455
446
|
it "should tag the resource with any provided tags" do
|
456
447
|
@data['tags'] = %w{foo bar}
|
457
|
-
resource = Puppet::Resource.
|
448
|
+
resource = Puppet::Resource.from_pson(@data)
|
458
449
|
resource.tags.should be_include("foo")
|
459
450
|
resource.tags.should be_include("bar")
|
460
451
|
end
|
461
452
|
|
462
453
|
it "should set its file to the provided file" do
|
463
454
|
@data['file'] = "/foo/bar"
|
464
|
-
Puppet::Resource.
|
455
|
+
Puppet::Resource.from_pson(@data).file.should == "/foo/bar"
|
465
456
|
end
|
466
457
|
|
467
458
|
it "should set its line to the provided line" do
|
468
459
|
@data['line'] = 50
|
469
|
-
Puppet::Resource.
|
460
|
+
Puppet::Resource.from_pson(@data).line.should == 50
|
470
461
|
end
|
471
462
|
|
472
|
-
it "should 'exported' to true if set in the
|
463
|
+
it "should 'exported' to true if set in the pson data" do
|
473
464
|
@data['exported'] = true
|
474
|
-
Puppet::Resource.
|
465
|
+
Puppet::Resource.from_pson(@data).exported.should be_true
|
475
466
|
end
|
476
467
|
|
477
|
-
it "should 'exported' to false if not set in the
|
478
|
-
Puppet::Resource.
|
468
|
+
it "should 'exported' to false if not set in the pson data" do
|
469
|
+
Puppet::Resource.from_pson(@data).exported.should be_false
|
479
470
|
end
|
480
471
|
|
481
472
|
it "should fail if no title is provided" do
|
482
473
|
@data.delete('title')
|
483
|
-
lambda { Puppet::Resource.
|
474
|
+
lambda { Puppet::Resource.from_pson(@data) }.should raise_error(ArgumentError)
|
484
475
|
end
|
485
476
|
|
486
477
|
it "should fail if no type is provided" do
|
487
478
|
@data.delete('type')
|
488
|
-
lambda { Puppet::Resource.
|
479
|
+
lambda { Puppet::Resource.from_pson(@data) }.should raise_error(ArgumentError)
|
489
480
|
end
|
490
481
|
|
491
482
|
it "should set each of the provided parameters" do
|
492
483
|
@data['parameters'] = {'foo' => %w{one two}, 'fee' => %w{three four}}
|
493
|
-
resource = Puppet::Resource.
|
484
|
+
resource = Puppet::Resource.from_pson(@data)
|
494
485
|
resource['foo'].should == %w{one two}
|
495
486
|
resource['fee'].should == %w{three four}
|
496
487
|
end
|
497
488
|
|
498
489
|
it "should convert single-value array parameters to normal values" do
|
499
490
|
@data['parameters'] = {'foo' => %w{one}}
|
500
|
-
resource = Puppet::Resource.
|
491
|
+
resource = Puppet::Resource.from_pson(@data)
|
501
492
|
resource['foo'].should == %w{one}
|
502
493
|
end
|
503
494
|
end
|
@@ -35,6 +35,18 @@ describe Puppet::Resource::Catalog, "when compiling" do
|
|
35
35
|
@catalog.write_class_file
|
36
36
|
end
|
37
37
|
|
38
|
+
it "should have a client_version attribute" do
|
39
|
+
@catalog = Puppet::Resource::Catalog.new("host")
|
40
|
+
@catalog.client_version = 5
|
41
|
+
@catalog.client_version.should == 5
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should have a server_version attribute" do
|
45
|
+
@catalog = Puppet::Resource::Catalog.new("host")
|
46
|
+
@catalog.server_version = 5
|
47
|
+
@catalog.server_version.should == 5
|
48
|
+
end
|
49
|
+
|
38
50
|
describe "when compiling" do
|
39
51
|
it "should accept tags" do
|
40
52
|
config = Puppet::Resource::Catalog.new("mynode")
|
@@ -875,71 +887,70 @@ describe Puppet::Resource::Catalog, "when compiling" do
|
|
875
887
|
end
|
876
888
|
end
|
877
889
|
|
878
|
-
describe Puppet::Resource::Catalog, "when converting to
|
879
|
-
confine "Missing '
|
890
|
+
describe Puppet::Resource::Catalog, "when converting to pson" do
|
891
|
+
confine "Missing 'pson' library" => Puppet.features.pson?
|
880
892
|
|
881
893
|
before do
|
882
894
|
@catalog = Puppet::Resource::Catalog.new("myhost")
|
883
895
|
end
|
884
896
|
|
885
|
-
def
|
886
|
-
@catalog.class.expects(:
|
897
|
+
def pson_output_should
|
898
|
+
@catalog.class.expects(:pson_create).with { |hash| yield hash }.returns(:something)
|
887
899
|
end
|
888
900
|
|
889
901
|
# LAK:NOTE For all of these tests, we convert back to the resource so we can
|
890
902
|
# trap the actual data structure then.
|
891
|
-
it "should set its
|
892
|
-
|
903
|
+
it "should set its document_type to 'Catalog'" do
|
904
|
+
pson_output_should { |hash| hash['document_type'] == "Catalog" }
|
893
905
|
|
894
|
-
|
906
|
+
PSON.parse @catalog.to_pson
|
895
907
|
end
|
896
908
|
|
897
909
|
it "should set its data as a hash" do
|
898
|
-
|
899
|
-
|
910
|
+
pson_output_should { |hash| hash['data'].is_a?(Hash) }
|
911
|
+
PSON.parse @catalog.to_pson
|
900
912
|
end
|
901
913
|
|
902
|
-
[:name, :version, :tags].each do |param|
|
914
|
+
[:name, :version, :tags, :classes].each do |param|
|
903
915
|
it "should set its #{param} to the #{param} of the resource" do
|
904
916
|
@catalog.send(param.to_s + "=", "testing") unless @catalog.send(param)
|
905
917
|
|
906
|
-
|
907
|
-
|
918
|
+
pson_output_should { |hash| hash['data'][param.to_s] == @catalog.send(param) }
|
919
|
+
PSON.parse @catalog.to_pson
|
908
920
|
end
|
909
921
|
end
|
910
922
|
|
911
|
-
it "should convert its resources to a
|
912
|
-
one = stub 'one', :
|
913
|
-
two = stub 'two', :
|
923
|
+
it "should convert its resources to a PSON-encoded array and store it as the 'resources' data" do
|
924
|
+
one = stub 'one', :to_pson_data_hash => "one_resource", :ref => "Foo[one]"
|
925
|
+
two = stub 'two', :to_pson_data_hash => "two_resource", :ref => "Foo[two]"
|
914
926
|
|
915
927
|
@catalog.add_resource(one)
|
916
928
|
@catalog.add_resource(two)
|
917
929
|
|
918
930
|
# TODO this should really guarantee sort order
|
919
|
-
|
920
|
-
|
931
|
+
PSON.parse(@catalog.to_pson,:create_additions => false)['data']['resources'].sort.should == ["one_resource", "two_resource"].sort
|
932
|
+
|
921
933
|
end
|
922
934
|
|
923
|
-
it "should convert its edges to a
|
924
|
-
one
|
925
|
-
two
|
926
|
-
three = stub 'three', :
|
935
|
+
it "should convert its edges to a PSON-encoded array and store it as the 'edges' data" do
|
936
|
+
one = stub 'one', :to_pson_data_hash => "one_resource", :ref => 'Foo[one]'
|
937
|
+
two = stub 'two', :to_pson_data_hash => "two_resource", :ref => 'Foo[two]'
|
938
|
+
three = stub 'three', :to_pson_data_hash => "three_resource", :ref => 'Foo[three]'
|
927
939
|
|
928
940
|
@catalog.add_edge(one, two)
|
929
941
|
@catalog.add_edge(two, three)
|
930
942
|
|
931
|
-
@catalog.edge(one, two).expects(:
|
932
|
-
@catalog.edge(two, three).expects(:
|
943
|
+
@catalog.edge(one, two ).expects(:to_pson_data_hash).returns "one_two_pson"
|
944
|
+
@catalog.edge(two, three).expects(:to_pson_data_hash).returns "two_three_pson"
|
933
945
|
|
934
|
-
|
935
|
-
JSON.parse @catalog.to_json
|
946
|
+
PSON.parse(@catalog.to_pson,:create_additions => false)['data']['edges'].sort.should == %w{one_two_pson two_three_pson}.sort
|
936
947
|
end
|
937
948
|
end
|
938
949
|
|
939
|
-
describe Puppet::Resource::Catalog, "when converting from
|
940
|
-
confine "Missing '
|
950
|
+
describe Puppet::Resource::Catalog, "when converting from pson" do
|
951
|
+
confine "Missing 'pson' library" => Puppet.features.pson?
|
941
952
|
|
942
|
-
def
|
953
|
+
def pson_result_should
|
943
954
|
Puppet::Resource::Catalog.expects(:new).with { |hash| yield hash }
|
944
955
|
end
|
945
956
|
|
@@ -947,54 +958,58 @@ describe Puppet::Resource::Catalog, "when converting from json" do
|
|
947
958
|
@data = {
|
948
959
|
'name' => "myhost"
|
949
960
|
}
|
950
|
-
@
|
951
|
-
'
|
952
|
-
'data' => @data
|
961
|
+
@pson = {
|
962
|
+
'document_type' => 'Puppet::Resource::Catalog',
|
963
|
+
'data' => @data,
|
964
|
+
'metadata' => {}
|
953
965
|
}
|
954
966
|
|
955
967
|
@catalog = Puppet::Resource::Catalog.new("myhost")
|
956
968
|
Puppet::Resource::Catalog.stubs(:new).returns @catalog
|
957
969
|
end
|
958
970
|
|
959
|
-
it "should be extended with the
|
960
|
-
Puppet::Resource::Catalog.metaclass.ancestors.should be_include(Puppet::Util::
|
971
|
+
it "should be extended with the PSON utility module" do
|
972
|
+
Puppet::Resource::Catalog.metaclass.ancestors.should be_include(Puppet::Util::Pson)
|
961
973
|
end
|
962
974
|
|
963
975
|
it "should create it with the provided name" do
|
964
976
|
Puppet::Resource::Catalog.expects(:new).with('myhost').returns @catalog
|
965
|
-
|
977
|
+
PSON.parse @pson.to_pson
|
966
978
|
end
|
967
979
|
|
968
980
|
it "should set the provided version on the catalog if one is set" do
|
969
981
|
@data['version'] = 50
|
970
|
-
@
|
971
|
-
|
972
|
-
JSON.parse @json.to_json
|
982
|
+
PSON.parse @pson.to_pson
|
983
|
+
@catalog.version.should == @data['version']
|
973
984
|
end
|
974
985
|
|
975
986
|
it "should set any provided tags on the catalog" do
|
976
987
|
@data['tags'] = %w{one two}
|
977
|
-
@
|
988
|
+
PSON.parse @pson.to_pson
|
989
|
+
@catalog.tags.should == @data['tags']
|
990
|
+
end
|
978
991
|
|
979
|
-
|
992
|
+
it "should set any provided classes on the catalog" do
|
993
|
+
@data['classes'] = %w{one two}
|
994
|
+
PSON.parse @pson.to_pson
|
995
|
+
@catalog.classes.should == @data['classes']
|
980
996
|
end
|
981
997
|
|
982
998
|
it 'should convert the resources list into resources and add each of them' do
|
983
999
|
@data['resources'] = [Puppet::Resource.new(:file, "/foo"), Puppet::Resource.new(:file, "/bar")]
|
984
1000
|
|
985
1001
|
@catalog.expects(:add_resource).times(2).with { |res| res.type == "File" }
|
986
|
-
|
987
|
-
JSON.parse @json.to_json
|
1002
|
+
PSON.parse @pson.to_pson
|
988
1003
|
end
|
989
1004
|
|
990
|
-
it 'should convert resources even if they do not include "
|
1005
|
+
it 'should convert resources even if they do not include "type" information' do
|
991
1006
|
@data['resources'] = [Puppet::Resource.new(:file, "/foo")]
|
992
1007
|
|
993
|
-
@data['resources'][0].expects(:
|
1008
|
+
@data['resources'][0].expects(:to_pson).returns '{"title":"/foo","tags":["file"],"type":"File"}'
|
994
1009
|
|
995
1010
|
@catalog.expects(:add_resource).with { |res| res.type == "File" }
|
996
1011
|
|
997
|
-
|
1012
|
+
PSON.parse @pson.to_pson
|
998
1013
|
end
|
999
1014
|
|
1000
1015
|
it 'should convert the edges list into edges and add each of them' do
|
@@ -1008,12 +1023,12 @@ describe Puppet::Resource::Catalog, "when converting from json" do
|
|
1008
1023
|
@catalog.expects(:add_edge).with { |edge| edge.event == "one" }
|
1009
1024
|
@catalog.expects(:add_edge).with { |edge| edge.event == "two" }
|
1010
1025
|
|
1011
|
-
|
1026
|
+
PSON.parse @pson.to_pson
|
1012
1027
|
end
|
1013
1028
|
|
1014
|
-
it "should be able to convert relationships that do not include '
|
1029
|
+
it "should be able to convert relationships that do not include 'type' information" do
|
1015
1030
|
one = Puppet::Relationship.new("osource", "otarget", :event => "one", :callback => "refresh")
|
1016
|
-
one.expects(:
|
1031
|
+
one.expects(:to_pson).returns "{\"event\":\"one\",\"callback\":\"refresh\",\"source\":\"osource\",\"target\":\"otarget\"}"
|
1017
1032
|
|
1018
1033
|
@data['edges'] = [one]
|
1019
1034
|
|
@@ -1021,7 +1036,7 @@ describe Puppet::Resource::Catalog, "when converting from json" do
|
|
1021
1036
|
|
1022
1037
|
@catalog.expects(:add_edge).with { |edge| edge.event == "one" }
|
1023
1038
|
|
1024
|
-
|
1039
|
+
PSON.parse @pson.to_pson
|
1025
1040
|
end
|
1026
1041
|
|
1027
1042
|
it "should set the source and target for each edge to the actual resource" do
|
@@ -1034,7 +1049,7 @@ describe Puppet::Resource::Catalog, "when converting from json" do
|
|
1034
1049
|
|
1035
1050
|
@catalog.expects(:add_edge).with { |edge| edge.source == "source_resource" and edge.target == "target_resource" }
|
1036
1051
|
|
1037
|
-
|
1052
|
+
PSON.parse @pson.to_pson
|
1038
1053
|
end
|
1039
1054
|
|
1040
1055
|
it "should fail if the source resource cannot be found" do
|
@@ -1045,7 +1060,7 @@ describe Puppet::Resource::Catalog, "when converting from json" do
|
|
1045
1060
|
@catalog.expects(:resource).with("source").returns(nil)
|
1046
1061
|
@catalog.stubs(:resource).with("target").returns("target_resource")
|
1047
1062
|
|
1048
|
-
lambda {
|
1063
|
+
lambda { PSON.parse @pson.to_pson }.should raise_error(ArgumentError)
|
1049
1064
|
end
|
1050
1065
|
|
1051
1066
|
it "should fail if the target resource cannot be found" do
|
@@ -1056,6 +1071,6 @@ describe Puppet::Resource::Catalog, "when converting from json" do
|
|
1056
1071
|
@catalog.stubs(:resource).with("source").returns("source_resource")
|
1057
1072
|
@catalog.expects(:resource).with("target").returns(nil)
|
1058
1073
|
|
1059
|
-
lambda {
|
1074
|
+
lambda { PSON.parse @pson.to_pson }.should raise_error(ArgumentError)
|
1060
1075
|
end
|
1061
1076
|
end
|