summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--acceptance/tests/allow_arbitrary_node_name_for_agent.rb29
-rw-r--r--acceptance/tests/allow_arbitrary_node_name_for_apply.rb17
-rw-r--r--lib/puppet/application/apply.rb8
-rw-r--r--lib/puppet/configurer.rb4
-rw-r--r--lib/puppet/configurer/fact_handler.rb2
-rw-r--r--lib/puppet/defaults.rb1
-rw-r--r--lib/puppet/transaction/report.rb2
-rwxr-xr-xspec/integration/defaults_spec.rb7
-rwxr-xr-xspec/unit/application/apply_spec.rb4
-rwxr-xr-xspec/unit/configurer/fact_handler_spec.rb11
-rwxr-xr-xspec/unit/configurer_spec.rb6
-rwxr-xr-xspec/unit/transaction/report_spec.rb6
12 files changed, 81 insertions, 16 deletions
diff --git a/acceptance/tests/allow_arbitrary_node_name_for_agent.rb b/acceptance/tests/allow_arbitrary_node_name_for_agent.rb
new file mode 100644
index 000000000..f5e027660
--- /dev/null
+++ b/acceptance/tests/allow_arbitrary_node_name_for_agent.rb
@@ -0,0 +1,29 @@
+test_name "node_name_value should be used as the node name for puppet agent"
+
+success_message = "node_name_value setting was correctly used as the node name"
+
+authfile = "/tmp/auth.conf-2128-#{$$}"
+create_remote_file master, authfile, <<AUTHCONF
+path /catalog/specified_node_name
+auth yes
+allow *
+AUTHCONF
+
+manifest_file = "/tmp/node_name_value-test-#{$$}.pp"
+create_remote_file master, manifest_file, <<MANIFEST
+ Exec { path => "/usr/bin:/bin" }
+ node default {
+ exec { "false": }
+ }
+ node specified_node_name {
+ exec { "echo #{success_message}": }
+ }
+MANIFEST
+
+on master, "chmod 644 #{authfile} #{manifest_file}"
+
+with_master_running_on(master, "--rest_authconfig #{authfile} --manifest #{manifest_file} --daemonize --autosign true") do
+ run_agent_on(agents, "--no-daemonize --verbose --onetime --node_name_value specified_node_name --server #{master}") do
+ assert_match(success_message, stdout)
+ end
+end
diff --git a/acceptance/tests/allow_arbitrary_node_name_for_apply.rb b/acceptance/tests/allow_arbitrary_node_name_for_apply.rb
new file mode 100644
index 000000000..4daa8a65b
--- /dev/null
+++ b/acceptance/tests/allow_arbitrary_node_name_for_apply.rb
@@ -0,0 +1,17 @@
+test_name "node_name_value should be used as the node name for puppet apply"
+
+success_message = "node_name_value setting was correctly used as the node name"
+
+manifest = %Q[
+ Exec { path => "/usr/bin:/bin" }
+ node default {
+ exec { "false": }
+ }
+ node a_different_node_name {
+ exec { "echo #{success_message}": }
+ }
+]
+
+on agents, puppet_apply("--verbose --node_name_value a_different_node_name"), :stdin => manifest do
+ assert_match(success_message, stdout)
+end
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 7f0b95a89..3f423a4c4 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -85,13 +85,13 @@ class Puppet::Application::Apply < Puppet::Application
end
# Collect our facts.
- unless facts = Puppet::Node::Facts.find(Puppet[:certname])
- raise "Could not find facts for #{Puppet[:certname]}"
+ unless facts = Puppet::Node::Facts.find(Puppet[:node_name_value])
+ raise "Could not find facts for #{Puppet[:node_name_value]}"
end
# Find our Node
- unless node = Puppet::Node.find(Puppet[:certname])
- raise "Could not find node #{Puppet[:certname]}"
+ unless node = Puppet::Node.find(Puppet[:node_name_value])
+ raise "Could not find node #{Puppet[:node_name_value]}"
end
# Merge in the facts.
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index 9f68ca499..d0251de82 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -220,7 +220,7 @@ class Puppet::Configurer
def retrieve_catalog_from_cache(fact_options)
result = nil
@duration = thinmark do
- result = Puppet::Resource::Catalog.find(Puppet[:certname], fact_options.merge(:ignore_terminus => true))
+ result = Puppet::Resource::Catalog.find(Puppet[:node_name_value], fact_options.merge(:ignore_terminus => true))
end
Puppet.notice "Using cached catalog"
result
@@ -233,7 +233,7 @@ class Puppet::Configurer
def retrieve_new_catalog(fact_options)
result = nil
@duration = thinmark do
- result = Puppet::Resource::Catalog.find(Puppet[:certname], fact_options.merge(:ignore_cache => true))
+ result = Puppet::Resource::Catalog.find(Puppet[:node_name_value], fact_options.merge(:ignore_cache => true))
end
result
rescue SystemExit,NoMemoryError
diff --git a/lib/puppet/configurer/fact_handler.rb b/lib/puppet/configurer/fact_handler.rb
index 075a59458..4d80e17b6 100644
--- a/lib/puppet/configurer/fact_handler.rb
+++ b/lib/puppet/configurer/fact_handler.rb
@@ -16,7 +16,7 @@ module Puppet::Configurer::FactHandler
# compile them and then "cache" them on the server.
begin
reload_facter
- Puppet::Node::Facts.find(Puppet[:certname])
+ Puppet::Node::Facts.find(Puppet[:node_name_value])
rescue SystemExit,NoMemoryError
raise
rescue Exception => detail
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 2a1ded592..17c2850e5 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -486,6 +486,7 @@ module Puppet
)
setdefaults(:agent,
+ :node_name_value => ["$certname", "The name of the node."],
:localconfig => { :default => "$statedir/localconfig",
:owner => "root",
:mode => 0660,
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index 16fee42ae..841c56968 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -67,7 +67,7 @@ class Puppet::Transaction::Report
@logs = []
@resource_statuses = {}
@external_times ||= {}
- @host = Puppet[:certname]
+ @host = Puppet[:node_name_value]
@time = Time.now
@kind = kind
@report_format = 2
diff --git a/spec/integration/defaults_spec.rb b/spec/integration/defaults_spec.rb
index 2f30014e8..572d98cde 100755
--- a/spec/integration/defaults_spec.rb
+++ b/spec/integration/defaults_spec.rb
@@ -23,6 +23,13 @@ describe "Puppet defaults" do
end
end
+ describe "when setting :node_name_value" do
+ it "should default to the value of :certname" do
+ Puppet.settings[:certname] = 'blargle'
+ Puppet.settings[:node_name_value].should == 'blargle'
+ end
+ end
+
describe "when configuring the :crl" do
it "should warn if :cacrl is set to false" do
Puppet.expects(:warning)
diff --git a/spec/unit/application/apply_spec.rb b/spec/unit/application/apply_spec.rb
index 5bd902a03..83a5ded7f 100755
--- a/spec/unit/application/apply_spec.rb
+++ b/spec/unit/application/apply_spec.rb
@@ -192,10 +192,10 @@ describe Puppet::Application::Apply do
Puppet::Node::Facts.terminus_class = :memory
Puppet::Node.terminus_class = :memory
- @facts = Puppet::Node::Facts.new(Puppet[:certname])
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
@facts.save
- @node = Puppet::Node.new(Puppet[:certname])
+ @node = Puppet::Node.new(Puppet[:node_name_value])
@node.save
@catalog = Puppet::Resource::Catalog.new
diff --git a/spec/unit/configurer/fact_handler_spec.rb b/spec/unit/configurer/fact_handler_spec.rb
index 241da57d6..ddb541174 100755
--- a/spec/unit/configurer/fact_handler_spec.rb
+++ b/spec/unit/configurer/fact_handler_spec.rb
@@ -50,6 +50,17 @@ describe Puppet::Configurer::FactHandler do
Puppet::Node::Facts.terminus_class = :memory
end
+ it "should use the node name value to retrieve the facts" do
+ foo_facts = Puppet::Node::Facts.new('foo')
+ bar_facts = Puppet::Node::Facts.new('bar')
+ foo_facts.save
+ bar_facts.save
+ Puppet[:certname] = 'foo'
+ Puppet[:node_name_value] = 'bar'
+
+ @facthandler.find_facts.should == bar_facts
+ end
+
it "should reload Facter before finding facts" do
@facthandler.expects(:reload_facter)
diff --git a/spec/unit/configurer_spec.rb b/spec/unit/configurer_spec.rb
index 1504ae5c0..6c4f9b90a 100755
--- a/spec/unit/configurer_spec.rb
+++ b/spec/unit/configurer_spec.rb
@@ -77,7 +77,7 @@ describe Puppet::Configurer do
Puppet.settings.stubs(:use).returns(true)
@agent.stubs(:prepare)
Puppet::Node::Facts.terminus_class = :memory
- @facts = Puppet::Node::Facts.new(Puppet[:certname])
+ @facts = Puppet::Node::Facts.new(Puppet[:node_name_value])
@facts.save
@catalog = Puppet::Resource::Catalog.new
@@ -392,9 +392,9 @@ describe Puppet::Configurer do
@agent.retrieve_catalog
end
- it "should use its certname to retrieve the catalog" do
+ it "should use its node_name_value to retrieve the catalog" do
Facter.stubs(:value).returns "eh"
- Puppet.settings[:certname] = "myhost.domain.com"
+ Puppet.settings[:node_name_value] = "myhost.domain.com"
Puppet::Resource::Catalog.expects(:find).with { |name, options| name == "myhost.domain.com" }.returns @catalog
@agent.retrieve_catalog
diff --git a/spec/unit/transaction/report_spec.rb b/spec/unit/transaction/report_spec.rb
index 81efa340e..26d90acb4 100755
--- a/spec/unit/transaction/report_spec.rb
+++ b/spec/unit/transaction/report_spec.rb
@@ -9,9 +9,9 @@ describe Puppet::Transaction::Report do
Puppet::Util::Storage.stubs(:store)
end
- it "should set its host name to the certname" do
- Puppet.settings.expects(:value).with(:certname).returns "myhost"
- Puppet::Transaction::Report.new("apply").host.should == "myhost"
+ it "should set its host name to the node_name_value" do
+ Puppet[:node_name_value] = 'mynode'
+ Puppet::Transaction::Report.new("apply").host.should == "mynode"
end
it "should return its host name as its name" do