Skip to content

Commit

Permalink
(PUP-10853) Remove legacy facts
Browse files Browse the repository at this point in the history
Replaces legacy facts with newer structured facts.
  • Loading branch information
cthorn42 committed Feb 3, 2023
1 parent f4fbaaa commit 82cef23
Show file tree
Hide file tree
Showing 136 changed files with 477 additions and 478 deletions.
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/language/binary_data_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,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 @@ -65,7 +65,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 @@ -45,7 +45,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 @@ -43,9 +43,9 @@
- "host"
- "roles"
- "profiles"
- "%{::operatingsystem}"
- "%{::osfamily}"
- "%{::kernel}"
- "%{facts.os.name}"
- "%{facts.os.family}"
- "%{facts.kernel}"
- "common"
:merge_behavior: deeper
:deep_merge_options:
Expand Down
2 changes: 1 addition & 1 deletion acceptance/tests/resource/service/service_enable_linux.rb
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
4 changes: 2 additions & 2 deletions acceptance/tests/ssl/certificate_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
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"
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
2 changes: 1 addition & 1 deletion acceptance/tests/windows/QA-506_windows_exit_codes_test.rb
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
34 changes: 17 additions & 17 deletions install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def do_man(man, strip = 'man/')
FileUtils.install(mf, omf, mode: 0644, preserve: true, verbose: true)
# Solaris does not support gzipped man pages. When called with
# --no-check-prereqs/without facter the default gzip behavior still applies
unless $operatingsystem == "Solaris"
unless $osname == "Solaris"
gzip = %x{which gzip}
gzip.chomp!
%x{#{gzip} -f #{omf}}
Expand Down Expand Up @@ -234,56 +234,56 @@ def prepare_installation
RbConfig::CONFIG['bindir'] = "/usr/bin"
end

# Here we only set $operatingsystem if we have opted to check for prereqs.
# Here we only set $osname if we have opted to check for prereqs.
# Otherwise facter won't be guaranteed to be present.
if InstallOptions.check_prereqs
check_prereqs
$operatingsystem = Facter.value :operatingsystem
$osname = Facter.value('os.name')
end

if not InstallOptions.configdir.nil?
configdir = InstallOptions.configdir
elsif $operatingsystem == "windows"
elsif $osname == "windows"
configdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "etc")
else
configdir = "/etc/puppetlabs/puppet"
end

if not InstallOptions.codedir.nil?
codedir = InstallOptions.codedir
elsif $operatingsystem == "windows"
elsif $osname == "windows"
codedir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "code")
else
codedir = "/etc/puppetlabs/code"
end

if not InstallOptions.vardir.nil?
vardir = InstallOptions.vardir
elsif $operatingsystem == "windows"
elsif $osname == "windows"
vardir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "cache")
else
vardir = "/opt/puppetlabs/puppet/cache"
end

if not InstallOptions.publicdir.nil?
publicdir = InstallOptions.publicdir
elsif $operatingsystem == "windows"
elsif $osname == "windows"
publicdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "public")
else
publicdir = "/opt/puppetlabs/puppet/public"
end

if not InstallOptions.rundir.nil?
rundir = InstallOptions.rundir
elsif $operatingsystem == "windows"
elsif $osname == "windows"
rundir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "run")
else
rundir = "/var/run/puppetlabs"
end

if not InstallOptions.logdir.nil?
logdir = InstallOptions.logdir
elsif $operatingsystem == "windows"
elsif $osname == "windows"
logdir = File.join(ENV['ALLUSERSPROFILE'], "PuppetLabs", "puppet", "var", "log")
else
logdir = "/var/log/puppetlabs/puppet"
Expand All @@ -298,7 +298,7 @@ def prepare_installation
if not InstallOptions.localedir.nil?
localedir = InstallOptions.localedir
else
if $operatingsystem == "windows"
if $osname == "windows"
localedir = File.join(ENV['PROGRAMFILES'], "Puppet Labs", "Puppet", "puppet", "share", "locale")
else
localedir = "/opt/puppetlabs/puppet/share/locale"
Expand Down Expand Up @@ -376,7 +376,7 @@ def prepare_installation
# by stripping the drive letter, but only if the basedir is not empty.
#
def join(basedir, dir)
return "#{basedir}#{dir[2..-1]}" if $operatingsystem == "windows" and basedir.length > 0 and dir.length > 2
return "#{basedir}#{dir[2..-1]}" if $osname == "windows" and basedir.length > 0 and dir.length > 2

"#{basedir}#{dir}"
end
Expand All @@ -398,7 +398,7 @@ def build_rdoc(files)

def build_ri(files)
return unless $haverdoc
return if $operatingsystem == "windows"
return if $osname == "windows"
begin
ri = RDoc::RDoc.new
#ri.document(["--ri-site", "--merge"] + files)
Expand Down Expand Up @@ -427,14 +427,14 @@ def install_binfile(from, op_file, target)

File.open(from) do |ip|
File.open(tmp_file.path, "w") do |op|
op.puts "#!#{ruby}" unless $operatingsystem == "windows"
op.puts "#!#{ruby}" unless $osname == "windows"
contents = ip.readlines
contents.shift if contents[0] =~ /^#!/
op.write contents.join
end
end

if $operatingsystem == "windows" && InstallOptions.batch_files
if $osname == "windows" && InstallOptions.batch_files
installed_wrapper = false

unless File.extname(from) =~ /\.(cmd|bat)/
Expand Down Expand Up @@ -484,16 +484,16 @@ def install_binfile(from, op_file, target)

prepare_installation

if $operatingsystem == "windows"
if $osname == "windows"
windows_bins = glob(%w{ext/windows/*bat})
end

#build_rdoc(rdoc) if InstallOptions.rdoc
#build_ri(ri) if InstallOptions.ri
do_configs(configs, InstallOptions.config_dir) if InstallOptions.configs
do_bins(bins, InstallOptions.bin_dir)
do_bins(windows_bins, InstallOptions.bin_dir, 'ext/windows/') if $operatingsystem == "windows" && InstallOptions.batch_files
do_bins(windows_bins, InstallOptions.bin_dir, 'ext/windows/') if $osname == "windows" && InstallOptions.batch_files
do_libs(libs)
do_locales(locales)
do_man(man) unless $operatingsystem == "windows"
do_man(man) unless $osname == "windows"
end
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" => Puppet.runtime[:facter].value("hostname"),
"h" => Puppet.runtime[:facter].value('networking.hostname'),
"H" => [
Puppet.runtime[:facter].value("hostname"),
Puppet.runtime[:facter].value("domain")
Puppet.runtime[:facter].value('networking.hostname'),
Puppet.runtime[:facter].value('networking.domain')
].join("."),
"d" => Puppet.runtime[:facter].value("domain")
"d" => Puppet.runtime[: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 @@ -429,9 +429,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 = Puppet.runtime[:facter].value(fact)
if !value.nil?
Expand All @@ -440,10 +440,10 @@ def set_server_facts
end

if @server_facts["servername"].nil?
host = Puppet.runtime[:facter].value(:hostname)
host = Puppet.runtime[:facter].value('networking.hostname')
if host.nil?
Puppet.warning _("Could not retrieve fact servername")
elsif domain = Puppet.runtime[:facter].value(:domain) #rubocop:disable Lint/AssignmentInCondition
elsif domain = Puppet.runtime[:facter].value('networking.domain') #rubocop:disable Lint/AssignmentInCondition
@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
2 changes: 1 addition & 1 deletion lib/puppet/provider/group/groupadd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

commands :add => "groupadd", :delete => "groupdel", :modify => "groupmod"

has_feature :system_groups unless %w{HP-UX Solaris}.include? Puppet.runtime[:facter].value(:operatingsystem)
has_feature :system_groups unless %w{HP-UX Solaris}.include? Puppet.runtime[:facter].value('os.name')

verify :gid, _("GID must be an integer") do |value|
value.is_a? Integer
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/group/pw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
commands :pw => "pw"
has_features :manages_members

defaultfor :operatingsystem => [:freebsd, :dragonfly]
confine :operatingsystem => [:freebsd, :dragonfly]
defaultfor 'os.name' => [:freebsd, :dragonfly]
confine 'os.name' => [:freebsd, :dragonfly]

options :members, :flag => "-M", :method => :mem

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/group/windows_adsi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
desc "Local group management for Windows. Group members can be both users and groups.
Additionally, local groups can contain domain users."

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

has_features :manages_members

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/nameservice/directoryservice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class << self
commands :dscl => "/usr/bin/dscl"
commands :dseditgroup => "/usr/sbin/dseditgroup"
commands :sw_vers => "/usr/bin/sw_vers"
confine :operatingsystem => :darwin
confine 'os.name' => :darwin
confine :feature => :cfpropertylist
defaultfor :operatingsystem => :darwin
defaultfor 'os.name' => :darwin

# There is no generalized mechanism for provider cache management, but we can
# use post_resource_eval, which will be run for each suitable provider at the
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/package/aix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
# AIX supports versionable packages with and without a NIM server
has_feature :versionable

confine :operatingsystem => [ :aix ]
defaultfor :operatingsystem => :aix
confine 'os.name' => [ :aix ]
defaultfor 'os.name' => :aix

attr_accessor :latest_info

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/appdmg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Puppet::Type.type(:package).provide(:appdmg, :parent => Puppet::Provider::Package) do
desc "Package management which copies application bundles to a target."

confine :operatingsystem => :darwin
confine 'os.name' => :darwin
confine :feature => :cfpropertylist

commands :hdiutil => "/usr/bin/hdiutil"
Expand Down
Loading

0 comments on commit 82cef23

Please sign in to comment.