facter 4.0.41 → 4.0.42

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c21fc41638fbbab14ccb415eec2104ed296236c98d7870a341c37742796c8fc1
4
- data.tar.gz: 7b09bdc7ecc99e1947d9eb5bcacb7873f3b954224904d0930ee69846c47d5e88
3
+ metadata.gz: ffa55de7f92a74b84788507b7e9667f158edc68abef1412f40ab5d3beb8f6aad
4
+ data.tar.gz: e92ff5798a9abab30f1887c5e4f934d75cef67975b2485e53ba6dc58b59ee899
5
5
  SHA512:
6
- metadata.gz: 327664693c0725ab4aafc339e6091557dc00d2dee945a9f6d6f3bca5d3a6d1ab8b56809c5d9b7374029fcd277a8bc5107ff76a03522c9104e214f4c967417a04
7
- data.tar.gz: 2d60b83c461d1bcdaa611322061f844f186951341562b5a3ec83d35512d58059776a5772b41bdf97b2cb77c2fb53abd2a744f9bddc49042b6d421868411c010a
6
+ metadata.gz: 4841268cf5f76f1ad2b0ed2bf16b2527dd73e4d41728c64dbe13986b1a574759f900e2748e72ce72f6c677cf754d8a4f5115530140285412a07943e13b6312a5
7
+ data.tar.gz: bd48e0942af375429188957956a5555963297d62a9bc6549529ae1713b7670b41bfc5eea6b894d961e3e32507963e394779c372ad3b12a6422b5218f94b0f9e4
@@ -90,7 +90,7 @@ module Facter
90
90
  end
91
91
 
92
92
  def execute_command(command, on_fail, logger = nil, time_limit = nil)
93
- time_limit ||= 1.5
93
+ time_limit ||= 300
94
94
  begin
95
95
  # Set LC_ALL and LANG to force i18n to C for the duration of this exec;
96
96
  # this ensures that any code that parses the
@@ -100,18 +100,24 @@ module Facter
100
100
  @log.debug("Executing command: #{command}")
101
101
  out, stderr = Open3.popen3(opts, command.to_s) do |_, stdout, stderr, wait_thr|
102
102
  pid = wait_thr.pid
103
- output = +''
104
- err = +''
103
+ stdout_messages = +''
104
+ stderr_messages = +''
105
+ out_reader = Thread.new { stdout.read }
106
+ err_reader = Thread.new { stderr.read }
105
107
  begin
106
108
  Timeout.timeout(time_limit) do
107
- output << stdout.read
108
- err << stderr.read
109
+ stdout_messages << out_reader.value
110
+ stderr_messages << err_reader.value
109
111
  end
110
112
  rescue Timeout::Error
111
- @log.debug("Timeout encounter after #{time_limit}s, killing process with pid: #{pid}")
113
+ message = "Timeout encounter after #{time_limit}s, killing process with pid: #{pid}"
112
114
  Process.kill('KILL', pid)
115
+ on_fail == :raise ? (raise StandardError, message) : @log.debug(message)
116
+ ensure
117
+ out_reader.kill
118
+ err_reader.kill
113
119
  end
114
- [output, err]
120
+ [stdout_messages, stderr_messages]
115
121
  end
116
122
  log_stderr(stderr, command, logger)
117
123
  rescue StandardError => e
@@ -75,11 +75,6 @@ module Facter
75
75
  type: :boolean,
76
76
  desc: 'Enable verbose (info) output.'
77
77
 
78
- class_option :puppet,
79
- type: :boolean,
80
- aliases: '-p',
81
- desc: 'Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.'
82
-
83
78
  class_option :show_legacy,
84
79
  type: :boolean,
85
80
  desc: 'Show legacy facts when querying all facts.'
@@ -157,6 +152,12 @@ module Facter
157
152
  puts cache_groups
158
153
  end
159
154
 
155
+ desc '--puppet, -p', '(NOT SUPPORTED)Load the Puppet libraries, thus allowing Facter to load Puppet-specific facts.'
156
+ map ['--puppet', '-p'] => :puppet
157
+ def puppet(*_args)
158
+ puts '`facter --puppet` and `facter -p` are no longer supported, use `puppet facts show` instead'
159
+ end
160
+
160
161
  desc 'help', 'Help for all arguments'
161
162
  def help(*args)
162
163
  help_string = +''
@@ -56,13 +56,15 @@ module Facter
56
56
  private
57
57
 
58
58
  def resolve_fact(searched_fact)
59
- return unless fact_cache_enabled?(searched_fact.name)
59
+ fact_name = if searched_fact.file
60
+ File.basename(searched_fact.file)
61
+ else
62
+ searched_fact.name
63
+ end
60
64
 
61
- fact = if searched_fact.file
62
- @fact_groups.get_fact(File.basename(searched_fact.file))
63
- else
64
- @fact_groups.get_fact(searched_fact.name)
65
- end
65
+ return unless fact_cache_enabled?(fact_name)
66
+
67
+ fact = @fact_groups.get_fact(fact_name)
66
68
 
67
69
  return unless fact
68
70
 
@@ -97,14 +99,17 @@ module Facter
97
99
  end
98
100
 
99
101
  def cache_fact(fact)
100
- group_name = if fact.file
101
- File.basename(fact.file)
102
- else
103
- @fact_groups.get_fact_group(fact.name)
104
- end
102
+ fact_name = if fact.file
103
+ File.basename(fact.file)
104
+ else
105
+ fact.name
106
+ end
107
+
108
+ group_name = @fact_groups.get_fact_group(fact_name)
109
+
105
110
  return if !group_name || fact.value.nil?
106
111
 
107
- return unless fact_cache_enabled?(fact.name)
112
+ return unless fact_cache_enabled?(fact_name)
108
113
 
109
114
  @groups[group_name] ||= {}
110
115
  @groups[group_name][fact.name] = fact.value
@@ -14,7 +14,7 @@ module Facter
14
14
  end
15
15
 
16
16
  def read_oslevel(fact_name)
17
- output = Facter::Core::Execution.execute('/usr/bin/oslevel -s', { limit: 2, logger: log })
17
+ output = Facter::Core::Execution.execute('/usr/bin/oslevel -s', logger: log)
18
18
  @fact_list[:build] = output unless output.empty?
19
19
  @fact_list[:kernel] = 'AIX'
20
20
 
@@ -25,11 +25,21 @@ module Facter
25
25
 
26
26
  def read_system(output)
27
27
  @fact_list[:total] = kilobytes_to_bytes(output.match(/MemTotal:\s+(\d+)\s/)[1])
28
- @fact_list[:memfree] = kilobytes_to_bytes(output.match(/MemFree:\s+(\d+)\s/)[1])
29
- @fact_list[:used_bytes] = compute_used(@fact_list[:total], reclaimable_memory(output))
28
+ @fact_list[:memfree] = memfree(output)
29
+ @fact_list[:used_bytes] = compute_used(@fact_list[:total], @fact_list[:memfree])
30
30
  @fact_list[:capacity] = compute_capacity(@fact_list[:used_bytes], @fact_list[:total])
31
31
  end
32
32
 
33
+ def memfree(output)
34
+ available = output.match(/MemAvailable:\s+(\d+)\s/)
35
+ return kilobytes_to_bytes(available[1]) if available
36
+
37
+ buffers = kilobytes_to_bytes(output.match(/Buffers:\s+(\d+)\s/)[1])
38
+ cached = kilobytes_to_bytes(output.match(/Cached:\s+(\d+)\s/)[1])
39
+ memfree = kilobytes_to_bytes(output.match(/MemFree:\s+(\d+)\s/)[1])
40
+ memfree + buffers + cached
41
+ end
42
+
33
43
  def read_swap(output)
34
44
  total = output.match(/SwapTotal:\s+(\d+)\s/)[1]
35
45
  return if total.to_i.zero?
@@ -44,18 +54,6 @@ module Facter
44
54
  quantity.to_i * 1024
45
55
  end
46
56
 
47
- def reclaimable_memory(output)
48
- buffers = kilobytes_to_bytes(output.match(/Buffers:\s+(\d+)\s/)[1])
49
- cached = kilobytes_to_bytes(output.match(/Cached:\s+(\d+)\s/)[1])
50
- s_reclaimable = output.match(/SReclaimable:\s+(\d+)\s/)
51
- s_reclaimable = if s_reclaimable
52
- kilobytes_to_bytes(s_reclaimable[1])
53
- else
54
- 0
55
- end
56
- @fact_list[:memfree] + buffers + cached + s_reclaimable
57
- end
58
-
59
57
  def compute_capacity(used, total)
60
58
  format('%<computed_capacity>.2f', computed_capacity: (used / total.to_f * 100)) + '%'
61
59
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Facter
4
- VERSION = '4.0.41' unless defined?(VERSION)
4
+ VERSION = '4.0.42' unless defined?(VERSION)
5
5
  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.41
4
+ version: 4.0.42
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-01 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler