summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaire McQuin <clairemcquin@seamcquin100loaner.local>2014-01-09 17:51:49 -0800
committerClaire McQuin <clairemcquin@seamcquin100loaner.local>2014-01-09 17:51:49 -0800
commitc396684c8d795c1662e45eea46b5de004fba76a6 (patch)
tree3acbd727eb169b22f17d06f6f2f74aa9cd28e6aa
parent0529076157d7ac2e6191d51434ce657a8c901b22 (diff)
parent798daefb3104cf9911e397ad9a1b200dc8c00fdc (diff)
downloadohai-c396684c8d795c1662e45eea46b5de004fba76a6.tar.gz
merged most of 6-stable into master. remaining files: lib/ohai/plugins/cloud.rb, lib/ohai/plugins/gce.rb, spec/unit/plugins/gce_spec.rb
-rw-r--r--.gitignore1
-rw-r--r--docs/man/man1/ohai.1104
-rw-r--r--lib/ohai/mixin/command.rb7
-rw-r--r--lib/ohai/mixin/gce_metadata.rb2
-rw-r--r--lib/ohai/plugins/aix/cpu.rb53
-rw-r--r--lib/ohai/plugins/aix/filesystem.rb77
-rw-r--r--lib/ohai/plugins/aix/kernel.rb31
-rw-r--r--lib/ohai/plugins/aix/memory.rb28
-rw-r--r--lib/ohai/plugins/aix/network.rb158
-rw-r--r--lib/ohai/plugins/aix/platform.rb28
-rw-r--r--lib/ohai/plugins/aix/uptime.rb38
-rw-r--r--lib/ohai/plugins/java.rb13
-rw-r--r--lib/ohai/plugins/linux/platform.rb10
-rw-r--r--lib/ohai/plugins/sigar/cpu.rb2
-rw-r--r--lib/ohai/plugins/sigar/memory.rb2
-rw-r--r--lib/ohai/plugins/sigar/platform.rb2
-rw-r--r--lib/ohai/plugins/uptime.rb2
-rw-r--r--ohai.gemspec2
-rw-r--r--spec/unit/mixin/command_spec.rb24
-rw-r--r--spec/unit/plugins/aix/cpu_spec.rb81
-rw-r--r--spec/unit/plugins/aix/filesystem_spec.rb111
-rw-r--r--spec/unit/plugins/aix/hostname_spec.rb28
-rw-r--r--spec/unit/plugins/aix/kernel_spec.rb51
-rw-r--r--spec/unit/plugins/aix/network_spec.rb258
-rw-r--r--spec/unit/plugins/aix/platform_spec.rb42
-rw-r--r--spec/unit/plugins/aix/uptime_spec.rb40
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb6
27 files changed, 1151 insertions, 50 deletions
diff --git a/.gitignore b/.gitignore
index 19c83b90..edddf9d2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ Gemfile.lock
pkg/
tmp/
coverage/
+.DS_Store
diff --git a/docs/man/man1/ohai.1 b/docs/man/man1/ohai.1
index 6474d31a..dc59458f 100644
--- a/docs/man/man1/ohai.1
+++ b/docs/man/man1/ohai.1
@@ -1,23 +1,91 @@
-.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.36.
-.TH OHAI "1" "April 2009" "ohai" "User Commands"
+.TH "OHAI" "1" "Ohai 6.20.0" "" "ohai"
.SH NAME
-ohai \- collect system information
-.SH SYNOPSIS
-.B ohai
-[\fIOPTION\fR]...
-.SH DESCRIPTION
-Information about your system is collected and returned as multidimensional
-attributes in a JSON format.
+ohai \- The man page for the ohai command line tool.
+.
+.nr rst2man-indent-level 0
+.
+.de1 rstReportMargin
+\\$1 \\n[an-margin]
+level \\n[rst2man-indent-level]
+level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
+-
+\\n[rst2man-indent0]
+\\n[rst2man-indent1]
+\\n[rst2man-indent2]
+..
+.de1 INDENT
+.\" .rstReportMargin pre:
+. RS \\$1
+. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
+. nr rst2man-indent-level +1
+.\" .rstReportMargin post:
+..
+.de UNINDENT
+. RE
+.\" indent \\n[an-margin]
+.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.nr rst2man-indent-level -1
+.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
+.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
+..
+.\" Man page generated from reStructuredText.
+.
+.sp
+Ohai is a tool that is used to detect attributes on a node, and then provide these attributes to the chef\-client at the start of every chef\-client run. Ohai is required by the chef\-client and must be present on a node. The types of attributes Ohai collects include:
+.INDENT 0.0
+.IP \(bu 2
+Platform details
+.IP \(bu 2
+Networking usage
+.IP \(bu 2
+Memory usage
+.IP \(bu 2
+Processor usage
+.IP \(bu 2
+Kernel data
+.IP \(bu 2
+Host names
+.IP \(bu 2
+Fully qualified domain names
+.IP \(bu 2
+Other configuration details
+.UNINDENT
+.sp
+Attributes that are collected by Ohai are automatic attributes, in that these attributes are used by the chef\-client to ensure that these attributes remain unchanged after the chef\-client is done configuring the node.
+.sp
+ohai is the command\-line interface for Ohai, a tool that is used to detect attributes on a node, and then provide these attributes to the chef\-client at the start of every chef\-client run.
+.SH OPTIONS
+.sp
+This command has the following syntax:
+.sp
+.nf
+.ft C
+ohai OPTION
+.ft P
+.fi
+.sp
+This tool has the following options:
+.INDENT 0.0
.TP
-\fB\-d\fR, \fB\-\-directory\fR NAME
-A directory to add to the Ohai search path
+.B \fB\-d PATH\fP, \fB\-\-directory PATH\fP
+The directory in which Ohai plugins are located. For example: \fB/etc/ohai/plugins\fP.
.TP
-\fB\-f\fR, \fB\-\-file\fR NAME
-A file to run Ohai against
+.B \fB\-f FILE_NAME\fP, \fB\-\-file FILE_NAME\fP
+The file against which Ohai will run.
.TP
-\fB\-l\fR, \fB\-\-loglevel\fR NAME
-Set log level for Ohai
+.B \fB\-h\fP, \fB\-\-help\fP
+Shows help for the command.
.TP
-\fB\-h\fR, \fB\-\-help\fR
-Show this message
-.IP
+.B \fB\-l LEVEL\fP, \fB\-\-log_level LEVEL\fP
+The level of logging that will be stored in a log file: \fBdebug\fP, \fBinfo\fP, \fBwarn\fP, \fBerror\fP, or \fBfatal\fP.
+.TP
+.B \fB\-L LOGLOCATION\fP, \fB\-\-logfile c\fP
+The location in which log file output files will be saved. If this location is set to something other than \fBSTDOUT\fP, standard output logging will still be performed (otherwise there would be no output other than to a file).
+.TP
+.B \fB\-v\fP, \fB\-\-version\fP
+The version of Ohai.
+.UNINDENT
+.SH AUTHOR
+Opscode
+.\" Generated by docutils manpage writer.
+.
diff --git a/lib/ohai/mixin/command.rb b/lib/ohai/mixin/command.rb
index e80b6b10..48758eb5 100644
--- a/lib/ohai/mixin/command.rb
+++ b/lib/ohai/mixin/command.rb
@@ -124,12 +124,12 @@ module Ohai
#
# Thanks Ara!
def popen4(cmd, args={}, &b)
-
+
## Disable garbage collection to work around possible bug in MRI
# Ruby 1.8 suffers from intermittent segfaults believed to be due to GC while IO.select
# See OHAI-330 / CHEF-2916 / CHEF-1305
GC.disable
-
+
# Waitlast - this is magic.
#
# Do we wait for the child process to die before we yield
@@ -325,9 +325,10 @@ module Ohai
# have encoding methods.
if "".respond_to?(:force_encoding) && defined?(Encoding)
o.string.force_encoding(Encoding.default_external)
+ o.string.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
e.string.force_encoding(Encoding.default_external)
+ e.string.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?')
end
-
b[cid, pi[0], o, e]
results.last
end
diff --git a/lib/ohai/mixin/gce_metadata.rb b/lib/ohai/mixin/gce_metadata.rb
index 6a35f5b9..3593ccf0 100644
--- a/lib/ohai/mixin/gce_metadata.rb
+++ b/lib/ohai/mixin/gce_metadata.rb
@@ -22,7 +22,7 @@ module Ohai
module GCEMetadata
GCE_METADATA_ADDR = "metadata.google.internal" unless defined?(GCE_METADATA_ADDR)
- GCE_METADATA_URL = "/0.1/meta-data" unless defined?(GCE_METADATA_URL)
+ GCE_METADATA_URL = "/computeMetadata/v1beta1/?recursive=true" unless defined?(GCE_METADATA_URL)
def can_metadata_connect?(addr, port, timeout=2)
t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0)
diff --git a/lib/ohai/plugins/aix/cpu.rb b/lib/ohai/plugins/aix/cpu.rb
new file mode 100644
index 00000000..d885a391
--- /dev/null
+++ b/lib/ohai/plugins/aix/cpu.rb
@@ -0,0 +1,53 @@
+#
+# 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");
+# 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.
+#
+
+Ohai.plugin(:CPU) do
+ provides "cpu"
+
+ collect_data(:aix) do
+ 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
+ end
+end
diff --git a/lib/ohai/plugins/aix/filesystem.rb b/lib/ohai/plugins/aix/filesystem.rb
new file mode 100644
index 00000000..55e576c7
--- /dev/null
+++ b/lib/ohai/plugins/aix/filesystem.rb
@@ -0,0 +1,77 @@
+#
+# 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");
+# 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.
+#
+
+Ohai.plugin(:Filesystem) do
+ provides "filesystem"
+
+ collect_data(:aix) do
+ 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
+ end
+end
diff --git a/lib/ohai/plugins/aix/kernel.rb b/lib/ohai/plugins/aix/kernel.rb
new file mode 100644
index 00000000..748ce702
--- /dev/null
+++ b/lib/ohai/plugins/aix/kernel.rb
@@ -0,0 +1,31 @@
+#
+# 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.
+#
+
+Ohai.plugin(:Kernel) do
+ provides "kernel", "kernel/modules"
+
+ collect_data(:aix) do
+ 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
+ end
+end
diff --git a/lib/ohai/plugins/aix/memory.rb b/lib/ohai/plugins/aix/memory.rb
new file mode 100644
index 00000000..8500a42d
--- /dev/null
+++ b/lib/ohai/plugins/aix/memory.rb
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+
+Ohai.plugin(:Memory) do
+ provides "memory"
+
+ collect_data(:aix) do
+ memory = Mash.new
+
+ meminfo = from("svmon -G -O unit=MB,summary=longreal | grep '[0-9]'")
+ memory[:total], u, memory[:free] = meminfo.split
+ end
+end
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb
new file mode 100644
index 00000000..164ae57b
--- /dev/null
+++ b/lib/ohai/plugins/aix/network.rb
@@ -0,0 +1,158 @@
+#
+# 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");
+# 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.
+#
+
+Ohai.plugin(:Network) do
+ require 'ipaddr'
+
+ provides "network", "counters/network"
+
+ # 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
+
+ collect_data(:aix) do
+ # 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
+
+ # 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
+ end
+end
diff --git a/lib/ohai/plugins/aix/platform.rb b/lib/ohai/plugins/aix/platform.rb
new file mode 100644
index 00000000..29239a28
--- /dev/null
+++ b/lib/ohai/plugins/aix/platform.rb
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+
+Ohai.plugin(:Platform) do
+ provides "platform", "platform_version", "platform_family"
+ depends "kernel"
+
+ collect_data(:aix) do
+ platform kernel[:name]
+ platform_version [kernel[:version], kernel[:release]].join(".")
+ platform_family platform
+ end
+end
diff --git a/lib/ohai/plugins/aix/uptime.rb b/lib/ohai/plugins/aix/uptime.rb
new file mode 100644
index 00000000..a65892f4
--- /dev/null
+++ b/lib/ohai/plugins/aix/uptime.rb
@@ -0,0 +1,38 @@
+#
+# 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");
+# 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.
+#
+
+Ohai.plugin(:Uptime) do
+ provides "uptime", "uptime_seconds"
+
+ collect_data(:aix) do
+ require 'date'
+ # 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
+ end
+end
diff --git a/lib/ohai/plugins/java.rb b/lib/ohai/plugins/java.rb
index c94a93a9..e8321de6 100644
--- a/lib/ohai/plugins/java.rb
+++ b/lib/ohai/plugins/java.rb
@@ -6,9 +6,9 @@
# 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.
@@ -18,13 +18,8 @@
Ohai.plugin(:Java) do
provides "languages/java"
-
depends "languages"
- collect_data do
- get_java_info if has_real_java?
- end
-
def get_java_info
java = Mash.new
so = shell_out("java -version")
@@ -69,5 +64,7 @@ Ohai.plugin(:Java) do
RUBY_PLATFORM.downcase.include?("darwin")
end
-
+ collect_data do
+ get_java_info if has_real_java?
+ end
end
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index bd0379bc..8b11fe2f 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -18,7 +18,6 @@
Ohai.plugin(:Platform) do
provides "platform", "platform_version", "platform_family"
-
depends "lsb"
def get_redhatish_platform(contents)
@@ -40,14 +39,11 @@ Ohai.plugin(:Platform) do
platform "oracle"
platform_version get_redhatish_version(contents)
elsif File.exists?("/etc/debian_version")
- # Ubuntu, GCEL and Debian both have /etc/debian_version
- # Ubuntu, GCEL should always have a working lsb, debian does not by default
+ # Ubuntu and Debian both have /etc/debian_version
+ # Ubuntu should always have a working lsb, debian does not by default
if lsb[:id] =~ /Ubuntu/i
platform "ubuntu"
platform_version lsb[:release]
- elsif lsb[:id] =~ /gcel/i
- platform "gcel"
- platform_version lsb[:release]
elsif lsb[:id] =~ /LinuxMint/i
platform "linuxmint"
platform_version lsb[:release]
@@ -100,7 +96,7 @@ Ohai.plugin(:Platform) do
end
case platform
- when /debian/, /ubuntu/, /linuxmint/, /raspbian/, /gcel/
+ when /debian/, /ubuntu/, /linuxmint/, /raspbian/
platform_family "debian"
when /fedora/
platform_family "fedora"
diff --git a/lib/ohai/plugins/sigar/cpu.rb b/lib/ohai/plugins/sigar/cpu.rb
index 8f85de33..a5bcc73f 100644
--- a/lib/ohai/plugins/sigar/cpu.rb
+++ b/lib/ohai/plugins/sigar/cpu.rb
@@ -19,7 +19,7 @@
Ohai.plugin(:CPU) do
provides "cpu"
- collect_data(:aix, :hpux, :default) do
+ collect_data(:hpux, :default) do
require 'sigar'
sigar = Sigar.new
diff --git a/lib/ohai/plugins/sigar/memory.rb b/lib/ohai/plugins/sigar/memory.rb
index 4944aeb5..78f55199 100644
--- a/lib/ohai/plugins/sigar/memory.rb
+++ b/lib/ohai/plugins/sigar/memory.rb
@@ -19,7 +19,7 @@
Ohai.plugin(:Memory) do
provides "memory"
- collect_data(:aix, :hpux, :default) do
+ collect_data(:hpux, :default) do
require "sigar"
sigar = Sigar.new
diff --git a/lib/ohai/plugins/sigar/platform.rb b/lib/ohai/plugins/sigar/platform.rb
index ef6249f4..20e9eb9b 100644
--- a/lib/ohai/plugins/sigar/platform.rb
+++ b/lib/ohai/plugins/sigar/platform.rb
@@ -19,7 +19,7 @@
Ohai.plugin(:Platform) do
provides "platform", "platform_version", "platform_family"
- collect_data(:aix, :hpux, :default) do
+ collect_data(:hpux, :default) do
require "sigar"
sys = Sigar.new.sys_info
diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb
index c723e74e..4ae82d7a 100644
--- a/lib/ohai/plugins/uptime.rb
+++ b/lib/ohai/plugins/uptime.rb
@@ -42,7 +42,7 @@ Ohai.plugin(:Uptime) do
return [nil, nil]
end
- collect_data(:aix, :hpux, :default) do
+ collect_data(:hpux, :default) do
require 'sigar'
sigar = Sigar.new
diff --git a/ohai.gemspec b/ohai.gemspec
index dd93c0ab..e9620314 100644
--- a/ohai.gemspec
+++ b/ohai.gemspec
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
s.homepage = "http://wiki.opscode.com/display/chef/Ohai"
s.add_dependency "mime-types", "~> 1.16"
-
+ s.add_dependency "systemu", "~> 2.5.2"
s.add_dependency "yajl-ruby"
s.add_dependency "mixlib-cli"
s.add_dependency "mixlib-config", "~> 2.0"
diff --git a/spec/unit/mixin/command_spec.rb b/spec/unit/mixin/command_spec.rb
index 9e454117..26189dfd 100644
--- a/spec/unit/mixin/command_spec.rb
+++ b/spec/unit/mixin/command_spec.rb
@@ -37,10 +37,30 @@ describe Ohai::Mixin::Command, "popen4" do
end
if defined?(::Encoding) && "".respond_to?(:force_encoding) #i.e., ruby 1.9
- it "[OHAI-275] should mark strings as in the default external encoding" do
+ context "when external commands return UTF-8 strings and we are running under LANG=C encoding" do
+ before do
+ @saved_default_external = Encoding.default_external
+ @saved_default_internal = Encoding.default_internal
+ Encoding.default_external = Encoding::US_ASCII
+ Encoding.default_internal = Encoding::US_ASCII
+ end
+
+ after do
+ Encoding.default_external = @saved_default_external
+ Encoding.default_internal = @saved_default_internal
+ end
+
+ it "should force encode the string to UTF-8" do
+ extend Ohai::Mixin::Command
+ snowy = run_command(:command => ("echo '" + ('☃' * 8096) + "'"))[1]
+ snowy.encoding.should == Encoding::UTF_8
+ end
+ end
+
+ it "should force encode the string to UTF-8" do
extend Ohai::Mixin::Command
snowy = run_command(:command => ("echo '" + ('☃' * 8096) + "'"))[1]
- snowy.encoding.should == Encoding.default_external
+ snowy.encoding.should == Encoding::UTF_8
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
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index fc9662a7..d3b36f56 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -65,12 +65,6 @@ describe Ohai::System, "Linux plugin platform" do
@plugin[:platform].should == "linuxmint"
@plugin[:platform_family].should == "debian"
end
- it "should set platform to gcel and platform_family to debian [:lsb][:id] contains GCEL" do
- @plugin[:lsb][:id] = "GCEL"
- @plugin.run
- @plugin[:platform].should == "gcel"
- @plugin[:platform_family].should == "debian"
- end
it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do
@plugin[:lsb][:id] = "Debian"
@plugin.run