~nvalcarcel/ubuntu/lucid/puppet/fix-546677

« back to all changes in this revision

Viewing changes to ext/puppet-test

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-12-23 00:48:10 UTC
  • mfrom: (1.1.10 upstream) (3.1.7 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091223004810-3i4oryds922g5n59
Tags: 0.25.1-3ubuntu1
* Merge from debian testing.  Remaining changes:
  - debian/rules:
    + Don't start puppet when first installing puppet.
  - debian/puppet.conf, lib/puppet/defaults.rb:
    + Move templates to /etc/puppet
  - lib/puppet/defaults.rb:
    + Fix /var/lib/puppet/state ownership.
  - man/man8/puppet.conf.8: 
    + Fix broken URL in manpage.
  - debian/control:
    + Update maintainer accordint to spec.
    + Puppetmaster Recommends -> Suggests
    + Created puppet-testsuite as a seperate. Allow the users to run puppet's 
      testsuite.
  - tests/Rakefile: Fix rakefile so that the testsuite can acutally be ran.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env ruby
2
 
# == Synopsis 
 
2
# == Synopsis
3
3
#
4
4
# Test individual client performance.  Can compile configurations, describe
5
5
# files, or retrieve files.
53
53
# list::
54
54
#   List all available tests.
55
55
#
 
56
# node::
 
57
#  Specify the node to use.  This is useful for looking up cached yaml data
 
58
#  in your :clientyaml directory, and forcing a specific host's configuration to
 
59
#  get compiled.
 
60
#
56
61
# pause::
57
62
#  Pause before starting test (useful for testing with dtrace).
58
63
#
216
221
 
217
222
Suite.new :local_catalog, "Local catalog handling" do
218
223
    def prepare
219
 
        @node = Puppet::Node.find(Puppet[:certname])
 
224
        @node = Puppet::Node.find($options[:nodes][0])
220
225
    end
221
226
 
222
227
    newtest :compile, "Compiled catalog" do
223
 
        Puppet::Node::Catalog.find(@node)
 
228
        Puppet::Resource::Catalog.find(@node)
224
229
    end
225
230
end
226
231
 
233
238
            fail "Could not read client certificate"
234
239
        end
235
240
 
236
 
        # Use the facts from the cache, to skip the time it takes
237
 
        # to load them.
238
 
        @client.dostorage
239
 
        @facts = Puppet::Util::Storage.cache(:configuration)[:facts] || {}
240
 
 
241
 
        if @facts.empty?
242
 
            if tmp = Puppet::Node::Facts.find("me")
243
 
                @facts = tmp.values
244
 
            end
 
241
        if tmp = Puppet::Node::Facts.find($options[:nodes][0])
 
242
            @facts = tmp.values
 
243
        else
 
244
            raise "Could not find facts for %s" % $optins[:nodes][0]
245
245
        end
246
246
 
247
247
        if host = $options[:fqdn]
309
309
        Puppet::Rails.init
310
310
        @facts = Facter.to_hash
311
311
 
312
 
        if num = ENV["RESOURCECOUNT"] 
 
312
        if num = ENV["RESOURCECOUNT"]
313
313
            @resources = Integer(num)
314
314
        else
315
315
            @resources = 10
364
364
    end
365
365
end
366
366
 
 
367
Suite.new :report, "Reports interactions" do
 
368
    def prepare
 
369
        Puppet::Transaction::Report.terminus_class = :rest
 
370
    end
 
371
 
 
372
    newtest :empty, "send empty report" do
 
373
        report = Puppet::Transaction::Report.new
 
374
        report.time = Time.now
 
375
        report.save
 
376
    end
 
377
 
 
378
    newtest :fake, "send fake report" do
 
379
        report = Puppet::Transaction::Report.new
 
380
 
 
381
        resourcemetrics = {
 
382
            :total => 12,
 
383
            :out_of_sync => 20,
 
384
            :applied => 45,
 
385
            :skipped => 1,
 
386
            :restarted => 23,
 
387
            :failed_restarts => 1,
 
388
            :scheduled => 10
 
389
        }
 
390
        report.newmetric(:resources, resourcemetrics)
 
391
 
 
392
        timemetrics = {
 
393
            :resource1 => 10,
 
394
            :resource2 => 50,
 
395
            :resource3 => 40,
 
396
            :resource4 => 20,
 
397
        }
 
398
        report.newmetric(:times, timemetrics)
 
399
 
 
400
        report.newmetric(:changes,
 
401
            :total => 20
 
402
        )
 
403
 
 
404
        report.time = Time.now
 
405
        report.save
 
406
    end
 
407
end
 
408
 
 
409
 
367
410
$cmdargs = [
368
 
        [ "--compile",    "-c",                 GetoptLong::NO_ARGUMENT ],
369
 
        [ "--describe",                         GetoptLong::REQUIRED_ARGUMENT ],
370
 
        [ "--retrieve",  "-R",                  GetoptLong::REQUIRED_ARGUMENT ],
371
 
        [ "--fork",                             GetoptLong::REQUIRED_ARGUMENT ],
372
 
        [ "--fqdn",      "-F",                  GetoptLong::REQUIRED_ARGUMENT ],
373
 
        [ "--suite",     "-s",                  GetoptLong::REQUIRED_ARGUMENT ],
374
 
        [ "--test",      "-t",                  GetoptLong::REQUIRED_ARGUMENT ],
375
 
        [ "--pause",     "-p",                  GetoptLong::NO_ARGUMENT ],
376
 
        [ "--repeat",    "-r",                  GetoptLong::REQUIRED_ARGUMENT ],
377
 
        [ "--debug",     "-d",                  GetoptLong::NO_ARGUMENT ],
378
 
        [ "--help",              "-h",                  GetoptLong::NO_ARGUMENT ],
379
 
        [ "--list",          "-l",                      GetoptLong::NO_ARGUMENT ],
380
 
        [ "--verbose",   "-v",                  GetoptLong::NO_ARGUMENT ],
381
 
        [ "--version",   "-V",                  GetoptLong::NO_ARGUMENT ],
 
411
    [ "--compile",  "-c", GetoptLong::NO_ARGUMENT       ],
 
412
    [ "--describe",       GetoptLong::REQUIRED_ARGUMENT ],
 
413
    [ "--retrieve", "-R", GetoptLong::REQUIRED_ARGUMENT ],
 
414
    [ "--fork",           GetoptLong::REQUIRED_ARGUMENT ],
 
415
    [ "--fqdn",     "-F", GetoptLong::REQUIRED_ARGUMENT ],
 
416
    [ "--suite",    "-s", GetoptLong::REQUIRED_ARGUMENT ],
 
417
    [ "--test",     "-t", GetoptLong::REQUIRED_ARGUMENT ],
 
418
    [ "--pause",    "-p", GetoptLong::NO_ARGUMENT       ],
 
419
    [ "--repeat",   "-r", GetoptLong::REQUIRED_ARGUMENT ],
 
420
    [ "--node",     "-n", GetoptLong::REQUIRED_ARGUMENT ],
 
421
    [ "--debug",    "-d", GetoptLong::NO_ARGUMENT       ],
 
422
    [ "--help",     "-h", GetoptLong::NO_ARGUMENT       ],
 
423
    [ "--list",     "-l", GetoptLong::NO_ARGUMENT       ],
 
424
    [ "--verbose",  "-v", GetoptLong::NO_ARGUMENT       ],
 
425
    [ "--version",  "-V", GetoptLong::NO_ARGUMENT       ],
382
426
]
383
427
 
384
428
# Add all of the config parameters as valid $options.
385
429
Puppet.settings.addargs($cmdargs)
386
430
Puppet::Util::Log.newdestination(:console)
387
431
 
 
432
Puppet::Node.terminus_class = :plain
 
433
Puppet::Node.cache_class = :yaml
 
434
Puppet::Node::Facts.terminus_class = :facter
 
435
Puppet::Node::Facts.cache_class = :yaml
 
436
 
388
437
result = GetoptLong.new(*$cmdargs)
389
438
 
390
439
$args = {}
391
440
 
392
 
$options = {:repeat => 1, :fork => 0, :pause => false}
 
441
$options = {:repeat => 1, :fork => 0, :pause => false, :nodes => []}
393
442
 
394
443
begin
395
444
    explicit_waitforcert = false
443
492
                $options[:file] = arg
444
493
            when "--pause"
445
494
                $options[:pause] = true
 
495
            when "--node"
 
496
                $options[:nodes] << arg
446
497
            when "--list"
447
498
                Suite.suites.sort { |a,b| a.to_s <=> b.to_s }.each do |suite_name|
448
499
                    suite = Suite[suite_name]
463
514
# Now parse the config
464
515
Puppet.parse_config
465
516
 
 
517
$options[:nodes] << Puppet.settings[:certname] if $options[:nodes].empty?
 
518
 
466
519
$args[:Server] = Puppet[:server]
467
520
 
468
521
unless $options[:test]
481
534
if $options[:fork] > 0
482
535
    Process.waitall
483
536
end
484
 
 
485
 
# $Id$