facter 1.7.2 → 1.7.3.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.
- data/README.md +8 -0
- data/Rakefile +10 -4
- data/ext/build_defaults.yaml +4 -3
- data/ext/debian/changelog.erb +7 -1
- data/ext/debian/control +2 -2
- data/ext/redhat/facter.spec.erb +1 -1
- data/install.rb +1 -1
- data/lib/facter/domain.rb +11 -3
- data/lib/facter/hardwaremodel.rb +7 -2
- data/lib/facter/ipaddress.rb +16 -4
- data/lib/facter/ipaddress6.rb +12 -3
- data/lib/facter/macaddress.rb +1 -1
- data/lib/facter/netmask.rb +19 -0
- data/lib/facter/util/directory_loader.rb +1 -1
- data/lib/facter/util/ip.rb +14 -18
- data/lib/facter/util/ip/windows.rb +215 -0
- data/lib/facter/util/macaddress.rb +3 -9
- data/lib/facter/util/netmask.rb +1 -1
- data/lib/facter/util/parser.rb +30 -19
- data/lib/facter/version.rb +1 -1
- data/lib/facter/virtual.rb +5 -5
- data/spec/fixtures/unit/ipaddress/ifconfig_non_english_locale.txt +18 -0
- data/spec/lib/facter_spec/windows_network.rb +64 -0
- data/spec/spec_helper.rb +25 -7
- data/spec/unit/architecture_spec.rb +1 -0
- data/spec/unit/domain_spec.rb +37 -6
- data/spec/unit/ec2_spec.rb +1 -1
- data/spec/unit/facter_spec.rb +2 -2
- data/spec/unit/hardwaremodel_spec.rb +16 -1
- data/spec/unit/ipaddress6_spec.rb +106 -13
- data/spec/unit/ipaddress_spec.rb +100 -22
- data/spec/unit/macaddress_spec.rb +0 -4
- data/spec/unit/memory_spec.rb +8 -7
- data/spec/unit/netmask_spec.rb +62 -5
- data/spec/unit/util/ip/windows_spec.rb +48 -0
- data/spec/unit/util/ip_spec.rb +9 -21
- data/spec/unit/util/macaddress_spec.rb +52 -10
- data/spec/unit/util/parser_spec.rb +32 -3
- data/spec/unit/util/virtual_spec.rb +9 -4
- data/spec/unit/zfs_version_spec.rb +4 -5
- data/spec/unit/zpool_version_spec.rb +4 -5
- metadata +480 -477
- data/ext/osx/PackageInfo.plist +0 -36
- data/ext/osx/createpackage.sh +0 -179
- data/spec/fixtures/netsh/windows_netsh_addresses_with_multiple_interfaces +0 -35
@@ -33,16 +33,10 @@ module Facter::Util::Macaddress
|
|
33
33
|
|
34
34
|
module Windows
|
35
35
|
def macaddress
|
36
|
-
require 'facter/util/
|
36
|
+
require 'facter/util/ip/windows'
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
ether = nil
|
41
|
-
Facter::Util::WMI.execquery(query).each do |nic|
|
42
|
-
ether = nic.MacAddress
|
43
|
-
break
|
44
|
-
end
|
45
|
-
ether
|
38
|
+
adapter = Facter::Util::IP::Windows.get_preferred_ipv4_adapters.first
|
39
|
+
adapter ? adapter.MACAddress : nil
|
46
40
|
end
|
47
41
|
module_function :macaddress
|
48
42
|
end
|
data/lib/facter/util/netmask.rb
CHANGED
@@ -25,7 +25,7 @@ module Facter::NetMask
|
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
|
-
Facter::Util::IP.exec_ifconfig(ops[:ifconfig_opts]).split(/\n/).collect do |line|
|
28
|
+
String(Facter::Util::IP.exec_ifconfig(ops[:ifconfig_opts])).split(/\n/).collect do |line|
|
29
29
|
matches = line.match(ops[:regex])
|
30
30
|
if !matches.nil?
|
31
31
|
if ops[:munge].nil?
|
data/lib/facter/util/parser.rb
CHANGED
@@ -66,6 +66,19 @@ module Facter::Util::Parser
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
+
module KeyValuePairOutputFormat
|
70
|
+
def self.parse(output)
|
71
|
+
result = {}
|
72
|
+
re = /^(.+?)=(.+)$/
|
73
|
+
output.each_line do |line|
|
74
|
+
if match_data = re.match(line.chomp)
|
75
|
+
result[match_data[1]] = match_data[2]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
result
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
69
82
|
class YamlParser < Base
|
70
83
|
def parse_results
|
71
84
|
YAML.load(content)
|
@@ -78,14 +91,7 @@ module Facter::Util::Parser
|
|
78
91
|
|
79
92
|
class TextParser < Base
|
80
93
|
def parse_results
|
81
|
-
|
82
|
-
result = {}
|
83
|
-
content.each_line do |line|
|
84
|
-
if match_data = re.match(line.chomp)
|
85
|
-
result[match_data[1]] = match_data[2]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
result
|
94
|
+
KeyValuePairOutputFormat.parse content
|
89
95
|
end
|
90
96
|
end
|
91
97
|
|
@@ -111,25 +117,30 @@ module Facter::Util::Parser
|
|
111
117
|
|
112
118
|
class ScriptParser < Base
|
113
119
|
def results
|
114
|
-
|
115
|
-
|
116
|
-
result = {}
|
117
|
-
re = /^(.+)=(.+)$/
|
118
|
-
output.each_line do |line|
|
119
|
-
if match_data = re.match(line.chomp)
|
120
|
-
result[match_data[1]] = match_data[2]
|
121
|
-
end
|
122
|
-
end
|
123
|
-
result
|
120
|
+
KeyValuePairOutputFormat.parse Facter::Util::Resolution.exec(filename)
|
124
121
|
end
|
125
122
|
end
|
126
123
|
|
127
124
|
register(ScriptParser) do |filename|
|
128
|
-
if
|
125
|
+
if Facter::Util::Config.is_windows?
|
126
|
+
extension_matches?(filename, %w{bat cmd com exe}) && File.file?(filename)
|
127
|
+
else
|
129
128
|
File.executable?(filename) && File.file?(filename)
|
130
129
|
end
|
131
130
|
end
|
132
131
|
|
132
|
+
# Executes and parses the key value output of Powershell scripts
|
133
|
+
class PowershellParser < Base
|
134
|
+
# Returns a hash of facts from powershell output
|
135
|
+
def results
|
136
|
+
shell_command = "powershell -NoProfile -NonInteractive -NoLogo -ExecutionPolicy Bypass -File \"#{filename}\""
|
137
|
+
KeyValuePairOutputFormat.parse Facter::Util::Resolution.exec(shell_command)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
register(PowershellParser) do |filename|
|
142
|
+
Facter::Util::Config.is_windows? && extension_matches?(filename, "ps1") && File.file?(filename)
|
143
|
+
end
|
133
144
|
|
134
145
|
# A parser that is used when there is no other parser that can handle the file
|
135
146
|
# The return from results indicates to the caller the file was not parsed correctly.
|
data/lib/facter/version.rb
CHANGED
data/lib/facter/virtual.rb
CHANGED
@@ -46,7 +46,7 @@ end
|
|
46
46
|
|
47
47
|
Facter.add("virtual") do
|
48
48
|
confine :kernel => ["FreeBSD", "GNU/kFreeBSD"]
|
49
|
-
|
49
|
+
has_weight 10
|
50
50
|
setcode do
|
51
51
|
"jail" if Facter::Util::Virtual.jail?
|
52
52
|
end
|
@@ -54,7 +54,7 @@ end
|
|
54
54
|
|
55
55
|
Facter.add("virtual") do
|
56
56
|
confine :kernel => 'SunOS'
|
57
|
-
|
57
|
+
has_weight 10
|
58
58
|
setcode do
|
59
59
|
next "zone" if Facter::Util::Virtual.zone?
|
60
60
|
|
@@ -74,7 +74,7 @@ end
|
|
74
74
|
|
75
75
|
Facter.add("virtual") do
|
76
76
|
confine :kernel => 'HP-UX'
|
77
|
-
|
77
|
+
has_weight 10
|
78
78
|
setcode do
|
79
79
|
"hpvm" if Facter::Util::Virtual.hpvm?
|
80
80
|
end
|
@@ -82,7 +82,7 @@ end
|
|
82
82
|
|
83
83
|
Facter.add("virtual") do
|
84
84
|
confine :architecture => 's390x'
|
85
|
-
|
85
|
+
has_weight 10
|
86
86
|
setcode do
|
87
87
|
"zlinux" if Facter::Util::Virtual.zlinux?
|
88
88
|
end
|
@@ -90,7 +90,7 @@ end
|
|
90
90
|
|
91
91
|
Facter.add("virtual") do
|
92
92
|
confine :kernel => 'OpenBSD'
|
93
|
-
|
93
|
+
has_weight 10
|
94
94
|
setcode do
|
95
95
|
output = Facter::Util::Resolution.exec('sysctl -n hw.product 2>/dev/null')
|
96
96
|
if output
|
@@ -0,0 +1,18 @@
|
|
1
|
+
lo Link encap:Boucle locale
|
2
|
+
inet adr:127.0.0.1 Masque:255.0.0.0
|
3
|
+
adr inet6: ::1/128 Scope:Hote
|
4
|
+
UP LOOPBACK RUNNING MTU:65536 Metric:1
|
5
|
+
RX packets:1001 errors:0 dropped:0 overruns:0 frame:0
|
6
|
+
TX packets:1001 errors:0 dropped:0 overruns:0 carrier:0
|
7
|
+
collisions:0 lg file transmission:0
|
8
|
+
RX bytes:52562 (51.3 KiB) TX bytes:52562 (51.3 KiB)
|
9
|
+
|
10
|
+
wlan0 Link encap:Ethernet HWaddr ac:81:12:2d:86:25
|
11
|
+
inet adr:192.168.1.83 Bcast:192.168.1.255 Masque:255.255.255.0
|
12
|
+
adr inet6: fe80::ae81:12ff:fe2d:8625/64 Scope:Lien
|
13
|
+
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
|
14
|
+
RX packets:493220 errors:0 dropped:0 overruns:0 frame:0
|
15
|
+
TX packets:390375 errors:0 dropped:0 overruns:0 carrier:0
|
16
|
+
collisions:0 lg file transmission:1000
|
17
|
+
RX bytes:569234568 (542.8 MiB) TX bytes:69778980 (66.5 MiB)
|
18
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module FacterSpec::WindowsNetwork
|
4
|
+
|
5
|
+
def settingId0
|
6
|
+
'{4AE6B55C-6DD6-427D-A5BB-13535D4BE926}'
|
7
|
+
end
|
8
|
+
|
9
|
+
def settingId1
|
10
|
+
'{38762816-7957-42AC-8DAA-3B08D0C857C7}'
|
11
|
+
end
|
12
|
+
|
13
|
+
def nic_bindings
|
14
|
+
["\\Device\\#{settingId0}", "\\Device\\#{settingId1}" ]
|
15
|
+
end
|
16
|
+
|
17
|
+
def macAddress0
|
18
|
+
'23:24:df:12:12:00'
|
19
|
+
end
|
20
|
+
|
21
|
+
def macAddress1
|
22
|
+
'00:0C:29:0C:9E:9F'
|
23
|
+
end
|
24
|
+
|
25
|
+
def ipAddress0
|
26
|
+
'12.123.12.12'
|
27
|
+
end
|
28
|
+
|
29
|
+
def ipAddress1
|
30
|
+
'12.123.12.13'
|
31
|
+
end
|
32
|
+
|
33
|
+
def subnet0
|
34
|
+
'255.255.255.0'
|
35
|
+
end
|
36
|
+
|
37
|
+
def subnet1
|
38
|
+
'255.255.0.0'
|
39
|
+
end
|
40
|
+
|
41
|
+
def ipv6Address0
|
42
|
+
'2011:0:4137:9e76:2087:77a:53ef:7527'
|
43
|
+
end
|
44
|
+
|
45
|
+
def ipv6Address1
|
46
|
+
'2013:0:4137:9e76:2087:77a:53ef:7527'
|
47
|
+
end
|
48
|
+
|
49
|
+
def ipv6LinkLocal
|
50
|
+
'fe80::2db2:5b42:4e30:b508'
|
51
|
+
end
|
52
|
+
|
53
|
+
def given_a_valid_windows_nic_with_ipv4_and_ipv6
|
54
|
+
stub('network0', :IPAddress => [ipAddress0, ipv6Address0], :SettingID => settingId0, :IPConnectionMetric => 10,:MACAddress => macAddress0,:IPSubnet => [subnet0, '48','2'])
|
55
|
+
end
|
56
|
+
|
57
|
+
def given_two_valid_windows_nics_with_ipv4_and_ipv6
|
58
|
+
{
|
59
|
+
:nic0 => given_a_valid_windows_nic_with_ipv4_and_ipv6,
|
60
|
+
:nic1 => stub('network1', :IPAddress => [ipAddress1, ipv6Address1], :SettingID => settingId1, :IPConnectionMetric => 10,:MACAddress => macAddress1,:IPSubnet => [subnet1, '48','2'])
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,3 @@
|
|
1
|
-
# Add the projects lib directory to our load path so we can require libraries
|
2
|
-
# within it easily.
|
3
|
-
dir = File.expand_path(File.dirname(__FILE__))
|
4
|
-
|
5
|
-
SPECDIR = dir
|
6
|
-
$LOAD_PATH.unshift("#{dir}/../lib")
|
7
|
-
|
8
1
|
require 'rubygems'
|
9
2
|
require 'mocha'
|
10
3
|
require 'rspec'
|
@@ -13,10 +6,35 @@ require 'fileutils'
|
|
13
6
|
require 'puppetlabs_spec_helper'
|
14
7
|
require 'pathname'
|
15
8
|
|
9
|
+
# load shared_context within this project's spec directory
|
10
|
+
dir = File.expand_path(File.dirname(__FILE__))
|
11
|
+
$LOAD_PATH.unshift File.join(dir, 'lib')
|
12
|
+
|
16
13
|
Pathname.glob("#{dir}/shared_contexts/*.rb") do |file|
|
17
14
|
require file.relative_path_from(Pathname.new(dir))
|
18
15
|
end
|
19
16
|
|
17
|
+
module LogSpecOrder
|
18
|
+
# Log the spec order to a file, but only if the LOG_SPEC_ORDER environment
|
19
|
+
# variable is set. This could be enabled on Jenkins runs, as it can
|
20
|
+
# be used with Nick L.'s bisect script to help identify and debug
|
21
|
+
# order-dependent spec failures.
|
22
|
+
#
|
23
|
+
# jpartlow 2013-07-05: this was in puppet and I pulled it into facter because
|
24
|
+
# I was seeing similar ordering issues in the specs...and needed to bisect them :/
|
25
|
+
def self.log_spec_order
|
26
|
+
if ENV['LOG_SPEC_ORDER']
|
27
|
+
File.open("./spec_order.txt", "w") do |logfile|
|
28
|
+
RSpec.configuration.files_to_run.each { |f| logfile.puts f }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Executing here rather than after :suite, so that we can get the order output
|
35
|
+
# even when the issue breaks rspec when specs are first loaded.
|
36
|
+
LogSpecOrder.log_spec_order
|
37
|
+
|
20
38
|
RSpec.configure do |config|
|
21
39
|
config.mock_with :mocha
|
22
40
|
|
data/spec/unit/domain_spec.rb
CHANGED
@@ -160,18 +160,49 @@ describe "Domain name facts" do
|
|
160
160
|
Facter::Util::Registry.stubs(:hklm_read).returns('')
|
161
161
|
end
|
162
162
|
|
163
|
-
|
164
|
-
|
165
|
-
nic.stubs(:DNSDomain).returns("foo.com")
|
163
|
+
def expects_dnsdomains(domains)
|
164
|
+
nics = []
|
166
165
|
|
167
|
-
|
168
|
-
|
166
|
+
domains.each do |domain|
|
167
|
+
nic = stubs 'nic'
|
168
|
+
nic.stubs(:DNSDomain).returns(domain)
|
169
|
+
nics << nic
|
170
|
+
end
|
169
171
|
|
170
172
|
require 'facter/util/wmi'
|
171
|
-
Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns(
|
173
|
+
Facter::Util::WMI.stubs(:execquery).with("select DNSDomain from Win32_NetworkAdapterConfiguration where IPEnabled = True").returns(nics)
|
174
|
+
end
|
175
|
+
|
176
|
+
it "uses the first DNSDomain" do
|
177
|
+
expects_dnsdomains(['foo.com', 'bar.com'])
|
172
178
|
|
173
179
|
Facter.fact(:domain).value.should == 'foo.com'
|
174
180
|
end
|
181
|
+
|
182
|
+
it "uses the first non-nil DNSDomain" do
|
183
|
+
expects_dnsdomains([nil, 'bar.com'])
|
184
|
+
|
185
|
+
Facter.fact(:domain).value.should == 'bar.com'
|
186
|
+
end
|
187
|
+
|
188
|
+
it "uses the first non-empty DNSDomain" do
|
189
|
+
expects_dnsdomains(['', 'bar.com'])
|
190
|
+
|
191
|
+
Facter.fact(:domain).value.should == 'bar.com'
|
192
|
+
end
|
193
|
+
|
194
|
+
context "without any network adapters with a specified DNSDomain" do
|
195
|
+
let(:hostname_command) { 'hostname > NUL' }
|
196
|
+
|
197
|
+
it "should return nil" do
|
198
|
+
expects_dnsdomains([nil])
|
199
|
+
|
200
|
+
Facter::Util::Resolution.stubs(:exec).with(hostname_command).returns('sometest')
|
201
|
+
FileTest.stubs(:exists?).with("/etc/resolv.conf").returns(false)
|
202
|
+
|
203
|
+
Facter.fact(:domain).value.should be_nil
|
204
|
+
end
|
205
|
+
end
|
175
206
|
end
|
176
207
|
end
|
177
208
|
|
data/spec/unit/ec2_spec.rb
CHANGED
@@ -136,7 +136,7 @@ describe "ec2 facts" do
|
|
136
136
|
end
|
137
137
|
|
138
138
|
it "should return nil if open fails" do
|
139
|
-
Facter.expects(:warn).with('Could not retrieve ec2 metadata: host unreachable')
|
139
|
+
Facter.expects(:warn).with('Could not retrieve ec2 metadata: host unreachable')
|
140
140
|
Facter::Util::Resolution.any_instance.stubs(:warn) # do not pollute test output
|
141
141
|
|
142
142
|
Object.any_instance.expects(:open).
|
data/spec/unit/facter_spec.rb
CHANGED
@@ -102,13 +102,13 @@ describe Facter do
|
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
|
-
describe Facter[:hostname] do
|
105
|
+
describe "Facter[:hostname]" do
|
106
106
|
it "should have its ldapname set to 'cn'" do
|
107
107
|
Facter[:hostname].ldapname.should == "cn"
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
-
describe Facter[:ipaddress] do
|
111
|
+
describe "Facter[:ipaddress]" do
|
112
112
|
it "should have its ldapname set to 'iphostnumber'" do
|
113
113
|
Facter[:ipaddress].ldapname.should == "iphostnumber"
|
114
114
|
end
|
@@ -17,6 +17,14 @@ describe "Hardwaremodel fact" do
|
|
17
17
|
Facter.fact(:kernel).stubs(:value).returns("windows")
|
18
18
|
end
|
19
19
|
|
20
|
+
it "should detect i486" do
|
21
|
+
cpu = mock('cpu', :Architecture => 0)
|
22
|
+
cpu.expects(:Level).returns(4).twice
|
23
|
+
Facter::Util::WMI.expects(:execquery).returns([cpu])
|
24
|
+
|
25
|
+
Facter.fact(:hardwaremodel).value.should == "i486"
|
26
|
+
end
|
27
|
+
|
20
28
|
it "should detect i686" do
|
21
29
|
cpu = mock('cpu', :Architecture => 0, :Level => 6)
|
22
30
|
Facter::Util::WMI.expects(:execquery).returns([cpu])
|
@@ -25,7 +33,7 @@ describe "Hardwaremodel fact" do
|
|
25
33
|
end
|
26
34
|
|
27
35
|
it "should detect x64" do
|
28
|
-
cpu = mock('cpu', :Architecture => 9, :AddressWidth => 64)
|
36
|
+
cpu = mock('cpu', :Architecture => 9, :AddressWidth => 64, :Level => 6)
|
29
37
|
Facter::Util::WMI.expects(:execquery).returns([cpu])
|
30
38
|
|
31
39
|
Facter.fact(:hardwaremodel).value.should == "x64"
|
@@ -37,5 +45,12 @@ describe "Hardwaremodel fact" do
|
|
37
45
|
|
38
46
|
Facter.fact(:hardwaremodel).value.should == "i686"
|
39
47
|
end
|
48
|
+
|
49
|
+
it "(#20989) should report i686 when a 32 bit OS is running on a 64 bit CPU and when level is greater than 6 (and not something like i1586)" do
|
50
|
+
cpu = mock('cpu', :Architecture => 9, :AddressWidth => 32, :Level => 15)
|
51
|
+
Facter::Util::WMI.expects(:execquery).returns([cpu])
|
52
|
+
|
53
|
+
Facter.fact(:hardwaremodel).value.should == "i686"
|
54
|
+
end
|
40
55
|
end
|
41
56
|
end
|
@@ -7,12 +7,7 @@ def ifconfig_fixture(filename)
|
|
7
7
|
File.read(fixtures('ifconfig', filename))
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
File.read(fixtures('netsh', filename))
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
describe "IPv6 address fact" do
|
10
|
+
describe "The IPv6 address fact" do
|
16
11
|
include FacterSpec::ConfigHelper
|
17
12
|
|
18
13
|
before do
|
@@ -55,14 +50,112 @@ describe "IPv6 address fact" do
|
|
55
50
|
Facter.value(:ipaddress6).should == "2610:10:20:209:203:baff:fe27:a7c"
|
56
51
|
end
|
57
52
|
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
context "on Windows" do
|
54
|
+
require 'facter/util/wmi'
|
55
|
+
require 'facter/util/registry'
|
56
|
+
require 'facter/util/ip/windows'
|
57
|
+
require 'facter_spec/windows_network'
|
58
|
+
|
59
|
+
include FacterSpec::WindowsNetwork
|
60
|
+
|
61
|
+
before :each do
|
62
|
+
Facter.fact(:kernel).stubs(:value).returns(:windows)
|
63
|
+
Facter::Util::Registry.stubs(:hklm_read).returns(nic_bindings)
|
64
|
+
given_a_configuration_of(:is_windows => true)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should do what when VPN is turned on?"
|
68
|
+
|
69
|
+
context "when you have no active network adapter" do
|
70
|
+
it "should return nil if there are no active (or any) network adapters" do
|
71
|
+
Facter::Util::WMI.expects(:execquery).with(Facter::Util::IP::Windows::WMI_IP_INFO_QUERY).returns([])
|
72
|
+
|
73
|
+
Facter.value(:ipaddress6).should == nil
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should return nil if the system doesn't have ipv6 installed", :if => Facter::Util::Config.is_windows? do
|
78
|
+
Facter::Util::Resolution.any_instance.expects(:warn).never
|
79
|
+
Facter::Util::Registry.stubs(:hklm_read).raises(Win32::Registry::Error, 2)
|
61
80
|
|
62
|
-
|
63
|
-
|
64
|
-
|
81
|
+
Facter.value(:ipaddress6).should == nil
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when you have one network adapter" do
|
85
|
+
it "should return empty if ipv6 is not on" do
|
86
|
+
nic = given_a_valid_windows_nic_with_ipv4_and_ipv6
|
87
|
+
nic.expects(:IPAddress).returns([ipAddress1])
|
88
|
+
Facter::Util::WMI.expects(:execquery).returns([nic])
|
89
|
+
|
90
|
+
Facter.value(:ipaddress6).should == nil
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return the ipv6 address properly" do
|
94
|
+
Facter::Util::WMI.expects(:execquery).returns([given_a_valid_windows_nic_with_ipv4_and_ipv6])
|
95
|
+
|
96
|
+
Facter.value(:ipaddress6).should == ipv6Address0
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should return the first ipv6 address if there is more than one (multi-homing)" do
|
100
|
+
nic = given_a_valid_windows_nic_with_ipv4_and_ipv6
|
101
|
+
nic.expects(:IPAddress).returns([ipAddress0, ipv6Address0,ipv6Address1])
|
102
|
+
Facter::Util::WMI.expects(:execquery).returns([nic])
|
65
103
|
|
66
|
-
|
104
|
+
Facter.value(:ipaddress6).should == ipv6Address0
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return return nil if the ipv6 address is link local" do
|
108
|
+
nic = given_a_valid_windows_nic_with_ipv4_and_ipv6
|
109
|
+
nic.expects(:IPAddress).returns([ipAddress0, ipv6LinkLocal])
|
110
|
+
Facter::Util::WMI.expects(:execquery).returns([nic])
|
111
|
+
|
112
|
+
Facter.value(:ipaddress6).should == nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "when you have more than one network adapter" do
|
117
|
+
it "should return empty if ipv6 is not on" do
|
118
|
+
nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
|
119
|
+
nics[:nic0].expects(:IPAddress).returns([ipAddress0])
|
120
|
+
nics[:nic1].expects(:IPAddress).returns([ipAddress1])
|
121
|
+
Facter::Util::WMI.expects(:execquery).returns(nics.values)
|
122
|
+
|
123
|
+
Facter.value(:ipaddress6).should == nil
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return the ipv6 of the adapter with the lowest IP connection metric (best connection)" do
|
127
|
+
nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
|
128
|
+
nics[:nic1].expects(:IPConnectionMetric).returns(5)
|
129
|
+
Facter::Util::WMI.expects(:execquery).returns(nics.values)
|
130
|
+
|
131
|
+
Facter.value(:ipaddress6).should == ipv6Address1
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should return the ipv6 of the adapter with the lowest IP connection metric (best connection) that has ipv6 enabled" do
|
135
|
+
nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
|
136
|
+
nics[:nic1].expects(:IPConnectionMetric).returns(5)
|
137
|
+
nics[:nic1].expects(:IPAddress).returns([ipAddress1])
|
138
|
+
Facter::Util::WMI.expects(:execquery).returns(nics.values)
|
139
|
+
|
140
|
+
Facter.value(:ipaddress6).should == ipv6Address0
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when the IP connection metric is the same" do
|
144
|
+
it "should return the ipv6 of the adapter with the lowest binding order" do
|
145
|
+
nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
|
146
|
+
Facter::Util::WMI.expects(:execquery).returns(nics.values)
|
147
|
+
|
148
|
+
Facter.value(:ipaddress6).should == ipv6Address0
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should return the ipv6 of the adapter with the lowest binding order even if the adapter is not first" do
|
152
|
+
nics = given_two_valid_windows_nics_with_ipv4_and_ipv6
|
153
|
+
Facter::Util::Registry.stubs(:hklm_read).returns(["\\Device\\#{settingId1}", "\\Device\\#{settingId0}" ])
|
154
|
+
Facter::Util::WMI.expects(:execquery).returns(nics.values)
|
155
|
+
|
156
|
+
Facter.value(:ipaddress6).should == ipv6Address1
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
67
160
|
end
|
68
161
|
end
|