PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/spec/unit/plugins/solaris2/network_spec.rb

https://github.com/jmanero/ohai
Ruby | 142 lines | 107 code | 17 blank | 18 comment | 2 complexity | 93b522b914779c1fe66c0dfbbce43edd MD5 | raw file
Possible License(s): Apache-2.0
  1. #
  2. # Author:: Daniel DeLeo <dan@opscode.com>
  3. # Copyright:: Copyright (c) 2010 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. describe Ohai::System, "Solaris2.X network plugin" do
  20. before do
  21. solaris_ifconfig = <<-ENDIFCONFIG
  22. lo0:3: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
  23. inet 127.0.0.1 netmask ff000000
  24. e1000g0:3: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 3
  25. inet 72.2.115.28 netmask ffffff80 broadcast 72.2.115.127
  26. e1000g2:1: flags=201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS> mtu 1500 index 4
  27. inet 10.2.115.28 netmask ffffff80 broadcast 10.2.115.127
  28. inet6 2001:0db8:3c4d:55:a00:20ff:fe8e:f3ad/64
  29. net0: flags=40201000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4,CoS,L3PROTECT> mtu 1500 index 2
  30. inet 37.153.96.148 netmask fffffe00 broadcast 37.153.97.255
  31. ether 90:b8:d0:16:9b:97
  32. ip.tun0: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
  33. inet tunnel src 109.146.85.57 tunnel dst 109.146.85.212
  34. tunnel security settings --> use 'ipsecconf -ln -i ip.tun1'
  35. tunnel hop limit 60
  36. inet6 fe80::6d92:5539/10 --> fe80::6d92:55d4
  37. ip.tun0:1: flags=2200851<UP,POINTOPOINT,RUNNING,MULTICAST,NONUD,IPv6> mtu 1480 index 3
  38. inet6 2::45/128 --> 2::46
  39. lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
  40. inet 127.0.0.1 netmask ff000000
  41. eri0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 \
  42. index 2
  43. inet 172.17.128.208 netmask ffffff00 broadcast 172.17.128.255
  44. ip6.tun0: flags=10008d1<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST,IPv4> \
  45. mtu 1460
  46. index 3
  47. inet6 tunnel src fe80::1 tunnel dst fe80::2
  48. tunnel security settings --> use 'ipsecconf -ln -i ip.tun1'
  49. tunnel hop limit 60 tunnel encapsulation limit 4
  50. inet 10.0.0.208 --> 10.0.0.210 netmask ff000000
  51. qfe1: flags=2000841<UP,RUNNING,MULTICAST,IPv6> mtu 1500 index 3
  52. usesrc vni0
  53. inet6 fe80::203:baff:fe17:4be0/10
  54. ether 0:3:ba:17:4b:e0
  55. vni0: flags=2002210041<UP,RUNNING,NOXMIT,NONUD,IPv6,VIRTUAL> mtu 0
  56. index 5
  57. srcof qfe1
  58. inet6 fe80::203:baff:fe17:4444/128
  59. ENDIFCONFIG
  60. solaris_netstat_rn = <<-NETSTAT_RN
  61. Routing Table: IPv4
  62. Destination Gateway Flags Ref Use Interface
  63. -------------------- -------------------- ----- ----- ---------- ---------
  64. default 10.13.37.1 UG 1 0 e1000g0
  65. 10.13.37.0 10.13.37.157 U 1 2 e1000g0
  66. 127.0.0.1 127.0.0.1 UH 1 35 lo0
  67. Routing Table: IPv6
  68. Destination/Mask Gateway Flags Ref Use If
  69. --------------------------- --------------------------- ----- --- ------- -----
  70. fe80::/10 fe80::250:56ff:fe13:3757 U 1 0 e1000g0
  71. ::1 ::1 UH 1 0 lo0
  72. NETSTAT_RN
  73. @solaris_route_get = <<-ROUTE_GET
  74. route to: default
  75. destination: default
  76. mask: default
  77. gateway: 10.13.37.1
  78. interface: e1000g0
  79. flags: <UP,GATEWAY,DONE,STATIC>
  80. recvpipe sendpipe ssthresh rtt,ms rttvar,ms hopcount mtu expire
  81. 0 0 0 0 0 0 1500 0
  82. ROUTE_GET
  83. @stdin = StringIO.new
  84. @ifconfig_lines = solaris_ifconfig.split("\n")
  85. @ohai = Ohai::System.new
  86. @ohai.stub!(:require_plugin).and_return(true)
  87. @ohai[:network] = Mash.new
  88. @ohai.stub(:popen4).with("ifconfig -a")
  89. @ohai.stub(:popen4).with("arp -an")
  90. end
  91. describe "gathering IP layer address info" do
  92. before do
  93. @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin, @ifconfig_lines, nil)
  94. @ohai._require_plugin("solaris2::network")
  95. end
  96. it "completes the run" do
  97. @ohai['network'].should_not be_nil
  98. end
  99. it "detects the interfaces" do
  100. @ohai['network']['interfaces'].keys.sort.should == ["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "lo0", "lo0:3", "net0", "qfe1"]
  101. end
  102. it "detects the ip addresses of the interfaces" do
  103. @ohai['network']['interfaces']['e1000g0:3']['addresses'].keys.should include('72.2.115.28')
  104. end
  105. it "detects the encapsulation type of the interfaces" do
  106. @ohai['network']['interfaces']['e1000g0:3']['encapsulation'].should == 'Ethernet'
  107. end
  108. it "detects the L3PROTECT network flag" do
  109. @ohai['network']['interfaces']['net0']['flags'].should include('L3PROTECT')
  110. end
  111. end
  112. # TODO: specs for the arp -an stuff, check that it correctly adds the MAC addr to the right iface, etc.
  113. describe "setting the node's default IP address attribute" do
  114. before do
  115. @stdout = mock("Pipe, stdout, cmd=`route get default`", :read => @solaris_route_get)
  116. @ohai.stub!(:popen4).with("route -n get default").and_yield(nil,@stdin, @stdout, nil)
  117. @ohai._require_plugin("solaris2::network")
  118. end
  119. it "finds the default interface by asking which iface has the default route" do
  120. @ohai[:network][:default_interface].should == 'e1000g0'
  121. end
  122. end
  123. end