Skip to content

Commit 0a68b60

Browse files
(PUP-12046) Send facts for puppet catalog download
Facts were not always sent with the catalog request for when using the catalog face. This change allows the face to send facts for the request so that the catalog returned compiled with the correct set of facts.
1 parent 7739378 commit 0a68b60

File tree

3 files changed

+64
-9
lines changed

3 files changed

+64
-9
lines changed

lib/puppet/face/catalog.rb

+24-8
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,27 @@
2525

2626
deactivate_action(:destroy)
2727
deactivate_action(:search)
28-
find = get_action(:find)
29-
find.summary "Retrieve the catalog for the node from which the command is run."
30-
find.arguments "<certname>"
31-
find.returns <<-'EOT'
32-
A serialized catalog. When used from the Ruby API, returns a
33-
Puppet::Resource::Catalog object.
34-
EOT
28+
action(:find) do
29+
summary _("Retrieve the catalog for the node from which the comamand is run.")
30+
arguments "<certname>, <facts>"
31+
option("--facts_for_catalog") do
32+
summary _("Not yet implemented for the CLI; facts will be collected internally.")
33+
end
34+
returns <<-'EOT'
35+
A serialized catalog. When used from the Ruby API, returns a
36+
Puppet::Resource::Catalog object.
37+
EOT
38+
39+
when_invoked do |*args|
40+
# Default the key to Puppet[:certname] if none is supplied
41+
if args.length == 1
42+
key = Puppet[:certname]
43+
else
44+
key = args.shift
45+
end
46+
call_indirection_method :find, key, args.first
47+
end
48+
end
3549

3650
action(:apply) do
3751
summary "Find and apply a catalog."
@@ -135,9 +149,11 @@
135149
when_invoked do |_options|
136150
Puppet::Resource::Catalog.indirection.terminus_class = :rest
137151
Puppet::Resource::Catalog.indirection.cache_class = nil
152+
facts = Puppet::Face[:facts, '0.0.1'].find(Puppet[:certname])
138153
catalog = nil
139154
retrieval_duration = thinmark do
140-
catalog = Puppet::Face[:catalog, '0.0.1'].find(Puppet[:certname])
155+
catalog = Puppet::Face[:catalog, '0.0.1'].find(Puppet[:certname],
156+
{ facts_for_catalog: facts })
141157
end
142158
catalog.retrieval_duration = retrieval_duration
143159
catalog.write_class_file

lib/puppet/interface/action_manager.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module Puppet::Interface::ActionManager
1919
# @dsl Faces
2020
def action(name, &block)
2121
@actions ||= {}
22-
Puppet.warning _("Redefining action %{name} for %{self}") % { name: name, self: self } if action?(name)
22+
Puppet.debug _("Redefining action %{name} for %{self}") % { name: name, self: self } if action?(name)
2323

2424
action = Puppet::Interface::ActionBuilder.build(self, name, &block)
2525

spec/unit/face/catalog_spec.rb

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require 'spec_helper'
2+
require 'puppet/face'
3+
require 'puppet/indirector/facts/facter'
4+
require 'puppet/indirector/facts/rest'
5+
6+
describe Puppet::Face[:catalog, '0.0.1'] do
7+
8+
describe '#download' do
9+
let(:model) { Puppet::Node::Facts }
10+
let(:test_data) { model.new('puppet.node.test', {test_fact: 'catalog_face_request_test_value'}) }
11+
let(:catalog) { Puppet::Resource::Catalog.new('puppet.node.test', Puppet::Node::Environment.remote(Puppet[:environment].to_sym)) }
12+
13+
before(:each) do
14+
Puppet[:facts_terminus] = :memory
15+
Puppet::Node::Facts.indirection.save(test_data)
16+
allow(Puppet::Face[:catalog, "0.0.1"]).to receive(:save).once
17+
18+
Puppet.settings.parse_config(<<-CONF)
19+
[main]
20+
server=puppet.server.test
21+
certname=puppet.node.test
22+
CONF
23+
24+
# Faces start in :user run mode
25+
Puppet.settings.preferred_run_mode = :user
26+
end
27+
28+
it "adds facts to the catalog request" do
29+
stub_request(:post, 'https://puppet.server.test:8140/puppet/v3/catalog/puppet.node.test?environment=*root*')
30+
.with(
31+
headers: { 'Content-Type' => 'application/x-www-form-urlencoded' },
32+
body: /catalog_face_request_test_value/
33+
).to_return(:status => 200, :body => catalog.render(:json), :headers => {'Content-Type' => 'application/json'})
34+
subject.download
35+
end
36+
end
37+
end
38+
39+

0 commit comments

Comments
 (0)