facter 2.0.1.rc1-universal-darwin → 2.0.1.rc2-universal-darwin

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -5
  3. data/ext/build_defaults.yaml +2 -2
  4. data/lib/facter/core/execution.rb +15 -3
  5. data/lib/facter/core/execution/base.rb +18 -10
  6. data/lib/facter/domain.rb +2 -2
  7. data/lib/facter/hostname.rb +1 -3
  8. data/lib/facter/ldom.rb +1 -1
  9. data/lib/facter/lsbdistcodename.rb +1 -3
  10. data/lib/facter/lsbdistdescription.rb +4 -0
  11. data/lib/facter/lsbdistid.rb +1 -3
  12. data/lib/facter/lsbdistrelease.rb +1 -3
  13. data/lib/facter/lsbrelease.rb +1 -3
  14. data/lib/facter/physicalprocessorcount.rb +6 -8
  15. data/lib/facter/processor.rb +5 -20
  16. data/lib/facter/util/manufacturer.rb +2 -6
  17. data/lib/facter/util/resolution.rb +6 -2
  18. data/lib/facter/util/solaris_zones.rb +4 -4
  19. data/lib/facter/util/uptime.rb +4 -4
  20. data/lib/facter/util/vlans.rb +9 -12
  21. data/lib/facter/version.rb +1 -1
  22. data/lib/facter/virtual.rb +11 -3
  23. data/spec/fixtures/unit/util/vlans/centos-5-no-vlans +2 -0
  24. data/spec/unit/core/execution/base_spec.rb +22 -9
  25. data/spec/unit/core/execution_spec.rb +1 -1
  26. data/spec/unit/domain_spec.rb +5 -5
  27. data/spec/unit/hardwareisa_spec.rb +5 -5
  28. data/spec/unit/hardwaremodel_spec.rb +2 -2
  29. data/spec/unit/hostname_spec.rb +1 -1
  30. data/spec/unit/id_spec.rb +2 -2
  31. data/spec/unit/kernelrelease_spec.rb +27 -27
  32. data/spec/unit/kernelversion_spec.rb +13 -13
  33. data/spec/unit/ldom_spec.rb +2 -1
  34. data/spec/unit/lsbdistcodename_spec.rb +6 -6
  35. data/spec/unit/lsbdistdescription_spec.rb +7 -7
  36. data/spec/unit/lsbdistid_spec.rb +6 -6
  37. data/spec/unit/lsbdistrelease_spec.rb +2 -2
  38. data/spec/unit/lsbrelease_spec.rb +6 -6
  39. data/spec/unit/processor_spec.rb +5 -5
  40. data/spec/unit/uniqueid_spec.rb +3 -3
  41. data/spec/unit/util/ip_spec.rb +4 -0
  42. data/spec/unit/util/resolution_spec.rb +1 -1
  43. data/spec/unit/util/solaris_zones_spec.rb +2 -2
  44. data/spec/unit/util/uptime_spec.rb +2 -2
  45. data/spec/unit/util/vlans_spec.rb +34 -4
  46. data/spec/unit/zonename_spec.rb +1 -1
  47. data/spec/unit/zones_spec.rb +1 -1
  48. metadata +4 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09203ccf21d37452ffef44bdbd3a3dccecc09ed8
4
- data.tar.gz: a439679e95420277cdd03065bd1ad90f3ab30a79
3
+ metadata.gz: e6bbacc80d05536c080152a4608faf9bba735507
4
+ data.tar.gz: bbc421d37a8a25e9a1649603671e6ed7cb1b3c4e
5
5
  SHA512:
6
- metadata.gz: a8d74b12820a4741f5c97900c1e9cf5848a5c1688e6a34e4ed05f2102b8b1ea946df0d4bc1d1974f5474633507996d43a7e0c05767ff936717fd103c60255fc3
7
- data.tar.gz: 28bed2f6624c92256e5c284c4dcc105c37c8ba7078dc7f1a6c3cd1cd9b1c2631f0b261dc9e089413efaf909249fbc8a8ec1f72c4ca16ccd403233a60e098ac3c
6
+ metadata.gz: b3149487f44c1b3dc12f5f6e17b22e184efee36c280c59a02e5aaf0e2275fc935d84d0114a3a01ded0e3eaab28949e3abd797f565ac4e6e1e492a5937ad412d7
7
+ data.tar.gz: e7e15e44ec2237398fbd18776a1a9f92856a0e650c315c68b436e9903731c240b80d87ca2b042ff1b241fd8d52b9afaf726776f5755ff78fc158779f7a1e6cdf
data/Gemfile CHANGED
@@ -1,8 +1,4 @@
1
- if gem_source = ENV['GEM_SOURCE']
2
- source gem_source
3
- else
4
- source "https://rubygems.org"
5
- end
1
+ source ENV['GEM_SOURCE'] || "https://rubygems.org"
6
2
 
7
3
  # C Ruby (MRI) or Rubinius, but NOT Windows
8
4
  platforms :ruby do
@@ -2,14 +2,14 @@
2
2
  packaging_url: 'git://github.com/puppetlabs/packaging.git --branch=master'
3
3
  packaging_repo: 'packaging'
4
4
  default_cow: 'base-squeeze-i386.cow'
5
- cows: 'base-lucid-i386.cow base-lucid-amd64.cow base-precise-i386.cow base-precise-amd64.cow base-quantal-i386.cow base-quantal-amd64.cow base-raring-i386.cow base-raring-amd64.cow base-saucy-i386.cow base-saucy-amd64.cow base-sid-i386.cow base-sid-amd64.cow base-squeeze-i386.cow base-squeeze-amd64.cow base-stable-i386.cow base-stable-amd64.cow base-testing-i386.cow base-testing-amd64.cow base-unstable-i386.cow base-unstable-amd64.cow base-wheezy-i386.cow base-wheezy-amd64.cow'
5
+ cows: 'base-lucid-i386.cow base-lucid-amd64.cow base-precise-i386.cow base-precise-amd64.cow base-quantal-i386.cow base-quantal-amd64.cow base-raring-i386.cow base-raring-amd64.cow base-saucy-i386.cow base-saucy-amd64.cow base-sid-i386.cow base-sid-amd64.cow base-squeeze-i386.cow base-squeeze-amd64.cow base-stable-i386.cow base-stable-amd64.cow base-testing-i386.cow base-testing-amd64.cow base-trusty-i386.cow base-trusty-amd64.cow base-unstable-i386.cow base-unstable-amd64.cow base-wheezy-i386.cow base-wheezy-amd64.cow'
6
6
  pbuild_conf: '/etc/pbuilderrc'
7
7
  packager: 'puppetlabs'
8
8
  gpg_name: 'info@puppetlabs.com'
9
9
  gpg_key: '4BD6EC30'
10
10
  sign_tar: FALSE
11
11
  # a space separated list of mock configs
12
- final_mocks: 'pl-el-5-i386 pl-el-5-x86_64 pl-el-6-i386 pl-el-6-x86_64 pl-el-7-x86_64 pl-fedora-18-i386 pl-fedora-18-x86_64 pl-fedora-19-i386 pl-fedora-19-x86_64 pl-fedora-20-i386 pl-fedora-20-x86_64'
12
+ final_mocks: 'pl-el-5-i386 pl-el-5-x86_64 pl-el-6-i386 pl-el-6-x86_64 pl-el-7-x86_64 pl-fedora-19-i386 pl-fedora-19-x86_64 pl-fedora-20-i386 pl-fedora-20-x86_64'
13
13
  yum_host: 'yum.puppetlabs.com'
14
14
  yum_repo_path: '/opt/repository/yum/'
15
15
  build_gem: TRUE
@@ -89,12 +89,24 @@ module Facter
89
89
  # executing the code.
90
90
  #
91
91
  # @param code [String] the program to run
92
- # @return [String] the output of the program or the empty string on error
92
+ # @param options [Hash]
93
+ #
94
+ # @option options [Object] :on_fail How to behave when the command could
95
+ # not be run. Specifying :raise will raise an error, anything else will
96
+ # return that object on failure. Default is :raise.
97
+ #
98
+ # @raise [Facter::Core::Execution::ExecutionFailure] If the command does
99
+ # not exist or could not be executed.
100
+ #
101
+ # @return [String] the output of the program, or the value of :on_fail if
102
+ # command execution failed and :on_fail was specified.
93
103
  #
94
104
  # @api public
95
- def exec(command)
96
- @@impl.exec(command)
105
+ def exec(command, options = {})
106
+ @@impl.exec(command, options)
97
107
  end
108
+
109
+ class ExecutionFailure < StandardError; end
98
110
  end
99
111
  end
100
112
  end
@@ -27,31 +27,39 @@ class Facter::Core::Execution::Base
27
27
  rv
28
28
  end
29
29
 
30
- def exec(code)
30
+ def exec(command, options = {})
31
+
32
+ on_fail = options.fetch(:on_fail, :raise)
31
33
 
32
34
  ## Set LANG to force i18n to C for the duration of this exec; this ensures that any code that parses the
33
35
  ## output of the command can expect it to be in a consistent / predictable format / locale
34
36
  with_env "LANG" => "C" do
35
37
 
36
- if expanded_code = expand_command(code)
37
- # if we can find the binary, we'll run the command with the expanded path to the binary
38
- code = expanded_code
39
- else
40
- return ''
38
+ expanded_command = expand_command(command)
39
+
40
+ if expanded_command.nil?
41
+ if on_fail == :raise
42
+ raise Facter::Core::Execution::ExecutionFailure.new, "Could not execute '#{command}': command not found"
43
+ else
44
+ return on_fail
45
+ end
41
46
  end
42
47
 
43
48
  out = ''
44
49
 
45
50
  begin
46
51
  wait_for_child = true
47
- out = %x{#{code}}.chomp
52
+ out = %x{#{expanded_command}}.chomp
48
53
  wait_for_child = false
49
54
  rescue => detail
50
- Facter.warn(detail.message)
51
- return ''
55
+ if on_fail == :raise
56
+ raise Facter::Core::Execution::ExecutionFailure.new, "Failed while executing '#{expanded_command}': #{detail.message}"
57
+ else
58
+ return on_fail
59
+ end
52
60
  ensure
53
61
  if wait_for_child
54
- # We need to ensure that if this code exits early then any spawned
62
+ # We need to ensure that if this command exits early then any spawned
55
63
  # children will be reaped. Process execution is frequently
56
64
  # terminated using Timeout.timeout but since the timeout isn't in
57
65
  # this scope we can't rescue the raised exception. The best that
@@ -41,11 +41,11 @@ Facter.add(:domain) do
41
41
  basic_hostname
42
42
  end
43
43
 
44
- if name = Facter::Core::Execution.exec(hostname_command) \
44
+ if name = Facter::Core::Execution.exec(hostname_command, :on_fail => nil) \
45
45
  and name =~ /.*?\.(.+$)/
46
46
 
47
47
  return_value = $1
48
- elsif Facter.value(:kernel) != "windows" and domain = Facter::Core::Execution.exec('dnsdomainname 2> /dev/null') \
48
+ elsif Facter.value(:kernel) != "windows" and domain = Facter::Core::Execution.exec('dnsdomainname 2> /dev/null', :on_fail => nil) \
49
49
  and domain =~ /.+/
50
50
 
51
51
  return_value = domain
@@ -27,7 +27,5 @@ end
27
27
 
28
28
  Facter.add(:hostname) do
29
29
  confine :kernel => :darwin, :kernelrelease => "R7"
30
- setcode do
31
- Facter::Core::Execution.exec('/usr/sbin/scutil --get LocalHostName')
32
- end
30
+ setcode '/usr/sbin/scutil --get LocalHostName'
33
31
  end
@@ -1,4 +1,4 @@
1
- if Facter.value(:kernel) == 'SunOS'
1
+ if Facter.value(:kernel) == 'SunOS' and Facter::Core::Execution.which('virtinfo')
2
2
  virtinfo = Facter::Core::Execution.exec('virtinfo -ap')
3
3
 
4
4
  # Convert virtinfo parseable output format to array of arrays.
@@ -12,7 +12,5 @@
12
12
 
13
13
  Facter.add(:lsbdistcodename) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
- setcode do
16
- Facter::Core::Execution.exec('lsb_release -c -s 2>/dev/null')
17
- end
15
+ setcode 'lsb_release -c -s 2>/dev/null'
18
16
  end
@@ -12,6 +12,10 @@
12
12
 
13
13
  Facter.add(:lsbdistdescription) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
+ confine do
16
+ Facter::Core::Execution.which("lsb_release")
17
+ end
18
+
15
19
  setcode do
16
20
  if output = Facter::Core::Execution.exec('lsb_release -d -s 2>/dev/null')
17
21
  # the output may be quoted (at least it is on gentoo)
@@ -12,7 +12,5 @@
12
12
 
13
13
  Facter.add(:lsbdistid) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
- setcode do
16
- Facter::Core::Execution.exec('lsb_release -i -s 2>/dev/null')
17
- end
15
+ setcode 'lsb_release -i -s 2>/dev/null'
18
16
  end
@@ -12,7 +12,5 @@
12
12
 
13
13
  Facter.add(:lsbdistrelease) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
- setcode do
16
- Facter::Core::Execution.exec('lsb_release -r -s 2>/dev/null')
17
- end
15
+ setcode 'lsb_release -r -s 2>/dev/null'
18
16
  end
@@ -12,7 +12,5 @@
12
12
 
13
13
  Facter.add(:lsbrelease) do
14
14
  confine :kernel => [ :linux, :"gnu/kfreebsd" ]
15
- setcode do
16
- Facter::Core::Execution.exec('lsb_release -v -s 2>/dev/null')
17
- end
15
+ setcode 'lsb_release -v -s 2>/dev/null'
18
16
  end
@@ -66,19 +66,17 @@ end
66
66
  Facter.add('physicalprocessorcount') do
67
67
  confine :kernel => :sunos
68
68
 
69
+ # (#16526) The -p flag was not added until Solaris 8. Our intent is to
70
+ # split the kernel release fact value on the dot, take the second element,
71
+ # and disable the -p flag for values < 8 when.
69
72
  setcode do
70
- # (#16526) The -p flag was not added until Solaris 8. Our intent is to
71
- # split the kernel release fact value on the dot, take the second element,
72
- # and disable the -p flag for values < 8 when.
73
73
  kernelrelease = Facter.value(:kernelrelease)
74
74
  (major_version, minor_version) = kernelrelease.split(".").map { |str| str.to_i }
75
- cmd = "/usr/sbin/psrinfo"
76
- result = nil
77
75
  if (major_version > 5) or (major_version == 5 and minor_version >= 8) then
78
- result = Facter::Core::Execution.exec("#{cmd} -p")
76
+ Facter::Core::Execution.exec("/usr/sbin/psrinfo -p")
79
77
  else
80
- output = Facter::Core::Execution.exec(cmd)
81
- result = output.split("\n").length.to_s
78
+ output = Facter::Core::Execution.exec("/usr/sbin/psrinfo")
79
+ output.split("\n").length.to_s
82
80
  end
83
81
  end
84
82
  end
@@ -90,23 +90,12 @@ end
90
90
 
91
91
  Facter.add("Processor") do
92
92
  confine :kernel => :openbsd
93
- setcode do
94
- Facter::Core::Execution.exec("uname -p")
95
- end
96
- end
97
-
98
- Facter.add("ProcessorCount") do
99
- confine :kernel => :openbsd
100
- setcode do
101
- Facter::Core::Execution.exec("sysctl -n hw.ncpu")
102
- end
93
+ setcode "uname -p"
103
94
  end
104
95
 
105
96
  Facter.add("ProcessorCount") do
106
97
  confine :kernel => :Darwin
107
- setcode do
108
- Facter::Core::Execution.exec("sysctl -n hw.ncpu")
109
- end
98
+ setcode "sysctl -n hw.ncpu"
110
99
  end
111
100
 
112
101
  if Facter.value(:kernel) == "windows"
@@ -149,16 +138,12 @@ end
149
138
 
150
139
  Facter.add("Processor") do
151
140
  confine :kernel => [:dragonfly,:freebsd]
152
- setcode do
153
- Facter::Core::Execution.exec("sysctl -n hw.model")
154
- end
141
+ setcode "sysctl -n hw.model"
155
142
  end
156
143
 
157
144
  Facter.add("ProcessorCount") do
158
- confine :kernel => [:dragonfly,:freebsd]
159
- setcode do
160
- Facter::Core::Execution.exec("sysctl -n hw.ncpu")
161
- end
145
+ confine :kernel => [:dragonfly,:freebsd,:openbsd]
146
+ setcode "sysctl -n hw.ncpu"
162
147
  end
163
148
 
164
149
  Facter.add("ProcessorCount") do
@@ -54,9 +54,7 @@ module Facter::Manufacturer
54
54
  name.each do |sysctlkey,facterkey|
55
55
  Facter.add(facterkey) do
56
56
  confine :kernel => [:openbsd, :darwin]
57
- setcode do
58
- Facter::Core::Execution.exec("sysctl -n #{sysctlkey} 2>/dev/null")
59
- end
57
+ setcode "sysctl -n #{sysctlkey} 2>/dev/null"
60
58
  end
61
59
  end
62
60
  end
@@ -80,9 +78,7 @@ module Facter::Manufacturer
80
78
  end
81
79
 
82
80
  Facter.add('serialnumber') do
83
- setcode do
84
- Facter::Core::Execution.exec("/usr/sbin/sneep")
85
- end
81
+ setcode "/usr/sbin/sneep"
86
82
  end
87
83
  end
88
84
 
@@ -128,8 +128,12 @@ class Facter::Util::Resolution
128
128
  def setcode(string = nil, &block)
129
129
  if string
130
130
  @code = Proc.new do
131
- output = Facter::Core::Execution.exec(string)
132
- output.empty? ? nil : output
131
+ output = Facter::Core::Execution.exec(string, :on_fail => nil)
132
+ if output.nil? or output.empty?
133
+ nil
134
+ else
135
+ output
136
+ end
133
137
  end
134
138
  elsif block_given?
135
139
  @code = block
@@ -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::Core::Execution.exec(zoneadm_cmd)
96
+ @zoneadm_output = Facter::Core::Execution.exec(zoneadm_cmd, {:on_fail => nil})
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.empty?
106
+ if @zoneadm_output
107
+ rows = @zoneadm_output.split("\n").collect { |line| line.split(':') }
108
+ else
107
109
  Facter.debug "Cannot parse zone facts, #{zoneadm_cmd} returned no output"
108
110
  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|
@@ -28,16 +28,16 @@ module Facter::Util::Uptime
28
28
  end
29
29
 
30
30
  def self.uptime_sysctl
31
- output = Facter::Core::Execution.exec("#{uptime_sysctl_cmd} 2>/dev/null")
32
- if not output.empty?
31
+ output = Facter::Core::Execution.exec("#{uptime_sysctl_cmd} 2>/dev/null", :on_fail => nil)
32
+ if output
33
33
  compute_uptime(Time.at(output.match(/\d+/)[0].to_i))
34
34
  end
35
35
  end
36
36
 
37
37
  def self.uptime_executable
38
- output = Facter::Core::Execution.exec("#{uptime_executable_cmd} 2>/dev/null")
38
+ output = Facter::Core::Execution.exec("#{uptime_executable_cmd} 2>/dev/null", :on_fail => nil)
39
39
 
40
- if not output.empty?
40
+ if output
41
41
  up=0
42
42
  if output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+):(\d+)/
43
43
  # Regexp handles Solaris, AIX, HP-UX, and Tru64.
@@ -2,23 +2,20 @@
2
2
  #
3
3
  module Facter::Util::Vlans
4
4
  def self.get_vlan_config
5
- output = ""
6
- if File.exists?('/proc/net/vlan/config') and File.readable?('/proc/net/vlan/config')
7
- output = File.open('/proc/net/vlan/config').read
8
- end
9
- output
5
+ if File.exist?('/proc/net/vlan/config') and File.readable?('/proc/net/vlan/config')
6
+ File.read('/proc/net/vlan/config')
7
+ end
10
8
  end
11
9
 
12
10
  def self.get_vlans
13
- vlans = Array.new
14
- if self.get_vlan_config
15
- self.get_vlan_config.each_line do |line|
16
- if line =~ /^([0-9A-Za-z]+)\.([0-9]+) /
17
- vlans.insert(-1, $~[2]) if $~[2]
11
+ if (config = self.get_vlan_config)
12
+ vlans = []
13
+ config.each_line do |line|
14
+ if (match = line.match(/^([0-9A-Za-z]+)\.([0-9]+) /))
15
+ vlans << match[2] if match[2]
18
16
  end
19
17
  end
18
+ vlans.join(',') unless vlans.empty?
20
19
  end
21
-
22
- vlans.join(',')
23
20
  end
24
21
  end
@@ -1,6 +1,6 @@
1
1
  module Facter
2
2
  if not defined? FACTERVERSION then
3
- FACTERVERSION = '2.0.1-rc1'
3
+ FACTERVERSION = '2.0.1-rc2'
4
4
  end
5
5
 
6
6
  # Returns the running version of Facter.
@@ -144,15 +144,23 @@ Facter.add("virtual") do
144
144
  next "ovirt" if lines.any? {|l| l =~ /Product Name: oVirt Node/ }
145
145
  end
146
146
 
147
+ # Default to 'physical'
148
+ next 'physical'
149
+ end
150
+ end
151
+
152
+ Facter.add("virtual") do
153
+ confine do
154
+ Facter::Core::Execution.which('vmware')
155
+ end
156
+
157
+ setcode do
147
158
  # Sample output of vmware -v `VMware Server 1.0.5 build-80187`
148
159
  output = Facter::Core::Execution.exec("vmware -v")
149
160
  if output
150
161
  mdata = output.match /(\S+)\s+(\S+)/
151
162
  next "#{mdata[1]}_#{mdata[2]}".downcase if mdata
152
163
  end
153
-
154
- # Default to 'physical'
155
- next 'physical'
156
164
  end
157
165
  end
158
166
 
@@ -0,0 +1,2 @@
1
+ VLAN Dev name | VLAN ID
2
+ Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
@@ -77,18 +77,31 @@ describe Facter::Core::Execution::Base do
77
77
  subject.exec('foo')
78
78
  end
79
79
 
80
- it "returns an empty string when the command could not be expanded" do
81
- subject.expects(:expand_command).with('foo').returns nil
82
- expect(subject.exec('foo')).to be_empty
80
+ describe "and the command is not present" do
81
+ it "raises an error when the :on_fail behavior is :raise" do
82
+ subject.expects(:expand_command).with('foo').returns nil
83
+ expect { subject.exec('foo') }.to raise_error(Facter::Core::Execution::ExecutionFailure)
84
+ end
85
+
86
+ it "returns the given value when :on_fail is set to a value" do
87
+ subject.expects(:expand_command).with('foo').returns nil
88
+ expect(subject.exec('foo', :on_fail => nil)).to be_nil
89
+ end
83
90
  end
84
91
 
85
- it "logs a warning and returns an empty string when the command execution fails" do
86
- subject.expects(:`).with("/bin/foo").raises "kaboom!"
87
- Facter.expects(:warn).with("kaboom!")
92
+ describe "when command execution fails" do
93
+ before do
94
+ subject.expects(:`).with("/bin/foo").raises "kaboom!"
95
+ subject.expects(:expand_command).with('foo').returns '/bin/foo'
96
+ end
88
97
 
89
- subject.expects(:expand_command).with('foo').returns '/bin/foo'
98
+ it "raises an error when the :on_fail behavior is :raise" do
99
+ expect { subject.exec('foo') }.to raise_error(Facter::Core::Execution::ExecutionFailure)
100
+ end
90
101
 
91
- expect(subject.exec("foo")).to be_empty
102
+ it "returns the given value when :on_fail is set to a value" do
103
+ expect(subject.exec('foo', :on_fail => nil)).to be_nil
104
+ end
92
105
  end
93
106
 
94
107
  it "launches a thread to wait on children if the command was interrupted" do
@@ -99,7 +112,7 @@ describe Facter::Core::Execution::Base do
99
112
  Thread.expects(:new).yields
100
113
  Process.expects(:waitall).once
101
114
 
102
- subject.exec("foo")
115
+ subject.exec("foo", :on_fail => nil)
103
116
  end
104
117
 
105
118
  it "returns the output of the command" do
@@ -31,7 +31,7 @@ describe Facter::Core::Execution do
31
31
  end
32
32
 
33
33
  it "delegates #exec to the implementation" do
34
- impl.expects(:exec).with('waffles')
34
+ impl.expects(:exec).with('waffles', {})
35
35
  subject.exec('waffles')
36
36
  end
37
37
  end
@@ -24,11 +24,11 @@ describe "Domain name facts" do
24
24
  let(:dnsdomain_command) { "dnsdomainname 2> /dev/null" }
25
25
 
26
26
  def the_hostname_is(value)
27
- Facter::Core::Execution.stubs(:exec).with(hostname_command).returns(value)
27
+ Facter::Core::Execution.stubs(:exec).with(hostname_command, {:on_fail => nil}).returns(value)
28
28
  end
29
29
 
30
30
  def the_dnsdomainname_is(value)
31
- Facter::Core::Execution.stubs(:exec).with(dnsdomain_command).returns(value)
31
+ Facter::Core::Execution.stubs(:exec).with(dnsdomain_command, {:on_fail => nil}).returns(value)
32
32
  end
33
33
 
34
34
  before do
@@ -197,7 +197,7 @@ describe "Domain name facts" do
197
197
  it "should return nil" do
198
198
  expects_dnsdomains([nil])
199
199
 
200
- Facter::Core::Execution.stubs(:exec).with(hostname_command).returns('sometest')
200
+ Facter::Core::Execution.stubs(:exec).with(hostname_command, {:on_fail => nil}).returns('sometest')
201
201
  FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(false)
202
202
 
203
203
  Facter.fact(:domain).value.should be_nil
@@ -288,8 +288,8 @@ describe "Domain name facts" do
288
288
 
289
289
  describe scenario[:scenario] do
290
290
  before(:each) do
291
- Facter::Core::Execution.stubs(:exec).with("hostname -f 2> /dev/null").returns(scenario[:hostname])
292
- Facter::Core::Execution.stubs(:exec).with("dnsdomainname 2> /dev/null").returns(scenario[:dnsdomainname])
291
+ Facter::Core::Execution.stubs(:exec).with("hostname -f 2> /dev/null", {:on_fail => nil}).returns(scenario[:hostname])
292
+ Facter::Core::Execution.stubs(:exec).with("dnsdomainname 2> /dev/null", {:on_fail => nil}).returns(scenario[:dnsdomainname])
293
293
  resolv_conf_contains(
294
294
  "search #{scenario[:resolve_search]}",
295
295
  "domain #{scenario[:resolve_domain]}"
@@ -6,35 +6,35 @@ require 'facter'
6
6
  describe "Hardwareisa fact" do
7
7
  it "should match uname -p on Linux" do
8
8
  Facter.fact(:kernel).stubs(:value).returns("Linux")
9
- Facter::Core::Execution.stubs(:exec).with("uname -p").returns("Inky")
9
+ Facter::Core::Execution.stubs(:exec).with("uname -p", anything).returns("Inky")
10
10
 
11
11
  Facter.fact(:hardwareisa).value.should == "Inky"
12
12
  end
13
13
 
14
14
  it "should match uname -p on Darwin" do
15
15
  Facter.fact(:kernel).stubs(:value).returns("Darwin")
16
- Facter::Core::Execution.stubs(:exec).with("uname -p").returns("Blinky")
16
+ Facter::Core::Execution.stubs(:exec).with("uname -p", anything).returns("Blinky")
17
17
 
18
18
  Facter.fact(:hardwareisa).value.should == "Blinky"
19
19
  end
20
20
 
21
21
  it "should match uname -p on SunOS" do
22
22
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
23
- Facter::Core::Execution.stubs(:exec).with("uname -p").returns("Pinky")
23
+ Facter::Core::Execution.stubs(:exec).with("uname -p", anything).returns("Pinky")
24
24
 
25
25
  Facter.fact(:hardwareisa).value.should == "Pinky"
26
26
  end
27
27
 
28
28
  it "should match uname -p on FreeBSD" do
29
29
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
30
- Facter::Core::Execution.stubs(:exec).with("uname -p").returns("Clyde")
30
+ Facter::Core::Execution.stubs(:exec).with("uname -p", anything).returns("Clyde")
31
31
 
32
32
  Facter.fact(:hardwareisa).value.should == "Clyde"
33
33
  end
34
34
 
35
35
  it "should match uname -m on HP-UX" do
36
36
  Facter.fact(:kernel).stubs(:value).returns("HP-UX")
37
- Facter::Core::Execution.stubs(:exec).with("uname -m").returns("Pac-Man")
37
+ Facter::Core::Execution.stubs(:exec).with("uname -m", anything).returns("Pac-Man")
38
38
 
39
39
  Facter.fact(:hardwareisa).value.should == "Pac-Man"
40
40
  end
@@ -6,7 +6,7 @@ require 'facter'
6
6
  describe "Hardwaremodel fact" do
7
7
  it "should match uname -m by default" do
8
8
  Facter.fact(:kernel).stubs(:value).returns("Darwin")
9
- Facter::Core::Execution.stubs(:exec).with("uname -m").returns("Inky")
9
+ Facter::Core::Execution.stubs(:exec).with("uname -m", anything).returns("Inky")
10
10
 
11
11
  Facter.fact(:hardwaremodel).value.should == "Inky"
12
12
  end
@@ -23,7 +23,7 @@ describe "Hardwaremodel fact" do
23
23
  Facter::Util::WMI.expects(:execquery).returns([cpu])
24
24
 
25
25
  Facter.fact(:hardwaremodel).value.should == "i486"
26
- end
26
+ end
27
27
 
28
28
  it "should detect i686" do
29
29
  cpu = mock('cpu', :Architecture => 0, :Level => 6)
@@ -33,7 +33,7 @@ describe "Hostname facts" do
33
33
  end
34
34
 
35
35
  it "should use scutil to get the hostname" do
36
- Facter::Core::Execution.expects(:exec).with('/usr/sbin/scutil --get LocalHostName').returns("host1")
36
+ Facter::Core::Execution.expects(:exec).with('/usr/sbin/scutil --get LocalHostName', anything).returns("host1")
37
37
  Facter.fact(:hostname).value.should == "host1"
38
38
  end
39
39
  end
@@ -12,7 +12,7 @@ describe "id fact" do
12
12
  it "should return the current user" do
13
13
  given_a_configuration_of(:is_windows => k == 'windows')
14
14
  Facter.fact(:kernel).stubs(:value).returns(k)
15
- Facter::Core::Execution.expects(:exec).once.with('whoami').returns 'bar'
15
+ Facter::Core::Execution.expects(:exec).once.with('whoami', anything).returns 'bar'
16
16
 
17
17
  Facter.fact(:id).value.should == 'bar'
18
18
  end
@@ -22,7 +22,7 @@ describe "id fact" do
22
22
  it "should return the current user on Solaris" do
23
23
  given_a_configuration_of(:is_windows => false)
24
24
  Facter::Core::Execution.stubs(:exec).with('uname -s').returns('SunOS')
25
- Facter::Core::Execution.expects(:exec).once.with('/usr/xpg4/bin/id -un').returns 'bar'
25
+ Facter::Core::Execution.expects(:exec).once.with('/usr/xpg4/bin/id -un', anything).returns 'bar'
26
26
 
27
27
  Facter.fact(:id).value.should == 'bar'
28
28
  end
@@ -2,52 +2,52 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe "Kernel release fact" do
5
+ describe "Kernel release fact" do
6
6
 
7
- describe "on Windows" do
8
- before do
7
+ describe "on Windows" do
8
+ before do
9
9
  Facter.fact(:kernel).stubs(:value).returns("windows")
10
10
  require 'facter/util/wmi'
11
11
  version = stubs 'version'
12
12
  version.stubs(:Version).returns("test_kernel")
13
13
  Facter::Util::WMI.stubs(:execquery).with("SELECT Version from Win32_OperatingSystem").returns([version])
14
14
  end
15
-
16
- it "should return the kernel release" do
15
+
16
+ it "should return the kernel release" do
17
17
  Facter.fact(:kernelrelease).value.should == "test_kernel"
18
- end
19
- end
18
+ end
19
+ end
20
20
 
21
- describe "on AIX" do
22
- before do
21
+ describe "on AIX" do
22
+ before do
23
23
  Facter.fact(:kernel).stubs(:value).returns("aix")
24
- Facter::Core::Execution.stubs(:exec).with('oslevel -s').returns("test_kernel")
25
- end
26
-
27
- it "should return the kernel release" do
24
+ Facter::Core::Execution.stubs(:exec).with('oslevel -s', anything).returns("test_kernel")
25
+ end
26
+
27
+ it "should return the kernel release" do
28
28
  Facter.fact(:kernelrelease).value.should == "test_kernel"
29
- end
30
- end
29
+ end
30
+ end
31
31
 
32
32
  describe "on HP-UX" do
33
33
  before do
34
- Facter.fact(:kernel).stubs(:value).returns("hp-ux")
34
+ Facter.fact(:kernel).stubs(:value).returns("hp-ux")
35
35
  Facter::Core::Execution.stubs(:exec).with('uname -r').returns("B.11.31")
36
- end
37
-
36
+ end
37
+
38
38
  it "should remove preceding letters" do
39
39
  Facter.fact(:kernelrelease).value.should == "11.31"
40
- end
41
- end
40
+ end
41
+ end
42
42
 
43
- describe "on everything else" do
43
+ describe "on everything else" do
44
44
  before do
45
45
  Facter.fact(:kernel).stubs(:value).returns("linux")
46
- Facter::Core::Execution.stubs(:exec).with('uname -r').returns("test_kernel")
47
- end
48
-
46
+ Facter::Core::Execution.stubs(:exec).with('uname -r', anything).returns("test_kernel")
47
+ end
48
+
49
49
  it "should return the kernel release" do
50
50
  Facter.fact(:kernelrelease).value.should == "test_kernel"
51
- end
52
- end
53
- end
51
+ end
52
+ end
53
+ end
@@ -3,29 +3,29 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe "Kernel version fact" do
6
-
6
+
7
7
  describe "on Solaris/Sun OS" do
8
8
  before do
9
9
  Facter.fact(:kernel).stubs(:value).returns('sunos')
10
- Facter::Core::Execution.stubs(:exec).with('uname -v').returns("1.234.5")
11
- end
12
-
13
- it "should return the kernel version using 'uname -v'" do
10
+ Facter::Core::Execution.stubs(:exec).with('uname -v', anything).returns("1.234.5")
11
+ end
12
+
13
+ it "should return the kernel version using 'uname -v'" do
14
14
  Facter.fact(:kernelversion).value.should == "1.234.5"
15
- end
15
+ end
16
16
  end
17
-
17
+
18
18
  describe "on everything else" do
19
- before do
19
+ before do
20
20
  Facter.fact(:kernel).stubs(:value).returns('linux')
21
21
  Facter.fact(:kernelrelease).stubs(:value).returns('1.23.4-56')
22
- end
23
-
24
- it "should return the kernel version using kernel release" do
22
+ end
23
+
24
+ it "should return the kernel version using kernel release" do
25
25
  Facter.fact(:kernelversion).value.should == "1.23.4"
26
- end
26
+ end
27
27
  end
28
- end
28
+ end
29
29
 
30
30
 
31
31
 
@@ -15,6 +15,7 @@ describe "ldom fact" do
15
15
  before :each do
16
16
  # For virtinfo documentation:
17
17
  # http://docs.oracle.com/cd/E23824_01/html/821-1462/virtinfo-1m.html
18
+ Facter::Core::Execution.stubs(:which).with("virtinfo").returns 'virtinfo'
18
19
  Facter::Core::Execution.stubs(:exec).with("virtinfo -ap").
19
20
  returns(ldom_fixtures('ldom_v1'))
20
21
  Facter.collection.internal_loader.load(:ldom)
@@ -63,7 +64,7 @@ describe "ldom fact" do
63
64
 
64
65
  describe "when running on non ldom hardware" do
65
66
  before :each do
66
- Facter::Core::Execution.stubs(:exec).with("virtinfo -ap").returns(nil)
67
+ Facter::Core::Execution.stubs(:which).with("virtinfo").returns(nil)
67
68
  Facter.collection.internal_loader.load(:ldom)
68
69
  end
69
70
 
@@ -10,14 +10,14 @@ describe "lsbdistcodename fact" do
10
10
  Facter.fact(:kernel).stubs(:value).returns kernel
11
11
  end
12
12
 
13
- it "should return the codename through lsb_release -c -s 2>/dev/null" do
14
- Facter::Core::Execution.stubs(:exec).with('lsb_release -c -s 2>/dev/null').returns 'n/a'
15
- Facter.fact(:lsbdistcodename).value.should == 'n/a'
13
+ it "returns the codename through lsb_release -c -s 2>/dev/null" do
14
+ Facter::Core::Execution.impl.stubs(:exec).with('lsb_release -c -s 2>/dev/null', anything).returns 'n/a'
15
+ expect(Facter.fact(:lsbdistcodename).value).to eq 'n/a'
16
16
  end
17
17
 
18
- it "should return nil if lsb_release is not installed" do
19
- Facter::Core::Execution.stubs(:exec).with('lsb_release -c -s 2>/dev/null').returns nil
20
- Facter.fact(:lsbdistcodename).value.should be_nil
18
+ it "returns nil if lsb_release is not installed" do
19
+ Facter::Core::Execution.impl.stubs(:expand_command).with('lsb_release -c -s 2>/dev/null').returns nil
20
+ expect(Facter.fact(:lsbdistcodename).value).to be_nil
21
21
  end
22
22
  end
23
23
  end
@@ -10,16 +10,16 @@ describe "lsbdistdescription fact" do
10
10
  Facter.fact(:kernel).stubs(:value).returns kernel
11
11
  end
12
12
 
13
- it "should return the description through lsb_release -d -s 2>/dev/null" do
14
- Facter::Core::Execution.stubs(:exec).with('lsb_release -d -s 2>/dev/null').returns '"Gentoo Base System release 2.1"'
15
- Facter.fact(:lsbdistdescription).value.should == 'Gentoo Base System release 2.1'
13
+ it "returns the description through lsb_release -d -s 2>/dev/null" do
14
+ Facter::Core::Execution.stubs(:which).with('lsb_release').returns '/usr/bin/lsb_release'
15
+ Facter::Core::Execution.stubs(:exec).with('lsb_release -d -s 2>/dev/null', anything).returns '"Gentoo Base System release 2.1"'
16
+ expect(Facter.fact(:lsbdistdescription).value).to eq 'Gentoo Base System release 2.1'
16
17
  end
17
18
 
18
- it "should return nil if lsb_release is not installed" do
19
- Facter::Core::Execution.stubs(:exec).with('lsb_release -d -s 2>/dev/null').returns nil
20
- Facter.fact(:lsbdistdescription).value.should be_nil
19
+ it "returns nil if lsb_release is not installed" do
20
+ Facter::Core::Execution.stubs(:which).with('lsb_release').returns nil
21
+ expect(Facter.fact(:lsbdistdescription).value).to be_nil
21
22
  end
22
23
  end
23
24
  end
24
-
25
25
  end
@@ -10,14 +10,14 @@ describe "lsbdistid fact" do
10
10
  Facter.fact(:kernel).stubs(:value).returns kernel
11
11
  end
12
12
 
13
- it "should return the id through lsb_release -i -s 2>/dev/null" do
14
- Facter::Core::Execution.stubs(:exec).with('lsb_release -i -s 2>/dev/null').returns 'Gentoo'
15
- Facter.fact(:lsbdistid).value.should == 'Gentoo'
13
+ it "returns the id through lsb_release -i -s 2>/dev/null" do
14
+ Facter::Core::Execution.impl.stubs(:exec).with('lsb_release -i -s 2>/dev/null', anything).returns 'Gentoo'
15
+ expect(Facter.fact(:lsbdistid).value).to eq 'Gentoo'
16
16
  end
17
17
 
18
- it "should return nil if lsb_release is not installed 2>/dev/null" do
19
- Facter::Core::Execution.stubs(:exec).with('lsb_release -i -s 2>/dev/null').returns nil
20
- Facter.fact(:lsbdistid).value.should be_nil
18
+ it "returns nil if lsb_release is not installed" do
19
+ Facter::Core::Execution.impl.stubs(:expand_command).with('lsb_release -i -s 2>/dev/null').returns nil
20
+ expect(Facter.fact(:lsbdistid).value).to be_nil
21
21
  end
22
22
  end
23
23
  end
@@ -11,12 +11,12 @@ describe "lsbdistrelease fact" do
11
11
  end
12
12
 
13
13
  it "should return the release through lsb_release -r -s 2>/dev/null" do
14
- Facter::Core::Execution.stubs(:exec).with('lsb_release -r -s 2>/dev/null').returns '2.1'
14
+ Facter::Core::Execution.stubs(:exec).with('lsb_release -r -s 2>/dev/null', anything).returns '2.1'
15
15
  Facter.fact(:lsbdistrelease).value.should == '2.1'
16
16
  end
17
17
 
18
18
  it "should return nil if lsb_release is not installed" do
19
- Facter::Core::Execution.stubs(:exec).with('lsb_release -r -s 2>/dev/null').returns nil
19
+ Facter::Core::Execution.stubs(:exec).with('lsb_release -r -s 2>/dev/null', anything).returns nil
20
20
  Facter.fact(:lsbdistrelease).value.should be_nil
21
21
  end
22
22
  end
@@ -10,14 +10,14 @@ describe "lsbrelease fact" do
10
10
  Facter.fact(:kernel).stubs(:value).returns kernel
11
11
  end
12
12
 
13
- it "should return the release through lsb_release -v -s 2>/dev/null" do
14
- Facter::Core::Execution.stubs(:exec).with('lsb_release -v -s 2>/dev/null').returns 'n/a'
15
- Facter.fact(:lsbrelease).value.should == 'n/a'
13
+ it "returns the release through lsb_release -v -s 2>/dev/null" do
14
+ Facter::Core::Execution.impl.stubs(:exec).with('lsb_release -v -s 2>/dev/null', anything).returns 'n/a'
15
+ expect(Facter.fact(:lsbrelease).value).to eq 'n/a'
16
16
  end
17
17
 
18
- it "should return nil if lsb_release is not installed" do
19
- Facter::Core::Execution.stubs(:exec).with('lsb_release -v -s 2>/dev/null').returns nil
20
- Facter.fact(:lsbrelease).value.should be_nil
18
+ it "returns nil if lsb_release is not installed" do
19
+ Facter::Core::Execution.impl.stubs(:expand_command).with('lsb_release -v -s 2>/dev/null').returns nil
20
+ expect(Facter.fact(:lsbrelease).value).to be_nil
21
21
  end
22
22
  end
23
23
  end
@@ -185,35 +185,35 @@ describe "Processor facts" do
185
185
 
186
186
  it "should be 2 on dual-processor Darwin box" do
187
187
  Facter.fact(:kernel).stubs(:value).returns("Darwin")
188
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
188
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu", anything).returns('2')
189
189
 
190
190
  Facter.fact(:processorcount).value.should == "2"
191
191
  end
192
192
 
193
193
  it "should be 2 on dual-processor OpenBSD box" do
194
194
  Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
195
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
195
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu", anything).returns('2')
196
196
 
197
197
  Facter.fact(:processorcount).value.should == "2"
198
198
  end
199
199
 
200
200
  it "should be 2 on dual-processor FreeBSD box" do
201
201
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
202
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
202
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu", anything).returns('2')
203
203
 
204
204
  Facter.fact(:processorcount).value.should == "2"
205
205
  end
206
206
 
207
207
  it "should print the correct CPU Model on FreeBSD" do
208
208
  Facter.fact(:kernel).stubs(:value).returns("FreeBSD")
209
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.model").returns('SomeVendor CPU 3GHz')
209
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.model", anything).returns('SomeVendor CPU 3GHz')
210
210
 
211
211
  Facter.fact(:processor).value.should == "SomeVendor CPU 3GHz"
212
212
  end
213
213
 
214
214
  it "should be 2 on dual-processor DragonFly box" do
215
215
  Facter.fact(:kernel).stubs(:value).returns("DragonFly")
216
- Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
216
+ Facter::Core::Execution.stubs(:exec).with("sysctl -n hw.ncpu", anything).returns('2')
217
217
 
218
218
  Facter.fact(:processorcount).value.should == "2"
219
219
  end
@@ -6,21 +6,21 @@ require 'facter'
6
6
  describe "Uniqueid fact" do
7
7
  it "should match hostid on Solaris" do
8
8
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
9
- Facter::Core::Execution.stubs(:exec).with("hostid").returns("Larry")
9
+ Facter::Core::Execution.stubs(:exec).with("hostid", anything).returns("Larry")
10
10
 
11
11
  Facter.fact(:uniqueid).value.should == "Larry"
12
12
  end
13
13
 
14
14
  it "should match hostid on Linux" do
15
15
  Facter.fact(:kernel).stubs(:value).returns("Linux")
16
- Facter::Core::Execution.stubs(:exec).with("hostid").returns("Curly")
16
+ Facter::Core::Execution.stubs(:exec).with("hostid", anything).returns("Curly")
17
17
 
18
18
  Facter.fact(:uniqueid).value.should == "Curly"
19
19
  end
20
20
 
21
21
  it "should match hostid on AIX" do
22
22
  Facter.fact(:kernel).stubs(:value).returns("AIX")
23
- Facter::Core::Execution.stubs(:exec).with("hostid").returns("Moe")
23
+ Facter::Core::Execution.stubs(:exec).with("hostid", anything).returns("Moe")
24
24
 
25
25
  Facter.fact(:uniqueid).value.should == "Moe"
26
26
  end
@@ -401,10 +401,13 @@ describe Facter::Util::IP do
401
401
 
402
402
  describe "exec_ifconfig" do
403
403
  it "uses get_ifconfig" do
404
+ Facter::Core::Execution.stubs(:exec)
405
+
404
406
  Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig").once
405
407
 
406
408
  Facter::Util::IP.exec_ifconfig
407
409
  end
410
+
408
411
  it "support additional arguments" do
409
412
  Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
410
413
 
@@ -412,6 +415,7 @@ describe Facter::Util::IP do
412
415
 
413
416
  Facter::Util::IP.exec_ifconfig(["-a"])
414
417
  end
418
+
415
419
  it "joins multiple arguments correctly" do
416
420
  Facter::Util::IP.stubs(:get_ifconfig).returns("/sbin/ifconfig")
417
421
 
@@ -74,7 +74,7 @@ describe Facter::Util::Resolution do
74
74
  describe "and the code is a string" do
75
75
  it "returns the result of executing the code" do
76
76
  resolution.setcode "/bin/foo"
77
- Facter::Core::Execution.expects(:exec).once.with("/bin/foo").returns "yup"
77
+ Facter::Core::Execution.expects(:exec).once.with("/bin/foo", anything).returns "yup"
78
78
 
79
79
  expect(resolution.value).to eq "yup"
80
80
  end
@@ -47,7 +47,7 @@ describe Facter::Util::SolarisZones do
47
47
 
48
48
  describe '#refresh' do
49
49
  it 'executes the zoneadm_cmd' do
50
- Facter::Core::Execution.expects(:exec).with(subject.zoneadm_cmd).returns(zone_list)
50
+ Facter::Core::Execution.expects(:exec).with(subject.zoneadm_cmd, {:on_fail => nil}).returns(zone_list)
51
51
  subject.refresh
52
52
  end
53
53
  end
@@ -112,7 +112,7 @@ describe Facter::Util::SolarisZones do
112
112
 
113
113
  def given_initial_zone_facts
114
114
  Facter::Core::Execution.stubs(:exec).
115
- with(subject.zoneadm_cmd).
115
+ with(subject.zoneadm_cmd, {:on_fail => nil}).
116
116
  returns(zone_list)
117
117
  described_class.add_facts
118
118
  end
@@ -99,14 +99,14 @@ describe Facter::Util::Uptime do
99
99
 
100
100
  test_cases.each do |uptime, expected|
101
101
  it "should return #{expected} for #{uptime}" do
102
- Facter::Core::Execution.stubs(:exec).with('uptime 2>/dev/null').returns(uptime)
102
+ Facter::Core::Execution.stubs(:exec).with('uptime 2>/dev/null', {:on_fail => nil}).returns(uptime)
103
103
  Facter.fact(:uptime_seconds).value.should == expected
104
104
  end
105
105
  end
106
106
 
107
107
  describe "nor is 'uptime' command" do
108
108
  before :each do
109
- Facter::Util::Uptime.stubs(:uptime_executable_cmd).returns("cat \"#{@nonexistent_file}\"")
109
+ Facter::Core::Execution.stubs(:exec).with('uptime 2>/dev/null', {:on_fail => nil}).returns(nil)
110
110
  end
111
111
 
112
112
  it "should return nil" do
@@ -4,9 +4,39 @@ require 'spec_helper'
4
4
  require 'facter/util/vlans'
5
5
 
6
6
  describe Facter::Util::Vlans do
7
- it "should return a list of vlans on Linux" do
8
- linux_vlanconfig = my_fixture_read("linux_vlan_config")
9
- Facter::Util::Vlans.stubs(:get_vlan_config).returns(linux_vlanconfig)
10
- Facter::Util::Vlans.get_vlans().should == %{400,300,200,100}
7
+ let(:vlan_file) { "/proc/net/vlan/config" }
8
+
9
+ describe "reading the vlan configuration" do
10
+ it "uses the contents of /proc/net/vlan/config" do
11
+ File.expects(:exist?).with(vlan_file).returns true
12
+ File.expects(:readable?).with(vlan_file).returns true
13
+ File.expects(:read).with(vlan_file).returns "vlan contents here"
14
+
15
+ expect(Facter::Util::Vlans.get_vlan_config).to eq "vlan contents here"
16
+ end
17
+
18
+ it "returns nil when /proc/net/vlan/config is absent" do
19
+ File.expects(:exist?).with(vlan_file).returns false
20
+ expect(Facter::Util::Vlans.get_vlan_config).to be_nil
21
+ end
22
+ end
23
+
24
+ describe "parsing the vlan configuration" do
25
+ let(:vlan_content) { my_fixture_read("linux_vlan_config") }
26
+
27
+ it "returns a list of vlans on Linux when vlans are configured" do
28
+ Facter::Util::Vlans.stubs(:get_vlan_config).returns(vlan_content)
29
+ expect(Facter::Util::Vlans.get_vlans()).to eq %{400,300,200,100}
30
+ end
31
+
32
+ it "returns nil when no vlans are configured" do
33
+ Facter::Util::Vlans.stubs(:get_vlan_config).returns(nil)
34
+ expect(Facter::Util::Vlans.get_vlans()).to be_nil
35
+ end
36
+
37
+ it "returns nil when only the vlan header is returned" do
38
+ Facter::Util::Vlans.stubs(:get_vlan_config).returns(my_fixture_read("centos-5-no-vlans"))
39
+ expect(Facter::Util::Vlans.get_vlans()).to be_nil
40
+ end
11
41
  end
12
42
  end
@@ -7,7 +7,7 @@ describe "zonename fact" do
7
7
 
8
8
  it "should return global zone" do
9
9
  Facter.fact(:kernel).stubs(:value).returns("SunOS")
10
- Facter::Core::Execution.stubs(:exec).with("zonename").returns('global')
10
+ Facter::Core::Execution.stubs(:exec).with("zonename", anything).returns('global')
11
11
 
12
12
  Facter.fact(:zonename).value.should == "global"
13
13
  end
@@ -10,7 +10,7 @@ describe "on Solaris" do
10
10
  -:local:configured:/::native:shared
11
11
  -:zoneA:stopped:/::native:shared
12
12
  EOF
13
- Facter::Core::Execution.stubs(:exec).with('/usr/sbin/zoneadm list -cp').returns(zone_list)
13
+ Facter::Core::Execution.stubs(:exec).with('/usr/sbin/zoneadm list -cp', {:on_fail => nil}).returns(zone_list)
14
14
  Facter.collection.internal_loader.load(:zones)
15
15
  end
16
16
 
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: 2.0.1.rc1
4
+ version: 2.0.1.rc2
5
5
  platform: universal-darwin
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-28 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: CFPropertyList
@@ -300,6 +300,7 @@ files:
300
300
  - spec/fixtures/unit/util/uptime/ubuntu_proc_uptime
301
301
  - spec/fixtures/unit/util/virtual/invalid_unicode_dmi_entries
302
302
  - spec/fixtures/unit/util/virtual/solaris10_proc_self_status1
303
+ - spec/fixtures/unit/util/vlans/centos-5-no-vlans
303
304
  - spec/fixtures/unit/util/vlans/linux_vlan_config
304
305
  - spec/fixtures/unit/util/xendomains/xendomains
305
306
  - spec/fixtures/unit/virtual/sysfs_dmi_entries_raw.txt
@@ -564,6 +565,7 @@ test_files:
564
565
  - spec/fixtures/unit/util/uptime/ubuntu_proc_uptime
565
566
  - spec/fixtures/unit/util/virtual/invalid_unicode_dmi_entries
566
567
  - spec/fixtures/unit/util/virtual/solaris10_proc_self_status1
568
+ - spec/fixtures/unit/util/vlans/centos-5-no-vlans
567
569
  - spec/fixtures/unit/util/vlans/linux_vlan_config
568
570
  - spec/fixtures/unit/util/xendomains/xendomains
569
571
  - spec/fixtures/unit/virtual/sysfs_dmi_entries_raw.txt