facter 1.7.6 → 2.0.1.rc1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of facter might be problematic. Click here for more details.

Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/COMMITTERS.md +194 -0
  3. data/CONTRIBUTING.md +63 -235
  4. data/Gemfile +12 -8
  5. data/README.md +1 -2
  6. data/Rakefile +1 -1
  7. data/bin/facter +0 -4
  8. data/ext/build_defaults.yaml +2 -2
  9. data/ext/project_data.yaml +18 -0
  10. data/install.rb +1 -16
  11. data/lib/facter.rb +171 -171
  12. data/lib/facter/application.rb +65 -54
  13. data/lib/facter/core/aggregate.rb +220 -0
  14. data/lib/facter/core/directed_graph.rb +46 -0
  15. data/lib/facter/core/execution.rb +100 -0
  16. data/lib/facter/core/execution/base.rb +73 -0
  17. data/lib/facter/core/execution/posix.rb +50 -0
  18. data/lib/facter/core/execution/windows.rb +57 -0
  19. data/lib/facter/core/logging.rb +169 -0
  20. data/lib/facter/core/resolvable.rb +94 -0
  21. data/lib/facter/core/suitable.rb +117 -0
  22. data/lib/facter/domain.rb +15 -9
  23. data/lib/facter/filesystems.rb +1 -1
  24. data/lib/facter/hardwaremodel.rb +1 -1
  25. data/lib/facter/hostname.rb +3 -3
  26. data/lib/facter/interfaces.rb +6 -1
  27. data/lib/facter/ipaddress.rb +2 -2
  28. data/lib/facter/kernel.rb +1 -1
  29. data/lib/facter/kernelrelease.rb +1 -1
  30. data/lib/facter/ldom.rb +1 -1
  31. data/lib/facter/lsbdistcodename.rb +1 -1
  32. data/lib/facter/lsbdistdescription.rb +1 -1
  33. data/lib/facter/lsbdistid.rb +1 -1
  34. data/lib/facter/lsbdistrelease.rb +1 -1
  35. data/lib/facter/lsbrelease.rb +1 -1
  36. data/lib/facter/macaddress.rb +1 -14
  37. data/lib/facter/macosx.rb +2 -2
  38. data/lib/facter/memory.rb +8 -19
  39. data/lib/facter/operatingsystem.rb +1 -1
  40. data/lib/facter/operatingsystemrelease.rb +34 -1
  41. data/lib/facter/physicalprocessorcount.rb +6 -6
  42. data/lib/facter/processor.rb +11 -10
  43. data/lib/facter/selinux.rb +4 -15
  44. data/lib/facter/ssh.rb +5 -2
  45. data/lib/facter/util/architecture.rb +2 -2
  46. data/lib/facter/util/collection.rb +42 -38
  47. data/lib/facter/util/config.rb +19 -9
  48. data/lib/facter/util/confine.rb +34 -4
  49. data/lib/facter/util/ec2.rb +1 -1
  50. data/lib/facter/util/fact.rb +108 -36
  51. data/lib/facter/util/file_read.rb +7 -6
  52. data/lib/facter/util/formatter.rb +38 -0
  53. data/lib/facter/util/ip.rb +3 -3
  54. data/lib/facter/util/loader.rb +62 -42
  55. data/lib/facter/util/macosx.rb +7 -8
  56. data/lib/facter/util/manufacturer.rb +3 -3
  57. data/lib/facter/util/memory.rb +13 -13
  58. data/lib/facter/util/monkey_patches.rb +0 -31
  59. data/lib/facter/util/netmask.rb +3 -3
  60. data/lib/facter/util/normalization.rb +94 -0
  61. data/lib/facter/util/nothing_loader.rb +3 -6
  62. data/lib/facter/util/parser.rb +3 -5
  63. data/lib/facter/util/plist/generator.rb +1 -1
  64. data/lib/facter/util/processor.rb +15 -15
  65. data/lib/facter/util/resolution.rb +112 -289
  66. data/lib/facter/util/solaris_zones.rb +4 -4
  67. data/lib/facter/util/uptime.rb +8 -3
  68. data/lib/facter/util/values.rb +67 -1
  69. data/lib/facter/util/virtual.rb +10 -10
  70. data/lib/facter/util/xendomains.rb +1 -1
  71. data/lib/facter/version.rb +42 -39
  72. data/lib/facter/virtual.rb +6 -7
  73. data/lib/facter/zfs_version.rb +3 -3
  74. data/lib/facter/zpool_version.rb +3 -3
  75. data/spec/fixtures/unit/netmask/darwin_10_8_5.txt +30 -0
  76. data/spec/unit/application_spec.rb +46 -1
  77. data/spec/unit/core/aggregate_spec.rb +125 -0
  78. data/spec/unit/core/directed_graph_spec.rb +79 -0
  79. data/spec/unit/core/execution/base_spec.rb +119 -0
  80. data/spec/unit/core/execution/posix_spec.rb +86 -0
  81. data/spec/unit/core/execution/windows_spec.rb +106 -0
  82. data/spec/unit/core/execution_spec.rb +37 -0
  83. data/spec/unit/core/logging_spec.rb +104 -0
  84. data/spec/unit/core/resolvable_spec.rb +81 -0
  85. data/spec/unit/core/suitable_spec.rb +96 -0
  86. data/spec/unit/domain_spec.rb +5 -5
  87. data/spec/unit/facter_spec.rb +61 -222
  88. data/spec/unit/filesystems_spec.rb +2 -2
  89. data/spec/unit/hardwareisa_spec.rb +5 -5
  90. data/spec/unit/hardwaremodel_spec.rb +1 -1
  91. data/spec/unit/hostname_spec.rb +4 -4
  92. data/spec/unit/id_spec.rb +3 -3
  93. data/spec/unit/interfaces_spec.rb +10 -0
  94. data/spec/unit/ipaddress6_spec.rb +4 -4
  95. data/spec/unit/ipaddress_spec.rb +1 -1
  96. data/spec/unit/kernel_spec.rb +2 -2
  97. data/spec/unit/kernelmajversion_spec.rb +1 -1
  98. data/spec/unit/kernelrelease_spec.rb +4 -4
  99. data/spec/unit/kernelversion_spec.rb +2 -2
  100. data/spec/unit/ldom_spec.rb +2 -2
  101. data/spec/unit/lsbdistcodename_spec.rb +2 -2
  102. data/spec/unit/lsbdistdescription_spec.rb +2 -2
  103. data/spec/unit/lsbdistid_spec.rb +2 -2
  104. data/spec/unit/lsbdistrelease_spec.rb +2 -2
  105. data/spec/unit/lsbrelease_spec.rb +2 -2
  106. data/spec/unit/manufacturer_spec.rb +1 -1
  107. data/spec/unit/memory_spec.rb +24 -31
  108. data/spec/unit/netmask_spec.rb +9 -0
  109. data/spec/unit/operatingsystem_spec.rb +1 -1
  110. data/spec/unit/operatingsystemrelease_spec.rb +62 -4
  111. data/spec/unit/physicalprocessorcount_spec.rb +10 -10
  112. data/spec/unit/processor_spec.rb +11 -11
  113. data/spec/unit/selinux_spec.rb +2 -8
  114. data/spec/unit/ssh_spec.rb +3 -2
  115. data/spec/unit/uniqueid_spec.rb +3 -3
  116. data/spec/unit/util/collection_spec.rb +37 -35
  117. data/spec/unit/util/config_spec.rb +20 -0
  118. data/spec/unit/util/confine_spec.rb +21 -0
  119. data/spec/unit/util/directory_loader_spec.rb +1 -0
  120. data/spec/unit/util/ec2_spec.rb +6 -6
  121. data/spec/unit/util/fact_spec.rb +92 -90
  122. data/spec/unit/util/ip_spec.rb +2 -2
  123. data/spec/unit/util/loader_spec.rb +127 -186
  124. data/spec/unit/util/macaddress_spec.rb +2 -2
  125. data/spec/unit/util/macosx_spec.rb +8 -8
  126. data/spec/unit/util/manufacturer_spec.rb +3 -3
  127. data/spec/unit/util/normalization_spec.rb +113 -0
  128. data/spec/unit/util/parser_spec.rb +25 -3
  129. data/spec/unit/util/processor_spec.rb +2 -2
  130. data/spec/unit/util/resolution_spec.rb +60 -631
  131. data/spec/unit/util/solaris_zones_spec.rb +5 -5
  132. data/spec/unit/util/uptime_spec.rb +1 -1
  133. data/spec/unit/util/values_spec.rb +131 -0
  134. data/spec/unit/util/virtual_spec.rb +16 -16
  135. data/spec/unit/util/xendomains_spec.rb +2 -2
  136. data/spec/unit/virtual_spec.rb +39 -39
  137. data/spec/unit/zfs_version_spec.rb +11 -11
  138. data/spec/unit/zonename_spec.rb +2 -2
  139. data/spec/unit/zones_spec.rb +1 -1
  140. data/spec/unit/zpool_version_spec.rb +11 -11
  141. metadata +466 -447
  142. data/lib/facter/util/cfpropertylist.rb +0 -6
  143. data/lib/facter/util/cfpropertylist/LICENSE +0 -19
  144. data/lib/facter/util/cfpropertylist/README +0 -44
  145. data/lib/facter/util/cfpropertylist/Rakefile +0 -44
  146. data/lib/facter/util/cfpropertylist/THANKS +0 -7
  147. data/lib/facter/util/cfpropertylist/lib/cfpropertylist.rb +0 -6
  148. data/lib/facter/util/cfpropertylist/lib/rbBinaryCFPropertyList.rb +0 -562
  149. data/lib/facter/util/cfpropertylist/lib/rbCFPlistError.rb +0 -26
  150. data/lib/facter/util/cfpropertylist/lib/rbCFPropertyList.rb +0 -407
  151. data/lib/facter/util/cfpropertylist/lib/rbCFTypes.rb +0 -244
  152. data/lib/facter/util/cfpropertylist/lib/rbLibXMLParser.rb +0 -135
  153. data/lib/facter/util/cfpropertylist/lib/rbNokogiriParser.rb +0 -140
  154. data/lib/facter/util/cfpropertylist/lib/rbREXMLParser.rb +0 -136
  155. data/spec/unit/util/monkey_patches_spec.rb +0 -42
@@ -93,7 +93,7 @@ module Util
93
93
  #
94
94
  # @return [Hash] the parsed output of the zoneadm command
95
95
  def refresh
96
- @zoneadm_output = Facter::Util::Resolution.exec(zoneadm_cmd)
96
+ @zoneadm_output = Facter::Core::Execution.exec(zoneadm_cmd)
97
97
  parse!
98
98
  end
99
99
 
@@ -103,11 +103,11 @@ module Util
103
103
  #
104
104
  # @api private
105
105
  def parse!
106
- if @zoneadm_output
107
- rows = @zoneadm_output.split("\n").collect { |line| line.split(':') }
108
- else
106
+ if @zoneadm_output.empty?
109
107
  Facter.debug "Cannot parse zone facts, #{zoneadm_cmd} returned no output"
110
108
  rows = []
109
+ else
110
+ rows = @zoneadm_output.split("\n").collect { |line| line.split(':') }
111
111
  end
112
112
 
113
113
  @zone_hash = rows.inject({}) do |memo, fields|
@@ -20,19 +20,24 @@ module Facter::Util::Uptime
20
20
  private
21
21
 
22
22
  def self.uptime_proc_uptime
23
- if output = Facter::Util::Resolution.exec("/bin/cat #{uptime_file} 2>/dev/null")
23
+ output = Facter::Core::Execution.exec("/bin/cat #{uptime_file} 2>/dev/null")
24
+
25
+ if not output.empty?
24
26
  output.chomp.split(" ").first.to_i
25
27
  end
26
28
  end
27
29
 
28
30
  def self.uptime_sysctl
29
- if output = Facter::Util::Resolution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
31
+ output = Facter::Core::Execution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
32
+ if not output.empty?
30
33
  compute_uptime(Time.at(output.match(/\d+/)[0].to_i))
31
34
  end
32
35
  end
33
36
 
34
37
  def self.uptime_executable
35
- if output = Facter::Util::Resolution.exec("#{uptime_executable_cmd} 2>/dev/null")
38
+ output = Facter::Core::Execution.exec("#{uptime_executable_cmd} 2>/dev/null")
39
+
40
+ if not output.empty?
36
41
  up=0
37
42
  if output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+):(\d+)/
38
43
  # Regexp handles Solaris, AIX, HP-UX, and Tru64.
@@ -1,9 +1,75 @@
1
- # A util module for facter containing helper methods
2
1
  module Facter
3
2
  module Util
3
+ # A util module for facter containing helper methods
4
4
  module Values
5
5
  module_function
6
6
 
7
+ class DeepFreezeError < StandardError; end
8
+
9
+ # Duplicate and deeply freeze a given data structure
10
+ #
11
+ # @param value [Object] The structure to freeze
12
+ # @return [void]
13
+ def deep_freeze(value)
14
+ case value
15
+ when Numeric, Symbol, TrueClass, FalseClass, NilClass
16
+ # These are immutable values, we can safely ignore them
17
+ value
18
+ when String
19
+ value.dup.freeze
20
+ when Array
21
+ value.map do |entry|
22
+ deep_freeze(entry)
23
+ end.freeze
24
+ when Hash
25
+ value.inject({}) do |hash, (key, value)|
26
+ hash[deep_freeze(key)] = deep_freeze(value)
27
+ hash
28
+ end.freeze
29
+ else
30
+ raise DeepFreezeError, "Cannot deep freeze #{value}:#{value.class}"
31
+ end
32
+ end
33
+
34
+ class DeepMergeError < StandardError; end
35
+
36
+ # Perform a deep merge of two nested data structures.
37
+ #
38
+ # @param left [Object]
39
+ # @param right [Object]
40
+ # @param path [Array<String>] The traversal path followed when merging nested hashes
41
+ #
42
+ # @return [Object] The merged data structure.
43
+ def deep_merge(left, right, path = [], &block)
44
+ ret = nil
45
+
46
+ if left.is_a? Hash and right.is_a? Hash
47
+ ret = left.merge(right) do |key, left_val, right_val|
48
+ path.push(key)
49
+ merged = deep_merge(left_val, right_val, path)
50
+ path.pop
51
+ merged
52
+ end
53
+ elsif left.is_a? Array and right.is_a? Array
54
+ ret = left.dup.concat(right)
55
+ elsif right.nil?
56
+ ret = left
57
+ elsif left.nil?
58
+ ret = right
59
+ elsif left.nil? and right.nil?
60
+ ret = nil
61
+ else
62
+ msg = "Cannot merge #{left.inspect}:#{left.class} and #{right.inspect}:#{right.class}"
63
+ if not path.empty?
64
+ msg << " at root"
65
+ msg << path.map { |part| "[#{part.inspect}]" }.join
66
+ end
67
+ raise DeepMergeError, msg
68
+ end
69
+
70
+ ret
71
+ end
72
+
7
73
  def convert(value)
8
74
  value = value.to_s if value.is_a?(Symbol)
9
75
  value = value.downcase if value.is_a?(String)
@@ -4,7 +4,7 @@ module Facter::Util::Virtual
4
4
  ##
5
5
  # virt_what is a delegating helper method intended to make it easier to stub
6
6
  # the system call without affecting other calls to
7
- # Facter::Util::Resolution.exec
7
+ # Facter::Core::Execution.exec
8
8
  #
9
9
  # Per https://bugzilla.redhat.com/show_bug.cgi?id=719611 when run as a
10
10
  # non-root user the virt-what command may emit an error message on stdout,
@@ -12,7 +12,7 @@ module Facter::Util::Virtual
12
12
  # method ensures stderr is redirected and that error messages are stripped
13
13
  # from stdout.
14
14
  def self.virt_what(command = "virt-what")
15
- command = Facter::Util::Resolution.which(command)
15
+ command = Facter::Core::Execution.which(command)
16
16
  return unless command
17
17
 
18
18
  if Facter.value(:kernel) == 'windows'
@@ -20,15 +20,15 @@ module Facter::Util::Virtual
20
20
  else
21
21
  redirected_cmd = "#{command} 2>/dev/null"
22
22
  end
23
- output = Facter::Util::Resolution.exec redirected_cmd
23
+ output = Facter::Core::Execution.exec redirected_cmd
24
24
  output.gsub(/^virt-what: .*$/, '') if output
25
25
  end
26
26
 
27
27
  ##
28
28
  # lspci is a delegating helper method intended to make it easier to stub the
29
- # system call without affecting other calls to Facter::Util::Resolution.exec
29
+ # system call without affecting other calls to Facter::Core::Execution.exec
30
30
  def self.lspci(command = "lspci 2>/dev/null")
31
- Facter::Util::Resolution.exec command
31
+ Facter::Core::Execution.exec command
32
32
  end
33
33
 
34
34
  def self.openvz?
@@ -40,7 +40,7 @@ module Facter::Util::Virtual
40
40
  return false unless self.openvz?
41
41
  return false unless FileTest.exists?( '/proc/self/status' )
42
42
 
43
- envid = Facter::Util::Resolution.exec( 'grep "envID" /proc/self/status' )
43
+ envid = Facter::Core::Execution.exec( 'grep "envID" /proc/self/status' )
44
44
  if envid =~ /^envID:\s+0$/i
45
45
  return 'openvzhn'
46
46
  elsif envid =~ /^envID:\s+(\d+)$/i
@@ -56,7 +56,7 @@ module Facter::Util::Virtual
56
56
 
57
57
  def self.zone?
58
58
  return true if FileTest.directory?("/.SUNWnative")
59
- z = Facter::Util::Resolution.exec("/sbin/zonename")
59
+ z = Facter::Core::Execution.exec("/sbin/zonename")
60
60
  return false unless z
61
61
  return z.chomp != 'global'
62
62
  end
@@ -92,7 +92,7 @@ module Facter::Util::Virtual
92
92
  txt = if FileTest.exists?("/proc/cpuinfo")
93
93
  File.read("/proc/cpuinfo")
94
94
  elsif ["FreeBSD", "OpenBSD"].include? Facter.value(:kernel)
95
- Facter::Util::Resolution.exec("/sbin/sysctl -n hw.model")
95
+ Facter::Core::Execution.exec("/sbin/sysctl -n hw.model")
96
96
  end
97
97
  (txt =~ /QEMU Virtual CPU/) ? true : false
98
98
  end
@@ -123,11 +123,11 @@ module Facter::Util::Virtual
123
123
  when "FreeBSD" then "/sbin"
124
124
  when "GNU/kFreeBSD" then "/bin"
125
125
  end
126
- Facter::Util::Resolution.exec("#{path}/sysctl -n security.jail.jailed") == "1"
126
+ Facter::Core::Execution.exec("#{path}/sysctl -n security.jail.jailed") == "1"
127
127
  end
128
128
 
129
129
  def self.hpvm?
130
- Facter::Util::Resolution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/
130
+ Facter::Core::Execution.exec("/usr/bin/getconf MACHINE_MODEL").chomp =~ /Virtual Machine/
131
131
  end
132
132
 
133
133
  def self.zlinux?
@@ -2,7 +2,7 @@
2
2
  #
3
3
  module Facter::Util::Xendomains
4
4
  def self.get_domains
5
- if xm_list = Facter::Util::Resolution.exec('/usr/sbin/xm list 2>/dev/null')
5
+ if xm_list = Facter::Core::Execution.exec('/usr/sbin/xm list 2>/dev/null')
6
6
  domains = xm_list.split("\n").reject { |line| line =~ /^(Name|Domain-0)/ }
7
7
  domains.map { |line| line.split(/\s/)[0] }.join(',')
8
8
  end
@@ -1,54 +1,53 @@
1
1
  module Facter
2
2
  if not defined? FACTERVERSION then
3
- FACTERVERSION = '1.7.6'
3
+ FACTERVERSION = '2.0.1-rc1'
4
4
  end
5
5
 
6
- ##
7
- # version is a public API method intended to always provide a fast and
8
- # lightweight way to determine the version of Facter.
6
+ # Returns the running version of Facter.
9
7
  #
10
- # The intent is that software external to Facter be able to determine the
11
- # Facter version with no side-effects. The expected use is:
8
+ # @comment The intent is that software external to Facter be able to
9
+ # determine the Facter version with no side-effects. The expected
10
+ # use is:
12
11
  #
13
12
  # require 'facter/version'
14
13
  # version = Facter.version
15
14
  #
16
- # This function has the following ordering precedence. This precedence list
17
- # is designed to facilitate automated packaging tasks by simply writing to
18
- # the VERSION file in the same directory as this source file.
15
+ # This function has the following ordering precedence. This precedence list
16
+ # is designed to facilitate automated packaging tasks by simply writing to
17
+ # the VERSION file in the same directory as this source file.
19
18
  #
20
- # 1. If a version has been explicitly assigned using the Facter.version=
21
- # method, return that version.
22
- # 2. If there is a VERSION file, read the contents, trim any
23
- # trailing whitespace, and return that version string.
24
- # 3. Return the value of the Facter::FACTERVERSION constant hard-coded into
25
- # the source code.
19
+ # 1. If a version has been explicitly assigned using the Facter.version=
20
+ # method, return that version.
21
+ # 2. If there is a VERSION file, read the contents, trim any
22
+ # trailing whitespace, and return that version string.
23
+ # 3. Return the value of the Facter::FACTERVERSION constant hard-coded into
24
+ # the source code.
26
25
  #
27
- # If there is no VERSION file, the method must return the version string of
28
- # the nearest parent version that is an officially released version. That is
29
- # to say, if a branch named 3.1.x contains 25 patches on top of the most
30
- # recent official release of 3.1.1, then the version method must return the
31
- # string "3.1.1" if no "VERSION" file is present.
26
+ # If there is no VERSION file, the method must return the version string of
27
+ # the nearest parent version that is an officially released version. That is
28
+ # to say, if a branch named 3.1.x contains 25 patches on top of the most
29
+ # recent official release of 3.1.1, then the version method must return the
30
+ # string "3.1.1" if no "VERSION" file is present.
32
31
  #
33
- # By design the version identifier is _not_ intended to vary during the life
34
- # a process. There is no guarantee provided that writing to the VERSION file
35
- # while a Puppet process is running will cause the version string to be
36
- # updated. On the contrary, the contents of the VERSION are cached to reduce
37
- # filesystem accesses.
32
+ # By design the version identifier is _not_ intended to vary during the life of
33
+ # a process. There is no guarantee provided that writing to the VERSION file
34
+ # while a Puppet process is running will cause the version string to be
35
+ # updated. On the contrary, the contents of the VERSION are cached to reduce
36
+ # filesystem accesses.
38
37
  #
39
- # The VERSION file is intended to be used by package maintainers who may be
40
- # applying patches or otherwise changing the software version in a manner
41
- # that warrants a different software version identifier. The VERSION file is
42
- # intended to be managed and owned by the release process and packaging
43
- # related tasks, and as such should not reside in version control. The
44
- # FACTERVERSION constant is intended to be version controlled in history.
38
+ # The VERSION file is intended to be used by package maintainers who may be
39
+ # applying patches or otherwise changing the software version in a manner
40
+ # that warrants a different software version identifier. The VERSION file is
41
+ # intended to be managed and owned by the release process and packaging
42
+ # related tasks, and as such should not reside in version control. The
43
+ # FACTERVERSION constant is intended to be version controlled in history.
45
44
  #
46
- # Ideally, this behavior will allow package maintainers to precisely specify
47
- # the version of the software they're packaging as in the following example:
45
+ # Ideally, this behavior will allow package maintainers to precisely specify
46
+ # the version of the software they're packaging as in the following example:
48
47
  #
49
- # $ git describe > lib/facter/VERSION
50
- # $ ruby -r facter -e 'puts Facter.version'
51
- # 1.6.14-6-g66f2c99
48
+ # $ git describe > lib/facter/VERSION
49
+ # $ ruby -r facter -e 'puts Facter.version'
50
+ # 1.6.14-6-g66f2c99
52
51
  #
53
52
  # @api public
54
53
  #
@@ -62,17 +61,21 @@ module Facter
62
61
  @facter_version ||= FACTERVERSION
63
62
  end
64
63
 
64
+ # Sets the Facter version
65
+ #
66
+ # @return [void]
67
+ #
68
+ # @api private
65
69
  def self.version=(version)
66
70
  @facter_version = version
67
71
  end
68
72
 
69
- ##
70
- # read_version_file reads the content of the "VERSION" file that lives in the
73
+ # This reads the content of the "VERSION" file that lives in the
71
74
  # same directory as this source code file.
72
75
  #
73
76
  # @api private
74
77
  #
75
- # @return [String] for example: "1.6.14-6-gea42046" or nil if the VERSION
78
+ # @return [String] the version -- for example: "1.6.14-6-gea42046" or nil if the VERSION
76
79
  # file does not exist.
77
80
  def self.read_version_file(path)
78
81
  if File.exists?(path)
@@ -55,13 +55,12 @@ end
55
55
  Facter.add("virtual") do
56
56
  confine :kernel => 'SunOS'
57
57
  has_weight 10
58
+ self.timeout = 6
59
+
58
60
  setcode do
59
61
  next "zone" if Facter::Util::Virtual.zone?
60
62
 
61
- resolver = Facter::Util::Resolution.new('prtdiag')
62
- resolver.timeout = 6
63
- resolver.setcode('prtdiag')
64
- output = resolver.value
63
+ output = Facter::Core::Execution.exec('prtdiag')
65
64
  if output
66
65
  lines = output.split("\n")
67
66
  next "parallels" if lines.any? {|l| l =~ /Parallels/ }
@@ -92,7 +91,7 @@ Facter.add("virtual") do
92
91
  confine :kernel => 'OpenBSD'
93
92
  has_weight 10
94
93
  setcode do
95
- output = Facter::Util::Resolution.exec('sysctl -n hw.product 2>/dev/null')
94
+ output = Facter::Core::Execution.exec('sysctl -n hw.product 2>/dev/null')
96
95
  if output
97
96
  lines = output.split("\n")
98
97
  next "parallels" if lines.any? {|l| l =~ /Parallels/ }
@@ -133,7 +132,7 @@ Facter.add("virtual") do
133
132
  end
134
133
 
135
134
  # Parse dmidecode
136
- output = Facter::Util::Resolution.exec('dmidecode 2> /dev/null')
135
+ output = Facter::Core::Execution.exec('dmidecode 2> /dev/null')
137
136
  if output
138
137
  lines = output.split("\n")
139
138
  next "parallels" if lines.any? {|l| l =~ /Parallels/ }
@@ -146,7 +145,7 @@ Facter.add("virtual") do
146
145
  end
147
146
 
148
147
  # Sample output of vmware -v `VMware Server 1.0.5 build-80187`
149
- output = Facter::Util::Resolution.exec("vmware -v")
148
+ output = Facter::Core::Execution.exec("vmware -v")
150
149
  if output
151
150
  mdata = output.match /(\S+)\s+(\S+)/
152
151
  next "#{mdata[1]}_#{mdata[2]}".downcase if mdata
@@ -2,9 +2,9 @@ require 'facter'
2
2
 
3
3
  Facter.add('zfs_version') do
4
4
  setcode do
5
- if Facter::Util::Resolution.which('zfs')
6
- zfs_v = Facter::Util::Resolution.exec('zfs upgrade -v')
7
- zfs_version = zfs_v.scan(/^\s+(\d+)\s+/m).flatten.last unless zfs_v.nil?
5
+ if Facter::Core::Execution.which('zfs')
6
+ zfs_v = Facter::Core::Execution.exec('zfs upgrade -v')
7
+ zfs_version = zfs_v.scan(/^\s+(\d+)\s+/m).flatten.last unless zfs_v.empty?
8
8
  end
9
9
  end
10
10
  end
@@ -2,9 +2,9 @@ require 'facter'
2
2
 
3
3
  Facter.add('zpool_version') do
4
4
  setcode do
5
- if Facter::Util::Resolution.which('zpool')
6
- zpool_v = Facter::Util::Resolution.exec('zpool upgrade -v')
7
- zpool_version = zpool_v.match(/ZFS pool version (\d+)./).captures.first unless zpool_v.nil?
5
+ if Facter::Core::Execution.which('zpool')
6
+ zpool_v = Facter::Core::Execution.exec('zpool upgrade -v')
7
+ zpool_version = zpool_v.match(/ZFS pool version (\d+)./).captures.first unless zpool_v.empty?
8
8
  end
9
9
  end
10
10
  end
@@ -0,0 +1,30 @@
1
+ lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
2
+ options=3<RXCSUM,TXCSUM>
3
+ inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
4
+ inet 127.0.0.1 netmask 0xff000000
5
+ inet6 ::1 prefixlen 128
6
+ gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
7
+ stf0: flags=0<> mtu 1280
8
+ en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
9
+ ether 28:cf:e9:1a:8a:2d
10
+ inet6 fe80::2acf:e9ff:fe1a:8a2d%en0 prefixlen 64 scopeid 0x5
11
+ inet 10.16.141.17 netmask 0xfffffc00 broadcast 10.16.143.255
12
+ media: autoselect
13
+ status: active
14
+ p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
15
+ ether 0a:cf:e9:1a:8a:2d
16
+ media: autoselect
17
+ status: inactive
18
+ vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
19
+ ether 00:50:56:c0:00:01
20
+ inet 192.168.51.1 netmask 0xffffff00 broadcast 192.168.51.255
21
+ vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
22
+ ether 00:50:56:c0:00:08
23
+ inet 172.16.138.1 netmask 0xffffff00 broadcast 172.16.138.255
24
+ en3: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
25
+ options=4<VLAN_MTU>
26
+ ether 70:11:24:8c:33:df
27
+ inet6 fe80::7211:24ff:fe8c:33df%en3 prefixlen 64 scopeid 0x7
28
+ inet 10.16.16.205 netmask 0xfffffc00 broadcast 10.16.19.255
29
+ media: autoselect (100baseTX <full-duplex>)
30
+ status: active
@@ -8,7 +8,7 @@ describe Facter::Application do
8
8
  Facter::Application.parse(['architecture', 'kernel']).should == {}
9
9
  end
10
10
 
11
- [:yaml, :json, :trace].each do |option_key|
11
+ [:yaml, :json].each do |option_key|
12
12
  it "sets options[:#{option_key}] when given --#{option_key}" do
13
13
  options = Facter::Application.parse(["--#{option_key}"])
14
14
  options[option_key].should be_true
@@ -31,6 +31,13 @@ describe Facter::Application do
31
31
  end
32
32
  end
33
33
 
34
+ it "enables tracing when given --trace" do
35
+ Facter.trace(false)
36
+ Facter::Application.parse(['--trace'])
37
+ Facter.should be_trace
38
+ Facter.trace(false)
39
+ end
40
+
34
41
  ['-t', '--timing'].each do |option|
35
42
  it "enables timing when given #{option}" do
36
43
  Facter.timing(false)
@@ -52,5 +59,43 @@ describe Facter::Application do
52
59
  Facter::Application.parse(argv)
53
60
  argv.should == ['uptime', 'virtual']
54
61
  end
62
+
63
+ after(:all) do
64
+ Facter.debugging(false)
65
+ Facter.timing(false)
66
+ Facter.trace(false)
67
+ end
68
+ end
69
+
70
+ describe "formatting facts" do
71
+ before do
72
+ Facter.stubs(:to_hash)
73
+ Facter.stubs(:value)
74
+ Facter::Application.stubs(:puts)
75
+ end
76
+
77
+ it "delegates YAML formatting" do
78
+ Facter::Util::Formatter.expects(:format_yaml)
79
+ Facter::Application.stubs(:exit).with(0)
80
+ Facter::Application.run(['--yaml'])
81
+ end
82
+
83
+ it "delegates JSON formatting", :if => Facter.json? do
84
+ Facter::Util::Formatter.expects(:format_json)
85
+ Facter::Application.stubs(:exit).with(0)
86
+ Facter::Application.run(['--json'])
87
+ end
88
+
89
+ it "delegates plaintext formatting" do
90
+ Facter::Util::Formatter.expects(:format_plaintext)
91
+ Facter::Application.stubs(:exit).with(0)
92
+ Facter::Application.run(['--plaintext'])
93
+ end
94
+
95
+ it "defaults to plaintext" do
96
+ Facter::Util::Formatter.expects(:format_plaintext)
97
+ Facter::Application.stubs(:exit).with(0)
98
+ Facter::Application.run([])
99
+ end
55
100
  end
56
101
  end