summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2009-07-23 23:52:44 -0700
committerLuke Kanies <luke@madstop.com>2009-08-01 12:50:41 -0700
commit6ed01037ad8b6d8d5ff7158ef6e09c785ed8b9fe (patch)
treec0c6e37e74d8fabaa95e32092b0d4296aa4542a5
parent39320b8794549fa7806f2e9e57346242b0b7e847 (diff)
downloadpuppet-6ed01037ad8b6d8d5ff7158ef6e09c785ed8b9fe.tar.gz
puppet-6ed01037ad8b6d8d5ff7158ef6e09c785ed8b9fe.tar.xz
puppet-6ed01037ad8b6d8d5ff7158ef6e09c785ed8b9fe.zip
Adding support for an external catalog version
This allows you to specify a command used to determine the catalog version. Also added an integration test to verify the version cascades. Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/defaults.rb6
-rw-r--r--lib/puppet/parser/parser_support.rb12
-rwxr-xr-xspec/integration/defaults.rb4
-rwxr-xr-xspec/integration/parser/compiler.rb29
-rwxr-xr-xspec/unit/parser/compiler.rb4
-rwxr-xr-xspec/unit/parser/parser.rb15
6 files changed, 68 insertions, 2 deletions
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 9444e1164..b1fddc3a3 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -188,7 +188,11 @@ module Puppet
:hook => proc do |value|
Puppet.settings[:storeconfigs] = true if value
end
- }
+ },
+ :config_version => ["", "How to determine the configuration version. By default, it will be the
+ time that the configuration is parsed, but you can provide a shell script to override how the
+ version is determined. The output of this script will be added to every log message in the
+ reports, allowing you to correlate changes on your hosts to the source version on the server."]
)
hostname = Facter["hostname"].value
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index b13fbb47f..f1c1da0b0 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -437,7 +437,6 @@ class Puppet::Parser::Parser
# Store the results as the top-level class.
newclass("", :code => main)
end
- @version = Time.now.to_i
return @loaded_code
ensure
@lexer.clear
@@ -456,6 +455,17 @@ class Puppet::Parser::Parser
@lexer.string = string
end
+ def version
+ return @version if defined?(@version)
+
+ if Puppet[:config_version] == ""
+ @version = Time.now.to_i
+ return @version
+ end
+
+ @version = %x{#{Puppet[:config_version]}}.chomp
+ end
+
# Add a new file to be checked when we're checking to see if we should be
# reparsed. This is basically only used by the TemplateWrapper to let the
# parser know about templates that should be parsed.
diff --git a/spec/integration/defaults.rb b/spec/integration/defaults.rb
index 72b5127e5..b2e5a829c 100755
--- a/spec/integration/defaults.rb
+++ b/spec/integration/defaults.rb
@@ -153,4 +153,8 @@ describe "Puppet defaults" do
Puppet.settings[:storeconfigs].should be_true
end
end
+
+ it "should have a setting for determining the configuration version and should default to an empty string" do
+ Puppet.settings[:config_version].should == ""
+ end
end
diff --git a/spec/integration/parser/compiler.rb b/spec/integration/parser/compiler.rb
new file mode 100755
index 000000000..27666400b
--- /dev/null
+++ b/spec/integration/parser/compiler.rb
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+describe Puppet::Parser::Compiler do
+ before :each do
+ @node = Puppet::Node.new "testnode"
+
+ @scope_resource = stub 'scope_resource', :builtin? => true, :finish => nil, :ref => 'Class[main]'
+ @scope = stub 'scope', :resource => @scope_resource, :source => mock("source")
+ end
+
+ after do
+ Puppet.settings.clear
+ end
+
+ it "should be able to determine the configuration version from a local version control repository" do
+ # This should always work, because we should always be
+ # in the puppet repo when we run this.
+ version = %x{git rev-parse HEAD}.chomp
+
+ Puppet.settings[:config_version] = 'git rev-parse HEAD'
+
+ @parser = Puppet::Parser::Parser.new :environment => "development"
+ @compiler = Puppet::Parser::Compiler.new(@node, @parser)
+
+ @compiler.catalog.version.should == version
+ end
+end
diff --git a/spec/unit/parser/compiler.rb b/spec/unit/parser/compiler.rb
index 9b9428296..0cc6e8a17 100755
--- a/spec/unit/parser/compiler.rb
+++ b/spec/unit/parser/compiler.rb
@@ -82,6 +82,10 @@ describe Puppet::Parser::Compiler do
@parser.expects(:nodes?).returns true
@compiler.ast_nodes?.should be_true
end
+
+ it "should copy the parser version to the catalog" do
+ @compiler.catalog.version.should == @parser.version
+ end
end
describe "when managing scopes" do
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 3fd1b2d57..bd12f7155 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -313,4 +313,19 @@ describe Puppet::Parser do
end
end
+ describe "when determining the configuration version" do
+ it "should default to the current time" do
+ time = Time.now
+
+ Time.stubs(:now).returns time
+ @parser.version.should == time.to_i
+ end
+
+ it "should use the output of the config_version setting if one is provided" do
+ Puppet.settings.stubs(:[]).with(:config_version).returns("/my/foo")
+
+ @parser.expects(:`).with("/my/foo").returns "output\n"
+ @parser.version.should == "output"
+ end
+ end
end