facter 2.3.0-universal-darwin → 2.4.0-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.

@@ -31,6 +31,13 @@ module Facter::Util::IP
31
31
  :macaddress => /(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/,
32
32
  :netmask => /.*\s+netmask (\S+)\s.*/
33
33
  },
34
+ :aix => {
35
+ :ipaddress => /inet\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/,
36
+ :ipaddress6 => /inet6 ((?![fe80|::1])(?>[0-9,a-f,A-F]*\:{1,2})+[0-9,a-f,A-F]{0,4})/,
37
+ :netmask => /netmask\s+0x(\w{8})/,
38
+ :mtu => /mtu\s+(\d+)/,
39
+ :macaddress => /^Hardware\sAddress:\s(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
40
+ },
34
41
  :windows => {}
35
42
  }
36
43
 
@@ -40,7 +47,7 @@ module Facter::Util::IP
40
47
  end
41
48
 
42
49
  def self.convert_from_hex?(kernel)
43
- kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux", :"gnu/kfreebsd", :dragonfly]
50
+ kernels_to_convert = [:sunos, :openbsd, :netbsd, :freebsd, :darwin, :"hp-ux", :"gnu/kfreebsd", :dragonfly, :aix]
44
51
  kernels_to_convert.include?(kernel)
45
52
  end
46
53
 
@@ -73,7 +80,7 @@ module Facter::Util::IP
73
80
 
74
81
  def self.get_all_interface_output
75
82
  case Facter.value(:kernel)
76
- when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly'
83
+ when 'Linux', 'OpenBSD', 'NetBSD', 'FreeBSD', 'Darwin', 'GNU/kFreeBSD', 'DragonFly', 'AIX'
77
84
  output = Facter::Util::IP.exec_ifconfig(["-a","2>/dev/null"])
78
85
  when 'SunOS'
79
86
  output = Facter::Util::IP.exec_ifconfig(["-a"])
@@ -106,6 +113,23 @@ module Facter::Util::IP
106
113
  common_paths=["/bin/ifconfig","/sbin/ifconfig","/usr/sbin/ifconfig"]
107
114
  common_paths.select{|path| File.executable?(path)}.first
108
115
  end
116
+
117
+ ##
118
+ # exec_netstat uses the netstat command
119
+ #
120
+ # @return [String] the output of `netstat #{arguments} 2>/dev/null` or nil
121
+ def self.exec_netstat(additional_arguments=[])
122
+ Facter::Core::Execution.exec("#{self.get_netstat} #{additional_arguments.join(' ')}")
123
+ end
124
+ ##
125
+ # get_netstat looks up the netstat binary
126
+ #
127
+ # @return [String] path to the netstat binary
128
+ def self.get_netstat
129
+ common_paths=["/bin/netstat","/sbin/netstat","/usr/sbin/netstat","/usr/bin/netstat"]
130
+ common_paths.select{|path| File.executable?(path)}.first
131
+ end
132
+
109
133
  ##
110
134
  # hpux_netstat_in is a delegate method that allows us to stub netstat -in
111
135
  # without stubbing exec.
@@ -117,7 +141,7 @@ module Facter::Util::IP
117
141
  if File.exists?("/sys/class/net/#{interface}/address") then
118
142
  ib_mac_address = `cat /sys/class/net/#{interface}/address`.chomp
119
143
  elsif File.exists?("/sbin/ip") then
120
- ip_output = %x{/sbin/ip link show #{interface}}
144
+ ip_output = %x{/sbin/ip link show '#{interface}'}
121
145
  ib_mac_address = ip_output.scan(%r{infiniband\s+((\w{1,2}:){5,}\w{1,2})})
122
146
  else
123
147
  ib_mac_address = "FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF:FF"
@@ -127,7 +151,7 @@ module Facter::Util::IP
127
151
  end
128
152
 
129
153
  def self.ifconfig_interface(interface)
130
- output = Facter::Util::IP.exec_ifconfig([interface,"2>/dev/null"])
154
+ output = Facter::Util::IP.exec_ifconfig(["'#{interface}'","2>/dev/null"])
131
155
  end
132
156
 
133
157
  def self.get_single_interface_output(interface)
@@ -151,6 +175,9 @@ module Facter::Util::IP
151
175
  hpux_lanscan.scan(/(\dx\S+).*UP\s+(\w+\d+)/).each {|i| mac = i[0] if i.include?(interface) }
152
176
  mac = mac.sub(/0x(\S+)/,'\1').scan(/../).join(":")
153
177
  output = ifc + "\n" + mac
178
+ when 'AIX'
179
+ output = Facter::Util::IP.ifconfig_interface(interface) + "\n" + aix_get_mtu(interface) + "\n" + aix_get_macadress(interface)
180
+ output
154
181
  end
155
182
  output
156
183
  end
@@ -163,6 +190,34 @@ module Facter::Util::IP
163
190
  Facter::Core::Execution.exec("/usr/sbin/lanscan")
164
191
  end
165
192
 
193
+ def self.aix_lsattr_interface(interface)
194
+ Facter::Core::Execution.exec("/usr/sbin/lsattr -El #{interface}")
195
+ end
196
+
197
+ def self.aix_entstat_interface(interface)
198
+ if interface[0..1] != "lo"
199
+ Facter::Core::Execution.exec("/usr/bin/entstat #{interface}")
200
+ else
201
+ return ""
202
+ end
203
+ end
204
+
205
+ def self.aix_get_mtu(interface)
206
+ aix_lsattr_interface(interface).each_line do |s|
207
+ if s =~ /mtu\s+(\d+)/
208
+ return s
209
+ end
210
+ end
211
+ end
212
+
213
+ def self.aix_get_macadress(interface)
214
+ aix_entstat_interface(interface).each_line do |s|
215
+ if s =~ /^Hardware\sAddress:\s(\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2}:\w{1,2})/
216
+ return s
217
+ end
218
+ end
219
+ end
220
+
166
221
  def self.get_output_for_interface_and_label(interface, label)
167
222
  return get_single_interface_output(interface) unless Facter.value(:kernel) == 'windows'
168
223
 
@@ -188,7 +243,7 @@ module Facter::Util::IP
188
243
  return nil
189
244
  end
190
245
  regex = /SLAVE[,>].* (bond[0-9]+)/
191
- ethbond = regex.match(%x{/sbin/ip link show #{interface}})
246
+ ethbond = regex.match(%x{/sbin/ip link show '#{interface}'})
192
247
  if ethbond
193
248
  device = ethbond[1]
194
249
  else
@@ -43,8 +43,8 @@ class Facter::Util::IP::Windows
43
43
  interface_names = []
44
44
 
45
45
  network_adapter_configurations.map do |nic|
46
- Facter::Util::WMI.execquery("SELECT * FROM Win32_NetworkAdapter WHERE Index = #{nic.Index} AND NetEnabled = TRUE").each do |nic|
47
- interface_names << nic.NetConnectionId unless nic.NetConnectionId.nil? or nic.NetConnectionId.empty?
46
+ Facter::Util::WMI.execquery("SELECT * FROM Win32_NetworkAdapter WHERE Index = #{nic.Index} AND NetEnabled = TRUE").each do |sub_nic|
47
+ interface_names << sub_nic.NetConnectionId unless sub_nic.NetConnectionId.nil? or sub_nic.NetConnectionId.empty?
48
48
  end
49
49
  end
50
50
 
@@ -37,6 +37,10 @@ module Facter::Util::Partitions
37
37
  implementation.filesystem(partition)
38
38
  end
39
39
 
40
+ def self.label(partition)
41
+ implementation.label(partition)
42
+ end
43
+
40
44
  def self.available?
41
45
  !self.list.empty?
42
46
  end
@@ -55,6 +55,12 @@ module Facter::Util::Partitions
55
55
  end
56
56
  end
57
57
 
58
+ def self.label(partition)
59
+ if Facter::Core::Execution.which('blkid')
60
+ Facter::Core::Execution.exec("blkid #{File.join('/dev', partition)}").scan(/LABEL="([^"]*)"/).flatten.first
61
+ end
62
+ end
63
+
58
64
  private
59
65
  def self.read_size(partition)
60
66
  if device = partition.match(/(\D+)/)[1] and File.readable?(File.join(SYSFS_BLOCK_DIRECTORY, device, partition, 'size'))
@@ -22,6 +22,11 @@ module Facter::Util::Partitions
22
22
  def self.filesystem(partition)
23
23
  scan_mount(/\/dev\/#{partition}\son\s\S+\stype\s(\S+)/)
24
24
  end
25
+
26
+ # On OpenBSD there are no labels for partitions
27
+ def self.label(partition)
28
+ nil
29
+ end
25
30
 
26
31
  private
27
32
  def self.scan_mount(scan_regex)
@@ -25,7 +25,7 @@ class Facter::Util::Resolution
25
25
 
26
26
  class << self
27
27
  # Expose command execution methods that were extracted into
28
- # Facter::Util::Execution from Facter::Util::Resolution in Facter 2.0.0 for
28
+ # Facter::Core::Execution from Facter::Util::Resolution in Facter 2.0.0 for
29
29
  # compatibility.
30
30
  #
31
31
  # @deprecated
@@ -40,7 +40,7 @@ module Facter::Util::Uptime
40
40
 
41
41
  if output
42
42
  up=0
43
- if output =~ /(\d+) day(?:s|\(s\))?,\s+(\d+):(\d+)/
43
+ if output =~ /(\d+) day(?:s|\(s\))?,?\s+(\d+):-?(\d+)/
44
44
  # Regexp handles Solaris, AIX, HP-UX, and Tru64.
45
45
  # 'day(?:s|\(s\))?' says maybe 'day', 'days',
46
46
  # or 'day(s)', and don't set $2.
@@ -51,9 +51,10 @@ module Facter::Util::Uptime
51
51
  up=86400*$1.to_i + 60*$2.to_i
52
52
  elsif output =~ /(\d+) day(?:s|\(s\))?,/
53
53
  up=86400*$1.to_i
54
- elsif output =~ /up\s+(\d+):(\d+),/
54
+ elsif output =~ /up\s+(\d+):-?(\d+),/
55
55
  # must anchor to 'up' to avoid matching time of day
56
- # at beginning of line.
56
+ # at beginning of line. Certain versions of uptime on
57
+ # Solaris may insert a '-' into the minutes field.
57
58
  up=3600*$1.to_i + 60*$2.to_i
58
59
  elsif output =~ /(\d+) hr(?:s|\(s\))?,/
59
60
  up=3600*$1.to_i
@@ -77,6 +78,6 @@ module Facter::Util::Uptime
77
78
  end
78
79
 
79
80
  def self.uptime_executable_cmd
80
- "/usr/bin/uptime"
81
+ "uptime"
81
82
  end
82
83
  end
@@ -153,7 +153,13 @@ module Facter::Util::Virtual
153
153
  def self.lxc?
154
154
  path = Pathname.new('/proc/1/cgroup')
155
155
  return false unless path.readable?
156
- in_lxc = path.readlines.any? {|l| l.split(":")[2].to_s.start_with? '/lxc/' }
156
+ begin
157
+ in_lxc = path.readlines.any? {|l| l.split(":")[2].to_s.start_with? '/lxc/' }
158
+ rescue Errno::EPERM => exc
159
+ # If we get "operation not permitted" here, it probably means we are
160
+ # running OpenVZ. We are not running LXC anyway, so...
161
+ return false
162
+ end
157
163
  return true if in_lxc
158
164
  return false
159
165
  end
@@ -164,7 +170,12 @@ module Facter::Util::Virtual
164
170
  def self.docker?
165
171
  path = Pathname.new('/proc/1/cgroup')
166
172
  return false unless path.readable?
167
- in_docker = path.readlines.any? {|l| l.split(":")[2].to_s.start_with? '/docker/' }
173
+ begin
174
+ in_docker = path.readlines.any? {|l| l.split(":")[2].to_s.start_with? '/docker/' }
175
+ rescue Errno::EPERM => exc
176
+ # This can fail under OpenVZ, just like in .lxc?
177
+ return false
178
+ end
168
179
  return true if in_docker
169
180
  return false
170
181
  end
@@ -1,6 +1,6 @@
1
1
  module Facter
2
2
  if not defined? FACTERVERSION then
3
- FACTERVERSION = '2.3.0'
3
+ FACTERVERSION = '2.4.0'
4
4
  end
5
5
 
6
6
  # Returns the running version of Facter.
@@ -131,7 +131,7 @@ Facter.add("virtual") do
131
131
 
132
132
  if Facter::Util::Virtual.xen?
133
133
  next "xen0" if FileTest.exists?("/dev/xen/evtchn")
134
- next "xenu" if FileTest.exists?("/proc/xen")
134
+ next "xenu" if FileTest.exists?("/proc/xen") || FileTest.exists?("/dev/xvda1")
135
135
  end
136
136
 
137
137
  next "virtualbox" if Facter::Util::Virtual.virtualbox?
@@ -8,6 +8,7 @@ describe Facter::Core::Logging do
8
8
  after(:all) do
9
9
  subject.debugging(false)
10
10
  subject.timing(false)
11
+ subject.on_message
11
12
  end
12
13
 
13
14
  describe "emitting debug messages" do
@@ -101,4 +102,122 @@ describe Facter::Core::Logging do
101
102
  expect(subject.timing?).to be_false
102
103
  end
103
104
  end
105
+
106
+ describe 'without a logging callback' do
107
+ before :each do
108
+ subject.timing(true)
109
+ subject.debugging(true)
110
+ subject.on_message
111
+ end
112
+
113
+ it 'calls puts for debug' do
114
+ subject.expects(:puts).with(subject::GREEN + 'foo' + subject::RESET).once
115
+ subject.debug('foo')
116
+ end
117
+
118
+ it 'calls puts for debugonce' do
119
+ subject.expects(:puts).with(subject::GREEN + 'foo' + subject::RESET).once
120
+ subject.debugonce('foo')
121
+ subject.debugonce('foo')
122
+ end
123
+
124
+ it 'calls Kernel.warn for warn' do
125
+ Kernel.expects(:warn).with('foo').once
126
+ subject.warn('foo')
127
+ end
128
+
129
+ it 'calls Kernel.warn for warnonce' do
130
+ Kernel.expects(:warn).with('foo').once
131
+ subject.warnonce('foo')
132
+ subject.warnonce('foo')
133
+ end
134
+
135
+ it 'calls $stderr.puts for timing' do
136
+ $stderr.expects(:puts).with(subject::GREEN + 'foo' + subject::RESET).once
137
+ subject.show_time('foo')
138
+ end
139
+ end
140
+
141
+ describe 'with a logging callback' do
142
+ before :each do
143
+ subject.debugging(true)
144
+ subject.timing(true)
145
+ subject.on_message
146
+ end
147
+
148
+ def log_message(level, message)
149
+ called = false
150
+ subject.on_message do |lvl, msg|
151
+ called = true
152
+ expect(lvl).to eq(level)
153
+ expect(msg).to eq(message)
154
+ end
155
+ case level
156
+ when :debug
157
+ Facter.debug(message)
158
+ when :warn
159
+ Facter.warn(message)
160
+ when :info
161
+ Facter.show_time(message)
162
+ else
163
+ raise 'unexpected logging level'
164
+ end
165
+ subject.on_message
166
+ expect(called).to be_true
167
+ end
168
+
169
+ def log_message_once(level, message)
170
+ calls = 0
171
+ subject.on_message do |lvl, msg|
172
+ expect(lvl).to eq(level)
173
+ expect(msg).to eq(message)
174
+ calls += 1
175
+ end
176
+ case level
177
+ when :debug
178
+ Facter.debugonce(message)
179
+ Facter.debugonce(message)
180
+ when :warn
181
+ Facter.warnonce(message)
182
+ Facter.warnonce(message)
183
+ else
184
+ raise 'unexpected logging level'
185
+ end
186
+ expect(calls).to eq(1)
187
+ end
188
+
189
+ it 'does not call puts for debug or debugonce' do
190
+ subject.on_message {}
191
+ subject.expects(:puts).never
192
+ subject.debug('debug message')
193
+ subject.debugonce('debug once message')
194
+ end
195
+
196
+ it 'passes debug messages to callback' do
197
+ log_message(:debug, 'debug message')
198
+ log_message_once(:debug, 'debug once message')
199
+ end
200
+
201
+ it 'does not call Kernel.warn for warn or warnonce' do
202
+ subject.on_message {}
203
+ Kernel.expects(:warn).never
204
+ subject.warn('warn message')
205
+ subject.warnonce('warn once message')
206
+ end
207
+
208
+ it 'passes warning messages to callback' do
209
+ log_message(:warn, 'warn message')
210
+ log_message_once(:warn, 'warn once message')
211
+ end
212
+
213
+ it 'does not call $stderr.puts for show_time' do
214
+ subject.on_message {}
215
+ $stderr.expects(:puts).never
216
+ subject.show_time('debug message')
217
+ end
218
+
219
+ it 'passes info messages to callback' do
220
+ log_message(:info, 'timing message')
221
+ end
222
+ end
104
223
  end
@@ -18,6 +18,7 @@ describe "DHCP server facts" do
18
18
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices"))
19
19
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d list iface eth0").returns(my_fixture_read("nmcli_eth0_dhcp"))
20
20
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d list iface wlan0").returns(my_fixture_read("nmcli_wlan0_dhcp"))
21
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE nm 2>/dev/null').returns("connected\n")
21
22
  end
22
23
 
23
24
  it "should produce a dhcp_servers fact that includes values for 'system' as well as each dhcp enabled interface" do
@@ -30,6 +31,7 @@ describe "DHCP server facts" do
30
31
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices"))
31
32
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d list iface eth0").returns(my_fixture_read("nmcli_eth0_static"))
32
33
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d list iface wlan0").returns(my_fixture_read("nmcli_wlan0_dhcp"))
34
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE nm 2>/dev/null').returns("connected\n")
33
35
  end
34
36
 
35
37
  it "should a dhcp_servers fact that includes values for each dhcp enables interface and NO 'system' value" do
@@ -43,6 +45,7 @@ describe "DHCP server facts" do
43
45
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices"))
44
46
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d list iface eth0").returns(my_fixture_read("nmcli_eth0_dhcp"))
45
47
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d list iface wlan0").returns(my_fixture_read("nmcli_wlan0_dhcp"))
48
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE nm 2>/dev/null').returns("connected\n")
46
49
  end
47
50
 
48
51
  it "should a dhcp_servers fact that includes values for each dhcp enables interface and NO 'system' value" do
@@ -55,6 +58,7 @@ describe "DHCP server facts" do
55
58
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices"))
56
59
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d list iface eth0").returns(my_fixture_read("nmcli_eth0_static"))
57
60
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d list iface wlan0").returns(my_fixture_read("nmcli_wlan0_static"))
61
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE nm 2>/dev/null').returns("connected\n")
58
62
  end
59
63
 
60
64
  it "should not produce a dhcp_servers fact" do
@@ -65,6 +69,7 @@ describe "DHCP server facts" do
65
69
  describe "with no CONNECTED devices" do
66
70
  before :each do
67
71
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices_disconnected"))
72
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE nm 2>/dev/null').returns("disconnected\n")
68
73
  end
69
74
 
70
75
  it "should not produce a dhcp_servers fact" do
@@ -84,6 +89,7 @@ describe "DHCP server facts" do
84
89
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices"))
85
90
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d show eth0").returns(my_fixture_read("nmcli_eth0_dhcp"))
86
91
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d show wlan0").returns(my_fixture_read("nmcli_wlan0_dhcp"))
92
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE g 2>/dev/null').returns("connected\n")
87
93
  end
88
94
 
89
95
  it "should produce a dhcp_servers fact that includes values for 'system' as well as each dhcp enabled interface" do
@@ -96,6 +102,7 @@ describe "DHCP server facts" do
96
102
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices"))
97
103
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d show eth0").returns(my_fixture_read("nmcli_eth0_static"))
98
104
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d show wlan0").returns(my_fixture_read("nmcli_wlan0_dhcp"))
105
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE g 2>/dev/null').returns("connected\n")
99
106
  end
100
107
 
101
108
  it "should a dhcp_servers fact that includes values for each dhcp enables interface and NO 'system' value" do
@@ -109,6 +116,7 @@ describe "DHCP server facts" do
109
116
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices"))
110
117
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d show eth0").returns(my_fixture_read("nmcli_eth0_dhcp"))
111
118
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d show wlan0").returns(my_fixture_read("nmcli_wlan0_dhcp"))
119
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE g 2>/dev/null').returns("connected\n")
112
120
  end
113
121
 
114
122
  it "should a dhcp_servers fact that includes values for each dhcp enables interface and NO 'system' value" do
@@ -121,6 +129,7 @@ describe "DHCP server facts" do
121
129
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices"))
122
130
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d show eth0").returns(my_fixture_read("nmcli_eth0_static"))
123
131
  Facter::Core::Execution.stubs(:exec).with("nmcli -f all d show wlan0").returns(my_fixture_read("nmcli_wlan0_static"))
132
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE g 2>/dev/null').returns("connected\n")
124
133
  end
125
134
 
126
135
  it "should not produce a dhcp_servers fact" do
@@ -131,6 +140,7 @@ describe "DHCP server facts" do
131
140
  describe "with no CONNECTED devices" do
132
141
  before :each do
133
142
  Facter::Core::Execution.stubs(:exec).with("nmcli d").returns(my_fixture_read("nmcli_devices_disconnected"))
143
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE g 2>/dev/null').returns("disconnected\n")
134
144
  end
135
145
 
136
146
  it "should not produce a dhcp_servers fact" do
@@ -139,6 +149,34 @@ describe "DHCP server facts" do
139
149
  end
140
150
  end
141
151
 
152
+ describe 'without NetworkManager running' do
153
+ before :each do
154
+ Facter::Core::Execution.stubs(:which).with('nmcli').returns('/usr/bin/nmcli')
155
+ end
156
+
157
+ describe 'with nmcli version >= 0.9.9 available' do
158
+ before :each do
159
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE g 2>/dev/null').returns("unknown\n")
160
+ Facter::Core::Execution.stubs(:exec).with('nmcli --version').returns('nmcli tool, version 0.9.9.0')
161
+ end
162
+
163
+ it 'should not produce a dhcp_servers fact' do
164
+ Facter.fact(:dhcp_servers).value.should be_nil
165
+ end
166
+ end
167
+
168
+ describe 'with nmcli version <= 0.9.8 available' do
169
+ before :each do
170
+ Facter::Core::Execution.stubs(:exec).with('nmcli -t -f STATE nm 2>/dev/null').returns("unknown\n")
171
+ Facter::Core::Execution.stubs(:exec).with('nmcli --version').returns('nmcli tool, version 0.9.7.0')
172
+ end
173
+
174
+ it 'should not produce a dhcp_servers fact' do
175
+ Facter.fact(:dhcp_servers).value.should be_nil
176
+ end
177
+ end
178
+ end
179
+
142
180
  describe "without nmcli available" do
143
181
  before :each do
144
182
  Facter::Core::Execution.stubs(:which).with('nmcli').returns(nil)