diff options
| author | Nick Lewis <nick@puppetlabs.com> | 2010-11-23 16:42:06 -0800 |
|---|---|---|
| committer | Nick Lewis <nick@puppetlabs.com> | 2010-11-23 16:42:06 -0800 |
| commit | 4b35402ba85d8842d757becec5c8a7bf4d6f6654 (patch) | |
| tree | 5da174c4c1c106b99e8c464e45e89d7b5ba2b5a2 /spec/integration | |
| parent | a7bd1630622cace01d0e4c974c76366e4b3b886c (diff) | |
| parent | 2bc6727b6ac7348dbac98099f1fe0aeb3cd1295f (diff) | |
| download | puppet-4b35402ba85d8842d757becec5c8a7bf4d6f6654.tar.gz puppet-4b35402ba85d8842d757becec5c8a7bf4d6f6654.tar.xz puppet-4b35402ba85d8842d757becec5c8a7bf4d6f6654.zip | |
Merge branch 'next'
Diffstat (limited to 'spec/integration')
| -rwxr-xr-x | spec/integration/configurer_spec.rb | 43 | ||||
| -rwxr-xr-x | spec/integration/defaults_spec.rb | 1 | ||||
| -rw-r--r-- | spec/integration/parser/functions_spec.rb | 21 | ||||
| -rw-r--r-- | spec/integration/parser/ruby_manifest_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/integration/ssl/certificate_authority_spec.rb | 4 | ||||
| -rwxr-xr-x | spec/integration/util/file_locking_spec.rb | 42 |
6 files changed, 93 insertions, 20 deletions
diff --git a/spec/integration/configurer_spec.rb b/spec/integration/configurer_spec.rb index 9a8b66fe4..cb7d3d779 100755 --- a/spec/integration/configurer_spec.rb +++ b/spec/integration/configurer_spec.rb @@ -5,6 +5,8 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/configurer' describe Puppet::Configurer do + include PuppetSpec::Files + describe "when downloading plugins" do it "should use the :pluginsignore setting, split on whitespace, for ignoring remote files" do resource = Puppet::Type.type(:notify).new :name => "yay" @@ -17,19 +19,50 @@ describe Puppet::Configurer do end describe "when running" do - it "should send a transaction report with valid data" do - catalog = Puppet::Resource::Catalog.new - catalog.add_resource(Puppet::Type.type(:notify).new(:title => "testing")) + before(:each) do + @catalog = Puppet::Resource::Catalog.new + @catalog.add_resource(Puppet::Type.type(:notify).new(:title => "testing")) - configurer = Puppet::Configurer.new + # Make sure we don't try to persist the local state after the transaction ran, + # because it will fail during test (the state file is in an not existing directory) + # and we need the transaction to be successful to be able to produce a summary report + @catalog.host_config = false + + @configurer = Puppet::Configurer.new + end + + it "should send a transaction report with valid data" do + @configurer.stubs(:save_last_run_summary) Puppet::Transaction::Report.indirection.expects(:save).with do |x, report| report.time.class == Time and report.logs.length > 0 end Puppet[:report] = true - configurer.run :catalog => catalog + @configurer.run :catalog => @catalog + end + + it "should save a correct last run summary" do + report = Puppet::Transaction::Report.new + report.stubs(:save) + + Puppet[:lastrunfile] = tmpfile("lastrunfile") + Puppet[:report] = true + + @configurer.run :catalog => @catalog, :report => report + + summary = nil + File.open(Puppet[:lastrunfile], "r") do |fd| + summary = YAML.load(fd.read) + end + + summary.should be_a(Hash) + %w{time changes events resources}.each do |key| + summary.should be_key(key) + end + summary["time"].should be_key("notify") + summary["time"]["last_run"].should >= Time.now.tv_sec end end end diff --git a/spec/integration/defaults_spec.rb b/spec/integration/defaults_spec.rb index 1f90c7cbc..2f30014e8 100755 --- a/spec/integration/defaults_spec.rb +++ b/spec/integration/defaults_spec.rb @@ -3,6 +3,7 @@ require File.dirname(__FILE__) + '/../spec_helper' require 'puppet/defaults' +require 'puppet/rails' describe "Puppet defaults" do include Puppet::Util::Execution diff --git a/spec/integration/parser/functions_spec.rb b/spec/integration/parser/functions_spec.rb new file mode 100644 index 000000000..cbfb4ac88 --- /dev/null +++ b/spec/integration/parser/functions_spec.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../spec_helper' + +describe Puppet::Parser::Functions do + before :each do + Puppet::Parser::Functions.rmfunction("template") if Puppet::Parser::Functions.function("template") + end + + it "should support multiple threads autoloading the same function" do + threads = [] + lambda { + 10.times { |a| + threads << Thread.new { + Puppet::Parser::Functions.function("template") + } + } + }.should_not raise_error + threads.each { |t| t.join } + end +end
\ No newline at end of file diff --git a/spec/integration/parser/ruby_manifest_spec.rb b/spec/integration/parser/ruby_manifest_spec.rb index af110d3b3..de6f4628c 100644 --- a/spec/integration/parser/ruby_manifest_spec.rb +++ b/spec/integration/parser/ruby_manifest_spec.rb @@ -69,7 +69,7 @@ describe "Pure ruby manifests" do write_file('foo.rb', "hostclass 'bar' do file 'test_file', :owner => 'root', :mode => '644' end") catalog = compile("import 'foo'\ninclude bar") file = catalog.resource("File[test_file]") - file.should be_a Puppet::Resource + file.should be_a(Puppet::Resource) file.type.should == 'File' file.title.should == 'test_file' file.exported.should_not be diff --git a/spec/integration/ssl/certificate_authority_spec.rb b/spec/integration/ssl/certificate_authority_spec.rb index fca17b405..67ff6f215 100755 --- a/spec/integration/ssl/certificate_authority_spec.rb +++ b/spec/integration/ssl/certificate_authority_spec.rb @@ -121,9 +121,7 @@ describe Puppet::SSL::CertificateAuthority do it "should save valid certificates" do @ca.sign("luke.madstop.com") - ssl = %x{which openssl} - - unless ssl + unless ssl = Puppet::Util::which('openssl') pending "No ssl available" else ca_cert = Puppet[:cacert] diff --git a/spec/integration/util/file_locking_spec.rb b/spec/integration/util/file_locking_spec.rb index 20c61d3d5..50613448b 100755 --- a/spec/integration/util/file_locking_spec.rb +++ b/spec/integration/util/file_locking_spec.rb @@ -5,28 +5,30 @@ Dir.chdir(File.dirname(__FILE__)) { (s = lambda { |f| File.exist?(f) ? require(f require 'puppet/util/file_locking' describe Puppet::Util::FileLocking do - it "should be able to keep file corruption from happening when there are multiple writers" do - file = Tempfile.new("puppetspec") - filepath = file.path - file.close!() - file = filepath - data = {:a => :b, :c => "A string", :d => "another string", :e => %w{an array of strings}} - File.open(file, "w") { |f| f.puts YAML.dump(data) } + before :each do + @file = Tempfile.new("puppetspec") + filepath = @file.path + @file.close!() + @file = filepath + @data = {:a => :b, :c => "A string", :d => "another string", :e => %w{an array of strings}} + File.open(@file, "w") { |f| f.puts YAML.dump(@data) } + end + it "should be able to keep file corruption from happening when there are multiple writers threads" do threads = [] sync = Sync.new 9.times { |a| threads << Thread.new { 9.times { |b| sync.synchronize(Sync::SH) { - Puppet::Util::FileLocking.readlock(file) { |f| - YAML.load(f.read).should == data + Puppet::Util::FileLocking.readlock(@file) { |f| + YAML.load(f.read).should == @data } } sleep 0.01 sync.synchronize(Sync::EX) { - Puppet::Util::FileLocking.writelock(file) { |f| - f.puts YAML.dump(data) + Puppet::Util::FileLocking.writelock(@file) { |f| + f.puts YAML.dump(@data) } } } @@ -34,4 +36,22 @@ describe Puppet::Util::FileLocking do } threads.each { |th| th.join } end + + it "should be able to keep file corruption from happening when there are multiple writers processes" do + unless Process.fork + 50.times { |b| + Puppet::Util::FileLocking.writelock(@file) { |f| + f.puts YAML.dump(@data) + } + sleep 0.01 + } + Kernel.exit! + end + + 50.times { |c| + Puppet::Util::FileLocking.readlock(@file) { |f| + YAML.load(f.read).should == @data + } + } + end end |
