diff options
-rw-r--r-- | lib/ohai/plugins/aix/filesystem.rb | 8 | ||||
-rw-r--r-- | spec/unit/plugins/aix/filesystem_spec.rb | 117 | ||||
-rw-r--r-- | spec/unit/plugins/aix/network_spec.rb | 252 |
3 files changed, 373 insertions, 4 deletions
diff --git a/lib/ohai/plugins/aix/filesystem.rb b/lib/ohai/plugins/aix/filesystem.rb index d590a326..785a6b93 100644 --- a/lib/ohai/plugins/aix/filesystem.rb +++ b/lib/ohai/plugins/aix/filesystem.rb @@ -50,7 +50,7 @@ popen4("mount") do |pid, stdin, stdout, stderr| when /^\s*---/ next when /^\s*\/\w/ - fields = line.split(" ") + fields = line.split filesystem = fields[0] fs[filesystem] = Mash.new unless fs.has_key?(filesystem) fs[filesystem][:mount] = fields[1] @@ -58,11 +58,11 @@ popen4("mount") do |pid, stdin, stdout, stderr| #fs[filesystem][:mount_options] = fields[6] fs[filesystem][:mount_options] = fields[6] else - fields = line.split(" ") + fields = line.split filesystem = fields[0] + ":" + fields[1] fs[filesystem] = Mash.new unless fs.has_key?(filesystem) - fs[filesystem][:mount] = fields[3] - fs[filesystem][:fs_type] = fields[4] + fs[filesystem][:mount] = fields[2] + fs[filesystem][:fs_type] = fields[3] fs[filesystem][:mount_options] = fields[7] end end diff --git a/spec/unit/plugins/aix/filesystem_spec.rb b/spec/unit/plugins/aix/filesystem_spec.rb new file mode 100644 index 00000000..58a88240 --- /dev/null +++ b/spec/unit/plugins/aix/filesystem_spec.rb @@ -0,0 +1,117 @@ +# +# Author:: Prabhu Das (<prabhu.das@clogeny.com>) +# Copyright:: Copyright (c) 2013 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') + +describe Ohai::System, "AIX filesystem plugin" do + before do + @df_P = <<-DF_P +Filesystem 512-blocks Used Available Capacity Mounted on +/dev/hd4 786432 495632 290800 64% / +/dev/hd2 10485760 8743200 1742560 84% /usr +/dev/hd9var 2621440 1152952 1468488 44% /var +/dev/hd3 2621440 541928 2079512 21% /tmp +/dev/hd1 8650752 6098080 2552672 71% /home +/dev/hd11admin 262144 760 261384 1% /admin +/proc - - - - /proc +/dev/hd10opt 3407872 1744384 1663488 52% /opt +192.168.1.11:/stage/middleware 314572800 177025952 137546848 57% /stage/middleware +DF_P + + @mount = <<-MOUNT + node mounted mounted over vfs date options +-------- --------------- --------------- ------ ------------ --------------- + /dev/hd4 / jfs2 Jul 17 13:22 rw,log=/dev/hd8 + /dev/hd2 /usr jfs2 Jul 17 13:22 rw,log=/dev/hd8 + /dev/hd9var /var jfs2 Jul 17 13:22 rw,log=/dev/hd8 + /dev/hd3 /tmp jfs2 Jul 17 13:22 rw,log=/dev/hd8 + /dev/hd1 /home jfs2 Jul 17 13:22 rw,log=/dev/hd8 + /dev/hd11admin /admin jfs2 Jul 17 13:22 rw,log=/dev/hd8 + /proc /proc procfs Jul 17 13:22 rw + /dev/hd10opt /opt jfs2 Jul 17 13:22 rw,log=/dev/hd8 +192.168.1.11 /stage/middleware /stage/middleware nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys +MOUNT + + @ohai = Ohai::System.new + @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("aix/filesystem.rb", PLUGIN_PATH)) + @plugin.stub(:require_plugin).and_return(true) + @plugin[:filesystem] = Mash.new + @plugin.stub(:popen4).with("df -P").and_yield(nil, StringIO.new, StringIO.new(@df_P), nil) + @plugin.stub(:popen4).with("mount").and_yield(nil, StringIO.new, StringIO.new(@mount), nil) + end + + describe "df -P" do + before do + @plugin.run + end + + it "returns the filesystem block size" do + @plugin[:filesystem]["/dev/hd4"]['kb_size'].should == "786432" + end + + it "returns the filesystem used space in kb" do + @plugin[:filesystem]["/dev/hd4"]['kb_used'].should == "495632" + end + + it "returns the filesystem available space in kb" do + @plugin[:filesystem]["/dev/hd4"]['kb_available'].should == "290800" + end + + it "returns the filesystem capacity in percentage" do + @plugin[:filesystem]["/dev/hd4"]['percent_used'].should == "64%" + end + + it "returns the filesystem mounted location" do + @plugin[:filesystem]["/dev/hd4"]['mount'].should == "/" + end + end + + describe "mount" do + before do + @plugin.run + end + + it "returns the filesystem mount location" do + @plugin[:filesystem]["/dev/hd4"]['mount'].should == "/" + end + + it "returns the filesystem type" do + @plugin[:filesystem]["/dev/hd4"]['fs_type'].should == "jfs2" + end + + it "returns the filesystem mount options" do + @plugin[:filesystem]["/dev/hd4"]['mount_options'].should == "rw,log=/dev/hd8" + end + + # For entries like 192.168.1.11 /stage/middleware /stage/middleware nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys + context "having node values" do + before do + @plugin.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) + end + it "returns the filesystem mount location" do + @plugin[:filesystem]["192.168.1.11:/stage/middleware"]['mount'].should == "/stage/middleware" + end + + it "returns the filesystem type" do + @plugin[:filesystem]["192.168.1.11:/stage/middleware"]['fs_type'].should == "nfs3" + end + + it "returns the filesystem mount options" do + @plugin[:filesystem]["192.168.1.11:/stage/middleware"]['mount_options'].should == "ro,bg,hard,intr,sec=sys" + end + end + end +end diff --git a/spec/unit/plugins/aix/network_spec.rb b/spec/unit/plugins/aix/network_spec.rb new file mode 100644 index 00000000..d602575a --- /dev/null +++ b/spec/unit/plugins/aix/network_spec.rb @@ -0,0 +1,252 @@ +# +# Author:: Prabhu Das (<prabhu.das@clogeny.com>) +# Copyright:: Copyright (c) 2013 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') + +describe Ohai::System, "AIX network plugin" do + + before do + @route_n_get_0 = <<-ROUTE_N_GET_0 + route to: default +destination: default + mask: default + gateway: 172.29.128.13 + interface: en0 +interf addr: 172.29.174.58 + flags: <UP,GATEWAY,DONE> + recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire + 0 0 0 0 0 0 0 -79 +ROUTE_N_GET_0 + + @lsdev_Cc_if = <<-LSDEV_CC_IF +en0 Available Standard Ethernet Network Interface +LSDEV_CC_IF + + @ifconfig_en0 = <<-IFCONFIG_EN0 +en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN> metric 1 + inet 172.29.174.58 netmask 0xffffc000 broadcast 172.29.191.255 + inet 172.29.174.59 broadcast 172.29.191.255 + inet 172.29.174.60 netmask 0xffffc000 broadcast 172.29.191.255 + inet6 ::1%1/0 + tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1 +IFCONFIG_EN0 + + @netstat_nrf_inet = <<-NETSTAT_NRF_INET +Destination Gateway Flags Refs Use If Exp Groups +Route Tree for Protocol Family 2 (Internet): +default 172.29.128.13 UG 0 587683 en0 - - +172.29.128.0 172.29.174.58 UHSb 0 0 en0 - - => +172.29.128/18 172.29.174.58 U 7 1035485 en0 - - +172.29.191.255 172.29.174.58 UHSb 0 1 en0 - - +NETSTAT_NRF_INET + + @aix_arp_an = <<-ARP_AN + ? (172.29.131.16) at 6e:87:70:0:40:3 [ethernet] stored in bucket 16 + + ? (10.153.50.202) at 34:40:b5:ab:fb:5a [ethernet] stored in bucket 40 + + ? (10.153.1.99) at 52:54:0:8e:f2:fb [ethernet] stored in bucket 58 + + ? (172.29.132.250) at 34:40:b5:a5:d7:1e [ethernet] stored in bucket 59 + + ? (172.29.132.253) at 34:40:b5:a5:d7:2a [ethernet] stored in bucket 62 + + ? (172.29.128.13) at 60:73:5c:69:42:44 [ethernet] stored in bucket 139 + +bucket: 0 contains: 0 entries +There are 6 entries in the arp table. +ARP_AN + + @ohai = Ohai::System.new + @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("aix/network.rb", PLUGIN_PATH)) + @plugin.stub(:require_plugin).and_return(true) + @plugin[:network] = Mash.new + @plugin.stub(:popen4).with("route -n get 0").and_yield(nil, StringIO.new, StringIO.new(@route_n_get_0), nil) + @plugin.stub(:popen4).with("lsdev -Cc if").and_yield(nil, StringIO.new, StringIO.new(@lsdev_Cc_if), nil) + @plugin.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new(@ifconfig_en0), nil) + @plugin.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) + %w{inet inet6}.each { |i| @plugin.stub(:popen4).with("netstat -nrf #{i}").and_yield(nil, StringIO.new, StringIO.new(@netstat_nrf_inet), nil)} + @plugin.stub(:popen4).with("arp -an").and_yield(nil, StringIO.new, StringIO.new(@aix_arp_an), nil) + end + + describe "run" do + before(:each) do + @plugin.run + end + + it "detects network information" do + @plugin['network'].should_not be_nil + end + + it "detects the interfaces" do + @plugin['network']['interfaces'].keys.sort.should == ["en0"] + end + + it "detects the ip addresses of the interfaces" do + @plugin['network']['interfaces']['en0']['addresses'].keys.should include('172.29.174.58') + end + end + + describe "route -n get 0" do + before do + @plugin.run + end + + it "returns the default gateway of the system's network" do + @plugin[:network][:default_gateway].should == '172.29.128.13' + end + + it "returns the default interface of the system's network" do + @plugin[:network][:default_interface].should == 'en0' + end + end + + describe "lsdev -Cc if" do + before do + @plugin.run + end + + it "detects the state of the interfaces in the system" do + @plugin['network']['interfaces']['en0'][:state].should == "up" + end + + it "detects the description of the interfaces in the system" do + @plugin['network']['interfaces']['en0'][:description].should == "Standard Ethernet Network Interface" + end + + describe "ifconfig interface" do + it "detects the CHAIN network flag" do + @plugin['network']['interfaces']['en0'][:flags].should include('CHAIN') + end + + it "detects the metric network flag" do + @plugin['network']['interfaces']['en0'][:metric].should == '1' + end + + context "inet entries" do + before do + @inet_entry = @plugin['network']['interfaces']['en0'][:addresses]["172.29.174.58"] + end + it "detects the family" do + @inet_entry[:family].should == 'inet' + end + + it "detects the netmask" do + @inet_entry[:netmask].should == '255.255.192.0' + end + + it "detects the broadcast" do + @inet_entry[:broadcast].should == '172.29.191.255' + end + + it "detects all key-values" do + @plugin['network']['interfaces']['en0'][:tcp_sendspace].should == "262144" + @plugin['network']['interfaces']['en0'][:tcp_recvspace].should == "262144" + @plugin['network']['interfaces']['en0'][:rfc1323].should == "1" + end + + # For an output with no netmask like inet 172.29.174.59 broadcast 172.29.191.255 + context "with no netmask in the output" do + before do + @inet_entry = @plugin['network']['interfaces']['en0'][:addresses]["172.29.174.59"] + @plugin.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new("inet 172.29.174.59 broadcast 172.29.191.255"), nil) + end + + it "detects the default prefixlen" do + @inet_entry[:prefixlen].should == '32' + end + + it "detects the default netmask" do + @inet_entry[:netmask].should == '255.255.255.255' + end + end + end + + context "inet6 entries" do + before do + @inet_entry = @plugin['network']['interfaces']['en0'][:addresses]["::1%1"] + @plugin.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new("inet6 ::1%1/0"), nil) + end + + it "detects the prefixlen" do + @inet_entry[:prefixlen].should == '0' + end + + it "detects the family" do + @inet_entry[:family].should == 'inet6' + end + end + end + + context "entstat -d interface" do + before do + @inet_interface_addresses = @plugin['network']['interfaces']['en0'][:addresses]["BE:42:80:00:B0:05"] + end + it "detects the family" do + @inet_interface_addresses[:family].should == 'lladdr' + end + end + end + + describe "netstat -nrf family" do + before do + @plugin.run + end + + it "detects the route destinations" do + @plugin['network']['interfaces']['en0'][:routes][0][:destination].should == "default" + @plugin['network']['interfaces']['en0'][:routes][1][:destination].should == "172.29.128.0" + end + + it "detects the route family" do + @plugin['network']['interfaces']['en0'][:routes][0][:family].should == "inet" + end + + it "detects the route gateway" do + @plugin['network']['interfaces']['en0'][:routes][0][:via].should == "172.29.128.13" + end + + it "detects the route flags" do + @plugin['network']['interfaces']['en0'][:routes][0][:flags].should == "UG" + end + end + + describe "arp -an" do + before do + @plugin.run + end + + it "supresses the hostname entries" do + @plugin['network']['arp'][0][:remote_host].should == "?" + end + + it "detects the remote ip entry" do + @plugin['network']['arp'][0][:remote_ip].should == "172.29.131.16" + end + + it "detects the remote mac entry" do + @plugin['network']['arp'][0][:remote_mac].should == "6e:87:70:0:40:3" + end + end + + describe "hex_to_dec_netmask method" do + it "converts a netmask from hexadecimal form to decimal form" do + @plugin.run + @plugin.hex_to_dec_netmask('0xffff0000').should == "255.255.0.0" + end + end +end |