Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet/data_binding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Puppet::DataBinding
# Set up indirection, so that data can be looked for in the compiler
extend Puppet::Indirector

indirects(:data_binding, :terminus_setting => :data_binding_terminus,
indirects(:data_binding, :terminus_class => :hiera,
:doc => "Where to find external data bindings.")

class LookupError < Puppet::PreformattedError; end
Expand Down
36 changes: 0 additions & 36 deletions lib/puppet/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -541,28 +541,6 @@ def self.initialize_default_settings!(settings)
:desc => "How to store cached nodes.
Valid values are (none), 'json', 'msgpack', or 'yaml'.",
},
:data_binding_terminus => {
:type => :terminus,
:default => "hiera",
:desc =>
"This setting has been deprecated. Use of any value other than 'hiera' should instead be configured
in a version 5 hiera.yaml. Until this setting is removed, it controls which data binding terminus
to use for global automatic data binding (across all environments). By default this value is 'hiera'.
A value of 'none' turns off the global binding.",
:call_hook => :on_initialize_and_write,
:hook => proc do |value|
if Puppet[:strict] != :off
s_val = value.to_s # because sometimes the value is a symbol
unless s_val == 'hiera' || s_val == 'none' || value == '' || value.nil?
#TRANSLATORS 'data_binding_terminus' is a setting and should not be translated
message = _("Setting 'data_binding_terminus' is deprecated.")
#TRANSLATORS 'hiera' should not be translated
message += ' ' + _("Convert custom terminus to hiera 5 API.")
Puppet.deprecation_warning(message)
end
end
end
},
:hiera_config => {
:default => lambda do
config = nil
Expand Down Expand Up @@ -741,20 +719,6 @@ def self.initialize_default_settings!(settings)
[administrative API](https://puppet.com/docs/puppetserver/latest/admin-api/v1/environment-cache.html).
"
},
:environment_data_provider => {
:desc => "The name of a registered environment data provider used when obtaining environment
specific data. The three built in and registered providers are 'none' (no data), 'function' (data
obtained by calling the function 'environment::data()') and 'hiera' (data obtained using a data
provider configured using a hiera.yaml file in root of the environment).
Other environment data providers may be registered in modules on the module path. For such
custom data providers see the respective module documentation. This setting is deprecated.",
:hook => proc { |value|
unless value.nil? || Puppet[:strict] == :off
#TRANSLATORS 'environment_data_provider' is a setting and should not be translated
Puppet.deprecation_warning(_("Setting 'environment_data_provider' is deprecated."))
end
}
},
:prerun_command => {
:default => "",
:desc => "A command to run before every agent run. If this command returns a non-zero
Expand Down
52 changes: 5 additions & 47 deletions lib/puppet/pops/lookup/lookup_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ def convert_result(key, lookup_options, lookup_invocation, the_lookup)
end

def lookup_global(key, lookup_invocation, merge_strategy)
# hiera_xxx will always use global_provider regardless of data_binding_terminus setting
terminus = lookup_invocation.hiera_xxx_call? ? :hiera : Puppet[:data_binding_terminus]
terminus = :hiera
case terminus
when :hiera, 'hiera'
provider = global_provider(lookup_invocation)
Expand Down Expand Up @@ -468,55 +467,14 @@ def initialize_env_provider(lookup_invocation)
env_conf = environment.configuration
return nil if env_conf.nil? || env_conf.path_to_env.nil?

# Get the name of the data provider from the environment's configuration
provider_name = env_conf.environment_data_provider
env_path = Pathname(env_conf.path_to_env)
config_path = env_path + HieraConfig::CONFIG_FILE_NAME

ep = nil
if config_path.exist?
ep = EnvironmentDataProvider.new
# A version 5 hiera.yaml trumps any data provider setting in the environment.conf
ep_config = ep.config(lookup_invocation)
if ep_config.nil?
ep = nil
elsif ep_config.version >= 5
unless provider_name.nil? || Puppet[:strict] == :off
Puppet.warn_once('deprecations', 'environment.conf#data_provider',
_("Defining environment_data_provider='%{provider_name}' in environment.conf is deprecated") % { provider_name: provider_name }, env_path + 'environment.conf')

unless provider_name == 'hiera'
Puppet.warn_once('deprecations', 'environment.conf#data_provider_overridden',
_("The environment_data_provider='%{provider_name}' setting is ignored since '%{config_path}' version >= 5") % { provider_name: provider_name, config_path: config_path }, env_path + 'environment.conf')
end
end
provider_name = nil
end
end

if provider_name.nil?
ep
else
unless Puppet[:strict] == :off
msg = _("Defining environment_data_provider='%{provider_name}' in environment.conf is deprecated.") % { provider_name: provider_name }
msg += " " + _("A '%{hiera_config}' file should be used instead") % { hiera_config: HieraConfig::CONFIG_FILE_NAME } if ep.nil?
Puppet.warn_once('deprecations', 'environment.conf#data_provider', msg, env_path + 'environment.conf')
end
return nil unless config_path.exist?

case provider_name
when 'none'
nil
when 'hiera'
# Use hiera.yaml or default settings if it is missing
ep || EnvironmentDataProvider.new
when 'function'
ep = EnvironmentDataProvider.new
ep.config = HieraConfigV5.v4_function_config(env_path, 'environment::data', ep)
ep
else
raise Puppet::Error, _("Environment '%{env}', cannot find environment_data_provider '%{provider}'") % { env: environment.name, provider: provider_name }
end
end
ep = EnvironmentDataProvider.new
ep_config = ep.config(lookup_invocation)
ep_config.nil? ? nil : ep
end

# @return [Puppet::Node::Environment] the environment of the compiler that this adapter is associated with
Expand Down
14 changes: 3 additions & 11 deletions lib/puppet/settings/environment_conf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# @api private
class Puppet::Settings::EnvironmentConf
ENVIRONMENT_CONF_ONLY_SETTINGS = [:modulepath, :manifest, :config_version].freeze
VALID_SETTINGS = (ENVIRONMENT_CONF_ONLY_SETTINGS + [:environment_timeout, :environment_data_provider, :static_catalogs, :rich_data]).freeze
VALID_SETTINGS = (ENVIRONMENT_CONF_ONLY_SETTINGS + [:environment_timeout, :static_catalogs, :rich_data]).freeze

# Given a path to a directory environment, attempts to load and parse an
# environment.conf in ini format, and return an EnvironmentConf instance.
Expand Down Expand Up @@ -41,7 +41,7 @@ def self.load_from(path_to_env, global_module_path)
# without interpolation. This is a special case for the default configured
# environment returned by the Puppet::Environments::StaticPrivate loader.
def self.static_for(environment, environment_timeout = 0, static_catalogs = false, rich_data = false)
Static.new(environment, environment_timeout, static_catalogs, nil, rich_data)
Static.new(environment, environment_timeout, static_catalogs, rich_data)
end

attr_reader :section, :path_to_env, :global_modulepath
Expand Down Expand Up @@ -91,12 +91,6 @@ def environment_timeout
end
end

def environment_data_provider
get_setting(:environment_data_provider, Puppet.settings.value(:environment_data_provider)) do |value|
value
end
end

def modulepath
default_modulepath = [File.join(@path_to_env, "modules")] + @global_module_path
get_setting(:modulepath, default_modulepath) do |modulepath|
Expand Down Expand Up @@ -197,15 +191,13 @@ def absolute(path)
# @api private
class Static
attr_reader :environment_timeout
attr_reader :environment_data_provider
attr_reader :rich_data
attr_reader :static_catalogs

def initialize(environment, environment_timeout, static_catalogs, environment_data_provider = nil, rich_data = false)
def initialize(environment, environment_timeout, static_catalogs, rich_data = false)
@environment = environment
@environment_timeout = environment_timeout
@static_catalogs = static_catalogs
@environment_data_provider = environment_data_provider
@rich_data = rich_data
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
environment_data_provider = 'hiera'
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
version: 5
hierarchy:
- name: "Common"
path: "common.yaml"
defaults:
data_hash: yaml_data
datadir: data
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
environment_data_provider = 'function'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
version: 5
hierarchy:
- name: "Environment data function"
v4_data_hash: environment::data
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Use the 'sample' env data provider (in this fixture)
environment_data_provider=hiera
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Use the 'sample' env data provider (in this fixture)
environment_data_provider=hiera
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Use the 'sample' env data provider (in this fixture)
environment_data_provider=hiera
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
version: 5
hierarchy:
- name: "Common"
path: "common.yaml"
defaults:
data_hash: yaml_data
datadir: data
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Use the 'sample' env data provider (in this fixture)
environment_data_provider=hiera
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Use the 'sample' env data provider (in this fixture)
environment_data_provider=hiera
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
version: 5
hierarchy:
- name: "Common"
path: "common.yaml"
defaults:
data_hash: yaml_data
datadir: data
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Use the 'sample' env data provider (in this fixture)
environment_data_provider=hiera
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
# Use the 'sample' env data provider (in this fixture)
environment_data_provider=hiera
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
environment_timeout = 0
environment_data_provider = 'function'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
version: 5
hierarchy:
- name: "Environment data function"
v4_data_hash: environment::data
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
environment_timeout = 0
environment_data_provider = 'function'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
version: 5
hierarchy:
- name: "Environment data function"
v4_data_hash: environment::data
3 changes: 1 addition & 2 deletions spec/integration/data_binding_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@

before do
# Drop all occurances of cached hiera instances. This will reset @hiera in Puppet::Indirector::Hiera, Testing::DataBinding::Hiera,
# and Puppet::DataBinding::Hiera. Different classes are active as indirection depending on configuration
# and Puppet::DataBinding::Hiera.
ObjectSpace.each_object(Class).select {|klass| klass <= Puppet::Indirector::Hiera }.each { |klass| klass.instance_variable_set(:@hiera, nil) }
Puppet[:data_binding_terminus] = 'hiera'
Puppet[:modulepath] = dir
end

Expand Down
22 changes: 0 additions & 22 deletions spec/integration/defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,28 +247,6 @@
end
end

describe "when configuring the data_binding terminus" do
it "should have a data_binding_terminus setting" do
expect(Puppet.settings[:data_binding_terminus]).not_to be_nil
end

it "should be set to hiera by default" do
expect(Puppet.settings[:data_binding_terminus]).to eq(:hiera)
end

it "to be neither 'hiera' nor 'none', a deprecation warning is logged" do
expect(@logs).to eql([])
Puppet[:data_binding_terminus] = 'magic'
expect(@logs[0].to_s).to match(/Setting 'data_binding_terminus' is deprecated/)
end

it "to not log a warning if set to 'none' or 'hiera'" do
expect(@logs).to eql([])
Puppet[:data_binding_terminus] = 'none'
Puppet[:data_binding_terminus] = 'hiera'
expect(@logs).to eql([])
end
end

describe "agent_catalog_run_lockfile" do
it "(#2888) is not a file setting so it is absent from the Settings catalog" do
Expand Down
4 changes: 0 additions & 4 deletions spec/shared_behaviours/hiera_indirections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ def request(key)
test_klass.instance_variable_set(:@hiera, nil)
end

it "should be the default data_binding terminus" do
expect(Puppet.settings[:data_binding_terminus]).to eq(:hiera)
end

it "should raise an error if we don't have the hiera feature" do
expect(Puppet.features).to receive(:hiera?).and_return(false)
expect { test_klass.new }.to raise_error RuntimeError,
Expand Down
Loading