Skip to content

Commit

Permalink
(PUP-2522) Include transaction_uuid in node requests
Browse files Browse the repository at this point in the history
This makes the transaction_uuid available for use by a node terminus, to make
it easier to track the full catalog lifecycle when using an ENC.
  • Loading branch information
pcarlisle authored and Kylo Ginsberg committed May 15, 2014
1 parent 528c687 commit df37377
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
11 changes: 4 additions & 7 deletions lib/puppet/configurer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ def apply_catalog(catalog, options)
report
end

def get_transaction_uuid
{ :transaction_uuid => @transaction_uuid }
end

# The code that actually runs the catalog.
# This just passes any options on to the catalog,
# which accepts :tags and :ignoreschedules.
Expand All @@ -148,7 +144,7 @@ def run(options = {})
unless options[:catalog]
begin
if node = Puppet::Node.indirection.find(Puppet[:node_name_value],
:environment => @environment, :ignore_cache => true)
:environment => @environment, :ignore_cache => true, :transaction_uuid => @transaction_uuid)
if node.environment.to_s != @environment
Puppet.warning "Local environment: \"#{@environment}\" doesn't match server specified node environment \"#{node.environment}\", switching agent to \"#{node.environment}\"."
@environment = node.environment.to_s
Expand All @@ -166,8 +162,9 @@ def run(options = {})

query_options = get_facts(options) unless query_options

# add the transaction uuid to the catalog query options hash
query_options.merge! get_transaction_uuid if query_options
# get_facts returns nil during puppet apply
query_options ||= {}
query_options[:transaction_uuid] = @transaction_uuid

unless catalog = prepare_and_retrieve_catalog(options, query_options)
return nil
Expand Down
7 changes: 4 additions & 3 deletions lib/puppet/indirector/catalog/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,12 @@ def compile(node)
end

# Turn our host name into a node object.
def find_node(name, environment)
def find_node(name, environment, transaction_uuid)
Puppet::Util::Profiler.profile("Found node information") do
node = nil
begin
node = Puppet::Node.indirection.find(name, :environment => environment)
node = Puppet::Node.indirection.find(name, :environment => environment,
:transaction_uuid => transaction_uuid)
rescue => detail
message = "Failed when searching for node #{name}: #{detail}"
Puppet.log_exception(detail, message)
Expand Down Expand Up @@ -143,7 +144,7 @@ def node_from_request(request)
# node's catalog with only one certificate and a modification to auth.conf
# If no key is provided we can only compile the currently connected node.
name = request.key || request.node
if node = find_node(name, request.environment)
if node = find_node(name, request.environment, request.options[:transaction_uuid])
return node
end

Expand Down
7 changes: 7 additions & 0 deletions spec/unit/configurer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,13 @@ def method_missing(*args)
end
end

describe "when requesting a node" do
it "uses the transaction uuid in the request" do
Puppet::Node.indirection.expects(:find).with(anything, has_entries(:transaction_uuid => anything)).twice
@agent.run
end
end

describe "when retrieving a catalog" do
before do
Puppet.settings.stubs(:use).returns(true)
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/indirector/catalog/compiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ def a_request_that_contains(facts)

compiler.find(request)
end

it "should pass the transaction_uuid to the node indirection" do
uuid = '793ff10d-89f8-4527-a645-3302cbc749f3'
node = Puppet::Node.new("thing")
compiler = Puppet::Resource::Catalog::Compiler.new
compiler.stubs(:compile)
request = Puppet::Indirector::Request.new(:catalog, :find, "thing",
nil, :transaction_uuid => uuid)

Puppet::Node.indirection.expects(:find).with(
"thing",
has_entries(:transaction_uuid => uuid)
).returns(node)

compiler.find(request)
end
end

describe "after finding nodes" do
Expand Down

0 comments on commit df37377

Please sign in to comment.