diff options
author | Claire McQuin <claire@opscode.com> | 2013-10-03 17:29:03 -0700 |
---|---|---|
committer | Claire McQuin <claire@opscode.com> | 2013-10-17 12:07:30 -0700 |
commit | e456e5e91f58c13101ee1631b9def808f27efd5a (patch) | |
tree | 08995ef8ae50850f928418ac6234238eb8607713 | |
parent | b9f197ceb3c377b1f0e7c269252ea1c8757d35c1 (diff) | |
download | ohai-e456e5e91f58c13101ee1631b9def808f27efd5a.tar.gz |
update plugin files
174 files changed, 947 insertions, 1333 deletions
diff --git a/lib/ohai/plugins/aix/cpu.rb b/lib/ohai/plugins/aix/cpu.rb deleted file mode 100644 index 990b5ec1..00000000 --- a/lib/ohai/plugins/aix/cpu.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::cpu" -end diff --git a/lib/ohai/plugins/aix/filesystem.rb b/lib/ohai/plugins/aix/filesystem.rb deleted file mode 100644 index fb0aaddc..00000000 --- a/lib/ohai/plugins/aix/filesystem.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::filesystem" -end diff --git a/lib/ohai/plugins/aix/memory.rb b/lib/ohai/plugins/aix/memory.rb deleted file mode 100644 index e711fe25..00000000 --- a/lib/ohai/plugins/aix/memory.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::memory" -end diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb deleted file mode 100644 index 807b4a4a..00000000 --- a/lib/ohai/plugins/aix/network.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::network" -end diff --git a/lib/ohai/plugins/aix/platform.rb b/lib/ohai/plugins/aix/platform.rb deleted file mode 100644 index 9f142810..00000000 --- a/lib/ohai/plugins/aix/platform.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::platform" -end diff --git a/lib/ohai/plugins/aix/uptime.rb b/lib/ohai/plugins/aix/uptime.rb deleted file mode 100644 index 324ced96..00000000 --- a/lib/ohai/plugins/aix/uptime.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::uptime" -end diff --git a/lib/ohai/plugins/azure.rb b/lib/ohai/plugins/azure.rb index be97b030..27454f48 100644 --- a/lib/ohai/plugins/azure.rb +++ b/lib/ohai/plugins/azure.rb @@ -1,5 +1,5 @@ -Ohai.plugin do +Ohai.plugin(:Azure) do provides "azure" collect_data do diff --git a/lib/ohai/plugins/c.rb b/lib/ohai/plugins/c.rb index 9eb5d36e..36bb13db 100644 --- a/lib/ohai/plugins/c.rb +++ b/lib/ohai/plugins/c.rb @@ -18,7 +18,7 @@ require 'rbconfig' -Ohai.plugin do +Ohai.plugin(:C) do provides "languages/c" depends "languages" diff --git a/lib/ohai/plugins/chef.rb b/lib/ohai/plugins/chef.rb index bbe16b46..fd9b7889 100644 --- a/lib/ohai/plugins/chef.rb +++ b/lib/ohai/plugins/chef.rb @@ -16,15 +16,15 @@ # limitations under the License. # -require 'chef/version' - -Ohai.plugin do +Ohai.plugin(:Chef) do provides "chef_packages/chef" collect_data do - self[:chef_packages] = Mash.new unless self[:chef_packages] - self[:chef_packages][:chef] = Mash.new - self[:chef_packages][:chef][:version] = Chef::VERSION - self[:chef_packages][:chef][:chef_root] = Chef::CHEF_ROOT + require 'chef/version' + + chef_packages Mash.new unless chef_packages + chef_packages[:chef] = Mash.new + chef_packages[:chef][:version] = Chef::VERSION + chef_packages[:chef][:chef_root] = Chef::CHEF_ROOT end end diff --git a/lib/ohai/plugins/cloud.rb b/lib/ohai/plugins/cloud.rb index 76913871..e8019074 100644 --- a/lib/ohai/plugins/cloud.rb +++ b/lib/ohai/plugins/cloud.rb @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -Ohai.plugin do +Ohai.plugin(:Cloud) do provides "cloud" depends "ec2" diff --git a/lib/ohai/plugins/command.rb b/lib/ohai/plugins/command.rb index 7c49ab3c..930846a5 100644 --- a/lib/ohai/plugins/command.rb +++ b/lib/ohai/plugins/command.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Command) do provides "command" collect_data do diff --git a/lib/ohai/plugins/darwin/cpu.rb b/lib/ohai/plugins/darwin/cpu.rb index 6f1dc035..f43554b9 100644 --- a/lib/ohai/plugins/darwin/cpu.rb +++ b/lib/ohai/plugins/darwin/cpu.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:CPU) do provides "cpu" - collect_data do + collect_data(:darwin) do cpu Mash.new so = shell_out("sysctl -n hw.physicalcpu") cpu[:real] = so.stdout.to_i diff --git a/lib/ohai/plugins/darwin/filesystem.rb b/lib/ohai/plugins/darwin/filesystem.rb index 905df94d..83c8a6cf 100644 --- a/lib/ohai/plugins/darwin/filesystem.rb +++ b/lib/ohai/plugins/darwin/filesystem.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Filesystem) do provides "filesystem" - collect_data do + collect_data(:darwin) do fs = Mash.new block_size = 0 diff --git a/lib/ohai/plugins/darwin/kernel.rb b/lib/ohai/plugins/darwin/kernel.rb deleted file mode 100644 index 51e2e4ef..00000000 --- a/lib/ohai/plugins/darwin/kernel.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 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 do - provides "kernel/os", "kernel/machine", "kernel/modules" - depends "kernel/name" - - collect_data do - kernel[:os] = kernel[:name] - - so = shell_out("sysctl -n hw.optional.x86_64") - if so.stdout.split($/)[0].to_i == 1 - kernel[:machine] = 'x86_64' - end - - kext = Mash.new - so = shell_out("kextstat -k -l") - so.stdout.lines do |line| - if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/ - kext[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 } - end - end - - kernel[:modules] = kext - end -end diff --git a/lib/ohai/plugins/darwin/network.rb b/lib/ohai/plugins/darwin/network.rb index cf209a97..4ed63eb7 100644 --- a/lib/ohai/plugins/darwin/network.rb +++ b/lib/ohai/plugins/darwin/network.rb @@ -16,10 +16,9 @@ # limitations under the License. # -require 'scanf' - -Ohai.plugin do - provides "network", "counters/network" +Ohai.plugin(:Network) do + provides "network", "network/interfaces" + provides "counters/network", "counters/network/interfaces" def parse_media(media_string) media = Hash.new @@ -84,7 +83,9 @@ Ohai.plugin do nil end - collect_data do + collect_data(:darwin) do + require 'scanf' + network Mash.new unless network network[:interfaces] = Mash.new unless network[:interfaces] counters Mash.new unless counters diff --git a/lib/ohai/plugins/darwin/platform.rb b/lib/ohai/plugins/darwin/platform.rb index a96cc0a9..fc26544c 100644 --- a/lib/ohai/plugins/darwin/platform.rb +++ b/lib/ohai/plugins/darwin/platform.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Platform) do provides "platform", "platform_version", "platform_build", "platform_family" - collect_data do + collect_data(:darwin) do so = shell_out("#{ Ohai.abs_path( "/usr/bin/sw_vers" )}") so.stdout.lines do |line| case line diff --git a/lib/ohai/plugins/darwin/ps.rb b/lib/ohai/plugins/darwin/ps.rb deleted file mode 100644 index 013c1eb0..00000000 --- a/lib/ohai/plugins/darwin/ps.rb +++ /dev/null @@ -1,27 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 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 do - provides "command/ps" - - depends 'command' - - collect_data do - command[:ps] = 'ps -ef' - end -end diff --git a/lib/ohai/plugins/darwin/system_profiler.rb b/lib/ohai/plugins/darwin/system_profiler.rb index 5c364beb..e3756d3f 100644 --- a/lib/ohai/plugins/darwin/system_profiler.rb +++ b/lib/ohai/plugins/darwin/system_profiler.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:SystemProfile) do provides "system_profile" - collect_data do + collect_data(:darwin) do begin require 'plist' diff --git a/lib/ohai/plugins/darwin/uptime.rb b/lib/ohai/plugins/darwin/uptime.rb deleted file mode 100644 index 4d966cd5..00000000 --- a/lib/ohai/plugins/darwin/uptime.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "uptime", "uptime_seconds" - - # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009 - - collect_data do - so = shell_out("#{ Ohai.abs_path( "/usr/sbin/sysctl" )} kern.boottime") - so.stdout.lines do |line| - if line =~ /kern.boottime:\D+(\d+)/ - uptime_seconds Time.new.to_i - $1.to_i - uptime seconds_to_human(uptime_seconds) - end - end - end -end diff --git a/lib/ohai/plugins/dmi.rb b/lib/ohai/plugins/dmi.rb index 48bcb5e1..81c271e9 100644 --- a/lib/ohai/plugins/dmi.rb +++ b/lib/ohai/plugins/dmi.rb @@ -16,14 +16,14 @@ # limitations under the License. # -require "ohai/plugins/dmi_common" - -Ohai.plugin do +Ohai.plugin(:DMI) do provides "dmi" # dmidecode does not return data without access to /dev/mem (or its equivalent) collect_data do + require "ohai/plugins/dmi_common" + dmi Mash.new # all output lines should fall within one of these patterns diff --git a/lib/ohai/plugins/ec2.rb b/lib/ohai/plugins/ec2.rb index 2df62ac7..e7ab945d 100644 --- a/lib/ohai/plugins/ec2.rb +++ b/lib/ohai/plugins/ec2.rb @@ -19,14 +19,12 @@ require 'ohai/mixin/ec2_metadata' -Ohai.plugin do +Ohai.plugin(:EC2) do include Ohai::Mixin::Ec2Metadata - + provides "ec2" - depends "fqdn", "domain" - depends "kernel" - depends "network", "counters/network" + depends "network/interfaces" def has_ec2_mac? network[:interfaces].values.each do |iface| diff --git a/lib/ohai/plugins/erlang.rb b/lib/ohai/plugins/erlang.rb index e398fc61..ebea9da7 100644 --- a/lib/ohai/plugins/erlang.rb +++ b/lib/ohai/plugins/erlang.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Erlang) do provides "languages/erlang" depends "languages" diff --git a/lib/ohai/plugins/eucalyptus.rb b/lib/ohai/plugins/eucalyptus.rb index 2d84cb21..c5fed2f0 100644 --- a/lib/ohai/plugins/eucalyptus.rb +++ b/lib/ohai/plugins/eucalyptus.rb @@ -19,14 +19,12 @@ require 'ohai/mixin/ec2_metadata' -Ohai.plugin do +Ohai.plugin(:Eucalyptus) do include Ohai::Mixin::Ec2Metadata provides "eucalyptus" - depends "fqdn", "domain" - depends "kernel" - depends "network" + depends "network/interfaces" def get_mac_address(addresses) detected_addresses = addresses.detect { |address, keypair| keypair == {"family"=>"lladdr"} } diff --git a/lib/ohai/plugins/freebsd/cpu.rb b/lib/ohai/plugins/freebsd/cpu.rb index 7512c042..1a9c97cf 100644 --- a/lib/ohai/plugins/freebsd/cpu.rb +++ b/lib/ohai/plugins/freebsd/cpu.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:CPU) do provides "cpu" - collect_data do + collect_data(:freebsd) do # all dmesg output for smp I can find only provides info about a single processor # identical processors is probably a hardware requirement so we'll duplicate data for each cpu # old examples: http://www.bnv-bamberg.de/home/ba3294/smp/rbuild/index.htm diff --git a/lib/ohai/plugins/freebsd/filesystem.rb b/lib/ohai/plugins/freebsd/filesystem.rb index 7131cdad..b0037512 100644 --- a/lib/ohai/plugins/freebsd/filesystem.rb +++ b/lib/ohai/plugins/freebsd/filesystem.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Filesystem) do provides "filesystem" - collect_data do + collect_data(:freebsd) do fs = Mash.new # Grab filesystem data from df diff --git a/lib/ohai/plugins/freebsd/kernel.rb b/lib/ohai/plugins/freebsd/kernel.rb deleted file mode 100644 index e5a5a314..00000000 --- a/lib/ohai/plugins/freebsd/kernel.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "kernel" - - collect_data do - kernel[:os] = kernel[:name] - so = shell_out("uname -i") - kernel[:ident] = so.stdout.split($/)[0] - so = shell_out("sysctl kern.securelevel") - kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ } - - kld = Mash.new - so = shell_out("#{ Ohai.abs_path( "/sbin/kldstat" )}") - so.stdout.lines do |line| - # 1 7 0xc0400000 97f830 kernel - if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/ - kld[$5] = { :size => $4, :refcount => $2 } - end - end - - kernel[:modules] = kld - end -end diff --git a/lib/ohai/plugins/freebsd/memory.rb b/lib/ohai/plugins/freebsd/memory.rb index 969c89f2..842f9689 100644 --- a/lib/ohai/plugins/freebsd/memory.rb +++ b/lib/ohai/plugins/freebsd/memory.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do - provides "memory" +Ohai.plugin(:Memory) do + provides "memory", "memory/swap" - collect_data do + collect_data(:freebsd) do memory Mash.new memory[:swap] = Mash.new diff --git a/lib/ohai/plugins/freebsd/network.rb b/lib/ohai/plugins/freebsd/network.rb index 2286e033..6f5eed5b 100644 --- a/lib/ohai/plugins/freebsd/network.rb +++ b/lib/ohai/plugins/freebsd/network.rb @@ -16,9 +16,10 @@ # limitations under the License. # -Ohai.plugin do - provides "network", "counters/network" - +Ohai.plugin(:Network) do + provides "network", "network/interfaces" + provides "counters/network", "counters/network/interfaces" + collect_data do network Mash.new unless network network[:interfaces] = Mash.new unless network[:interfaces] diff --git a/lib/ohai/plugins/freebsd/platform.rb b/lib/ohai/plugins/freebsd/platform.rb index 0bfaee77..bef7b73e 100644 --- a/lib/ohai/plugins/freebsd/platform.rb +++ b/lib/ohai/plugins/freebsd/platform.rb @@ -16,13 +16,14 @@ # limitations under the License. # -Ohai.plugin do - provides "platform", "platform_version" +Ohai.plugin(:Platform) do + provides "platform", "platform_version", "platform_family" - collect_data do + collect_data(:freebsd) do so = shell_out("uname -s") platform so.stdout.split($/)[0].downcase so = shell_out("uname -r") platform_version so.stdout.split($/)[0] + platform_family "freebsd" end end diff --git a/lib/ohai/plugins/freebsd/ps.rb b/lib/ohai/plugins/freebsd/ps.rb deleted file mode 100644 index 8bde6414..00000000 --- a/lib/ohai/plugins/freebsd/ps.rb +++ /dev/null @@ -1,28 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "command/ps" - - depends 'command' - - collect_data do - # ps -e requires procfs - command[:ps] = 'ps -ax' - end -end diff --git a/lib/ohai/plugins/freebsd/uptime.rb b/lib/ohai/plugins/freebsd/uptime.rb deleted file mode 100644 index db05656f..00000000 --- a/lib/ohai/plugins/freebsd/uptime.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "uptime", "uptime_seconds" - - # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009 - - collect_data do - so = shell_out("#{ Ohai.abs_path( "/sbin/sysctl" )} kern.boottime") - so.stdout.lines do |line| - if line =~ /kern.boottime:\D+(\d+)/ - uptime_seconds Time.new.to_i - $1.to_i - uptime seconds_to_human(uptime_seconds) - end - end - end -end diff --git a/lib/ohai/plugins/freebsd/virtualization.rb b/lib/ohai/plugins/freebsd/virtualization.rb index 3a7ae79c..aedcb694 100644 --- a/lib/ohai/plugins/freebsd/virtualization.rb +++ b/lib/ohai/plugins/freebsd/virtualization.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Virtualization) do provides "virtualization" - collect_data do + collect_data(:freebsd) do virtualization Mash.new so = shell_out("sysctl -n security.jail.jailed") diff --git a/lib/ohai/plugins/gce.rb b/lib/ohai/plugins/gce.rb index 75930ec3..1fc2841e 100644 --- a/lib/ohai/plugins/gce.rb +++ b/lib/ohai/plugins/gce.rb @@ -16,7 +16,7 @@ require 'ohai/mixin/gce_metadata' -Ohai.plugin do +Ohai.plugin(:GCE) do include Ohai::Mixin::GCEMetadata provides "gce" diff --git a/lib/ohai/plugins/groovy.rb b/lib/ohai/plugins/groovy.rb index de45e0e9..044a6e33 100644 --- a/lib/ohai/plugins/groovy.rb +++ b/lib/ohai/plugins/groovy.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Groovy) do provides "languages/groovy" depends "languages" diff --git a/lib/ohai/plugins/hostname.rb b/lib/ohai/plugins/hostname.rb index 9016ebf1..779af3ec 100644 --- a/lib/ohai/plugins/hostname.rb +++ b/lib/ohai/plugins/hostname.rb @@ -1,6 +1,14 @@ # # Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Author:: Benjamin Black (<nostromo@gmail.com>) +# Author:: Bryan McLellan (<btm@loftninjas.org>) +# Author:: Daniel DeLeo (<dan@kallistec.com>) +# Author:: Doug MacEachern (<dougm@vmware.com>) +# Author:: James Gartrell (<jgartrel@gmail.com>) +# Copyright:: Copyright (c) 2008, 2009 Opscode, Inc. +# Copyright:: Copyright (c) 2009 Bryan McLellan +# Copyright:: Copyright (c) 2009 Daniel DeLeo +# Copyright:: Copyright (c) 2010 VMware, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/lib/ohai/plugins/hpux/cpu.rb b/lib/ohai/plugins/hpux/cpu.rb deleted file mode 100644 index 990b5ec1..00000000 --- a/lib/ohai/plugins/hpux/cpu.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::cpu" -end diff --git a/lib/ohai/plugins/hpux/filesystem.rb b/lib/ohai/plugins/hpux/filesystem.rb deleted file mode 100644 index fb0aaddc..00000000 --- a/lib/ohai/plugins/hpux/filesystem.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::filesystem" -end diff --git a/lib/ohai/plugins/hpux/memory.rb b/lib/ohai/plugins/hpux/memory.rb deleted file mode 100644 index e711fe25..00000000 --- a/lib/ohai/plugins/hpux/memory.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::memory" -end diff --git a/lib/ohai/plugins/hpux/network.rb b/lib/ohai/plugins/hpux/network.rb deleted file mode 100644 index 807b4a4a..00000000 --- a/lib/ohai/plugins/hpux/network.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::network" -end diff --git a/lib/ohai/plugins/hpux/platform.rb b/lib/ohai/plugins/hpux/platform.rb deleted file mode 100644 index 9f142810..00000000 --- a/lib/ohai/plugins/hpux/platform.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::platform" -end diff --git a/lib/ohai/plugins/hpux/ps.rb b/lib/ohai/plugins/hpux/ps.rb deleted file mode 100644 index 51e4e44f..00000000 --- a/lib/ohai/plugins/hpux/ps.rb +++ /dev/null @@ -1,27 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 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 do - provides "command/ps" - - depends 'command' - - collect_data do - command[:ps] = 'ps -ef' - end -end diff --git a/lib/ohai/plugins/hpux/uptime.rb b/lib/ohai/plugins/hpux/uptime.rb deleted file mode 100644 index 324ced96..00000000 --- a/lib/ohai/plugins/hpux/uptime.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 do - depends "sigar::uptime" -end diff --git a/lib/ohai/plugins/ip_scopes.rb b/lib/ohai/plugins/ip_scopes.rb index 62ab6cd0..261bea5b 100644 --- a/lib/ohai/plugins/ip_scopes.rb +++ b/lib/ohai/plugins/ip_scopes.rb @@ -15,11 +15,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -Ohai.plugin do +Ohai.plugin(:IpScopes) do provides "network_ip_scope", "privateaddress" - depends "domain", "fqdn" - depends "network", "counters/network" + depends "network/interfaces" collect_data do begin diff --git a/lib/ohai/plugins/java.rb b/lib/ohai/plugins/java.rb index 6a620a80..11a5a643 100644 --- a/lib/ohai/plugins/java.rb +++ b/lib/ohai/plugins/java.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Java) do provides "languages/java" depends "languages" diff --git a/lib/ohai/plugins/kernel.rb b/lib/ohai/plugins/kernel.rb index 17ae07aa..66af66c8 100644 --- a/lib/ohai/plugins/kernel.rb +++ b/lib/ohai/plugins/kernel.rb @@ -1,40 +1,203 @@ # # Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Author:: Benjamin Black (<nostromo@gmail.com>) +# Author:: Bryan McLellan (<btm@loftninjas.org>) +# Author:: Claire McQuin (<claire@opscode.com>) +# Author:: James Gartrell (<jgartrel@gmail.com>) +# Copyright:: Copyright (c) 2008, 2009, 2013 Opscode, Inc. +# Copyright:: Copyright (c) 2009 Bryan McLellan # 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. +# 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 do - provides "kernel" - provides "kernel/name", "kernel/release", "kernel/version", "kernel/machine", "kernel/modules" +Ohai.plugin(:Kernel) do + provides "kernel", "kernel/modules" - depends "languages/ruby" - - collect_data do + # common initial kernel attribute values + def init_kernel kernel Mash.new - case languages[:ruby][:host_os] - when /mswin|mingw32|windows/ - require_plugin "windows::kernel" - require_plugin "windows::kernel_devices" - else - [["uname -s", :name], ["uname -r", :release], - ["uname -v", :version], ["uname -m", :machine]].each do |command, node| - so = shell_out(command) - kernel[node] = so.stdout.split($/)[0] + [["uname -s", :name], ["uname -r", :release], + ["uname -v", :version], ["uname -m", :machine]].each do |cmd, property| + so = shell_out(cmd) + kernel[property] = so.stdout.split($/)[0] + end + kernel + end + + # common *bsd code for collecting modules data + def bsd_modules(path) + modules = Mash.new + so = shell_out("#{Ohai.abs_path(path)}") + so.stdout.lines do |line| + # 1 7 0xc0400000 97f830 kernel + if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/ + modules[$5] = { :size => $4, :refcount => $2 } + end + end + modules + end + + # windows + def machine_lookup(sys_type) + return "i386" if sys_type.eql?("X86-based PC") + return "x86_64" if sys_type.eql?("x64-based PC") + sys_type + end + + # windows + def os_lookup(sys_type) + return "Unknown" if sys_type.to_s.eql?("0") + return "Other" if sys_type.to_s.eql?("1") + return "MSDOS" if sys_type.to_s.eql?("14") + return "WIN3x" if sys_type.to_s.eql?("15") + return "WIN95" if sys_type.to_s.eql?("16") + return "WIN98" if sys_type.to_s.eql?("17") + return "WINNT" if sys_type.to_s.eql?("18") + return "WINCE" if sys_type.to_s.eql?("19") + return nil + end + + collect_data(:default) do + kernel init_kernel + end + + collect_data(:darwin) do + kernel init_kernel + kernel[:os] = kernel[:name] + + so = shell_out("sysctl -n hw.optional.x86_64") + if so.stdout.split($/)[0].to_i == 1 + kernel[:machine] = 'x86_64' + end + + modules = Mash.new + so = shell_out("kextstat -k -l") + so.stdout.lines do |line| + if line =~ /(\d+)\s+(\d+)\s+0x[0-9a-f]+\s+0x([0-9a-f]+)\s+0x[0-9a-f]+\s+([a-zA-Z0-9\.]+) \(([0-9\.]+)\)/ + kext[$4] = { :version => $5, :size => $3.hex, :index => $1, :refcount => $2 } + end + end + + kernel[:modules] = modules + end + + collect_data(:freebsd) do + kernel init_kernel + kernel[:os] = kernel[:name] + + so = shell_out("uname -i") + kernel[:ident] = so.stdout.split($/)[0] + so = shell_out("sysctl kern.securelevel") + kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel: (.+)$/ } + + kernel[:modules] = bsd_modules("/sbin/kldstat") + end + + collect_data(:linux) do + kernel init_kernel + + so = shell_out("uname -o") + kernel[:os] = so.stdout.split($/)[0] + + modules = Mash.new + so = shell_out("env lsmod") + so.stdout.lines do |line| + if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/ + modules[$1] = { :size => $2, :refcount => $3 } end - kernel[:modules] = Mash.new end + + kernel[:modules] = modules + end + + collect_data(:netbsd, :openbsd) do + kernel init_kernel + kernel[:os] = kernel[:name] + + so = shell_out("sysctl kern.securelevel") + kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ } + + kernel[:modules] = bsd_modules("/usr/bin/modstat") + end + + collect_data(:solaris2) do + kernel init_kernel + + so = shell_out("uname -s") + kernel[:os] = so.stdout.split($/)[0] + + modules = Mash.new + + so = shell_out("modinfo") + # EXAMPLE: + # Id Loadaddr Size Info Rev Module Name + # 6 1180000 4623 1 1 specfs (filesystem for specfs) + module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/ + so.stdout.lines do |line| + if mod = module_description.match(line) + modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]} + end + end + + kernel[:modules] = modules + end + + collect_data(:windows) do + require 'ruby-wmi' + WIN32OLE.codepage = WIN32OLE::CP_UTF8 + + kernel = Mash.new + + host = WMI::Win32_OperatingSystem.find(:first) + kernel[:os_info] = Mash.new + host.properties_.each do |p| + kernel[:os_info][p.name.wmi_underscore.to_sym] = host.send(p.name) + end + + kernel[:name] = "#{kernel[:os_info][:caption]}" + kernel[:release] = "#{kernel[:os_info][:version]}" + kernel[:version] = "#{kernel[:os_info][:version]} + ##{kernel[:os_info][:csd_version]} Build + ###{kernel[:os_info][:build_number]}" + kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os] + + host = WMI::Win32_ComputerSystem.find(:first) + kernel[:cs_info] = Mash.new + host.properties_.each do |p| + kernel[:cs_info][p.name.wmi_underscore.to_sym] = host.send(p.name) + end + + kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}") + + kext = Mash.new + pnp_drivers = Mash.new + + drivers = WMI::Win32_PnPSignedDriver.find(:all) + drivers.each do |driver| + pnp_drivers[driver.DeviceID] = Mash.new + driver.properties_.each do |p| + pnp_drivers[driver.DeviceID][p.name.wmi_underscore.to_sym] = driver.send(p.name) + end + if driver.DeviceName + kext[driver.DeviceName] = pnp_drivers[driver.DeviceID] + kext[driver.DeviceName][:version] = pnp_drivers[driver.DeviceID][:driver_version] + kext[driver.DeviceName][:date] = pnp_drivers[driver.DeviceID][:driver_date] ? pnp_drivers[driver.DeviceID][:driver_date].to_s[0..7] : nil + end + end + + kernel[:pnp_drivers] = pnp_drivers + kernel[:modules] = kext end end diff --git a/lib/ohai/plugins/keys.rb b/lib/ohai/plugins/keys.rb index 6de9286d..d786f4fd 100644 --- a/lib/ohai/plugins/keys.rb +++ b/lib/ohai/plugins/keys.rb @@ -17,7 +17,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Keys) do provides "keys" collect_data do diff --git a/lib/ohai/plugins/languages.rb b/lib/ohai/plugins/languages.rb index e7e1eda2..678c8a24 100644 --- a/lib/ohai/plugins/languages.rb +++ b/lib/ohai/plugins/languages.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Languages) do provides "languages" collect_data do diff --git a/lib/ohai/plugins/linode.rb b/lib/ohai/plugins/linode.rb index b21bf097..fb0fea19 100644 --- a/lib/ohai/plugins/linode.rb +++ b/lib/ohai/plugins/linode.rb @@ -14,11 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -Ohai.plugin do +Ohai.plugin(:Linode) do provides "linode" depends "kernel" - depends "network", "counters/network" + depends "network/interfaces" # Checks for matching linode kernel name # diff --git a/lib/ohai/plugins/linux/block_device.rb b/lib/ohai/plugins/linux/block_device.rb index ff8890aa..e8854e68 100644 --- a/lib/ohai/plugins/linux/block_device.rb +++ b/lib/ohai/plugins/linux/block_device.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:BlockDevice) do provides "block_device" - collect_data do + collect_data(:linux) do if File.exists?("/sys/block") block = Mash.new Dir["/sys/block/*"].each do |block_device_dir| diff --git a/lib/ohai/plugins/linux/cpu.rb b/lib/ohai/plugins/linux/cpu.rb index 5bc189bc..aeee390a 100644 --- a/lib/ohai/plugins/linux/cpu.rb +++ b/lib/ohai/plugins/linux/cpu.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:CPU) do provides "cpu" - collect_data do + collect_data(:linux) do cpuinfo = Mash.new real_cpu = Mash.new cpu_number = 0 diff --git a/lib/ohai/plugins/linux/filesystem.rb b/lib/ohai/plugins/linux/filesystem.rb index 41939c06..6a10d75c 100644 --- a/lib/ohai/plugins/linux/filesystem.rb +++ b/lib/ohai/plugins/linux/filesystem.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Filesystem) do provides "filesystem" - collect_data do + collect_data(:linux) do fs = Mash.new # Grab filesystem data from df diff --git a/lib/ohai/plugins/linux/kernel.rb b/lib/ohai/plugins/linux/kernel.rb deleted file mode 100644 index c2dd3e45..00000000 --- a/lib/ohai/plugins/linux/kernel.rb +++ /dev/null @@ -1,36 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 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 do - provides "kernel" - - collect_data do - so = shell_out("uname -o") - kernel[:os] = so.stdout.split(/\r?\n/)[0] - - kext = Mash.new - so = shell_out("env lsmod") - so.stdout.lines do |line| - if line =~ /([a-zA-Z0-9\_]+)\s+(\d+)\s+(\d+)/ - kext[$1] = { :size => $2, :refcount => $3 } - end - end - - kernel[:modules] = kext - end -end diff --git a/lib/ohai/plugins/linux/lsb.rb b/lib/ohai/plugins/linux/lsb.rb index a982fce4..7bd16b63 100644 --- a/lib/ohai/plugins/linux/lsb.rb +++ b/lib/ohai/plugins/linux/lsb.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:LSB) do provides "lsb" - collect_data do + collect_data(:linux) do lsb Mash.new if File.exists?("/etc/lsb-release") diff --git a/lib/ohai/plugins/linux/memory.rb b/lib/ohai/plugins/linux/memory.rb index d41fc783..e5c76801 100644 --- a/lib/ohai/plugins/linux/memory.rb +++ b/lib/ohai/plugins/linux/memory.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do - provides "memory" +Ohai.plugin(:Memory) do + provides "memory", "memory/swap" - collect_data do + collect_data(:linux) do memory Mash.new memory[:swap] = Mash.new diff --git a/lib/ohai/plugins/linux/network.rb b/lib/ohai/plugins/linux/network.rb index ad701b5d..c25e4986 100644 --- a/lib/ohai/plugins/linux/network.rb +++ b/lib/ohai/plugins/linux/network.rb @@ -16,10 +16,9 @@ # limitations under the License. # -require 'ipaddr' - -Ohai.plugin do - provides "network", "counters/network" +Ohai.plugin(:Network) do + provides "network", "network/interfaces" + provides "counters/network", "counters/network/interfaces" provides "ipaddress", "ip6address", "macaddress" def encaps_lookup(encap) @@ -34,6 +33,8 @@ Ohai.plugin do end collect_data do + require 'ipaddr' + iface = Mash.new net_counters = Mash.new diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb index 85450560..8d77a491 100644 --- a/lib/ohai/plugins/linux/platform.rb +++ b/lib/ohai/plugins/linux/platform.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Platform) do provides "platform", "platform_version", "platform_family" - depends 'linux::lsb' + depends "lsb" def get_redhatish_platform(contents) contents[/^Red Hat/i] ? "redhat" : contents[/(\w+)/i, 1].downcase @@ -29,7 +29,7 @@ Ohai.plugin do contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1] end - collect_data do + collect_data(:linux) do # platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching if File.exists?("/etc/oracle-release") contents = File.read("/etc/oracle-release").chomp @@ -99,7 +99,6 @@ Ohai.plugin do platform_version lsb[:release] end - case platform when /debian/, /ubuntu/, /linuxmint/, /raspbian/, /gcel/ platform_family "debian" diff --git a/lib/ohai/plugins/linux/ps.rb b/lib/ohai/plugins/linux/ps.rb deleted file mode 100644 index 013c1eb0..00000000 --- a/lib/ohai/plugins/linux/ps.rb +++ /dev/null @@ -1,27 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 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 do - provides "command/ps" - - depends 'command' - - collect_data do - command[:ps] = 'ps -ef' - end -end diff --git a/lib/ohai/plugins/linux/uptime.rb b/lib/ohai/plugins/linux/uptime.rb deleted file mode 100644 index d2ecdb1e..00000000 --- a/lib/ohai/plugins/linux/uptime.rb +++ /dev/null @@ -1,29 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 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 do - provides "uptime", "idletime", "uptime_seconds", "idletime_seconds" - - collect_data do - uptime, idletime = File.open("/proc/uptime").gets.split(" ") - uptime_seconds uptime.to_i - uptime seconds_to_human(uptime.to_i) - idletime_seconds idletime.to_i - idletime seconds_to_human(idletime.to_i) - end -end diff --git a/lib/ohai/plugins/linux/virtualization.rb b/lib/ohai/plugins/linux/virtualization.rb index 6a88aa5a..95b57ef4 100644 --- a/lib/ohai/plugins/linux/virtualization.rb +++ b/lib/ohai/plugins/linux/virtualization.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Virtualization) do provides "virtualization" - collect_data do + collect_data(:linux) do virtualization Mash.new # if it is possible to detect paravirt vs hardware virt, it should be put in diff --git a/lib/ohai/plugins/lua.rb b/lib/ohai/plugins/lua.rb index fb7a4325..0b1a269d 100644 --- a/lib/ohai/plugins/lua.rb +++ b/lib/ohai/plugins/lua.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Lua) do provides "languages/lua" depends "languages" diff --git a/lib/ohai/plugins/mono.rb b/lib/ohai/plugins/mono.rb index b51bd7e0..8a458bf1 100644 --- a/lib/ohai/plugins/mono.rb +++ b/lib/ohai/plugins/mono.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Mono) do provides "languages/mono" depends "languages" diff --git a/lib/ohai/plugins/netbsd/cpu.rb b/lib/ohai/plugins/netbsd/cpu.rb index fbced143..1b0a2667 100644 --- a/lib/ohai/plugins/netbsd/cpu.rb +++ b/lib/ohai/plugins/netbsd/cpu.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:CPU) do provides 'cpu' - collect_data do + collect_data(:netbsd) do cpuinfo = Mash.new # NetBSD provides some cpu information via sysctl, and a little via dmesg.boot diff --git a/lib/ohai/plugins/netbsd/filesystem.rb b/lib/ohai/plugins/netbsd/filesystem.rb index 225b8ef4..89a715b6 100644 --- a/lib/ohai/plugins/netbsd/filesystem.rb +++ b/lib/ohai/plugins/netbsd/filesystem.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Filesystem) do provides "filesystem" - collect_data do + collect_data(:netbsd) do fs = Mash.new # Grab filesystem data from df diff --git a/lib/ohai/plugins/netbsd/kernel.rb b/lib/ohai/plugins/netbsd/kernel.rb deleted file mode 100644 index 4da3c229..00000000 --- a/lib/ohai/plugins/netbsd/kernel.rb +++ /dev/null @@ -1,39 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "kernel" - - collect_data do - kernel[:os] = kernel[:name] - so = shell_out("sysctl kern.securelevel") - - # regex modified based on sample data in the test - kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ } - mod = Mash.new - so = shell_out("#{ Ohai.abs_path( "/usr/bin/modstat" )}") - so.stdout.lines do |line| - # 1 7 0xc0400000 97f830 kernel - if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/ - mod[$5] = { :size => $4, :refcount => $2 } - end - end - - kernel[:modules] = mod unless mod.empty? - end -end diff --git a/lib/ohai/plugins/netbsd/memory.rb b/lib/ohai/plugins/netbsd/memory.rb index 1326b983..02ddcf5c 100644 --- a/lib/ohai/plugins/netbsd/memory.rb +++ b/lib/ohai/plugins/netbsd/memory.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Memory) do provides "memory" - collect_data do + collect_data(:netbsd) do memory Mash.new memory[:swap] = Mash.new diff --git a/lib/ohai/plugins/netbsd/network.rb b/lib/ohai/plugins/netbsd/network.rb index e418995f..8f0cff56 100644 --- a/lib/ohai/plugins/netbsd/network.rb +++ b/lib/ohai/plugins/netbsd/network.rb @@ -16,10 +16,11 @@ # limitations under the License. # -Ohai.plugin do - provides "network", "counters/network" +Ohai.plugin(:Network) do + provides "network", "network/interfaces" + provides "counters/network", "counters/network/interfaces" - collect_data do + collect_data(:netbsd) do network Mash.new unless network network[:interfaces] = Mash.new unless network[:interfaces] counters Mash.new unless counters diff --git a/lib/ohai/plugins/netbsd/platform.rb b/lib/ohai/plugins/netbsd/platform.rb index 0bfaee77..9293787b 100644 --- a/lib/ohai/plugins/netbsd/platform.rb +++ b/lib/ohai/plugins/netbsd/platform.rb @@ -16,13 +16,14 @@ # limitations under the License. # -Ohai.plugin do - provides "platform", "platform_version" +Ohai.plugin(:Platform) do + provides "platform", "platform_version", "platform_family" - collect_data do + collect_data(:netbsd) do so = shell_out("uname -s") platform so.stdout.split($/)[0].downcase so = shell_out("uname -r") platform_version so.stdout.split($/)[0] + platform_family "netbsd" end end diff --git a/lib/ohai/plugins/netbsd/ps.rb b/lib/ohai/plugins/netbsd/ps.rb deleted file mode 100644 index d0f0fe0b..00000000 --- a/lib/ohai/plugins/netbsd/ps.rb +++ /dev/null @@ -1,28 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "command/ps" - - depends 'command' - - collect_data do - # ps -e requires procfs - command[:ps] = 'ps -ax' - end -end diff --git a/lib/ohai/plugins/netbsd/uptime.rb b/lib/ohai/plugins/netbsd/uptime.rb deleted file mode 100644 index db05656f..00000000 --- a/lib/ohai/plugins/netbsd/uptime.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "uptime", "uptime_seconds" - - # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009 - - collect_data do - so = shell_out("#{ Ohai.abs_path( "/sbin/sysctl" )} kern.boottime") - so.stdout.lines do |line| - if line =~ /kern.boottime:\D+(\d+)/ - uptime_seconds Time.new.to_i - $1.to_i - uptime seconds_to_human(uptime_seconds) - end - end - end -end diff --git a/lib/ohai/plugins/netbsd/virtualization.rb b/lib/ohai/plugins/netbsd/virtualization.rb index d9534e94..d2fabf25 100644 --- a/lib/ohai/plugins/netbsd/virtualization.rb +++ b/lib/ohai/plugins/netbsd/virtualization.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Virtualization) do provides "virtualization" - collect_data do + collect_data(:netbsd) do virtualization Mash.new # KVM Host support for FreeBSD is in development diff --git a/lib/ohai/plugins/network.rb b/lib/ohai/plugins/network.rb index 3a679103..b32c6fa4 100644 --- a/lib/ohai/plugins/network.rb +++ b/lib/ohai/plugins/network.rb @@ -18,12 +18,10 @@ require 'ipaddress' -Ohai.plugin do - provides "network", "counters/network" +Ohai.plugin(:NetworkAddresses) do provides "ipaddress", "ip6address", "macaddress" - depends "hostname" - depends_os "network" + depends "network/interfaces" FAMILIES = { "inet" => "default", diff --git a/lib/ohai/plugins/network_listeners.rb b/lib/ohai/plugins/network_listeners.rb index 6f97399f..fcfcf0ba 100644 --- a/lib/ohai/plugins/network_listeners.rb +++ b/lib/ohai/plugins/network_listeners.rb @@ -16,16 +16,15 @@ # limitations under the License. # -require 'sigar' - -Ohai.plugin do +Ohai.plugin(:NetworkListeners) do provides "network/listeners" depends "network", "counters/network" - flags = Sigar::NETCONN_TCP|Sigar::NETCONN_SERVER + collect_data(:aix, :hpux, :sigar) do + require 'sigar' + flags = Sigar::NETCONN_TCP|Sigar::NETCONN_SERVER - collect_data do network Mash.new unless network listeners = Mash.new diff --git a/lib/ohai/plugins/nodejs.rb b/lib/ohai/plugins/nodejs.rb index 42c8ae44..1ceef91e 100644 --- a/lib/ohai/plugins/nodejs.rb +++ b/lib/ohai/plugins/nodejs.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Nodejs) do provides "languages/nodejs" depends "languages" diff --git a/lib/ohai/plugins/ohai.rb b/lib/ohai/plugins/ohai.rb index 97092ab5..ca01e21e 100644 --- a/lib/ohai/plugins/ohai.rb +++ b/lib/ohai/plugins/ohai.rb @@ -16,15 +16,15 @@ # limitations under the License. # -require "ohai" - -Ohai.plugin do - provides "ohai" +Ohai.plugin(:Ohai) do + provides "chef_packages/ohai" collect_data do - self[:chef_packages] = Mash.new unless self[:chef_packages] - self[:chef_packages][:ohai] = Mash.new - self[:chef_packages][:ohai][:version] = Ohai::VERSION - self[:chef_packages][:ohai][:ohai_root] = Ohai::OHAI_ROOT + require 'ohai' + + chef_packages Mash.new unless chef_packages + chef_packages[:ohai] = Mash.new + chef_packages[:ohai][:version] = Ohai::VERSION + chef_packages[:ohai][:ohai_root] = Ohai::OHAI_ROOT end end diff --git a/lib/ohai/plugins/ohai_time.rb b/lib/ohai/plugins/ohai_time.rb index 6afb6860..9867ec7f 100644 --- a/lib/ohai/plugins/ohai_time.rb +++ b/lib/ohai/plugins/ohai_time.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:OhaiTime) do provides "ohai_time" collect_data do diff --git a/lib/ohai/plugins/openbsd/cpu.rb b/lib/ohai/plugins/openbsd/cpu.rb index ed69db61..91af3fe6 100644 --- a/lib/ohai/plugins/openbsd/cpu.rb +++ b/lib/ohai/plugins/openbsd/cpu.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:CPU) do provides 'cpu' - collect_data do + collect_data(:openbsd) do cpuinfo = Mash.new # OpenBSD provides most cpu information via sysctl, the only thing we need to diff --git a/lib/ohai/plugins/openbsd/filesystem.rb b/lib/ohai/plugins/openbsd/filesystem.rb index 225b8ef4..aa33f9b2 100644 --- a/lib/ohai/plugins/openbsd/filesystem.rb +++ b/lib/ohai/plugins/openbsd/filesystem.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Filesystem) do provides "filesystem" - collect_data do + collect_data(:openbsd) do fs = Mash.new # Grab filesystem data from df diff --git a/lib/ohai/plugins/openbsd/kernel.rb b/lib/ohai/plugins/openbsd/kernel.rb deleted file mode 100644 index bc41f620..00000000 --- a/lib/ohai/plugins/openbsd/kernel.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "kernel" - - collect_data do - kernel[:os] = kernel[:name] - so = shell_out("sysctl kern.securelevel") - - #modified regex to fit sample data - kernel[:securelevel] = so.stdout.split($/).select { |e| e =~ /kern.securelevel:\ (.+)$/ } - - mod = Mash.new - so = shell_out("#{ Ohai.abs_path( "/usr/bin/modstat" )}") - so.stdout.lines do |line| - # 1 7 0xc0400000 97f830 kernel - if line =~ /(\d+)\s+(\d+)\s+([0-9a-fx]+)\s+([0-9a-fx]+)\s+([a-zA-Z0-9\_]+)/ - mod[$5] = { :size => $4, :refcount => $2 } - end - end - - kernel[:modules] = mod unless mod.empty? - end -end diff --git a/lib/ohai/plugins/openbsd/memory.rb b/lib/ohai/plugins/openbsd/memory.rb index 8951da08..3ad60fbc 100644 --- a/lib/ohai/plugins/openbsd/memory.rb +++ b/lib/ohai/plugins/openbsd/memory.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do - provides "memory" +Ohai.plugin(:Memory) do + provides "memory", "memory/swap" - collect_data do + collect_data(:openbsd) do memory Mash.new memory[:swap] = Mash.new diff --git a/lib/ohai/plugins/openbsd/network.rb b/lib/ohai/plugins/openbsd/network.rb index d802f338..a19c4f1e 100644 --- a/lib/ohai/plugins/openbsd/network.rb +++ b/lib/ohai/plugins/openbsd/network.rb @@ -16,10 +16,11 @@ # limitations under the License. # -Ohai.plugin do - provides "network", "counters/network" +Ohai.plugin(:Network) do + provides "network", "network/interfaces" + provides "counters/network", "counters/network/interfaces" - collect_data do + collect_data(:openbsd) do network Mash.new unless network network[:interfaces] = Mash.new unless network[:interfaces] counters Mash.new unless counters diff --git a/lib/ohai/plugins/openbsd/platform.rb b/lib/ohai/plugins/openbsd/platform.rb index 0bfaee77..a99cf7a5 100644 --- a/lib/ohai/plugins/openbsd/platform.rb +++ b/lib/ohai/plugins/openbsd/platform.rb @@ -16,13 +16,14 @@ # limitations under the License. # -Ohai.plugin do - provides "platform", "platform_version" +Ohai.plugin(:Platform) do + provides "platform", "platform_version", "platform_family" - collect_data do + collect_data(:openbsd) do so = shell_out("uname -s") platform so.stdout.split($/)[0].downcase so = shell_out("uname -r") platform_version so.stdout.split($/)[0] + platform_family "openbsd" end end diff --git a/lib/ohai/plugins/openbsd/ps.rb b/lib/ohai/plugins/openbsd/ps.rb deleted file mode 100644 index 8bde6414..00000000 --- a/lib/ohai/plugins/openbsd/ps.rb +++ /dev/null @@ -1,28 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "command/ps" - - depends 'command' - - collect_data do - # ps -e requires procfs - command[:ps] = 'ps -ax' - end -end diff --git a/lib/ohai/plugins/openbsd/uptime.rb b/lib/ohai/plugins/openbsd/uptime.rb deleted file mode 100644 index 48f71908..00000000 --- a/lib/ohai/plugins/openbsd/uptime.rb +++ /dev/null @@ -1,33 +0,0 @@ -# -# Author:: Bryan McLellan (btm@loftninjas.org) -# Copyright:: Copyright (c) 2009 Bryan McLellan -# 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 do - provides "uptime", "uptime_seconds" - - # kern.boottime=Tue Nov 1 14:45:52 2011 - - collect_data do - so = shell_out("#{ Ohai.abs_path( "/sbin/sysctl" )} kern.boottime") - so.stdout.lines do |line| - if line =~ /kern.boottime=(.+)/ - uptime_seconds Time.new.to_i - Time.parse($1).to_i - uptime seconds_to_human(uptime_seconds) - end - end - end -end diff --git a/lib/ohai/plugins/openbsd/virtualization.rb b/lib/ohai/plugins/openbsd/virtualization.rb index 142fa648..45715887 100644 --- a/lib/ohai/plugins/openbsd/virtualization.rb +++ b/lib/ohai/plugins/openbsd/virtualization.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Virtualization) do provides "virtualization" - collect_data do + collect_data(:openbsd) do virtualization Mash.new # KVM Host support for FreeBSD is in development diff --git a/lib/ohai/plugins/openstack.rb b/lib/ohai/plugins/openstack.rb index 10c23433..afe14a1a 100644 --- a/lib/ohai/plugins/openstack.rb +++ b/lib/ohai/plugins/openstack.rb @@ -18,7 +18,7 @@ require 'ohai/mixin/ec2_metadata' extend Ohai::Mixin::Ec2Metadata -Ohai.plugin do +Ohai.plugin(:Openstack) do provides "openstack" # does it matter that it's not hitting latest? diff --git a/lib/ohai/plugins/os.rb b/lib/ohai/plugins/os.rb index 860475ee..631ed237 100644 --- a/lib/ohai/plugins/os.rb +++ b/lib/ohai/plugins/os.rb @@ -18,7 +18,7 @@ require 'ohai/os' -Ohai.plugin do +Ohai.plugin(:OS) do provides "os", "os_version" depends 'kernel' diff --git a/lib/ohai/plugins/passwd.rb b/lib/ohai/plugins/passwd.rb index fd7d0500..397b15c6 100644 --- a/lib/ohai/plugins/passwd.rb +++ b/lib/ohai/plugins/passwd.rb @@ -1,7 +1,7 @@ require 'etc' -Ohai.plugin do +Ohai.plugin(:Passwd) do provides 'etc', 'current_user' def fix_encoding(str) diff --git a/lib/ohai/plugins/perl.rb b/lib/ohai/plugins/perl.rb index 3b4b3282..30bd6e1a 100644 --- a/lib/ohai/plugins/perl.rb +++ b/lib/ohai/plugins/perl.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Perl) do provides "languages/perl" depends "languages" diff --git a/lib/ohai/plugins/php.rb b/lib/ohai/plugins/php.rb index 3cdb3543..7489b52f 100644 --- a/lib/ohai/plugins/php.rb +++ b/lib/ohai/plugins/php.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:PHP) do provides "languages/php" depends "languages" diff --git a/lib/ohai/plugins/platform.rb b/lib/ohai/plugins/platform.rb index 5d5a935e..07d8246e 100644 --- a/lib/ohai/plugins/platform.rb +++ b/lib/ohai/plugins/platform.rb @@ -16,16 +16,13 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Platform) do provides "platform", "platform_version", "platform_family" + depends "os", "os_version" - depends_os "platform" - - collect_data do + collect_data(:default) do platform os unless attribute?("platform") - platform_version os_version unless attribute?("platform_version") - platform_family platform unless attribute?("platform_family") end end diff --git a/lib/ohai/plugins/aix/ps.rb b/lib/ohai/plugins/ps.rb index 51e4e44f..ac0ee07d 100644 --- a/lib/ohai/plugins/aix/ps.rb +++ b/lib/ohai/plugins/ps.rb @@ -1,6 +1,8 @@ # # Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Bryan McLellan (<btm@loftninjas.org>) # Copyright:: Copyright (c) 2008 Opscode, Inc. +# Copyright:: Copyright (c) 2009 Bryan McLellan # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -11,17 +13,22 @@ # # 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. +# 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 do +Ohai.plugin(:PS) do provides "command/ps" + depends "command" - depends 'command' - - collect_data do + collect_data(:aix, :darwin, :hpux, :linux, :solaris2) do command[:ps] = 'ps -ef' end + + collect_data(:freebsd, :netbsd, :openbsd) do + # ps -e requires procfs + command[:ps] = 'ps -ax' + end end diff --git a/lib/ohai/plugins/python.rb b/lib/ohai/plugins/python.rb index b551a661..683042ba 100644 --- a/lib/ohai/plugins/python.rb +++ b/lib/ohai/plugins/python.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Python) do provides "languages/python" depends "languages" diff --git a/lib/ohai/plugins/rackspace.rb b/lib/ohai/plugins/rackspace.rb index 8f113611..b96ebdf9 100644 --- a/lib/ohai/plugins/rackspace.rb +++ b/lib/ohai/plugins/rackspace.rb @@ -14,11 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -Ohai.plugin do +Ohai.plugin(:Rackspace) do provides "rackspace" - depends "kernel" - depends "network", "counters/network" + depends "kernel", "network/interfaces" # Checks for matching rackspace kernel name # diff --git a/lib/ohai/plugins/root_group.rb b/lib/ohai/plugins/root_group.rb index 212e4e05..1e5145e9 100644 --- a/lib/ohai/plugins/root_group.rb +++ b/lib/ohai/plugins/root_group.rb @@ -15,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -Ohai.plugin do +Ohai.plugin(:RootGroup) do provides 'root_group' collect_data do diff --git a/lib/ohai/plugins/ruby.rb b/lib/ohai/plugins/ruby.rb index 13c94bcb..bbb08397 100644 --- a/lib/ohai/plugins/ruby.rb +++ b/lib/ohai/plugins/ruby.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Ruby) do provides "languages/ruby" depends "languages" diff --git a/lib/ohai/plugins/sigar/cpu.rb b/lib/ohai/plugins/sigar/cpu.rb index 66d09609..c61da5a0 100644 --- a/lib/ohai/plugins/sigar/cpu.rb +++ b/lib/ohai/plugins/sigar/cpu.rb @@ -16,12 +16,12 @@ # limitations under the License. # -require "sigar" - -Ohai.plugin do +Ohai.plugin(:CPU) do provides "cpu" - collect_data do + collect_data(:aix, :hpux, :sigar) do + require 'sigar' + sigar = Sigar.new cpuinfo = Mash.new diff --git a/lib/ohai/plugins/sigar/filesystem.rb b/lib/ohai/plugins/sigar/filesystem.rb index 603b4892..e243c4ce 100644 --- a/lib/ohai/plugins/sigar/filesystem.rb +++ b/lib/ohai/plugins/sigar/filesystem.rb @@ -16,16 +16,15 @@ # limitations under the License. # -require "sigar" - -Ohai.plugin do +Ohai.plugin(:Filesystem) do provides "filesystem" - collect_data do - fs = Mash.new - + collect_data(:aix, :hpux, :sigar) do + require "sigar" sigar = Sigar.new + fs = Mash.new + sigar.file_system_list.each do |fsys| filesystem = fsys.dev_name fs[filesystem] = Mash.new diff --git a/lib/ohai/plugins/sigar/memory.rb b/lib/ohai/plugins/sigar/memory.rb index 95daef24..7390cac5 100644 --- a/lib/ohai/plugins/sigar/memory.rb +++ b/lib/ohai/plugins/sigar/memory.rb @@ -16,12 +16,11 @@ # limitations under the License. # -require "sigar" - -Ohai.plugin do +Ohai.plugin(:Memory) do provides "memory" - collect_data do + collect_data(:aix, :hpux, :sigar) do + require "sigar" sigar = Sigar.new memory Mash.new diff --git a/lib/ohai/plugins/sigar/network.rb b/lib/ohai/plugins/sigar/network.rb index b683986c..a6029ac3 100644 --- a/lib/ohai/plugins/sigar/network.rb +++ b/lib/ohai/plugins/sigar/network.rb @@ -18,10 +18,9 @@ #http://github.com/mdkent/ohai/commit/92f51aa18b6add9682510a87dcf94835ea72b04d -require "sigar" - -Ohai.plugin do - provides "network", "counters/network" +Ohai.plugin(:Network) do + provides "network", "network/interfaces" + provides "counters/network", "counters/network/interfaces" def encaps_lookup(encap) return "Loopback" if encap.eql?("Local Loopback") @@ -33,31 +32,21 @@ Ohai.plugin do encap end - collect_data do - sigar = Sigar.new - network Mash.new unless network - network[:interfaces] = Mash.new unless network[:interfaces] - counters Mash.new unless counters - counters[:network] = Mash.new unless counters[:network] - - ninfo = sigar.net_info - - network[:default_interface] = ninfo.default_gateway_interface - - network[:default_gateway] = ninfo.default_gateway - + def fetch_interfaces(sigar) iface = Mash.new - net_counters = Mash.new sigar.net_interface_list.each do |cint| iface[cint] = Mash.new + if cint =~ /^(\w+)(\d+.*)/ iface[cint][:type] = $1 iface[cint][:number] = $2 end + ifconfig = sigar.net_interface_config(cint) iface[cint][:encapsulation] = encaps_lookup(ifconfig.type) + iface[cint][:addresses] = Mash.new # Backwards compat: loopback has no hwaddr if (ifconfig.flags & Sigar::IFF_LOOPBACK) == 0 @@ -72,14 +61,17 @@ Ohai.plugin do end iface[cint][:addresses][ifconfig.address]["netmask"] = ifconfig.netmask end - iface[cint][:flags] = Sigar.net_interface_flags_to_s(ifconfig.flags).split(' ') - iface[cint][:mtu] = ifconfig.mtu.to_s - iface[cint][:queuelen] = ifconfig.tx_queue_len.to_s + if ifconfig.prefix6_length != 0 iface[cint][:addresses][ifconfig.address6] = { "family" => "inet6" } iface[cint][:addresses][ifconfig.address6]["prefixlen"] = ifconfig.prefix6_length.to_s iface[cint][:addresses][ifconfig.address6]["scope"] = Sigar.net_scope_to_s(ifconfig.scope6) end + + iface[cint][:flags] = Sigar.net_interface_flags_to_s(ifconfig.flags).split(' ') + iface[cint][:mtu] = ifconfig.mtu.to_s + iface[cint][:queuelen] = ifconfig.tx_queue_len.to_s + net_counters[cint] = Mash.new unless net_counters[cint] if (!cint.include?(":")) ifstat = sigar.net_interface_stat(cint) @@ -103,8 +95,75 @@ Ohai.plugin do #64-bit AIX for example requires 64-bit caller end - counters[:network][:interfaces] = net_counters + [iface, net_counters] + end + # sigar-only, from network_route plugin + def flags(flags) + f = "" + if (flags & Sigar::RTF_UP) != 0 + f += "U" + end + if (flags & Sigar::RTF_GATEWAY) != 0 + f += "G" + end + if (flags & Sigar::RTF_HOST) != 0 + f += "H" + end + f + end + + # From sigar: include/sigar.h sigar_net_route_t + SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname] + + collect_data(:aix, :hpux) do + require "sigar" + sigar = Sigar.new + + network Mash.new unless network + network[:interfaces] = Mash.new unless network[:interfaces] + counters Mash.new unless counters + counters[:network] = Mash.new unless counters[:network] + + ninfo = sigar.net_info + network[:default_interface] = ninfo.default_gateway_interface + network[:default_gateway] = ninfo.default_gateway + + iface, net_counters = fetch_interfaces(sigar) + counters[:network][:interfaces] = net_counters network["interfaces"] = iface end + + collect_data(:sigar) do + require "sigar" + sigar = Sigar.new + + network Mash.new unless network + network[:interfaces] = Mash.new unless network[:interfaces] + counters Mash.new unless counters + counters[:network] = Mash.new unless counters[:network] + + ninfo = sigar.net_info + network[:default_interface] = ninfo.default_gateway_interface + network[:default_gateway] = ninfo.default_gateway + + iface, net_counters = fetch_interfaces(sigar) + counters[:network][:interfaces] = net_counters + network[:interfaces] = iface + + sigar.net_route_list.each do |route| + next unless network[:interfaces][route.ifname] # this + # should never happen + network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route] + route_data={} + SIGAR_ROUTE_METHODS.each do |m| + if(m == :flags) + route_data[m]=flags(route.send(m)) + else + route_data[m]=route.send(m) + end + end + network[:interfaces][route.ifname][:route][route.destination] = route_data + end + end end diff --git a/lib/ohai/plugins/sigar/network_route.rb b/lib/ohai/plugins/sigar/network_route.rb index 022112db..d06352aa 100644 --- a/lib/ohai/plugins/sigar/network_route.rb +++ b/lib/ohai/plugins/sigar/network_route.rb @@ -19,8 +19,6 @@ require "sigar" Ohai.plugin do - depends "network" - provides "network" def flags(flags) @@ -40,12 +38,9 @@ Ohai.plugin do # From sigar: include/sigar.h sigar_net_route_t SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, :refcnt, :use, :metric, :mtu, :window, :irtt, :ifname] - collect_data do - sigar=Sigar.new - network Mash.new unless network - network[:interfaces] = Mash.new unless network[:interfaces] - counters Mash.new unless counters - counters[:network] = Mash.new unless counters[:network] + collect_data(:sigar) do + require "sigar" + sigar = Sigar.new sigar.net_route_list.each do |route| next unless network[:interfaces][route.ifname] # this should never happen diff --git a/lib/ohai/plugins/sigar/platform.rb b/lib/ohai/plugins/sigar/platform.rb index cbdf283e..c90a4115 100644 --- a/lib/ohai/plugins/sigar/platform.rb +++ b/lib/ohai/plugins/sigar/platform.rb @@ -16,15 +16,15 @@ # limitations under the License. # -require "sigar" +Ohai.plugin(:Platform) do + provides "platform", "platform_version", "platform_family" -Ohai.plugin do - provides "platform", "platform_version" - - collect_data do + collect_data(:aix, :hpux, :sigar) do + require "sigar" sys = Sigar.new.sys_info platform sys.name.downcase platform_version sys.version + platform_family platform end end diff --git a/lib/ohai/plugins/sigar/uptime.rb b/lib/ohai/plugins/sigar/uptime.rb deleted file mode 100644 index d1beca2c..00000000 --- a/lib/ohai/plugins/sigar/uptime.rb +++ /dev/null @@ -1,30 +0,0 @@ -# -# Author:: Doug MacEachern <dougm@vmware.com> -# Copyright:: Copyright (c) 2010 VMware, 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 "sigar" - -Ohai.plugin do - provides "uptime", "uptime_seconds" - - collect_data do - sigar = Sigar.new - uptime = sigar.uptime.uptime - uptime_seconds uptime.to_i * 1000 - uptime seconds_to_human(uptime.to_i) - end -end diff --git a/lib/ohai/plugins/solaris2/dmi.rb b/lib/ohai/plugins/solaris2/dmi.rb index c3010771..8308bc78 100644 --- a/lib/ohai/plugins/solaris2/dmi.rb +++ b/lib/ohai/plugins/solaris2/dmi.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:DMI) do depends "dmi" - collect_data do + collect_data(:solaris2) do # if we already have a "dmi" with keys (presumably from dmidecode), don't try smbios # note that a single key just means dmidecode exited with its version if (dmi.class.to_s == 'Mash') and (dmi.keys.length > 1) diff --git a/lib/ohai/plugins/solaris2/filesystem.rb b/lib/ohai/plugins/solaris2/filesystem.rb index 0d73ff4b..2bf5e505 100644 --- a/lib/ohai/plugins/solaris2/filesystem.rb +++ b/lib/ohai/plugins/solaris2/filesystem.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Filesystem) do provides "filesystem" - collect_data do + collect_data(:solaris2) do fs = Mash.new # Grab filesystem data from df diff --git a/lib/ohai/plugins/solaris2/kernel.rb b/lib/ohai/plugins/solaris2/kernel.rb deleted file mode 100644 index 9e14f458..00000000 --- a/lib/ohai/plugins/solaris2/kernel.rb +++ /dev/null @@ -1,41 +0,0 @@ -# -# Author:: Benjamin Black (<nostromo@gmail.com>) -# Copyright:: Copyright (c) 2009 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 do - provides "kernel/os" - - collect_data do - so = shell_out("uname -s") - kernel[:os] = so.stdout.split($/)[0] - - modules = Mash.new - - so = shell_out("modinfo") - # EXAMPLE: - # Id Loadaddr Size Info Rev Module Name - # 6 1180000 4623 1 1 specfs (filesystem for specfs) - module_description = /[\s]*([\d]+)[\s]+([a-f\d]+)[\s]+([a-f\d]+)[\s]+(?:[\-\d]+)[\s]+(?:[\d]+)[\s]+([\S]+)[\s]+\((.+)\)$/ - so.stdout.lines do |line| - if mod = module_description.match(line) - modules[mod[4]] = { :id => mod[1].to_i, :loadaddr => mod[2], :size => mod[3].to_i(16), :description => mod[5]} - end - end - - kernel[:modules] = modules - end -end diff --git a/lib/ohai/plugins/solaris2/network.rb b/lib/ohai/plugins/solaris2/network.rb index 2cf3907d..6a69b4a6 100644 --- a/lib/ohai/plugins/solaris2/network.rb +++ b/lib/ohai/plugins/solaris2/network.rb @@ -53,10 +53,9 @@ # srcof qfe1 # inet6 fe80::203:baff:fe17:4444/128 -require 'scanf' - -Ohai.plugin do - provides "network" +Ohai.plugin(:Network) do + provides "network", "network/interfaces" + provides "counters/network", "counters/network/interfaces" def encaps_lookup(ifname) return "Ethernet" if ifname.eql?("e1000g") @@ -74,7 +73,9 @@ Ohai.plugin do nil end - collect_data do + collect_data(:solaris2) do + require 'scanf' + iface = Mash.new network Mash.new unless network network[:interfaces] = Mash.new unless network[:interfaces] diff --git a/lib/ohai/plugins/solaris2/platform.rb b/lib/ohai/plugins/solaris2/platform.rb index a9172fcd..ea10e7a8 100644 --- a/lib/ohai/plugins/solaris2/platform.rb +++ b/lib/ohai/plugins/solaris2/platform.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do - provides "platform", "platform_version", "platform_build" +Ohai.plugin(:Platform) do + provides "platform", "platform_version", "platform_build", "platform_family" - collect_data do + collect_data(:solaris2) do if File.exists?("/sbin/uname") uname_exec = "/sbin/uname" else @@ -59,5 +59,7 @@ Ohai.plugin do end end end + + platform_family platform end end diff --git a/lib/ohai/plugins/solaris2/ps.rb b/lib/ohai/plugins/solaris2/ps.rb deleted file mode 100644 index 51e4e44f..00000000 --- a/lib/ohai/plugins/solaris2/ps.rb +++ /dev/null @@ -1,27 +0,0 @@ -# -# Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 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 do - provides "command/ps" - - depends 'command' - - collect_data do - command[:ps] = 'ps -ef' - end -end diff --git a/lib/ohai/plugins/solaris2/uptime.rb b/lib/ohai/plugins/solaris2/uptime.rb deleted file mode 100644 index e44632b9..00000000 --- a/lib/ohai/plugins/solaris2/uptime.rb +++ /dev/null @@ -1,38 +0,0 @@ -# -# Author:: Kurt Yoder (<ktyopscode@yoderhome.com>) -# Copyright:: Copyright (c) 2008 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 'date' -# It would be far better if we could include sys/uptime from sys-uptime RubyGem -# It would also be good if we could pull idle time; how do we do this on Solaris? - -Ohai.plugin do - provides "uptime", "uptime_seconds" - - collect_data do - # Example output: - # $ who -b - # . system boot Jul 9 17:51 - so = shell_out("who -b") - so.stdout.lines do |line| - if line =~ /.* boot (.+)/ - uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i - uptime seconds_to_human(uptime_seconds) - break - end - end - end -end diff --git a/lib/ohai/plugins/solaris2/virtualization.rb b/lib/ohai/plugins/solaris2/virtualization.rb index ec38fd64..af3ea7c1 100644 --- a/lib/ohai/plugins/solaris2/virtualization.rb +++ b/lib/ohai/plugins/solaris2/virtualization.rb @@ -18,10 +18,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Virtualization) do provides "virtualization" - collect_data do + collect_data(:solaris2) do virtualization Mash.new # Detect KVM/QEMU from cpuinfo, report as KVM diff --git a/lib/ohai/plugins/solaris2/zpools.rb b/lib/ohai/plugins/solaris2/zpools.rb index e6f6e469..f0867cd5 100644 --- a/lib/ohai/plugins/solaris2/zpools.rb +++ b/lib/ohai/plugins/solaris2/zpools.rb @@ -16,10 +16,10 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:Zpools) do provides "zpools" - collect_data do + collect_data(:solaris2) do pools = Mash.new # Grab ZFS zpools overall health and attributes diff --git a/lib/ohai/plugins/ssh_host_key.rb b/lib/ohai/plugins/ssh_host_key.rb index e23ab523..82d89308 100644 --- a/lib/ohai/plugins/ssh_host_key.rb +++ b/lib/ohai/plugins/ssh_host_key.rb @@ -16,7 +16,7 @@ # limitations under the License. # -Ohai.plugin do +Ohai.plugin(:SSHHostKey) do provides "keys/ssh" depends "keys" diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb index c5f9c58f..a29a0680 100644 --- a/lib/ohai/plugins/uptime.rb +++ b/lib/ohai/plugins/uptime.rb @@ -1,19 +1,110 @@ # # Author:: Adam Jacob (<adam@opscode.com>) -# Copyright:: Copyright (c) 2008 Opscode, Inc. +# Author:: Bryan McLellan (<btm@loftninjas.org>) +# Author:: Claire McQuin (<claire@opscode.com>) +# Author:: Doug MacEachern (<dougm@vmware.com>) +# Author:: Kurt Yoder (<ktyopscode@yoderhome.com>) +# Author:: Paul Mooring (<paul@opscode.com>) +# Copyright:: Copyright (c) 2008, 2012, 2013 Opscode, Inc. +# Copyright:: Copyright (c) 2009 Bryan McLellan +# Copyright:: Copyright (c) 2010 VMware, 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. +# 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 'ohai/mixin/seconds_to_human' + +Ohai.plugin(:Uptime) do + provides "uptime", "uptime_seconds" + provides "idletime", "idletime_seconds" # linux only + + def collect_uptime(path) + # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009 + so = shell_out("#{Ohai.abs_path(path)} kern.boottime") + so.stdout.lines do |line| + if line =~ /kern.boottime:\D+(\d+)/ + usec = Time.new.to_i - $1.to_i + return [usec, seconds_to_human(usec)] + end + end + return [nil, nil] + end + + collect_data(:aix, :hpux, :sigar) do + require 'sigar' + + sigar = Sigar.new + uptime = sigar.uptime.uptime + uptime_seconds uptime.to_i * 1000 + uptime seconds_to_human(uptime.to_i) + end + + collect_data(:darwin) do + data = collect_uptime("/usr/sbin/sysctl") + uptime_seconds data.first + uptime data.last + end + + collect_data(:freebsd, :netbsd) do + data = collect_uptime("/sbin/sysctl") + uptime_seconds data.first + uptime data.last + end + + collect_data(:linux) do + uptime, idletime = File.open("/proc/uptime").gets.split(" ") + uptime_seconds uptime.to_i + uptime seconds_to_human(uptime.to_i) + idletime_seconds idletime.to_i + idletime seconds_to_human(idletime.to_i) + end + + collect_data(:openbsd) do + # kern.boottime=Tue Nov 1 14:45:52 2011 + so = shell_out("#{ Ohai.abs_path( "/sbin/sysctl" )} + #kern.boottime") + so.stdout.lines do |line| + if line =~ /kern.boottime=(.+)/ + uptime_seconds Time.new.to_i - Time.parse($1).to_i + uptime seconds_to_human(uptime_seconds) + end + end + end + + collect_data(:solaris2) do + require 'date' + + # Example output: + # $ who -b + # . system boot Jul 9 17:51 + so = shell_out("who -b") + so.stdout.lines do |line| + if line =~ /.* boot (.+)/ + uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i + uptime seconds_to_human(uptime_seconds) + break + end + end + end + + collect_data(:windows) do + require 'ruby-wmi' + + uptime_seconds ::WMI::Win32_PerfFormattedData_PerfOS_System.find(:first).SystemUpTime.to_i + uptime seconds_to_human(uptime_seconds) + end + +end diff --git a/lib/ohai/plugins/virtualization.rb b/lib/ohai/plugins/virtualization.rb index 4c9a0d91..310bdeeb 100644 --- a/lib/ohai/plugins/virtualization.rb +++ b/lib/ohai/plugins/virtualization.rb @@ -16,10 +16,12 @@ # limitations under the License. # -Ohai.plugin do - provides "virtualization" +Ohai.plugin(:VirtualizationInfo) do + %w{ uri capabilities nodeinfo domains networks storage }.each do |info| + provides "virtualization/#{info}" + end - depends_os "virtualization" + depends "virtualization" collect_data do unless virtualization.nil? || !(virtualization[:role].eql?("host")) diff --git a/lib/ohai/plugins/windows/cpu.rb b/lib/ohai/plugins/windows/cpu.rb index 4ffa9328..5c52a4d7 100644 --- a/lib/ohai/plugins/windows/cpu.rb +++ b/lib/ohai/plugins/windows/cpu.rb @@ -16,12 +16,12 @@ # limitations under the License. # -require 'ruby-wmi' - -Ohai.plugin do +Ohai.plugin(:CPU) do provides "cpu" - collect_data do + collect_data(:windows) do + require 'ruby-wmi' + cpuinfo = Mash.new cpu_number = 0 index = 0 diff --git a/lib/ohai/plugins/windows/filesystem.rb b/lib/ohai/plugins/windows/filesystem.rb index 7aec0c1e..9a7e7dea 100644 --- a/lib/ohai/plugins/windows/filesystem.rb +++ b/lib/ohai/plugins/windows/filesystem.rb @@ -16,12 +16,12 @@ # limitations under the License. # -require 'ruby-wmi' - -Ohai.plugin do +Ohai.plugin(:Filesystem) do provides "filesystem" - collect_data do + collect_data(:windows) do + require 'ruby-wmi' + fs = Mash.new ld_info = Mash.new diff --git a/lib/ohai/plugins/windows/kernel.rb b/lib/ohai/plugins/windows/kernel.rb deleted file mode 100644 index a5c73167..00000000 --- a/lib/ohai/plugins/windows/kernel.rb +++ /dev/null @@ -1,64 +0,0 @@ -# -# Author:: James Gartrell (<jgartrel@gmail.com>) -# Copyright:: Copyright (c) 2009 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 'ruby-wmi' - -Ohai.plugin do - provides "kernel" - - WIN32OLE.codepage = WIN32OLE::CP_UTF8 - - def machine_lookup(sys_type) - return "i386" if sys_type.eql?("X86-based PC") - return "x86_64" if sys_type.eql?("x64-based PC") - sys_type - end - - def os_lookup(sys_type) - return "Unknown" if sys_type.to_s.eql?("0") - return "Other" if sys_type.to_s.eql?("1") - return "MSDOS" if sys_type.to_s.eql?("14") - return "WIN3x" if sys_type.to_s.eql?("15") - return "WIN95" if sys_type.to_s.eql?("16") - return "WIN98" if sys_type.to_s.eql?("17") - return "WINNT" if sys_type.to_s.eql?("18") - return "WINCE" if sys_type.to_s.eql?("19") - return nil - end - - collect_data do - host = WMI::Win32_OperatingSystem.find(:first) - kernel[:os_info] = Mash.new - host.properties_.each do |p| - kernel[:os_info][p.name.wmi_underscore.to_sym] = host.send(p.name) - end - - kernel[:name] = "#{kernel[:os_info][:caption]}" - kernel[:release] = "#{kernel[:os_info][:version]}" - kernel[:version] = "#{kernel[:os_info][:version]} #{kernel[:os_info][:csd_version]} Build #{kernel[:os_info][:build_number]}" - kernel[:os] = os_lookup(kernel[:os_info][:os_type]) || languages[:ruby][:host_os] - - host = WMI::Win32_ComputerSystem.find(:first) - kernel[:cs_info] = Mash.new - host.properties_.each do |p| - kernel[:cs_info][p.name.wmi_underscore.to_sym] = host.send(p.name) - end - - kernel[:machine] = machine_lookup("#{kernel[:cs_info][:system_type]}") - end -end diff --git a/lib/ohai/plugins/windows/network.rb b/lib/ohai/plugins/windows/network.rb index 0720672a..d1454805 100644 --- a/lib/ohai/plugins/windows/network.rb +++ b/lib/ohai/plugins/windows/network.rb @@ -16,17 +16,18 @@ # limitations under the License. # -require 'ruby-wmi' - -Ohai.plugin do - provides "network" +Ohai.plugin(:Network) do + provides "network", "network/interfaces" + provides "counters/network", "counters/network/interfaces" def encaps_lookup(encap) return "Ethernet" if encap.eql?("Ethernet 802.3") encap end - collect_data do + collect_data(:windows) do + require 'ruby-wmi' + iface = Mash.new iface_config = Mash.new iface_instance = Mash.new diff --git a/lib/ohai/plugins/windows/platform.rb b/lib/ohai/plugins/windows/platform.rb index 690daa9b..2d2951c1 100644 --- a/lib/ohai/plugins/windows/platform.rb +++ b/lib/ohai/plugins/windows/platform.rb @@ -22,10 +22,10 @@ # platforms built upon the Windows_NT kernel and have access to win32 or win64 # subsystems. -Ohai.plugin do - provides "platform" +Ohai.plugin(:Platform) do + provides "platform", "platform_version", "platform_family" - collect_data do + collect_data (:windows)do platform os platform_version kernel['release'] platform_family "windows" diff --git a/lib/ohai/plugins/windows/uptime.rb b/lib/ohai/plugins/windows/uptime.rb deleted file mode 100644 index 59d79529..00000000 --- a/lib/ohai/plugins/windows/uptime.rb +++ /dev/null @@ -1,27 +0,0 @@ -# -# Author:: Paul Mooring (paul@opscode.com) -# Copyright:: Copyright (c) 2012 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 'ruby-wmi' - -Ohai.plugin do - provides "uptime", "uptime_seconds" - - collect_data do - uptime_seconds ::WMI::Win32_PerfFormattedData_PerfOS_System.find(:first).SystemUpTime.to_i - uptime seconds_to_human(uptime_seconds) - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 89017881..516a6ddc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ require 'rspec' -# require 'pry' -# require 'pry-debugger' +require 'pry' +require 'pry-debugger' # require 'pry-stack_explorer' $:.unshift(File.expand_path("../..", __FILE__)) diff --git a/spec/unit/plugins/azure_spec.rb b/spec/unit/plugins/azure_spec.rb index 375b4204..64aa3785 100644 --- a/spec/unit/plugins/azure_spec.rb +++ b/spec/unit/plugins/azure_spec.rb @@ -25,6 +25,12 @@ describe Ohai::System, "plugin azure" do @plugin = get_plugin("azure") end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Azure) + Ohai::NamedPlugin.send(:remove_const, :Azure) + end + end + describe "with azure cloud file" do before(:each) do File.stub(:exist?).with('/etc/chef/ohai/hints/azure.json').and_return(true) diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb index 33daa21c..2077f119 100644 --- a/spec/unit/plugins/c_spec.rb +++ b/spec/unit/plugins/c_spec.rb @@ -122,6 +122,12 @@ describe Ohai::System, "plugin c" do @plugin.stub(:shell_out).with("what /opt/ansic/bin/cc").and_return(mock_shell_out(0, C_HPUX, "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :C) + Ohai::NamedPlugin.send(:remove_const, :C) + end + end + #gcc it "should get the gcc version from running gcc -v" do @plugin.should_receive(:shell_out).with("gcc -v").and_return(mock_shell_out(0, "", C_GCC)) diff --git a/spec/unit/plugins/chef_spec.rb b/spec/unit/plugins/chef_spec.rb index 0d9a206c..fc6d083a 100644 --- a/spec/unit/plugins/chef_spec.rb +++ b/spec/unit/plugins/chef_spec.rb @@ -27,6 +27,12 @@ begin before(:each) do @plugin = get_plugin("chef") end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Chef) + Ohai::NamedPlugin.send(:remove_const, :Chef) + end + end it "should set [:chef_packages][:chef][:version] to the current chef version", :if => defined?(Chef) do @plugin.run diff --git a/spec/unit/plugins/cloud_spec.rb b/spec/unit/plugins/cloud_spec.rb index e4dc1ef3..111eee15 100644 --- a/spec/unit/plugins/cloud_spec.rb +++ b/spec/unit/plugins/cloud_spec.rb @@ -18,10 +18,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin cloud" do - before do + before(:each) do @plugin = get_plugin("cloud") end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Cloud) + Ohai::NamedPlugin.send(:remove_const, :Cloud) + end + end + describe "with no cloud mashes" do it "doesn't populate the cloud data" do @plugin[:ec2] = nil diff --git a/spec/unit/plugins/darwin/cpu_spec.rb b/spec/unit/plugins/darwin/cpu_spec.rb index 2ea93ea9..ae355f45 100644 --- a/spec/unit/plugins/darwin/cpu_spec.rb +++ b/spec/unit/plugins/darwin/cpu_spec.rb @@ -22,11 +22,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin cpu plugin" do before(:each) do @plugin = get_plugin("darwin/cpu") - + @plugin.stub(:collect_os).and_return(:darwin) @plugin.stub(:shell_out).with("sysctl -n hw.physicalcpu").and_return(mock_shell_out(0, "1", "")) @plugin.stub(:shell_out).with("sysctl -n hw.logicalcpu").and_return(mock_shell_out(0, "2", "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :CPU) + Ohai::NamedPlugin.send(:remove_const, :CPU) + end + end + it "should set cpu[:total] to 2" do @plugin.run @plugin[:cpu][:total].should == 2 diff --git a/spec/unit/plugins/darwin/kernel_spec.rb b/spec/unit/plugins/darwin/kernel_spec.rb index 7b36d4b4..6cc587e5 100644 --- a/spec/unit/plugins/darwin/kernel_spec.rb +++ b/spec/unit/plugins/darwin/kernel_spec.rb @@ -21,12 +21,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin kernel plugin" do before(:each) do - @plugin = get_plugin("darwin/kernel") - @plugin[:kernel] = Mash.new - @plugin[:kernel][:name] = "darwin" + @plugin = get_plugin("kernel") + @plugin.stub(:collect_os).and_return(:darwin) + @plugin.stub(:init_kernel).and_return({}) @plugin.should_receive(:shell_out).with("kextstat -k -l").and_return(mock_shell_out(0, "", "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Kernel) + Ohai::NamedPlugin.send(:remove_const, :Kernel) + end + end + it "should not set kernel_machine to x86_64" do @plugin.stub(:shell_out).with("sysctl -n hw.optional.x86_64").and_return(mock_shell_out(0, "0", "")) @plugin.run diff --git a/spec/unit/plugins/darwin/network_spec.rb b/spec/unit/plugins/darwin/network_spec.rb index 6e949456..425a4b6d 100644 --- a/spec/unit/plugins/darwin/network_spec.rb +++ b/spec/unit/plugins/darwin/network_spec.rb @@ -413,6 +413,7 @@ net.smb.fs.tcprcvbuf: 261120 DARWIN_SYSCTL @plugin = get_plugin("darwin/network") + @plugin.stub(:collect_os).and_return(:darwin) # @stdin_ifconfig = StringIO.new # @stdin_arp = StringIO.new @@ -426,14 +427,11 @@ net.smb.fs.tcprcvbuf: 261120 @plugin.stub(:shell_out).with("route -n get default").and_return(mock_shell_out(0, @darwin_route, "")) @plugin.stub(:shell_out).with("netstat -i -d -l -b -n") + end - Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(3).times - - %w{ darwin/hostname hostname network }.each do |plgn| - p = get_plugin(plgn) - p.stub(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", "")) - p.stub(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.bethell", "")) - p.run + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Network) + Ohai::NamedPlugin.send(:remove_const, :Network) end end diff --git a/spec/unit/plugins/darwin/platform_spec.rb b/spec/unit/plugins/darwin/platform_spec.rb index c7b02f37..c700c8cb 100644 --- a/spec/unit/plugins/darwin/platform_spec.rb +++ b/spec/unit/plugins/darwin/platform_spec.rb @@ -22,11 +22,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin plugin platform" do before(:each) do @plugin = get_plugin("darwin/platform") - - @plugin[:os] = "darwin" + @plugin.stub(:collect_os).and_return(:darwin) @stdout = "ProductName: Mac OS X\nProductVersion: 10.5.5\nBuildVersion: 9F33" @plugin.stub(:shell_out).with("/usr/bin/sw_vers").and_return(mock_shell_out(0, @stdout, "")) end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Platform) + Ohai::NamedPlugin.send(:remove_const, :Platform) + end + end it "should run sw_vers" do @plugin.should_receive(:shell_out).with("/usr/bin/sw_vers").and_return(mock_shell_out(0, @stdout, "")) diff --git a/spec/unit/plugins/darwin/system_profiler_spec.rb b/spec/unit/plugins/darwin/system_profiler_spec.rb index 20e99f72..604b40fe 100644 --- a/spec/unit/plugins/darwin/system_profiler_spec.rb +++ b/spec/unit/plugins/darwin/system_profiler_spec.rb @@ -29,6 +29,13 @@ end describe Ohai::System, "Darwin system_profiler plugin", :unix_only do before(:each) do @plugin = get_plugin("darwin/system_profiler") + @plugin.stub(:collect_os).and_return(:darwin) + end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :SystemProfile) + Ohai::NamedPlugin.send(:remove_const, :SystemProfile) + end end it "should return the right serial number" do diff --git a/spec/unit/plugins/dmi_spec.rb b/spec/unit/plugins/dmi_spec.rb index 9d75e066..ea38aca2 100644 --- a/spec/unit/plugins/dmi_spec.rb +++ b/spec/unit/plugins/dmi_spec.rb @@ -98,6 +98,12 @@ describe Ohai::System, "plugin dmi" do @plugin.stub(:shell_out).with("dmidecode").and_return(mock_shell_out(0, @stdout, "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :DMI) + Ohai::NamedPlugin.send(:remove_const, :DMI) + end + end + it "should run dmidecode" do @plugin.should_receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, @stdout, "")) @plugin.run diff --git a/spec/unit/plugins/ec2_spec.rb b/spec/unit/plugins/ec2_spec.rb index 09742209..199426a6 100644 --- a/spec/unit/plugins/ec2_spec.rb +++ b/spec/unit/plugins/ec2_spec.rb @@ -26,6 +26,12 @@ describe Ohai::System, "plugin ec2" do @plugin[:network] = {:interfaces => {:eth0 => {} } } end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :EC2) + Ohai::NamedPlugin.send(:remove_const, :EC2) + end + end + shared_examples_for "!ec2" do it "should NOT attempt to fetch the ec2 metadata" do @plugin.should_not_receive(:http_client) diff --git a/spec/unit/plugins/eucalyptus_spec.rb b/spec/unit/plugins/eucalyptus_spec.rb index f0dcd600..0039a8fc 100644 --- a/spec/unit/plugins/eucalyptus_spec.rb +++ b/spec/unit/plugins/eucalyptus_spec.rb @@ -25,6 +25,12 @@ describe Ohai::System, "plugin eucalyptus" do @plugin = get_plugin("eucalyptus") end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Eucalyptus) + Ohai::NamedPlugin.send(:remove_const, :Eucalyptus) + end + end + shared_examples_for "!eucalyptus" do it "should NOT attempt to fetch the eucalyptus metadata" do OpenURI.should_not_receive(:open) diff --git a/spec/unit/plugins/freebsd/kernel_spec.rb b/spec/unit/plugins/freebsd/kernel_spec.rb index e4f7174f..4b8c5292 100644 --- a/spec/unit/plugins/freebsd/kernel_spec.rb +++ b/spec/unit/plugins/freebsd/kernel_spec.rb @@ -21,12 +21,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "FreeBSD kernel plugin" do before(:each) do - @plugin = get_plugin("freebsd/kernel") + @plugin = get_plugin("kernel") + @plugin.stub(:collect_os).and_return(:freebsd) + @plugin.stub(:init_kernel).and_return({:name => "freebsd"}) @plugin.stub(:shell_out).with("uname -i").and_return(mock_shell_out(0, "foo\n", "")) @plugin.stub(:shell_out).with("sysctl kern.securelevel").and_return(mock_shell_out(0, "kern.securelevel: 1", "")) @plugin.stub(:shell_out).with( Ohai.abs_path( "/sbin/kldstat" )).and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", "")) - @plugin[:kernel] = Mash.new - @plugin[:kernel][:name] = "freebsd" + end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Kernel) + Ohai::NamedPlugin.send(:remove_const, :Kernel) + end end it "should set the kernel_os to the kernel_name value" do diff --git a/spec/unit/plugins/freebsd/platform_spec.rb b/spec/unit/plugins/freebsd/platform_spec.rb index 798b1063..32f2138d 100644 --- a/spec/unit/plugins/freebsd/platform_spec.rb +++ b/spec/unit/plugins/freebsd/platform_spec.rb @@ -24,7 +24,13 @@ describe Ohai::System, "FreeBSD plugin platform" do @plugin = get_plugin("freebsd/platform") @plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "FreeBSD\n", "")) @plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "7.1\n", "")) - @plugin[:os] = "freebsd" + @plugin.stub(:collect_os).and_return(:freebsd) + end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Platform) + Ohai::NamedPlugin.send(:remove_const, :Platform) + end end it "should set platform to lowercased lsb[:id]" do diff --git a/spec/unit/plugins/freebsd/virtualization_spec.rb b/spec/unit/plugins/freebsd/virtualization_spec.rb index 02f3f090..983f7aab 100644 --- a/spec/unit/plugins/freebsd/virtualization_spec.rb +++ b/spec/unit/plugins/freebsd/virtualization_spec.rb @@ -22,13 +22,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "FreeBSD virtualization plugin" do before(:each) do @plugin = get_plugin("freebsd/virtualization") - @plugin[:os] = "freebsd" + @plugin.stub(:collect_os).and_return(:freebsd) + @plugin.extend(SimpleFromFile) @plugin.stub(:shell_out).with("sysctl -n security.jail.jailed").and_return(mock_shell_out(0, "0", "")) @plugin.stub(:shell_out).with("#{ Ohai.abs_path( "/sbin/kldstat" )}").and_return(mock_shell_out(0, "", "")) @plugin.stub(:shell_out).with("jls -n").and_return(mock_shell_out(0, "","")) @plugin.stub(:shell_out).with("sysctl -n hw.model").and_return(mock_shell_out(0, "", "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Virtualization) + Ohai::NamedPlugin.send(:remove_const, :Virtualization) + end + end + context "jails" do it "detects we are in a jail" do @plugin.stub(:shell_out).with("sysctl -n security.jail.jailed").and_return(mock_shell_out(0, "1", "")) diff --git a/spec/unit/plugins/gce_spec.rb b/spec/unit/plugins/gce_spec.rb index b9df2c60..ed98e662 100644 --- a/spec/unit/plugins/gce_spec.rb +++ b/spec/unit/plugins/gce_spec.rb @@ -23,6 +23,12 @@ describe Ohai::System, "plugin gce" do @plugin = get_plugin("gce") end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :GCE) + Ohai::NamedPlugin.send(:remove_const, :GCE) + end + end + shared_examples_for "!gce" do it "should NOT attempt to fetch the gce metadata" do @plugin.should_not_receive(:http_client) diff --git a/spec/unit/plugins/groovy_spec.rb b/spec/unit/plugins/groovy_spec.rb index 5d072d16..15a187f1 100644 --- a/spec/unit/plugins/groovy_spec.rb +++ b/spec/unit/plugins/groovy_spec.rb @@ -29,6 +29,12 @@ describe Ohai::System, "plugin groovy" do @plugin.stub(:shell_out).with("groovy -v").and_return(mock_shell_out(0, @stdout, "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Groovy) + Ohai::NamedPlugin.send(:remove_const, :Groovy) + end + end + it "should get the groovy version from running groovy -v" do @plugin.should_receive(:shell_out).with("groovy -v").and_return(mock_shell_out(0, @stdout, "")) @plugin.run diff --git a/spec/unit/plugins/java_spec.rb b/spec/unit/plugins/java_spec.rb index 7258ce66..49bc7308 100644 --- a/spec/unit/plugins/java_spec.rb +++ b/spec/unit/plugins/java_spec.rb @@ -27,6 +27,12 @@ describe Ohai::System, "plugin java (Java5 Client VM)" do @plugin.stub(:shell_out).with("java -version").and_return(mock_shell_out(0, "", @stderr)) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Java) + Ohai::NamedPlugin.send(:remove_const, :Java) + end + end + it "should run java -version" do @plugin.should_receive(:shell_out).with("java -version").and_return(mock_shell_out(0, "", @stderr)) @plugin.run diff --git a/spec/unit/plugins/kernel_spec.rb b/spec/unit/plugins/kernel_spec.rb index a3bf1626..db7902cf 100644 --- a/spec/unit/plugins/kernel_spec.rb +++ b/spec/unit/plugins/kernel_spec.rb @@ -22,9 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin kernel" do before(:each) do @plugin = get_plugin("kernel") - - @plugin[:languages] = Mash.new - @plugin[:languages][:ruby] = Mash.new + @plugin.stub(:collect_os).and_return(:default) # for debugging @plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "Darwin\n", "")) @plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "9.5.0\n", "")) @plugin.stub(:shell_out).with("uname -v").and_return(mock_shell_out(0, "Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386\n", "")) @@ -32,6 +30,12 @@ describe Ohai::System, "plugin kernel" do @plugin.stub(:shell_out).with("uname -o").and_return(mock_shell_out(0, "Linux\n", "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Kernel) + Ohai::NamedPlugin.send(:remove_const, :Kernel) + end + end + it_should_check_from_mash("kernel", "name", "uname -s", [0, "Darwin\n", ""]) it_should_check_from_mash("kernel", "release", "uname -r", [0, "9.5.0\n", ""]) it_should_check_from_mash("kernel", "version", "uname -v", [0, "Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386\n", ""]) diff --git a/spec/unit/plugins/linode_spec.rb b/spec/unit/plugins/linode_spec.rb index b773e4ff..30bc76ab 100644 --- a/spec/unit/plugins/linode_spec.rb +++ b/spec/unit/plugins/linode_spec.rb @@ -46,6 +46,12 @@ describe Ohai::System, "plugin linode" do } end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Linode) + Ohai::NamedPlugin.send(:remove_const, :Linode) + end + end + shared_examples_for "!linode" do it "does not create the linode mash" do @plugin.run diff --git a/spec/unit/plugins/linux/cpu_spec.rb b/spec/unit/plugins/linux/cpu_spec.rb index 925d0553..fe804512 100644 --- a/spec/unit/plugins/linux/cpu_spec.rb +++ b/spec/unit/plugins/linux/cpu_spec.rb @@ -22,7 +22,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux cpu plugin" do before(:each) do @plugin = get_plugin("linux/cpu") - @plugin[:os] = "linux" + @plugin.stub(:collect_os).and_return(:linux) @double_file = double("/proc/cpuinfo") @double_file.stub(:each). and_yield("processor : 0"). @@ -46,6 +46,12 @@ describe Ohai::System, "Linux cpu plugin" do and_yield("clflush size : 32") File.stub(:open).with("/proc/cpuinfo").and_return(@double_file) end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :CPU) + Ohai::NamedPlugin.send(:remove_const, :CPU) + end + end it "should set cpu[:total] to 1" do @plugin.run diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb index d6f70f79..5ce7f94c 100644 --- a/spec/unit/plugins/linux/filesystem_spec.rb +++ b/spec/unit/plugins/linux/filesystem_spec.rb @@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux filesystem plugin" do before(:each) do @plugin = get_plugin("linux/filesystem") - @plugin[:os] = "linux" + @plugin.stub(:collect_os).and_return(:linux) @plugin.extend(SimpleFromFile) @plugin.stub(:shell_out).with("df -P").and_return(mock_shell_out(0, "", "")) @@ -33,6 +33,12 @@ describe Ohai::System, "Linux filesystem plugin" do File.stub(:exists?).with("/proc/mounts").and_return(false) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Filesystem) + Ohai::NamedPlugin.send(:remove_const, :Filesystem) + end + end + describe "when gathering filesystem usage data from df" do before(:each) do @stdout = <<-DF diff --git a/spec/unit/plugins/linux/kernel_spec.rb b/spec/unit/plugins/linux/kernel_spec.rb index 557a0d00..084f81ed 100644 --- a/spec/unit/plugins/linux/kernel_spec.rb +++ b/spec/unit/plugins/linux/kernel_spec.rb @@ -20,7 +20,6 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') require File.expand_path(File.dirname(__FILE__) + '/../../path/ohai_plugin_common.rb') - describe Ohai::System, "Linux kernel plugin" do before(:each) do @env_lsmod = <<-ENV_LSMOD @@ -33,14 +32,21 @@ serio_raw 13031 0 virtio_balloon 13168 0 floppy 55441 0 ENV_LSMOD - @plugin = get_plugin("linux/kernel") + @plugin = get_plugin("kernel") + @plugin.stub(:collect_os).and_return(:linux) + @plugin.stub(:init_kernel).and_return({}) @plugin.stub(:shell_out).with("uname -o").and_return(mock_shell_out(0, "Linux", "")) @plugin.stub(:shell_out).with("env lsmod").and_return(mock_shell_out(0, @env_lsmod, "")) @plugin.should_receive(:shell_out).with("env lsmod").at_least(1).times - @plugin[:kernel] = {} @plugin.run end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Kernel) + Ohai::NamedPlugin.send(:remove_const, :Kernel) + end + end + it_should_check_from_deep_mash("linux::kernel", "kernel", "os", "uname -o", [0, "Linux", ""]) test_plugin([ "kernel", "linux/kernel" ], [ "uname", "env" ]) do | p | diff --git a/spec/unit/plugins/linux/lsb_spec.rb b/spec/unit/plugins/linux/lsb_spec.rb index 7bbdaef1..219ff0b9 100644 --- a/spec/unit/plugins/linux/lsb_spec.rb +++ b/spec/unit/plugins/linux/lsb_spec.rb @@ -24,10 +24,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux lsb plugin" do before(:each) do @plugin = get_plugin("linux/lsb") - @plugin[:os] = "linux" + @plugin.stub(:collect_os).and_return(:linux) @plugin.extend(SimpleFromFile) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :LSB) + Ohai::NamedPlugin.send(:remove_const, :LSB) + end + end + describe "on systems with /etc/lsb-release" do before(:each) do @double_file = double("/etc/lsb-release") diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb index 22cb6800..a2b90d8c 100644 --- a/spec/unit/plugins/linux/network_spec.rb +++ b/spec/unit/plugins/linux/network_spec.rb @@ -257,13 +257,11 @@ IP_ROUTE_SCOPE @plugin = get_plugin("linux/network") @plugin.stub(:shell_out).with("ifconfig -a").and_return([0, @linux_ifconfig, ""]) @plugin.stub(:shell_out).with("arp -an").and_return([0, @linux_arp_an, ""]) - Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(3).times + end - %w{ linux/hostname hostname network }.each do |plgn| - p = get_plugin(plgn) - p.stub(:shell_out).with("hostname -s").and_return(mock_shell_out(0, "katie", "")) - p.stub(:shell_out).with("hostname --fqdn").and_return(mock_shell_out(0, "katie.bethell", "")) - p.run + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Network) + Ohai::NamedPlugin.send(:remove_const, :Network) end end diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index 4ab6bba2..7eef92ce 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -24,7 +24,7 @@ describe Ohai::System, "Linux plugin platform" do before(:each) do @plugin = get_plugin("linux/platform") @plugin.extend(SimpleFromFile) - @plugin[:os] = "linux" + @plugin.stub(:collect_os).and_return(:linux) @plugin[:lsb] = Mash.new File.stub(:exists?).with("/etc/debian_version").and_return(false) File.stub(:exists?).with("/etc/redhat-release").and_return(false) @@ -38,6 +38,12 @@ describe Ohai::System, "Linux plugin platform" do File.stub(:exists?).with("/usr/bin/raspi-config").and_return(false) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Platform) + Ohai::NamedPlugin.send(:remove_const, :Platform) + end + end + describe "on lsb compliant distributions" do before(:each) do @plugin[:lsb][:id] = "Ubuntu" diff --git a/spec/unit/plugins/linux/uptime_spec.rb b/spec/unit/plugins/linux/uptime_spec.rb index 14d26a4d..1beea6fc 100644 --- a/spec/unit/plugins/linux/uptime_spec.rb +++ b/spec/unit/plugins/linux/uptime_spec.rb @@ -21,11 +21,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux plugin uptime" do before(:each) do - @plugin = get_plugin("linux/uptime") - @plugin[:os] = "linux" + @plugin = get_plugin("uptime") + @plugin.stub(:collect_os).and_return(:linux) @double_file = double("/proc/uptime", { :gets => "18423 989" }) File.stub(:open).with("/proc/uptime").and_return(@double_file) end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Uptime) + Ohai::NamedPlugin.send(:remove_const, :Uptime) + end + end it "should set uptime_seconds to uptime" do @plugin.run diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index 5392f610..415b7945 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -21,7 +21,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux virtualization platform" do before(:each) do @plugin = get_plugin("linux/virtualization") - @plugin[:os] = "linux" + @plugin.stub(:collect_os).and_return(:linux) @plugin.extend(SimpleFromFile) # default to all requested Files not existing @@ -35,6 +35,12 @@ describe Ohai::System, "Linux virtualization platform" do File.stub(:exists?).with("/proc/vz").and_return(false) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Virtualization) + Ohai::NamedPlugin.send(:remove_const, :Virtualization) + end + end + describe "when we are checking for xen" do it "should set xen guest if /proc/xen exists but /proc/xen/capabilities does not" do File.should_receive(:exists?).with("/proc/xen").and_return(true) diff --git a/spec/unit/plugins/lua_spec.rb b/spec/unit/plugins/lua_spec.rb index 8dff19b6..80ee6400 100644 --- a/spec/unit/plugins/lua_spec.rb +++ b/spec/unit/plugins/lua_spec.rb @@ -30,6 +30,12 @@ describe Ohai::System, "plugin lua" do @plugin.stub(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @stderr)) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Lua) + Ohai::NamedPlugin.send(:remove_const, :Lua) + end + end + it "should get the lua version from running lua -v" do @plugin.should_receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @stderr)) @plugin.run diff --git a/spec/unit/plugins/mono_spec.rb b/spec/unit/plugins/mono_spec.rb index 2d71d83e..d3a79e12 100644 --- a/spec/unit/plugins/mono_spec.rb +++ b/spec/unit/plugins/mono_spec.rb @@ -28,6 +28,12 @@ describe Ohai::System, "plugin mono" do @plugin.stub(:shell_out).with("mono -V").and_return(mock_shell_out(0, @stdout, "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Mono) + Ohai::NamedPlugin.send(:remove_const, :Mono) + end + end + it "should get the mono version from running mono -V" do @plugin.should_receive(:shell_out).with("mono -V").and_return(mock_shell_out(0, @stdout, "")) @plugin.run diff --git a/spec/unit/plugins/netbsd/kernel_spec.rb b/spec/unit/plugins/netbsd/kernel_spec.rb index 832176d4..f79518e0 100644 --- a/spec/unit/plugins/netbsd/kernel_spec.rb +++ b/spec/unit/plugins/netbsd/kernel_spec.rb @@ -21,14 +21,21 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "NetBSD kernel plugin" do before(:each) do - @plugin = get_plugin("netbsd/kernel") + @plugin = get_plugin("kernel") + @plugin.stub(:collect_os).and_return(:netbsd) + @plugin.stub(:init_kernel).and_return({}) @plugin.stub(:shell_out).with("uname -i").and_return(mock_shell_out(0, "foo", "")) @plugin.stub(:shell_out).with("sysctl kern.securelevel").and_return(mock_shell_out(0, "kern.securelevel: 1\n", "")) @plugin.stub(:shell_out).with("#{ Ohai.abs_path( "/usr/bin/modstat" )}").and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", "")) - @plugin[:kernel] = Mash.new - @plugin[:kernel][:name] = "netbsd" end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Kernel) + Ohai::NamedPlugin.send(:remove_const, :Kernel) + end + end + + it "should set the kernel_os to the kernel_name value" do @plugin.run @plugin[:kernel][:os].should == @plugin[:kernel][:name] diff --git a/spec/unit/plugins/netbsd/platform_spec.rb b/spec/unit/plugins/netbsd/platform_spec.rb index 4397d100..004126ee 100644 --- a/spec/unit/plugins/netbsd/platform_spec.rb +++ b/spec/unit/plugins/netbsd/platform_spec.rb @@ -24,7 +24,13 @@ describe Ohai::System, "NetBSD plugin platform" do @plugin = get_plugin("netbsd/platform") @plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "NetBSD\n", "")) @plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "4.5\n", "")) - @plugin[:os] = "netbsd" + @plugin.stub(:collect_os).and_return(:netbsd) + end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Platform) + Ohai::NamedPlugin.send(:remove_const, :Platform) + end end it "should set platform to lowercased lsb[:id]" do diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb index 27354bf7..07ed0c8c 100644 --- a/spec/unit/plugins/network_spec.rb +++ b/spec/unit/plugins/network_spec.rb @@ -290,6 +290,12 @@ describe Ohai::System, "Network Plugin" do @plugin["network"] = basic_data["linux"]["network"] end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :NetworkAddresses) + Ohai::NamedPlugin.send(:remove_const, :NetworkAddresses) + end + end + describe "when the linux::network plugin hasn't set any of {ip,ip6,mac}address attributes" do describe "simple setup" do it_does_not_fail diff --git a/spec/unit/plugins/nodejs_spec.rb b/spec/unit/plugins/nodejs_spec.rb index 15a596af..286bdf77 100644 --- a/spec/unit/plugins/nodejs_spec.rb +++ b/spec/unit/plugins/nodejs_spec.rb @@ -29,6 +29,12 @@ describe Ohai::System, "plugin nodejs" do @plugin.stub(:shell_out).with("node -v").and_return(mock_shell_out(0, @stdout, "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Nodejs) + Ohai::NamedPlugin.send(:remove_const, :Nodejs) + end + end + it "should get the nodejs version from running node -v" do @plugin.should_receive(:shell_out).with("node -v").and_return(mock_shell_out(0, @stdout, "")) @plugin.run diff --git a/spec/unit/plugins/ohai_spec.rb b/spec/unit/plugins/ohai_spec.rb index cea24ee4..785aa3fd 100644 --- a/spec/unit/plugins/ohai_spec.rb +++ b/spec/unit/plugins/ohai_spec.rb @@ -24,6 +24,12 @@ describe Ohai::System, "plugin ohai" do before(:each) do @plugin = get_plugin("ohai") end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Ohai) + Ohai::NamedPlugin.send(:remove_const, :Ohai) + end + end it "should set [:chef_packages][:ohai][:version] to the current version" do @plugin.run diff --git a/spec/unit/plugins/ohai_time_spec.rb b/spec/unit/plugins/ohai_time_spec.rb index 003f4da3..e000a985 100644 --- a/spec/unit/plugins/ohai_time_spec.rb +++ b/spec/unit/plugins/ohai_time_spec.rb @@ -23,6 +23,12 @@ describe Ohai::System, "plugin ohai_time" do before(:each) do @plugin = get_plugin("ohai_time") end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :OhaiTime) + Ohai::NamedPlugin.send(:remove_const, :OhaiTime) + end + end it "should get the current time" do Time.should_receive(:now) diff --git a/spec/unit/plugins/openbsd/kernel_spec.rb b/spec/unit/plugins/openbsd/kernel_spec.rb index 8979b431..c7732862 100644 --- a/spec/unit/plugins/openbsd/kernel_spec.rb +++ b/spec/unit/plugins/openbsd/kernel_spec.rb @@ -21,14 +21,21 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "OpenBSD kernel plugin" do before(:each) do - @plugin = get_plugin("openbsd/kernel") + @plugin = get_plugin("kernel") + @plugin.stub(:collect_os).and_return(:openbsd) + @plugin.stub(:init_kernel).and_return({}) @plugin.stub(:shell_out).with("uname -i").and_return(mock_shell_out(0, "foo", "")) @plugin.stub(:shell_out).with("sysctl kern.securelevel").and_return(mock_shell_out(0, "kern.securelevel: 1\n", "")) @plugin.stub(:shell_out).with( Ohai.abs_path( "/usr/bin/modstat" )).and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", "")) - @plugin[:kernel] = Mash.new - @plugin[:kernel][:name] = "openbsd" end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Kernel) + Ohai::NamedPlugin.send(:remove_const, :Kernel) + end + end + + it "should set the kernel_os to the kernel_name value" do @plugin.run @plugin[:kernel][:os].should == @plugin[:kernel][:name] diff --git a/spec/unit/plugins/openbsd/platform_spec.rb b/spec/unit/plugins/openbsd/platform_spec.rb index e11f2495..7a3dcf85 100644 --- a/spec/unit/plugins/openbsd/platform_spec.rb +++ b/spec/unit/plugins/openbsd/platform_spec.rb @@ -24,7 +24,13 @@ describe Ohai::System, "OpenBSD plugin platform" do @plugin = get_plugin("openbsd/platform") @plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "OpenBSD\n", "")) @plugin.stub(:shell_out).with("uname -r").and_return(mock_shell_out(0, "4.5\n", "")) - @plugin[:os] = "openbsd" + @plugin.stub(:collect_os).and_return(:openbsd) + end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Platform) + Ohai::NamedPlugin.send(:remove_const, :Platform) + end end it "should set platform to lowercased lsb[:id]" do diff --git a/spec/unit/plugins/os_spec.rb b/spec/unit/plugins/os_spec.rb index 86faa1e0..8571e37e 100644 --- a/spec/unit/plugins/os_spec.rb +++ b/spec/unit/plugins/os_spec.rb @@ -24,14 +24,15 @@ ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG['host_os'] describe Ohai::System, "plugin os" do before(:each) do @plugin = get_plugin("os") - @plugin[:languages] = Mash.new - @plugin[:languages][:ruby] = Mash.new @plugin[:kernel] = Mash.new @plugin[:kernel][:release] = "kings of leon" end after do ::RbConfig::CONFIG['host_os'] = ORIGINAL_CONFIG_HOST_OS + if Ohai::NamedPlugin.send(:const_defined?, :OS) + Ohai::NamedPlugin.send(:remove_const, :OS) + end end it "should set os_version to kernel_release" do diff --git a/spec/unit/plugins/passwd_spec.rb b/spec/unit/plugins/passwd_spec.rb index 4e3a2e33..a3294432 100644 --- a/spec/unit/plugins/passwd_spec.rb +++ b/spec/unit/plugins/passwd_spec.rb @@ -5,6 +5,12 @@ describe Ohai::System, "plugin etc" do @plugin = get_plugin("passwd") end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Passwd) + Ohai::NamedPlugin.send(:remove_const, :Passwd) + end + end + PasswdEntry = Struct.new(:name, :uid, :gid, :dir, :shell, :gecos) GroupEntry = Struct.new(:name, :gid, :mem) diff --git a/spec/unit/plugins/perl_spec.rb b/spec/unit/plugins/perl_spec.rb index 1922a3cf..f69be6f2 100644 --- a/spec/unit/plugins/perl_spec.rb +++ b/spec/unit/plugins/perl_spec.rb @@ -27,6 +27,12 @@ describe Ohai::System, "plugin perl" do @plugin.stub(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Perl) + Ohai::NamedPlugin.send(:remove_const, :Perl) + end + end + it "should run perl -V:version -V:archname" do @plugin.should_receive(:shell_out).with("perl -V:version -V:archname").and_return(mock_shell_out(0, @stdout, "")) @plugin.run diff --git a/spec/unit/plugins/php_spec.rb b/spec/unit/plugins/php_spec.rb index fac70509..a843389e 100644 --- a/spec/unit/plugins/php_spec.rb +++ b/spec/unit/plugins/php_spec.rb @@ -31,6 +31,12 @@ describe Ohai::System, "plugin php" do @plugin.stub(:shell_out).with("php -v").and_return(mock_shell_out(0, @stdout, "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :PHP) + Ohai::NamedPlugin.send(:remove_const, :PHP) + end + end + it "should get the php version from running php -V" do @plugin.should_receive(:shell_out).with("php -v").and_return(mock_shell_out(0, @stdout, "")) @plugin.run diff --git a/spec/unit/plugins/platform_spec.rb b/spec/unit/plugins/platform_spec.rb index cf743a96..4d0bba4c 100644 --- a/spec/unit/plugins/platform_spec.rb +++ b/spec/unit/plugins/platform_spec.rb @@ -22,10 +22,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin platform" do before(:each) do @plugin = get_plugin("platform") + @plugin.stub(:collect_os).and_return(:default) @plugin[:os] = 'monkey' @plugin[:os_version] = 'poop' end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Platform) + Ohai::NamedPlugin.send(:remove_const, :Platform) + end + end + it "should set the platform and platform family to the os if it was not set earlier" do @plugin.run @plugin[:platform].should eql("monkey") diff --git a/spec/unit/plugins/python_spec.rb b/spec/unit/plugins/python_spec.rb index 68ef48c6..c8be32b9 100644 --- a/spec/unit/plugins/python_spec.rb +++ b/spec/unit/plugins/python_spec.rb @@ -28,6 +28,12 @@ describe Ohai::System, "plugin python" do @stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n" @plugin.stub(:shell_out).with("python -c \"import sys; print sys.version\"").and_return(mock_shell_out(0, @stdout, "")) end + + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Python) + Ohai::NamedPlugin.send(:remove_const, :Python) + end + end it "should get the python version from printing sys.version and sys.platform" do @plugin.should_receive(:shell_out).with("python -c \"import sys; print sys.version\"").and_return(mock_shell_out(0, @stdout, "")) diff --git a/spec/unit/plugins/rackspace_spec.rb b/spec/unit/plugins/rackspace_spec.rb index 357905c8..5a53044a 100644 --- a/spec/unit/plugins/rackspace_spec.rb +++ b/spec/unit/plugins/rackspace_spec.rb @@ -69,6 +69,12 @@ describe Ohai::System, "plugin rackspace" do @plugin.stub(:shell_out).and_return(mock_shell_out(1, "", "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Rackspace) + Ohai::NamedPlugin.send(:remove_const, :Rackspace) + end + end + shared_examples_for "!rackspace" do it "should NOT create rackspace" do @plugin.run diff --git a/spec/unit/plugins/root_group_spec.rb b/spec/unit/plugins/root_group_spec.rb index 9e463dd9..a839468d 100644 --- a/spec/unit/plugins/root_group_spec.rb +++ b/spec/unit/plugins/root_group_spec.rb @@ -25,6 +25,12 @@ describe Ohai::System, 'root_group' do @plugin = get_plugin("root_group") end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :RootGroup) + Ohai::NamedPlugin.send(:remove_const, :RootGroup) + end + end + describe 'unix platform', :unix_only do before(:each) do # this is deeply intertwingled. unfortunately, the law of demeter diff --git a/spec/unit/plugins/ruby_spec.rb b/spec/unit/plugins/ruby_spec.rb index 6c3a3def..49e8c9c3 100644 --- a/spec/unit/plugins/ruby_spec.rb +++ b/spec/unit/plugins/ruby_spec.rb @@ -31,6 +31,12 @@ describe Ohai::System, "plugin ruby" do @ruby_ohai_data_pristine = @plugin[:languages][:ruby] end + after(:all) do + if Ohai::NamedPlugin.send(:const_defined?, :Ruby) + Ohai::NamedPlugin.send(:remove_const, :Ruby) + end + end + before(:each) do @ruby_ohai_data = @ruby_ohai_data_pristine.dup end diff --git a/spec/unit/plugins/sigar/network_route_spec.rb b/spec/unit/plugins/sigar/network_route_spec.rb index 45fec414..c4e05253 100644 --- a/spec/unit/plugins/sigar/network_route_spec.rb +++ b/spec/unit/plugins/sigar/network_route_spec.rb @@ -33,7 +33,8 @@ describe Ohai::System, "Sigar network route plugin" do before(:each) do @ohai = Ohai::System.new - @plugin = get_plugin("sigar/network_route", @ohai) + @plugin = get_plugin("sigar/network", @ohai) + @plugin.stub(:collect_os).and_return(:sigar) @sigar = double("Sigar") @net_info_conf={ :default_gateway => "192.168.1.254", @@ -112,7 +113,7 @@ describe Ohai::System, "Sigar network route plugin" do net_arp.stub(k).and_return(v) end @sigar.stub(:fqdn).and_return("localhost.localdomain") - @sigar.should_receive(:net_info).at_least(2).times.and_return(net_info) + @sigar.should_receive(:net_info).once.times.and_return(net_info) @sigar.should_receive(:net_interface_list).once.and_return(["eth0"]) @sigar.should_receive(:net_interface_config).with("eth0").and_return(net_conf) @sigar.should_receive(:net_interface_stat).with("eth0").and_return(net_stat) @@ -120,21 +121,17 @@ describe Ohai::System, "Sigar network route plugin" do # Since we double net_route_list here, flags never gets called @sigar.should_receive(:net_route_list).once.and_return([net_route]) - Sigar.should_receive(:new).at_least(2).times.and_return(@sigar) - - %w{ languages ruby kernel os }.each do |plgn| - get_plugin(plgn, @ohai).run - end - @plugin.data[:os]="sigar" - - #Ohai::Log.should_receive(:warn).with(/unable to detect ip6address/).once - %w{ sigar/hostname hostname sigar/network network }.each do |plgn| - get_plugin(plgn, @ohai).run - end + Sigar.should_receive(:new).once.and_return(@sigar) @plugin.run end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Network) + Ohai::NamedPlugin.send(:remove_const, :Network) + end + end + it "should set the routes" do @plugin[:network][:interfaces][:eth0].should have_key(:route) end diff --git a/spec/unit/plugins/solaris2/kernel_spec.rb b/spec/unit/plugins/solaris2/kernel_spec.rb index 008672ec..56741236 100644 --- a/spec/unit/plugins/solaris2/kernel_spec.rb +++ b/spec/unit/plugins/solaris2/kernel_spec.rb @@ -134,12 +134,20 @@ describe Ohai::System, "Solaris2.X kernel plugin" do TOOMUCH before(:each) do - @plugin = get_plugin("solaris2/kernel") - @plugin[:kernel] = Mash.new + @plugin = get_plugin("kernel") + @plugin.stub(:collect_os).and_return(:solaris2) + @plugin.stub(:init_kernel).and_return({}) @plugin.stub(:shell_out).with("uname -s").and_return(mock_shell_out(0, "SunOS\n", "")) @plugin.stub(:shell_out).with("modinfo").and_return(mock_shell_out(0, MODINFO, "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Kernel) + Ohai::NamedPlugin.send(:remove_const, :Kernel) + end + end + + it_should_check_from_deep_mash("solaris2::kernel", "kernel", "os", "uname -s", [0, "SunOS\n", ""]) it "gives excruciating detail about kernel modules" do diff --git a/spec/unit/plugins/solaris2/network_spec.rb b/spec/unit/plugins/solaris2/network_spec.rb index 08561682..20942f89 100644 --- a/spec/unit/plugins/solaris2/network_spec.rb +++ b/spec/unit/plugins/solaris2/network_spec.rb @@ -112,6 +112,7 @@ ROUTE_GET @ifconfig_lines = @solaris_ifconfig.split("\n") @plugin = get_plugin("solaris2/network") + @plugin.stub(:collect_os).and_return(:solaris2) @plugin[:network] = Mash.new @plugin.stub(:shell_out).with("ifconfig -a").and_return(mock_shell_out(0, @solaris_route_get, "")) @@ -119,6 +120,12 @@ ROUTE_GET @plugin.stub(:shell_out).with("route -n get default").and_return(mock_shell_out(0, @soalris_route_get, "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Network) + Ohai::NamedPlugin.send(:remove_const, :Network) + end + end + describe "gathering IP layer address info" do before do @stdout = double("Pipe, stdout, cmd=`route get default`", :read => @solaris_route_get) diff --git a/spec/unit/plugins/solaris2/platform_spec.rb b/spec/unit/plugins/solaris2/platform_spec.rb index 5be59f76..afa17cb1 100644 --- a/spec/unit/plugins/solaris2/platform_spec.rb +++ b/spec/unit/plugins/solaris2/platform_spec.rb @@ -22,10 +22,16 @@ describe Ohai::System, "Solaris plugin platform" do before(:each) do @plugin = get_plugin("solaris2/platform") @plugin.extend(SimpleFromFile) - @plugin[:os] = "solaris2" + @plugin.stub(:collect_os).and_return(:solaris2) @plugin.stub(:shell_out).with("/sbin/uname -X") end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Platform) + Ohai::NamedPlugin.send(:remove_const, :Platform) + end + end + describe "on SmartOS" do before(:each) do @uname_x = <<-UNAME_X diff --git a/spec/unit/plugins/solaris2/virtualization_spec.rb b/spec/unit/plugins/solaris2/virtualization_spec.rb index 15a5667a..8a90a731 100644 --- a/spec/unit/plugins/solaris2/virtualization_spec.rb +++ b/spec/unit/plugins/solaris2/virtualization_spec.rb @@ -27,7 +27,7 @@ The physical processor has 1 virtual processor (0) PSRINFO_PV @plugin = get_plugin("solaris2/virtualization") - @plugin[:os] = "solaris2" + @plugin.stub(:collect_os).and_return(:solaris2) @plugin.extend(SimpleFromFile) # default to all requested Files not existing @@ -38,6 +38,12 @@ PSRINFO_PV @plugin.stub(:shell_out).with("#{ Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, "", "")) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :Virtualization) + Ohai::NamedPlugin.send(:remove_const, :Virtualization) + end + end + describe "when we are checking for kvm" do before(:each) do File.should_receive(:exists?).with("/usr/sbin/psrinfo").and_return(true) diff --git a/spec/unit/plugins/ssh_host_keys_spec.rb b/spec/unit/plugins/ssh_host_keys_spec.rb index 4ead4478..f01b3e9b 100644 --- a/spec/unit/plugins/ssh_host_keys_spec.rb +++ b/spec/unit/plugins/ssh_host_keys_spec.rb @@ -47,6 +47,12 @@ describe Ohai::System, "ssh_host_key plugin" do IO.stub(:read).with("/etc/ssh/ssh_host_ecdsa_key.pub").and_return(@ecdsa_key) end + after(:each) do + if Ohai::NamedPlugin.send(:const_defined?, :SSHHostKey) + Ohai::NamedPlugin.send(:remove_const, :SSHHostKey) + end + end + shared_examples "loads keys" do it "reads the key and sets the dsa attribute correctly" do @plugin.run |