ohai 6.18.0 → 6.20.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,18 +18,36 @@ provides "gce"
18
18
 
19
19
  require 'ohai/mixin/gce_metadata'
20
20
 
21
-
21
+ # Checks for matching gce dmi
22
+ # https://developers.google.com/compute/docs/instances#dmi
23
+ #
24
+ # === Return
25
+ # true:: If gce dmi matches
26
+ # false:: Otherwise
22
27
  GOOGLE_SYSFS_DMI = '/sys/firmware/dmi/entries/1-0/raw'
23
-
24
- #https://developers.google.com/compute/docs/instances#dmi
25
28
  def has_google_dmi?
26
29
  ::File.read(GOOGLE_SYSFS_DMI).include?('Google')
27
30
  end
28
31
 
32
+ # Checks for gce metadata server
33
+ #
34
+ # === Return
35
+ # true:: If gce metadata server found
36
+ # false:: Otherwise
37
+ def has_gce_metadata?
38
+ Ohai::Mixin::GCEMetadata.can_metadata_connect?(Ohai::Mixin::GCEMetadata::GCE_METADATA_ADDR,80)
39
+ end
40
+
41
+ # Identifies gce
42
+ #
43
+ # === Return
44
+ # true:: If gce can be identified
45
+ # false:: Otherwise
29
46
  def looks_like_gce?
30
- hint?('gce') || (has_google_dmi? && Ohai::Mixin::GCEMetadata.can_metadata_connect?(Ohai::Mixin::GCEMetadata::GCE_METADATA_ADDR,80))
47
+ hint?('gce') || has_google_dmi? || has_gce_metadata?
31
48
  end
32
49
 
50
+ # Adds the gce Mash
33
51
  if looks_like_gce?
34
52
  Ohai::Log.debug("looks_like_gce? == true")
35
53
  gce Mash.new
@@ -38,14 +38,11 @@ elsif File.exists?("/etc/enterprise-release")
38
38
  platform "oracle"
39
39
  platform_version get_redhatish_version(contents)
40
40
  elsif File.exists?("/etc/debian_version")
41
- # Ubuntu, GCEL and Debian both have /etc/debian_version
42
- # Ubuntu, GCEL should always have a working lsb, debian does not by default
41
+ # Ubuntu and Debian both have /etc/debian_version
42
+ # Ubuntu should always have a working lsb, debian does not by default
43
43
  if lsb[:id] =~ /Ubuntu/i
44
44
  platform "ubuntu"
45
45
  platform_version lsb[:release]
46
- elsif lsb[:id] =~ /gcel/i
47
- platform "gcel"
48
- platform_version lsb[:release]
49
46
  elsif lsb[:id] =~ /LinuxMint/i
50
47
  platform "linuxmint"
51
48
  platform_version lsb[:release]
@@ -99,7 +96,7 @@ end
99
96
 
100
97
 
101
98
  case platform
102
- when /debian/, /ubuntu/, /linuxmint/, /raspbian/, /gcel/
99
+ when /debian/, /ubuntu/, /linuxmint/, /raspbian/
103
100
  platform_family "debian"
104
101
  when /fedora/
105
102
  platform_family "fedora"
data/lib/ohai/version.rb CHANGED
@@ -18,6 +18,6 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = '6.18.0'
21
+ VERSION = '6.20.0.rc.1'
22
22
  end
23
23
 
@@ -37,10 +37,30 @@ describe Ohai::Mixin::Command, "popen4" do
37
37
  end
38
38
 
39
39
  if defined?(::Encoding) && "".respond_to?(:force_encoding) #i.e., ruby 1.9
40
- it "[OHAI-275] should mark strings as in the default external encoding" do
40
+ context "when external commands return UTF-8 strings and we are running under LANG=C encoding" do
41
+ before do
42
+ @saved_default_external = Encoding.default_external
43
+ @saved_default_internal = Encoding.default_internal
44
+ Encoding.default_external = Encoding::US_ASCII
45
+ Encoding.default_internal = Encoding::US_ASCII
46
+ end
47
+
48
+ after do
49
+ Encoding.default_external = @saved_default_external
50
+ Encoding.default_internal = @saved_default_internal
51
+ end
52
+
53
+ it "should force encode the string to UTF-8" do
54
+ extend Ohai::Mixin::Command
55
+ snowy = run_command(:command => ("echo '" + ('☃' * 8096) + "'"))[1]
56
+ snowy.encoding.should == Encoding::UTF_8
57
+ end
58
+ end
59
+
60
+ it "should force encode the string to UTF-8" do
41
61
  extend Ohai::Mixin::Command
42
62
  snowy = run_command(:command => ("echo '" + ('☃' * 8096) + "'"))[1]
43
- snowy.encoding.should == Encoding.default_external
63
+ snowy.encoding.should == Encoding::UTF_8
44
64
  end
45
65
  end
46
66
 
@@ -0,0 +1,81 @@
1
+ #
2
+ # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
3
+ # Copyright:: Copyright (c) 2013 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
+
20
+ describe Ohai::System, "AIX cpu plugin" do
21
+ before(:each) do
22
+ @lsdev_Cc_processor = <<-LSDEV_CC_PROCESSOR
23
+ proc0 Available 00-00 Processor
24
+ proc4 Defined 00-04 Processor
25
+ LSDEV_CC_PROCESSOR
26
+
27
+ @lsattr_El_proc0 = <<-LSATTR_EL
28
+ frequency 1654344000 Processor Speed False
29
+ smt_enabled true Processor SMT enabled False
30
+ smt_threads 2 Processor SMT threads False
31
+ state enable Processor state False
32
+ type PowerPC_POWER5 Processor type False
33
+ LSATTR_EL
34
+ @ohai = Ohai::System.new
35
+ @ohai.stub!(:require_plugin).and_return(true)
36
+ @ohai[:os] = "aix"
37
+
38
+ @ohai.stub(:from).with("lsdev -Cc processor").and_return(@lsdev_Cc_processor)
39
+ @ohai.stub(:from).with("lsattr -El proc0").and_return(@lsattr_El_proc0)
40
+ @ohai._require_plugin("aix::cpu")
41
+ end
42
+
43
+
44
+ it "sets the vendor id to IBM" do
45
+ @ohai[:cpu][:vendor_id].should == "IBM"
46
+ end
47
+
48
+ it "sets the available attribute" do
49
+ @ohai[:cpu][:available].should == 1
50
+ end
51
+
52
+ it "sets the total number of devices" do
53
+ @ohai[:cpu][:total].should == 2
54
+ end
55
+
56
+ it "detects the model" do
57
+ @ohai[:cpu][:model].should == "PowerPC_POWER5"
58
+ end
59
+
60
+ it "detects the mhz" do
61
+ @ohai[:cpu][:mhz].should == 1615570
62
+ end
63
+
64
+ it "detects the status of the device" do
65
+ @ohai[:cpu][:proc0][:status].should == "Available"
66
+ end
67
+
68
+ it "detects the location of the device" do
69
+ @ohai[:cpu][:proc0][:location].should == "00-00"
70
+ end
71
+
72
+ context "lsattr -El device_name" do
73
+ it "detects all the attributes of the device" do
74
+ @ohai[:cpu][:proc0][:frequency].should == "1654344000"
75
+ @ohai[:cpu][:proc0][:smt_enabled].should == "true"
76
+ @ohai[:cpu][:proc0][:smt_threads].should == "2"
77
+ @ohai[:cpu][:proc0][:state].should == "enable"
78
+ @ohai[:cpu][:proc0][:type].should == "PowerPC_POWER5"
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,111 @@
1
+ #
2
+ # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
3
+ # Copyright:: Copyright (c) 2013 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
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
18
+
19
+ describe Ohai::System, "AIX filesystem plugin" do
20
+ before(:each) do
21
+ @df_P = <<-DF_P
22
+ Filesystem 512-blocks Used Available Capacity Mounted on
23
+ /dev/hd4 786432 495632 290800 64% /
24
+ /dev/hd2 10485760 8743200 1742560 84% /usr
25
+ /dev/hd9var 2621440 1152952 1468488 44% /var
26
+ /dev/hd3 2621440 541928 2079512 21% /tmp
27
+ /dev/hd1 8650752 6098080 2552672 71% /home
28
+ /dev/hd11admin 262144 760 261384 1% /admin
29
+ /proc - - - - /proc
30
+ /dev/hd10opt 3407872 1744384 1663488 52% /opt
31
+ 192.168.1.11:/stage/middleware 314572800 177025952 137546848 57% /stage/middleware
32
+ DF_P
33
+
34
+ @mount = <<-MOUNT
35
+ node mounted mounted over vfs date options
36
+ -------- --------------- --------------- ------ ------------ ---------------
37
+ /dev/hd4 / jfs2 Jul 17 13:22 rw,log=/dev/hd8
38
+ /dev/hd2 /usr jfs2 Jul 17 13:22 rw,log=/dev/hd8
39
+ /dev/hd9var /var jfs2 Jul 17 13:22 rw,log=/dev/hd8
40
+ /dev/hd3 /tmp jfs2 Jul 17 13:22 rw,log=/dev/hd8
41
+ /dev/hd1 /home jfs2 Jul 17 13:22 rw,log=/dev/hd8
42
+ /dev/hd11admin /admin jfs2 Jul 17 13:22 rw,log=/dev/hd8
43
+ /proc /proc procfs Jul 17 13:22 rw
44
+ /dev/hd10opt /opt jfs2 Jul 17 13:22 rw,log=/dev/hd8
45
+ 192.168.1.11 /stage/middleware /stage/middleware nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
46
+ MOUNT
47
+
48
+ @ohai = Ohai::System.new
49
+ @ohai.stub(:require_plugin).and_return(true)
50
+ @ohai[:filesystem] = Mash.new
51
+ @ohai.stub(:popen4).with("df -P").and_yield(nil, StringIO.new, StringIO.new(@df_P), nil)
52
+ @ohai.stub(:popen4).with("mount").and_yield(nil, StringIO.new, StringIO.new(@mount), nil)
53
+ @ohai._require_plugin("aix::filesystem")
54
+ end
55
+
56
+ describe "df -P" do
57
+
58
+ it "returns the filesystem block size" do
59
+ @ohai[:filesystem]["/dev/hd4"]['kb_size'].should == "786432"
60
+ end
61
+
62
+ it "returns the filesystem used space in kb" do
63
+ @ohai[:filesystem]["/dev/hd4"]['kb_used'].should == "495632"
64
+ end
65
+
66
+ it "returns the filesystem available space in kb" do
67
+ @ohai[:filesystem]["/dev/hd4"]['kb_available'].should == "290800"
68
+ end
69
+
70
+ it "returns the filesystem capacity in percentage" do
71
+ @ohai[:filesystem]["/dev/hd4"]['percent_used'].should == "64%"
72
+ end
73
+
74
+ it "returns the filesystem mounted location" do
75
+ @ohai[:filesystem]["/dev/hd4"]['mount'].should == "/"
76
+ end
77
+ end
78
+
79
+ describe "mount" do
80
+
81
+ it "returns the filesystem mount location" do
82
+ @ohai[:filesystem]["/dev/hd4"]['mount'].should == "/"
83
+ end
84
+
85
+ it "returns the filesystem type" do
86
+ @ohai[:filesystem]["/dev/hd4"]['fs_type'].should == "jfs2"
87
+ end
88
+
89
+ it "returns the filesystem mount options" do
90
+ @ohai[:filesystem]["/dev/hd4"]['mount_options'].should == "rw,log=/dev/hd8"
91
+ end
92
+
93
+ # For entries like 192.168.1.11 /stage/middleware /stage/middleware nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
94
+ context "having node values" do
95
+ before do
96
+ @ohai.stub(:popen4).with("mount").and_yield(nil, StringIO.new, StringIO.new("192.168.1.11 /stage/middleware /stage/middleware nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys"), nil)
97
+ end
98
+ it "returns the filesystem mount location" do
99
+ @ohai[:filesystem]["192.168.1.11:/stage/middleware"]['mount'].should == "/stage/middleware"
100
+ end
101
+
102
+ it "returns the filesystem type" do
103
+ @ohai[:filesystem]["192.168.1.11:/stage/middleware"]['fs_type'].should == "nfs3"
104
+ end
105
+
106
+ it "returns the filesystem mount options" do
107
+ @ohai[:filesystem]["192.168.1.11:/stage/middleware"]['mount_options'].should == "ro,bg,hard,intr,sec=sys"
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,28 @@
1
+ #
2
+ # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
3
+ # Copyright:: Copyright (c) 2013 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
+
20
+ describe Ohai::System, "Aix hostname plugin" do
21
+ before(:each) do
22
+ @ohai = Ohai::System.new
23
+ @ohai.stub(:from).with("hostname").and_return("aix_admin")
24
+ @ohai._require_plugin("aix::hostname")
25
+ end
26
+
27
+ it_should_check_from("aix::hostname", "hostname", "hostname", "aix_admin")
28
+ end
@@ -0,0 +1,51 @@
1
+ #
2
+ # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
3
+ # Copyright:: Copyright (c) 2013 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
+
20
+ describe Ohai::System, "AIX kernel plugin" do
21
+ before(:each) do
22
+ @ohai = Ohai::System.new
23
+ @ohai.stub(:from).with("uname -s").and_return("AIX")
24
+ @ohai.stub(:from).with("uname -r").and_return(1)
25
+ @ohai.stub(:from).with("uname -v").and_return(6)
26
+ @ohai.stub(:from).with("uname -p").and_return("powerpc")
27
+ @modules = Mash.new
28
+ @ohai[:kernel].stub(:modules).and_return(@modules)
29
+ @ohai._require_plugin("aix::kernel")
30
+ end
31
+
32
+ it "uname -s detects the name" do
33
+ @ohai[:kernel][:name].should == "aix"
34
+ end
35
+
36
+ it "uname -r detects the release" do
37
+ @ohai[:kernel][:release].should == 1
38
+ end
39
+
40
+ it "uname -v detects the version" do
41
+ @ohai[:kernel][:version].should == 6
42
+ end
43
+
44
+ it "uname -p detects the machine" do
45
+ @ohai[:kernel][:machine].should == "powerpc"
46
+ end
47
+
48
+ it "detects the modules" do
49
+ @ohai[:kernel][:modules].should == @modules
50
+ end
51
+ end
@@ -0,0 +1,258 @@
1
+ #
2
+ # Author:: Prabhu Das (<prabhu.das@clogeny.com>)
3
+ # Copyright:: Copyright (c) 2013 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
+
20
+ describe Ohai::System, "AIX network plugin" do
21
+
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
34
+
35
+ @lsdev_Cc_if = <<-LSDEV_CC_IF
36
+ en0 Available Standard Ethernet Network Interface
37
+ LSDEV_CC_IF
38
+
39
+ @ifconfig_en0 = <<-IFCONFIG_EN0
40
+ en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN> metric 1
41
+ inet 172.29.174.58 netmask 0xffffc000 broadcast 172.29.191.255
42
+ inet 172.29.174.59 broadcast 172.29.191.255
43
+ inet 172.29.174.60 netmask 0xffffc000 broadcast 172.29.191.255
44
+ inet6 ::1%1/0
45
+ tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
46
+ IFCONFIG_EN0
47
+
48
+ @netstat_nrf_inet = <<-NETSTAT_NRF_INET
49
+ Destination Gateway Flags Refs Use If Exp Groups
50
+ Route Tree for Protocol Family 2 (Internet):
51
+ default 172.29.128.13 UG 0 587683 en0 - -
52
+ 172.29.128.0 172.29.174.58 UHSb 0 0 en0 - - =>
53
+ 172.29.128/18 172.29.174.58 U 7 1035485 en0 - -
54
+ 172.29.191.255 172.29.174.58 UHSb 0 1 en0 - -
55
+ NETSTAT_NRF_INET
56
+
57
+ @aix_arp_an = <<-ARP_AN
58
+ ? (172.29.131.16) at 6e:87:70:0:40:3 [ethernet] stored in bucket 16
59
+
60
+ ? (10.153.50.202) at 34:40:b5:ab:fb:5a [ethernet] stored in bucket 40
61
+
62
+ ? (10.153.1.99) at 52:54:0:8e:f2:fb [ethernet] stored in bucket 58
63
+
64
+ ? (172.29.132.250) at 34:40:b5:a5:d7:1e [ethernet] stored in bucket 59
65
+
66
+ ? (172.29.132.253) at 34:40:b5:a5:d7:2a [ethernet] stored in bucket 62
67
+
68
+ ? (172.29.128.13) at 60:73:5c:69:42:44 [ethernet] stored in bucket 139
69
+
70
+ bucket: 0 contains: 0 entries
71
+ There are 6 entries in the arp table.
72
+ ARP_AN
73
+
74
+ @ohai = Ohai::System.new
75
+ @ohai.stub(:require_plugin).and_return(true)
76
+ @ohai[:network] = Mash.new
77
+ @ohai.stub(:popen4).with("route -n get 0").and_yield(nil, StringIO.new, StringIO.new(@route_n_get_0), nil)
78
+ @ohai.stub(:popen4).with("lsdev -Cc if").and_yield(nil, StringIO.new, StringIO.new(@lsdev_Cc_if), nil)
79
+ @ohai.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new(@ifconfig_en0), nil)
80
+ @ohai.stub(:popen4).with("entstat -d en0 | grep \"Hardware Address\"").and_yield(nil, StringIO.new, StringIO.new("Hardware Address: be:42:80:00:b0:05"), nil)
81
+ @ohai.stub(:popen4).with("netstat -nrf inet").and_yield(nil, StringIO.new, StringIO.new(@netstat_nrf_inet), nil)
82
+ @ohai.stub(:popen4).with("netstat -nrf inet6").and_yield(nil, StringIO.new, StringIO.new("::1%1 ::1%1 UH 1 109392 en0 - -"), nil)
83
+ @ohai.stub(:popen4).with("arp -an").and_yield(nil, StringIO.new, StringIO.new(@aix_arp_an), nil)
84
+ @ohai._require_plugin("aix::network")
85
+ end
86
+
87
+ describe "run" do
88
+
89
+ it "detects network information" do
90
+ @ohai['network'].should_not be_nil
91
+ end
92
+
93
+ it "detects the interfaces" do
94
+ @ohai['network']['interfaces'].keys.sort.should == ["en0"]
95
+ end
96
+
97
+ it "detects the ip addresses of the interfaces" do
98
+ @ohai['network']['interfaces']['en0']['addresses'].keys.should include('172.29.174.58')
99
+ end
100
+ end
101
+
102
+ describe "route -n get 0" do
103
+
104
+ it "returns the default gateway of the system's network" do
105
+ @ohai[:network][:default_gateway].should == '172.29.128.13'
106
+ end
107
+
108
+ it "returns the default interface of the system's network" do
109
+ @ohai[:network][:default_interface].should == 'en0'
110
+ end
111
+ end
112
+
113
+ describe "lsdev -Cc if" do
114
+
115
+ it "detects the state of the interfaces in the system" do
116
+ @ohai['network']['interfaces']['en0'][:state].should == "up"
117
+ end
118
+
119
+ it "detects the description of the interfaces in the system" do
120
+ @ohai['network']['interfaces']['en0'][:description].should == "Standard Ethernet Network Interface"
121
+ end
122
+
123
+ describe "ifconfig interface" do
124
+ it "detects the CHAIN network flag" do
125
+ @ohai['network']['interfaces']['en0'][:flags].should include('CHAIN')
126
+ end
127
+
128
+ it "detects the metric network flag" do
129
+ @ohai['network']['interfaces']['en0'][:metric].should == '1'
130
+ end
131
+
132
+ context "inet entries" do
133
+ before do
134
+ @inet_entry = @ohai['network']['interfaces']['en0'][:addresses]["172.29.174.58"]
135
+ end
136
+ it "detects the family" do
137
+ @inet_entry[:family].should == 'inet'
138
+ end
139
+
140
+ it "detects the netmask" do
141
+ @inet_entry[:netmask].should == '255.255.192.0'
142
+ end
143
+
144
+ it "detects the broadcast" do
145
+ @inet_entry[:broadcast].should == '172.29.191.255'
146
+ end
147
+
148
+ it "detects all key-values" do
149
+ @ohai['network']['interfaces']['en0'][:tcp_sendspace].should == "262144"
150
+ @ohai['network']['interfaces']['en0'][:tcp_recvspace].should == "262144"
151
+ @ohai['network']['interfaces']['en0'][:rfc1323].should == "1"
152
+ end
153
+
154
+ # For an output with no netmask like inet 172.29.174.59 broadcast 172.29.191.255
155
+ context "with no netmask in the output" do
156
+ before do
157
+ @inet_entry = @ohai['network']['interfaces']['en0'][:addresses]["172.29.174.59"]
158
+ @ohai.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new("inet 172.29.174.59 broadcast 172.29.191.255"), nil)
159
+ end
160
+
161
+ it "detects the default prefixlen" do
162
+ @inet_entry[:prefixlen].should == '32'
163
+ end
164
+
165
+ it "detects the default netmask" do
166
+ @inet_entry[:netmask].should == '255.255.255.255'
167
+ end
168
+ end
169
+ end
170
+
171
+ context "inet6 entries" do
172
+ before do
173
+ @inet_entry = @ohai['network']['interfaces']['en0'][:addresses]["::1%1"]
174
+ @ohai.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new("inet6 ::1%1/0"), nil)
175
+ end
176
+
177
+ it "detects the prefixlen" do
178
+ @inet_entry[:prefixlen].should == '0'
179
+ end
180
+
181
+ it "detects the family" do
182
+ @inet_entry[:family].should == 'inet6'
183
+ end
184
+ end
185
+ end
186
+
187
+ context "entstat -d interface" do
188
+ before do
189
+ @inet_interface_addresses = @ohai['network']['interfaces']['en0'][:addresses]["BE:42:80:00:B0:05"]
190
+ end
191
+ it "detects the family" do
192
+ @inet_interface_addresses[:family].should == 'lladdr'
193
+ end
194
+ end
195
+ end
196
+
197
+ describe "netstat -nrf family" do
198
+ context "inet" do
199
+
200
+ it "detects the route destinations" do
201
+ @ohai['network']['interfaces']['en0'][:routes][0][:destination].should == "default"
202
+ @ohai['network']['interfaces']['en0'][:routes][1][:destination].should == "172.29.128.0"
203
+ end
204
+
205
+ it "detects the route family" do
206
+ @ohai['network']['interfaces']['en0'][:routes][0][:family].should == "inet"
207
+ end
208
+
209
+ it "detects the route gateway" do
210
+ @ohai['network']['interfaces']['en0'][:routes][0][:via].should == "172.29.128.13"
211
+ end
212
+
213
+ it "detects the route flags" do
214
+ @ohai['network']['interfaces']['en0'][:routes][0][:flags].should == "UG"
215
+ end
216
+ end
217
+
218
+ context "inet6" do
219
+
220
+ it "detects the route destinations" do
221
+ @ohai['network']['interfaces']['en0'][:routes][4][:destination].should == "::1%1"
222
+ end
223
+
224
+ it "detects the route family" do
225
+ @ohai['network']['interfaces']['en0'][:routes][4][:family].should == "inet6"
226
+ end
227
+
228
+ it "detects the route gateway" do
229
+ @ohai['network']['interfaces']['en0'][:routes][4][:via].should == "::1%1"
230
+ end
231
+
232
+ it "detects the route flags" do
233
+ @ohai['network']['interfaces']['en0'][:routes][4][:flags].should == "UH"
234
+ end
235
+ end
236
+ end
237
+
238
+ describe "arp -an" do
239
+
240
+ it "supresses the hostname entries" do
241
+ @ohai['network']['arp'][0][:remote_host].should == "?"
242
+ end
243
+
244
+ it "detects the remote ip entry" do
245
+ @ohai['network']['arp'][0][:remote_ip].should == "172.29.131.16"
246
+ end
247
+
248
+ it "detects the remote mac entry" do
249
+ @ohai['network']['arp'][0][:remote_mac].should == "6e:87:70:0:40:3"
250
+ end
251
+ end
252
+
253
+ describe "hex_to_dec_netmask method" do
254
+ it "converts a netmask from hexadecimal form to decimal form" do
255
+ @ohai.hex_to_dec_netmask('0xffff0000').should == "255.255.0.0"
256
+ end
257
+ end
258
+ end