Skip to content

Commit 7f96b47

Browse files
authored
Merge pull request #8990 from mhashizume/PUP-11621/main/drop-hiera-3
(PUP-11621) Hiera 3 deprecation
2 parents 7bc3c5d + 9adac7f commit 7f96b47

File tree

10 files changed

+47
-62
lines changed

10 files changed

+47
-62
lines changed

.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Gem::Specification.new do |s|
3232
s.summary = "Puppet, an automated configuration management tool"
3333
s.specification_version = 3
3434
s.add_runtime_dependency(%q<facter>, [">= 2.4.0", "< 5"])
35-
s.add_runtime_dependency(%q<hiera>, [">= 3.2.1", "< 4"])
3635
s.add_runtime_dependency(%q<semantic_puppet>, "~> 1.0")
3736
s.add_runtime_dependency(%q<fast_gettext>, ">= 2.1", "< 3")
3837
s.add_runtime_dependency(%q<locale>, "~> 2.1")

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ end
1414

1515
# override .gemspec deps - may issue warning depending on Bundler version
1616
gem "facter", :git => 'https://github.com/puppetlabs/facter'
17-
gem "hiera", *location_for(ENV['HIERA_LOCATION']) if ENV.has_key?('HIERA_LOCATION')
1817
gem "semantic_puppet", *location_for(ENV['SEMANTIC_PUPPET_LOCATION'] || ["~> 1.0"])
1918
gem "puppet-resource_api", *location_for(ENV['RESOURCE_API_LOCATION'] || ["~> 1.5"])
2019

2120
group(:features) do
2221
gem 'diff-lcs', '~> 1.3', require: false
22+
gem "hiera", *location_for(ENV['HIERA_LOCATION']) if ENV.has_key?('HIERA_LOCATION')
2323
gem 'hiera-eyaml', *location_for(ENV['HIERA_EYAML_LOCATION'])
2424
gem 'hocon', '~> 1.0', require: false
2525
# requires native libshadow headers/libs

ext/project_data.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ gem_required_ruby_version: '>= 2.5.0'
1919
gem_required_rubygems_version: '> 1.3.1'
2020
gem_runtime_dependencies:
2121
facter: ['> 2.0.1', '< 5']
22-
hiera: ['>= 3.2.1', '< 4']
2322
semantic_puppet: '~> 1.0'
2423
fast_gettext: ['>= 1.1', '< 3']
2524
locale: '~> 2.1'

install.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
$haverdoc = false
4545
end
4646

47-
PREREQS = %w{openssl facter cgi hiera}
47+
PREREQS = %w{openssl facter cgi}
4848
MIN_FACTER_VERSION = 1.5
4949

5050
InstallOptions = OpenStruct.new

lib/hiera_puppet.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'hiera'
1+
Puppet.features.hiera?
22
require 'hiera/scope'
33
require_relative 'puppet'
44

lib/puppet/pops/lookup/hiera_config.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,9 @@ def name
282282
end
283283

284284
def create_hiera3_backend_provider(name, backend, parent_data_provider, datadir, paths, hiera3_config)
285-
# Custom backend. Hiera v3 must be installed, it's logger configured, and it must be made aware of the loaded config
286-
require 'hiera'
285+
# Custom backend. Hiera 3 must be installed, its logger configured, and it must be made aware of the loaded config
286+
raise Puppet::DataBinding::LookupError, 'Hiera 3 is not installed' if !Puppet.features.hiera?
287+
287288
if Hiera::Config.instance_variable_defined?(:@config) && (current_config = Hiera::Config.instance_variable_get(:@config)).is_a?(Hash)
288289
current_config.each_pair do |key, val|
289290
case key

spec/unit/functions/hiera_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def func(*args, &block)
161161
with_scope { |scope| the_func.call(scope, *args, &block) }
162162
end
163163

164-
context 'hiera' do
164+
context 'hiera', :if => Puppet.features.hiera? do
165165
it 'should require a key argument' do
166166
expect { func([]) }.to raise_error(ArgumentError)
167167
end
@@ -195,7 +195,7 @@ def func(*args, &block)
195195
expect(func('datasources', nil, 'the_override')).to eql(['the_override', 'first', 'second'])
196196
end
197197

198-
it 'a hiera v3 scope is used' do
198+
it 'a hiera v3 scope is used', :if => Puppet.features.hiera? do
199199
expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['-- testing --', '-- mod::foo --', '-- mod/foo --', '-- mod --', '-- mod --'])
200200
class testing () {
201201
notice(hiera('class_name'))
@@ -266,7 +266,7 @@ class testing () {
266266
end
267267
end
268268

269-
context 'hiera_array' do
269+
context 'hiera_array', :if => Puppet.features.hiera? do
270270
let(:the_func) { Puppet.lookup(:loaders).puppet_system_loader.load(:function, 'hiera_array') }
271271

272272
it 'should require a key argument' do
@@ -299,7 +299,7 @@ class testing () {
299299
end
300300
end
301301

302-
context 'hiera_hash' do
302+
context 'hiera_hash', :if => Puppet.features.hiera? do
303303
let(:the_func) { Puppet.lookup(:loaders).puppet_system_loader.load(:function, 'hiera_hash') }
304304

305305
it 'should require a key argument' do
@@ -336,7 +336,7 @@ class testing () {
336336
end
337337
end
338338

339-
context 'hiera_include' do
339+
context 'hiera_include', :if => Puppet.features.hiera? do
340340
let(:the_func) { Puppet.lookup(:loaders).puppet_system_loader.load(:function, 'hiera_include') }
341341

342342
it 'should require a key argument' do
@@ -365,7 +365,7 @@ class testing () {
365365
end
366366
end
367367

368-
context 'with custom backend and merge_behavior declared in hiera.yaml' do
368+
context 'with custom backend and merge_behavior declared in hiera.yaml', :if => Puppet.features.hiera? do
369369
let(:merge_behavior) { 'deeper' }
370370

371371
let(:hiera_yaml) do
@@ -468,7 +468,7 @@ class testing () {
468468
end
469469
end
470470

471-
context 'hiera_array' do
471+
context 'hiera_array', :if => Puppet.features.hiera? do
472472
let(:the_func) { Puppet.lookup(:loaders).puppet_system_loader.load(:function, 'hiera_array') }
473473

474474
it 'declared merge_behavior is ignored' do

spec/unit/functions/lookup_spec.rb

Lines changed: 26 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'puppet_spec/files'
44
require 'puppet/pops'
55
require 'deep_merge/core'
6-
require 'hiera'
76

87
describe "The lookup function" do
98
include PuppetSpec::Compiler
@@ -1652,7 +1651,7 @@ def uri_test_func(options, context)
16521651
end
16531652
end
16541653

1655-
context 'version 3' do
1654+
context 'version 3', :if => Puppet.features.hiera? do
16561655
it 'finds data in in global layer and reports deprecation warnings for hiera.yaml' do
16571656
expect(lookup('a')).to eql('value a (from global)')
16581657
expect(warnings).to include(/Use of 'hiera.yaml' version 3 is deprecated. It should be converted to version 5/)
@@ -1697,6 +1696,14 @@ def uri_test_func(options, context)
16971696
expect(lookup('datasources')).to eql(['common', 'example.com'])
16981697
end
16991698

1699+
it 'backend specific options are propagated to custom backend' do
1700+
expect(lookup('other_option')).to eql('value of other_option')
1701+
end
1702+
1703+
it 'dotted keys are passed down to custom backend' do
1704+
expect(lookup('dotted.key')).to eql('custom backend received request for dotted.key value')
1705+
end
1706+
17001707
it 'delegates configured hocon backend to hocon_data function' do
17011708
expect(explain('xs')).to match(/Hierarchy entry "hocon"\n.*\n.*\n.*"common"\n\s*Found key: "xs"/m)
17021709
end
@@ -1705,6 +1712,18 @@ def uri_test_func(options, context)
17051712
expect(lookup('xs.subkey')).to eql('value xs.subkey (from global hocon)')
17061713
end
17071714

1715+
it 'multiple hiera3_backend declarations can be used and are merged into the generated config' do
1716+
expect(lookup(['datasources', 'other_option'])).to eql([['common', 'example.com'], 'value of other_option'])
1717+
expect(Hiera::Config.instance_variable_get(:@config)).to eql(
1718+
{
1719+
:backends => ['custom', 'other'],
1720+
:hierarchy => ['common', '%{domain}'],
1721+
:custom => { :datadir => "#{code_dir}/hieradata" },
1722+
:other => { :other_option => 'value of other_option', :datadir=>"#{code_dir}/hieradata" },
1723+
:logger => 'puppet'
1724+
})
1725+
end
1726+
17081727
context 'with a module data provider' do
17091728
let(:module_files) do
17101729
{
@@ -2041,18 +2060,6 @@ def uri_test_func(options, context)
20412060
paths:
20422061
- common.conf
20432062
- "%{domain}.conf"
2044-
- name: Custom
2045-
hiera3_backend: custom
2046-
paths:
2047-
- common.custom
2048-
- "%{domain}.custom"
2049-
- name: Other
2050-
hiera3_backend: other
2051-
options:
2052-
other_option: value of other_option
2053-
paths:
2054-
- common.other
2055-
- "%{domain}.other"
20562063
YAML
20572064
end
20582065

@@ -2067,7 +2074,6 @@ def uri_test_func(options, context)
20672074
expect(explanation).to include('Hierarchy entry "Yaml"')
20682075
expect(explanation).to include('Hierarchy entry "Json"')
20692076
expect(explanation).to include('Hierarchy entry "Hocon"')
2070-
expect(explanation).to include('Hierarchy entry "Custom"')
20712077
expect(explanation).to include('Found key: "a" value: "value a (from global)"')
20722078
end
20732079

@@ -2079,35 +2085,10 @@ def uri_test_func(options, context)
20792085
'caa' => 'value hash_c.hash_ca.caa (from environment)',
20802086
'cab' => 'value hash_c.hash_ca.cab (from global)',
20812087
'cac' => 'value hash_c.hash_ca.cac (from global json)',
2082-
'cad' => 'value hash_c.hash_ca.cad (from global custom)'
20832088
}
20842089
})
20852090
end
20862091

2087-
it 'backend data sources are propagated to custom backend' do
2088-
expect(lookup('datasources')).to eql(['common', 'example.com'])
2089-
end
2090-
2091-
it 'backend specific options are propagated to custom backend' do
2092-
expect(lookup('other_option')).to eql('value of other_option')
2093-
end
2094-
2095-
it 'dotted keys are passed down to custom backend' do
2096-
expect(lookup('dotted.key')).to eql('custom backend received request for dotted.key value')
2097-
end
2098-
2099-
it 'multiple hiera3_backend declarations can be used and are merged into the generated config' do
2100-
expect(lookup(['datasources', 'other_option'])).to eql([['common', 'example.com'], 'value of other_option'])
2101-
expect(Hiera::Config.instance_variable_get(:@config)).to eql(
2102-
{
2103-
:backends => ['custom', 'other'],
2104-
:hierarchy => ['common', '%{domain}'],
2105-
:custom => { :datadir => "#{code_dir}/hieradata" },
2106-
:other => { :other_option => 'value of other_option', :datadir=>"#{code_dir}/hieradata" },
2107-
:logger => 'puppet'
2108-
})
2109-
end
2110-
21112092
it 'provides a sensible error message when the hocon library is not loaded' do
21122093
allow(Puppet.features).to receive(:hocon?).and_return(false)
21132094

@@ -2156,7 +2137,7 @@ def uri_test_func(options, context)
21562137
end
21572138
end
21582139

2159-
context 'and eyaml_lookup_key function' do
2140+
context 'and eyaml_lookup_key function', :if => Puppet.features.hiera_eyaml? do
21602141
let(:hiera_yaml) { <<-YAML.unindent }
21612142
version: 5
21622143
hierarchy:
@@ -2171,7 +2152,7 @@ def uri_test_func(options, context)
21712152
end
21722153
end
21732154

2174-
context 'with a hiera3_backend that has no paths' do
2155+
context 'with a hiera3_backend that has no paths', :if => Puppet.features.hiera? do
21752156
let(:hiera_yaml) do
21762157
<<-YAML.unindent
21772158
---
@@ -2215,7 +2196,7 @@ def uri_test_func(options, context)
22152196
expect { lookup('mod_a::b') }.to raise_error(Puppet::DataBinding::LookupError, /did not find a value for the name 'mod_a::b'/)
22162197
end
22172198

2218-
context 'with a Hiera v3 configuration' do
2199+
context 'with a Hiera v3 configuration', :if => Puppet.features.hiera? do
22192200
let(:mod_a_files) do
22202201
{
22212202
'mod_a' => {
@@ -2992,7 +2973,7 @@ def ruby_dig(segments, options, context)
29922973
end
29932974
end
29942975

2995-
context 'and an eyaml lookup_key function' do
2976+
context 'and an eyaml lookup_key function', :if => Puppet.features.hiera_eyaml? do
29962977
let(:private_key_name) { 'private_key.pkcs7.pem' }
29972978
let(:public_key_name) { 'public_key.pkcs7.pem' }
29982979

@@ -3294,7 +3275,7 @@ def ruby_dig(segments, options, context)
32943275
expect(lookup('array_a')).to eql(['array_a[0]', 'array_a[1]'])
32953276
end
32963277

3297-
context 'declared in global scope as a Hiera v3 backend' do
3278+
context 'declared in global scope as a Hiera v3 backend', :if => Puppet.features.hiera? do
32983279
let(:environment_files) { {} }
32993280
let(:data_file_content) { <<-YAML.unindent }
33003281
a: >

spec/unit/hiera_puppet_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'hiera_puppet'
33
require 'puppet_spec/scope'
44

5-
describe 'HieraPuppet' do
5+
describe 'HieraPuppet', :if => Puppet.features.hiera? do
66
include PuppetSpec::Scope
77

88
after(:all) do

spec/unit/indirector/hiera_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
require 'spec_helper'
22
require 'puppet/data_binding'
33
require 'puppet/indirector/hiera'
4-
require 'hiera/backend'
54

6-
describe Puppet::Indirector::Hiera do
5+
begin
6+
require 'hiera/backend'
7+
rescue LoadError => e
8+
Puppet.warning(_("Unable to load Hiera 3 backend: %{message}") % {message: e.message})
9+
end
10+
11+
describe Puppet::Indirector::Hiera, :if => Puppet.features.hiera? do
712

813
module Testing
914
module DataBinding

0 commit comments

Comments
 (0)