PageRenderTime 63ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/spec/unit/plugins/linux/network_spec.rb

https://github.com/jmanero/ohai
Ruby | 949 lines | 843 code | 87 blank | 19 comment | 65 complexity | 038368ff6459306e966ac76c477e1749 MD5 | raw file
Possible License(s): Apache-2.0
  1. #
  2. # Author:: Caleb Tennis <caleb.tennis@gmail.com>
  3. # Copyright:: Copyright (c) 2011 Opscode, Inc.
  4. # License:: Apache License, Version 2.0
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License");
  7. # you may not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #
  18. require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
  19. begin
  20. require 'ipaddress'
  21. rescue LoadError => e
  22. puts "The linux network plugin spec tests will fail without the 'ipaddress' library/gem.\n\n"
  23. raise e
  24. end
  25. def prepare_data
  26. @ifconfig_lines = @linux_ifconfig.split("\n")
  27. @route_lines = @linux_route_n.split("\n")
  28. @arp_lines = @linux_arp_an.split("\n")
  29. @ipaddr_lines = @linux_ip_addr.split("\n")
  30. @iplink_lines = @linux_ip_link_s_d.split("\n")
  31. @ipneighbor_lines = @linux_ip_neighbor_show.split("\n")
  32. @ipneighbor_lines_inet6 = @linux_ip_inet6_neighbor_show.split("\n")
  33. @ip_route_lines = @linux_ip_route.split("\n")
  34. @ip_route_inet6_lines = @linux_ip_route_inet6.split("\n")
  35. end
  36. def do_stubs
  37. @ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
  38. @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
  39. @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
  40. @ohai.stub!(:popen4).with("ip -f inet neigh show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
  41. @ohai.stub!(:popen4).with("ip -f inet6 neigh show").and_yield(nil, @stdin_ipneighbor_inet6, @ipneighbor_lines_inet6, nil)
  42. @ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
  43. @ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
  44. @ohai.stub!(:popen4).with("ip -f inet route show").and_yield(nil, @stdin_ip_route, @ip_route_lines, nil)
  45. @ohai.stub!(:popen4).with("ip -f inet6 route show").and_yield(nil, @stdin_ip_route_inet6, @ip_route_inet6_lines, nil)
  46. end
  47. describe Ohai::System, "Linux Network Plugin" do
  48. before do
  49. @linux_ifconfig = <<-ENDIFCONFIG
  50. eth0 Link encap:Ethernet HWaddr 12:31:3D:02:BE:A2
  51. inet addr:10.116.201.76 Bcast:10.116.201.255 Mask:255.255.255.0
  52. inet6 addr: fe80::1031:3dff:fe02:bea2/64 Scope:Link
  53. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  54. RX packets:2659966 errors:0 dropped:0 overruns:0 frame:0
  55. TX packets:1919690 errors:0 dropped:0 overruns:0 carrier:0
  56. collisions:0 txqueuelen:1000
  57. RX bytes:1392844460 (1.2 GiB) TX bytes:691785313 (659.7 MiB)
  58. Interrupt:16
  59. eth0:5 Link encap:Ethernet HWaddr 00:0c:29:41:71:45
  60. inet addr:192.168.5.1 Bcast:192.168.5.255 Mask:255.255.255.0
  61. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  62. eth0.11 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
  63. inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0
  64. inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
  65. inet6 addr: 1111:2222:3333:4444::2/64 Scope:Global
  66. inet6 addr: 1111:2222:3333:4444::3/64 Scope:Global
  67. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  68. RX packets:1208795008 errors:0 dropped:0 overruns:0 frame:0
  69. TX packets:3269635153 errors:0 dropped:0 overruns:0 carrier:0
  70. collisions:0 txqueuelen:0
  71. RX bytes:1751940374 (1.6 GiB) TX bytes:2195567597 (2.0 GiB)
  72. eth0.151 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
  73. inet addr:10.151.0.16 Bcast:10.151.0.255 Mask:255.255.255.0
  74. inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
  75. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  76. RX packets:206553677 errors:0 dropped:0 overruns:0 frame:0
  77. TX packets:163901336 errors:0 dropped:0 overruns:0 carrier:0
  78. collisions:0 txqueuelen:0
  79. RX bytes:3190792261 (2.9 GiB) TX bytes:755086548 (720.1 MiB)
  80. eth0.152 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
  81. inet addr:10.152.1.16 Bcast:10.152.3.255 Mask:255.255.252.0
  82. inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
  83. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  84. RX packets:14016741 errors:0 dropped:0 overruns:0 frame:0
  85. TX packets:55232 errors:0 dropped:0 overruns:0 carrier:0
  86. collisions:0 txqueuelen:0
  87. RX bytes:664957462 (634.1 MiB) TX bytes:4876434 (4.6 MiB)
  88. eth0.153 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
  89. inet addr:10.153.1.16 Bcast:10.153.3.255 Mask:255.255.252.0
  90. inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
  91. UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
  92. RX packets:2022667595 errors:0 dropped:0 overruns:0 frame:0
  93. TX packets:1798627472 errors:0 dropped:0 overruns:0 carrier:0
  94. collisions:0 txqueuelen:0
  95. RX bytes:4047036732 (3.7 GiB) TX bytes:3451231474 (3.2 GiB)
  96. foo:veth0@eth0 Link encap:Ethernet HWaddr ca:b3:73:8b:0c:e4
  97. BROADCAST MULTICAST MTU:1500 Metric:1
  98. tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
  99. inet addr:172.16.19.39 P-t-P:172.16.19.1 Mask:255.255.255.255
  100. UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
  101. RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
  102. TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
  103. collisions:0 txqueuelen:100
  104. RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
  105. venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
  106. UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
  107. RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
  108. TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
  109. collisions:0 txqueuelen:100
  110. RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
  111. venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
  112. UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
  113. RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
  114. TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
  115. collisions:0 txqueuelen:100
  116. RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
  117. lo Link encap:Local Loopback
  118. inet addr:127.0.0.1 Mask:255.0.0.0
  119. inet6 addr: ::1/128 Scope:Host
  120. UP LOOPBACK RUNNING MTU:16436 Metric:1
  121. RX packets:524 errors:0 dropped:0 overruns:0 frame:0
  122. TX packets:524 errors:0 dropped:0 overruns:0 carrier:0
  123. collisions:0 txqueuelen:0
  124. RX bytes:35224 (34.3 KiB) TX bytes:35224 (34.3 KiB)
  125. ENDIFCONFIG
  126. # Note that ifconfig shows foo:veth0@eth0 but fails to show any address information.
  127. # This was not a mistake collecting the output and Apparently ifconfig is broken in this regard.
  128. @linux_ip_addr = <<-IP_ADDR
  129. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
  130. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  131. inet 127.0.0.1/8 scope host lo
  132. inet6 ::1/128 scope host
  133. valid_lft forever preferred_lft forever
  134. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  135. link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff
  136. inet 10.116.201.76/24 brd 10.116.201.255 scope global eth0
  137. inet 10.116.201.75/32 scope global eth0
  138. inet 10.116.201.74/24 scope global secondary eth0
  139. inet 192.168.5.1/24 brd 192.168.5.255 scope global eth0:5
  140. inet6 fe80::1031:3dff:fe02:bea2/64 scope link
  141. valid_lft forever preferred_lft forever
  142. inet6 2001:44b8:4160:8f00:a00:27ff:fe13:eacd/64 scope global dynamic
  143. valid_lft 6128sec preferred_lft 2526sec
  144. 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
  145. link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
  146. inet 192.168.0.16/24 brd 192.168.0.255 scope global eth0.11
  147. inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
  148. inet6 1111:2222:3333:4444::2/64 scope global
  149. valid_lft forever preferred_lft forever
  150. inet6 1111:2222:3333:4444::3/64 scope global
  151. valid_lft forever preferred_lft forever
  152. 4: eth0.151@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
  153. link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
  154. inet 10.151.0.16/24 brd 10.151.0.255 scope global eth0.151
  155. inet 10.151.1.16/24 scope global eth0.151
  156. inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
  157. valid_lft forever preferred_lft forever
  158. 5: eth0.152@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
  159. link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
  160. inet 10.152.1.16/22 brd 10.152.3.255 scope global eth0.152
  161. inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
  162. valid_lft forever preferred_lft forever
  163. 6: eth0.153@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
  164. link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
  165. inet 10.153.1.16/22 brd 10.153.3.255 scope global eth0.153
  166. inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
  167. valid_lft forever preferred_lft forever
  168. 7: foo:veth0@eth0@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN
  169. link/ether ca:b3:73:8b:0c:e4 brd ff:ff:ff:ff:ff:ff
  170. inet 192.168.212.2/24 scope global foo:veth0@eth0
  171. 8: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
  172. link/none
  173. inet 172.16.19.39 peer 172.16.19.1 scope global tun0
  174. 9: venet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
  175. link/void
  176. inet 127.0.0.2/32 scope host venet0
  177. inet 172.16.19.48/32 scope global venet0:0
  178. IP_ADDR
  179. @linux_ip_link_s_d = <<-IP_LINK_S
  180. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
  181. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  182. RX: bytes packets errors dropped overrun mcast
  183. 35224 524 0 0 0 0
  184. TX: bytes packets errors dropped carrier collsns
  185. 35224 524 0 0 0 0
  186. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  187. link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff
  188. RX: bytes packets errors dropped overrun mcast
  189. 1392844460 2659966 0 0 0 0
  190. TX: bytes packets errors dropped carrier collsns
  191. 691785313 1919690 0 0 0 0
  192. 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
  193. link/ether 00:0c:29:41:71:45 brd ff:ff:ff:ff:ff:ff
  194. vlan id 11 <REORDER_HDR>
  195. RX: bytes packets errors dropped overrun mcast
  196. 0 0 0 0 0 0
  197. TX: bytes packets errors dropped carrier collsns
  198. 0 0 0 0 0 0
  199. 4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100
  200. link/none
  201. RX: bytes packets errors dropped overrun mcast
  202. 1392844460 2659966 0 0 0 0
  203. TX: bytes packets errors dropped carrier collsns
  204. 691785313 1919690 0 0 0 0
  205. 5: venet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
  206. link/void
  207. RX: bytes packets errors dropped overrun mcast
  208. 1392844460 2659966 0 0 0 0
  209. TX: bytes packets errors dropped carrier collsns
  210. 691785313 1919690 0 0 0 0
  211. IP_LINK_S
  212. @linux_route_n = <<-ROUTE_N
  213. Kernel IP routing table
  214. Destination Gateway Genmask Flags Metric Ref Use Iface
  215. 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
  216. 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
  217. 0.0.0.0 10.116.201.1 0.0.0.0 UG 0 0 0 eth0
  218. ROUTE_N
  219. @linux_arp_an = <<-ARP_AN
  220. ? (10.116.201.1) at fe:ff:ff:ff:ff:ff [ether] on eth0
  221. ARP_AN
  222. @linux_ip_neighbor_show = <<-NEIGHBOR_SHOW
  223. 10.116.201.1 dev eth0 lladdr fe:ff:ff:ff:ff:ff REACHABLE
  224. NEIGHBOR_SHOW
  225. @linux_ip_inet6_neighbor_show = <<-NEIGHBOR_SHOW
  226. 1111:2222:3333:4444::1 dev eth0.11 lladdr 00:1c:0e:12:34:56 router REACHABLE
  227. fe80::21c:eff:fe12:3456 dev eth0.11 lladdr 00:1c:0e:30:28:00 router REACHABLE
  228. fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE
  229. NEIGHBOR_SHOW
  230. @linux_ip_route = <<-IP_ROUTE_SCOPE
  231. 10.116.201.0/24 dev eth0 proto kernel
  232. 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
  233. 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
  234. 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
  235. 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
  236. default via 10.116.201.1 dev eth0
  237. IP_ROUTE_SCOPE
  238. @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
  239. fe80::/64 dev eth0 proto kernel metric 256
  240. fe80::/64 dev eth0.11 proto kernel metric 256
  241. 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 expires 86023sec
  242. default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
  243. IP_ROUTE_SCOPE
  244. @stdin_ifconfig = StringIO.new
  245. @stdin_arp = StringIO.new
  246. @stdin_ipaddr = StringIO.new
  247. @stdin_iplink = StringIO.new
  248. @stdin_ipneighbor = StringIO.new
  249. @stdin_ipneighbor_inet6 = StringIO.new
  250. @stdin_ip_route = StringIO.new
  251. @stdin_ip_route_inet6 = StringIO.new
  252. prepare_data
  253. @ohai = Ohai::System.new
  254. @ohai.stub!(:require_plugin).and_return(true)
  255. @ohai.stub(:popen4).with("ifconfig -a")
  256. @ohai.stub(:popen4).with("arp -an")
  257. Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(3).times
  258. @ohai._require_plugin("network")
  259. end
  260. ["ifconfig","iproute2"].each do |network_method|
  261. describe "gathering IP layer address info via #{network_method}" do
  262. before do
  263. File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
  264. do_stubs
  265. end
  266. it "completes the run" do
  267. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  268. @ohai._require_plugin("linux::network")
  269. @ohai['network'].should_not be_nil
  270. end
  271. it "detects the interfaces" do
  272. @ohai._require_plugin("linux::network")
  273. @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"]
  274. end
  275. it "detects the ipv4 addresses of the ethernet interface" do
  276. @ohai._require_plugin("linux::network")
  277. @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('10.116.201.76')
  278. @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['netmask'].should == '255.255.255.0'
  279. @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['broadcast'].should == '10.116.201.255'
  280. @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['family'].should == 'inet'
  281. end
  282. it "detects the ipv4 addresses of an ethernet subinterface" do
  283. @ohai._require_plugin("linux::network")
  284. @ohai['network']['interfaces']['eth0.11']['addresses'].keys.should include('192.168.0.16')
  285. @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['netmask'].should == '255.255.255.0'
  286. @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['broadcast'].should == '192.168.0.255'
  287. @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['family'].should == 'inet'
  288. end
  289. it "detects the ipv6 addresses of the ethernet interface" do
  290. @ohai._require_plugin("linux::network")
  291. @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('fe80::1031:3dff:fe02:bea2')
  292. @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['scope'].should == 'Link'
  293. @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['prefixlen'].should == '64'
  294. @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['family'].should == 'inet6'
  295. end
  296. it "detects the ipv6 addresses of an ethernet subinterface" do
  297. @ohai._require_plugin("linux::network")
  298. %w[ 1111:2222:3333:4444::2 1111:2222:3333:4444::3 ].each do |addr|
  299. @ohai['network']['interfaces']['eth0.11']['addresses'].keys.should include(addr)
  300. @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['scope'].should == 'Global'
  301. @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['prefixlen'].should == '64'
  302. @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['family'].should == 'inet6'
  303. end
  304. end
  305. it "detects the mac addresses of the ethernet interface" do
  306. @ohai._require_plugin("linux::network")
  307. @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('12:31:3D:02:BE:A2')
  308. @ohai['network']['interfaces']['eth0']['addresses']['12:31:3D:02:BE:A2']['family'].should == 'lladdr'
  309. end
  310. it "detects the encapsulation type of the ethernet interface" do
  311. @ohai._require_plugin("linux::network")
  312. @ohai['network']['interfaces']['eth0']['encapsulation'].should == 'Ethernet'
  313. end
  314. it "detects the flags of the ethernet interface" do
  315. @ohai._require_plugin("linux::network")
  316. if network_method == "ifconfig"
  317. @ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','MULTICAST','RUNNING','UP']
  318. else
  319. @ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','LOWER_UP','MULTICAST','UP']
  320. end
  321. end
  322. it "detects the number of the ethernet interface" do
  323. @ohai._require_plugin("linux::network")
  324. @ohai['network']['interfaces']['eth0']['number'].should == "0"
  325. end
  326. it "detects the mtu of the ethernet interface" do
  327. @ohai._require_plugin("linux::network")
  328. @ohai['network']['interfaces']['eth0']['mtu'].should == "1500"
  329. end
  330. it "detects the ipv4 addresses of the loopback interface" do
  331. @ohai._require_plugin("linux::network")
  332. @ohai['network']['interfaces']['lo']['addresses'].keys.should include('127.0.0.1')
  333. @ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0'
  334. @ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['family'].should == 'inet'
  335. end
  336. it "detects the ipv6 addresses of the loopback interface" do
  337. @ohai._require_plugin("linux::network")
  338. @ohai['network']['interfaces']['lo']['addresses'].keys.should include('::1')
  339. @ohai['network']['interfaces']['lo']['addresses']['::1']['scope'].should == 'Node'
  340. @ohai['network']['interfaces']['lo']['addresses']['::1']['prefixlen'].should == '128'
  341. @ohai['network']['interfaces']['lo']['addresses']['::1']['family'].should == 'inet6'
  342. end
  343. it "detects the encapsulation type of the loopback interface" do
  344. @ohai._require_plugin("linux::network")
  345. @ohai['network']['interfaces']['lo']['encapsulation'].should == 'Loopback'
  346. end
  347. it "detects the flags of the ethernet interface" do
  348. @ohai._require_plugin("linux::network")
  349. if network_method == "ifconfig"
  350. @ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','RUNNING','UP']
  351. else
  352. @ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','LOWER_UP','UP']
  353. end
  354. end
  355. it "detects the mtu of the loopback interface" do
  356. @ohai._require_plugin("linux::network")
  357. @ohai['network']['interfaces']['lo']['mtu'].should == "16436"
  358. end
  359. it "detects the arp entries" do
  360. @ohai._require_plugin("linux::network")
  361. @ohai['network']['interfaces']['eth0']['arp']['10.116.201.1'].should == 'fe:ff:ff:ff:ff:ff'
  362. end
  363. end
  364. describe "gathering interface counters via #{network_method}" do
  365. before do
  366. File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
  367. do_stubs
  368. @ohai._require_plugin("linux::network")
  369. end
  370. it "detects the ethernet counters" do
  371. @ohai['counters']['network']['interfaces']['eth0']['tx']['bytes'].should == "691785313"
  372. @ohai['counters']['network']['interfaces']['eth0']['tx']['packets'].should == "1919690"
  373. @ohai['counters']['network']['interfaces']['eth0']['tx']['collisions'].should == "0"
  374. @ohai['counters']['network']['interfaces']['eth0']['tx']['queuelen'].should == "1000"
  375. @ohai['counters']['network']['interfaces']['eth0']['tx']['errors'].should == "0"
  376. @ohai['counters']['network']['interfaces']['eth0']['tx']['carrier'].should == "0"
  377. @ohai['counters']['network']['interfaces']['eth0']['tx']['drop'].should == "0"
  378. @ohai['counters']['network']['interfaces']['eth0']['rx']['bytes'].should == "1392844460"
  379. @ohai['counters']['network']['interfaces']['eth0']['rx']['packets'].should == "2659966"
  380. @ohai['counters']['network']['interfaces']['eth0']['rx']['errors'].should == "0"
  381. @ohai['counters']['network']['interfaces']['eth0']['rx']['overrun'].should == "0"
  382. @ohai['counters']['network']['interfaces']['eth0']['rx']['drop'].should == "0"
  383. end
  384. it "detects the loopback counters" do
  385. @ohai['counters']['network']['interfaces']['lo']['tx']['bytes'].should == "35224"
  386. @ohai['counters']['network']['interfaces']['lo']['tx']['packets'].should == "524"
  387. @ohai['counters']['network']['interfaces']['lo']['tx']['collisions'].should == "0"
  388. @ohai['counters']['network']['interfaces']['lo']['tx']['errors'].should == "0"
  389. @ohai['counters']['network']['interfaces']['lo']['tx']['carrier'].should == "0"
  390. @ohai['counters']['network']['interfaces']['lo']['tx']['drop'].should == "0"
  391. @ohai['counters']['network']['interfaces']['lo']['rx']['bytes'].should == "35224"
  392. @ohai['counters']['network']['interfaces']['lo']['rx']['packets'].should == "524"
  393. @ohai['counters']['network']['interfaces']['lo']['rx']['errors'].should == "0"
  394. @ohai['counters']['network']['interfaces']['lo']['rx']['overrun'].should == "0"
  395. @ohai['counters']['network']['interfaces']['lo']['rx']['drop'].should == "0"
  396. end
  397. end
  398. describe "setting the node's default IP address attribute with #{network_method}" do
  399. before do
  400. File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
  401. do_stubs
  402. end
  403. describe "without a subinterface" do
  404. before do
  405. @ohai._require_plugin("linux::network")
  406. end
  407. it "finds the default interface by asking which iface has the default route" do
  408. @ohai['network']['default_interface'].should == 'eth0'
  409. end
  410. it "finds the default gateway by asking which iface has the default route" do
  411. @ohai['network']['default_gateway'].should == '10.116.201.1'
  412. end
  413. end
  414. describe "with a link level default route" do
  415. before do
  416. @linux_ip_route = <<-IP_ROUTE
  417. 10.116.201.0/24 dev eth0 proto kernel
  418. default dev eth0 scope link
  419. IP_ROUTE
  420. @linux_route_n = <<-ROUTE_N
  421. Kernel IP routing table
  422. Destination Gateway Genmask Flags Metric Ref Use Iface
  423. 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
  424. 0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth0
  425. ROUTE_N
  426. prepare_data
  427. do_stubs
  428. @ohai._require_plugin("linux::network")
  429. end
  430. it "finds the default interface by asking which iface has the default route" do
  431. @ohai['network']['default_interface'].should == 'eth0'
  432. end
  433. it "finds the default interface by asking which iface has the default route" do
  434. @ohai['network']['default_gateway'].should == '0.0.0.0'
  435. end
  436. end
  437. describe "with a subinterface" do
  438. before do
  439. @linux_ip_route = <<-IP_ROUTE
  440. 192.168.0.0/24 dev eth0.11 proto kernel src 192.168.0.2
  441. default via 192.168.0.15 dev eth0.11
  442. IP_ROUTE
  443. @linux_route_n = <<-ROUTE_N
  444. Kernel IP routing table
  445. Destination Gateway Genmask Flags Metric Ref Use Iface
  446. 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.11
  447. 0.0.0.0 192.168.0.15 0.0.0.0 UG 0 0 0 eth0.11
  448. ROUTE_N
  449. prepare_data
  450. do_stubs
  451. @ohai._require_plugin("linux::network")
  452. end
  453. it "finds the default interface by asking which iface has the default route" do
  454. @ohai['network']["default_interface"].should == 'eth0.11'
  455. end
  456. it "finds the default interface by asking which iface has the default route" do
  457. @ohai['network']["default_gateway"].should == '192.168.0.15'
  458. end
  459. end
  460. end
  461. end
  462. describe "for newer network features using iproute2 only" do
  463. before do
  464. File.stub!(:exist?).with("/sbin/ip").and_return(true) # iproute2 only
  465. do_stubs
  466. end
  467. it "completes the run" do
  468. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  469. @ohai._require_plugin("linux::network")
  470. @ohai['network'].should_not be_nil
  471. end
  472. it "finds the default inet6 interface if there's a inet6 default route" do
  473. @ohai._require_plugin("linux::network")
  474. @ohai['network']['default_inet6_interface'].should == 'eth0.11'
  475. end
  476. it "finds the default inet6 gateway if there's a inet6 default route" do
  477. @ohai._require_plugin("linux::network")
  478. @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::1'
  479. end
  480. it "finds inet6 neighbours" do
  481. @ohai._require_plugin("linux::network")
  482. @ohai['network']['interfaces']['eth0.11']['neighbour_inet6']['1111:2222:3333:4444::1'].should == '00:1c:0e:12:34:56'
  483. end
  484. it "detects the ipv4 addresses of an ethernet interface with a crazy name" do
  485. @ohai._require_plugin("linux::network")
  486. @ohai['network']['interfaces']['foo:veth0@eth0']['addresses'].keys.should include('192.168.212.2')
  487. @ohai['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['netmask'].should == '255.255.255.0'
  488. @ohai['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['family'].should == 'inet'
  489. end
  490. it "generates a fake interface for ip aliases for backward compatibility" do
  491. @ohai._require_plugin("linux::network")
  492. @ohai['network']['interfaces']['eth0:5']['addresses'].keys.should include('192.168.5.1')
  493. @ohai['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['netmask'].should == '255.255.255.0'
  494. @ohai['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['family'].should == 'inet'
  495. end
  496. it "adds the vlan information of an interface" do
  497. @ohai._require_plugin("linux::network")
  498. @ohai['network']['interfaces']['eth0.11']['vlan']['id'].should == '11'
  499. @ohai['network']['interfaces']['eth0.11']['vlan']['flags'].should == [ 'REORDER_HDR' ]
  500. end
  501. it "adds the state of an interface" do
  502. @ohai._require_plugin("linux::network")
  503. @ohai['network']['interfaces']['eth0.11']['state'].should == 'up'
  504. end
  505. describe "when dealing with routes" do
  506. it "adds routes" do
  507. @ohai._require_plugin("linux::network")
  508. @ohai['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.116.201.0/24", :proto => "kernel", :family =>"inet" )
  509. @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" )
  510. @ohai['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "fe80::/64", :metric => "256", :proto => "kernel", :family => "inet6" )
  511. @ohai['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "1111:2222:3333:4444::/64", :metric => "1024", :family => "inet6" )
  512. @ohai['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "default", :via => "1111:2222:3333:4444::1", :metric => "1024", :family => "inet6")
  513. end
  514. describe "when there isn't a source field in route entries " do
  515. it "doesn't set ipaddress" do
  516. @ohai._require_plugin("linux::network")
  517. @ohai['ipaddress'].should be nil
  518. end
  519. it "doesn't set macaddress" do
  520. @ohai._require_plugin("linux::network")
  521. @ohai['macaddress'].should be nil
  522. end
  523. it "doesn't set ip6address" do
  524. @ohai._require_plugin("linux::network")
  525. @ohai['ip6address'].should be nil
  526. end
  527. end
  528. describe "when there's a source field in the default route entry" do
  529. before do
  530. @linux_ip_route = <<-IP_ROUTE_SCOPE
  531. 10.116.201.0/24 dev eth0 proto kernel
  532. 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
  533. 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
  534. 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
  535. 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
  536. default via 10.116.201.1 dev eth0 src 10.116.201.76
  537. IP_ROUTE_SCOPE
  538. @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
  539. fe80::/64 dev eth0 proto kernel metric 256
  540. fe80::/64 dev eth0.11 proto kernel metric 256
  541. 1111:2222:3333:4444::/64 dev eth0.11 metric 1024
  542. default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
  543. IP_ROUTE_SCOPE
  544. prepare_data
  545. do_stubs
  546. end
  547. it "completes the run" do
  548. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  549. @ohai._require_plugin("linux::network")
  550. @ohai['network'].should_not be_nil
  551. end
  552. it "sets ipaddress" do
  553. @ohai._require_plugin("linux::network")
  554. @ohai['ipaddress'].should == "10.116.201.76"
  555. end
  556. it "sets ip6address" do
  557. @ohai._require_plugin("linux::network")
  558. @ohai['ip6address'].should == "1111:2222:3333:4444::3"
  559. end
  560. end
  561. describe "when there're several default routes" do
  562. before do
  563. @linux_ip_route = <<-IP_ROUTE_SCOPE
  564. 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
  565. 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
  566. 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
  567. 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
  568. 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
  569. default via 10.116.201.1 dev eth0 metric 10
  570. default via 10.116.201.254 dev eth0 metric 9
  571. IP_ROUTE_SCOPE
  572. @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
  573. fe80::/64 dev eth0 proto kernel metric 256
  574. fe80::/64 dev eth0.11 proto kernel metric 256
  575. 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
  576. default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
  577. default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023
  578. IP_ROUTE_SCOPE
  579. prepare_data
  580. do_stubs
  581. end
  582. it "completes the run" do
  583. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  584. @ohai._require_plugin("linux::network")
  585. @ohai['network'].should_not be_nil
  586. end
  587. it "sets default ipv4 interface and gateway" do
  588. @ohai._require_plugin("linux::network")
  589. @ohai['network']['default_interface'].should == 'eth0'
  590. @ohai['network']['default_gateway'].should == '10.116.201.254'
  591. end
  592. it "sets default ipv6 interface and gateway" do
  593. @ohai._require_plugin("linux::network")
  594. @ohai['network']['default_inet6_interface'].should == 'eth0.11'
  595. @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::ffff'
  596. end
  597. end
  598. describe "when there're a mixed setup of routes that could be used to set ipaddress" do
  599. before do
  600. @linux_ip_route = <<-IP_ROUTE_SCOPE
  601. 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
  602. 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
  603. 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
  604. 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
  605. 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
  606. default via 10.116.201.1 dev eth0 metric 10
  607. default via 10.116.201.254 dev eth0 metric 9 src 10.116.201.74
  608. IP_ROUTE_SCOPE
  609. @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
  610. fe80::/64 dev eth0 proto kernel metric 256
  611. fe80::/64 dev eth0.11 proto kernel metric 256
  612. 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
  613. default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
  614. default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 src 1111:2222:3333:4444::2
  615. IP_ROUTE_SCOPE
  616. prepare_data
  617. do_stubs
  618. end
  619. it "completes the run" do
  620. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  621. @ohai._require_plugin("linux::network")
  622. @ohai['network'].should_not be_nil
  623. end
  624. it "sets ipaddress" do
  625. @ohai._require_plugin("linux::network")
  626. @ohai["ipaddress"].should == "10.116.201.74"
  627. end
  628. it "sets ip6address" do
  629. @ohai._require_plugin("linux::network")
  630. @ohai["ip6address"].should == "1111:2222:3333:4444::2"
  631. end
  632. end
  633. describe "when there's a source field in a local route entry " do
  634. before do
  635. @linux_ip_route = <<-IP_ROUTE_SCOPE
  636. 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
  637. 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
  638. 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
  639. 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
  640. 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
  641. default via 10.116.201.1 dev eth0
  642. IP_ROUTE_SCOPE
  643. @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
  644. fe80::/64 dev eth0 proto kernel metric 256
  645. fe80::/64 dev eth0.11 proto kernel metric 256
  646. 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
  647. default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
  648. IP_ROUTE_SCOPE
  649. prepare_data
  650. do_stubs
  651. end
  652. it "completes the run" do
  653. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  654. @ohai._require_plugin("linux::network")
  655. @ohai['network'].should_not be_nil
  656. end
  657. it "sets ipaddress" do
  658. @ohai._require_plugin("linux::network")
  659. @ohai['ipaddress'].should == "10.116.201.76"
  660. end
  661. describe "when about to set macaddress" do
  662. it "sets macaddress" do
  663. @ohai._require_plugin("linux::network")
  664. @ohai['macaddress'].should == "12:31:3D:02:BE:A2"
  665. end
  666. describe "when then interface has the NOARP flag" do
  667. before do
  668. @linux_ip_route = <<-IP_ROUTE
  669. 10.118.19.1 dev tun0 proto kernel src 10.118.19.39
  670. default via 172.16.19.1 dev tun0
  671. IP_ROUTE
  672. prepare_data
  673. do_stubs
  674. end
  675. it "completes the run" do
  676. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  677. @ohai._require_plugin("linux::network")
  678. @ohai['network'].should_not be_nil
  679. end
  680. it "doesn't set macaddress" do
  681. @ohai._require_plugin("linux::network")
  682. @ohai['macaddress'].should be_nil
  683. end
  684. end
  685. end
  686. it "sets ip6address" do
  687. @ohai._require_plugin("linux::network")
  688. @ohai['ip6address'].should == "1111:2222:3333:4444::3"
  689. end
  690. end
  691. describe "with a link level default route" do
  692. before do
  693. @linux_ip_route = <<-IP_ROUTE
  694. default dev venet0 scope link
  695. IP_ROUTE
  696. prepare_data
  697. do_stubs
  698. end
  699. it "completes the run" do
  700. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  701. @ohai._require_plugin("linux::network")
  702. @ohai['network'].should_not be_nil
  703. end
  704. it "doesn't set ipaddress" do
  705. @ohai._require_plugin("linux::network")
  706. @ohai['ipaddress'].should be_nil
  707. end
  708. end
  709. describe "when not having a global scope ipv6 address" do
  710. before do
  711. @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
  712. fe80::/64 dev eth0 proto kernel metric 256
  713. default via fe80::21c:eff:fe12:3456 dev eth0.153 src fe80::2e0:81ff:fe2b:48e7 metric 1024
  714. IP_ROUTE_SCOPE
  715. prepare_data
  716. do_stubs
  717. end
  718. it "completes the run" do
  719. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  720. @ohai._require_plugin("linux::network")
  721. @ohai['network'].should_not be_nil
  722. end
  723. it "doesn't set ip6address" do
  724. @ohai._require_plugin("linux::network")
  725. @ohai['ip6address'].should be_nil
  726. end
  727. end
  728. describe "with no default route" do
  729. before do
  730. @linux_ip_route = <<-IP_ROUTE
  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. IP_ROUTE
  737. @linux_ip_route_inet6 = <<-IP_ROUTE
  738. fe80::/64 dev eth0 proto kernel metric 256
  739. fe80::/64 dev eth0.11 proto kernel metric 256
  740. 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
  741. IP_ROUTE
  742. prepare_data
  743. do_stubs
  744. end
  745. it "completes the run" do
  746. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  747. @ohai._require_plugin("linux::network")
  748. @ohai['network'].should_not be_nil
  749. end
  750. it "doesn't set ipaddress" do
  751. @ohai._require_plugin("linux::network")
  752. @ohai['ipaddress'].should be_nil
  753. end
  754. it "doesn't set ip6address" do
  755. @ohai._require_plugin("linux::network")
  756. @ohai['ip6address'].should be_nil
  757. end
  758. end
  759. describe "with irrelevant routes (container setups)" do
  760. before do
  761. @linux_ip_route = <<-IP_ROUTE
  762. 10.116.201.0/26 dev eth0 proto kernel src 10.116.201.39
  763. 10.116.201.0/26 dev if4 proto kernel src 10.116.201.45
  764. 10.118.19.0/26 dev eth0 proto kernel src 10.118.19.39
  765. 10.118.19.0/26 dev if5 proto kernel src 10.118.19.45
  766. default via 10.116.201.1 dev eth0 src 10.116.201.99
  767. IP_ROUTE
  768. @linux_ip_route_inet6 = <<-IP_ROUTE
  769. fe80::/64 dev eth0 proto kernel metric 256
  770. fe80::/64 dev eth0.11 proto kernel metric 256
  771. 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::FFFF:2
  772. default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
  773. IP_ROUTE
  774. prepare_data
  775. do_stubs
  776. end
  777. it "completes the run" do
  778. Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
  779. @ohai._require_plugin("linux::network")
  780. @ohai['network'].should_not be_nil
  781. end
  782. it "doesn't add bogus routes" do
  783. @ohai._require_plugin("linux::network")
  784. @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" )
  785. @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" )
  786. @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "1111:2222:3333:4444::/64", :family => "inet6", :metric => "1024" )
  787. end
  788. it "doesn't set ipaddress" do
  789. @ohai._require_plugin("linux::network")
  790. @ohai['ipaddress'].should be_nil
  791. end
  792. it "doesn't set ip6address" do
  793. @ohai._require_plugin("linux::network")
  794. @ohai['ip6address'].should be_nil
  795. end
  796. end
  797. # This should never happen in the real world.
  798. describe "when encountering a surprise interface" do
  799. before do
  800. @linux_ip_route = <<-IP_ROUTE
  801. 192.168.122.0/24 dev virbr0 proto kernel src 192.168.122.1
  802. IP_ROUTE
  803. prepare_data
  804. do_stubs
  805. end
  806. it "logs a message and skips previously unseen interfaces in 'ip route show'" do
  807. Ohai::Log.should_receive(:debug).with("Skipping previously unseen interface from 'ip route show': virbr0").once
  808. Ohai::Log.should_receive(:debug).any_number_of_times # Catches the 'Loading plugin network' type messages
  809. @ohai._require_plugin("linux::network")
  810. end
  811. end
  812. end
  813. end
  814. end