Skip to content

(PUP-10853) Remove usage of legacy facts #8492

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 25, 2021
Merged
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 .gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]
s.summary = "Puppet, an automated configuration management tool"
s.specification_version = 3
s.add_runtime_dependency(%q<facter>, [">= 2.4.0", "< 5"])
s.add_runtime_dependency(%q<facter>, [">= 4.0.0", "< 5"])
s.add_runtime_dependency(%q<hiera>, [">= 3.2.1", "< 4"])
s.add_runtime_dependency(%q<semantic_puppet>, "~> 1.0")
s.add_runtime_dependency(%q<fast_gettext>, "~> 1.1")
Expand Down
2 changes: 1 addition & 1 deletion acceptance/lib/puppet/acceptance/agent_fqdn_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module AgentFqdnUtils
# convert from an Beaker::Host (agent) to the systems fqdn as returned by facter
def agent_to_fqdn(agent)
unless @@hostname_to_fqdn.has_key?(agent.hostname)
@@hostname_to_fqdn[agent.hostname] = on(agent, facter('fqdn')).stdout.chomp
@@hostname_to_fqdn[agent.hostname] = on(agent, facter('networking.fqdn')).stdout.chomp
end
@@hostname_to_fqdn[agent.hostname]
end
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/aix/nim_package_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
version = on(aix, 'puppet --version').stdout
version &&
Gem::Version.new(version) > Gem::Version.new('6.4.0') &&
on(aix, 'facter operatingsystemrelease').stdout == '7.2'
on(aix, 'facter os.release.full').stdout == '7.2'
end

teardown do
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/catalog_with_binary_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
manifest = <<-MANIFEST
class #{test_num}(
) {
\$test_path = \$::fqdn ? #{agent_tmp_dirs}
\$test_path = \$facts['networking']['fqdn'] ? #{agent_tmp_dirs}
file { '#{test_num}':
path => "\$test_path/#{test_num}",
content => file('#{test_num}/binary_data'),
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/direct_puppet/supports_utf8.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$::fqdn ? #{tmp_file}
\$test_path = \$facts['networking']['fqdn'] ? #{tmp_file}
file { \$test_path:
content => @(UTF8)
#{file_contents}
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/language/binary_data_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
:assertions => { :assert_match => 'Notice: A:\\xF0\\x9F\\x91\\x92' } },
{ :type => 'notify', :parameters => { :namevar => "B:${type($bin_file)}" }, :pre_code => '$bin_file=binary_file("empty/blah.txt")',
:assertions => { :assert_match => 'Notice: B:Binary' } },
{ :type => 'file', :parameters => { :namevar => "$pup_tmp_filename", :content => "$relaxed" }, :pre_code => "$pup_tmp_filename = if $osfamily == 'windows' { '#{tmp_filename_win}' } else { '#{tmp_filename_else}' }",
{ :type => 'file', :parameters => { :namevar => "$pup_tmp_filename", :content => "$relaxed" }, :pre_code => "$pup_tmp_filename = if $facts['os']['family'] == 'windows' { '#{tmp_filename_win}' } else { '#{tmp_filename_else}' }",
:assertions => { :assert_match => /#{base64_relaxed}/ } },
]

Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/language/sensitive_data_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
{:type => 'notify', :parameters => {:namevar => "C:meh", :message => '"C:${$mehC.unwrap |$unwrapped| { "blk_${unwrapped}_blk" } } nonblk_${mehC}_nonblk"'}, :pre_code => '$mehC=Sensitive.new("sekritC")',
:assertions => {:assert_match => ["C:blk_sekritC_blk", "nonblk_#{notify_redacted}_nonblk"]}},
# for --show_diff
{:type => 'file', :parameters => {:namevar => "$pup_tmp_filename", :content => "Sensitive.new('sekritD')"}, :pre_code => "$pup_tmp_filename = if $osfamily == 'windows' { '#{tmp_filename_win}' } else { '#{tmp_filename_else}' }",
{:type => 'file', :parameters => {:namevar => "$pup_tmp_filename", :content => "Sensitive.new('sekritD')"}, :pre_code => "$pup_tmp_filename = if $facts['os']['family'] == 'windows' { '#{tmp_filename_win}' } else { '#{tmp_filename_else}' }",
:assertions => [{:refute_match => 'sekritD'}, {:assert_match => /#{tmp_environment}\.txt..content. #{file_redacted}/}]},

]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def empty_execution_log_file(host, path)
custom_type = <<-END
Puppet::Type.newtype(:type_tst) do
newparam(:name, :namevar => true) do
fqdn = Facter.value(:fqdn)
fqdn = Facter.value('networking.fqdn')
if fqdn == '#{agent_to_fqdn(master)}'
File.open("#{execution_log[agent_to_fqdn(master)]}", 'a+') { |f| f.puts("found_type_tst: " + Time.now.to_s) }
end
Expand Down
6 changes: 3 additions & 3 deletions acceptance/tests/lookup/merge_strategies.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
- "host"
- "roles"
- "profiles"
- "%{::operatingsystem}"
- "%{::osfamily}"
- "%{::kernel}"
- "%{facts.os.name}"
- "%{facts.os.family}"
- "%{facts.kernel}"
- "common"
:merge_behavior: deeper
:deep_merge_options:
Expand Down
16 changes: 8 additions & 8 deletions acceptance/tests/parser_functions/hiera_in_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def create_environment(osfamilies, tmp_dirs)
\\$msgs = hiera_array('message')
notify {\\$msgs:}
class {'#{@module_name}':
result_dir => hiera('result_dir')[\\$::hostname],
result_dir => hiera('result_dir')[\\$facts['networking']['hostname']],
}
}
",
Expand Down Expand Up @@ -188,7 +188,7 @@ class #{@module_name} (
file { "#{moduledir}/manifests/mod_default.pp":
content => "
class #{@module_name}::mod_default {
\\$result_dir = hiera('result_dir')[\\$::hostname]
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_default invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_default\\\":
ensure => 'file',
Expand All @@ -202,7 +202,7 @@ class #{@module_name}::mod_default {
file { "#{moduledir}/manifests/mod_osfamily.pp":
content => "
class #{@module_name}::mod_osfamily {
\\$result_dir = hiera('result_dir')[\\$::hostname]
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_osfamily invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_osfamily\\\":
ensure => 'file',
Expand All @@ -216,7 +216,7 @@ class #{@module_name}::mod_osfamily {
file { "#{moduledir}/manifests/mod_production.pp":
content => "
class #{@module_name}::mod_production {
\\$result_dir = hiera('result_dir')[\\$::hostname]
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_production invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_production\\\":
ensure => 'file',
Expand All @@ -230,7 +230,7 @@ class #{@module_name}::mod_production {
file { "#{moduledir}/manifests/mod_fqdn.pp":
content => "
class #{@module_name}::mod_fqdn {
\\$result_dir = hiera('result_dir')[\\$::hostname]
\\$result_dir = hiera('result_dir')[\\$facts['networking']['hostname']]
notify{\\"module mod_fqdn invoked.\\\\n\\":}
file {\\\"\\\${result_dir}/mod_fqdn\\\":
ensure => 'file',
Expand Down Expand Up @@ -271,7 +271,7 @@ class #{@module_name}::mod_fqdn {
def find_osfamilies
family_hash = {}
agents.each do |agent|
res = on(agent, facter("osfamily"))
res = on(agent, facter('os.family'))
osf = res.stdout.chomp
family_hash[osf] = 1
end
Expand All @@ -282,7 +282,7 @@ def find_tmp_dirs
tmp_dirs = ""
host_to_result_dir = {}
agents.each do |agent|
h = on(agent, facter("hostname")).stdout.chomp
h = on(agent, facter('networking.hostname')).stdout.chomp
t = agent.tmpdir("#{@module_name}_results")
tmp_dirs += " #{h}: '#{t}'\n"
host_to_result_dir[h] = t
Expand All @@ -304,7 +304,7 @@ def find_tmp_dirs
env_manifest = create_environment(find_osfamilies, tmp_dirs)
apply_manifest_on(master, env_manifest, :catch_failures => true)
agents.each do |agent|
resultdir = host_to_result_dir[on(agent, facter("hostname")).stdout.chomp]
resultdir = host_to_result_dir[on(agent, facter('networking.hostname')).stdout.chomp]
step "Applying catalog to agent: #{agent}. result files in #{resultdir}"
on(
agent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$::fqdn ? #{tmp_file}
\$test_path = \$facts['networking']['fqdn'] ? #{tmp_file}
file { \$test_path:
content => @(UTF8)
#{file_contents}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
file { '#{environmentpath}/#{tmp_environment}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$::fqdn ? #{tmp_file}
\$test_path = \$facts['networking']['fqdn'] ? #{tmp_file}
file { \$test_path:
content => @(UTF8)
#{file_contents}
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/reports/corrective_change_via_puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def create_manifest_for_file_resource(file_resource, file_contents, environment_
file { '#{environmentpath}/#{environment_name}/manifests/site.pp':
ensure => file,
content => '
\$test_path = \$::fqdn ? #{file_resource}
\$test_path = \$facts['networking']['fqdn'] ? #{file_resource}
file { \$test_path:
content => @(UTF8)
#{file_contents}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

step 'create a site.pp on master containing a unicode file resource' do
site_pp_contents = <<-SITE_PP
\$test_path = \$::fqdn ? #{agent_tmp_dirs}
\$test_path = \$facts['networking']['fqdn'] ? #{agent_tmp_dirs}
file { "\$test_path/\uff72\uff67\u30d5\u30eb":
ensure => present,
source => "puppet:///modules/utf8_file_module/\u9759\u7684",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
agents.each do |agent|
platform = agent.platform.variant
osname = on(agent, facter('os.name')).stdout.chomp
majrelease = on(agent, facter('operatingsystemmajrelease')).stdout.chomp.to_i
majrelease = on(agent, facter('os.release.major')).stdout.chomp.to_i

init_script_systemd = "/usr/lib/systemd/system/#{package_name[platform]}.service"
symlink_systemd = "/etc/systemd/system/multi-user.target.wants/#{package_name[platform]}.service"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
package { '#{package_name[platform]}':
ensure => present,
}
if ($::operatingsystem == 'Fedora') and ($::operatingsystemmajrelease == '23') {
if ($os['name'] == 'Fedora') and ($os['release']['major'] == '23') {
package{'libnghttp2':
ensure => latest,
install_options => '--best',
Expand Down
16 changes: 8 additions & 8 deletions acceptance/tests/ssl/certificate_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,29 @@
initialize_temp_dirs

agent_certnames = []
hostname = master.execute('facter hostname')
fqdn = master.execute('facter fqdn')
hostname = master.execute('facter networking.hostname')
fqdn = master.execute('facter networking.fqdn')

teardown do
step "Cleanup the test agent certs"
master_config = {
server_config = {
'main' => { 'server' => fqdn },
'master' => { 'dns_alt_names' => "puppet,#{hostname},#{fqdn}" }
'server' => { 'dns_alt_names' => "puppet,#{hostname},#{fqdn}" }
}

with_puppet_running_on(master, master_config) do
with_puppet_running_on(master, server_config) do
on(master,
"puppetserver ca clean --certname #{agent_certnames.join(',')}",
:acceptable_exit_codes => [0,24])
end
end

environments_dir = get_test_file_path(master, "environments")
master_config = {
server_config = {
'main' => {
'environmentpath' => environments_dir,
},
'master' => {
'server' => {
'autosign' => true,
'dns_alt_names' => "puppet,#{hostname},#{fqdn}",
}
Expand Down Expand Up @@ -74,7 +74,7 @@
}
MANIFEST

with_puppet_running_on(master, master_config) do
with_puppet_running_on(master, server_config) do
agents.each do |agent|
next if agent == master

Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/ticket_15560_managehome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

deleteable_profile = true

version = on(host, facter('operatingsystemrelease')).stdout.chomp
version = on(host, facter('os.release.full')).stdout.chomp
if version =~ /^5\.[012]|2003/
homedir = "C:/Documents and Settings/#{username}"
deleteable_profile = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
native_modules_path = on(agent, puppet("config print #{module_path_config_property}")).stdout.gsub('C:', '/cygdrive/c').strip

#Check to see if we are running on Windows 2003. Do a crazy hack to get around SCP issues.
if (on(agent, facter("find operatingsystemmajrelease")).stdout =~ /2003/)
if (on(agent, facter("os.release.major")).stdout =~ /2003/)
on(agent, "ln -s #{native_modules_path.gsub(/ /, '\ ')} /tmp/puppet_etc")
modules_path = '/tmp/puppet_etc'
else
Expand Down
2 changes: 1 addition & 1 deletion ext/project_data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ gem_forge_project: 'puppet'
gem_required_ruby_version: '>= 2.5.0'
gem_required_rubygems_version: '> 1.3.1'
gem_runtime_dependencies:
facter: ['> 2.0.1', '< 5']
facter: ['>= 4.0.0', '< 5']
hiera: ['>= 3.2.1', '< 4']
semantic_puppet: '~> 1.0'
fast_gettext: '~> 1.1'
Expand Down
4 changes: 2 additions & 2 deletions install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
end

PREREQS = %w{openssl facter cgi hiera}
MIN_FACTER_VERSION = 1.5
MIN_FACTER_VERSION = 4.0

InstallOptions = OpenStruct.new

Expand Down Expand Up @@ -242,7 +242,7 @@ def prepare_installation
# Otherwise facter won't be guaranteed to be present.
if InstallOptions.check_prereqs
check_prereqs
$operatingsystem = Facter.value :operatingsystem
$operatingsystem = Facter.value('os.name')
end

if not InstallOptions.configdir.nil?
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/confiner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Puppet::Confiner
# * `:any` => an array of expressions that will be ORed together
#
# @example
# confine :operatingsystem => [:redhat, :fedora]
# confine 'os.name' => [:redhat, :fedora]
# confine :true { ... }
#
# @param hash [Hash<{Symbol => Object}>] hash of confines
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/file_serving/mount/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
class Puppet::FileServing::Mount::File < Puppet::FileServing::Mount
def self.localmap
@localmap ||= {
"h" => Facter.value("hostname"),
"h" => Facter.value('networking.hostname'),
"H" => [
Facter.value("hostname"),
Facter.value("domain")
Facter.value('networking.hostname'),
Facter.value('networking.domain')
].join("."),
"d" => Facter.value("domain")
"d" => Facter.value('networking.domain')
}
end

Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/indirector/catalog/compiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,9 @@ def set_server_facts
@server_facts["serverversion"] = Puppet.version.to_s

# And then add the server name and IP
{"servername" => "fqdn",
"serverip" => "ipaddress",
"serverip6" => "ipaddress6"
{"servername" => "networking.fqdn",
"serverip" => "networking.ip",
"serverip6" => "networking.ip6"
}.each do |var, fact|
value = Facter.value(fact)
if !value.nil?
Expand All @@ -421,10 +421,10 @@ def set_server_facts
end

if @server_facts["servername"].nil?
host = Facter.value(:hostname)
host = Facter.value('networking.hostname')
if host.nil?
Puppet.warning _("Could not retrieve fact servername")
elsif domain = Facter.value(:domain) #rubocop:disable Lint/AssignmentInCondition
elsif (domain = Facter.value('networking.domain'))
@server_facts["servername"] = [host, domain].join(".")
else
@server_facts["servername"] = host
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/exec/windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

Puppet::Type.type(:exec).provide :windows, :parent => Puppet::Provider::Exec do

confine :operatingsystem => :windows
defaultfor :operatingsystem => :windows
confine 'os.name' => :windows
defaultfor 'os.name' => :windows

desc <<-'EOT'
Execute external binaries on Windows systems. As with the `posix`
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/file/windows.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Puppet::Type.type(:file).provide :windows do
desc "Uses Microsoft Windows functionality to manage file ownership and permissions."

confine :operatingsystem => :windows
confine 'os.name' => :windows
has_feature :manages_symlinks if Puppet.features.manages_symlinks?

include Puppet::Util::Warnings
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/group/aix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
desc "Group management for AIX."

# This will the default provider for this platform
defaultfor :operatingsystem => :aix
confine :operatingsystem => :aix
defaultfor 'os.name' => :aix
confine 'os.name' => :aix

# Commands that manage the element
commands :list => "/usr/sbin/lsgroup"
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/group/directoryservice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"

commands :dscl => "/usr/bin/dscl"
confine :operatingsystem => :darwin
defaultfor :operatingsystem => :darwin
confine 'os.name' => :darwin
defaultfor 'os.name' => :darwin
has_feature :manages_members

def members_insync?(current, should)
Expand Down
Loading