Skip to content

Commit 60fab12

Browse files
committed
(PUP-11074) Add catalog edge only if parent resource has a container
Managing resources with generators behaves differently with `puppet resource` and `puppet apply`. When running with `puppet apply`, the parent resource is always contained by something like `Class[Main]`, so adding an edge between that and our generated resource works. When running with `puppet resource`, the parent resource is not contained by anything (`container_of(parent_resource)` returns nil), which adds an edge with a nil vertex to the catalog. This in turn causes the run to fail with a NilClass exception when performing pre-run checks[1] in the Transaction class, as the catalog now contains a nil vertex. [1] https://github.com/puppetlabs/puppet/blob/ab56d86ecb4b71298c75325462bf73376420bb40/lib/puppet/transaction.rb#L80
1 parent 2fde3e6 commit 60fab12

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/puppet/transaction/additional_resource_generator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def add_resource(res, parent_resource, priority=nil)
137137
else
138138
@catalog.add_resource_after(parent_resource, res)
139139
end
140-
@catalog.add_edge(@catalog.container_of(parent_resource), res)
140+
@catalog.add_edge(@catalog.container_of(parent_resource), res) if @catalog.container_of(parent_resource)
141141
if @relationship_graph && priority
142142
# If we have a relationship_graph we should add the resource
143143
# to it (this is an eval_generate). If we don't, then the
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'spec_helper'
2+
require 'puppet_spec/files'
3+
4+
describe "puppet resource", unless: Puppet::Util::Platform.jruby? do
5+
include PuppetSpec::Files
6+
7+
let(:resource) { Puppet::Application[:resource] }
8+
9+
describe "when handling file and tidy types" do
10+
let!(:dir) { dir_containing('testdir', 'testfile' => 'contents') }
11+
12+
it 'does not raise when generating file resources' do
13+
resource.command_line.args = ['file', dir, 'ensure=directory', 'recurse=true']
14+
15+
expect {
16+
resource.run
17+
}.to output(/ensure.+=> 'directory'/).to_stdout
18+
end
19+
20+
it 'correctly cleans up a given path' do
21+
resource.command_line.args = ['tidy', dir, 'rmdirs=true', 'recurse=true']
22+
23+
expect {
24+
resource.run
25+
}.to output(/Notice: \/File\[#{dir}\]\/ensure: removed/).to_stdout
26+
27+
expect(Puppet::FileSystem.exist?(dir)).to be false
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)