Skip to content

Commit 09c9644

Browse files
authored
Fix use of legacy facts (#302)
* Fix use of legacy facts Fixes #301 * Add missing tests for uid_min fact
1 parent 0b1575c commit 09c9644

18 files changed

Lines changed: 125 additions & 75 deletions

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* Mon Dec 30 2024 Steven Pritchard <steve@sicura.us> - 4.14.0
2+
- Fix use of legacy facts (#301)
3+
14
* Mon Dec 23 2024 Steven Pritchard <steve@sicura.us> - 4.13.0
25
- Refactor and cleanup for rubocop
36

lib/facter/uid_min.rb

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,12 @@
66
confine { File.exist?('/etc/login.defs') }
77

88
setcode do
9-
uid_min = File.open('/etc/login.defs').grep(%r{UID_MIN})
9+
uid_min = File.read('/etc/login.defs')
10+
.lines(chomp: true)
11+
.find { |line| line.split.first == 'UID_MIN' }
12+
.to_s.split.last
1013

11-
# Grep returns an Array
12-
uid_min = '' if uid_min.empty?
13-
14-
unless uid_min.empty?
15-
uid_min = uid_min.first.to_s.chomp.split.last
16-
end
17-
18-
unless uid_min.empty?
19-
uid_min = if ['RedHat', 'CentOS', 'OracleLinux', 'Scientific'].include?(Facter.value(:operatingsystem)) &&
20-
Facter.value(:operatingsystemmajrelease) < '7'
21-
'500'
22-
else
23-
'1000'
24-
end
25-
end
14+
uid_min = '1000' if uid_min.nil? || uid_min.empty?
2615

2716
uid_min
2817
end

lib/puppet/functions/simplib/filtered.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
# data_hash: "yaml_data" # Use the built-in YAML backend.
1414
# hierarchy: # Each hierarchy consists of multiple levels
1515
# - name: "OSFamily"
16-
# path: "osfamily/%{facts.osfamily}.yaml"
16+
# path: "osfamily/%{facts.os.family}.yaml"
1717
# - name: "datamodules"
1818
# data_hash: simplib::filtered
1919
# datadir: "delegated-data"
2020
# paths:
21-
# - "%{facts.sitename}/osfamily/%{facts.osfamily}.yaml"
22-
# - "%{facts.sitename}/os/%{facts.operatingsystem}.yaml"
23-
# - "%{facts.sitename}/host/%{facts.fqdn}.yaml"
21+
# - "%{facts.sitename}/osfamily/%{facts.os.family}.yaml"
22+
# - "%{facts.sitename}/os/%{facts.os.name}.yaml"
23+
# - "%{facts.sitename}/host/%{facts.networking.fqdn}.yaml"
2424
# - "%{facts.sitename}/common.yaml"
2525
# options:
2626
# function: yaml_data

lib/puppet/functions/simplib/host_is_me.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def hostlist_contains_me(hosts)
2828
scope = closure_scope
2929

3030
host_identifiers = [
31-
scope['facts']['fqdn'],
32-
scope['facts']['hostname'],
31+
scope['facts']['networking']['fqdn'],
32+
scope['facts']['networking']['hostname'],
3333
'localhost',
3434
'localhost.localdomain',
3535
]

lib/puppet/functions/simplib/ip_to_cron.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#
3030
# @param ip
3131
# The IP address to use as the basis for the generated values.
32-
# When `nil`, the 'ipaddress' fact (IPv4) is used.
32+
# When `nil`, the 'networking.ip' fact (IPv4) is used.
3333
#
3434
# @return [Array[Integer]] Array of integers suitable for use in the
3535
# ``minute`` or ``hour`` cron field.
@@ -53,7 +53,7 @@
5353
def ip_to_cron(occurs = 1, max_value = 59, algorithm = 'ip_mod', ip = nil)
5454
if ip.nil?
5555
scope = closure_scope
56-
ipaddr = scope['facts']['ipaddress']
56+
ipaddr = scope['facts']['networking']['ip']
5757
else
5858
ipaddr = ip.dup
5959
end

lib/puppet/functions/simplib/ipaddresses.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,10 @@
1313
def ipaddresses(only_remote = false)
1414
retval = []
1515
scope = closure_scope
16-
interfaces = scope['facts']['interfaces']
16+
interfaces = scope['facts'].dig('networking', 'interfaces')
1717

18-
if interfaces
19-
interfaces.split(',').each do |iface|
20-
iface_addr = scope['facts']["ipaddress_#{iface}"]
21-
22-
retval << iface_addr unless iface_addr.nil? || iface_addr.strip.empty?
23-
end
18+
if interfaces.is_a?(Hash) && !interfaces.empty?
19+
retval = interfaces.select { |_, v| v['ip'].is_a?(String) && !v['ip'].empty? }.map { |_, v| v['ip'] }
2420

2521
retval.delete_if { |x| x =~ %r{^127} } if only_remote
2622
end

lib/puppet/functions/simplib/join_mount_opts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def join_mount_opts(system_mount_opts, new_mount_opts)
3434

3535
mount_options = {}
3636
scope = closure_scope
37-
selinux_current_mode = scope['facts']['selinux_current_mode']
37+
selinux_current_mode = scope['facts']['os'].dig('selinux', 'current_mode')
3838

3939
if !selinux_current_mode || (selinux_current_mode == 'disabled')
4040
# SELinux is off, get rid of selinux related items in the options

lib/puppet/functions/simplib/validate_sysctl_value.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ def fs__inotify__max_user_watches(key, value)
4444
validate_sysctl_err("#{key} cannot be #{value}")
4545
end
4646

47-
system_ram_mb = closure_scope['facts']['memorysize_mb']
48-
49-
return unless system_ram_mb
50-
system_ram_mb = system_ram_mb.to_i
47+
system_ram_mb = closure_scope['facts'].dig('memory', 'system', 'total_bytes').to_i >> 20
5148

5249
size_multiplier = 512
53-
size_multiplier = 1024 if closure_scope['facts']['architecture'] == 'x86_64'
50+
size_multiplier = 1024 if closure_scope['facts'].dig('os', 'architecture') == 'x86_64'
5451

5552
inode_ram_mb = (value.to_i * size_multiplier) / 1024 / 1024
5653

lib/puppet/provider/reboot_notify/notify.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def self.post_resource_eval
124124
# If the number of seconds between the time that the record was written
125125
# and the current time is greater than the system uptime then we should
126126
# remove the record
127-
(current_time - v['updated']) > Facter.value(:uptime_seconds)
127+
(current_time - v['updated']) > Facter.value(:system_uptime)['seconds']
128128
end
129129

130130
unless records.empty?

metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "simp-simplib",
3-
"version": "4.13.0",
3+
"version": "4.14.0",
44
"author": "SIMP Team",
55
"summary": "A collection of common SIMP functions, facts, and types",
66
"license": "Apache-2.0",

0 commit comments

Comments
 (0)