Skip to content

Commit 40f4352

Browse files
committed
Add Puppet 6 support for computed catalogs
Add support for Puppet >= 6.5.0. The Puppet command Octocatalog-diff used was removed in 6.0.0 and an equivalent command was added back in 6.5.0. With this change, Octocatalog-diff detects the Puppet version and adjusts the Puppet command line as needed based on the version.
1 parent 1493455 commit 40f4352

File tree

7 files changed

+82
-15
lines changed

7 files changed

+82
-15
lines changed

config/puppet-versions.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@
1919
"maximum_version": "5.99.99",
2020
"additional_gems": [
2121
]
22+
},
23+
{
24+
"minimum_version": "6.0.0",
25+
"maximum_version": "6.99.99",
26+
"additional_gems": [
27+
]
2228
}
2329
]

lib/octocatalog-diff/catalog-util/command.rb

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,21 @@ def setup
5454
raise ArgumentError, 'Puppet binary was not supplied' if @puppet_binary.nil?
5555
raise Errno::ENOENT, "Puppet binary #{@puppet_binary} doesn't exist" unless File.file?(@puppet_binary)
5656

57+
puppet_version = Gem::Version.new(@options[:puppet_version])
58+
5759
# Node to compile
5860
cmdline = []
59-
cmdline.concat ['master', '--compile', Shellwords.escape(@node)]
61+
# The 'puppet master --compile' command was removed in Puppet 6.x and replaced in
62+
# Puppet 6.5 with an identically functioning 'puppet catalog compile' command.
63+
# From versions 6.0.0 until 6.5.0 there is no compatible invocation method.
64+
if puppet_version < Gem::Version.new('6.0.0')
65+
cmdline.concat ['master', '--compile', Shellwords.escape(@node)]
66+
elsif puppet_version < Gem::Version.new('6.5.0')
67+
raise OctocatalogDiff::Errors::PuppetVersionError,
68+
'Octocatalog-diff does not support Puppet versions >= 6.0.0 and < 6.5.0'
69+
else
70+
cmdline.concat ['catalog', 'compile', Shellwords.escape(@node)]
71+
end
6072

6173
# storeconfigs?
6274
if @options[:storeconfigs]
@@ -93,11 +105,21 @@ def setup
93105
# Some typical options for puppet
94106
cmdline.concat %w(
95107
--no-daemonize
96-
--no-ca
97108
--color=false
98-
--config_version="/bin/echo catalogscript"
99109
)
100110

111+
if puppet_version < Gem::Version.new('6.0.0')
112+
# This config_version parameter causes an error when run with Puppet 6.x. Per
113+
# the Puppet configuration settings docs, the below config_version argument
114+
# may not actually be valid, but for backward compatibility's sake we'll keep it
115+
# for the versions it has always worked with:
116+
cmdline.concat ['--config_version="/bin/echo catalogscript"']
117+
118+
# The 'ca' configuration option was removed in Puppet 6, but we'll keep it
119+
# for older versions:
120+
cmdline.concat ['--no-ca']
121+
end
122+
101123
# Add environment - only make this variable if preserve_environments is used.
102124
# If preserve_environments is not used, the hard-coded 'production' here matches
103125
# up with the symlink created under the temporary directory structure.

lib/octocatalog-diff/catalog/computed.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ def puppet_command_obj
147147
puppet_binary: @puppet_binary,
148148
fact_file: @builddir.fact_file,
149149
dir: @builddir.tempdir,
150-
enc: @builddir.enc
150+
enc: @builddir.enc,
151+
puppet_version: puppet_version
151152
)
152153
OctocatalogDiff::CatalogUtil::Command.new(command_opts)
153154
end

spec/octocatalog-diff/integration/reference_validation_spec.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def self.catalog_contains_resource(result, type, title)
126126
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::CatalogError)
127127
end
128128

129-
if OctocatalogDiff::Spec.is_puppet5?
129+
if OctocatalogDiff::Spec.major_version >= 5
130130
it 'should pass through the error messages from Puppet' do
131131
msg = @result.exception.message
132132
expect(msg).to match(/Error: Could not find resource 'Exec\[subscribe target\]' in parameter 'subscribe'/)
@@ -159,7 +159,7 @@ def self.catalog_contains_resource(result, type, title)
159159
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::CatalogError)
160160
end
161161

162-
if OctocatalogDiff::Spec.is_puppet5?
162+
if OctocatalogDiff::Spec.major_version >= 5
163163
it 'should pass through the error messages from Puppet' do
164164
msg = @result.exception.message
165165
expect(msg).to match(/Error: Could not find resource 'Exec\[before target\]' in parameter 'before'/)
@@ -187,7 +187,7 @@ def self.catalog_contains_resource(result, type, title)
187187
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::CatalogError)
188188
end
189189

190-
if OctocatalogDiff::Spec.is_puppet5?
190+
if OctocatalogDiff::Spec.major_version >= 5
191191
it 'should pass through the error messages from Puppet' do
192192
msg = @result.exception.message
193193
expect(msg).to match(/Error: Could not find resource 'Test::Foo::Bar\[notify target\]' in parameter 'notify'/)
@@ -215,7 +215,7 @@ def self.catalog_contains_resource(result, type, title)
215215
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::CatalogError)
216216
end
217217

218-
if OctocatalogDiff::Spec.is_puppet5?
218+
if OctocatalogDiff::Spec.major_version >= 5
219219
it 'should pass through the error messages from Puppet' do
220220
msg = @result.exception.message
221221
expect(msg).to match(/Error: Could not find resource 'Exec\[require target\]' in parameter 'require'/)
@@ -239,7 +239,7 @@ def self.catalog_contains_resource(result, type, title)
239239
@result = OctocatalogDiff::Spec.reference_validation_catalog('broken-subscribe', %w(before notify require))
240240
end
241241

242-
if OctocatalogDiff::Spec.is_puppet5?
242+
if OctocatalogDiff::Spec.major_version >= 5
243243
it 'should raise CatalogError' do
244244
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::CatalogError)
245245
end
@@ -295,7 +295,7 @@ def self.catalog_contains_resource(result, type, title)
295295
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::CatalogError)
296296
end
297297

298-
if OctocatalogDiff::Spec.is_puppet5?
298+
if OctocatalogDiff::Spec.major_version >= 5
299299
it 'should pass through the error messages from Puppet' do
300300
msg = @result.exception.message
301301
expect(msg).to match(/Error: Could not find resource 'Exec\[before alias target\]' in parameter 'before'/)

spec/octocatalog-diff/tests/catalog-util/command_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_relative '../spec_helper'
44
require 'fileutils'
55
require OctocatalogDiff::Spec.require_path('/catalog-util/command')
6+
require OctocatalogDiff::Spec.require_path('/errors')
67

78
describe OctocatalogDiff::CatalogUtil::Command do
89
describe '#initialize' do
@@ -73,6 +74,23 @@
7374
expect { testobj.puppet_command }.to raise_error(Errno::ENOENT, /Puppet binary.*doesn't exist/)
7475
end
7576

77+
it 'should use "master --compile" when Puppet version is 5.x' do
78+
testobj = OctocatalogDiff::CatalogUtil::Command.new(@default_opts.merge(puppet_version: '5.5.20'))
79+
result = testobj.puppet_command
80+
expect(result).to match(/master --compile/)
81+
end
82+
83+
it 'should use "catalog compile" when Puppet version is 6.x' do
84+
testobj = OctocatalogDiff::CatalogUtil::Command.new(@default_opts.merge(puppet_version: '6.5.0'))
85+
result = testobj.puppet_command
86+
expect(result).to match(/catalog compile/)
87+
end
88+
89+
it 'should raise an error when Puppet version is 6.4' do
90+
testobj = OctocatalogDiff::CatalogUtil::Command.new(@default_opts.merge(puppet_version: '6.4.0'))
91+
expect { testobj.puppet_command }.to raise_error(OctocatalogDiff::Errors::PuppetVersionError, /does not support/)
92+
end
93+
7694
it 'should include --storeconfigs and --storeconfigs_backend when storeconfigs is enabled' do
7795
testobj = OctocatalogDiff::CatalogUtil::Command.new(@default_opts.merge(storeconfigs: true))
7896
result = testobj.puppet_command
@@ -134,6 +152,18 @@
134152
expect(result).to match(/--facts_terminus=facter/)
135153
end
136154

155+
it 'should include config_version when Puppet version < 6' do
156+
testobj = OctocatalogDiff::CatalogUtil::Command.new(@default_opts.merge(puppet_version: '5.5.20'))
157+
result = testobj.puppet_command
158+
expect(result).to match(%r{--config_version="/bin/echo catalogscript"})
159+
end
160+
161+
it 'should not include config_version when Puppet version >= 6' do
162+
testobj = OctocatalogDiff::CatalogUtil::Command.new(@default_opts.merge(puppet_version: '6.18.0'))
163+
result = testobj.puppet_command
164+
expect(result).not_to match(/--config_version=/)
165+
end
166+
137167
it 'should raise error when invalid facts terminus is specified' do
138168
testobj = OctocatalogDiff::CatalogUtil::Command.new(@default_opts.merge(facts_terminus: 'chicken'))
139169
expect { testobj.puppet_command }.to raise_error(ArgumentError, /Unrecognized facts_terminus setting/)

spec/octocatalog-diff/tests/catalog/computed_spec.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@
7070
expect(@logger_str.string).to match(%r{Symlinked.*environments/production ->.*/repos/default})
7171
expect(@logger_str.string).to match(/Installed hiera.yaml from/)
7272
expect(@logger_str.string).to match(/Installed fact file at/)
73-
expect(@logger_str.string).to match(/puppet master --compile rspec-node.github.net/)
73+
if OctocatalogDiff::Spec.major_version >= 6
74+
expect(@logger_str.string).to match(/puppet catalog compile rspec-node.github.net/)
75+
else
76+
expect(@logger_str.string).to match(/puppet master --compile rspec-node.github.net/)
77+
end
7478
expect(@logger_str.string).to match(/Catalog succeeded on try 1/)
7579
end
7680
end
@@ -150,7 +154,11 @@
150154
it 'should have the correct log messages' do
151155
expect(@logger_str.string).to match(%r{Symlinked.*environments/production ->.*/repos/failing-catalog})
152156
expect(@logger_str.string).to match(/Installed fact file at/)
153-
expect(@logger_str.string).to match(/puppet master --compile rspec-node.github.net/)
157+
if OctocatalogDiff::Spec.major_version >= 6
158+
expect(@logger_str.string).to match(/puppet catalog compile rspec-node.github.net/)
159+
else
160+
expect(@logger_str.string).to match(/puppet master --compile rspec-node.github.net/)
161+
end
154162
expect(@logger_str.string).to match(/Catalog failed on try 1/)
155163
end
156164
end

spec/octocatalog-diff/tests/spec_helper.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ def self.mock_puppetdb_fact_response(hostname)
288288
facts_in['values'].keys.map { |k| { 'name' => k, 'value' => facts_in['values'][k] } }.to_json
289289
end
290290

291-
# Determine if puppet version is Puppet 5 or not
292-
def self.is_puppet5?
293-
puppet_version && puppet_version >= '5.0.0'
291+
# Helper functions to determine which major version of Puppet we are working with:
292+
def self.major_version
293+
puppet_version && puppet_version.split('.')[0].to_i
294294
end
295295
end
296296
end

0 commit comments

Comments
 (0)