Skip to content

Commit

Permalink
Merge pull request #2594 from mhashizume/FACT-3187/main/statvfs
Browse files Browse the repository at this point in the history
(FACT-3187) Rescue Solaris mountpoint errors
  • Loading branch information
AriaXLi authored Jul 24, 2023
2 parents a346b73 + 5abc69f commit 0ca9786
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions lib/facter/resolvers/solaris/mountpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,52 @@ def read_mounts(fact_name) # rubocop:disable Metrics/MethodLength

next if fs.mount_type == 'autofs'

mounts = {}
device = fs.name
filesystem = fs.mount_type
path = fs.mount_point
options = fs.options.split(',').map(&:strip)

stats = Facter::Util::Resolvers::FilesystemHelper.read_mountpoint_stats(path)
size_bytes = stats.bytes_total.abs
available_bytes = stats.bytes_available.abs

used_bytes = stats.bytes_used.abs
total_bytes = used_bytes + available_bytes
capacity = Facter::Util::Resolvers::FilesystemHelper.compute_capacity(used_bytes, total_bytes)

size = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(size_bytes)
available = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(available_bytes)
used = Facter::Util::Facts::UnitConverter.bytes_to_human_readable(used_bytes)
mounts = read_stats(path).tap do |hash|
hash[:device] = device
hash[:filesystem] = filesystem
hash[:path] = path
hash[:options] = options if options.any?
end

@mounts << Hash[Facter::Util::Resolvers::FilesystemHelper::MOUNT_KEYS
.zip(Facter::Util::Resolvers::FilesystemHelper::MOUNT_KEYS
.map { |v| binding.local_variable_get(v) })]
.map { |v| mounts[v] })]
end

exclude_auto_home_mounts!

@fact_list[:mountpoints] = @mounts
@fact_list[fact_name]
end

def read_stats(path)
begin
stats = Facter::Util::Resolvers::FilesystemHelper.read_mountpoint_stats(path)
size_bytes = stats.bytes_total.abs
available_bytes = stats.bytes_available.abs
used_bytes = stats.bytes_used.abs
total_bytes = used_bytes + available_bytes
rescue Sys::Filesystem::Error
size_bytes = used_bytes = available_bytes = 0
end

{
size_bytes: size_bytes,
available_bytes: available_bytes,
used_bytes: used_bytes,
total_bytes: total_bytes,
capacity: Facter::Util::Resolvers::FilesystemHelper.compute_capacity(used_bytes, total_bytes),
size: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(size_bytes),
available: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(available_bytes),
used: Facter::Util::Facts::UnitConverter.bytes_to_human_readable(used_bytes)
}
end
end
end
end
Expand Down

0 comments on commit 0ca9786

Please sign in to comment.