facter 4.0.13 → 4.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.rubocop_todo.yml +322 -38
  4. data/VERSION +1 -1
  5. data/lib/custom_facts/core/aggregate.rb +2 -2
  6. data/lib/custom_facts/core/execution.rb +2 -2
  7. data/lib/custom_facts/core/execution/base.rb +27 -13
  8. data/lib/custom_facts/core/execution/posix.rb +2 -2
  9. data/lib/custom_facts/core/execution/windows.rb +9 -2
  10. data/lib/custom_facts/core/legacy_facter.rb +3 -3
  11. data/lib/custom_facts/util/collection.rb +3 -3
  12. data/lib/custom_facts/util/fact.rb +2 -2
  13. data/lib/custom_facts/util/resolution.rb +2 -2
  14. data/lib/facter.rb +9 -6
  15. data/lib/facts/aix/mountpoints.rb +15 -0
  16. data/lib/facts/debian/os/distro/release.rb +17 -8
  17. data/lib/facts/debian/os/name.rb +1 -1
  18. data/lib/facts/debian/os/release.rb +14 -2
  19. data/lib/facts/debian/partitions.rb +26 -0
  20. data/lib/facts/el/partitions.rb +26 -0
  21. data/lib/facts/sles/partitions.rb +26 -0
  22. data/lib/facts/solaris/solaris_zones/zone.rb +2 -0
  23. data/lib/framework/core/fact_loaders/internal_fact_loader.rb +11 -7
  24. data/lib/framework/core/{cache_manager.rb → session_cache.rb} +1 -1
  25. data/lib/framework/detector/os_detector.rb +2 -0
  26. data/lib/framework/logging/logger.rb +1 -10
  27. data/lib/resolvers/aix/mountpoints.rb +69 -0
  28. data/lib/resolvers/base_resolver.rb +1 -1
  29. data/lib/resolvers/{debian_version_resolver.rb → debian_version.rb} +4 -6
  30. data/lib/resolvers/partitions.rb +101 -0
  31. data/lib/resolvers/solaris/solaris_zone_name.rb +2 -0
  32. data/lib/resolvers/solaris/zone_resolver.rb +2 -0
  33. data/lib/util/api_debugger.rb +43 -0
  34. metadata +11 -5
  35. data/lib/util/fact.rb +0 -14
@@ -21,6 +21,8 @@ module Facts
21
21
  zones = {}
22
22
 
23
23
  results = Facter::Resolvers::SolarisZone.resolve(:zone)
24
+ return Facter::ResolvedFact.new(FACT_NAME, nil) unless results
25
+
24
26
  results&.each do |result|
25
27
  zones.merge!(parse_result(result))
26
28
  resolved_facts << create_legacy_zone_facts(result)
@@ -16,13 +16,13 @@ module Facter
16
16
  @facts = []
17
17
 
18
18
  os_descendents = OsDetector.instance.hierarchy
19
- load_all_oses(os_descendents)
19
+ load_all_oses_in_descending_order(os_descendents)
20
20
  end
21
21
 
22
22
  private
23
23
 
24
- def load_all_oses(os_descendents)
25
- os_descendents.each do |os|
24
+ def load_all_oses_in_descending_order(os_descendents)
25
+ os_descendents.reverse_each do |os|
26
26
  load_for_os(os)
27
27
  end
28
28
  end
@@ -34,15 +34,19 @@ module Facter
34
34
  classes.each do |class_name|
35
35
  fact_name = class_name::FACT_NAME
36
36
 
37
- load_fact(fact_name, class_name)
37
+ # if fact is already loaded, skip it
38
+ next if @facts.any? { |fact| fact.name == fact_name }
39
+
40
+ type = fact_name.end_with?('.*') ? :legacy : :core
41
+ load_fact(fact_name, class_name, type)
38
42
  next unless class_name.const_defined?('ALIASES')
39
43
 
40
- [*class_name::ALIASES].each { |fact_alias| load_fact(fact_alias, class_name) }
44
+ [*class_name::ALIASES].each { |fact_alias| load_fact(fact_alias, class_name, :legacy) }
41
45
  end
42
46
  end
43
47
 
44
- def load_fact(fact_name, klass)
45
- loaded_fact = LoadedFact.new(fact_name, klass)
48
+ def load_fact(fact_name, klass, type)
49
+ loaded_fact = LoadedFact.new(fact_name, klass, type)
46
50
  @facts << loaded_fact
47
51
  end
48
52
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- class CacheManager
4
+ class SessionCache
5
5
  @semaphore = Mutex.new
6
6
  @resolvers = []
7
7
 
@@ -54,6 +54,8 @@ class OsDetector
54
54
  %w[Debian]
55
55
  when :elementary
56
56
  %w[Debian]
57
+ when :raspbian
58
+ %w[Debian]
57
59
  when :fedora
58
60
  %w[El]
59
61
  when :amzn
@@ -6,9 +6,8 @@ module Facter
6
6
  RED = 31
7
7
 
8
8
  class Log
9
- @@file_logger = Logger.new(File.new("#{ROOT_DIR}/example.log", 'a'))
10
9
  @@legacy_logger = nil
11
- @@logger = MultiLogger.new([@@file_logger])
10
+ @@logger = MultiLogger.new([])
12
11
  @@logger.level = :warn
13
12
  @@message_callback = nil
14
13
  @@has_errors = false
@@ -33,7 +32,6 @@ module Facter
33
32
 
34
33
  def initialize(logged_class)
35
34
  determine_callers_name(logged_class)
36
- set_format_for_file_logger
37
35
  end
38
36
 
39
37
  def self.add_legacy_logger(output)
@@ -57,13 +55,6 @@ module Facter
57
55
  end
58
56
  end
59
57
 
60
- def set_format_for_file_logger
61
- @@file_logger.formatter = proc do |severity, datetime, _progname, msg|
62
- datetime = datetime.strftime(@datetime_format || '%Y-%m-%d %H:%M:%S.%6N ')
63
- "[#{datetime}] #{severity} #{msg} \n"
64
- end
65
- end
66
-
67
58
  def self.set_format_for_legacy_logger
68
59
  @@legacy_logger.formatter = proc do |severity, datetime, _progname, msg|
69
60
  datetime = datetime.strftime(@datetime_format || '%Y-%m-%d %H:%M:%S.%6N ')
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ module Aix
6
+ class Mountpoints < BaseResolver
7
+ @semaphore = Mutex.new
8
+ @fact_list ||= {}
9
+ BLOCK_SIZE = 512
10
+
11
+ class << self
12
+ private
13
+
14
+ def post_resolve(fact_name)
15
+ @fact_list.fetch(fact_name) { read_mount(fact_name) }
16
+ end
17
+
18
+ def read_mount(fact_name)
19
+ @fact_list[:mountpoints] = {}
20
+ output, _status = Open3.capture2('mount 2>/dev/null')
21
+ output.split("\n").map do |line|
22
+ next if line =~ /\snode\s|---|procfs|ahafs/
23
+
24
+ elem = line.split("\s")
25
+
26
+ @fact_list[:mountpoints][elem[1]] = { device: elem[0], filesystem: elem[2],
27
+ options: elem.last.split(',') }
28
+ end
29
+
30
+ retrieve_sizes_for_mounts
31
+ @fact_list[fact_name]
32
+ end
33
+
34
+ def retrieve_sizes_for_mounts
35
+ output, _status = Open3.capture2('df -P 2>/dev/null')
36
+ output.split("\n").map do |line|
37
+ next if line =~ /Filesystem|-\s+-\s+-/
38
+
39
+ mount_info = line.split("\s")
40
+ mount_info[3] = translate_to_bytes(mount_info[3])
41
+ mount_info[2] = translate_to_bytes(mount_info[2])
42
+ mount_info[1] = translate_to_bytes(mount_info[1])
43
+ compute_sizes(mount_info)
44
+ end
45
+ end
46
+
47
+ def translate_to_bytes(strin_size)
48
+ strin_size.to_i * BLOCK_SIZE
49
+ end
50
+
51
+ def compute_sizes(info)
52
+ available_bytes = info[3]
53
+ used_bytes = info[2]
54
+ size_bytes = info[1]
55
+ @fact_list[:mountpoints][info.last].merge!(
56
+ capacity: FilesystemHelper.compute_capacity(used_bytes, size_bytes),
57
+ available_bytes: available_bytes,
58
+ used_bytes: used_bytes,
59
+ size_bytes: size_bytes,
60
+ available: BytesToHumanReadable.convert(available_bytes),
61
+ used: BytesToHumanReadable.convert(used_bytes),
62
+ size: BytesToHumanReadable.convert(size_bytes)
63
+ )
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -12,7 +12,7 @@ module Facter
12
12
  end
13
13
 
14
14
  def self.subscribe_to_manager
15
- Facter::CacheManager.subscribe(self)
15
+ Facter::SessionCache.subscribe(self)
16
16
  end
17
17
 
18
18
  def self.resolve(fact_name)
@@ -18,13 +18,11 @@ module Facter
18
18
  end
19
19
 
20
20
  def read_debian_version(fact_name)
21
- output, _status = Open3.capture2('cat /etc/debian_version')
22
- full_version = output.delete("\n")
23
- versions = full_version.split('.')
21
+ return unless File.readable?('/etc/debian_version')
24
22
 
25
- @fact_list[:full] = full_version
26
- @fact_list[:major] = versions[0]
27
- @fact_list[:minor] = versions[1].gsub(/^0([1-9])/, '\1')
23
+ verion = File.read('/etc/debian_version')
24
+
25
+ @fact_list[:version] = verion.strip
28
26
 
29
27
  @fact_list[fact_name]
30
28
  end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Facter
4
+ module Resolvers
5
+ class Partitions < BaseResolver
6
+ @semaphore = Mutex.new
7
+ @fact_list ||= {}
8
+ BLOCK_PATH = '/sys/block'
9
+
10
+ class << self
11
+ private
12
+
13
+ def post_resolve(fact_name)
14
+ @fact_list.fetch(fact_name) { read_partitions(fact_name) }
15
+ end
16
+
17
+ def read_partitions(fact_name)
18
+ @fact_list[:partitions] = {}
19
+ return {} unless File.readable?(BLOCK_PATH)
20
+
21
+ block_devices = Dir.entries(BLOCK_PATH).reject { |dir| dir =~ /^\.+/ }
22
+ block_devices.each do |block_device|
23
+ block_path = "#{BLOCK_PATH}/#{block_device}"
24
+ if File.directory?("#{block_path}/device")
25
+ extract_from_device(block_path)
26
+ elsif File.directory?("#{block_path}/dm")
27
+ extract_from_dm(block_path)
28
+ elsif File.directory?("#{block_path}/loop")
29
+ extract_from_loop(block_path)
30
+ end
31
+ end
32
+ @fact_list[fact_name]
33
+ end
34
+
35
+ def extract_from_device(block_path)
36
+ subdirs = browse_subdirectories(block_path)
37
+ subdirs.each do |subdir|
38
+ name = "/dev/#{subdir.split('/').last}"
39
+ populate_partitions(name, subdir)
40
+ end
41
+ end
42
+
43
+ def extract_from_dm(block_path)
44
+ map_name = File.readable?("#{block_path}/dm/name") ? File.read("#{block_path}/dm/name").chomp : ''
45
+ if map_name.empty?
46
+ populate_partitions("/dev/#{block_path}", block_path)
47
+ else
48
+ populate_partitions("/dev/mapper/#{map_name}", block_path)
49
+ end
50
+ end
51
+
52
+ def extract_from_loop(block_path)
53
+ populate_partitions("/dev/#{block_path}", block_path) if File.readable?("#{block_path}/loop/backing_file")
54
+ backing_file = File.read("#{block_path}/loop/backing_file").chomp
55
+ populate_partitions("/dev/#{block_path}", block_path, backing_file)
56
+ end
57
+
58
+ def populate_partitions(partition_name, block_path, backing_file = nil)
59
+ @fact_list[:partitions][partition_name] = {}
60
+ size_bytes = File.readable?("#{block_path}/size") ? File.read("#{block_path}/size").chomp.to_i * 512 : 0
61
+ info_hash = { size_bytes: size_bytes,
62
+ size: Facter::BytesToHumanReadable.convert(size_bytes), backing_file: backing_file }
63
+ info_hash.merge!(populate_from_blkid(partition_name))
64
+ @fact_list[:partitions][partition_name] = info_hash.reject { |_key, value| value.nil? }
65
+ end
66
+
67
+ def populate_from_blkid(partition_name)
68
+ return {} unless blkid_command?
69
+
70
+ @blkid_content ||= execute_and_extract_blkid_info
71
+ return {} unless @blkid_content[partition_name]
72
+
73
+ filesys = @blkid_content[partition_name]['TYPE']
74
+ uuid = @blkid_content[partition_name]['UUID']
75
+ label = @blkid_content[partition_name]['LABEL']
76
+ part_uuid = @blkid_content[partition_name]['PARTUUID']
77
+ part_label = @blkid_content[partition_name]['PARTLABEL']
78
+ { filesystem: filesys, uuid: uuid, label: label, partuuid: part_uuid, partlabel: part_label }
79
+ end
80
+
81
+ def blkid_command?
82
+ return @blkid_exists unless @blkid_exists.nil?
83
+
84
+ stdout, _stderr, _status = Open3.capture3('which blkid')
85
+ @blkid_exists = stdout && !stdout.empty?
86
+ end
87
+
88
+ def execute_and_extract_blkid_info
89
+ stdout, _stderr, _status = Open3.capture3('blkid')
90
+ output_hash = Hash[*stdout.split(/^([^:]+):/)[1..-1]]
91
+ output_hash.each { |key, value| output_hash[key] = Hash[*value.delete('"').chomp.split(/ ([^= ]+)=/)[1..-1]] }
92
+ end
93
+
94
+ def browse_subdirectories(path)
95
+ dirs = Dir[File.join(path, '**', '*')].select { |p| File.directory? p }
96
+ dirs.select { |subdir| subdir.split('/').last.include?(path.split('/').last) }.reject(&:nil?)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -14,6 +14,8 @@ module Facter
14
14
  end
15
15
 
16
16
  def build_current_zone_name_fact(fact_name)
17
+ return unless File.executable?('/bin/zonename')
18
+
17
19
  zone_name_output, status = Open3.capture2('/bin/zonename')
18
20
  unless status.to_s.include?('exit 0')
19
21
  @log.debug("Command #{command} returned status: #{status}")
@@ -14,6 +14,8 @@ module Facter
14
14
  end
15
15
 
16
16
  def build_zone_fact(fact_name)
17
+ return unless File.executable?('/usr/sbin/zoneadm')
18
+
17
19
  command = '/usr/sbin/zoneadm list -cp'
18
20
  zone_adm_output, status = Open3.capture2(command)
19
21
  unless status.to_s.include?('exit 0')
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApiDebugger
4
+ def self.prepended(receiver) # rubocop:disable Metrics/AbcSize
5
+ exclude, print_caller = parse_options(ENV['API_DEBUG'])
6
+
7
+ receiver_methods = receiver.instance_methods - Object.methods
8
+ receiver_methods.each do |meth|
9
+ ApiDebugger.class_eval do
10
+ define_method(meth) do |*args|
11
+ method_call = super(*args)
12
+
13
+ unless exclude.include?(meth)
14
+ puts '#' * 80
15
+ puts "Method call: #{meth}"
16
+ puts "Called with: #{args.inspect}"
17
+ if print_caller.include?(meth)
18
+ puts '-' * 80
19
+ puts caller
20
+ end
21
+ puts '#' * 80
22
+ end
23
+ method_call
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def self.parse_options(options)
30
+ exclude = []
31
+ print_caller = []
32
+
33
+ options.split(',').each do |option|
34
+ if option.start_with?('-')
35
+ exclude << option[1..-1].to_sym
36
+ elsif option.start_with?('+')
37
+ print_caller << option[1..-1].to_sym
38
+ end
39
+ end
40
+
41
+ [exclude, print_caller]
42
+ end
43
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.13
4
+ version: 4.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-25 00:00:00.000000000 Z
11
+ date: 2020-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -260,6 +260,7 @@ files:
260
260
  - lib/facts/aix/kernelrelease.rb
261
261
  - lib/facts/aix/kernelversion.rb
262
262
  - lib/facts/aix/load_averages.rb
263
+ - lib/facts/aix/mountpoints.rb
263
264
  - lib/facts/aix/networking/domain.rb
264
265
  - lib/facts/aix/networking/fqdn.rb
265
266
  - lib/facts/aix/networking/hostname.rb
@@ -348,6 +349,7 @@ files:
348
349
  - lib/facts/debian/os/selinux/enabled.rb
349
350
  - lib/facts/debian/os/selinux/enforced.rb
350
351
  - lib/facts/debian/os/selinux/policy_version.rb
352
+ - lib/facts/debian/partitions.rb
351
353
  - lib/facts/debian/path.rb
352
354
  - lib/facts/debian/processors/count.rb
353
355
  - lib/facts/debian/processors/isa.rb
@@ -429,6 +431,7 @@ files:
429
431
  - lib/facts/el/os/selinux/enabled.rb
430
432
  - lib/facts/el/os/selinux/enforced.rb
431
433
  - lib/facts/el/os/selinux/policy_version.rb
434
+ - lib/facts/el/partitions.rb
432
435
  - lib/facts/el/path.rb
433
436
  - lib/facts/el/processor.rb
434
437
  - lib/facts/el/processors/count.rb
@@ -597,6 +600,7 @@ files:
597
600
  - lib/facts/sles/os/selinux/enabled.rb
598
601
  - lib/facts/sles/os/selinux/enforced.rb
599
602
  - lib/facts/sles/os/selinux/policy_version.rb
603
+ - lib/facts/sles/partitions.rb
600
604
  - lib/facts/sles/path.rb
601
605
  - lib/facts/sles/processor.rb
602
606
  - lib/facts/sles/processors/count.rb
@@ -739,7 +743,6 @@ files:
739
743
  - lib/framework/cli/cli_launcher.rb
740
744
  - lib/framework/config/block_list.rb
741
745
  - lib/framework/config/config_reader.rb
742
- - lib/framework/core/cache_manager.rb
743
746
  - lib/framework/core/fact/external/external_fact_manager.rb
744
747
  - lib/framework/core/fact/internal/core_fact.rb
745
748
  - lib/framework/core/fact/internal/internal_fact_manager.rb
@@ -758,6 +761,7 @@ files:
758
761
  - lib/framework/core/options/options_validator.rb
759
762
  - lib/framework/core/options/priority_options.rb
760
763
  - lib/framework/core/options/validate_options.rb
764
+ - lib/framework/core/session_cache.rb
761
765
  - lib/framework/detector/os_detector.rb
762
766
  - lib/framework/formatters/formatter_factory.rb
763
767
  - lib/framework/formatters/formatter_helper.rb
@@ -779,12 +783,13 @@ files:
779
783
  - lib/resolvers/aix/filesystem_resolver.rb
780
784
  - lib/resolvers/aix/hardware_resolver.rb
781
785
  - lib/resolvers/aix/load_averages_resolver.rb
786
+ - lib/resolvers/aix/mountpoints.rb
782
787
  - lib/resolvers/aix/networking_resolver.rb
783
788
  - lib/resolvers/aix/os_level_resolver.rb
784
789
  - lib/resolvers/aix/utils/odm_query.rb
785
790
  - lib/resolvers/augeas_resolver.rb
786
791
  - lib/resolvers/base_resolver.rb
787
- - lib/resolvers/debian_version_resolver.rb
792
+ - lib/resolvers/debian_version.rb
788
793
  - lib/resolvers/disk_resolver.rb
789
794
  - lib/resolvers/dmi_resolver.rb
790
795
  - lib/resolvers/eos_release_resolver.rb
@@ -810,6 +815,7 @@ files:
810
815
  - lib/resolvers/networking_linux_resolver.rb
811
816
  - lib/resolvers/os_level_resolver.rb
812
817
  - lib/resolvers/os_release_resolver.rb
818
+ - lib/resolvers/partitions.rb
813
819
  - lib/resolvers/path_resolver.rb
814
820
  - lib/resolvers/processors_resolver.rb
815
821
  - lib/resolvers/puppet_version_resolver.rb
@@ -861,7 +867,7 @@ files:
861
867
  - lib/resolvers/windows/virtualization_resolver.rb
862
868
  - lib/resolvers/windows/win_os_description_resolver.rb
863
869
  - lib/resolvers/wpar_resolver.rb
864
- - lib/util/fact.rb
870
+ - lib/util/api_debugger.rb
865
871
  - tasks/create_fact.rake
866
872
  - tasks/fact_generator/fact.erb
867
873
  - tasks/fact_generator/fact_creator.rb