PageRenderTime 119ms CodeModel.GetById 24ms RepoModel.GetById 17ms app.codeStats 1ms

/spec/unit/plugins/network_spec.rb

https://github.com/jmanero/ohai
Ruby | 829 lines | 771 code | 40 blank | 18 comment | 21 complexity | 547ed77dae15142fd94710fac8ecd537 MD5 | raw file
Possible License(s): Apache-2.0
  1. #
  2. # Author:: Laurent Desarmes <laurent.desarmes@u-picardie.fr>
  3. # Copyright:: Copyright (c) 2012 Laurent Desarmes
  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. def it_does_not_fail
  20. it "doesn't fail" do
  21. Ohai::Log.should_receive(:warn).any_number_of_times
  22. Ohai::Log.should_not_receive(:debug).with(/^Plugin network threw exception/)
  23. @ohai._require_plugin("network")
  24. %w[ ipaddress, macaddress, ip6address ].each do |attribute|
  25. @ohai.should have_key(attribute)
  26. end
  27. end
  28. end
  29. describe Ohai::System, "Network Plugin" do
  30. basic_data = {
  31. "linux" => {
  32. "network" => {
  33. # pp Hash[node['network']] from shef to get the network data
  34. # have just removed the neighbour and route entries by hand
  35. "interfaces" => {
  36. "lo" => {
  37. "flags" => ["LOOPBACK", "UP"],
  38. "addresses" => {
  39. "::1" => {
  40. "scope" => "Node",
  41. "prefixlen" => "128",
  42. "family" => "inet6"
  43. },
  44. "127.0.0.1" => {
  45. "scope" => "Node",
  46. "netmask" => "255.0.0.0",
  47. "prefixlen" => "8",
  48. "family" => "inet"
  49. }
  50. },
  51. "mtu" => "16436",
  52. "encapsulation" => "Loopback"
  53. },
  54. "eth0" => {
  55. "flags" => ["BROADCAST", "MULTICAST", "UP"],
  56. "number" => "0",
  57. "addresses" => {
  58. "fe80::216:3eff:fe2f:3679" => {
  59. "scope" => "Link",
  60. "prefixlen" => "64",
  61. "family" => "inet6"
  62. },
  63. "00:16:3E:2F:36:79" => {"family" => "lladdr"},
  64. "192.168.66.33" => {
  65. "scope" => "Global",
  66. "netmask" => "255.255.255.0",
  67. "broadcast" => "192.168.66.255",
  68. "prefixlen" => "24",
  69. "family" => "inet"
  70. },
  71. "3ffe:1111:2222::33" => {
  72. "prefixlen" => "48",
  73. "family" => "inet6",
  74. "scope" => "Global"
  75. }
  76. },
  77. "mtu" => "1500",
  78. "type" => "eth",
  79. "encapsulation" => "Ethernet"
  80. },
  81. "eth1" => {
  82. "flags" => ["BROADCAST", "MULTICAST", "UP"],
  83. "number" => "1",
  84. "addresses" => {
  85. "fe80::216:3eff:fe2f:3680" => {
  86. "scope" => "Link",
  87. "prefixlen" => "64",
  88. "family" => "inet6"
  89. },
  90. "00:16:3E:2F:36:80" => {"family" => "lladdr"},
  91. "192.168.99.11" => {
  92. "scope" => "Global",
  93. "netmask" => "255.255.255.0",
  94. "broadcast" => "192.168.99.255",
  95. "prefixlen" => "24",
  96. "family" => "inet"
  97. },
  98. "3ffe:1111:3333::1" => {
  99. "prefixlen" => "48",
  100. "family" => "inet6",
  101. "scope" => "Global"
  102. }
  103. },
  104. "mtu" => "1500",
  105. "type" => "eth",
  106. "encapsulation" => "Ethernet"
  107. }
  108. },
  109. "default_gateway" => "192.168.66.15",
  110. "default_interface" => "eth0",
  111. "default_inet6_gateway" => "3ffe:1111:2222::",
  112. "default_inet6_interface" => "eth0"
  113. }
  114. },
  115. "windows" => {
  116. "network" => {
  117. "interfaces" => {
  118. "0xb" => {
  119. "addresses" => {
  120. "172.19.0.130" => {
  121. "prefixlen" => "24",
  122. "netmask" => "255.255.255.0",
  123. "broadcast" => "172.19.0.255",
  124. "family" => "inet"
  125. },
  126. "fe80::698d:3e37:7950:b28c" => {
  127. "prefixlen" => "64",
  128. "family" => "inet6",
  129. "scope" => "Link"
  130. },
  131. "52:54:44:66:66:02" => {
  132. "family" => "lladdr"
  133. }
  134. },
  135. "mtu" => nil,
  136. "type" => "Ethernet 802.3",
  137. "encapsulation" => "Ethernet"
  138. }
  139. },
  140. "default_gateway" => "172.19.0.1",
  141. "default_interface" => "0xb"
  142. }
  143. }
  144. }
  145. describe "with linux" do
  146. before(:each) do
  147. @ohai = Ohai::System.new
  148. @ohai.stub!(:require_plugin).twice.and_return(true)
  149. @ohai["network"] = basic_data["linux"]["network"]
  150. end
  151. describe "when the linux::network plugin hasn't set any of {ip,ip6,mac}address attributes" do
  152. describe "simple setup" do
  153. it_does_not_fail
  154. it "logs 2 debug messages" do
  155. Ohai::Log.should_receive(:debug).with(/^Loading plugin network/).once
  156. Ohai::Log.should_receive(:debug).with(/^\[inet\] Using default/).once
  157. Ohai::Log.should_receive(:debug).with(/^\[inet6\] Using default/).once
  158. @ohai._require_plugin("network")
  159. end
  160. it "detects {ip,ip6,mac}address" do
  161. @ohai._require_plugin("network")
  162. @ohai["ipaddress"].should == "192.168.66.33"
  163. @ohai["macaddress"].should == "00:16:3E:2F:36:79"
  164. @ohai["ip6address"].should == "3ffe:1111:2222::33"
  165. end
  166. end
  167. describe "default ipv4 and ipv6 gateway on different interfaces" do
  168. describe "both interfaces have an ARP" do
  169. before do
  170. @ohai["network"]["default_inet6_gateway"] = "3ffe:1111:3333::"
  171. @ohai["network"]["default_inet6_interface"] = "eth1"
  172. end
  173. it_does_not_fail
  174. it "detects {ip,ip6}address" do
  175. @ohai._require_plugin("network")
  176. @ohai["ipaddress"].should == "192.168.66.33"
  177. @ohai["ip6address"].should == "3ffe:1111:3333::1"
  178. end
  179. it "set macaddress from the ipv4 setup" do
  180. @ohai._require_plugin("network")
  181. @ohai["macaddress"].should == "00:16:3E:2F:36:79"
  182. end
  183. it "informs about this setup" do
  184. Ohai::Log.should_receive(:info).with(/^ipaddress and ip6address are set from different interfaces/)
  185. @ohai._require_plugin("network")
  186. end
  187. end
  188. describe "ipv4 interface has no ARP" do
  189. before do
  190. @ohai["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,kv| kv["family"] == "lladdr" }
  191. # not really checked by this pluging
  192. @ohai["network"]["interfaces"]["eth0"]["flags"] << "NOARP"
  193. @ohai["network"]["default_inet6_gateway"] = "3ffe:1111:3333::"
  194. @ohai["network"]["default_inet6_interface"] = "eth1"
  195. end
  196. it_does_not_fail
  197. it "detects {ip,ip6}address" do
  198. @ohai._require_plugin("network")
  199. @ohai["ipaddress"].should == "192.168.66.33"
  200. @ohai["ip6address"].should == "3ffe:1111:3333::1"
  201. end
  202. it "doesn't set macaddress, ipv4 setup is valid and has precedence over ipv6" do
  203. Ohai::Log.should_not_receive(:warn).with(/^unable to detect macaddress/)
  204. @ohai._require_plugin("network")
  205. @ohai["macaddress"].should be_nil
  206. end
  207. it "informs about this setup" do
  208. Ohai::Log.should_receive(:info).with(/^ipaddress and ip6address are set from different interfaces/)
  209. @ohai._require_plugin("network")
  210. end
  211. end
  212. end
  213. describe "conflicting results from the linux::network plugin" do
  214. describe "default interface doesn't match the default_gateway" do
  215. before do
  216. @ohai["network"]["default_interface"] = "eth1"
  217. @ohai["network"]["default_inet6_interface"] = "eth1"
  218. end
  219. it_does_not_fail
  220. it "doesn't detect {ip,ip6,mac}address" do
  221. Ohai::Log.should_receive(:warn).any_number_of_times
  222. @ohai._require_plugin("network")
  223. @ohai["ipaddress"].should be_nil
  224. @ohai["macaddress"].should be_nil
  225. @ohai["ip6address"].should be_nil
  226. end
  227. it "warns about this conflict" do
  228. Ohai::Log.should_receive(:warn).with(/^\[inet\] no ipaddress\/mask on eth1/).once
  229. Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
  230. Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
  231. Ohai::Log.should_receive(:warn).with(/^\[inet6\] no ipaddress\/mask on eth1/).once
  232. Ohai::Log.should_receive(:warn).with(/^unable to detect ip6address/).once
  233. @ohai._require_plugin("network")
  234. end
  235. end
  236. describe "no ip address for the given default interface/gateway" do
  237. before do
  238. @ohai["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,v| %w[inet inet6].include? v["family"]}
  239. end
  240. it_does_not_fail
  241. it "doesn't detect {ip,ip6,mac}address" do
  242. Ohai::Log.should_receive(:warn).any_number_of_times
  243. @ohai._require_plugin("network")
  244. @ohai["ipaddress"].should be_nil
  245. @ohai["macaddress"].should be_nil
  246. @ohai["ip6address"].should be_nil
  247. end
  248. it "warns about this conflict" do
  249. Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
  250. Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
  251. Ohai::Log.should_receive(:warn).with(/^\[inet\] no ip on eth0/).once
  252. Ohai::Log.should_receive(:warn).with(/^unable to detect ip6address/).once
  253. Ohai::Log.should_receive(:warn).with(/^\[inet6\] no ip on eth0/).once
  254. @ohai._require_plugin("network")
  255. end
  256. end
  257. describe "no ip at all" do
  258. before do
  259. @ohai["network"]["default_gateway"] = nil
  260. @ohai["network"]["default_interface"] = nil
  261. @ohai["network"]["default_inet6_gateway"] = nil
  262. @ohai["network"]["default_inet6_interface"] = nil
  263. @ohai["network"]["interfaces"].each do |i,iv|
  264. iv["addresses"].delete_if{|k,kv| %w[inet inet6].include? kv["family"]}
  265. end
  266. end
  267. it_does_not_fail
  268. it "doesn't detect {ip,ip6,mac}address" do
  269. Ohai::Log.should_receive(:warn).any_number_of_times
  270. @ohai._require_plugin("network")
  271. @ohai["ipaddress"].should be_nil
  272. @ohai["macaddress"].should be_nil
  273. @ohai["ip6address"].should be_nil
  274. end
  275. it "should warn about it" do
  276. Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
  277. Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
  278. Ohai::Log.should_receive(:warn).with(/^unable to detect ip6address/).once
  279. @ohai._require_plugin("network")
  280. end
  281. end
  282. end
  283. describe "several ipaddresses matching the default route" do
  284. describe "bigger prefix not set on the default interface" do
  285. before do
  286. @ohai["network"]["interfaces"]["eth2"] = {
  287. "flags" => ["BROADCAST", "MULTICAST", "UP"],
  288. "number" => "2",
  289. "addresses" => {
  290. "fe80::216:3eff:fe2f:3681" => {
  291. "scope" => "Link",
  292. "prefixlen" => "64",
  293. "family" => "inet6"
  294. },
  295. "00:16:3E:2F:36:81" => {"family" => "lladdr"},
  296. "192.168.66.99" => {
  297. "scope" => "Global",
  298. "netmask" => "255.255.255.128",
  299. "broadcast" => "192.168.99.127",
  300. "prefixlen" => "25",
  301. "family" => "inet"
  302. },
  303. "3ffe:1111:2222:0:4444::1" => {
  304. "prefixlen" => "64",
  305. "family" => "inet6",
  306. "scope" => "Global"
  307. }
  308. }
  309. }
  310. end
  311. it_does_not_fail
  312. it "sets {ip,ip6,mac}address correctly" do
  313. @ohai._require_plugin("network")
  314. @ohai["ipaddress"].should == "192.168.66.33"
  315. @ohai["macaddress"].should == "00:16:3E:2F:36:79"
  316. @ohai["ip6address"].should == "3ffe:1111:2222::33"
  317. end
  318. end
  319. describe "bigger prefix set on the default interface" do
  320. before do
  321. @ohai["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.99"] = {
  322. "scope" => "Global",
  323. "netmask" => "255.255.255.128",
  324. "broadcast" => "192.168.66.127",
  325. "prefixlen" => "25",
  326. "family" => "inet"
  327. }
  328. @ohai["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222:0:4444::1"] = {
  329. "prefixlen" => "64",
  330. "family" => "inet6",
  331. "scope" => "Global"
  332. }
  333. end
  334. it_does_not_fail
  335. it "sets {ip,ip6,mac}address correctly" do
  336. @ohai._require_plugin("network")
  337. @ohai["ipaddress"].should == "192.168.66.99"
  338. @ohai["macaddress"].should == "00:16:3E:2F:36:79"
  339. @ohai["ip6address"].should == "3ffe:1111:2222:0:4444::1"
  340. end
  341. end
  342. describe "smallest ip not set on the default_interface" do
  343. before do
  344. @ohai["network"]["interfaces"]["eth2"] = {
  345. "flags" => ["BROADCAST", "MULTICAST", "UP"],
  346. "number" => "2",
  347. "addresses" => {
  348. "fe80::216:3eff:fe2f:3681" => {
  349. "scope" => "Link",
  350. "prefixlen" => "64",
  351. "family" => "inet6"
  352. },
  353. "00:16:3E:2F:36:81" => {"family" => "lladdr"},
  354. "192.168.66.32" => {
  355. "scope" => "Global",
  356. "netmask" => "255.255.255.0",
  357. "broadcast" => "192.168.66.255",
  358. "prefixlen" => "24",
  359. "family" => "inet"
  360. },
  361. "3ffe:1111:2222::32" => {
  362. "prefixlen" => "48",
  363. "family" => "inet6",
  364. "scope" => "Global"
  365. }
  366. }
  367. }
  368. end
  369. it_does_not_fail
  370. it "sets {ip,ip6,mac}address correctly" do
  371. @ohai._require_plugin("network")
  372. @ohai["ipaddress"].should == "192.168.66.33"
  373. @ohai["macaddress"].should == "00:16:3E:2F:36:79"
  374. @ohai["ip6address"].should == "3ffe:1111:2222::33"
  375. end
  376. end
  377. describe "smallest ip set on the default_interface" do
  378. before do
  379. @ohai["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.32"] = {
  380. "scope" => "Global",
  381. "netmask" => "255.255.255.0",
  382. "broadcast" => "192.168.66.255",
  383. "prefixlen" => "24",
  384. "family" => "inet"
  385. }
  386. @ohai["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222::32"] = {
  387. "prefixlen" => "48",
  388. "family" => "inet6",
  389. "scope" => "Global"
  390. }
  391. end
  392. it_does_not_fail
  393. it "sets {ip,ip6,mac}address correctly" do
  394. @ohai._require_plugin("network")
  395. @ohai["ipaddress"].should == "192.168.66.32"
  396. @ohai["macaddress"].should == "00:16:3E:2F:36:79"
  397. @ohai["ip6address"].should == "3ffe:1111:2222::32"
  398. end
  399. end
  400. end
  401. describe "no default route" do
  402. describe "first interface is not the best choice" do
  403. before do
  404. @ohai["network"]["default_gateway"] = nil
  405. @ohai["network"]["default_interface"] = nil
  406. @ohai["network"]["default_inet6_gateway"] = nil
  407. @ohai["network"]["default_inet6_interface"] = nil
  408. # removing inet* addresses from eth0, to complicate things a bit
  409. @ohai["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,v| %w[inet inet6].include? v["family"]}
  410. end
  411. it_does_not_fail
  412. it "picks {ip,mac,ip6}address from the first interface" do
  413. Ohai::Log.should_receive(:info).with(/^\[inet\] no default interface/).once
  414. Ohai::Log.should_receive(:info).with(/^\[inet6\] no default interface/).once
  415. @ohai._require_plugin("network")
  416. @ohai["ipaddress"].should == "192.168.99.11"
  417. @ohai["macaddress"].should == "00:16:3E:2F:36:80"
  418. @ohai["ip6address"].should == "3ffe:1111:3333::1"
  419. end
  420. end
  421. describe "can choose from addresses with different scopes" do
  422. before do
  423. @ohai["network"]["default_gateway"] = nil
  424. @ohai["network"]["default_interface"] = nil
  425. @ohai["network"]["default_inet6_gateway"] = nil
  426. @ohai["network"]["default_inet6_interface"] = nil
  427. # just changing scopes to lInK for eth0 addresses
  428. @ohai["network"]["interfaces"]["eth0"]["addresses"].each{|k,v| v[:scope]="lInK" if %w[inet inet6].include? v["family"]}
  429. end
  430. it_does_not_fail
  431. it "prefers global scope addressses to set {ip,mac,ip6}address" do
  432. Ohai::Log.should_receive(:info).with(/^\[inet\] no default interface/).once
  433. Ohai::Log.should_receive(:info).with(/^\[inet6\] no default interface/).once
  434. @ohai._require_plugin("network")
  435. @ohai["ipaddress"].should == "192.168.99.11"
  436. @ohai["macaddress"].should == "00:16:3E:2F:36:80"
  437. @ohai["ip6address"].should == "3ffe:1111:3333::1"
  438. end
  439. end
  440. end
  441. describe "link level default route" do
  442. describe "simple setup" do
  443. before do
  444. @ohai["network"]["default_gateway"] = "0.0.0.0"
  445. @ohai["network"]["default_interface"] = "eth1"
  446. @ohai["network"]["default_inet6_gateway"] = "::"
  447. @ohai["network"]["default_inet6_interface"] = "eth1"
  448. end
  449. it_does_not_fail
  450. it "displays debug messages" do
  451. Ohai::Log.should_receive(:debug).with(/^Loading plugin network/).once
  452. Ohai::Log.should_receive(:debug).with(/^link level default inet /).once
  453. Ohai::Log.should_receive(:debug).with(/^link level default inet6 /).once
  454. @ohai._require_plugin("network")
  455. end
  456. it "picks {ip,mac,ip6}address from the default interface" do
  457. @ohai._require_plugin("network")
  458. @ohai["ipaddress"].should == "192.168.99.11"
  459. @ohai["macaddress"].should == "00:16:3E:2F:36:80"
  460. @ohai["ip6address"].should == "3ffe:1111:3333::1"
  461. end
  462. end
  463. describe "can choose from addresses with different scopes" do
  464. before do
  465. @ohai["network"]["default_gateway"] = "0.0.0.0"
  466. @ohai["network"]["default_interface"] = "eth1"
  467. @ohai["network"]["default_inet6_gateway"] = "::"
  468. @ohai["network"]["default_inet6_interface"] = "eth1"
  469. @ohai["network"]["interfaces"]["eth1"]["addresses"]["127.0.0.2"] = {
  470. "scope" => "host",
  471. "netmask" => "255.255.255.255",
  472. "prefixlen" => "32",
  473. "family" => "inet"
  474. }
  475. end
  476. it_does_not_fail
  477. it "displays debug messages" do
  478. Ohai::Log.should_receive(:debug).with(/^Loading plugin network/).once
  479. Ohai::Log.should_receive(:debug).with(/^link level default inet /).once
  480. Ohai::Log.should_receive(:debug).with(/^link level default inet6 /).once
  481. @ohai._require_plugin("network")
  482. end
  483. it "picks {ip,mac,ip6}address from the default interface" do
  484. @ohai._require_plugin("network")
  485. @ohai["ipaddress"].should == "192.168.99.11"
  486. @ohai["macaddress"].should == "00:16:3E:2F:36:80"
  487. @ohai["ip6address"].should == "3ffe:1111:3333::1"
  488. end
  489. end
  490. end
  491. describe "point to point address" do
  492. before do
  493. @ohai["network"]["interfaces"]["eth2"] = {
  494. "flags" => ["POINTOPOINT", "BROADCAST", "MULTICAST", "UP"],
  495. "number" => "2",
  496. "addresses" => {
  497. "fe80::216:3eff:fe2f:3681" => {
  498. "scope" => "Link",
  499. "prefixlen" => "64",
  500. "family" => "inet6"
  501. },
  502. "00:16:3E:2F:36:81" => {"family" => "lladdr"},
  503. "192.168.66.99" => {
  504. "scope" => "Global",
  505. "netmask" => "255.255.255.255",
  506. "peer" => "192.168.99.126",
  507. "prefixlen" => "32",
  508. "family" => "inet"
  509. },
  510. "3ffe:1111:2222:0:4444::1" => {
  511. "prefixlen" => "128",
  512. "peer" => "3ffe:1111:2222:0:4444::2",
  513. "family" => "inet6",
  514. "scope" => "Global"
  515. }
  516. }
  517. }
  518. @ohai["network"]["default_gateway"] = "192.168.99.126"
  519. @ohai["network"]["default_interface"] = "eth2"
  520. @ohai["network"]["default_inet6_gateway"] = "3ffe:1111:2222:0:4444::2"
  521. @ohai["network"]["default_inet6_interface"] = "eth2"
  522. end
  523. it_does_not_fail
  524. it "picks {ip,mac,ip6}address from the default interface" do
  525. @ohai._require_plugin("network")
  526. @ohai["ipaddress"].should == "192.168.66.99"
  527. @ohai["macaddress"].should == "00:16:3E:2F:36:81"
  528. @ohai["ip6address"].should == "3ffe:1111:2222:0:4444::1"
  529. end
  530. end
  531. describe "ipv6 only node" do
  532. before do
  533. @ohai["network"]["default_gateway"] = nil
  534. @ohai["network"]["default_interface"] = nil
  535. @ohai["network"]["interfaces"].each do |i,iv|
  536. iv["addresses"].delete_if{|k,kv| kv["family"] == "inet" }
  537. end
  538. end
  539. it_does_not_fail
  540. it "can't detect ipaddress" do
  541. Ohai::Log.should_receive(:warn).any_number_of_times
  542. @ohai._require_plugin("network")
  543. @ohai["ipaddress"].should be_nil
  544. end
  545. it "warns about not being able to set {ip,mac}address (ipv4)" do
  546. Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
  547. Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
  548. @ohai._require_plugin("network")
  549. end
  550. it "sets {ip6,mac}address" do
  551. Ohai::Log.should_receive(:warn).any_number_of_times
  552. @ohai._require_plugin("network")
  553. @ohai["ip6address"].should == "3ffe:1111:2222::33"
  554. @ohai["macaddress"].should == "00:16:3E:2F:36:79"
  555. end
  556. it "informs about macaddress being set using the ipv6 setup" do
  557. Ohai::Log.should_receive(:warn).any_number_of_times
  558. Ohai::Log.should_receive(:info).with(/^macaddress set to 00:16:3E:2F:36:79 from the ipv6 setup/).once
  559. @ohai._require_plugin("network")
  560. end
  561. end
  562. end
  563. basic_data.keys.sort.each do |os|
  564. describe "the #{os}::network has already set some of the {ip,mac,ip6}address attributes" do
  565. before(:each) do
  566. @ohai = Ohai::System.new
  567. @ohai.stub!(:require_plugin).twice.and_return(true)
  568. @ohai["network"] = basic_data[os]["network"]
  569. end
  570. describe "{ip,mac}address are already set" do
  571. before do
  572. @ohai["ipaddress"] = "10.11.12.13"
  573. @ohai["macaddress"] = "00:AA:BB:CC:DD:EE"
  574. @expected_results = {
  575. "linux" => {
  576. "ip6address" => "3ffe:1111:2222::33"
  577. },
  578. "windows" => {
  579. "ip6address" => "fe80::698d:3e37:7950:b28c"
  580. }
  581. }
  582. end
  583. it_does_not_fail
  584. it "detects ip6address" do
  585. @ohai._require_plugin("network")
  586. @ohai["ip6address"].should == @expected_results[os]["ip6address"]
  587. end
  588. it "doesn't overwrite {ip,mac}address" do
  589. @ohai._require_plugin("network")
  590. @ohai["ipaddress"].should == "10.11.12.13"
  591. @ohai["macaddress"].should == "00:AA:BB:CC:DD:EE"
  592. end
  593. end
  594. describe "ip6address is already set" do
  595. describe "node has ipv4 and ipv6" do
  596. before do
  597. @ohai["ip6address"] = "3ffe:8888:9999::1"
  598. @expected_results = {
  599. "linux" => {
  600. "ipaddress" => "192.168.66.33",
  601. "macaddress" => "00:16:3E:2F:36:79"
  602. },
  603. "windows" => {
  604. "ipaddress" => "172.19.0.130",
  605. "macaddress" => "52:54:44:66:66:02"
  606. }
  607. }
  608. end
  609. it_does_not_fail
  610. it "detects {ip,mac}address" do
  611. @ohai._require_plugin("network")
  612. @ohai["ipaddress"].should == @expected_results[os]["ipaddress"]
  613. @ohai["macaddress"].should == @expected_results[os]["macaddress"]
  614. end
  615. it "doesn't overwrite ip6address" do
  616. @ohai._require_plugin("network")
  617. @ohai["ip6address"].should == "3ffe:8888:9999::1"
  618. end
  619. end
  620. describe "ipv6 only node" do
  621. before do
  622. @ohai["network"]["default_gateway"] = nil
  623. @ohai["network"]["default_interface"] = nil
  624. @ohai["network"]["interfaces"].each do |i,iv|
  625. iv["addresses"].delete_if{|k,kv| kv["family"] == "inet" }
  626. end
  627. @ohai["ip6address"] = "3ffe:8888:9999::1"
  628. end
  629. it_does_not_fail
  630. it "can't detect ipaddress (ipv4)" do
  631. Ohai::Log.should_receive(:warn).any_number_of_times
  632. @ohai._require_plugin("network")
  633. @ohai["ipaddress"].should be_nil
  634. end
  635. it "can't detect macaddress either" do
  636. Ohai::Log.should_receive(:warn).any_number_of_times
  637. @ohai._require_plugin("network")
  638. @ohai["macaddress"].should be_nil
  639. end
  640. it "warns about not being able to set {ip,mac}address" do
  641. Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
  642. Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
  643. @ohai._require_plugin("network")
  644. end
  645. it "doesn't overwrite ip6address" do
  646. Ohai::Log.should_receive(:warn).any_number_of_times
  647. @ohai._require_plugin("network")
  648. @ohai["ip6address"].should == "3ffe:8888:9999::1"
  649. end
  650. end
  651. end
  652. describe "{mac,ip6}address are already set" do
  653. describe "valid ipv4 setup" do
  654. before do
  655. @ohai["macaddress"] = "00:AA:BB:CC:DD:EE"
  656. @ohai["ip6address"] = "3ffe:8888:9999::1"
  657. @expected_results = {
  658. "linux" => {
  659. "ipaddress" => "192.168.66.33",
  660. "macaddress" => "00:16:3E:2F:36:79"
  661. },
  662. "windows" => {
  663. "ipaddress" => "172.19.0.130",
  664. "macaddress" => "52:54:44:66:66:02"
  665. }
  666. }
  667. end
  668. it_does_not_fail
  669. it "detects ipaddress and overwrite macaddress" do
  670. @ohai._require_plugin("network")
  671. @ohai["ipaddress"].should == @expected_results[os]["ipaddress"]
  672. @ohai["macaddress"].should == @expected_results[os]["macaddress"]
  673. end
  674. it "doesn't overwrite ip6address" do
  675. @ohai._require_plugin("network")
  676. @ohai["ip6address"].should == "3ffe:8888:9999::1"
  677. end
  678. end
  679. describe "ipv6 only node" do
  680. before do
  681. @ohai["network"]["default_gateway"] = nil
  682. @ohai["network"]["default_interface"] = nil
  683. @ohai["network"]["interfaces"].each do |i,iv|
  684. iv["addresses"].delete_if{|k,kv| kv["family"] == "inet" }
  685. end
  686. @ohai["macaddress"] = "00:AA:BB:CC:DD:EE"
  687. @ohai["ip6address"] = "3ffe:8888:9999::1"
  688. end
  689. it_does_not_fail
  690. it "can't set ipaddress" do
  691. Ohai::Log.should_receive(:warn).any_number_of_times
  692. @ohai._require_plugin("network")
  693. @ohai["ipaddress"].should be_nil
  694. end
  695. it "doesn't overwrite {ip6,mac}address" do
  696. Ohai::Log.should_receive(:warn).any_number_of_times
  697. @ohai._require_plugin("network")
  698. @ohai["ip6address"].should == "3ffe:8888:9999::1"
  699. @ohai["macaddress"].should == "00:AA:BB:CC:DD:EE"
  700. end
  701. end
  702. end
  703. describe "{ip,mac,ip6}address are already set" do
  704. before do
  705. @ohai["ipaddress"] = "10.11.12.13"
  706. @ohai["macaddress"] = "00:AA:BB:CC:DD:EE"
  707. @ohai["ip6address"] = "3ffe:8888:9999::1"
  708. end
  709. it_does_not_fail
  710. it "doesn't overwrite {ip,mac,ip6}address" do
  711. @ohai._require_plugin("network")
  712. @ohai["ipaddress"].should == "10.11.12.13"
  713. @ohai["macaddress"].should == "00:AA:BB:CC:DD:EE"
  714. @ohai["ip6address"].should == "3ffe:8888:9999::1"
  715. end
  716. end
  717. describe "{ip,ip6}address are already set" do
  718. before do
  719. @ohai["ipaddress"] = "10.11.12.13"
  720. @ohai["ip6address"] = "3ffe:8888:9999::1"
  721. end
  722. it_does_not_fail
  723. it "doesn't overwrite {ip,mac,ip6}address" do
  724. @ohai._require_plugin("network")
  725. @ohai["ipaddress"].should == "10.11.12.13"
  726. @ohai["macaddress"].should == nil
  727. @ohai["ip6address"].should == "3ffe:8888:9999::1"
  728. end
  729. end
  730. end
  731. end
  732. end
  733. end