Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
(FACT-231) Fix for tests/facts/validate_file_system_size_bytes.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Tanasoiu committed May 11, 2020
1 parent 91df292 commit ed0aa0b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/facts/linux/os/architecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Architecture
def call_the_resolver
fact_value = Facter::Resolvers::Uname.resolve(:machine)

fact_value = fact_value =~ /i[3456]86|pentium/ ? 'i386' : fact_value

[Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)]
end
end
Expand Down
35 changes: 35 additions & 0 deletions lib/facts/rhel/os/release.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module Facts
module Rhel
module Os
class Release
FACT_NAME = 'os.release'
ALIASES = %w[operatingsystemmajrelease operatingsystemrelease].freeze

def call_the_resolver
version = determine_release_version

return Facter::ResolvedFact.new(FACT_NAME, nil) unless version

[Facter::ResolvedFact.new(FACT_NAME, version),
Facter::ResolvedFact.new(ALIASES.first, version['major'], :legacy),
Facter::ResolvedFact.new(ALIASES.last, version['full'], :legacy)]
end

def determine_release_version
version = Facter::Resolvers::RedHatRelease.resolve(:version)

return unless version

versions = version.split('.')
fact_value = {}
fact_value['full'] = version
fact_value['major'] = versions[0]
fact_value['minor'] = versions[1].gsub(/^0([1-9])/, '\1') if versions[1]
fact_value
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/resolvers/aix/mountpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def read_mount(fact_name)
@fact_list[:mountpoints] = {}
output = Facter::Core::Execution.execute('mount', logger: log)
output.split("\n").map do |line|
next if line =~ /\snode\s|---|procfs|ahafs/
next if line =~ /node|---|procfs|ahafs/

elem = line.split("\s")

Expand Down
6 changes: 3 additions & 3 deletions lib/resolvers/mountpoints_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ def read_mounts # rubocop:disable Metrics/AbcSize
next if path =~ %r{^/(proc|sys)} && filesystem != 'tmpfs' || filesystem == 'autofs'

stats = FilesystemHelper.read_mountpoint_stats(path)
size_bytes = stats.bytes_total
available_bytes = stats.bytes_available
size_bytes = stats.bytes_total.abs
available_bytes = stats.bytes_available.abs

used_bytes = stats.bytes_used
used_bytes = stats.bytes_used.abs
total_bytes = used_bytes + available_bytes
capacity = FilesystemHelper.compute_capacity(used_bytes, total_bytes)

Expand Down
7 changes: 7 additions & 0 deletions lib/resolvers/processors_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def read_cpuinfo(fact_name)
read_processors(cpuinfo_output) # + model names

@fact_list[:physical_count] = @fact_list[:physical_processors].uniq.length
@fact_list[:physical_count] = search_in_system_devices if @fact_list[:physical_count].zero?
@fact_list[fact_name]
end

Expand All @@ -51,6 +52,12 @@ def construct_models_list(tokens)
def count_physical_processors(tokens)
@fact_list[:physical_processors] << tokens.last.strip.to_i if tokens.first.strip == 'physical id'
end

def search_in_system_devices
dirs = Dir.entries('/sys/devices/system/cpu').reject { |dir| dir =~ /\.+/ }

dirs.count { |dir| dir =~ /cpu[0-9]+$/ }
end
end
end
end
Expand Down

0 comments on commit ed0aa0b

Please sign in to comment.