~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to spec/unit/configurer_spec.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env ruby
 
1
#!/usr/bin/env rspec
2
2
#
3
3
#  Created by Luke Kanies on 2007-11-12.
4
4
#  Copyright (c) 2007. All rights reserved.
5
5
 
6
 
require File.dirname(__FILE__) + '/../spec_helper'
 
6
require 'spec_helper'
7
7
require 'puppet/configurer'
8
8
 
9
9
describe Puppet::Configurer do
82
82
    @catalog.stubs(:apply)
83
83
    @agent.stubs(:retrieve_catalog).returns @catalog
84
84
    @agent.stubs(:save_last_run_summary)
85
 
 
86
 
    Puppet::Util::Log.stubs(:newdestination)
87
 
    Puppet::Util::Log.stubs(:close)
 
85
    Puppet::Transaction::Report.indirection.stubs(:save)
88
86
  end
89
87
 
90
88
  it "should prepare for the run" do
95
93
 
96
94
  it "should initialize a transaction report if one is not provided" do
97
95
    report = Puppet::Transaction::Report.new("apply")
98
 
    Puppet::Transaction::Report.expects(:new).returns report
 
96
    Puppet::Transaction::Report.expects(:new).at_least_once.returns report
99
97
 
100
98
    @agent.run
101
99
  end
120
118
    report = Puppet::Transaction::Report.new("apply")
121
119
    Puppet::Transaction::Report.expects(:new).returns report
122
120
 
 
121
    @agent.stubs(:send_report)
123
122
    Puppet::Util::Log.expects(:newdestination).with(report)
124
123
 
125
124
    @agent.run
212
211
    report = Puppet::Transaction::Report.new("apply")
213
212
    Puppet::Transaction::Report.expects(:new).returns(report)
214
213
 
215
 
    Puppet::Util::Log.expects(:close).with(report)
 
214
    report.expects(:<<).at_least_once
216
215
 
217
216
    @agent.run
 
217
    Puppet::Util::Log.destinations.should_not include(report)
218
218
  end
219
219
 
220
220
  it "should return the report as the result of the run" do
261
261
  it "should save the report if reporting is enabled" do
262
262
    Puppet.settings[:report] = true
263
263
 
264
 
    @report.expects(:save)
 
264
    Puppet::Transaction::Report.indirection.expects(:save).with(@report)
265
265
    @configurer.send_report(@report, nil)
266
266
  end
267
267
 
268
268
  it "should not save the report if reporting is disabled" do
269
269
    Puppet.settings[:report] = false
270
270
 
271
 
    @report.expects(:save).never
 
271
    Puppet::Transaction::Report.indirection.expects(:save).never
272
272
    @configurer.send_report(@report, nil)
273
273
  end
274
274
 
289
289
  it "should log but not fail if saving the report fails" do
290
290
    Puppet.settings[:report] = true
291
291
 
292
 
    @report.expects(:save).raises "whatever"
 
292
    Puppet::Transaction::Report.indirection.expects(:save).with(@report).raises "whatever"
293
293
 
294
294
    Puppet.expects(:err)
295
295
    lambda { @configurer.send_report(@report, nil) }.should_not raise_error
346
346
    end
347
347
 
348
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
 
349
      Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
 
350
      Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.never
351
351
 
352
352
      @agent.retrieve_catalog.should == @catalog
353
353
    end
354
354
 
355
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
 
356
      Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
 
357
      Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
358
358
 
359
359
      @agent.retrieve_catalog.should == @catalog
360
360
    end
363
363
  describe "when not using a REST terminus for catalogs" do
364
364
    it "should not pass any facts when retrieving the catalog" do
365
365
      @agent.expects(:facts_for_uploading).never
366
 
      Puppet::Resource::Catalog.expects(:find).with { |name, options|
 
366
      Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
367
367
        options[:facts].nil?
368
368
      }.returns @catalog
369
369
 
374
374
  describe "when using a REST terminus for catalogs" do
375
375
    it "should pass the prepared facts and the facts format as arguments when retrieving the catalog" do
376
376
      @agent.expects(:facts_for_uploading).returns(:facts => "myfacts", :facts_format => :foo)
377
 
      Puppet::Resource::Catalog.expects(:find).with { |name, options|
 
377
      Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options|
378
378
        options[:facts] == "myfacts" and options[:facts_format] == :foo
379
379
      }.returns @catalog
380
380
 
383
383
  end
384
384
 
385
385
  it "should use the Catalog class to get its catalog" do
386
 
    Puppet::Resource::Catalog.expects(:find).returns @catalog
 
386
    Puppet::Resource::Catalog.indirection.expects(:find).returns @catalog
387
387
 
388
388
    @agent.retrieve_catalog
389
389
  end
391
391
  it "should use its certname to retrieve the catalog" do
392
392
    Facter.stubs(:value).returns "eh"
393
393
    Puppet.settings[:certname] = "myhost.domain.com"
394
 
    Puppet::Resource::Catalog.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
 
394
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
395
395
 
396
396
    @agent.retrieve_catalog
397
397
  end
398
398
 
399
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
 
400
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
401
401
 
402
402
    @agent.retrieve_catalog.should == @catalog
403
403
  end
404
404
 
405
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
 
406
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
 
407
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
408
408
 
409
409
    Puppet.expects(:notice)
410
410
 
412
412
  end
413
413
 
414
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
 
415
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns @catalog
 
416
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.never
417
417
 
418
418
    @agent.retrieve_catalog.should == @catalog
419
419
  end
420
420
 
421
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
 
422
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.raises "eh"
 
423
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns @catalog
424
424
 
425
425
    @agent.retrieve_catalog.should == @catalog
426
426
  end
428
428
  it "should log and return nil if no catalog can be retrieved from the server and :usecacheonfailure is disabled" do
429
429
    Puppet.stubs(:[])
430
430
    Puppet.expects(:[]).with(:usecacheonfailure).returns false
431
 
    Puppet::Resource::Catalog.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
 
431
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
432
432
 
433
433
    Puppet.expects(:warning)
434
434
 
436
436
  end
437
437
 
438
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
 
439
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_cache] == true }.returns nil
 
440
    Puppet::Resource::Catalog.indirection.expects(:find).with { |name, options| options[:ignore_terminus] == true }.returns nil
441
441
 
442
442
    @agent.retrieve_catalog.should be_nil
443
443
  end
444
444
 
445
445
  it "should convert the catalog before returning" do
446
 
    Puppet::Resource::Catalog.stubs(:find).returns @catalog
 
446
    Puppet::Resource::Catalog.indirection.stubs(:find).returns @catalog
447
447
 
448
448
    @agent.expects(:convert_catalog).with { |cat, dur| cat == @catalog }.returns "converted catalog"
449
449
    @agent.retrieve_catalog.should == "converted catalog"
450
450
  end
451
451
 
452
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"
 
453
    Puppet::Resource::Catalog.indirection.expects(:find).at_least_once.raises "eh"
454
454
 
455
455
    @agent.retrieve_catalog.should be_nil
456
456
  end