Skip to content

Commit fe9b18f

Browse files
authored
Merge pull request #9439 from puppetlabs/backport-9424-to-7.x
[Backport 7.x] (PUP-12046) Send facts for `catalog download`
2 parents 714ec15 + ca42973 commit fe9b18f

File tree

3 files changed

+64
-9
lines changed

3 files changed

+64
-9
lines changed

lib/puppet/face/catalog.rb

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,27 @@
2323

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

3448
action(:apply) do
3549
summary "Find and apply a catalog."
@@ -133,9 +147,11 @@
133147
when_invoked do |options|
134148
Puppet::Resource::Catalog.indirection.terminus_class = :rest
135149
Puppet::Resource::Catalog.indirection.cache_class = nil
150+
facts = Puppet::Face[:facts, '0.0.1'].find(Puppet[:certname])
136151
catalog = nil
137152
retrieval_duration = thinmark do
138-
catalog = Puppet::Face[:catalog, '0.0.1'].find(Puppet[:certname])
153+
catalog = Puppet::Face[:catalog, '0.0.1'].find(Puppet[:certname],
154+
{ facts_for_catalog: facts })
139155
end
140156
catalog.retrieval_duration = retrieval_duration
141157
catalog.write_class_file

lib/puppet/interface/action_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module Puppet::Interface::ActionManager
1717
# @dsl Faces
1818
def action(name, &block)
1919
@actions ||= {}
20-
Puppet.warning _("Redefining action %{name} for %{self}") % { name: name, self: self } if action?(name)
20+
Puppet.debug _("Redefining action %{name} for %{self}") % { name: name, self: self } if action?(name)
2121

2222
action = Puppet::Interface::ActionBuilder.build(self, name, &block)
2323

spec/unit/face/catalog_spec.rb

Lines changed: 39 additions & 0 deletions
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: hash_including(facts: URI.encode_www_form_component(Puppet::Node::Facts.indirection.find('puppet.node.test').to_json))
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)