ohai 7.6.0.rc.0 → 7.6.0.rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -76,7 +76,10 @@ module Ohai
76
76
 
77
77
  def best_api_version
78
78
  response = http_client.get("/")
79
- unless response.code == '200'
79
+ if response.code == '404'
80
+ Ohai::Log.debug("Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
81
+ return "latest"
82
+ elsif response.code != '200'
80
83
  raise "Unable to determine EC2 metadata version (returned #{response.code} response)"
81
84
  end
82
85
  # Note: Sorting the list of versions may have unintended consequences in
@@ -51,7 +51,7 @@ module Ohai
51
51
  end
52
52
 
53
53
  def http_client
54
- Net::HTTP.start(GCE_METADATA_ADDR).tap {|h| h.read_timeout = 600}
54
+ Net::HTTP.start(GCE_METADATA_ADDR).tap {|h| h.read_timeout = 6}
55
55
  end
56
56
 
57
57
  def fetch_metadata(id='')
@@ -46,13 +46,12 @@ Ohai.plugin(:Network) do
46
46
  network[:interfaces] = Mash.new unless network[:interfaces]
47
47
 
48
48
  # :default_interface, :default_gateway - route -n get 0
49
- so = shell_out("route -n get 0")
49
+ so = shell_out("netstat -rn |grep default")
50
50
  so.stdout.lines.each do |line|
51
- case line
52
- when /gateway: (\S+)/
53
- network[:default_gateway] = $1
54
- when /interface: (\S+)/
55
- network[:default_interface] = $1
51
+ items = line.split(' ')
52
+ if items[0] == "default"
53
+ network[:default_gateway] = items[1]
54
+ network[:default_interface] = items[5]
56
55
  end
57
56
  end
58
57
 
@@ -27,10 +27,10 @@ Ohai.plugin(:Uptime) do
27
27
  so = shell_out('who -b')
28
28
  so.stdout.lines.each do |line|
29
29
  if line =~ /.* boot (.+)/
30
- uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i
30
+ uptime_seconds Time.now.to_i - DateTime.parse($1 + " #{Time.now.zone}").strftime('%s').to_i
31
31
  uptime seconds_to_human(uptime_seconds)
32
32
  break
33
33
  end
34
34
  end
35
35
  end
36
- end
36
+ end
@@ -55,6 +55,6 @@ Ohai.plugin(:CPU) do
55
55
 
56
56
  cpu cpuinfo
57
57
  so = shell_out("sysctl -n hw.ncpu")
58
- cpu[:total] = so.stdout.split($/)[0]
58
+ cpu[:total] = so.stdout.split($/)[0].to_i
59
59
  end
60
60
  end
@@ -28,9 +28,9 @@ Ohai.plugin(:Java) do
28
28
  case line
29
29
  when /java version \"([0-9\.\_]+)\"/
30
30
  java[:version] = $1
31
- when /^(.+Runtime Environment.*) \((build )?(.+)\)$/
31
+ when /^(.+Runtime Environment.*) \((build)\s*(.+)\)$/
32
32
  java[:runtime] = { "name" => $1, "build" => $3 }
33
- when /^(.+ (Client|Server) VM) \(build (.+)\)$/
33
+ when /^(.+ (Client|Server) VM) \(build\s*(.+)\)$/
34
34
  java[:hotspot] = { "name" => $1, "build" => $3 }
35
35
  end
36
36
  end
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Chris Read <chris.read@gmail.com>
3
4
  # Copyright:: Copyright (c) 2008 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -161,10 +162,16 @@ Ohai.plugin(:Network) do
161
162
  net_counters[tmp_int][:tx][:queuelen] = $1
162
163
  end
163
164
 
164
- if line =~ /vlan id (\d+)/
165
- tmp_id = $1
165
+ if line =~ /vlan id (\d+)/ or line =~ /vlan protocol ([\w\.]+) id (\d+)/
166
+ if $2
167
+ tmp_prot = $1
168
+ tmp_id = $2
169
+ else
170
+ tmp_id = $1
171
+ end
166
172
  iface[tmp_int][:vlan] = Mash.new unless iface[tmp_int][:vlan]
167
173
  iface[tmp_int][:vlan][:id] = tmp_id
174
+ iface[tmp_int][:vlan][:protocol] = tmp_prot if tmp_prot
168
175
 
169
176
  vlan_flags = line.scan(/(REORDER_HDR|GVRP|LOOSE_BINDING)/)
170
177
  if vlan_flags.length > 0
@@ -111,7 +111,7 @@ Ohai.plugin(:Platform) do
111
111
  case platform
112
112
  when /debian/, /ubuntu/, /linuxmint/, /raspbian/
113
113
  platform_family "debian"
114
- when /fedora/
114
+ when /fedora/, /pidora/
115
115
  platform_family "fedora"
116
116
  when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
117
117
  platform_family "rhel"
@@ -137,7 +137,7 @@ Ohai.plugin(:Virtualization) do
137
137
  # Detect Linux-VServer
138
138
  if File.exists?("/proc/self/status")
139
139
  proc_self_status = File.read("/proc/self/status")
140
- vxid = proc_self_status.match(/^(s_context|VxID): (\d+)$/)
140
+ vxid = proc_self_status.match(/^(s_context|VxID):\s*(\d+)$/)
141
141
  if vxid and vxid[2]
142
142
  virtualization[:system] = "linux-vserver"
143
143
  if vxid[2] == "0"
@@ -158,7 +158,7 @@ Ohai.plugin(:Virtualization) do
158
158
  # /proc/self/cgroup could have a name including alpha/digit/dashes
159
159
  # <index #>:<subsystem>:/lxc/<named container id>
160
160
  #
161
- # /proc/self/cgroup could have a non-lxc cgroup name indicating other uses
161
+ # /proc/self/cgroup could have a non-lxc cgroup name indicating other uses
162
162
  # of cgroups. This is probably not LXC/Docker.
163
163
  # <index #>:<subsystem>:/Charlie
164
164
  #
@@ -14,6 +14,8 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ require "resolv"
18
+
17
19
  Ohai.plugin(:Rackspace) do
18
20
  provides "rackspace"
19
21
 
@@ -129,7 +131,11 @@ Ohai.plugin(:Rackspace) do
129
131
  rackspace[:public_ipv4] = rackspace[:public_ip]
130
132
  get_global_ipv6_address(:public_ipv6, :eth0)
131
133
  unless rackspace[:public_ip].nil?
132
- rackspace[:public_hostname] = "#{rackspace[:public_ip].gsub('.','-')}.static.cloud-ips.com"
134
+ rackspace[:public_hostname] = begin
135
+ Resolv.getname(rackspace[:public_ip])
136
+ rescue Resolv::ResolvError, Resolv::ResolvTimeout
137
+ rackspace[:public_ip]
138
+ end
133
139
  end
134
140
  rackspace[:local_ipv4] = rackspace[:private_ip]
135
141
  get_global_ipv6_address(:local_ipv6, :eth1)
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = '7.6.0.rc.0'
21
+ VERSION = '7.6.0.rc.1'
22
22
  end
@@ -53,11 +53,12 @@ describe Ohai::Mixin::Ec2Metadata do
53
53
  end
54
54
  end
55
55
 
56
+ # Presume 'latest' when we get a 404 for Eucalyptus back-compat
56
57
  context "when the response code is 404" do
57
- let(:response) { double("Net::HTTP Response", :body => "1.0\n2011-05-01\n2012-01-12\nUnsupported", :code => "404") }
58
+ let(:response) { double("Net::HTTP Response", :code => "404") }
58
59
 
59
- it "raises an error" do
60
- lambda { mixin.best_api_version}.should raise_error
60
+ it "returns 'latest' as the version" do
61
+ mixin.best_api_version.should == 'latest'
61
62
  end
62
63
  end
63
64
 
@@ -20,17 +20,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
20
20
  describe Ohai::System, "AIX network plugin" do
21
21
 
22
22
  before(:each) do
23
- @route_n_get_0 = <<-ROUTE_N_GET_0
24
- route to: default
25
- destination: default
26
- mask: default
27
- gateway: 172.29.128.13
28
- interface: en0
29
- interf addr: 172.29.174.58
30
- flags: <UP,GATEWAY,DONE>
31
- recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
32
- 0 0 0 0 0 0 0 -79
33
- ROUTE_N_GET_0
23
+ @netstat_rn_grep_default = <<-NETSTAT_RN_GREP_DEFAULT
24
+ default 172.31.8.1 UG 2 121789 en0 - -
25
+ NETSTAT_RN_GREP_DEFAULT
34
26
 
35
27
  @lsdev_Cc_if = <<-LSDEV_CC_IF
36
28
  en0 Available Standard Ethernet Network Interface
@@ -74,7 +66,7 @@ ARP_AN
74
66
  @plugin = get_plugin("aix/network")
75
67
  @plugin.stub(:collect_os).and_return(:aix)
76
68
  @plugin[:network] = Mash.new
77
- @plugin.stub(:shell_out).with("route -n get 0").and_return(mock_shell_out(0, @route_n_get_0, nil))
69
+ @plugin.stub(:shell_out).with("netstat -rn |grep default").and_return(mock_shell_out(0, @netstat_rn_grep_default, nil))
78
70
  @plugin.stub(:shell_out).with("lsdev -Cc if").and_return(mock_shell_out(0, @lsdev_Cc_if, nil))
79
71
  @plugin.stub(:shell_out).with("ifconfig en0").and_return(mock_shell_out(0, @ifconfig_en0, nil))
80
72
  @plugin.stub(:shell_out).with("entstat -d en0 | grep \"Hardware Address\"").and_return(mock_shell_out(0, "Hardware Address: be:42:80:00:b0:05", nil))
@@ -101,13 +93,13 @@ ARP_AN
101
93
  end
102
94
  end
103
95
 
104
- describe "route -n get 0" do
96
+ describe "netstat -rn |grep default" do
105
97
  before do
106
98
  @plugin.run
107
99
  end
108
100
 
109
101
  it "returns the default gateway of the system's network" do
110
- @plugin[:network][:default_gateway].should == '172.29.128.13'
102
+ @plugin[:network][:default_gateway].should == '172.31.8.1'
111
103
  end
112
104
 
113
105
  it "returns the default interface of the system's network" do
@@ -22,18 +22,19 @@ describe Ohai::System, "Aix plugin uptime" do
22
22
  before(:each) do
23
23
  @plugin = get_plugin("aix/uptime")
24
24
  @plugin.stub(:collect_os).and_return(:aix)
25
- Time.stub_chain(:now, :to_i).and_return(1374258600)
26
- DateTime.stub_chain(:parse, :strftime, :to_i).and_return(1373392260)
27
- @plugin.stub(:shell_out).with("who -b").and_return(mock_shell_out(0, " . system boot Jul 9 17:51", nil))
25
+ Time.stub_chain(:now, :to_i).and_return(1412072511)
26
+ Time.stub_chain(:now, :zone).and_return("IST")
27
+ DateTime.stub_chain(:parse, :strftime, :to_i).and_return(1411561320)
28
+ @plugin.stub(:shell_out).with("who -b").and_return(mock_shell_out(0, " . system boot Sep 24 17:52", nil))
28
29
 
29
- @plugin.run
30
+ @plugin.run
30
31
  end
31
32
 
32
33
  it "should set uptime_seconds to uptime" do
33
- @plugin[:uptime_seconds].should == 866340
34
+ @plugin[:uptime_seconds].should == 511191
34
35
  end
35
36
 
36
37
  it "should set uptime to a human readable date" do
37
- @plugin[:uptime].should == "10 days 00 hours 39 minutes 00 seconds"
38
+ @plugin[:uptime].should == "5 days 21 hours 59 minutes 51 seconds"
38
39
  end
39
40
  end
@@ -62,7 +62,7 @@ describe Ohai::System, "FreeBSD cpu plugin" do
62
62
 
63
63
  it "detects all CPU total" do
64
64
  @plugin.run
65
- @plugin[:cpu][:total].should == "2"
65
+ @plugin[:cpu][:total].should == 2
66
66
  end
67
67
 
68
68
  end
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # Author:: Caleb Tennis <caleb.tennis@gmail.com>
3
+ # Author:: Chris Read <chris.read@gmail.com>
3
4
  # Copyright:: Copyright (c) 2011 Opscode, Inc.
4
5
  # License:: Apache License, Version 2.0
5
6
  #
@@ -25,38 +26,25 @@ rescue LoadError => e
25
26
  raise e
26
27
  end
27
28
 
28
- def do_stubs
29
- @plugin.stub(:collect_os).and_return(:linux)
30
- @plugin.stub(:shell_out).with("ip addr").and_return(mock_shell_out(0, @linux_ip_addr, ""))
31
- @plugin.stub(:shell_out).with("ip -d -s link").and_return(mock_shell_out(0, @linux_ip_link_s_d, ""))
32
- @plugin.stub(:shell_out).with("ip -f inet neigh show").and_return(mock_shell_out(0, @linux_ip_neighbor_show, ""))
33
- @plugin.stub(:shell_out).with("ip -f inet6 neigh show").and_return(mock_shell_out(0, @linux_ip_inet6_neighbor_show, ""))
34
- @plugin.stub(:shell_out).with("ip -o -f inet route show").and_return(mock_shell_out(0, @linux_ip_route, ""))
35
- @plugin.stub(:shell_out).with("ip -o -f inet6 route show").and_return(mock_shell_out(0, @linux_ip_route_inet6, ""))
36
- @plugin.stub(:shell_out).with("route -n").and_return(mock_shell_out(0, @linux_route_n, ""))
37
- @plugin.stub(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @linux_ifconfig, ""))
38
- @plugin.stub(:shell_out).with("arp -an").and_return(mock_shell_out(0, @linux_arp_an, ""))
39
- end
40
-
41
29
  describe Ohai::System, "Linux Network Plugin" do
30
+ let(:plugin) { get_plugin("linux/network") }
42
31
 
43
- before do
44
- @linux_ifconfig = <<-ENDIFCONFIG
45
- eth0 Link encap:Ethernet HWaddr 12:31:3D:02:BE:A2
32
+ let(:linux_ifconfig) {
33
+ 'eth0 Link encap:Ethernet HWaddr 12:31:3D:02:BE:A2
46
34
  inet addr:10.116.201.76 Bcast:10.116.201.255 Mask:255.255.255.0
47
35
  inet6 addr: fe80::1031:3dff:fe02:bea2/64 Scope:Link
48
36
  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
49
37
  RX packets:2659966 errors:0 dropped:0 overruns:0 frame:0
50
38
  TX packets:1919690 errors:0 dropped:0 overruns:0 carrier:0
51
- collisions:0 txqueuelen:1000
39
+ collisions:0 txqueuelen:1000
52
40
  RX bytes:1392844460 (1.2 GiB) TX bytes:691785313 (659.7 MiB)
53
- Interrupt:16
41
+ Interrupt:16
54
42
 
55
- eth0:5 Link encap:Ethernet HWaddr 00:0c:29:41:71:45
43
+ eth0:5 Link encap:Ethernet HWaddr 00:0c:29:41:71:45
56
44
  inet addr:192.168.5.1 Bcast:192.168.5.255 Mask:255.255.255.0
57
45
  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
58
46
 
59
- eth0.11 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
47
+ eth0.11 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
60
48
  inet addr:192.168.0.16 Bcast:192.168.0.255 Mask:255.255.255.0
61
49
  inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
62
50
  inet6 addr: 1111:2222:3333:4444::2/64 Scope:Global
@@ -64,78 +52,107 @@ eth0.11 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
64
52
  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
65
53
  RX packets:1208795008 errors:0 dropped:0 overruns:0 frame:0
66
54
  TX packets:3269635153 errors:0 dropped:0 overruns:0 carrier:0
67
- collisions:0 txqueuelen:0
55
+ collisions:0 txqueuelen:0
68
56
  RX bytes:1751940374 (1.6 GiB) TX bytes:2195567597 (2.0 GiB)
69
57
 
70
- eth0.151 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
58
+ eth0.151 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
71
59
  inet addr:10.151.0.16 Bcast:10.151.0.255 Mask:255.255.255.0
72
60
  inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
73
61
  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
74
62
  RX packets:206553677 errors:0 dropped:0 overruns:0 frame:0
75
63
  TX packets:163901336 errors:0 dropped:0 overruns:0 carrier:0
76
- collisions:0 txqueuelen:0
64
+ collisions:0 txqueuelen:0
77
65
  RX bytes:3190792261 (2.9 GiB) TX bytes:755086548 (720.1 MiB)
78
66
 
79
- eth0.152 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
67
+ eth0.152 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
80
68
  inet addr:10.152.1.16 Bcast:10.152.3.255 Mask:255.255.252.0
81
69
  inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
82
70
  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
83
71
  RX packets:14016741 errors:0 dropped:0 overruns:0 frame:0
84
72
  TX packets:55232 errors:0 dropped:0 overruns:0 carrier:0
85
- collisions:0 txqueuelen:0
73
+ collisions:0 txqueuelen:0
86
74
  RX bytes:664957462 (634.1 MiB) TX bytes:4876434 (4.6 MiB)
87
75
 
88
- eth0.153 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
76
+ eth0.153 Link encap:Ethernet HWaddr 00:aa:bb:cc:dd:ee
89
77
  inet addr:10.153.1.16 Bcast:10.153.3.255 Mask:255.255.252.0
90
78
  inet6 addr: fe80::2aa:bbff:fecc:ddee/64 Scope:Link
91
79
  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
92
80
  RX packets:2022667595 errors:0 dropped:0 overruns:0 frame:0
93
81
  TX packets:1798627472 errors:0 dropped:0 overruns:0 carrier:0
94
- collisions:0 txqueuelen:0
82
+ collisions:0 txqueuelen:0
95
83
  RX bytes:4047036732 (3.7 GiB) TX bytes:3451231474 (3.2 GiB)
96
84
 
97
- foo:veth0@eth0 Link encap:Ethernet HWaddr ca:b3:73:8b:0c:e4
85
+ foo:veth0@eth0 Link encap:Ethernet HWaddr ca:b3:73:8b:0c:e4
98
86
  BROADCAST MULTICAST MTU:1500 Metric:1
99
87
 
100
- tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
88
+ tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
101
89
  inet addr:172.16.19.39 P-t-P:172.16.19.1 Mask:255.255.255.255
102
90
  UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
103
91
  RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
104
92
  TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
105
- collisions:0 txqueuelen:100
93
+ collisions:0 txqueuelen:100
106
94
  RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
107
95
 
108
- venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
96
+ venet0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
109
97
  UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
110
98
  RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
111
99
  TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
112
- collisions:0 txqueuelen:100
100
+ collisions:0 txqueuelen:100
113
101
  RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
114
102
 
115
- venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
103
+ venet0:0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
116
104
  UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1418 Metric:1
117
105
  RX packets:57200 errors:0 dropped:0 overruns:0 frame:0
118
106
  TX packets:13782 errors:0 dropped:0 overruns:0 carrier:0
119
- collisions:0 txqueuelen:100
107
+ collisions:0 txqueuelen:100
120
108
  RX bytes:7377600 (7.0 MiB) TX bytes:1175481 (1.1 MiB)
121
109
 
122
- lo Link encap:Local Loopback
110
+ lo Link encap:Local Loopback
123
111
  inet addr:127.0.0.1 Mask:255.0.0.0
124
112
  inet6 addr: ::1/128 Scope:Host
125
113
  UP LOOPBACK RUNNING MTU:16436 Metric:1
126
114
  RX packets:524 errors:0 dropped:0 overruns:0 frame:0
127
115
  TX packets:524 errors:0 dropped:0 overruns:0 carrier:0
128
- collisions:0 txqueuelen:0
116
+ collisions:0 txqueuelen:0
129
117
  RX bytes:35224 (34.3 KiB) TX bytes:35224 (34.3 KiB)
130
- ENDIFCONFIG
118
+ '
131
119
  # Note that ifconfig shows foo:veth0@eth0 but fails to show any address information.
132
120
  # This was not a mistake collecting the output and Apparently ifconfig is broken in this regard.
121
+ }
122
+
123
+ let(:linux_ip_route) {
124
+ '10.116.201.0/24 dev eth0 proto kernel
125
+ 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
126
+ 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
127
+ 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
128
+ 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
129
+ 10.5.4.0/24 \\ nexthop via 10.5.4.1 dev eth0 weight 1\\ nexthop via 10.5.4.2 dev eth0 weight 1
130
+ default via 10.116.201.1 dev eth0
131
+ '
132
+ }
133
+
134
+ let(:linux_route_n) {
135
+ 'Kernel IP routing table
136
+ Destination Gateway Genmask Flags Metric Ref Use Iface
137
+ 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
138
+ 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
139
+ 0.0.0.0 10.116.201.1 0.0.0.0 UG 0 0 0 eth0
140
+ '
141
+ }
142
+
143
+ let(:linux_ip_route_inet6) {
144
+ 'fe80::/64 dev eth0 proto kernel metric 256
145
+ fe80::/64 dev eth0.11 proto kernel metric 256
146
+ 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 expires 86023sec
147
+ default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
148
+ '
149
+ }
133
150
 
134
- @linux_ip_addr = <<-IP_ADDR
135
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
151
+ let(:linux_ip_addr) {
152
+ '1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
136
153
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
137
154
  inet 127.0.0.1/8 scope host lo
138
- inet6 ::1/128 scope host
155
+ inet6 ::1/128 scope host
139
156
  valid_lft forever preferred_lft forever
140
157
  2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
141
158
  link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff
@@ -143,35 +160,35 @@ ENDIFCONFIG
143
160
  inet 10.116.201.75/32 scope global eth0
144
161
  inet 10.116.201.74/24 scope global secondary eth0
145
162
  inet 192.168.5.1/24 brd 192.168.5.255 scope global eth0:5
146
- inet6 fe80::1031:3dff:fe02:bea2/64 scope link
163
+ inet6 fe80::1031:3dff:fe02:bea2/64 scope link
147
164
  valid_lft forever preferred_lft forever
148
- inet6 2001:44b8:4160:8f00:a00:27ff:fe13:eacd/64 scope global dynamic
165
+ inet6 2001:44b8:4160:8f00:a00:27ff:fe13:eacd/64 scope global dynamic
149
166
  valid_lft 6128sec preferred_lft 2526sec
150
- 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
167
+ 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
151
168
  link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
152
169
  inet 192.168.0.16/24 brd 192.168.0.255 scope global eth0.11
153
- inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
170
+ inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
154
171
  inet6 1111:2222:3333:4444::2/64 scope global
155
172
  valid_lft forever preferred_lft forever
156
173
  inet6 1111:2222:3333:4444::3/64 scope global
157
174
  valid_lft forever preferred_lft forever
158
- 4: eth0.151@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
175
+ 4: eth0.151@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
159
176
  link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
160
177
  inet 10.151.0.16/24 brd 10.151.0.255 scope global eth0.151
161
178
  inet 10.151.1.16/24 scope global eth0.151
162
- inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
179
+ inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
163
180
  valid_lft forever preferred_lft forever
164
- 5: eth0.152@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
181
+ 5: eth0.152@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
165
182
  link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
166
183
  inet 10.152.1.16/22 brd 10.152.3.255 scope global eth0.152
167
- inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
184
+ inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
168
185
  valid_lft forever preferred_lft forever
169
- 6: eth0.153@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
186
+ 6: eth0.153@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
170
187
  link/ether 00:aa:bb:cc:dd:ee brd ff:ff:ff:ff:ff:ff
171
188
  inet 10.153.1.16/22 brd 10.153.3.255 scope global eth0.153
172
- inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
189
+ inet6 fe80::2e0:81ff:fe2b:48e7/64 scope link
173
190
  valid_lft forever preferred_lft forever
174
- 7: foo:veth0@eth0@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN
191
+ 7: foo:veth0@eth0@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN
175
192
  link/ether ca:b3:73:8b:0c:e4 brd ff:ff:ff:ff:ff:ff
176
193
  inet 192.168.212.2/24 scope global foo:veth0@eth0
177
194
  8: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
@@ -181,733 +198,724 @@ ENDIFCONFIG
181
198
  link/void
182
199
  inet 127.0.0.2/32 scope host venet0
183
200
  inet 172.16.19.48/32 scope global venet0:0
184
- IP_ADDR
201
+ '
202
+ }
185
203
 
186
- @linux_ip_link_s_d = <<-IP_LINK_S
187
- 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
204
+ let(:linux_ip_link_s_d) {
205
+ '1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
188
206
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
189
- RX: bytes packets errors dropped overrun mcast
190
- 35224 524 0 0 0 0
191
- TX: bytes packets errors dropped carrier collsns
192
- 35224 524 0 0 0 0
207
+ RX: bytes packets errors dropped overrun mcast
208
+ 35224 524 0 0 0 0
209
+ TX: bytes packets errors dropped carrier collsns
210
+ 35224 524 0 0 0 0
193
211
  2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
194
212
  link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff
195
- RX: bytes packets errors dropped overrun mcast
196
- 1392844460 2659966 0 0 0 0
197
- TX: bytes packets errors dropped carrier collsns
198
- 691785313 1919690 0 0 0 0
199
- 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
213
+ RX: bytes packets errors dropped overrun mcast
214
+ 1392844460 2659966 0 0 0 0
215
+ TX: bytes packets errors dropped carrier collsns
216
+ 691785313 1919690 0 0 0 0
217
+ 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
200
218
  link/ether 00:0c:29:41:71:45 brd ff:ff:ff:ff:ff:ff
201
- vlan id 11 <REORDER_HDR>
202
- RX: bytes packets errors dropped overrun mcast
203
- 0 0 0 0 0 0
204
- TX: bytes packets errors dropped carrier collsns
205
- 0 0 0 0 0 0
219
+ vlan id 11 <REORDER_HDR>
220
+ RX: bytes packets errors dropped overrun mcast
221
+ 0 0 0 0 0 0
222
+ TX: bytes packets errors dropped carrier collsns
223
+ 0 0 0 0 0 0
206
224
  4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 100
207
- link/none
208
- RX: bytes packets errors dropped overrun mcast
209
- 1392844460 2659966 0 0 0 0
210
- TX: bytes packets errors dropped carrier collsns
211
- 691785313 1919690 0 0 0 0
225
+ link/none
226
+ RX: bytes packets errors dropped overrun mcast
227
+ 1392844460 2659966 0 0 0 0
228
+ TX: bytes packets errors dropped carrier collsns
229
+ 691785313 1919690 0 0 0 0
212
230
  5: venet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
213
231
  link/void
214
- RX: bytes packets errors dropped overrun mcast
215
- 1392844460 2659966 0 0 0 0
216
- TX: bytes packets errors dropped carrier collsns
217
- 691785313 1919690 0 0 0 0
218
- IP_LINK_S
219
-
220
- @linux_route_n = <<-ROUTE_N
221
- Kernel IP routing table
222
- Destination Gateway Genmask Flags Metric Ref Use Iface
223
- 10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
224
- 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
225
- 0.0.0.0 10.116.201.1 0.0.0.0 UG 0 0 0 eth0
226
- ROUTE_N
227
-
228
- @linux_arp_an = <<-ARP_AN
229
- ? (10.116.201.1) at fe:ff:ff:ff:ff:ff [ether] on eth0
230
- ARP_AN
231
-
232
- @linux_ip_neighbor_show = <<-NEIGHBOR_SHOW
233
- 10.116.201.1 dev eth0 lladdr fe:ff:ff:ff:ff:ff REACHABLE
234
- NEIGHBOR_SHOW
235
-
236
- @linux_ip_inet6_neighbor_show = <<-NEIGHBOR_SHOW
237
- 1111:2222:3333:4444::1 dev eth0.11 lladdr 00:1c:0e:12:34:56 router REACHABLE
232
+ RX: bytes packets errors dropped overrun mcast
233
+ 1392844460 2659966 0 0 0 0
234
+ TX: bytes packets errors dropped carrier collsns
235
+ 691785313 1919690 0 0 0 0
236
+ '
237
+ }
238
+
239
+ let(:linux_arp_an) {
240
+ '? (10.116.201.1) at fe:ff:ff:ff:ff:ff [ether] on eth0
241
+ '
242
+ }
243
+
244
+ let(:linux_ip_neighbor_show) {
245
+ '10.116.201.1 dev eth0 lladdr fe:ff:ff:ff:ff:ff REACHABLE
246
+ '
247
+ }
248
+
249
+ let(:linux_ip_inet6_neighbor_show) {
250
+ '1111:2222:3333:4444::1 dev eth0.11 lladdr 00:1c:0e:12:34:56 router REACHABLE
238
251
  fe80::21c:eff:fe12:3456 dev eth0.11 lladdr 00:1c:0e:30:28:00 router REACHABLE
239
252
  fe80::21c:eff:fe12:3456 dev eth0.153 lladdr 00:1c:0e:30:28:00 router REACHABLE
240
- NEIGHBOR_SHOW
241
-
242
- @linux_ip_route = <<-IP_ROUTE_SCOPE
243
- 10.116.201.0/24 dev eth0 proto kernel
244
- 192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
245
- 192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
246
- 172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
247
- 192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
248
- 10.5.4.0/24 \\ nexthop via 10.5.4.1 dev eth0 weight 1\\ nexthop via 10.5.4.2 dev eth0 weight 1
249
- default via 10.116.201.1 dev eth0
250
- IP_ROUTE_SCOPE
251
-
252
- @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
253
- fe80::/64 dev eth0 proto kernel metric 256
254
- fe80::/64 dev eth0.11 proto kernel metric 256
255
- 1111:2222:3333:4444::/64 dev eth0.11 metric 1024 expires 86023sec
256
- default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
257
- IP_ROUTE_SCOPE
258
-
259
- @plugin = get_plugin("linux/network")
260
- @plugin.stub(:shell_out).with("ifconfig -a").and_return([0, @linux_ifconfig, ""])
261
- @plugin.stub(:shell_out).with("arp -an").and_return([0, @linux_arp_an, ""])
253
+ '
254
+ }
255
+
256
+ before(:each) do
257
+ allow(plugin).to receive(:collect_os).and_return(:linux)
258
+
259
+ allow(plugin).to receive(:shell_out).with("ip addr").and_return(mock_shell_out(0, linux_ip_addr, ""))
260
+ allow(plugin).to receive(:shell_out).with("ip -d -s link").and_return(mock_shell_out(0, linux_ip_link_s_d, ""))
261
+ allow(plugin).to receive(:shell_out).with("ip -f inet neigh show").and_return(mock_shell_out(0, linux_ip_neighbor_show, ""))
262
+ allow(plugin).to receive(:shell_out).with("ip -f inet6 neigh show").and_return(mock_shell_out(0, linux_ip_inet6_neighbor_show, ""))
263
+ allow(plugin).to receive(:shell_out).with("ip -o -f inet route show").and_return(mock_shell_out(0, linux_ip_route, ""))
264
+ allow(plugin).to receive(:shell_out).with("ip -o -f inet6 route show").and_return(mock_shell_out(0, linux_ip_route_inet6, ""))
265
+
266
+ allow(plugin).to receive(:shell_out).with("route -n").and_return(mock_shell_out(0, linux_route_n, ""))
267
+ allow(plugin).to receive(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, linux_ifconfig, ""))
268
+ allow(plugin).to receive(:shell_out).with("arp -an").and_return(mock_shell_out(0, linux_arp_an, ""))
262
269
  end
263
270
 
264
271
  ["ifconfig","iproute2"].each do |network_method|
265
272
 
266
273
  describe "gathering IP layer address info via #{network_method}" do
267
- before do
268
- File.stub(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
269
- do_stubs
274
+ before(:each) do
275
+ allow(File).to receive(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
276
+ plugin.run
270
277
  end
271
278
 
272
279
  it "completes the run" do
273
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
274
- @plugin.run
275
- @plugin['network'].should_not be_nil
280
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
281
+ expect(plugin['network']).not_to be_nil
276
282
  end
277
283
 
278
284
  it "detects the interfaces" do
279
- @plugin.run
280
- @plugin['network']['interfaces'].keys.sort.should == ["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "foo:veth0@eth0", "lo", "tun0", "venet0", "venet0:0"]
285
+ expect(plugin['network']['interfaces'].keys.sort).to eq(["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "foo:veth0@eth0", "lo", "tun0", "venet0", "venet0:0"])
281
286
  end
282
287
 
283
288
  it "detects the ipv4 addresses of the ethernet interface" do
284
- @plugin.run
285
- @plugin['network']['interfaces']['eth0']['addresses'].keys.should include('10.116.201.76')
286
- @plugin['network']['interfaces']['eth0']['addresses']['10.116.201.76']['netmask'].should == '255.255.255.0'
287
- @plugin['network']['interfaces']['eth0']['addresses']['10.116.201.76']['broadcast'].should == '10.116.201.255'
288
- @plugin['network']['interfaces']['eth0']['addresses']['10.116.201.76']['family'].should == 'inet'
289
+ expect(plugin['network']['interfaces']['eth0']['addresses'].keys).to include('10.116.201.76')
290
+ expect(plugin['network']['interfaces']['eth0']['addresses']['10.116.201.76']['netmask']).to eq('255.255.255.0')
291
+ expect(plugin['network']['interfaces']['eth0']['addresses']['10.116.201.76']['broadcast']).to eq('10.116.201.255')
292
+ expect(plugin['network']['interfaces']['eth0']['addresses']['10.116.201.76']['family']).to eq('inet')
289
293
  end
290
294
 
291
295
  it "detects the ipv4 addresses of an ethernet subinterface" do
292
- @plugin.run
293
- @plugin['network']['interfaces']['eth0.11']['addresses'].keys.should include('192.168.0.16')
294
- @plugin['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['netmask'].should == '255.255.255.0'
295
- @plugin['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['broadcast'].should == '192.168.0.255'
296
- @plugin['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['family'].should == 'inet'
296
+ expect(plugin['network']['interfaces']['eth0.11']['addresses'].keys).to include('192.168.0.16')
297
+ expect(plugin['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['netmask']).to eq('255.255.255.0')
298
+ expect(plugin['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['broadcast']).to eq('192.168.0.255')
299
+ expect(plugin['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['family']).to eq('inet')
297
300
  end
298
301
 
299
302
  it "detects the ipv6 addresses of the ethernet interface" do
300
- @plugin.run
301
- @plugin['network']['interfaces']['eth0']['addresses'].keys.should include('fe80::1031:3dff:fe02:bea2')
302
- @plugin['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['scope'].should == 'Link'
303
- @plugin['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['prefixlen'].should == '64'
304
- @plugin['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['family'].should == 'inet6'
303
+ expect(plugin['network']['interfaces']['eth0']['addresses'].keys).to include('fe80::1031:3dff:fe02:bea2')
304
+ expect(plugin['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['scope']).to eq('Link')
305
+ expect(plugin['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['prefixlen']).to eq('64')
306
+ expect(plugin['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['family']).to eq('inet6')
305
307
  end
306
308
 
307
309
  it "detects the ipv6 addresses of an ethernet subinterface" do
308
- @plugin.run
309
310
  %w[ 1111:2222:3333:4444::2 1111:2222:3333:4444::3 ].each do |addr|
310
- @plugin['network']['interfaces']['eth0.11']['addresses'].keys.should include(addr)
311
- @plugin['network']['interfaces']['eth0.11']['addresses'][addr]['scope'].should == 'Global'
312
- @plugin['network']['interfaces']['eth0.11']['addresses'][addr]['prefixlen'].should == '64'
313
- @plugin['network']['interfaces']['eth0.11']['addresses'][addr]['family'].should == 'inet6'
311
+ expect(plugin['network']['interfaces']['eth0.11']['addresses'].keys).to include(addr)
312
+ expect(plugin['network']['interfaces']['eth0.11']['addresses'][addr]['scope']).to eq('Global')
313
+ expect(plugin['network']['interfaces']['eth0.11']['addresses'][addr]['prefixlen']).to eq('64')
314
+ expect(plugin['network']['interfaces']['eth0.11']['addresses'][addr]['family']).to eq('inet6')
314
315
  end
315
316
  end
316
317
 
317
318
  it "detects the mac addresses of the ethernet interface" do
318
- @plugin.run
319
- @plugin['network']['interfaces']['eth0']['addresses'].keys.should include('12:31:3D:02:BE:A2')
320
- @plugin['network']['interfaces']['eth0']['addresses']['12:31:3D:02:BE:A2']['family'].should == 'lladdr'
319
+ expect(plugin['network']['interfaces']['eth0']['addresses'].keys).to include('12:31:3D:02:BE:A2')
320
+ expect(plugin['network']['interfaces']['eth0']['addresses']['12:31:3D:02:BE:A2']['family']).to eq('lladdr')
321
321
  end
322
322
 
323
323
  it "detects the encapsulation type of the ethernet interface" do
324
- @plugin.run
325
- @plugin['network']['interfaces']['eth0']['encapsulation'].should == 'Ethernet'
324
+ expect(plugin['network']['interfaces']['eth0']['encapsulation']).to eq('Ethernet')
326
325
  end
327
326
 
328
327
  it "detects the flags of the ethernet interface" do
329
- @plugin.run
330
328
  if network_method == "ifconfig"
331
- @plugin['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','MULTICAST','RUNNING','UP']
329
+ expect(plugin['network']['interfaces']['eth0']['flags'].sort).to eq(['BROADCAST','MULTICAST','RUNNING','UP'])
332
330
  else
333
- @plugin['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','LOWER_UP','MULTICAST','UP']
331
+ expect(plugin['network']['interfaces']['eth0']['flags'].sort).to eq(['BROADCAST','LOWER_UP','MULTICAST','UP'])
334
332
  end
335
333
  end
336
334
 
337
335
  it "detects the number of the ethernet interface" do
338
- @plugin.run
339
- @plugin['network']['interfaces']['eth0']['number'].should == "0"
336
+ expect(plugin['network']['interfaces']['eth0']['number']).to eq("0")
340
337
  end
341
338
 
342
339
  it "detects the mtu of the ethernet interface" do
343
- @plugin.run
344
- @plugin['network']['interfaces']['eth0']['mtu'].should == "1500"
340
+ expect(plugin['network']['interfaces']['eth0']['mtu']).to eq("1500")
345
341
  end
346
-
342
+
347
343
  it "detects the ipv4 addresses of the loopback interface" do
348
- @plugin.run
349
- @plugin['network']['interfaces']['lo']['addresses'].keys.should include('127.0.0.1')
350
- @plugin['network']['interfaces']['lo']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0'
351
- @plugin['network']['interfaces']['lo']['addresses']['127.0.0.1']['family'].should == 'inet'
344
+ expect(plugin['network']['interfaces']['lo']['addresses'].keys).to include('127.0.0.1')
345
+ expect(plugin['network']['interfaces']['lo']['addresses']['127.0.0.1']['netmask']).to eq('255.0.0.0')
346
+ expect(plugin['network']['interfaces']['lo']['addresses']['127.0.0.1']['family']).to eq('inet')
352
347
  end
353
348
 
354
349
  it "detects the ipv6 addresses of the loopback interface" do
355
- @plugin.run
356
- @plugin['network']['interfaces']['lo']['addresses'].keys.should include('::1')
357
- @plugin['network']['interfaces']['lo']['addresses']['::1']['scope'].should == 'Node'
358
- @plugin['network']['interfaces']['lo']['addresses']['::1']['prefixlen'].should == '128'
359
- @plugin['network']['interfaces']['lo']['addresses']['::1']['family'].should == 'inet6'
350
+ expect(plugin['network']['interfaces']['lo']['addresses'].keys).to include('::1')
351
+ expect(plugin['network']['interfaces']['lo']['addresses']['::1']['scope']).to eq('Node')
352
+ expect(plugin['network']['interfaces']['lo']['addresses']['::1']['prefixlen']).to eq('128')
353
+ expect(plugin['network']['interfaces']['lo']['addresses']['::1']['family']).to eq('inet6')
360
354
  end
361
355
 
362
356
  it "detects the encapsulation type of the loopback interface" do
363
- @plugin.run
364
- @plugin['network']['interfaces']['lo']['encapsulation'].should == 'Loopback'
357
+ expect(plugin['network']['interfaces']['lo']['encapsulation']).to eq('Loopback')
365
358
  end
366
359
 
367
360
  it "detects the flags of the ethernet interface" do
368
- @plugin.run
369
361
  if network_method == "ifconfig"
370
- @plugin['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','RUNNING','UP']
362
+ expect(plugin['network']['interfaces']['lo']['flags'].sort).to eq(['LOOPBACK','RUNNING','UP'])
371
363
  else
372
- @plugin['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','LOWER_UP','UP']
364
+ expect(plugin['network']['interfaces']['lo']['flags'].sort).to eq(['LOOPBACK','LOWER_UP','UP'])
373
365
  end
374
366
  end
375
367
 
376
368
 
377
369
  it "detects the mtu of the loopback interface" do
378
- @plugin.run
379
- @plugin['network']['interfaces']['lo']['mtu'].should == "16436"
370
+ expect(plugin['network']['interfaces']['lo']['mtu']).to eq("16436")
380
371
  end
381
372
 
382
373
  it "detects the arp entries" do
383
- @plugin.run
384
- @plugin['network']['interfaces']['eth0']['arp']['10.116.201.1'].should == 'fe:ff:ff:ff:ff:ff'
374
+ expect(plugin['network']['interfaces']['eth0']['arp']['10.116.201.1']).to eq('fe:ff:ff:ff:ff:ff')
385
375
  end
386
376
 
387
377
  end
388
-
378
+
389
379
  describe "gathering interface counters via #{network_method}" do
390
- before do
391
- File.stub(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
392
- do_stubs
393
- @plugin.run
380
+ before(:each) do
381
+ allow(File).to receive(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
382
+ plugin.run
394
383
  end
395
384
 
396
385
  it "detects the ethernet counters" do
397
- @plugin['counters']['network']['interfaces']['eth0']['tx']['bytes'].should == "691785313"
398
- @plugin['counters']['network']['interfaces']['eth0']['tx']['packets'].should == "1919690"
399
- @plugin['counters']['network']['interfaces']['eth0']['tx']['collisions'].should == "0"
400
- @plugin['counters']['network']['interfaces']['eth0']['tx']['queuelen'].should == "1000"
401
- @plugin['counters']['network']['interfaces']['eth0']['tx']['errors'].should == "0"
402
- @plugin['counters']['network']['interfaces']['eth0']['tx']['carrier'].should == "0"
403
- @plugin['counters']['network']['interfaces']['eth0']['tx']['drop'].should == "0"
386
+ expect(plugin['counters']['network']['interfaces']['eth0']['tx']['bytes']).to eq("691785313")
387
+ expect(plugin['counters']['network']['interfaces']['eth0']['tx']['packets']).to eq("1919690")
388
+ expect(plugin['counters']['network']['interfaces']['eth0']['tx']['collisions']).to eq("0")
389
+ expect(plugin['counters']['network']['interfaces']['eth0']['tx']['queuelen']).to eq("1000")
390
+ expect(plugin['counters']['network']['interfaces']['eth0']['tx']['errors']).to eq("0")
391
+ expect(plugin['counters']['network']['interfaces']['eth0']['tx']['carrier']).to eq("0")
392
+ expect(plugin['counters']['network']['interfaces']['eth0']['tx']['drop']).to eq("0")
404
393
 
405
- @plugin['counters']['network']['interfaces']['eth0']['rx']['bytes'].should == "1392844460"
406
- @plugin['counters']['network']['interfaces']['eth0']['rx']['packets'].should == "2659966"
407
- @plugin['counters']['network']['interfaces']['eth0']['rx']['errors'].should == "0"
408
- @plugin['counters']['network']['interfaces']['eth0']['rx']['overrun'].should == "0"
409
- @plugin['counters']['network']['interfaces']['eth0']['rx']['drop'].should == "0"
394
+ expect(plugin['counters']['network']['interfaces']['eth0']['rx']['bytes']).to eq("1392844460")
395
+ expect(plugin['counters']['network']['interfaces']['eth0']['rx']['packets']).to eq("2659966")
396
+ expect(plugin['counters']['network']['interfaces']['eth0']['rx']['errors']).to eq("0")
397
+ expect(plugin['counters']['network']['interfaces']['eth0']['rx']['overrun']).to eq("0")
398
+ expect(plugin['counters']['network']['interfaces']['eth0']['rx']['drop']).to eq("0")
410
399
  end
411
400
 
412
401
  it "detects the loopback counters" do
413
- @plugin['counters']['network']['interfaces']['lo']['tx']['bytes'].should == "35224"
414
- @plugin['counters']['network']['interfaces']['lo']['tx']['packets'].should == "524"
415
- @plugin['counters']['network']['interfaces']['lo']['tx']['collisions'].should == "0"
416
- @plugin['counters']['network']['interfaces']['lo']['tx']['errors'].should == "0"
417
- @plugin['counters']['network']['interfaces']['lo']['tx']['carrier'].should == "0"
418
- @plugin['counters']['network']['interfaces']['lo']['tx']['drop'].should == "0"
419
-
420
- @plugin['counters']['network']['interfaces']['lo']['rx']['bytes'].should == "35224"
421
- @plugin['counters']['network']['interfaces']['lo']['rx']['packets'].should == "524"
422
- @plugin['counters']['network']['interfaces']['lo']['rx']['errors'].should == "0"
423
- @plugin['counters']['network']['interfaces']['lo']['rx']['overrun'].should == "0"
424
- @plugin['counters']['network']['interfaces']['lo']['rx']['drop'].should == "0"
402
+ expect(plugin['counters']['network']['interfaces']['lo']['tx']['bytes']).to eq("35224")
403
+ expect(plugin['counters']['network']['interfaces']['lo']['tx']['packets']).to eq("524")
404
+ expect(plugin['counters']['network']['interfaces']['lo']['tx']['collisions']).to eq("0")
405
+ expect(plugin['counters']['network']['interfaces']['lo']['tx']['errors']).to eq("0")
406
+ expect(plugin['counters']['network']['interfaces']['lo']['tx']['carrier']).to eq("0")
407
+ expect(plugin['counters']['network']['interfaces']['lo']['tx']['drop']).to eq("0")
408
+
409
+ expect(plugin['counters']['network']['interfaces']['lo']['rx']['bytes']).to eq("35224")
410
+ expect(plugin['counters']['network']['interfaces']['lo']['rx']['packets']).to eq("524")
411
+ expect(plugin['counters']['network']['interfaces']['lo']['rx']['errors']).to eq("0")
412
+ expect(plugin['counters']['network']['interfaces']['lo']['rx']['overrun']).to eq("0")
413
+ expect(plugin['counters']['network']['interfaces']['lo']['rx']['drop']).to eq("0")
425
414
  end
426
415
  end
427
416
 
428
417
  describe "setting the node's default IP address attribute with #{network_method}" do
429
- before do
430
- File.stub(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
431
- do_stubs
418
+ before(:each) do
419
+ allow(File).to receive(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
420
+ plugin.run
432
421
  end
433
422
 
434
423
  describe "without a subinterface" do
435
- before do
436
- @plugin.run
437
- end
438
-
439
424
  it "finds the default interface by asking which iface has the default route" do
440
- @plugin['network']['default_interface'].should == 'eth0'
425
+ expect(plugin['network']['default_interface']).to eq('eth0')
441
426
  end
442
-
427
+
443
428
  it "finds the default gateway by asking which iface has the default route" do
444
- @plugin['network']['default_gateway'].should == '10.116.201.1'
429
+ expect(plugin['network']['default_gateway']).to eq('10.116.201.1')
445
430
  end
446
431
  end
447
-
432
+
448
433
  describe "with a link level default route" do
449
- before do
450
- @linux_ip_route = <<-IP_ROUTE
451
- 10.116.201.0/24 dev eth0 proto kernel
434
+ let(:linux_ip_route) {
435
+ '10.116.201.0/24 dev eth0 proto kernel
452
436
  default dev eth0 scope link
453
- IP_ROUTE
454
- @linux_route_n = <<-ROUTE_N
455
- Kernel IP routing table
437
+ '
438
+ }
439
+
440
+ let(:linux_route_n) {
441
+ 'Kernel IP routing table
456
442
  Destination Gateway Genmask Flags Metric Ref Use Iface
457
443
  10.116.201.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
458
444
  0.0.0.0 0.0.0.0 0.0.0.0 U 0 0 0 eth0
459
- ROUTE_N
460
- do_stubs
445
+ '
446
+ }
461
447
 
462
- @plugin.run
448
+ before(:each) do
449
+ plugin.run
463
450
  end
464
451
 
465
452
  it "finds the default interface by asking which iface has the default route" do
466
- @plugin['network']['default_interface'].should == 'eth0'
453
+ expect(plugin['network']['default_interface']).to eq('eth0')
467
454
  end
468
-
455
+
469
456
  it "finds the default interface by asking which iface has the default route" do
470
- @plugin['network']['default_gateway'].should == '0.0.0.0'
457
+ expect(plugin['network']['default_gateway']).to eq('0.0.0.0')
471
458
  end
472
459
  end
473
460
 
474
461
  describe "with a subinterface" do
475
- before do
476
- @linux_ip_route = <<-IP_ROUTE
477
- 192.168.0.0/24 dev eth0.11 proto kernel src 192.168.0.2
462
+ let(:linux_ip_route) {
463
+ '192.168.0.0/24 dev eth0.11 proto kernel src 192.168.0.2
478
464
  default via 192.168.0.15 dev eth0.11
479
- IP_ROUTE
480
- @linux_route_n = <<-ROUTE_N
481
- Kernel IP routing table
465
+ '
466
+ }
467
+
468
+ let(:linux_route_n) {
469
+ 'Kernel IP routing table
482
470
  Destination Gateway Genmask Flags Metric Ref Use Iface
483
471
  192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0.11
484
472
  0.0.0.0 192.168.0.15 0.0.0.0 UG 0 0 0 eth0.11
485
- ROUTE_N
486
-
487
- do_stubs
473
+ '
474
+ }
488
475
 
489
- @plugin.run
476
+ before(:each) do
477
+ plugin.run
490
478
  end
491
-
479
+
492
480
  it "finds the default interface by asking which iface has the default route" do
493
- @plugin['network']["default_interface"].should == 'eth0.11'
481
+ expect(plugin['network']["default_interface"]).to eq('eth0.11')
494
482
  end
495
-
483
+
496
484
  it "finds the default interface by asking which iface has the default route" do
497
- @plugin['network']["default_gateway"].should == '192.168.0.15'
485
+ expect(plugin['network']["default_gateway"]).to eq('192.168.0.15')
498
486
  end
499
487
  end
500
488
  end
501
489
  end
502
490
 
503
491
  describe "for newer network features using iproute2 only" do
504
- before do
505
- File.stub(:exist?).with("/sbin/ip").and_return(true) # iproute2 only
506
- do_stubs
492
+ before(:each) do
493
+ allow(File).to receive(:exist?).with("/sbin/ip").and_return(true) # iproute2 only
494
+ plugin.run
507
495
  end
508
496
 
509
497
  it "completes the run" do
510
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
511
- @plugin.run
512
- @plugin['network'].should_not be_nil
498
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
499
+ expect(plugin['network']).not_to be_nil
513
500
  end
514
501
 
515
502
  it "finds the default inet6 interface if there's a inet6 default route" do
516
- @plugin.run
517
- @plugin['network']['default_inet6_interface'].should == 'eth0.11'
503
+ expect(plugin['network']['default_inet6_interface']).to eq('eth0.11')
518
504
  end
519
505
 
520
506
  it "finds the default inet6 gateway if there's a inet6 default route" do
521
- @plugin.run
522
- @plugin['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::1'
507
+ expect(plugin['network']['default_inet6_gateway']).to eq('1111:2222:3333:4444::1')
523
508
  end
524
509
 
525
510
  it "finds inet6 neighbours" do
526
- @plugin.run
527
- @plugin['network']['interfaces']['eth0.11']['neighbour_inet6']['1111:2222:3333:4444::1'].should == '00:1c:0e:12:34:56'
511
+ expect(plugin['network']['interfaces']['eth0.11']['neighbour_inet6']['1111:2222:3333:4444::1']).to eq('00:1c:0e:12:34:56')
528
512
  end
529
513
 
530
514
  it "detects the ipv4 addresses of an ethernet interface with a crazy name" do
531
- @plugin.run
532
- @plugin['network']['interfaces']['foo:veth0@eth0']['addresses'].keys.should include('192.168.212.2')
533
- @plugin['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['netmask'].should == '255.255.255.0'
534
- @plugin['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['family'].should == 'inet'
515
+ expect(plugin['network']['interfaces']['foo:veth0@eth0']['addresses'].keys).to include('192.168.212.2')
516
+ expect(plugin['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['netmask']).to eq('255.255.255.0')
517
+ expect(plugin['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['family']).to eq('inet')
535
518
  end
536
519
 
537
520
  it "generates a fake interface for ip aliases for backward compatibility" do
538
- @plugin.run
539
- @plugin['network']['interfaces']['eth0:5']['addresses'].keys.should include('192.168.5.1')
540
- @plugin['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['netmask'].should == '255.255.255.0'
541
- @plugin['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['family'].should == 'inet'
521
+ expect(plugin['network']['interfaces']['eth0:5']['addresses'].keys).to include('192.168.5.1')
522
+ expect(plugin['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['netmask']).to eq('255.255.255.0')
523
+ expect(plugin['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['family']).to eq('inet')
542
524
  end
543
525
 
544
526
  it "adds the vlan information of an interface" do
545
- @plugin.run
546
- @plugin['network']['interfaces']['eth0.11']['vlan']['id'].should == '11'
547
- @plugin['network']['interfaces']['eth0.11']['vlan']['flags'].should == [ 'REORDER_HDR' ]
527
+ expect(plugin['network']['interfaces']['eth0.11']['vlan']['id']).to eq('11')
528
+ expect(plugin['network']['interfaces']['eth0.11']['vlan']['flags']).to eq([ 'REORDER_HDR' ])
548
529
  end
549
530
 
550
531
  it "adds the state of an interface" do
551
- @plugin.run
552
- @plugin['network']['interfaces']['eth0.11']['state'].should == 'up'
532
+ expect(plugin['network']['interfaces']['eth0.11']['state']).to eq('up')
553
533
  end
554
534
 
555
535
  describe "when dealing with routes" do
556
536
  it "adds routes" do
557
- @plugin.run
558
- @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.116.201.0/24", :proto => "kernel", :family =>"inet" )
559
- @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.5.4.0/24", :family =>"inet", :via => "10.5.4.1")
560
- @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.5.4.0/24", :family =>"inet", :via => "10.5.4.2")
561
- @plugin['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" )
562
- @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "fe80::/64", :metric => "256", :proto => "kernel", :family => "inet6" )
563
- @plugin['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "1111:2222:3333:4444::/64", :metric => "1024", :family => "inet6" )
564
- @plugin['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "default", :via => "1111:2222:3333:4444::1", :metric => "1024", :family => "inet6")
537
+ plugin.run
538
+ expect(plugin['network']['interfaces']['eth0']['routes']).to include Mash.new( :destination => "10.116.201.0/24", :proto => "kernel", :family =>"inet" )
539
+ expect(plugin['network']['interfaces']['eth0']['routes']).to include Mash.new( :destination => "10.5.4.0/24", :family =>"inet", :via => "10.5.4.1")
540
+ expect(plugin['network']['interfaces']['eth0']['routes']).to include Mash.new( :destination => "10.5.4.0/24", :family =>"inet", :via => "10.5.4.2")
541
+ expect(plugin['network']['interfaces']['foo:veth0@eth0']['routes']).to include Mash.new( :destination => "192.168.212.0/24", :proto => "kernel", :src => "192.168.212.2", :family =>"inet" )
542
+ expect(plugin['network']['interfaces']['eth0']['routes']).to include Mash.new( :destination => "fe80::/64", :metric => "256", :proto => "kernel", :family => "inet6" )
543
+ expect(plugin['network']['interfaces']['eth0.11']['routes']).to include Mash.new( :destination => "1111:2222:3333:4444::/64", :metric => "1024", :family => "inet6" )
544
+ expect(plugin['network']['interfaces']['eth0.11']['routes']).to include Mash.new( :destination => "default", :via => "1111:2222:3333:4444::1", :metric => "1024", :family => "inet6")
565
545
  end
566
546
 
567
547
  describe "when there isn't a source field in route entries " do
548
+ before(:each) do
549
+ plugin.run
550
+ end
551
+
568
552
  it "doesn't set ipaddress" do
569
- @plugin.run
570
- @plugin['ipaddress'].should be nil
553
+ expect(plugin['ipaddress']).to be nil
571
554
  end
572
555
 
573
556
  it "doesn't set macaddress" do
574
- @plugin.run
575
- @plugin['macaddress'].should be nil
557
+ expect(plugin['macaddress']).to be nil
576
558
  end
577
559
 
578
560
  it "doesn't set ip6address" do
579
- @plugin.run
580
- @plugin['ip6address'].should be nil
561
+ expect(plugin['ip6address']).to be nil
581
562
  end
582
563
  end
583
564
 
584
565
  describe "when there's a source field in the default route entry" do
585
- before do
586
- @linux_ip_route = <<-IP_ROUTE_SCOPE
587
- 10.116.201.0/24 dev eth0 proto kernel
566
+ let(:linux_ip_route) {
567
+ '10.116.201.0/24 dev eth0 proto kernel
588
568
  192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
589
569
  192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
590
570
  172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
591
571
  192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
592
572
  default via 10.116.201.1 dev eth0 src 10.116.201.76
593
- IP_ROUTE_SCOPE
573
+ '
574
+ }
594
575
 
595
- @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
596
- fe80::/64 dev eth0 proto kernel metric 256
576
+ let(:linux_ip_route_inet6) {
577
+ 'fe80::/64 dev eth0 proto kernel metric 256
597
578
  fe80::/64 dev eth0.11 proto kernel metric 256
598
579
  1111:2222:3333:4444::/64 dev eth0.11 metric 1024
599
580
  default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
600
- IP_ROUTE_SCOPE
581
+ '
582
+ }
601
583
 
602
- do_stubs
584
+ before(:each) do
585
+ plugin.run
603
586
  end
604
587
 
605
588
  it "completes the run" do
606
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
607
- @plugin.run
608
- @plugin['network'].should_not be_nil
589
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
590
+ expect(plugin['network']).not_to be_nil
609
591
  end
610
592
 
611
593
  it "sets ipaddress" do
612
- @plugin.run
613
- @plugin['ipaddress'].should == "10.116.201.76"
594
+ expect(plugin['ipaddress']).to eq("10.116.201.76")
614
595
  end
615
596
 
616
597
  it "sets ip6address" do
617
- @plugin.run
618
- @plugin['ip6address'].should == "1111:2222:3333:4444::3"
598
+ expect(plugin['ip6address']).to eq("1111:2222:3333:4444::3")
619
599
  end
620
600
  end
621
601
 
622
602
  describe "when there're several default routes" do
623
- before do
624
- @linux_ip_route = <<-IP_ROUTE_SCOPE
625
- 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
603
+ let(:linux_ip_route) {
604
+ '10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
626
605
  192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
627
606
  192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
628
607
  172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
629
608
  192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
630
609
  default via 10.116.201.1 dev eth0 metric 10
631
610
  default via 10.116.201.254 dev eth0 metric 9
632
- IP_ROUTE_SCOPE
611
+ '
612
+ }
633
613
 
634
- @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
635
- fe80::/64 dev eth0 proto kernel metric 256
614
+ let(:linux_ip_route_inet6) {
615
+ 'fe80::/64 dev eth0 proto kernel metric 256
636
616
  fe80::/64 dev eth0.11 proto kernel metric 256
637
617
  1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
638
618
  default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
639
619
  default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023
640
- IP_ROUTE_SCOPE
620
+ '
621
+ }
641
622
 
642
- do_stubs
623
+ before(:each) do
624
+ plugin.run
643
625
  end
644
626
 
645
627
  it "completes the run" do
646
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
647
- @plugin.run
648
- @plugin['network'].should_not be_nil
628
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
629
+ expect(plugin['network']).not_to be_nil
649
630
  end
650
631
 
651
632
  it "sets default ipv4 interface and gateway" do
652
- @plugin.run
653
- @plugin['network']['default_interface'].should == 'eth0'
654
- @plugin['network']['default_gateway'].should == '10.116.201.254'
633
+ expect(plugin['network']['default_interface']).to eq('eth0')
634
+ expect(plugin['network']['default_gateway']).to eq('10.116.201.254')
655
635
  end
656
636
 
657
637
  it "sets default ipv6 interface and gateway" do
658
- @plugin.run
659
- @plugin['network']['default_inet6_interface'].should == 'eth0.11'
660
- @plugin['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::ffff'
638
+ expect(plugin['network']['default_inet6_interface']).to eq('eth0.11')
639
+ expect(plugin['network']['default_inet6_gateway']).to eq('1111:2222:3333:4444::ffff')
661
640
  end
662
641
  end
663
642
 
664
643
  describe "when there're a mixed setup of routes that could be used to set ipaddress" do
665
- before do
666
- @linux_ip_route = <<-IP_ROUTE_SCOPE
667
- 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
644
+ let(:linux_ip_route) {
645
+ '10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
668
646
  192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
669
647
  192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
670
648
  172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
671
649
  192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
672
650
  default via 10.116.201.1 dev eth0 metric 10
673
651
  default via 10.116.201.254 dev eth0 metric 9 src 10.116.201.74
674
- IP_ROUTE_SCOPE
652
+ '
653
+ }
675
654
 
676
- @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
677
- fe80::/64 dev eth0 proto kernel metric 256
655
+ let(:linux_ip_route_inet6) {
656
+ 'fe80::/64 dev eth0 proto kernel metric 256
678
657
  fe80::/64 dev eth0.11 proto kernel metric 256
679
658
  1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
680
659
  default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
681
660
  default via 1111:2222:3333:4444::ffff dev eth0.11 metric 1023 src 1111:2222:3333:4444::2
682
- IP_ROUTE_SCOPE
661
+ '
662
+ }
683
663
 
684
- do_stubs
664
+ before(:each) do
665
+ plugin.run
685
666
  end
686
667
 
687
668
  it "completes the run" do
688
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
689
- @plugin.run
690
- @plugin['network'].should_not be_nil
669
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
670
+ expect(plugin['network']).not_to be_nil
691
671
  end
692
672
 
693
673
  it "sets ipaddress" do
694
- @plugin.run
695
- @plugin["ipaddress"].should == "10.116.201.74"
674
+ expect(plugin["ipaddress"]).to eq("10.116.201.74")
696
675
  end
697
676
 
698
677
  it "sets ip6address" do
699
- @plugin.run
700
- @plugin["ip6address"].should == "1111:2222:3333:4444::2"
678
+ expect(plugin["ip6address"]).to eq("1111:2222:3333:4444::2")
701
679
  end
702
680
  end
703
681
 
704
682
  describe "when there's a source field in a local route entry " do
705
- before do
706
- @linux_ip_route = <<-IP_ROUTE_SCOPE
707
- 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
683
+ let(:linux_ip_route) {
684
+ '10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
708
685
  192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
709
686
  192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
710
687
  172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
711
688
  192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
712
689
  default via 10.116.201.1 dev eth0
713
- IP_ROUTE_SCOPE
690
+ '
691
+ }
714
692
 
715
- @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
716
- fe80::/64 dev eth0 proto kernel metric 256
693
+ let(:linux_ip_route_inet6) {
694
+ 'fe80::/64 dev eth0 proto kernel metric 256
717
695
  fe80::/64 dev eth0.11 proto kernel metric 256
718
696
  1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
719
697
  default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
720
- IP_ROUTE_SCOPE
721
-
722
- do_stubs
723
- end
698
+ '
699
+ }
724
700
 
725
701
  it "completes the run" do
726
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
727
- @plugin.run
728
- @plugin['network'].should_not be_nil
702
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
703
+ plugin.run
704
+ expect(plugin['network']).not_to be_nil
729
705
  end
730
706
 
731
707
  it "sets ipaddress" do
732
- @plugin.run
733
- @plugin['ipaddress'].should == "10.116.201.76"
708
+ plugin.run
709
+ expect(plugin['ipaddress']).to eq("10.116.201.76")
734
710
  end
735
711
 
736
712
  describe "when about to set macaddress" do
737
713
  it "sets macaddress" do
738
- @plugin.run
739
- @plugin['macaddress'].should == "12:31:3D:02:BE:A2"
714
+ plugin.run
715
+ expect(plugin['macaddress']).to eq("12:31:3D:02:BE:A2")
740
716
  end
741
717
 
742
718
  describe "when then interface has the NOARP flag" do
743
- before do
744
- @linux_ip_route = <<-IP_ROUTE
745
- 10.118.19.1 dev tun0 proto kernel src 10.118.19.39
719
+ let(:linux_ip_route) {
720
+ '10.118.19.1 dev tun0 proto kernel src 10.118.19.39
746
721
  default via 172.16.19.1 dev tun0
747
- IP_ROUTE
748
-
749
- do_stubs
750
- end
722
+ '
723
+ }
751
724
 
752
725
  it "completes the run" do
753
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
754
- @plugin.run
755
- @plugin['network'].should_not be_nil
726
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
727
+ plugin.run
728
+ expect(plugin['network']).not_to be_nil
756
729
  end
757
730
 
758
731
  it "doesn't set macaddress" do
759
- @plugin.run
760
- @plugin['macaddress'].should be_nil
732
+ plugin.run
733
+ expect(plugin['macaddress']).to be_nil
761
734
  end
762
735
  end
763
736
  end
764
737
 
765
738
  it "sets ip6address" do
766
- @plugin.run
767
- @plugin['ip6address'].should == "1111:2222:3333:4444::3"
739
+ plugin.run
740
+ expect(plugin['ip6address']).to eq("1111:2222:3333:4444::3")
768
741
  end
769
742
  end
770
743
 
771
744
  describe "with a link level default route" do
772
- before do
773
- @linux_ip_route = <<-IP_ROUTE
774
- default dev venet0 scope link
775
- IP_ROUTE
745
+ let(:linux_ip_route) {
746
+ 'default dev venet0 scope link
747
+ '
748
+ }
776
749
 
777
- do_stubs
750
+ before(:each) do
751
+ plugin.run
778
752
  end
779
753
 
780
754
  it "completes the run" do
781
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
782
- @plugin.run
783
- @plugin['network'].should_not be_nil
755
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
756
+ expect(plugin['network']).not_to be_nil
784
757
  end
785
758
 
786
759
  it "doesn't set ipaddress" do
787
- @plugin.run
788
- @plugin['ipaddress'].should be_nil
760
+ expect(plugin['ipaddress']).to be_nil
789
761
  end
790
762
  end
791
763
 
792
764
  describe "when not having a global scope ipv6 address" do
793
- before do
794
- @linux_ip_route_inet6 = <<-IP_ROUTE_SCOPE
795
- fe80::/64 dev eth0 proto kernel metric 256
765
+ let(:linux_ip_route_inet6) {
766
+ 'fe80::/64 dev eth0 proto kernel metric 256
796
767
  default via fe80::21c:eff:fe12:3456 dev eth0.153 src fe80::2e0:81ff:fe2b:48e7 metric 1024
797
- IP_ROUTE_SCOPE
798
-
799
- do_stubs
768
+ '
769
+ }
770
+ before(:each) do
771
+ plugin.run
800
772
  end
801
773
 
802
774
  it "completes the run" do
803
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
804
- @plugin.run
805
- @plugin['network'].should_not be_nil
775
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
776
+ expect(plugin['network']).not_to be_nil
806
777
  end
807
778
 
808
779
  it "doesn't set ip6address" do
809
- @plugin.run
810
- @plugin['ip6address'].should be_nil
780
+ expect(plugin['ip6address']).to be_nil
811
781
  end
812
782
 
813
783
  end
814
784
 
815
785
  describe "with no default route" do
816
- before do
817
- @linux_ip_route = <<-IP_ROUTE
818
- 10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
786
+ let(:linux_ip_route) {
787
+ '10.116.201.0/24 dev eth0 proto kernel src 10.116.201.76
819
788
  192.168.5.0/24 dev eth0 proto kernel src 192.168.5.1
820
789
  192.168.212.0/24 dev foo:veth0@eth0 proto kernel src 192.168.212.2
821
790
  172.16.151.0/24 dev eth0 proto kernel src 172.16.151.100
822
791
  192.168.0.0/24 dev eth0 proto kernel src 192.168.0.2
823
- IP_ROUTE
792
+ '
793
+ }
824
794
 
825
- @linux_ip_route_inet6 = <<-IP_ROUTE
826
- fe80::/64 dev eth0 proto kernel metric 256
795
+ let(:linux_ip_route_inet6) {
796
+ 'fe80::/64 dev eth0 proto kernel metric 256
827
797
  fe80::/64 dev eth0.11 proto kernel metric 256
828
798
  1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::3
829
- IP_ROUTE
799
+ '
800
+ }
830
801
 
831
- do_stubs
802
+ before(:each) do
803
+ plugin.run
832
804
  end
833
805
 
834
806
  it "completes the run" do
835
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
836
- @plugin.run
837
- @plugin['network'].should_not be_nil
807
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
808
+ expect(plugin['network']).not_to be_nil
838
809
  end
839
810
 
840
811
  it "doesn't set ipaddress" do
841
- @plugin.run
842
- @plugin['ipaddress'].should be_nil
812
+ expect(plugin['ipaddress']).to be_nil
843
813
  end
844
814
 
845
815
  it "doesn't set ip6address" do
846
- @plugin.run
847
- @plugin['ip6address'].should be_nil
816
+ expect(plugin['ip6address']).to be_nil
848
817
  end
849
818
  end
850
819
 
851
820
  describe "with irrelevant routes (container setups)" do
852
- before do
853
- @linux_ip_route = <<-IP_ROUTE
854
- 10.116.201.0/26 dev eth0 proto kernel src 10.116.201.39
821
+ let(:linux_ip_route) {
822
+ '10.116.201.0/26 dev eth0 proto kernel src 10.116.201.39
855
823
  10.116.201.0/26 dev if4 proto kernel src 10.116.201.45
856
824
  10.118.19.0/26 dev eth0 proto kernel src 10.118.19.39
857
825
  10.118.19.0/26 dev if5 proto kernel src 10.118.19.45
858
826
  default via 10.116.201.1 dev eth0 src 10.116.201.99
859
- IP_ROUTE
827
+ '
828
+ }
860
829
 
861
- @linux_ip_route_inet6 = <<-IP_ROUTE
862
- fe80::/64 dev eth0 proto kernel metric 256
830
+ let(:linux_ip_route_inet6) {
831
+ 'fe80::/64 dev eth0 proto kernel metric 256
863
832
  fe80::/64 dev eth0.11 proto kernel metric 256
864
833
  1111:2222:3333:4444::/64 dev eth0.11 metric 1024 src 1111:2222:3333:4444::FFFF:2
865
834
  default via 1111:2222:3333:4444::1 dev eth0.11 metric 1024
866
- IP_ROUTE
835
+ '
836
+ }
867
837
 
868
- do_stubs
838
+ before(:each) do
839
+ plugin.run
869
840
  end
870
841
 
871
842
  it "completes the run" do
872
- Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
873
- @plugin.run
874
- @plugin['network'].should_not be_nil
843
+ expect(Ohai::Log).not_to receive(:debug).with(/Plugin linux::network threw exception/)
844
+ expect(plugin['network']).not_to be_nil
875
845
  end
876
846
 
877
847
  it "doesn't add bogus routes" do
878
- @plugin.run
879
- @plugin['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.116.201.0/26", :proto => "kernel", :family => "inet", :via => "10.116.201.39" )
880
- @plugin['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.118.19.0/26", :proto => "kernel", :family => "inet", :via => "10.118.19.39" )
881
- @plugin['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "1111:2222:3333:4444::/64", :family => "inet6", :metric => "1024" )
848
+ expect(plugin['network']['interfaces']['eth0']['routes']).not_to include Mash.new( :destination => "10.116.201.0/26", :proto => "kernel", :family => "inet", :via => "10.116.201.39" )
849
+ expect(plugin['network']['interfaces']['eth0']['routes']).not_to include Mash.new( :destination => "10.118.19.0/26", :proto => "kernel", :family => "inet", :via => "10.118.19.39" )
850
+ expect(plugin['network']['interfaces']['eth0']['routes']).not_to include Mash.new( :destination => "1111:2222:3333:4444::/64", :family => "inet6", :metric => "1024" )
882
851
  end
883
852
 
884
853
  it "doesn't set ipaddress" do
885
- @plugin.run
886
- @plugin['ipaddress'].should be_nil
854
+ expect(plugin['ipaddress']).to be_nil
887
855
  end
888
856
 
889
857
  it "doesn't set ip6address" do
890
- @plugin.run
891
- @plugin['ip6address'].should be_nil
858
+ expect(plugin['ip6address']).to be_nil
892
859
  end
893
860
  end
894
861
 
895
862
  # This should never happen in the real world.
896
863
  describe "when encountering a surprise interface" do
897
- before do
898
- @linux_ip_route = <<-IP_ROUTE
899
- 192.168.122.0/24 dev virbr0 proto kernel src 192.168.122.1
900
- IP_ROUTE
901
- do_stubs
902
- end
903
-
864
+ let(:linux_ip_route) {
865
+ '192.168.122.0/24 dev virbr0 proto kernel src 192.168.122.1
866
+ '
867
+ }
868
+
904
869
  it "logs a message and skips previously unseen interfaces in 'ip route show'" do
905
- Ohai::Log.should_receive(:debug).with("Skipping previously unseen interface from 'ip route show': virbr0").once
906
- Ohai::Log.stub(:debug) # Catches the 'Loading plugin network' type messages
907
- @plugin.run
870
+ expect(Ohai::Log).to receive(:debug).with("Skipping previously unseen interface from 'ip route show': virbr0").once
871
+ allow(Ohai::Log).to receive(:debug) # Catches the 'Loading plugin network' type messages
872
+ plugin.run
873
+ end
874
+ end
875
+
876
+ describe "when running with ip version ss131122" do
877
+ let(:linux_ip_link_s_d) {
878
+ '1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN mode DEFAULT group default
879
+ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0
880
+ RX: bytes packets errors dropped overrun mcast
881
+ 35224 524 0 0 0 0
882
+ TX: bytes packets errors dropped carrier collsns
883
+ 35224 524 0 0 0 0
884
+ 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
885
+ link/ether 12:31:3d:02:be:a2 brd ff:ff:ff:ff:ff:ff promiscuity 0
886
+ RX: bytes packets errors dropped overrun mcast
887
+ 1392844460 2659966 0 0 0 0
888
+ TX: bytes packets errors dropped carrier collsns
889
+ 691785313 1919690 0 0 0 0
890
+ 3: eth0.11@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default
891
+ link/ether 00:0c:29:41:71:45 brd ff:ff:ff:ff:ff:ff promiscuity 0
892
+ vlan protocol 802.1Q id 11 <REORDER_HDR>
893
+ RX: bytes packets errors dropped overrun mcast
894
+ 0 0 0 0 0 0
895
+ TX: bytes packets errors dropped carrier collsns
896
+ 0 0 0 0 0 0
897
+ 4: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 100
898
+ link/none promiscuity 0
899
+ RX: bytes packets errors dropped overrun mcast
900
+ 1392844460 2659966 0 0 0 0
901
+ TX: bytes packets errors dropped carrier collsns
902
+ 691785313 1919690 0 0 0 0
903
+ 5: venet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
904
+ link/void promiscuity 0
905
+ RX: bytes packets errors dropped overrun mcast
906
+ 1392844460 2659966 0 0 0 0
907
+ TX: bytes packets errors dropped carrier collsns
908
+ 691785313 1919690 0 0 0 0
909
+ '
910
+ }
911
+
912
+ it "adds the vlan information of an interface" do
913
+ plugin.run
914
+ expect(plugin['network']['interfaces']['eth0.11']['vlan']['id']).to eq('11')
915
+ expect(plugin['network']['interfaces']['eth0.11']['vlan']['protocol']).to eq('802.1Q')
916
+ expect(plugin['network']['interfaces']['eth0.11']['vlan']['flags']).to eq([ 'REORDER_HDR' ])
908
917
  end
909
918
  end
910
919
  end
911
920
  end
912
-
913
921
  end