diff options
author | Adam Edwards <adamed@opscode.com> | 2013-09-29 23:40:14 -0700 |
---|---|---|
committer | Adam Edwards <adamed@opscode.com> | 2013-09-29 23:40:14 -0700 |
commit | ce9a3a42b8f326445ae19134476428493b5711bc (patch) | |
tree | cca495214ca66ca3ca1df7d2a2e204a44f18325d | |
parent | 87042c00beb7e1563310d8d208a93216f89e5134 (diff) | |
parent | f6e9e57d38c0323100dcab9700ee31d3ab188c9d (diff) | |
download | ohai-ce9a3a42b8f326445ae19134476428493b5711bc.tar.gz |
Merge pull request #207 from opscode/adamed-OC-9106-re-merge
OC-9106 AIX Ohai changes re-merge
-rw-r--r-- | lib/ohai/plugins/aix/cpu.rb | 36 | ||||
-rw-r--r-- | lib/ohai/plugins/aix/filesystem.rb | 60 | ||||
-rw-r--r-- | lib/ohai/plugins/aix/hostname.rb | 4 | ||||
-rw-r--r-- | lib/ohai/plugins/aix/kernel.rb | 27 | ||||
-rw-r--r-- | lib/ohai/plugins/aix/memory.rb | 11 | ||||
-rw-r--r-- | lib/ohai/plugins/aix/network.rb | 142 | ||||
-rw-r--r-- | lib/ohai/plugins/aix/platform.rb | 12 | ||||
-rw-r--r-- | lib/ohai/plugins/aix/uptime.rb | 21 | ||||
-rw-r--r-- | spec/unit/plugins/aix/cpu_spec.rb | 81 | ||||
-rw-r--r-- | spec/unit/plugins/aix/filesystem_spec.rb | 111 | ||||
-rw-r--r-- | spec/unit/plugins/aix/hostname_spec.rb | 28 | ||||
-rw-r--r-- | spec/unit/plugins/aix/kernel_spec.rb | 51 | ||||
-rw-r--r-- | spec/unit/plugins/aix/network_spec.rb | 258 | ||||
-rw-r--r-- | spec/unit/plugins/aix/platform_spec.rb | 42 | ||||
-rw-r--r-- | spec/unit/plugins/aix/uptime_spec.rb | 40 |
15 files changed, 905 insertions, 19 deletions
diff --git a/lib/ohai/plugins/aix/cpu.rb b/lib/ohai/plugins/aix/cpu.rb index 32b2dc91..3c1af9ce 100644 --- a/lib/ohai/plugins/aix/cpu.rb +++ b/lib/ohai/plugins/aix/cpu.rb @@ -1,6 +1,7 @@ # -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, Inc. +# Author:: Joshua Timberman <joshua@opscode.com> +# 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"); @@ -16,4 +17,33 @@ # limitations under the License. # -require_plugin "sigar::cpu" +provides "cpu" + +cpu Mash.new + +# IBM is the only maker of CPUs for AIX systems. +cpu[:vendor_id] = "IBM" +# At least one CPU will be available, but we'll wait to increment this later. +cpu[:available] = 0 +cpu[:total] = 0 + +cpudevs = from("lsdev -Cc processor").lines +cpudevs.each do |c| + cpu[:total] += 1 + name, status, location = c.split + cpu[name] = Mash.new + cpu[name][:status] = status + cpu[name][:location] = location + if status =~ /Available/ + cpu[:available] += 1 + lsattr = from("lsattr -El #{name}").lines + lsattr.each do |attribute| + attrib, value = attribute.split + cpu[name][attrib] = value + end + end +end + +# Every AIX system has proc0. +cpu[:model] = cpu[:proc0][:type] +cpu[:mhz] = cpu[:proc0][:frequency].to_i / 1024 diff --git a/lib/ohai/plugins/aix/filesystem.rb b/lib/ohai/plugins/aix/filesystem.rb index 8322ee0b..785a6b93 100644 --- a/lib/ohai/plugins/aix/filesystem.rb +++ b/lib/ohai/plugins/aix/filesystem.rb @@ -1,6 +1,7 @@ # -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, Inc. +# Author:: Deepali Jagtap (<deepali.jagtap@clogeny.com>) +# 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"); @@ -16,4 +17,57 @@ # limitations under the License. # -require_plugin "sigar::filesystem" +provides "filesystem" + +fs = Mash.new + +# Grab filesystem data from df +popen4("df -P") do |pid, stdin, stdout, stderr| + stdin.close + stdout.each do |line| + case line + when /^Filesystem\s+1024-blocks/ + next + when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ + filesystem = $1 + fs[filesystem] = Mash.new + fs[filesystem][:kb_size] = $2 + fs[filesystem][:kb_used] = $3 + fs[filesystem][:kb_available] = $4 + fs[filesystem][:percent_used] = $5 + fs[filesystem][:mount] = $6 + end + end +end + +# Grab mount information from /bin/mount +popen4("mount") do |pid, stdin, stdout, stderr| + stdin.close + stdout.each do |line| + case line + when /^\s*node/ + next + when /^\s*---/ + next + when /^\s*\/\w/ + fields = line.split + filesystem = fields[0] + fs[filesystem] = Mash.new unless fs.has_key?(filesystem) + fs[filesystem][:mount] = fields[1] + fs[filesystem][:fs_type] = fields[2] + #fs[filesystem][:mount_options] = fields[6] + fs[filesystem][:mount_options] = fields[6] + else + fields = line.split + filesystem = fields[0] + ":" + fields[1] + fs[filesystem] = Mash.new unless fs.has_key?(filesystem) + fs[filesystem][:mount] = fields[2] + fs[filesystem][:fs_type] = fields[3] + fs[filesystem][:mount_options] = fields[7] + end + end +end + +# Set the filesystem data +filesystem fs + diff --git a/lib/ohai/plugins/aix/hostname.rb b/lib/ohai/plugins/aix/hostname.rb index 805b4734..4cf25ba8 100644 --- a/lib/ohai/plugins/aix/hostname.rb +++ b/lib/ohai/plugins/aix/hostname.rb @@ -16,4 +16,6 @@ # limitations under the License. # -require_plugin "sigar::hostname" +provides "hostname" + +hostname from("hostname") diff --git a/lib/ohai/plugins/aix/kernel.rb b/lib/ohai/plugins/aix/kernel.rb new file mode 100644 index 00000000..e76e6e35 --- /dev/null +++ b/lib/ohai/plugins/aix/kernel.rb @@ -0,0 +1,27 @@ +# +# Author:: Joshua Timberman <joshua@opscode.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. +# + +provides "kernel" + +kernel Mash.new + +kernel[:name] = from("uname -s").downcase +kernel[:release] = from("uname -r") +kernel[:version] = from("uname -v") +kernel[:machine] = from("uname -p") +kernel[:modules] = Mash.new diff --git a/lib/ohai/plugins/aix/memory.rb b/lib/ohai/plugins/aix/memory.rb index dd3532fb..88f1c5b8 100644 --- a/lib/ohai/plugins/aix/memory.rb +++ b/lib/ohai/plugins/aix/memory.rb @@ -1,6 +1,6 @@ # -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, Inc. +# Author:: Joshua Timberman <joshua@opscode.com> +# Copyright:: Copyright (c) 2013, Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,4 +16,9 @@ # limitations under the License. # -require_plugin "sigar::memory" +provides "memory" + +memory = Mash.new + +meminfo = from("svmon -G -O unit=MB,summary=longreal | grep '[0-9]'") +memory[:total], u, memory[:free] = meminfo.split diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb index 7071abef..052d2504 100644 --- a/lib/ohai/plugins/aix/network.rb +++ b/lib/ohai/plugins/aix/network.rb @@ -1,6 +1,7 @@ # -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, Inc. +# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>) +# 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"); @@ -16,4 +17,139 @@ # limitations under the License. # -require_plugin "sigar::network" +require 'ipaddr' +provides "network", "counters/network" + +# Loads following information. +# :default_interface, :default_gateway - route -n get 0 +# :interfaces +# => routes(netstat -nr | grep en0) +# => addresses (ifconfig en0 or lsattr -El en0), macaddress (entstat -d en0 = Hardware Address: be:42:80:00:b0:05) +# => flags (ifconfig en0) +# => state up/down (ifconfig/lsattr) +# => arp (arp -an) + +iface = Mash.new + + +# :default_interface, :default_gateway - route -n get 0 +popen4("route -n get 0") do |pid, stdin, stdout, stderr| + stdin.close + stdout.each do |line| + case line + when /gateway: (\S+)/ + network[:default_gateway] = $1 + when /interface: (\S+)/ + network[:default_interface] = $1 + end + end +end + +# Helpers +def hex_to_dec_netmask(netmask) + # example '0xffff0000' -> '255.255.0.0' + dec = netmask[2..3].to_i(16).to_s(10) + [4,6,8].each { |n| dec = dec + "." + netmask[n..n+1].to_i(16).to_s(10) } + dec +end + +# List the interfaces in system. +popen4("lsdev -Cc if") do |pid, stdin, stdout, stderr| + stdin.close + stdout.each do |line| + if line =~ /(\S+) (\S+)\s+(.+)/ + interface = $1 + iface[interface] = Mash.new unless iface[interface] + iface[interface][:state] = ($2 == 'Available' ? 'up' : 'down') + iface[interface][:description] = $3 + + # Query the interface information + popen4("ifconfig #{interface}") do |if_pid, if_stdin, if_stdout, if_stderr| + if_stdin.close + if_stdout.each do |line| + case line + when /^#{interface}:\sflags=\S+<(\S+)>/ + iface[interface][:flags] = $1.split(',') + iface[interface][:metric] = $1 if line =~ /metric\s(\S+)/ + else + # We have key value pairs. + if line =~ /inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/(\d{1,2}))?/ + tmp_addr, tmp_prefix = $1, $3 + if tmp_prefix.nil? + netmask = hex_to_dec_netmask($1) if line =~ /netmask\s(\S+)\s/ + unless netmask + tmp_prefix ||= "32" + netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s + end + else + netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s + end + + iface[interface][:addresses] = Mash.new unless iface[interface][:addresses] + iface[interface][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix } + iface[interface][:addresses][tmp_addr][:netmask] = netmask + + if line =~ /broadcast\s(\S+)\s/ + iface[interface][:addresses][tmp_addr][:broadcast] = $1 + end + elsif line =~ /inet6 ([a-f0-9\:%]+)\/(\d+)/ + # TODO do we have more properties on inet6 in aix? broadcast + iface[interface][:addresses] = Mash.new unless iface[interface][:addresses] + iface[interface][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2 } + else + # load all key-values, example "tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1" + properties = line.split + n = properties.length/2 - 1 + (0..n).each do |i| + iface[interface][properties[i*2]] = properties[(i*2+1)] + end + end + end + end + end #ifconfig stdout + + # Query macaddress + popen4("entstat -d #{interface} | grep \"Hardware Address\"") do |e_pid, e_stdin, e_stdout, e_stderr| + e_stdin.close + iface[interface][:addresses] = Mash.new unless iface[interface][:addresses] + e_stdout.each do |line| + iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" } if line =~ /Hardware Address: (\S+)/ + end + end + end + end #lsdev stdout +end + +# Query routes information +%w{inet inet6}.each do |family| + popen4("netstat -nrf #{family}") do |n_pid, n_stdin, n_stdout, n_stderr| + n_stdin.close + n_stdout.each do |line| + if line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)/ + interface = $6 + iface[interface][:routes] = Array.new unless iface[interface][:routes] + iface[interface][:routes] << Mash.new( :destination => $1, :family => family, + :via => $2, :flags => $3) + end + end + end +end + +# List the arp entries in system. +popen4("arp -an") do |pid, stdin, stdout, stderr| + stdin.close + count = 0 + stdout.each do |line| + network[:arp] = Mash.new unless network[:arp] + if line =~ /\s*(\S+) \((\S+)\) at ([a-fA-F0-9\:]+) \[(\w+)\] stored in bucket/ + network[:arp][count] = Mash.new unless network[:arp][count] + network[:arp][count][:remote_host] = $1 + network[:arp][count][:remote_ip] = $2 + network[:arp][count][:remote_mac] = $3.downcase + count += 1 + end + end +end + +network["interfaces"] = iface + diff --git a/lib/ohai/plugins/aix/platform.rb b/lib/ohai/plugins/aix/platform.rb index bea329d6..5f29c2fd 100644 --- a/lib/ohai/plugins/aix/platform.rb +++ b/lib/ohai/plugins/aix/platform.rb @@ -1,6 +1,6 @@ # -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, Inc. +# Author:: Joshua Timberman <joshua@opscode.com> +# Copyright:: Copyright (c) 2013, Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,4 +16,10 @@ # limitations under the License. # -require_plugin "sigar::platform" +require_plugin "#{os}::kernel" + +provides "platform", "platform_version", "platform_family" + +platform kernel[:name] +platform_version [kernel[:version], kernel[:release]].join(".") +platform_family platform diff --git a/lib/ohai/plugins/aix/uptime.rb b/lib/ohai/plugins/aix/uptime.rb index 23aa89f3..a45f2c26 100644 --- a/lib/ohai/plugins/aix/uptime.rb +++ b/lib/ohai/plugins/aix/uptime.rb @@ -1,6 +1,6 @@ # -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, Inc. +# Author:: Kurt Yoder (<ktyopscode@yoderhome.com>) +# Copyright:: Copyright (c) 2013 Opscode, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,5 +15,20 @@ # See the License for the specific language governing permissions and # limitations under the License. # +require 'date' -require_plugin "sigar::uptime" +provides "uptime", "uptime_seconds" + +# Example output: +# $ who -b +# . system boot Jul 9 17:51 +popen4('who -b') do |pid, stdin, stdout, stderr| + stdin.close + stdout.each do |line| + if line =~ /.* boot (.+)/ + uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i + uptime self._seconds_to_human(uptime_seconds) + break + end + end +end diff --git a/spec/unit/plugins/aix/cpu_spec.rb b/spec/unit/plugins/aix/cpu_spec.rb new file mode 100644 index 00000000..7e4b1977 --- /dev/null +++ b/spec/unit/plugins/aix/cpu_spec.rb @@ -0,0 +1,81 @@ +# +# 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 cpu plugin" do + before(:each) do + @lsdev_Cc_processor = <<-LSDEV_CC_PROCESSOR +proc0 Available 00-00 Processor +proc4 Defined 00-04 Processor +LSDEV_CC_PROCESSOR + + @lsattr_El_proc0 = <<-LSATTR_EL +frequency 1654344000 Processor Speed False +smt_enabled true Processor SMT enabled False +smt_threads 2 Processor SMT threads False +state enable Processor state False +type PowerPC_POWER5 Processor type False +LSATTR_EL + @ohai = Ohai::System.new + @ohai.stub!(:require_plugin).and_return(true) + @ohai[:os] = "aix" + + @ohai.stub(:from).with("lsdev -Cc processor").and_return(@lsdev_Cc_processor) + @ohai.stub(:from).with("lsattr -El proc0").and_return(@lsattr_El_proc0) + @ohai._require_plugin("aix::cpu") + end + + + it "sets the vendor id to IBM" do + @ohai[:cpu][:vendor_id].should == "IBM" + end + + it "sets the available attribute" do + @ohai[:cpu][:available].should == 1 + end + + it "sets the total number of devices" do + @ohai[:cpu][:total].should == 2 + end + + it "detects the model" do + @ohai[:cpu][:model].should == "PowerPC_POWER5" + end + + it "detects the mhz" do + @ohai[:cpu][:mhz].should == 1615570 + end + + it "detects the status of the device" do + @ohai[:cpu][:proc0][:status].should == "Available" + end + + it "detects the location of the device" do + @ohai[:cpu][:proc0][:location].should == "00-00" + end + + context "lsattr -El device_name" do + it "detects all the attributes of the device" do + @ohai[:cpu][:proc0][:frequency].should == "1654344000" + @ohai[:cpu][:proc0][:smt_enabled].should == "true" + @ohai[:cpu][:proc0][:smt_threads].should == "2" + @ohai[:cpu][:proc0][:state].should == "enable" + @ohai[:cpu][:proc0][:type].should == "PowerPC_POWER5" + end + 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..4f87712d --- /dev/null +++ b/spec/unit/plugins/aix/filesystem_spec.rb @@ -0,0 +1,111 @@ +# +# 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(:each) 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 + @ohai.stub(:require_plugin).and_return(true) + @ohai[:filesystem] = Mash.new + @ohai.stub(:popen4).with("df -P").and_yield(nil, StringIO.new, StringIO.new(@df_P), nil) + @ohai.stub(:popen4).with("mount").and_yield(nil, StringIO.new, StringIO.new(@mount), nil) + @ohai._require_plugin("aix::filesystem") + end + + describe "df -P" do + + it "returns the filesystem block size" do + @ohai[:filesystem]["/dev/hd4"]['kb_size'].should == "786432" + end + + it "returns the filesystem used space in kb" do + @ohai[:filesystem]["/dev/hd4"]['kb_used'].should == "495632" + end + + it "returns the filesystem available space in kb" do + @ohai[:filesystem]["/dev/hd4"]['kb_available'].should == "290800" + end + + it "returns the filesystem capacity in percentage" do + @ohai[:filesystem]["/dev/hd4"]['percent_used'].should == "64%" + end + + it "returns the filesystem mounted location" do + @ohai[:filesystem]["/dev/hd4"]['mount'].should == "/" + end + end + + describe "mount" do + + it "returns the filesystem mount location" do + @ohai[:filesystem]["/dev/hd4"]['mount'].should == "/" + end + + it "returns the filesystem type" do + @ohai[:filesystem]["/dev/hd4"]['fs_type'].should == "jfs2" + end + + it "returns the filesystem mount options" do + @ohai[: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 + @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) + end + it "returns the filesystem mount location" do + @ohai[:filesystem]["192.168.1.11:/stage/middleware"]['mount'].should == "/stage/middleware" + end + + it "returns the filesystem type" do + @ohai[:filesystem]["192.168.1.11:/stage/middleware"]['fs_type'].should == "nfs3" + end + + it "returns the filesystem mount options" do + @ohai[: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/hostname_spec.rb b/spec/unit/plugins/aix/hostname_spec.rb new file mode 100644 index 00000000..13eadd8a --- /dev/null +++ b/spec/unit/plugins/aix/hostname_spec.rb @@ -0,0 +1,28 @@ +# +# 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 hostname plugin" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub(:from).with("hostname").and_return("aix_admin") + @ohai._require_plugin("aix::hostname") + end + + it_should_check_from("aix::hostname", "hostname", "hostname", "aix_admin") +end diff --git a/spec/unit/plugins/aix/kernel_spec.rb b/spec/unit/plugins/aix/kernel_spec.rb new file mode 100644 index 00000000..85321402 --- /dev/null +++ b/spec/unit/plugins/aix/kernel_spec.rb @@ -0,0 +1,51 @@ +# +# 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 kernel plugin" do + before(:each) do + @ohai = Ohai::System.new + @ohai.stub(:from).with("uname -s").and_return("AIX") + @ohai.stub(:from).with("uname -r").and_return(1) + @ohai.stub(:from).with("uname -v").and_return(6) + @ohai.stub(:from).with("uname -p").and_return("powerpc") + @modules = Mash.new + @ohai[:kernel].stub(:modules).and_return(@modules) + @ohai._require_plugin("aix::kernel") + end + + it "uname -s detects the name" do + @ohai[:kernel][:name].should == "aix" + end + + it "uname -r detects the release" do + @ohai[:kernel][:release].should == 1 + end + + it "uname -v detects the version" do + @ohai[:kernel][:version].should == 6 + end + + it "uname -p detects the machine" do + @ohai[:kernel][:machine].should == "powerpc" + end + + it "detects the modules" do + @ohai[:kernel][:modules].should == @modules + 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..b2147576 --- /dev/null +++ b/spec/unit/plugins/aix/network_spec.rb @@ -0,0 +1,258 @@ +# +# 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(:each) 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 + @ohai.stub(:require_plugin).and_return(true) + @ohai[:network] = Mash.new + @ohai.stub(:popen4).with("route -n get 0").and_yield(nil, StringIO.new, StringIO.new(@route_n_get_0), nil) + @ohai.stub(:popen4).with("lsdev -Cc if").and_yield(nil, StringIO.new, StringIO.new(@lsdev_Cc_if), nil) + @ohai.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new(@ifconfig_en0), nil) + @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) + @ohai.stub(:popen4).with("netstat -nrf inet").and_yield(nil, StringIO.new, StringIO.new(@netstat_nrf_inet), nil) + @ohai.stub(:popen4).with("netstat -nrf inet6").and_yield(nil, StringIO.new, StringIO.new("::1%1 ::1%1 UH 1 109392 en0 - -"), nil) + @ohai.stub(:popen4).with("arp -an").and_yield(nil, StringIO.new, StringIO.new(@aix_arp_an), nil) + @ohai._require_plugin("aix::network") + end + + describe "run" do + + it "detects network information" do + @ohai['network'].should_not be_nil + end + + it "detects the interfaces" do + @ohai['network']['interfaces'].keys.sort.should == ["en0"] + end + + it "detects the ip addresses of the interfaces" do + @ohai['network']['interfaces']['en0']['addresses'].keys.should include('172.29.174.58') + end + end + + describe "route -n get 0" do + + it "returns the default gateway of the system's network" do + @ohai[:network][:default_gateway].should == '172.29.128.13' + end + + it "returns the default interface of the system's network" do + @ohai[:network][:default_interface].should == 'en0' + end + end + + describe "lsdev -Cc if" do + + it "detects the state of the interfaces in the system" do + @ohai['network']['interfaces']['en0'][:state].should == "up" + end + + it "detects the description of the interfaces in the system" do + @ohai['network']['interfaces']['en0'][:description].should == "Standard Ethernet Network Interface" + end + + describe "ifconfig interface" do + it "detects the CHAIN network flag" do + @ohai['network']['interfaces']['en0'][:flags].should include('CHAIN') + end + + it "detects the metric network flag" do + @ohai['network']['interfaces']['en0'][:metric].should == '1' + end + + context "inet entries" do + before do + @inet_entry = @ohai['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 + @ohai['network']['interfaces']['en0'][:tcp_sendspace].should == "262144" + @ohai['network']['interfaces']['en0'][:tcp_recvspace].should == "262144" + @ohai['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 = @ohai['network']['interfaces']['en0'][:addresses]["172.29.174.59"] + @ohai.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 = @ohai['network']['interfaces']['en0'][:addresses]["::1%1"] + @ohai.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 = @ohai['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 + context "inet" do + + it "detects the route destinations" do + @ohai['network']['interfaces']['en0'][:routes][0][:destination].should == "default" + @ohai['network']['interfaces']['en0'][:routes][1][:destination].should == "172.29.128.0" + end + + it "detects the route family" do + @ohai['network']['interfaces']['en0'][:routes][0][:family].should == "inet" + end + + it "detects the route gateway" do + @ohai['network']['interfaces']['en0'][:routes][0][:via].should == "172.29.128.13" + end + + it "detects the route flags" do + @ohai['network']['interfaces']['en0'][:routes][0][:flags].should == "UG" + end + end + + context "inet6" do + + it "detects the route destinations" do + @ohai['network']['interfaces']['en0'][:routes][4][:destination].should == "::1%1" + end + + it "detects the route family" do + @ohai['network']['interfaces']['en0'][:routes][4][:family].should == "inet6" + end + + it "detects the route gateway" do + @ohai['network']['interfaces']['en0'][:routes][4][:via].should == "::1%1" + end + + it "detects the route flags" do + @ohai['network']['interfaces']['en0'][:routes][4][:flags].should == "UH" + end + end + end + + describe "arp -an" do + + it "supresses the hostname entries" do + @ohai['network']['arp'][0][:remote_host].should == "?" + end + + it "detects the remote ip entry" do + @ohai['network']['arp'][0][:remote_ip].should == "172.29.131.16" + end + + it "detects the remote mac entry" do + @ohai['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 + @ohai.hex_to_dec_netmask('0xffff0000').should == "255.255.0.0" + end + end +end diff --git a/spec/unit/plugins/aix/platform_spec.rb b/spec/unit/plugins/aix/platform_spec.rb new file mode 100644 index 00000000..e7f70bdb --- /dev/null +++ b/spec/unit/plugins/aix/platform_spec.rb @@ -0,0 +1,42 @@ +# +# 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 plugin platform" do + before(:each) do + @ohai = Ohai::System.new + @ohai[:kernel] = Mash.new + @ohai[:kernel][:name] = "aix" + @ohai[:kernel][:version] = "1" + @ohai[:kernel][:release] = "0" + @ohai.stub(:require_plugin).and_return(true) + @ohai._require_plugin("aix::platform") + end + + it "should set platform to aix" do + @ohai[:platform].should == "aix" + end + + it "should set the platform_version" do + @ohai[:platform_version].should == "1.0" + end + + it "should set platform_family" do + @ohai[:platform_family].should == @ohai[:platform] + end +end diff --git a/spec/unit/plugins/aix/uptime_spec.rb b/spec/unit/plugins/aix/uptime_spec.rb new file mode 100644 index 00000000..0fd0afa8 --- /dev/null +++ b/spec/unit/plugins/aix/uptime_spec.rb @@ -0,0 +1,40 @@ +# +# 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 plugin uptime" do + + before(:each) do + @ohai = Ohai::System.new + @ohai[:os] = "aix" + @ohai._require_plugin("uptime") + @ohai.stub(:popen4).with("who -b").and_yield(nil, StringIO.new, StringIO.new(" . system boot Jul 9 17:51"), nil) + + Time.stub_chain(:now, :to_i).and_return(1374258600) + DateTime.stub_chain(:parse, :strftime, :to_i).and_return(1373392260) + @ohai._require_plugin("aix::uptime") + end + + it "should set uptime_seconds to uptime" do + @ohai[:uptime_seconds].should == 866340 + end + + it "should set uptime to a human readable date" do + @ohai[:uptime].should == "10 days 00 hours 39 minutes 00 seconds" + end +end |