ohai 0.6.12 → 0.6.14.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -64,4 +64,36 @@ describe Ohai::System, "Darwin plugin platform" do
64
64
  @ohai._require_plugin("darwin::platform")
65
65
  @ohai[:platform_build].should == "9F33"
66
66
  end
67
- end
67
+
68
+ it "should set platform_family to mac_os_x" do
69
+ @ohai._require_plugin("darwin::platform")
70
+ @ohai[:platform_family].should == "mac_os_x"
71
+ end
72
+
73
+ describe "on os x server" do
74
+ before(:each) do
75
+ @ohai = Ohai::System.new
76
+ @ohai.stub!(:require_plugin).and_return(true)
77
+ @ohai[:os] = "darwin"
78
+ @pid = 10
79
+ @stdin = mock("STDIN", { :close => true })
80
+ @stdout = mock("STDOUT")
81
+ @stdout.stub!(:each).
82
+ and_yield("ProductName: Mac OS X Server").
83
+ and_yield("ProductVersion: 10.6.8").
84
+ and_yield("BuildVersion: 10K549")
85
+ @stderr = mock("STDERR")
86
+ @ohai.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr)
87
+ end
88
+
89
+ it "should set platform to mac_os_x_server" do
90
+ @ohai._require_plugin("darwin::platform")
91
+ @ohai[:platform].should == "mac_os_x_server"
92
+ end
93
+
94
+ it "should set platform_family to mac_os_x" do
95
+ @ohai._require_plugin("darwin::platform")
96
+ @ohai[:platform_family].should == "mac_os_x"
97
+ end
98
+ end
99
+ end
@@ -85,4 +85,36 @@ describe Ohai::System, "plugin ec2" do
85
85
  @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"}
86
86
  end
87
87
  end
88
+
89
+ describe "with ec2 cloud file" do
90
+ it_should_behave_like "ec2"
91
+
92
+ before(:each) do
93
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
94
+ File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
95
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
96
+ File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
97
+ end
98
+ end
99
+
100
+ describe "without cloud file" do
101
+ it_should_behave_like "!ec2"
102
+
103
+ before(:each) do
104
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(false)
105
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false)
106
+ end
107
+ end
108
+
109
+ describe "with rackspace cloud file" do
110
+ it_should_behave_like "!ec2"
111
+
112
+ before(:each) do
113
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
114
+ File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
115
+ File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
116
+ File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
117
+ end
118
+ end
119
+
88
120
  end
@@ -84,4 +84,36 @@ describe Ohai::System, "plugin eucalyptus" do
84
84
  @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
85
85
  end
86
86
  end
87
+
88
+ describe "with eucalyptus cloud file" do
89
+ it_should_behave_like "eucalyptus"
90
+
91
+ before(:each) do
92
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(true)
93
+ File.stub!(:read).with('/etc/chef/ohai/hints/eucalyptus.json').and_return('')
94
+ File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(true)
95
+ File.stub!(:read).with('C:\chef\ohai\hints/eucalyptus.json').and_return('')
96
+ end
97
+ end
98
+
99
+ describe "without cloud file" do
100
+ it_should_behave_like "!eucalyptus"
101
+
102
+ before(:each) do
103
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false)
104
+ File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false)
105
+ end
106
+ end
107
+
108
+ describe "with ec2 cloud file" do
109
+ it_should_behave_like "!eucalyptus"
110
+
111
+ before(:each) do
112
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
113
+ File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
114
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
115
+ File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
116
+ end
117
+ end
118
+
87
119
  end
@@ -25,10 +25,34 @@ rescue LoadError => e
25
25
  raise e
26
26
  end
27
27
 
28
+ def prepare_data
29
+ @ifconfig_lines = @linux_ifconfig.split("\n")
30
+ @route_lines = @linux_route_n.split("\n")
31
+ @arp_lines = @linux_arp_an.split("\n")
32
+ @ipaddr_lines = @linux_ip_addr.split("\n")
33
+ @iplink_lines = @linux_ip_link_s_d.split("\n")
34
+ @ipneighbor_lines = @linux_ip_neighbor_show.split("\n")
35
+ @ipneighbor_lines_inet6 = @linux_ip_inet6_neighbor_show.split("\n")
36
+ @ip_route_lines = @linux_ip_route.split("\n")
37
+ @ip_route_inet6_lines = @linux_ip_route_inet6.split("\n")
38
+ end
39
+
40
+ def do_stubs
41
+ @ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
42
+ @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
43
+ @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
44
+ @ohai.stub!(:popen4).with("ip -f inet neigh show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
45
+ @ohai.stub!(:popen4).with("ip -f inet6 neigh show").and_yield(nil, @stdin_ipneighbor_inet6, @ipneighbor_lines_inet6, nil)
46
+ @ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
47
+ @ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
48
+ @ohai.stub!(:popen4).with("ip -f inet route show").and_yield(nil, @stdin_ip_route, @ip_route_lines, nil)
49
+ @ohai.stub!(:popen4).with("ip -f inet6 route show").and_yield(nil, @stdin_ip_route_inet6, @ip_route_inet6_lines, nil)
50
+ end
51
+
28
52
  describe Ohai::System, "Linux Network Plugin" do
29
53
 
30
54
  before do
31
- linux_ifconfig = <<-ENDIFCONFIG
55
+ @linux_ifconfig = <<-ENDIFCONFIG
32
56
  eth0 Link encap:Ethernet HWaddr 12:31:3D:02:BE:A2
33
57
  inet addr:10.116.201.76 Bcast:10.116.201.255 Mask:255.255.255.0
34
58
  inet6 addr: fe80::1031:3dff:fe02:bea2/64 Scope:Link
@@ -46,6 +70,8 @@ eth0:5 Link encap:Ethernet HWaddr 00:0c:29:41:71:45
46
70
  eth0.11 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
47
71
  inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0
48
72
  inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
73
+ inet6 addr: 1111:2222:3333:4444::2/64 Scope:Global
74
+ inet6 addr: 1111:2222:3333:4444::3/64 Scope:Global
49
75
  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
50
76
  RX packets:1208795008 errors:0 dropped:0 overruns:0 frame:0
51
77
  TX packets:3269635153 errors:0 dropped:0 overruns:0 carrier:0
@@ -82,6 +108,28 @@ eth0.153 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
82
108
  foo:veth0@eth0 Link encap:Ethernet HWaddr ca:b3:73:8b:0c:e4
83
109
  BROADCAST MULTICAST MTU:1500 Metric:1
84
110
 
111
+ tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
112
+ inet addr:172.16.19.39 P-t-P:172.16.19.1 Mask:255.255.255.255
113
+ UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
114
+ RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
115
+ TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
116
+ collisions:0 txqueuelen:100
117
+ RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
118
+
119
+ venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
120
+ UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
121
+ RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
122
+ TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
123
+ collisions:0 txqueuelen:100
124
+ RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
125
+
126
+ venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
127
+ UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
128
+ RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
129
+ TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
130
+ collisions:0 txqueuelen:100
131
+ RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
132
+
85
133
  lo Link encap:Local Loopback
86
134
  inet addr:127.0.0.1 Mask:255.0.0.0
87
135
  inet6 addr: ::1/128 Scope:Host
@@ -94,7 +142,7 @@ ENDIFCONFIG
94
142
  # Note that ifconfig shows foo:veth0@eth0 but fails to show any address information.
95
143
  # This was not a mistake collecting the output and Apparently ifconfig is broken in this regard.
96
144
 
97
- linux_ip_addr = <<-IP_ADDR
145
+ @linux_ip_addr = <<-IP_ADDR
98
146
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
99
147
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
100
148
  inet 127.0.0.1/8 scope host lo
@@ -108,10 +156,15 @@ ENDIFCONFIG
108
156
  inet 192.168.5.1/24 brd 192.168.5.255 scope global eth0:5
109
157
  inet6 fe80::1031:3dff:fe02:bea2/64 scope link
110
158
  valid_lft forever preferred_lft forever
159
+ inet6 2001:44b8:4160:8f00:a00:27ff:fe13:eacd/64 scope global dynamic
160
+ valid_lft 6128sec preferred_lft 2526sec
111
161
  3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
112
162
  link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
113
163
  inet 192.168.0.16/24 brd 192.168.0.255 scope global eth0.11
114
164
  inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
165
+ inet6 1111:2222:3333:4444::2/64 scope global
166
+ valid_lft forever preferred_lft forever
167
+ inet6 1111:2222:3333:4444::3/64 scope global
115
168
  valid_lft forever preferred_lft forever
116
169
  4: eth0.151@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
117
170
  link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
@@ -132,9 +185,16 @@ ENDIFCONFIG
132
185
  7: foo:veth0@eth0@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN
133
186
  link/ether ca:b3:73:8b:0c:e4 brd ff:ff:ff:ff:ff:ff
134
187
  inet 192.168.212.2/24 scope global foo:veth0@eth0
188
+ 8: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
189
+ link/none
190
+ inet 172.16.19.39 peer 172.16.19.1 scope global tun0
191
+ 9: venet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
192
+ link/void
193
+ inet 127.0.0.2/32 scope host venet0
194
+ inet 172.16.19.48/32 scope global venet0:0
135
195
  IP_ADDR
136
196
 
137
- linux_ip_link_s_d = <<-IP_LINK_S
197
+ @linux_ip_link_s_d = <<-IP_LINK_S
138
198
  1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
139
199
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
140
200
  RX: bytes packets errors dropped overrun mcast
@@ -154,9 +214,21 @@ IP_ADDR
154
214
  0 0 0 0 0 0
155
215
  TX: bytes packets errors dropped carrier collsns
156
216
  0 0 0 0 0 0
217
+ 4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100
218
+ link/none
219
+ RX: bytes packets errors dropped overrun mcast
220
+ 1392844460 2659966 0 0 0 0
221
+ TX: bytes packets errors dropped carrier collsns
222
+ 691785313 1919690 0 0 0 0
223
+ 5: venet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
224
+ link/void
225
+ RX: bytes packets errors dropped overrun mcast
226
+ 1392844460 2659966 0 0 0 0
227
+ TX: bytes packets errors dropped carrier collsns
228
+ 691785313 1919690 0 0 0 0
157
229
  IP_LINK_S
158
230
 
159
- linux_route_n = <<-ROUTE_N
231
+ @linux_route_n = <<-ROUTE_N
160
232
  Kernel IP routing table
161
233
  Destination Gateway Genmask Flags Metric Ref Use Iface
162
234
  10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
@@ -164,24 +236,34 @@ Destination Gateway Genmask Flags Metric Ref Use Iface
164
236
  0.0.0.0 10.116.201.1 0.0.0.0 UG 0 0 0 eth0
165
237
  ROUTE_N
166
238
 
167
- linux_arp_an = <<-ARP_AN
239
+ @linux_arp_an = <<-ARP_AN
168
240
  ? (10.116.201.1) at fe:ff:ff:ff:ff:ff [ether] on eth0
169
241
  ARP_AN
170
242
 
171
- linux_ip_neighbor_show = <<-NEIGHBOR_SHOW
243
+ @linux_ip_neighbor_show = <<-NEIGHBOR_SHOW
172
244
  10.116.201.1 dev eth0 lladdr fe:ff:ff:ff:ff:ff REACHABLE
173
245
  NEIGHBOR_SHOW
174
246
 
175
- linux_ip_route_show_exact = <<-IP_ROUTE
176
- default via 10.116.201.1 dev eth0
177
- IP_ROUTE
247
+ @linux_ip_inet6_neighbor_show = <<-NEIGHBOR_SHOW
248
+ 1111:2222:3333:4444::1 dev eth0.11 lladdr 00:1c:0e:12:34:56 router REACHABLE
249
+ fe80::21c:eff:fe12:3456 dev eth0.11 lladdr 00:1c:0e:30:28:00 router REACHABLE
250
+ fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE
251
+ NEIGHBOR_SHOW
178
252
 
179
- linux_ip_route_scope_link = <<-IP_ROUTE_SCOPE
180
- 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
253
+ @linux_ip_route = <<-IP_ROUTE_SCOPE
254
+ 10.116.201.0/24 dev eth0 proto kernel
181
255
  192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
182
256
  192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
183
257
  172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
184
258
  192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
259
+ default via 10.116.201.1 dev eth0
260
+ IP_ROUTE_SCOPE
261
+
262
+ @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
263
+ fe80::/64 dev eth0 proto kernel metric 256
264
+ fe80::/64 dev eth0.11 proto kernel metric 256
265
+ 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 expires 86023sec
266
+ default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
185
267
  IP_ROUTE_SCOPE
186
268
 
187
269
  @stdin_ifconfig = StringIO.new
@@ -189,17 +271,12 @@ IP_ROUTE_SCOPE
189
271
  @stdin_ipaddr = StringIO.new
190
272
  @stdin_iplink = StringIO.new
191
273
  @stdin_ipneighbor = StringIO.new
192
- @stdin_ip_route_scope_link = StringIO.new
193
-
194
- @ifconfig_lines = linux_ifconfig.split("\n")
195
- @route_lines = linux_route_n.split("\n")
196
- @arp_lines = linux_arp_an.split("\n")
197
- @ipaddr_lines = linux_ip_addr.split("\n")
198
- @iplink_lines = linux_ip_link_s_d.split("\n")
199
- @ipneighbor_lines = linux_ip_neighbor_show.split("\n")
200
- @iproute_lines = linux_ip_route_show_exact
201
- @ip_route_scope_link_lines = linux_ip_route_scope_link.split("\n")
274
+ @stdin_ipneighbor_inet6 = StringIO.new
275
+ @stdin_ip_route = StringIO.new
276
+ @stdin_ip_route_inet6 = StringIO.new
202
277
 
278
+ prepare_data
279
+
203
280
  @ohai = Ohai::System.new
204
281
  @ohai.stub!(:require_plugin).and_return(true)
205
282
 
@@ -212,27 +289,25 @@ IP_ROUTE_SCOPE
212
289
  describe "gathering IP layer address info via #{network_method}" do
213
290
  before do
214
291
  File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
215
- @ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
216
- @ohai.stub!(:from).with("ip route show exact 0.0.0.0/0").and_return(@iproute_lines)
217
- @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
218
- @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
219
- @ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
220
- @ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
221
- @ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
222
- @ohai.stub!(:popen4).with("ip route show scope link").and_yield(nil, @stdin_ip_route_scope_link, @ip_route_scope_link_lines, nil)
223
- @ohai._require_plugin("network")
224
- @ohai._require_plugin("linux::network")
292
+ do_stubs
225
293
  end
226
294
 
227
295
  it "completes the run" do
296
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
297
+ @ohai._require_plugin("network")
298
+ @ohai._require_plugin("linux::network")
228
299
  @ohai['network'].should_not be_nil
229
300
  end
230
301
 
231
302
  it "detects the interfaces" do
232
- @ohai['network']['interfaces'].keys.sort.should == ["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "foo:veth0@eth0", "lo"]
303
+ @ohai._require_plugin("network")
304
+ @ohai._require_plugin("linux::network")
305
+ @ohai['network']['interfaces'].keys.sort.should == ["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "foo:veth0@eth0", "lo", "tun0", "venet0", "venet0:0"]
233
306
  end
234
307
 
235
308
  it "detects the ipv4 addresses of the ethernet interface" do
309
+ @ohai._require_plugin("network")
310
+ @ohai._require_plugin("linux::network")
236
311
  @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('10.116.201.76')
237
312
  @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['netmask'].should == '255.255.255.0'
238
313
  @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['broadcast'].should == '10.116.201.255'
@@ -240,6 +315,8 @@ IP_ROUTE_SCOPE
240
315
  end
241
316
 
242
317
  it "detects the ipv4 addresses of an ethernet subinterface" do
318
+ @ohai._require_plugin("network")
319
+ @ohai._require_plugin("linux::network")
243
320
  @ohai['network']['interfaces']['eth0.11']['addresses'].keys.should include('192.168.0.16')
244
321
  @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['netmask'].should == '255.255.255.0'
245
322
  @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['broadcast'].should == '192.168.0.255'
@@ -247,22 +324,41 @@ IP_ROUTE_SCOPE
247
324
  end
248
325
 
249
326
  it "detects the ipv6 addresses of the ethernet interface" do
327
+ @ohai._require_plugin("network")
328
+ @ohai._require_plugin("linux::network")
250
329
  @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('fe80::1031:3dff:fe02:bea2')
251
330
  @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['scope'].should == 'Link'
252
331
  @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['prefixlen'].should == '64'
253
332
  @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['family'].should == 'inet6'
254
333
  end
255
334
 
335
+ it "detects the ipv6 addresses of an ethernet subinterface" do
336
+ @ohai._require_plugin("network")
337
+ @ohai._require_plugin("linux::network")
338
+ %w[ 1111:2222:3333:4444::2 1111:2222:3333:4444::3 ].each do |addr|
339
+ @ohai['network']['interfaces']['eth0.11']['addresses'].keys.should include(addr)
340
+ @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['scope'].should == 'Global'
341
+ @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['prefixlen'].should == '64'
342
+ @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['family'].should == 'inet6'
343
+ end
344
+ end
345
+
256
346
  it "detects the mac addresses of the ethernet interface" do
347
+ @ohai._require_plugin("network")
348
+ @ohai._require_plugin("linux::network")
257
349
  @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('12:31:3D:02:BE:A2')
258
350
  @ohai['network']['interfaces']['eth0']['addresses']['12:31:3D:02:BE:A2']['family'].should == 'lladdr'
259
351
  end
260
352
 
261
353
  it "detects the encapsulation type of the ethernet interface" do
354
+ @ohai._require_plugin("network")
355
+ @ohai._require_plugin("linux::network")
262
356
  @ohai['network']['interfaces']['eth0']['encapsulation'].should == 'Ethernet'
263
357
  end
264
358
 
265
359
  it "detects the flags of the ethernet interface" do
360
+ @ohai._require_plugin("network")
361
+ @ohai._require_plugin("linux::network")
266
362
  if network_method == "ifconfig"
267
363
  @ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','MULTICAST','RUNNING','UP']
268
364
  else
@@ -271,20 +367,28 @@ IP_ROUTE_SCOPE
271
367
  end
272
368
 
273
369
  it "detects the number of the ethernet interface" do
370
+ @ohai._require_plugin("network")
371
+ @ohai._require_plugin("linux::network")
274
372
  @ohai['network']['interfaces']['eth0']['number'].should == "0"
275
373
  end
276
374
 
277
375
  it "detects the mtu of the ethernet interface" do
376
+ @ohai._require_plugin("network")
377
+ @ohai._require_plugin("linux::network")
278
378
  @ohai['network']['interfaces']['eth0']['mtu'].should == "1500"
279
379
  end
280
380
 
281
381
  it "detects the ipv4 addresses of the loopback interface" do
382
+ @ohai._require_plugin("network")
383
+ @ohai._require_plugin("linux::network")
282
384
  @ohai['network']['interfaces']['lo']['addresses'].keys.should include('127.0.0.1')
283
385
  @ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0'
284
386
  @ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['family'].should == 'inet'
285
387
  end
286
388
 
287
389
  it "detects the ipv6 addresses of the loopback interface" do
390
+ @ohai._require_plugin("network")
391
+ @ohai._require_plugin("linux::network")
288
392
  @ohai['network']['interfaces']['lo']['addresses'].keys.should include('::1')
289
393
  @ohai['network']['interfaces']['lo']['addresses']['::1']['scope'].should == 'Node'
290
394
  @ohai['network']['interfaces']['lo']['addresses']['::1']['prefixlen'].should == '128'
@@ -292,10 +396,14 @@ IP_ROUTE_SCOPE
292
396
  end
293
397
 
294
398
  it "detects the encapsulation type of the loopback interface" do
399
+ @ohai._require_plugin("network")
400
+ @ohai._require_plugin("linux::network")
295
401
  @ohai['network']['interfaces']['lo']['encapsulation'].should == 'Loopback'
296
402
  end
297
403
 
298
404
  it "detects the flags of the ethernet interface" do
405
+ @ohai._require_plugin("network")
406
+ @ohai._require_plugin("linux::network")
299
407
  if network_method == "ifconfig"
300
408
  @ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','RUNNING','UP']
301
409
  else
@@ -305,10 +413,14 @@ IP_ROUTE_SCOPE
305
413
 
306
414
 
307
415
  it "detects the mtu of the loopback interface" do
416
+ @ohai._require_plugin("network")
417
+ @ohai._require_plugin("linux::network")
308
418
  @ohai['network']['interfaces']['lo']['mtu'].should == "16436"
309
419
  end
310
420
 
311
421
  it "detects the arp entries" do
422
+ @ohai._require_plugin("network")
423
+ @ohai._require_plugin("linux::network")
312
424
  @ohai['network']['interfaces']['eth0']['arp']['10.116.201.1'].should == 'fe:ff:ff:ff:ff:ff'
313
425
  end
314
426
 
@@ -317,14 +429,7 @@ IP_ROUTE_SCOPE
317
429
  describe "gathering interface counters via #{network_method}" do
318
430
  before do
319
431
  File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
320
- @ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
321
- @ohai.stub!(:from).with("ip route show exact 0.0.0.0/0").and_return(@iproute_lines)
322
- @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
323
- @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
324
- @ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
325
- @ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
326
- @ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
327
- @ohai.stub!(:popen4).with("ip route show scope link").and_yield(nil, @stdin_ip_route_scope_link, @ip_route_scope_link_lines, nil)
432
+ do_stubs
328
433
  @ohai._require_plugin("network")
329
434
  @ohai._require_plugin("linux::network")
330
435
  end
@@ -364,13 +469,7 @@ IP_ROUTE_SCOPE
364
469
  describe "setting the node's default IP address attribute with #{network_method}" do
365
470
  before do
366
471
  File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
367
- @ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
368
- @ohai.stub!(:from).with("ip route show exact 0.0.0.0/0").and_return(@iproute_lines)
369
- @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
370
- @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
371
- @ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
372
- @ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
373
- @ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
472
+ do_stubs
374
473
  end
375
474
 
376
475
  describe "without a subinterface" do
@@ -380,44 +479,68 @@ IP_ROUTE_SCOPE
380
479
  end
381
480
 
382
481
  it "finds the default interface by asking which iface has the default route" do
383
- @ohai['network'][:default_interface].should == 'eth0'
482
+ @ohai['network']['default_interface'].should == 'eth0'
384
483
  end
385
484
 
386
- it "finds the default interface by asking which iface has the default route" do
387
- @ohai['network'][:default_gateway].should == '10.116.201.1'
485
+ it "finds the default gateway by asking which iface has the default route" do
486
+ @ohai['network']['default_gateway'].should == '10.116.201.1'
388
487
  end
389
488
  end
390
489
 
490
+ describe "with a link level default route" do
491
+ before do
492
+ @linux_ip_route = <<-IP_ROUTE
493
+ 10.116.201.0/24 dev eth0 proto kernel
494
+ default dev eth0 scope link
495
+ IP_ROUTE
496
+ @linux_route_n = <<-ROUTE_N
497
+ Kernel IP routing table
498
+ Destination Gateway Genmask Flags Metric Ref Use Iface
499
+ 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
500
+ 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth0
501
+ ROUTE_N
502
+ prepare_data
503
+ do_stubs
504
+
505
+ @ohai._require_plugin("network")
506
+ @ohai._require_plugin("linux::network")
507
+ end
508
+
509
+ it "finds the default interface by asking which iface has the default route" do
510
+ @ohai['network']['default_interface'].should == 'eth0'
511
+ end
512
+
513
+ it "finds the default interface by asking which iface has the default route" do
514
+ @ohai['network']['default_gateway'].should == '0.0.0.0'
515
+ end
516
+ end
517
+
391
518
  describe "with a subinterface" do
392
519
  before do
393
- linux_ip_route_show_exact = <<-IP_ROUTE
520
+ @linux_ip_route = <<-IP_ROUTE
521
+ 192.168.0.0/24 dev eth0.11 proto kernel src 192.168.0.2
394
522
  default via 192.168.0.15 dev eth0.11
395
523
  IP_ROUTE
396
- linux_route_n = <<-ROUTE_N
524
+ @linux_route_n = <<-ROUTE_N
397
525
  Kernel IP routing table
398
526
  Destination Gateway Genmask Flags Metric Ref Use Iface
399
527
  192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.11
400
- 10.151.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.151
401
- 10.151.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.151
402
- 10.152.0.0 0.0.0.0 255.255.252.0 U 0 0 0 eth0.152
403
- 10.153.0.0 0.0.0.0 255.255.252.0 U 0 0 0 eth0.153
404
528
  0.0.0.0 192.168.0.15 0.0.0.0 UG 0 0 0 eth0.11
405
529
  ROUTE_N
406
530
 
407
- @iproute_lines = linux_ip_route_show_exact
408
- @route_lines = linux_route_n.split("\n")
409
- @ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
410
- @ohai.stub!(:from).with("ip route show exact 0.0.0.0/0").and_return(@iproute_lines)
531
+ prepare_data
532
+ do_stubs
533
+
411
534
  @ohai._require_plugin("network")
412
535
  @ohai._require_plugin("linux::network")
413
536
  end
414
537
 
415
538
  it "finds the default interface by asking which iface has the default route" do
416
- @ohai['network'][:default_interface].should == 'eth0.11'
539
+ @ohai['network']["default_interface"].should == 'eth0.11'
417
540
  end
418
541
 
419
542
  it "finds the default interface by asking which iface has the default route" do
420
- @ohai['network'][:default_gateway].should == '192.168.0.15'
543
+ @ohai['network']["default_gateway"].should == '192.168.0.15'
421
544
  end
422
545
  end
423
546
  end
@@ -426,14 +549,32 @@ ROUTE_N
426
549
  describe "for newer network features using iproute2 only" do
427
550
  before do
428
551
  File.stub!(:exist?).with("/sbin/ip").and_return(true) # iproute2 only
429
- @ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
430
- @ohai.stub!(:from).with("ip route show exact 0.0.0.0/0").and_return(@iproute_lines)
431
- @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
432
- @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
433
- @ohai.stub!(:popen4).with("ip neighbor show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
434
- @ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
435
- @ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
436
- @ohai.stub!(:popen4).with("ip route show scope link").and_yield(nil, @stdin_ip_route_scope_link, @ip_route_scope_link_lines, nil)
552
+ do_stubs
553
+ end
554
+
555
+ it "completes the run" do
556
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
557
+ @ohai._require_plugin("network")
558
+ @ohai._require_plugin("linux::network")
559
+ @ohai['network'].should_not be_nil
560
+ end
561
+
562
+ it "finds the default inet6 interface if there's a inet6 default route" do
563
+ @ohai._require_plugin("network")
564
+ @ohai._require_plugin("linux::network")
565
+ @ohai['network']['default_inet6_interface'].should == 'eth0.11'
566
+ end
567
+
568
+ it "finds the default inet6 gateway if there's a inet6 default route" do
569
+ @ohai._require_plugin("network")
570
+ @ohai._require_plugin("linux::network")
571
+ @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::1'
572
+ end
573
+
574
+ it "finds inet6 neighbours" do
575
+ @ohai._require_plugin("network")
576
+ @ohai._require_plugin("linux::network")
577
+ @ohai['network']['interfaces']['eth0.11']['neighbour_inet6']['1111:2222:3333:4444::1'].should == '00:1c:0e:12:34:56'
437
578
  end
438
579
 
439
580
  it "detects the ipv4 addresses of an ethernet interface with a crazy name" do
@@ -465,45 +606,401 @@ ROUTE_N
465
606
  @ohai['network']['interfaces']['eth0.11']['state'].should == 'up'
466
607
  end
467
608
 
468
- it "adds link level routes" do
469
- @ohai._require_plugin("network")
470
- @ohai._require_plugin("linux::network")
471
- @ohai['network']['interfaces']['eth0']['routes']['10.116.201.0/24'].should == Mash.new( :scope => "Link", :src => "10.116.201.76" )
472
- @ohai['network']['interfaces']['foo:veth0@eth0']['routes']['192.168.212.0/24'].should == Mash.new( :scope => "Link", :src => "192.168.212.2" )
473
- end
474
-
475
- describe "checking for the source address to reach the default gateway" do
476
- it "sets ipaddress" do
609
+ describe "when dealing with routes" do
610
+ it "adds routes" do
477
611
  @ohai._require_plugin("network")
478
612
  @ohai._require_plugin("linux::network")
479
- @ohai['ipaddress'].should == "10.116.201.76"
613
+ @ohai['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.116.201.0/24", :proto => "kernel", :family =>"inet" )
614
+ @ohai['network']['interfaces']['foo:veth0@eth0']['routes'].should include Mash.new( :destination => "192.168.212.0/24", :proto => "kernel", :src => "192.168.212.2", :family =>"inet" )
615
+ @ohai['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "fe80::/64", :metric => "256", :proto => "kernel", :family => "inet6" )
616
+ @ohai['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "1111:2222:3333:4444::/64", :metric => "1024", :family => "inet6" )
617
+ @ohai['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "default", :via => "1111:2222:3333:4444::1", :metric => "1024", :family => "inet6")
480
618
  end
481
619
 
482
- it "sets macaddress" do
483
- @ohai._require_plugin("network")
484
- @ohai._require_plugin("linux::network")
485
- @ohai['macaddress'].should == "12:31:3D:02:BE:A2"
620
+ describe "when there isn't a source field in route entries " do
621
+ it "doesn't set ipaddress" do
622
+ @ohai._require_plugin("network")
623
+ @ohai._require_plugin("linux::network")
624
+ @ohai['ipaddress'].should be nil
625
+ end
626
+
627
+ it "doesn't set macaddress" do
628
+ @ohai._require_plugin("network")
629
+ @ohai._require_plugin("linux::network")
630
+ @ohai['macaddress'].should be nil
631
+ end
632
+
633
+ it "doesn't set ip6address" do
634
+ @ohai._require_plugin("network")
635
+ @ohai._require_plugin("linux::network")
636
+ @ohai['ip6address'].should be nil
637
+ end
486
638
  end
487
- end
488
639
 
489
- # This should never happen in the real world.
490
- describe "when encountering a surprise interface" do
491
- before do
492
- linux_ip_route_scope_link = <<-IP_ROUTE_SCOPE
493
- 192.168.122.0/24 dev virbr0 proto kernel src 192.168.122.1
640
+ describe "when there's a source field in the default route entry" do
641
+ before do
642
+ @linux_ip_route = <<-IP_ROUTE_SCOPE
643
+ 10.116.201.0/24 dev eth0 proto kernel
644
+ 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
645
+ 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
646
+ 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
647
+ 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
648
+ default via 10.116.201.1 dev eth0 src 10.116.201.76
649
+ IP_ROUTE_SCOPE
650
+
651
+ @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
652
+ fe80::/64 dev eth0 proto kernel metric 256
653
+ fe80::/64 dev eth0.11 proto kernel metric 256
654
+ 1111:2222:3333:4444::/64 dev eth0.11 metric 1024
655
+ default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
494
656
  IP_ROUTE_SCOPE
495
- @ip_route_scope_link_lines = linux_ip_route_scope_link.split("\n")
496
- @ohai.stub!(:popen4).with("ip route show scope link").and_yield(nil, @stdin_ip_route_scope_link, @ip_route_scope_link_lines, nil)
657
+
658
+ prepare_data
659
+ do_stubs
660
+ end
661
+
662
+ it "completes the run" do
663
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
664
+ @ohai._require_plugin("network")
665
+ @ohai._require_plugin("linux::network")
666
+ @ohai['network'].should_not be_nil
667
+ end
668
+
669
+ it "sets ipaddress" do
670
+ @ohai._require_plugin("network")
671
+ @ohai._require_plugin("linux::network")
672
+ @ohai['ipaddress'].should == "10.116.201.76"
673
+ end
674
+
675
+ it "sets ip6address" do
676
+ @ohai._require_plugin("network")
677
+ @ohai._require_plugin("linux::network")
678
+ @ohai['ip6address'].should == "1111:2222:3333:4444::3"
679
+ end
497
680
  end
498
-
499
- it "logs a message and skips previously unseen interfaces in 'ip route show scope link'" do
500
- Ohai::Log.should_receive(:debug).with("Skipping previously unseen interface from 'ip route show scope link': virbr0").once
501
- Ohai::Log.should_receive(:debug).any_number_of_times # Catches the 'Loading plugin network' type messages
502
- @ohai._require_plugin("network")
503
- @ohai._require_plugin("linux::network")
681
+
682
+ describe "when there're several default routes" do
683
+ before do
684
+ @linux_ip_route = <<-IP_ROUTE_SCOPE
685
+ 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
686
+ 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
687
+ 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
688
+ 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
689
+ 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
690
+ default via 10.116.201.1 dev eth0 metric 10
691
+ default via 10.116.201.254 dev eth0 metric 9
692
+ IP_ROUTE_SCOPE
693
+
694
+ @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
695
+ fe80::/64 dev eth0 proto kernel metric 256
696
+ fe80::/64 dev eth0.11 proto kernel metric 256
697
+ 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
698
+ default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
699
+ default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023
700
+ IP_ROUTE_SCOPE
701
+
702
+ prepare_data
703
+ do_stubs
704
+ end
705
+
706
+ it "completes the run" do
707
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
708
+ @ohai._require_plugin("network")
709
+ @ohai._require_plugin("linux::network")
710
+ @ohai['network'].should_not be_nil
711
+ end
712
+
713
+ it "sets default ipv4 interface and gateway" do
714
+ @ohai._require_plugin("network")
715
+ @ohai._require_plugin("linux::network")
716
+ @ohai['network']['default_interface'].should == 'eth0'
717
+ @ohai['network']['default_gateway'].should == '10.116.201.254'
718
+ end
719
+
720
+ it "sets default ipv6 interface and gateway" do
721
+ @ohai._require_plugin("network")
722
+ @ohai._require_plugin("linux::network")
723
+ @ohai['network']['default_inet6_interface'].should == 'eth0.11'
724
+ @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::ffff'
725
+ end
726
+ end
727
+
728
+ describe "when there're a mixed setup of routes that could be used to set ipaddress" do
729
+ before do
730
+ @linux_ip_route = <<-IP_ROUTE_SCOPE
731
+ 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
732
+ 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
733
+ 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
734
+ 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
735
+ 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
736
+ default via 10.116.201.1 dev eth0 metric 10
737
+ default via 10.116.201.254 dev eth0 metric 9 src 10.116.201.74
738
+ IP_ROUTE_SCOPE
739
+
740
+ @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
741
+ fe80::/64 dev eth0 proto kernel metric 256
742
+ fe80::/64 dev eth0.11 proto kernel metric 256
743
+ 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
744
+ default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
745
+ default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 src 1111:2222:3333:4444::2
746
+ IP_ROUTE_SCOPE
747
+
748
+ prepare_data
749
+ do_stubs
750
+ end
751
+
752
+ it "completes the run" do
753
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
754
+ @ohai._require_plugin("network")
755
+ @ohai._require_plugin("linux::network")
756
+ @ohai['network'].should_not be_nil
757
+ end
758
+
759
+ it "sets ipaddress" do
760
+ @ohai._require_plugin("network")
761
+ @ohai._require_plugin("linux::network")
762
+ @ohai["ipaddress"].should == "10.116.201.74"
763
+ end
764
+
765
+ it "sets ip6address" do
766
+ @ohai._require_plugin("network")
767
+ @ohai._require_plugin("linux::network")
768
+ @ohai["ip6address"].should == "1111:2222:3333:4444::2"
769
+ end
770
+ end
771
+
772
+ describe "when there's a source field in a local route entry " do
773
+ before do
774
+ @linux_ip_route = <<-IP_ROUTE_SCOPE
775
+ 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
776
+ 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
777
+ 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
778
+ 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
779
+ 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
780
+ default via 10.116.201.1 dev eth0
781
+ IP_ROUTE_SCOPE
782
+
783
+ @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
784
+ fe80::/64 dev eth0 proto kernel metric 256
785
+ fe80::/64 dev eth0.11 proto kernel metric 256
786
+ 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
787
+ default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
788
+ IP_ROUTE_SCOPE
789
+
790
+ prepare_data
791
+ do_stubs
792
+ end
793
+
794
+ it "completes the run" do
795
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
796
+ @ohai._require_plugin("network")
797
+ @ohai._require_plugin("linux::network")
798
+ @ohai['network'].should_not be_nil
799
+ end
800
+
801
+ it "sets ipaddress" do
802
+ @ohai._require_plugin("network")
803
+ @ohai._require_plugin("linux::network")
804
+ @ohai['ipaddress'].should == "10.116.201.76"
805
+ end
806
+
807
+ describe "when about to set macaddress" do
808
+ it "sets macaddress" do
809
+ @ohai._require_plugin("network")
810
+ @ohai._require_plugin("linux::network")
811
+ @ohai['macaddress'].should == "12:31:3D:02:BE:A2"
812
+ end
813
+
814
+ describe "when then interface has the NOARP flag" do
815
+ before do
816
+ @linux_ip_route = <<-IP_ROUTE
817
+ 10.118.19.1 dev tun0 proto kernel src 10.118.19.39
818
+ default via 172.16.19.1 dev tun0
819
+ IP_ROUTE
820
+
821
+ prepare_data
822
+ do_stubs
823
+ end
824
+
825
+ it "completes the run" do
826
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
827
+ @ohai._require_plugin("network")
828
+ @ohai._require_plugin("linux::network")
829
+ @ohai['network'].should_not be_nil
830
+ end
831
+
832
+ it "doesn't set macaddress" do
833
+ @ohai._require_plugin("network")
834
+ @ohai._require_plugin("linux::network")
835
+ @ohai['macaddress'].should be_nil
836
+ end
837
+ end
838
+ end
839
+
840
+ it "sets ip6address" do
841
+ @ohai._require_plugin("network")
842
+ @ohai._require_plugin("linux::network")
843
+ @ohai['ip6address'].should == "1111:2222:3333:4444::3"
844
+ end
845
+ end
846
+
847
+ describe "with a link level default route" do
848
+ before do
849
+ @linux_ip_route = <<-IP_ROUTE
850
+ default dev venet0 scope link
851
+ IP_ROUTE
852
+
853
+ prepare_data
854
+ do_stubs
855
+ end
856
+
857
+ it "completes the run" do
858
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
859
+ @ohai._require_plugin("network")
860
+ @ohai._require_plugin("linux::network")
861
+ @ohai['network'].should_not be_nil
862
+ end
863
+
864
+ it "doesn't set ipaddress" do
865
+ @ohai._require_plugin("network")
866
+ @ohai._require_plugin("linux::network")
867
+ @ohai['ipaddress'].should be_nil
868
+ end
869
+ end
870
+
871
+ describe "when not having a global scope ipv6 address" do
872
+ before do
873
+ @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
874
+ fe80::/64 dev eth0 proto kernel metric 256
875
+ default via fe80::21c:eff:fe12:3456 dev eth0.153 src fe80::2e0:81ff:fe2b:48e7 metric 1024
876
+ IP_ROUTE_SCOPE
877
+
878
+ prepare_data
879
+ do_stubs
880
+ end
881
+
882
+ it "completes the run" do
883
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
884
+ @ohai._require_plugin("network")
885
+ @ohai._require_plugin("linux::network")
886
+ @ohai['network'].should_not be_nil
887
+ end
888
+
889
+ it "doesn't set ip6address" do
890
+ @ohai._require_plugin("network")
891
+ @ohai._require_plugin("linux::network")
892
+ @ohai['ip6address'].should be_nil
893
+ end
894
+
895
+ end
896
+
897
+ describe "with no default route" do
898
+ before do
899
+ @linux_ip_route = <<-IP_ROUTE
900
+ 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
901
+ 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
902
+ 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
903
+ 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
904
+ 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
905
+ IP_ROUTE
906
+
907
+ @linux_ip_route_inet6 = <<-IP_ROUTE
908
+ fe80::/64 dev eth0 proto kernel metric 256
909
+ fe80::/64 dev eth0.11 proto kernel metric 256
910
+ 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
911
+ IP_ROUTE
912
+
913
+ prepare_data
914
+ do_stubs
915
+ end
916
+
917
+ it "completes the run" do
918
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
919
+ @ohai._require_plugin("network")
920
+ @ohai._require_plugin("linux::network")
921
+ @ohai['network'].should_not be_nil
922
+ end
923
+
924
+ it "doesn't set ipaddress" do
925
+ @ohai._require_plugin("network")
926
+ @ohai._require_plugin("linux::network")
927
+ @ohai['ipaddress'].should be_nil
928
+ end
929
+
930
+ it "doesn't set ip6address" do
931
+ @ohai._require_plugin("network")
932
+ @ohai._require_plugin("linux::network")
933
+ @ohai['ip6address'].should be_nil
934
+ end
935
+ end
936
+
937
+ describe "with irrelevant routes (container setups)" do
938
+ before do
939
+ @linux_ip_route = <<-IP_ROUTE
940
+ 10.116.201.0/26 dev eth0 proto kernel src 10.116.201.39
941
+ 10.116.201.0/26 dev if4 proto kernel src 10.116.201.45
942
+ 10.118.19.0/26 dev eth0 proto kernel src 10.118.19.39
943
+ 10.118.19.0/26 dev if5 proto kernel src 10.118.19.45
944
+ default via 10.116.201.1 dev eth0 src 10.116.201.99
945
+ IP_ROUTE
946
+
947
+ @linux_ip_route_inet6 = <<-IP_ROUTE
948
+ fe80::/64 dev eth0 proto kernel metric 256
949
+ fe80::/64 dev eth0.11 proto kernel metric 256
950
+ 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::FFFF:2
951
+ default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
952
+ IP_ROUTE
953
+
954
+ prepare_data
955
+ do_stubs
956
+ end
957
+
958
+ it "completes the run" do
959
+ Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
960
+ @ohai._require_plugin("network")
961
+ @ohai._require_plugin("linux::network")
962
+ @ohai['network'].should_not be_nil
963
+ end
964
+
965
+ it "doesn't add bogus routes" do
966
+ @ohai._require_plugin("network")
967
+ @ohai._require_plugin("linux::network")
968
+ @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.116.201.0/26", :proto => "kernel", :family => "inet", :via => "10.116.201.39" )
969
+ @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.118.19.0/26", :proto => "kernel", :family => "inet", :via => "10.118.19.39" )
970
+ @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "1111:2222:3333:4444::/64", :family => "inet6", :metric => "1024" )
971
+ end
972
+
973
+ it "doesn't set ipaddress" do
974
+ @ohai._require_plugin("network")
975
+ @ohai._require_plugin("linux::network")
976
+ @ohai['ipaddress'].should be_nil
977
+ end
978
+
979
+ it "doesn't set ip6address" do
980
+ @ohai._require_plugin("network")
981
+ @ohai._require_plugin("linux::network")
982
+ @ohai['ip6address'].should be_nil
983
+ end
984
+ end
985
+
986
+ # This should never happen in the real world.
987
+ describe "when encountering a surprise interface" do
988
+ before do
989
+ @linux_ip_route = <<-IP_ROUTE
990
+ 192.168.122.0/24 dev virbr0 proto kernel src 192.168.122.1
991
+ IP_ROUTE
992
+ prepare_data
993
+ do_stubs
994
+ end
995
+
996
+ it "logs a message and skips previously unseen interfaces in 'ip route show'" do
997
+ Ohai::Log.should_receive(:debug).with("Skipping previously unseen interface from 'ip route show': virbr0").once
998
+ Ohai::Log.should_receive(:debug).any_number_of_times # Catches the 'Loading plugin network' type messages
999
+ @ohai._require_plugin("network")
1000
+ @ohai._require_plugin("linux::network")
1001
+ end
504
1002
  end
505
1003
  end
506
- end
1004
+ end
507
1005
 
508
1006
  end
509
-