facter 1.6.4 → 1.6.5
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/CHANGELOG +33 -1
- data/conf/redhat/facter.spec +2 -1
- data/install.rb +25 -23
- data/lib/facter.rb +2 -1
- data/lib/facter/domain.rb +4 -4
- data/lib/facter/ec2.rb +6 -28
- data/lib/facter/hardwareisa.rb +0 -1
- data/lib/facter/hardwaremodel.rb +1 -1
- data/lib/facter/lsbmajdistrelease.rb +1 -1
- data/lib/facter/macaddress.rb +1 -1
- data/lib/facter/memory.rb +15 -4
- data/lib/facter/operatingsystem.rb +8 -4
- data/lib/facter/osfamily.rb +1 -1
- data/lib/facter/uniqueid.rb +1 -1
- data/lib/facter/util/collection.rb +2 -3
- data/lib/facter/util/config.rb +3 -3
- data/lib/facter/util/ec2.rb +49 -0
- data/lib/facter/util/fact.rb +12 -7
- data/lib/facter/util/monkey_patches.rb +7 -0
- data/lib/facter/util/uptime.rb +2 -2
- data/lib/facter/util/virtual.rb +1 -1
- data/lib/facter/virtual.rb +11 -1
- data/spec/{unit/data → fixtures/unit/selinux}/selinux_sestatus +0 -0
- data/spec/fixtures/unit/util/ec2/linux-arp-ec2.out +1 -0
- data/spec/fixtures/unit/util/ec2/linux-arp-not-ec2.out +5 -0
- data/spec/fixtures/unit/util/ec2/windows-2008-arp-a-not-ec2.out +6 -0
- data/spec/fixtures/unit/util/ec2/windows-2008-arp-a.out +10 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/6.0-STABLE_FreeBSD_ifconfig +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/Mac_OS_X_10.5.5_ifconfig +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/darwin_ifconfig_all_with_multiple_interfaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/darwin_ifconfig_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/debian_kfreebsd_ifconfig +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/hpux_ifconfig_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/hpux_netstat_all_interfaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/linux_ifconfig_all_with_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/solaris_ifconfig_all_with_multiple_interfaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/solaris_ifconfig_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/windows_netsh_all_interfaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/windows_netsh_single_interface +0 -0
- data/spec/{unit/data → fixtures/unit/util/ip}/windows_netsh_single_interface6 +0 -0
- data/spec/{unit/data → fixtures/unit/util/manufacturer}/freebsd_dmidecode +0 -0
- data/spec/{unit/data → fixtures/unit/util/manufacturer}/linux_dmidecode_with_spaces +0 -0
- data/spec/{unit/data → fixtures/unit/util/manufacturer}/opensolaris_smbios +0 -0
- data/spec/fixtures/{uptime → unit/util/uptime}/kstat_boot_time +0 -0
- data/spec/fixtures/unit/util/uptime/sysctl_kern_boottime_darwin +1 -0
- data/spec/fixtures/unit/util/uptime/sysctl_kern_boottime_openbsd +1 -0
- data/spec/fixtures/{uptime → unit/util/uptime}/ubuntu_proc_uptime +0 -0
- data/spec/fixtures/{uptime → unit/util/uptime}/who_b_boottime +0 -0
- data/spec/{unit/data → fixtures/unit/util/vlans}/linux_vlan_config +0 -0
- data/spec/{unit/data → fixtures/unit/util/xendomains}/xendomains +0 -0
- data/spec/integration/facter_spec.rb +2 -2
- data/spec/puppetlabs_spec/files.rb +57 -0
- data/spec/puppetlabs_spec/fixtures.rb +49 -0
- data/spec/puppetlabs_spec/matchers.rb +87 -0
- data/spec/puppetlabs_spec_helper.rb +25 -0
- data/spec/spec_helper.rb +9 -12
- data/spec/unit/architecture_spec.rb +2 -4
- data/spec/unit/domain_spec.rb +3 -1
- data/spec/unit/ec2_spec.rb +140 -0
- data/spec/unit/facter_spec.rb +2 -2
- data/spec/unit/hardwareisa_spec.rb +34 -0
- data/spec/unit/hostname_spec.rb +3 -1
- data/spec/unit/id_spec.rb +2 -2
- data/spec/unit/interfaces_spec.rb +2 -4
- data/spec/unit/ipaddress6_spec.rb +4 -7
- data/spec/unit/lsbmajdistrelease_spec.rb +13 -0
- data/spec/unit/macaddress_spec.rb +4 -7
- data/spec/unit/memory_spec.rb +11 -6
- data/spec/unit/operatingsystem_spec.rb +101 -69
- data/spec/unit/operatingsystemrelease_spec.rb +2 -4
- data/spec/unit/physicalprocessorcount_spec.rb +1 -1
- data/spec/unit/processor_spec.rb +32 -35
- data/spec/unit/selinux_spec.rb +5 -10
- data/spec/unit/uniqueid_spec.rb +27 -0
- data/spec/unit/uptime_spec.rb +2 -4
- data/spec/unit/util/collection_spec.rb +12 -3
- data/spec/unit/util/config_spec.rb +24 -0
- data/spec/unit/util/confine_spec.rb +2 -3
- data/spec/unit/util/ec2_spec.rb +112 -0
- data/spec/unit/util/fact_spec.rb +2 -3
- data/spec/unit/util/ip_spec.rb +27 -55
- data/spec/unit/util/loader_spec.rb +2 -4
- data/spec/unit/util/macaddress_spec.rb +4 -5
- data/spec/unit/util/macosx_spec.rb +2 -3
- data/spec/unit/util/manufacturer_spec.rb +8 -9
- data/spec/unit/util/processor_spec.rb +8 -10
- data/spec/unit/util/resolution_spec.rb +2 -3
- data/spec/unit/util/uptime_spec.rb +15 -14
- data/spec/unit/util/virtual_spec.rb +10 -2
- data/spec/unit/util/vlans_spec.rb +3 -5
- data/spec/unit/util/wmi_spec.rb +2 -3
- data/spec/unit/util/xendomains_spec.rb +3 -5
- data/spec/unit/virtual_spec.rb +48 -18
- metadata +44 -28
- data/spec/fixtures/uptime/sysctl_kern_boottime_big_endian +0 -0
- data/spec/fixtures/uptime/sysctl_kern_boottime_little_endian +0 -0
data/spec/unit/processor_spec.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
#!/usr/bin/env
|
1
|
+
#!/usr/bin/env rspec
|
2
2
|
|
3
|
-
|
4
|
-
require File.join($basedir, 'spec_helper')
|
5
|
-
|
6
|
-
require 'facter'
|
3
|
+
require 'spec_helper'
|
7
4
|
|
8
5
|
def cpuinfo_fixture(filename)
|
9
|
-
|
6
|
+
File.open(fixtures('cpuinfo', filename)).readlines
|
10
7
|
end
|
11
8
|
|
12
9
|
describe "Processor facts" do
|
@@ -74,18 +71,18 @@ describe "Processor facts" do
|
|
74
71
|
end
|
75
72
|
|
76
73
|
it "should detect the correct processor count on x86_64" do
|
77
|
-
fixture_data = File.read(
|
74
|
+
fixture_data = File.read(fixtures('processorcount','solaris-x86_64-kstat-cpu-info'))
|
78
75
|
Facter::Util::Resolution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(fixture_data)
|
79
76
|
Facter.fact(:processorcount).value.should == 8
|
80
77
|
end
|
81
78
|
|
82
79
|
it "should detect the correct processor count on sparc" do
|
83
|
-
fixture_data = File.read(
|
80
|
+
fixture_data = File.read(fixtures('processorcount','solaris-sparc-kstat-cpu-info'))
|
84
81
|
Facter::Util::Resolution.expects(:exec).with("/usr/bin/kstat cpu_info").returns(fixture_data)
|
85
82
|
Facter.fact(:processorcount).value.should == 8
|
86
83
|
end
|
87
84
|
end
|
88
|
-
|
85
|
+
|
89
86
|
describe "on Unixes" do
|
90
87
|
before :each do
|
91
88
|
Facter.collection.loader.load(:processor)
|
@@ -106,102 +103,102 @@ describe "Processor facts" do
|
|
106
103
|
Facter.fact(:architecture).stubs(:value).returns("ppc64")
|
107
104
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
108
105
|
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("ppc64"))
|
109
|
-
|
106
|
+
|
110
107
|
Facter.fact(:processorcount).value.should == "2"
|
111
108
|
end
|
112
|
-
|
109
|
+
|
113
110
|
it "should be 2 in panda-armel fixture on Linux" do
|
114
111
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
115
112
|
Facter.fact(:architecture).stubs(:value).returns("arm")
|
116
113
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
117
114
|
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("panda-armel"))
|
118
|
-
|
115
|
+
|
119
116
|
Facter.fact(:processorcount).value.should == "2"
|
120
117
|
end
|
121
|
-
|
118
|
+
|
122
119
|
it "should be 1 in bbg3-armel fixture on Linux" do
|
123
120
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
124
121
|
Facter.fact(:architecture).stubs(:value).returns("arm")
|
125
122
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
126
123
|
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("bbg3-armel"))
|
127
|
-
|
124
|
+
|
128
125
|
Facter.fact(:processorcount).value.should == "1"
|
129
126
|
end
|
130
|
-
|
127
|
+
|
131
128
|
it "should be 1 in beaglexm-armel fixture on Linux" do
|
132
129
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
133
130
|
Facter.fact(:architecture).stubs(:value).returns("arm")
|
134
131
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
135
132
|
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("beaglexm-armel"))
|
136
|
-
|
133
|
+
|
137
134
|
Facter.fact(:processorcount).value.should == "1"
|
138
135
|
end
|
139
|
-
|
136
|
+
|
140
137
|
it "should be 1 in amd64solo fixture on Linux" do
|
141
138
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
142
139
|
Facter.fact(:architecture).stubs(:value).returns("amd64")
|
143
140
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
144
141
|
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64solo"))
|
145
|
-
|
142
|
+
|
146
143
|
Facter.fact(:processorcount).value.should == "1"
|
147
144
|
end
|
148
|
-
|
145
|
+
|
149
146
|
it "should be 2 in amd64dual fixture on Linux" do
|
150
147
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
151
148
|
Facter.fact(:architecture).stubs(:value).returns("amd64")
|
152
149
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
153
150
|
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64dual"))
|
154
|
-
|
151
|
+
|
155
152
|
Facter.fact(:processorcount).value.should == "2"
|
156
153
|
end
|
157
|
-
|
154
|
+
|
158
155
|
it "should be 3 in amd64tri fixture on Linux" do
|
159
156
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
160
157
|
Facter.fact(:architecture).stubs(:value).returns("amd64")
|
161
158
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
162
159
|
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64tri"))
|
163
|
-
|
160
|
+
|
164
161
|
Facter.fact(:processorcount).value.should == "3"
|
165
162
|
end
|
166
|
-
|
163
|
+
|
167
164
|
it "should be 4 in amd64quad fixture on Linux" do
|
168
165
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
169
166
|
Facter.fact(:architecture).stubs(:value).returns("amd64")
|
170
167
|
File.stubs(:exists?).with("/proc/cpuinfo").returns(true)
|
171
168
|
File.stubs(:readlines).with("/proc/cpuinfo").returns(cpuinfo_fixture("amd64quad"))
|
172
|
-
|
169
|
+
|
173
170
|
Facter.fact(:processorcount).value.should == "4"
|
174
171
|
end
|
175
|
-
|
172
|
+
|
176
173
|
it "should be 2 on dual-processor Darwin box" do
|
177
174
|
Facter.fact(:kernel).stubs(:value).returns("Darwin")
|
178
175
|
Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
|
179
|
-
|
176
|
+
|
180
177
|
Facter.fact(:processorcount).value.should == "2"
|
181
178
|
end
|
182
|
-
|
179
|
+
|
183
180
|
it "should be 2 on dual-processor OpenBSD box" do
|
184
181
|
Facter.fact(:kernel).stubs(:value).returns("OpenBSD")
|
185
182
|
Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
|
186
|
-
|
183
|
+
|
187
184
|
Facter.fact(:processorcount).value.should == "2"
|
188
185
|
end
|
189
186
|
|
190
187
|
it "should be 2 on dual-processor DragonFly box" do
|
191
188
|
Facter.fact(:kernel).stubs(:value).returns("DragonFly")
|
192
189
|
Facter::Util::Resolution.stubs(:exec).with("sysctl -n hw.ncpu").returns('2')
|
193
|
-
|
190
|
+
|
194
191
|
Facter.fact(:processorcount).value.should == "2"
|
195
192
|
end
|
196
|
-
|
193
|
+
|
197
194
|
it "should be 6 on six-processor AIX box" do
|
198
195
|
Facter.fact(:kernel).stubs(:value).returns("AIX")
|
199
196
|
Facter::Util::Resolution.stubs(:exec).with("lsdev -Cc processor").returns("proc0 Available 00-00 Processor\nproc2 Available 00-02 Processor\nproc4 Available 00-04 Processor\nproc6 Available 00-06 Processor\nproc8 Available 00-08 Processor\nproc10 Available 00-10 Processor")
|
200
197
|
Facter::Util::Resolution.stubs(:exec).with("lsattr -El proc0 -a type").returns("type PowerPC_POWER3 Processor type False")
|
201
|
-
|
198
|
+
|
202
199
|
Facter.fact(:processorcount).value.should == "6"
|
203
200
|
end
|
204
|
-
|
201
|
+
|
205
202
|
it "should be 2 via sysfs when cpu0 and cpu1 are present" do
|
206
203
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
207
204
|
File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
|
@@ -212,10 +209,10 @@ describe "Processor facts" do
|
|
212
209
|
/sys/devices/system/cpu/cpu0
|
213
210
|
/sys/devices/system/cpu/cpu1
|
214
211
|
})
|
215
|
-
|
212
|
+
|
216
213
|
Facter.fact(:processorcount).value.should == "2"
|
217
214
|
end
|
218
|
-
|
215
|
+
|
219
216
|
it "should be 16 via sysfs when cpu0 through cpu15 are present" do
|
220
217
|
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
221
218
|
File.stubs(:exists?).with('/sys/devices/system/cpu').returns(true)
|
@@ -240,7 +237,7 @@ describe "Processor facts" do
|
|
240
237
|
/sys/devices/system/cpu/cpu14
|
241
238
|
/sys/devices/system/cpu/cpu15
|
242
239
|
})
|
243
|
-
|
240
|
+
|
244
241
|
Facter.fact(:processorcount).value.should == "16"
|
245
242
|
end
|
246
243
|
end
|
data/spec/unit/selinux_spec.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#!/usr/bin/env
|
1
|
+
#!/usr/bin/env rspec
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
require 'facter'
|
3
|
+
require 'spec_helper'
|
6
4
|
|
7
5
|
describe "SELinux facts" do
|
8
6
|
|
@@ -50,8 +48,7 @@ describe "SELinux facts" do
|
|
50
48
|
it "should return the SELinux current mode" do
|
51
49
|
Facter.fact(:selinux).stubs(:value).returns("true")
|
52
50
|
|
53
|
-
|
54
|
-
selinux_sestatus = File.read(sample_output_file)
|
51
|
+
selinux_sestatus = my_fixture_read("selinux_sestatus")
|
55
52
|
|
56
53
|
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus)
|
57
54
|
|
@@ -61,8 +58,7 @@ describe "SELinux facts" do
|
|
61
58
|
it "should return the SELinux mode from the configuration file" do
|
62
59
|
Facter.fact(:selinux).stubs(:value).returns("true")
|
63
60
|
|
64
|
-
|
65
|
-
selinux_sestatus = File.read(sample_output_file)
|
61
|
+
selinux_sestatus = my_fixture_read("selinux_sestatus")
|
66
62
|
|
67
63
|
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus)
|
68
64
|
|
@@ -72,8 +68,7 @@ describe "SELinux facts" do
|
|
72
68
|
it "should return the SELinux configuration file policy" do
|
73
69
|
Facter.fact(:selinux).stubs(:value).returns("true")
|
74
70
|
|
75
|
-
|
76
|
-
selinux_sestatus = File.read(sample_output_file)
|
71
|
+
selinux_sestatus = my_fixture_read("selinux_sestatus")
|
77
72
|
|
78
73
|
Facter::Util::Resolution.stubs(:exec).with('/usr/sbin/sestatus').returns(selinux_sestatus)
|
79
74
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'facter'
|
5
|
+
|
6
|
+
describe "Uniqueid fact" do
|
7
|
+
it "should match hostid on Solaris" do
|
8
|
+
Facter.fact(:kernel).stubs(:value).returns("SunOS")
|
9
|
+
Facter::Util::Resolution.stubs(:exec).with("hostid").returns("Larry")
|
10
|
+
|
11
|
+
Facter.fact(:uniqueid).value.should == "Larry"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should match hostid on Linux" do
|
15
|
+
Facter.fact(:kernel).stubs(:value).returns("Linux")
|
16
|
+
Facter::Util::Resolution.stubs(:exec).with("hostid").returns("Curly")
|
17
|
+
|
18
|
+
Facter.fact(:uniqueid).value.should == "Curly"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should match hostid on AIX" do
|
22
|
+
Facter.fact(:kernel).stubs(:value).returns("AIX")
|
23
|
+
Facter::Util::Resolution.stubs(:exec).with("hostid").returns("Moe")
|
24
|
+
|
25
|
+
Facter.fact(:uniqueid).value.should == "Moe"
|
26
|
+
end
|
27
|
+
end
|
data/spec/unit/uptime_spec.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
#!/usr/bin/env
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
1
|
+
#!/usr/bin/env rspec
|
4
2
|
|
3
|
+
require 'spec_helper'
|
5
4
|
require 'facter/util/collection'
|
6
5
|
|
7
6
|
describe Facter::Util::Collection do
|
@@ -93,6 +92,16 @@ describe Facter::Util::Collection do
|
|
93
92
|
|
94
93
|
@coll.add(:myname) {}
|
95
94
|
end
|
95
|
+
|
96
|
+
it "should discard resolutions that throw an exception when added" do
|
97
|
+
lambda {
|
98
|
+
@coll.add('yay') do
|
99
|
+
raise
|
100
|
+
setcode { 'yay' }
|
101
|
+
end
|
102
|
+
}.should_not raise_error
|
103
|
+
@coll.value('yay').should be_nil
|
104
|
+
end
|
96
105
|
end
|
97
106
|
end
|
98
107
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'facter/util/config'
|
5
|
+
|
6
|
+
describe Facter::Util::Config do
|
7
|
+
describe "is_windows? function" do
|
8
|
+
it "should detect windows if RbConfig returns a windows OS" do
|
9
|
+
host_os = ["mswin","win32","dos","mingw","cygwin"]
|
10
|
+
host_os.each do |h|
|
11
|
+
RbConfig::CONFIG.expects(:[]).with('host_os').returns(h)
|
12
|
+
Facter::Util::Config.is_windows?.should be_true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not detect windows if RbConfig returns a non-windows OS" do
|
17
|
+
host_os = ["darwin","linux"]
|
18
|
+
host_os.each do |h|
|
19
|
+
RbConfig::CONFIG.expects(:[]).with('host_os').returns(h)
|
20
|
+
Facter::Util::Config.is_windows?.should be_false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#!/usr/bin/env rspec
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'facter/util/ec2'
|
5
|
+
|
6
|
+
describe Facter::Util::EC2 do
|
7
|
+
# This is the standard prefix for making an API call in EC2 (or fake)
|
8
|
+
# environments.
|
9
|
+
let(:api_prefix) { "http://169.254.169.254" }
|
10
|
+
|
11
|
+
describe "is_ec2_arp? method" do
|
12
|
+
describe "on linux" do
|
13
|
+
before :each do
|
14
|
+
# Return fake kernel
|
15
|
+
Facter.stubs(:value).with(:kernel).returns("linux")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should succeed if arp table contains fe:ff:ff:ff:ff:ff" do
|
19
|
+
ec2arp = my_fixture_read("linux-arp-ec2.out")
|
20
|
+
Facter::Util::Resolution.expects(:exec).with("arp -an").\
|
21
|
+
at_least_once.returns(ec2arp)
|
22
|
+
Facter::Util::EC2.has_ec2_arp?.should == true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should fail if arp table does not contain fe:ff:ff:ff:ff:ff" do
|
26
|
+
ec2arp = my_fixture_read("linux-arp-not-ec2.out")
|
27
|
+
Facter::Util::Resolution.expects(:exec).with("arp -an").
|
28
|
+
at_least_once.returns(ec2arp)
|
29
|
+
Facter::Util::EC2.has_ec2_arp?.should == false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "on windows" do
|
34
|
+
before :each do
|
35
|
+
# Return fake kernel
|
36
|
+
Facter.stubs(:value).with(:kernel).returns("windows")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should succeed if arp table contains fe-ff-ff-ff-ff-ff" do
|
40
|
+
ec2arp = my_fixture_read("windows-2008-arp-a.out")
|
41
|
+
Facter::Util::Resolution.expects(:exec).with("arp -a").\
|
42
|
+
at_least_once.returns(ec2arp)
|
43
|
+
Facter::Util::EC2.has_ec2_arp?.should == true
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should fail if arp table does not contain fe-ff-ff-ff-ff-ff" do
|
47
|
+
ec2arp = my_fixture_read("windows-2008-arp-a-not-ec2.out")
|
48
|
+
Facter::Util::Resolution.expects(:exec).with("arp -a").
|
49
|
+
at_least_once.returns(ec2arp)
|
50
|
+
Facter::Util::EC2.has_ec2_arp?.should == false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "is_euca_mac? method" do
|
56
|
+
it "should return true when the mac is a eucalyptus one" do
|
57
|
+
Facter.expects(:value).with(:macaddress).\
|
58
|
+
at_least_once.returns("d0:0d:1a:b0:a1:00")
|
59
|
+
|
60
|
+
Facter::Util::EC2.has_euca_mac?.should == true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return false when the mac is not a eucalyptus one" do
|
64
|
+
Facter.expects(:value).with(:macaddress).\
|
65
|
+
at_least_once.returns("0c:1d:a0:bc:aa:02")
|
66
|
+
|
67
|
+
Facter::Util::EC2.has_euca_mac?.should == false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "can_connect? method" do
|
72
|
+
it "returns true if api responds" do
|
73
|
+
# Return something upon connecting to the root
|
74
|
+
Module.any_instance.expects(:open).with("#{api_prefix}:80/").\
|
75
|
+
at_least_once.returns("2008-02-01\nlatest")
|
76
|
+
|
77
|
+
Facter::Util::EC2.can_connect?.should == true
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "when connection times out" do
|
81
|
+
before :each do
|
82
|
+
# Emulate a timeout when connecting by throwing an exception
|
83
|
+
Module.any_instance.expects(:open).with("#{api_prefix}:80/").\
|
84
|
+
at_least_once.raises(Timeout::Error)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should not raise exception" do
|
88
|
+
expect { Facter::Util::EC2.can_connect? }.to_not raise_error
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should return false" do
|
92
|
+
Facter::Util::EC2.can_connect?.should == false
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "when connection is refused" do
|
97
|
+
before :each do
|
98
|
+
# Emulate a connection refused
|
99
|
+
Module.any_instance.expects(:open).with("#{api_prefix}:80/").\
|
100
|
+
at_least_once.raises(Errno::ECONNREFUSED)
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should not raise exception" do
|
104
|
+
expect { Facter::Util::EC2.can_connect? }.to_not raise_error
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should return false" do
|
108
|
+
Facter::Util::EC2.can_connect?.should == false
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|