summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamedx <adamed@opscode.com>2013-09-23 11:03:08 -0700
committeradamedx <adamed@opscode.com>2013-09-23 11:03:08 -0700
commit91edd2b8b7e7bd0c846efe773d131e98d4ed1229 (patch)
treee4ac6bfe9bbf7d6f63b55cee419eca38db28574d
parentf1dd92a10aefce1ca316c98937fd62dfba3c62d8 (diff)
downloadohai-91edd2b8b7e7bd0c846efe773d131e98d4ed1229.tar.gz
Revert "Merge pull request #175 from opscode/adamed-oc-9106"
This reverts commit f1dd92a10aefce1ca316c98937fd62dfba3c62d8, reversing changes made to dfe0051098fbd3b6f37869db2040877422eb07e3. This commit unintentionally pulled in changes from the master branch.
-rw-r--r--Gemfile2
-rw-r--r--lib/ohai/dsl/plugin.rb136
-rw-r--r--lib/ohai/mixin/gce_metadata.rb2
-rw-r--r--lib/ohai/mixin/seconds_to_human.rb48
-rw-r--r--lib/ohai/plugins/aix/cpu.rb36
-rw-r--r--lib/ohai/plugins/aix/filesystem.rb60
-rw-r--r--lib/ohai/plugins/aix/hostname.rb4
-rw-r--r--lib/ohai/plugins/aix/kernel.rb27
-rw-r--r--lib/ohai/plugins/aix/memory.rb11
-rw-r--r--lib/ohai/plugins/aix/network.rb142
-rw-r--r--lib/ohai/plugins/aix/platform.rb12
-rw-r--r--lib/ohai/plugins/aix/uptime.rb21
-rw-r--r--lib/ohai/plugins/darwin/uptime.rb2
-rw-r--r--lib/ohai/plugins/freebsd/uptime.rb2
-rw-r--r--lib/ohai/plugins/gce.rb6
-rw-r--r--lib/ohai/plugins/linode.rb10
-rw-r--r--lib/ohai/plugins/linux/uptime.rb4
-rw-r--r--lib/ohai/plugins/netbsd/uptime.rb2
-rw-r--r--lib/ohai/plugins/openbsd/uptime.rb2
-rw-r--r--lib/ohai/plugins/sigar/uptime.rb2
-rw-r--r--lib/ohai/plugins/solaris2/uptime.rb2
-rw-r--r--lib/ohai/plugins/uptime.rb23
-rw-r--r--lib/ohai/plugins/windows/uptime.rb2
-rw-r--r--lib/ohai/system.rb139
-rw-r--r--ohai.gemspec3
-rw-r--r--spec/data/plugins/foo.rb0
-rw-r--r--spec/ohai/dsl/plugin_spec.rb76
-rw-r--r--spec/spec_helper.rb27
-rw-r--r--spec/unit/mixin/ec2_metadata_spec.rb18
-rw-r--r--spec/unit/mixin/from_file_spec.rb53
-rw-r--r--spec/unit/plugins/aix/cpu_spec.rb78
-rw-r--r--spec/unit/plugins/aix/filesystem_spec.rb117
-rw-r--r--spec/unit/plugins/aix/hostname_spec.rb28
-rw-r--r--spec/unit/plugins/aix/kernel_spec.rb52
-rw-r--r--spec/unit/plugins/aix/network_spec.rb277
-rw-r--r--spec/unit/plugins/aix/platform_spec.rb43
-rw-r--r--spec/unit/plugins/aix/uptime_spec.rb40
-rw-r--r--spec/unit/plugins/azure_spec.rb40
-rw-r--r--spec/unit/plugins/c_spec.rb174
-rw-r--r--spec/unit/plugins/chef_spec.rb8
-rw-r--r--spec/unit/plugins/cloud_spec.rb161
-rw-r--r--spec/unit/plugins/darwin/cpu_spec.rb15
-rw-r--r--spec/unit/plugins/darwin/hostname_spec.rb11
-rw-r--r--spec/unit/plugins/darwin/kernel_spec.rb34
-rw-r--r--spec/unit/plugins/darwin/network_spec.rb722
-rw-r--r--spec/unit/plugins/darwin/platform_spec.rb64
-rw-r--r--spec/unit/plugins/darwin/system_profiler_spec.rb11
-rw-r--r--spec/unit/plugins/dmi_spec.rb17
-rw-r--r--spec/unit/plugins/ec2_spec.rb129
-rw-r--r--spec/unit/plugins/erlang_spec.rb28
-rw-r--r--spec/unit/plugins/eucalyptus_spec.rb70
-rw-r--r--spec/unit/plugins/freebsd/hostname_spec.rb9
-rw-r--r--spec/unit/plugins/freebsd/kernel_spec.rb18
-rw-r--r--spec/unit/plugins/freebsd/platform_spec.rb17
-rw-r--r--spec/unit/plugins/freebsd/virtualization_spec.rb49
-rw-r--r--spec/unit/plugins/gce_spec.rb78
-rw-r--r--spec/unit/plugins/groovy_spec.rb21
-rw-r--r--spec/unit/plugins/hostname_spec.rb15
-rw-r--r--spec/unit/plugins/java_spec.rb74
-rw-r--r--spec/unit/plugins/kernel_spec.rb20
-rw-r--r--spec/unit/plugins/linode_spec.rb60
-rw-r--r--spec/unit/plugins/linux/cpu_spec.rb85
-rw-r--r--spec/unit/plugins/linux/filesystem_spec.rb171
-rw-r--r--spec/unit/plugins/linux/hostname_spec.rb17
-rw-r--r--spec/unit/plugins/linux/kernel_spec.rb11
-rw-r--r--spec/unit/plugins/linux/lsb_spec.rb87
-rw-r--r--spec/unit/plugins/linux/network_spec.rb395
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb397
-rw-r--r--spec/unit/plugins/linux/uptime_spec.rb39
-rw-r--r--spec/unit/plugins/linux/virtualization_spec.rb181
-rw-r--r--spec/unit/plugins/lua_spec.rb21
-rw-r--r--spec/unit/plugins/mono_spec.rb21
-rw-r--r--spec/unit/plugins/netbsd/hostname_spec.rb9
-rw-r--r--spec/unit/plugins/netbsd/kernel_spec.rb16
-rw-r--r--spec/unit/plugins/netbsd/platform_spec.rb17
-rw-r--r--spec/unit/plugins/network_spec.rb436
-rw-r--r--spec/unit/plugins/nodejs_spec.rb21
-rw-r--r--spec/unit/plugins/ohai_spec.rb7
-rw-r--r--spec/unit/plugins/ohai_time_spec.rb17
-rw-r--r--spec/unit/plugins/openbsd/hostname_spec.rb11
-rw-r--r--spec/unit/plugins/openbsd/kernel_spec.rb18
-rw-r--r--spec/unit/plugins/openbsd/platform_spec.rb19
-rw-r--r--spec/unit/plugins/os_spec.rb31
-rw-r--r--spec/unit/plugins/passwd_spec.rb25
-rw-r--r--spec/unit/plugins/perl_spec.rb33
-rw-r--r--spec/unit/plugins/php_spec.rb21
-rw-r--r--spec/unit/plugins/platform_spec.rb49
-rw-r--r--spec/unit/plugins/python_spec.rb21
-rw-r--r--spec/unit/plugins/rackspace_spec.rb110
-rw-r--r--spec/unit/plugins/root_group_spec.rb34
-rw-r--r--spec/unit/plugins/ruby_spec.rb29
-rw-r--r--spec/unit/plugins/sigar/network_route_spec.rb21
-rw-r--r--spec/unit/plugins/solaris2/hostname_spec.rb15
-rw-r--r--spec/unit/plugins/solaris2/kernel_spec.rb25
-rw-r--r--spec/unit/plugins/solaris2/network_spec.rb34
-rw-r--r--spec/unit/plugins/solaris2/platform_spec.rb32
-rw-r--r--spec/unit/plugins/solaris2/virtualization_spec.rb79
-rw-r--r--spec/unit/plugins/ssh_host_keys_spec.rb25
-rw-r--r--spec/unit/system_spec.rb85
99 files changed, 2512 insertions, 3507 deletions
diff --git a/Gemfile b/Gemfile
index b6ce5632..1186c0d9 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,4 @@
-source "https://rubygems.org"
+source :rubygems
gemspec
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb
deleted file mode 100644
index edc02af5..00000000
--- a/lib/ohai/dsl/plugin.rb
+++ /dev/null
@@ -1,136 +0,0 @@
-require 'ohai/mixin/command'
-require 'ohai/mixin/from_file'
-require 'ohai/mixin/seconds_to_human'
-
-module Ohai
- module DSL
- class Plugin
-
- include Ohai::Mixin::Command
- include Ohai::Mixin::FromFile
- include Ohai::Mixin::SecondsToHuman
-
- attr_reader :file
- attr_reader :data
-
- def initialize(controller, file)
- @controller = controller
- @data = controller.data
- @providers = controller.providers
- @file = file
- end
-
- def run
- from_file(@file)
- end
-
- def require_plugin(*args)
- @controller.require_plugin(*args)
- end
-
- def hints
- @controller.hints
- end
-
- def [](key)
- @data[key]
- end
-
- def []=(key, value)
- @data[key] = value
- end
-
- def each(&block)
- @data.each do |key, value|
- block.call(key, value)
- end
- end
-
- def attribute?(name)
- @data.has_key?(name)
- end
-
- def set(name, *value)
- set_attribute(name, *value)
- end
-
- def from(cmd)
- status, stdout, stderr = run_command(:command => cmd)
- return "" if stdout.nil? || stdout.empty?
- stdout.strip
- end
-
- def provides(*paths)
- paths.each do |path|
- parts = path.split('/')
- h = @providers
- unless parts.length == 0
- parts.shift if parts[0].length == 0
- parts.each do |part|
- h[part] ||= Mash.new
- h = h[part]
- end
- end
- h[:_providers] ||= []
- h[:_providers] << @file
- end
- end
-
- # Set the value equal to the stdout of the command, plus run through a regex - the first piece of match data is the value.
- def from_with_regex(cmd, *regex_list)
- regex_list.flatten.each do |regex|
- status, stdout, stderr = run_command(:command => cmd)
- return "" if stdout.nil? || stdout.empty?
- stdout.chomp!.strip
- md = stdout.match(regex)
- return md[1]
- end
- end
-
- def set_attribute(name, *values)
- @data[name] = Array18(*values)
- @data[name]
- end
-
- def get_attribute(name)
- @data[name]
- end
-
- def hint?(name)
- @json_parser ||= Yajl::Parser.new
-
- return hints[name] if hints[name]
-
- Ohai::Config[:hints_path].each do |path|
- filename = File.join(path, "#{name}.json")
- if File.exist?(filename)
- begin
- hash = @json_parser.parse(File.read(filename))
- hints[name] = hash || Hash.new # hint should exist because the file did, even if it didn't contain anything
- rescue Yajl::ParseError => e
- Ohai::Log.error("Could not parse hint file at #{filename}: #{e.message}")
- end
- end
- end
-
- hints[name]
- end
-
- def method_missing(name, *args)
- return get_attribute(name) if args.length == 0
-
- set_attribute(name, *args)
- end
-
- private
-
- def Array18(*args)
- return nil if args.empty?
- return args.first if args.length == 1
- return *args
- end
-
-
- end
- end
-end
diff --git a/lib/ohai/mixin/gce_metadata.rb b/lib/ohai/mixin/gce_metadata.rb
index 6a35f5b9..5188b381 100644
--- a/lib/ohai/mixin/gce_metadata.rb
+++ b/lib/ohai/mixin/gce_metadata.rb
@@ -21,6 +21,8 @@ module Ohai
module Mixin
module GCEMetadata
+ extend self
+
GCE_METADATA_ADDR = "metadata.google.internal" unless defined?(GCE_METADATA_ADDR)
GCE_METADATA_URL = "/0.1/meta-data" unless defined?(GCE_METADATA_URL)
diff --git a/lib/ohai/mixin/seconds_to_human.rb b/lib/ohai/mixin/seconds_to_human.rb
deleted file mode 100644
index c5fad1b8..00000000
--- a/lib/ohai/mixin/seconds_to_human.rb
+++ /dev/null
@@ -1,48 +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.
-#
-
-module Ohai
- module Mixin
- module SecondsToHuman
- def seconds_to_human(seconds)
- days = seconds.to_i / 86400
- seconds -= 86400 * days
-
- hours = seconds.to_i / 3600
- seconds -= 3600 * hours
-
- minutes = seconds.to_i / 60
- seconds -= 60 * minutes
-
- if days > 1
- return sprintf("%d days %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds)
- elsif days == 1
- return sprintf("%d day %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds)
- elsif hours > 0
- return sprintf("%d hours %02d minutes %02d seconds", hours, minutes, seconds)
- elsif minutes > 0
- return sprintf("%d minutes %02d seconds", minutes, seconds)
- else
- return sprintf("%02d seconds", seconds)
- end
- end
- end
- end
-end
-
-
diff --git a/lib/ohai/plugins/aix/cpu.rb b/lib/ohai/plugins/aix/cpu.rb
index 3c1af9ce..32b2dc91 100644
--- a/lib/ohai/plugins/aix/cpu.rb
+++ b/lib/ohai/plugins/aix/cpu.rb
@@ -1,7 +1,6 @@
#
-# Author:: Joshua Timberman <joshua@opscode.com>
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013, Opscode, Inc.
+# 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");
@@ -17,33 +16,4 @@
# limitations under the License.
#
-provides "cpu"
-
-cpu Mash.new
-
-# IBM is the only maker of CPUs for AIX systems.
-cpu[:vendor_id] = "IBM"
-# At least one CPU will be available, but we'll wait to increment this later.
-cpu[:available] = 0
-cpu[:total] = 0
-
-cpudevs = from("lsdev -Cc processor").lines
-cpudevs.each do |c|
- cpu[:total] += 1
- name, status, location = c.split
- cpu[name] = Mash.new
- cpu[name][:status] = status
- cpu[name][:location] = location
- if status =~ /Available/
- cpu[:available] += 1
- lsattr = from("lsattr -El #{name}").lines
- lsattr.each do |attribute|
- attrib, value = attribute.split
- cpu[name][attrib] = value
- end
- end
-end
-
-# Every AIX system has proc0.
-cpu[:model] = cpu[:proc0][:type]
-cpu[:mhz] = cpu[:proc0][:frequency].to_i / 1024
+require_plugin "sigar::cpu"
diff --git a/lib/ohai/plugins/aix/filesystem.rb b/lib/ohai/plugins/aix/filesystem.rb
index 785a6b93..8322ee0b 100644
--- a/lib/ohai/plugins/aix/filesystem.rb
+++ b/lib/ohai/plugins/aix/filesystem.rb
@@ -1,7 +1,6 @@
#
-# Author:: Deepali Jagtap (<deepali.jagtap@clogeny.com>)
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
+# 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");
@@ -17,57 +16,4 @@
# limitations under the License.
#
-provides "filesystem"
-
-fs = Mash.new
-
-# Grab filesystem data from df
-popen4("df -P") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- case line
- when /^Filesystem\s+1024-blocks/
- next
- when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/
- filesystem = $1
- fs[filesystem] = Mash.new
- fs[filesystem][:kb_size] = $2
- fs[filesystem][:kb_used] = $3
- fs[filesystem][:kb_available] = $4
- fs[filesystem][:percent_used] = $5
- fs[filesystem][:mount] = $6
- end
- end
-end
-
-# Grab mount information from /bin/mount
-popen4("mount") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- case line
- when /^\s*node/
- next
- when /^\s*---/
- next
- when /^\s*\/\w/
- fields = line.split
- filesystem = fields[0]
- fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
- fs[filesystem][:mount] = fields[1]
- fs[filesystem][:fs_type] = fields[2]
- #fs[filesystem][:mount_options] = fields[6]
- fs[filesystem][:mount_options] = fields[6]
- else
- fields = line.split
- filesystem = fields[0] + ":" + fields[1]
- fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
- fs[filesystem][:mount] = fields[2]
- fs[filesystem][:fs_type] = fields[3]
- fs[filesystem][:mount_options] = fields[7]
- end
- end
-end
-
-# Set the filesystem data
-filesystem fs
-
+require_plugin "sigar::filesystem"
diff --git a/lib/ohai/plugins/aix/hostname.rb b/lib/ohai/plugins/aix/hostname.rb
index 4cf25ba8..805b4734 100644
--- a/lib/ohai/plugins/aix/hostname.rb
+++ b/lib/ohai/plugins/aix/hostname.rb
@@ -16,6 +16,4 @@
# limitations under the License.
#
-provides "hostname"
-
-hostname from("hostname")
+require_plugin "sigar::hostname"
diff --git a/lib/ohai/plugins/aix/kernel.rb b/lib/ohai/plugins/aix/kernel.rb
deleted file mode 100644
index e76e6e35..00000000
--- a/lib/ohai/plugins/aix/kernel.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-#
-# Author:: Joshua Timberman <joshua@opscode.com>
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-provides "kernel"
-
-kernel Mash.new
-
-kernel[:name] = from("uname -s").downcase
-kernel[:release] = from("uname -r")
-kernel[:version] = from("uname -v")
-kernel[:machine] = from("uname -p")
-kernel[:modules] = Mash.new
diff --git a/lib/ohai/plugins/aix/memory.rb b/lib/ohai/plugins/aix/memory.rb
index 88f1c5b8..dd3532fb 100644
--- a/lib/ohai/plugins/aix/memory.rb
+++ b/lib/ohai/plugins/aix/memory.rb
@@ -1,6 +1,6 @@
#
-# Author:: Joshua Timberman <joshua@opscode.com>
-# Copyright:: Copyright (c) 2013, Opscode, Inc.
+# 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");
@@ -16,9 +16,4 @@
# limitations under the License.
#
-provides "memory"
-
-memory = Mash.new
-
-meminfo = from("svmon -G -O unit=MB,summary=longreal | grep '[0-9]'")
-memory[:total], u, memory[:free] = meminfo.split
+require_plugin "sigar::memory"
diff --git a/lib/ohai/plugins/aix/network.rb b/lib/ohai/plugins/aix/network.rb
index 052d2504..7071abef 100644
--- a/lib/ohai/plugins/aix/network.rb
+++ b/lib/ohai/plugins/aix/network.rb
@@ -1,7 +1,6 @@
#
-# Author:: Kaustubh Deorukhkar (<kaustubh@clogeny.com>)
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
+# 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");
@@ -17,139 +16,4 @@
# limitations under the License.
#
-require 'ipaddr'
-provides "network", "counters/network"
-
-# Loads following information.
-# :default_interface, :default_gateway - route -n get 0
-# :interfaces
-# => routes(netstat -nr | grep en0)
-# => addresses (ifconfig en0 or lsattr -El en0), macaddress (entstat -d en0 = Hardware Address: be:42:80:00:b0:05)
-# => flags (ifconfig en0)
-# => state up/down (ifconfig/lsattr)
-# => arp (arp -an)
-
-iface = Mash.new
-
-
-# :default_interface, :default_gateway - route -n get 0
-popen4("route -n get 0") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- case line
- when /gateway: (\S+)/
- network[:default_gateway] = $1
- when /interface: (\S+)/
- network[:default_interface] = $1
- end
- end
-end
-
-# Helpers
-def hex_to_dec_netmask(netmask)
- # example '0xffff0000' -> '255.255.0.0'
- dec = netmask[2..3].to_i(16).to_s(10)
- [4,6,8].each { |n| dec = dec + "." + netmask[n..n+1].to_i(16).to_s(10) }
- dec
-end
-
-# List the interfaces in system.
-popen4("lsdev -Cc if") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- if line =~ /(\S+) (\S+)\s+(.+)/
- interface = $1
- iface[interface] = Mash.new unless iface[interface]
- iface[interface][:state] = ($2 == 'Available' ? 'up' : 'down')
- iface[interface][:description] = $3
-
- # Query the interface information
- popen4("ifconfig #{interface}") do |if_pid, if_stdin, if_stdout, if_stderr|
- if_stdin.close
- if_stdout.each do |line|
- case line
- when /^#{interface}:\sflags=\S+<(\S+)>/
- iface[interface][:flags] = $1.split(',')
- iface[interface][:metric] = $1 if line =~ /metric\s(\S+)/
- else
- # We have key value pairs.
- if line =~ /inet (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\/(\d{1,2}))?/
- tmp_addr, tmp_prefix = $1, $3
- if tmp_prefix.nil?
- netmask = hex_to_dec_netmask($1) if line =~ /netmask\s(\S+)\s/
- unless netmask
- tmp_prefix ||= "32"
- netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
- end
- else
- netmask = IPAddr.new("255.255.255.255").mask(tmp_prefix.to_i).to_s
- end
-
- iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
- iface[interface][:addresses][tmp_addr] = { "family" => "inet", "prefixlen" => tmp_prefix }
- iface[interface][:addresses][tmp_addr][:netmask] = netmask
-
- if line =~ /broadcast\s(\S+)\s/
- iface[interface][:addresses][tmp_addr][:broadcast] = $1
- end
- elsif line =~ /inet6 ([a-f0-9\:%]+)\/(\d+)/
- # TODO do we have more properties on inet6 in aix? broadcast
- iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
- iface[interface][:addresses][$1] = { "family" => "inet6", "prefixlen" => $2 }
- else
- # load all key-values, example "tcp_sendspace 131072 tcp_recvspace 131072 rfc1323 1"
- properties = line.split
- n = properties.length/2 - 1
- (0..n).each do |i|
- iface[interface][properties[i*2]] = properties[(i*2+1)]
- end
- end
- end
- end
- end #ifconfig stdout
-
- # Query macaddress
- popen4("entstat -d #{interface} | grep \"Hardware Address\"") do |e_pid, e_stdin, e_stdout, e_stderr|
- e_stdin.close
- iface[interface][:addresses] = Mash.new unless iface[interface][:addresses]
- e_stdout.each do |line|
- iface[interface][:addresses][$1.upcase] = { "family" => "lladdr" } if line =~ /Hardware Address: (\S+)/
- end
- end
- end
- end #lsdev stdout
-end
-
-# Query routes information
-%w{inet inet6}.each do |family|
- popen4("netstat -nrf #{family}") do |n_pid, n_stdin, n_stdout, n_stderr|
- n_stdin.close
- n_stdout.each do |line|
- if line =~ /(\S+)\s+(\S+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)/
- interface = $6
- iface[interface][:routes] = Array.new unless iface[interface][:routes]
- iface[interface][:routes] << Mash.new( :destination => $1, :family => family,
- :via => $2, :flags => $3)
- end
- end
- end
-end
-
-# List the arp entries in system.
-popen4("arp -an") do |pid, stdin, stdout, stderr|
- stdin.close
- count = 0
- stdout.each do |line|
- network[:arp] = Mash.new unless network[:arp]
- if line =~ /\s*(\S+) \((\S+)\) at ([a-fA-F0-9\:]+) \[(\w+)\] stored in bucket/
- network[:arp][count] = Mash.new unless network[:arp][count]
- network[:arp][count][:remote_host] = $1
- network[:arp][count][:remote_ip] = $2
- network[:arp][count][:remote_mac] = $3.downcase
- count += 1
- end
- end
-end
-
-network["interfaces"] = iface
-
+require_plugin "sigar::network"
diff --git a/lib/ohai/plugins/aix/platform.rb b/lib/ohai/plugins/aix/platform.rb
index 5f29c2fd..bea329d6 100644
--- a/lib/ohai/plugins/aix/platform.rb
+++ b/lib/ohai/plugins/aix/platform.rb
@@ -1,6 +1,6 @@
#
-# Author:: Joshua Timberman <joshua@opscode.com>
-# Copyright:: Copyright (c) 2013, Opscode, Inc.
+# 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");
@@ -16,10 +16,4 @@
# limitations under the License.
#
-require_plugin "#{os}::kernel"
-
-provides "platform", "platform_version", "platform_family"
-
-platform kernel[:name]
-platform_version [kernel[:version], kernel[:release]].join(".")
-platform_family platform
+require_plugin "sigar::platform"
diff --git a/lib/ohai/plugins/aix/uptime.rb b/lib/ohai/plugins/aix/uptime.rb
index b15bffd5..23aa89f3 100644
--- a/lib/ohai/plugins/aix/uptime.rb
+++ b/lib/ohai/plugins/aix/uptime.rb
@@ -1,6 +1,6 @@
#
-# Author:: Kurt Yoder (<ktyopscode@yoderhome.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
+# 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");
@@ -15,20 +15,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'date'
-provides "uptime", "uptime_seconds"
-
-# Example output:
-# $ who -b
-# . system boot Jul 9 17:51
-popen4('who -b') do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- if line =~ /.* boot (.+)/
- uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i
- uptime seconds_to_human(uptime_seconds)
- break
- end
- end
-end
+require_plugin "sigar::uptime"
diff --git a/lib/ohai/plugins/darwin/uptime.rb b/lib/ohai/plugins/darwin/uptime.rb
index ea258ec4..d9cf01f5 100644
--- a/lib/ohai/plugins/darwin/uptime.rb
+++ b/lib/ohai/plugins/darwin/uptime.rb
@@ -25,7 +25,7 @@ popen4("/usr/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr|
stdout.each do |line|
if line =~ /kern.boottime:\D+(\d+)/
uptime_seconds Time.new.to_i - $1.to_i
- uptime seconds_to_human(uptime_seconds)
+ uptime self._seconds_to_human(uptime_seconds)
end
end
end
diff --git a/lib/ohai/plugins/freebsd/uptime.rb b/lib/ohai/plugins/freebsd/uptime.rb
index ea49fa09..7d0da153 100644
--- a/lib/ohai/plugins/freebsd/uptime.rb
+++ b/lib/ohai/plugins/freebsd/uptime.rb
@@ -25,7 +25,7 @@ popen4("/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr|
stdout.each do |line|
if line =~ /kern.boottime:\D+(\d+)/
uptime_seconds Time.new.to_i - $1.to_i
- uptime seconds_to_human(uptime_seconds)
+ uptime self._seconds_to_human(uptime_seconds)
end
end
end
diff --git a/lib/ohai/plugins/gce.rb b/lib/ohai/plugins/gce.rb
index c93f6d57..de5b0b4f 100644
--- a/lib/ohai/plugins/gce.rb
+++ b/lib/ohai/plugins/gce.rb
@@ -18,7 +18,7 @@ provides "gce"
require 'ohai/mixin/gce_metadata'
-extend Ohai::Mixin::GCEMetadata
+
GOOGLE_SYSFS_DMI = '/sys/firmware/dmi/entries/1-0/raw'
#https://developers.google.com/compute/docs/instances#dmi
@@ -27,13 +27,13 @@ def has_google_dmi?
end
def looks_like_gce?
- hint?('gce') || has_google_dmi? && can_metadata_connect?(GCE_METADATA_ADDR,80)
+ hint?('gce') || (has_google_dmi? && Ohai::Mixin::GCEMetadata.can_metadata_connect?(Ohai::Mixin::GCEMetadata::GCE_METADATA_ADDR,80))
end
if looks_like_gce?
Ohai::Log.debug("looks_like_gce? == true")
gce Mash.new
- fetch_metadata.each {|k, v| gce[k] = v }
+ Ohai::Mixin::GCEMetadata.fetch_metadata.each {|k, v| gce[k] = v }
else
Ohai::Log.debug("looks_like_gce? == false")
false
diff --git a/lib/ohai/plugins/linode.rb b/lib/ohai/plugins/linode.rb
index 2be916e5..69613857 100644
--- a/lib/ohai/plugins/linode.rb
+++ b/lib/ohai/plugins/linode.rb
@@ -23,9 +23,7 @@ require_plugin "network"
#
# Returns true or false
def has_linode_kernel?
- if kernel_data = kernel
- kernel_data[:release].split('-').last =~ /linode/
- end
+ kernel[:release].split('-').last =~ /linode/
end
# Identifies the linode cloud by preferring the hint, then
@@ -42,10 +40,8 @@ end
#
# Alters linode mash with new interface based on name parameter
def get_ip_address(name, eth)
- if eth_iface = network[:interfaces][eth]
- eth_iface[:addresses].each do |key, info|
- linode[name] = key if info['family'] == 'inet'
- end
+ network[:interfaces][eth][:addresses].each do |key, info|
+ linode[name] = key if info['family'] == 'inet'
end
end
diff --git a/lib/ohai/plugins/linux/uptime.rb b/lib/ohai/plugins/linux/uptime.rb
index 29f48eec..047cfc19 100644
--- a/lib/ohai/plugins/linux/uptime.rb
+++ b/lib/ohai/plugins/linux/uptime.rb
@@ -20,9 +20,9 @@ provides "uptime", "idletime", "uptime_seconds", "idletime_seconds"
uptime, idletime = File.open("/proc/uptime").gets.split(" ")
uptime_seconds uptime.to_i
-uptime seconds_to_human(uptime.to_i)
+uptime self._seconds_to_human(uptime.to_i)
idletime_seconds idletime.to_i
-idletime seconds_to_human(idletime.to_i)
+idletime self._seconds_to_human(idletime.to_i)
diff --git a/lib/ohai/plugins/netbsd/uptime.rb b/lib/ohai/plugins/netbsd/uptime.rb
index 75470735..85f3588a 100644
--- a/lib/ohai/plugins/netbsd/uptime.rb
+++ b/lib/ohai/plugins/netbsd/uptime.rb
@@ -25,7 +25,7 @@ popen4("/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr|
stdout.each do |line|
if line =~ /kern.boottime:\D+(\d+)/
uptime_seconds Time.new.to_i - $1.to_i
- uptime seconds_to_human(uptime_seconds)
+ uptime self._seconds_to_human(uptime_seconds)
end
end
end
diff --git a/lib/ohai/plugins/openbsd/uptime.rb b/lib/ohai/plugins/openbsd/uptime.rb
index 6028d1e7..3d903321 100644
--- a/lib/ohai/plugins/openbsd/uptime.rb
+++ b/lib/ohai/plugins/openbsd/uptime.rb
@@ -25,7 +25,7 @@ popen4("/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr|
stdout.each do |line|
if line =~ /kern.boottime=(.+)/
uptime_seconds Time.new.to_i - Time.parse($1).to_i
- uptime seconds_to_human(uptime_seconds)
+ uptime self._seconds_to_human(uptime_seconds)
end
end
end
diff --git a/lib/ohai/plugins/sigar/uptime.rb b/lib/ohai/plugins/sigar/uptime.rb
index 8d43d73a..5d2923d1 100644
--- a/lib/ohai/plugins/sigar/uptime.rb
+++ b/lib/ohai/plugins/sigar/uptime.rb
@@ -24,4 +24,4 @@ provides "uptime", "uptime_seconds"
uptime = sigar.uptime.uptime
uptime_seconds uptime.to_i * 1000
-uptime seconds_to_human(uptime.to_i)
+uptime self._seconds_to_human(uptime.to_i)
diff --git a/lib/ohai/plugins/solaris2/uptime.rb b/lib/ohai/plugins/solaris2/uptime.rb
index 804e9da5..e39dfcf8 100644
--- a/lib/ohai/plugins/solaris2/uptime.rb
+++ b/lib/ohai/plugins/solaris2/uptime.rb
@@ -29,7 +29,7 @@ popen4('who -b') do |pid, stdin, stdout, stderr|
stdout.each do |line|
if line =~ /.* boot (.+)/
uptime_seconds Time.now.to_i - DateTime.parse($1).strftime('%s').to_i
- uptime seconds_to_human(uptime_seconds)
+ uptime self._seconds_to_human(uptime_seconds)
break
end
end
diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb
index c5f9c58f..1930a746 100644
--- a/lib/ohai/plugins/uptime.rb
+++ b/lib/ohai/plugins/uptime.rb
@@ -16,4 +16,27 @@
# limitations under the License.
#
+def _seconds_to_human(seconds)
+ days = seconds.to_i / 86400
+ seconds -= 86400 * days
+
+ hours = seconds.to_i / 3600
+ seconds -= 3600 * hours
+
+ minutes = seconds.to_i / 60
+ seconds -= 60 * minutes
+
+ if days > 1
+ return sprintf("%d days %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds)
+ elsif days == 1
+ return sprintf("%d day %02d hours %02d minutes %02d seconds", days, hours, minutes, seconds)
+ elsif hours > 0
+ return sprintf("%d hours %02d minutes %02d seconds", hours, minutes, seconds)
+ elsif minutes > 0
+ return sprintf("%d minutes %02d seconds", minutes, seconds)
+ else
+ return sprintf("%02d seconds", seconds)
+ end
+end
+
diff --git a/lib/ohai/plugins/windows/uptime.rb b/lib/ohai/plugins/windows/uptime.rb
index 2dcc0e48..7ad4ab75 100644
--- a/lib/ohai/plugins/windows/uptime.rb
+++ b/lib/ohai/plugins/windows/uptime.rb
@@ -20,4 +20,4 @@ require 'ruby-wmi'
provides "uptime", "uptime_seconds"
uptime_seconds ::WMI::Win32_PerfFormattedData_PerfOS_System.find(:first).SystemUpTime.to_i
-uptime seconds_to_human(uptime_seconds)
+uptime self._seconds_to_human(uptime_seconds)
diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb
index 8e5e212a..8721be32 100644
--- a/lib/ohai/system.rb
+++ b/lib/ohai/system.rb
@@ -18,7 +18,6 @@
require 'ohai/mash'
require 'ohai/log'
-require 'ohai/dsl/plugin'
require 'ohai/mixin/from_file'
require 'ohai/mixin/command'
require 'ohai/mixin/string'
@@ -28,10 +27,10 @@ require 'yajl'
module Ohai
class System
- attr_accessor :data
- attr_reader :seen_plugins
- attr_reader :hints
- attr_reader :providers
+ attr_accessor :data, :seen_plugins, :hints
+
+ include Ohai::Mixin::FromFile
+ include Ohai::Mixin::Command
def initialize
@data = Mash.new
@@ -45,6 +44,87 @@ module Ohai
@data[key]
end
+ def []=(key, value)
+ @data[key] = value
+ end
+
+ def each(&block)
+ @data.each do |key, value|
+ block.call(key, value)
+ end
+ end
+
+ def attribute?(name)
+ @data.has_key?(name)
+ end
+
+ def set(name, *value)
+ set_attribute(name, *value)
+ end
+
+ def from(cmd)
+ status, stdout, stderr = run_command(:command => cmd)
+ return "" if stdout.nil? || stdout.empty?
+ stdout.strip
+ end
+
+ def provides(*paths)
+ paths.each do |path|
+ parts = path.split('/')
+ h = @providers
+ unless parts.length == 0
+ parts.shift if parts[0].length == 0
+ parts.each do |part|
+ h[part] ||= Mash.new
+ h = h[part]
+ end
+ end
+ h[:_providers] ||= []
+ h[:_providers] << @plugin_path
+ end
+ end
+
+ # Set the value equal to the stdout of the command, plus run through a regex - the first piece of match data is the value.
+ def from_with_regex(cmd, *regex_list)
+ regex_list.flatten.each do |regex|
+ status, stdout, stderr = run_command(:command => cmd)
+ return "" if stdout.nil? || stdout.empty?
+ stdout.chomp!.strip
+ md = stdout.match(regex)
+ return md[1]
+ end
+ end
+
+ def set_attribute(name, *values)
+ @data[name] = Array18(*values)
+ @data[name]
+ end
+
+ def get_attribute(name)
+ @data[name]
+ end
+
+ def hint?(name)
+ @json_parser ||= Yajl::Parser.new
+
+ return @hints[name] if @hints[name]
+
+ Ohai::Config[:hints_path].each do |path|
+ filename = File.join(path, "#{name}.json")
+ if File.exist?(filename)
+ begin
+ hash = @json_parser.parse(File.read(filename))
+ @hints[name] = hash || Hash.new # hint should exist because the file did, even if it didn't contain anything
+ rescue Yajl::ParseError => e
+ Ohai::Log.error("Could not parse hint file at #{filename}: #{e.message}")
+ end
+ end
+ end
+
+ @hints[name]
+ end
+
+
def all_plugins
require_plugin('os')
@@ -124,37 +204,30 @@ module Ohai
return false
end
- if plugin = plugin_for(plugin_name)
- @seen_plugins[plugin_name] = true
+ @plugin_path = plugin_name
+
+ filename = "#{plugin_name.gsub("::", File::SEPARATOR)}.rb"
+
+ Ohai::Config[:plugin_path].each do |path|
+ check_path = File.expand_path(File.join(path, filename))
begin
- plugin.run
- true
+ @seen_plugins[plugin_name] = true
+ Ohai::Log.debug("Loading plugin #{plugin_name}")
+ from_file(check_path)
+ return true
+ rescue Errno::ENOENT => e
+ Ohai::Log.debug("No #{plugin_name} at #{check_path}")
rescue SystemExit, Interrupt
raise
rescue Exception,Errno::ENOENT => e
Ohai::Log.debug("Plugin #{plugin_name} threw exception #{e.inspect} #{e.backtrace.join("\n")}")
end
- else
- Ohai::Log.debug("No #{plugin_name} found in #{Ohai::Config[:plugin_path]}")
end
end
- def plugin_for(plugin_name)
- filename = "#{plugin_name.gsub("::", File::SEPARATOR)}.rb"
-
- plugin = nil
-
- Ohai::Config[:plugin_path].each do |path|
- check_path = File.expand_path(File.join(path, filename))
- if File.exist?(check_path)
- plugin = DSL::Plugin.new(self, check_path)
- break
- else
- next
- end
- end
- plugin
- end
+ # Sneaky! Lets us stub out require_plugin when testing plugins, but still
+ # call the real require_plugin to kick the whole thing off.
+ alias :_require_plugin :require_plugin
# Serialize this object as a hash
def to_json
@@ -186,6 +259,18 @@ module Ohai
end
end
+ def method_missing(name, *args)
+ return get_attribute(name) if args.length == 0
+ set_attribute(name, *args)
+ end
+
+ private
+
+ def Array18(*args)
+ return nil if args.empty?
+ return args.first if args.length == 1
+ return *args
+ end
end
end
diff --git a/ohai.gemspec b/ohai.gemspec
index 945f866e..e4cb7e70 100644
--- a/ohai.gemspec
+++ b/ohai.gemspec
@@ -2,7 +2,7 @@
$:.unshift File.expand_path('../lib', __FILE__)
require 'ohai/version'
-Gem::Specification.new do |s|
+spec = Gem::Specification.new do |s|
s.name = "ohai"
s.version = Ohai::VERSION
s.platform = Gem::Platform::RUBY
@@ -32,7 +32,6 @@ Gem::Specification.new do |s|
s.add_development_dependency "rspec-expectations"
s.add_development_dependency "rspec-mocks"
s.add_development_dependency "rspec_junit_formatter"
- s.add_development_dependency "chef"
s.bindir = "bin"
s.executables = %w(ohai)
diff --git a/spec/data/plugins/foo.rb b/spec/data/plugins/foo.rb
deleted file mode 100644
index e69de29b..00000000
--- a/spec/data/plugins/foo.rb
+++ /dev/null
diff --git a/spec/ohai/dsl/plugin_spec.rb b/spec/ohai/dsl/plugin_spec.rb
deleted file mode 100644
index d0c30747..00000000
--- a/spec/ohai/dsl/plugin_spec.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# Author:: Adam Jacob (<adam@opscode.com>)
-# Author:: Daniel DeLeo (<dan@opscode.com>)
-# Copyright:: Copyright (c) 2008, 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 File.expand_path("../../../spec_helper", __FILE__)
-
-describe Ohai::DSL::Plugin do
- before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, "")
- end
-
- describe "when accessing data via method_missing" do
-
- it "should take a missing method and store the method name as a key, with its arguments as values" do
- @plugin.guns_n_roses("chinese democracy")
- @plugin.data["guns_n_roses"].should eql("chinese democracy")
- end
-
- it "should return the current value of the method name" do
- @plugin.guns_n_roses("chinese democracy").should eql("chinese democracy")
- end
-
- it "should allow you to get the value of a key by calling method_missing with no arguments" do
- @plugin.guns_n_roses("chinese democracy")
- @plugin.guns_n_roses.should eql("chinese democracy")
- end
- end
-
- describe "when checking attribute existence" do
- before(:each) do
- @plugin.metallica("death magnetic")
- end
-
- it "should return true if an attribute exists with the given name" do
- @plugin.attribute?("metallica").should eql(true)
- end
-
- it "should return false if an attribute does not exist with the given name" do
- @plugin.attribute?("alice in chains").should eql(false)
- end
- end
-
- describe "when setting attributes" do
- it "should let you set an attribute" do
- @plugin.set_attribute(:tea, "is soothing")
- @plugin.data["tea"].should eql("is soothing")
- end
- end
-
- describe "when getting attributes" do
- before(:each) do
- @plugin.set_attribute(:tea, "is soothing")
- end
-
- it "should let you get an attribute" do
- @plugin.get_attribute("tea").should eql("is soothing")
- end
- end
-end
-
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2119dc7b..8f41764f 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -7,44 +7,41 @@ require 'spec/support/platform_helpers'
require 'ohai'
Ohai::Config[:log_level] = :error
-PLUGIN_PATH = File.expand_path("../../lib/ohai/plugins", __FILE__)
-SPEC_PLUGIN_PATH = File.expand_path("../data/plugins", __FILE__)
-
def it_should_check_from(plugin, attribute, from, value)
it "should set the #{attribute} to the value from '#{from}'" do
- @plugin.run
- @plugin[attribute].should == value
+ @ohai._require_plugin(plugin)
+ @ohai[attribute].should == value
end
end
def it_should_check_from_mash(plugin, attribute, from, value)
it "should get the #{plugin}[:#{attribute}] value from '#{from}'" do
- @plugin.should_receive(:from).with(from).and_return(value)
- @plugin.run
+ @ohai.should_receive(:from).with(from).and_return(value)
+ @ohai._require_plugin(plugin)
end
it "should set the #{plugin}[:#{attribute}] to the value from '#{from}'" do
- @plugin.run
- @plugin[plugin][attribute].should == value
+ @ohai._require_plugin(plugin)
+ @ohai[plugin][attribute].should == value
end
end
# the mash variable may be an array listing multiple levels of Mash hierarchy
def it_should_check_from_deep_mash(plugin, mash, attribute, from, value)
it "should get the #{mash.inspect}[:#{attribute}] value from '#{from}'" do
- @plugin.should_receive(:from).with(from).and_return(value)
- @plugin.run
+ @ohai.should_receive(:from).with(from).and_return(value)
+ @ohai._require_plugin(plugin)
end
it "should set the #{mash.inspect}[:#{attribute}] to the value from '#{from}'" do
- @plugin.run
+ @ohai._require_plugin(plugin)
if mash.is_a?(String)
- @plugin[mash][attribute].should == value
+ @ohai[mash][attribute].should == value
elsif mash.is_a?(Array)
if mash.length == 2
- @plugin[mash[0]][mash[1]][attribute].should == value
+ @ohai[mash[0]][mash[1]][attribute].should == value
elsif mash.length == 3
- @plugin[mash[0]][mash[1]][mash[2]][attribute].should == value
+ @ohai[mash[0]][mash[1]][mash[2]][attribute].should == value
else
return nil
end
diff --git a/spec/unit/mixin/ec2_metadata_spec.rb b/spec/unit/mixin/ec2_metadata_spec.rb
index 1f5a65a2..a91da4c1 100644
--- a/spec/unit/mixin/ec2_metadata_spec.rb
+++ b/spec/unit/mixin/ec2_metadata_spec.rb
@@ -22,15 +22,15 @@ require 'ohai/mixin/ec2_metadata'
describe Ohai::Mixin::Ec2Metadata do
let(:mixin) {
metadata_object = Object.new.extend(Ohai::Mixin::Ec2Metadata)
- http_client = double("Net::HTTP client")
- http_client.stub(:get).and_return(response)
- metadata_object.stub(:http_client).and_return(http_client)
+ http_client = mock("Net::HTTP client")
+ http_client.stub!(:get).and_return(response)
+ metadata_object.stub!(:http_client).and_return(http_client)
metadata_object
}
context "#best_api_version" do
context "with a sorted list of metadata versions" do
- let(:response) { double("Net::HTTP Response", :body => "1.0\n2011-05-01\n2012-01-12\nUnsupported", :code => "200") }
+ let(:response) { mock("Net::HTTP Response", :body => "1.0\n2011-05-01\n2012-01-12\nUnsupported", :code => "200") }
it "returns the most recent version" do
mixin.best_api_version.should == "2012-01-12"
@@ -38,7 +38,7 @@ describe Ohai::Mixin::Ec2Metadata do
end
context "with an unsorted list of metadata versions" do
- let(:response) { double("Net::HTTP Response", :body => "1.0\n2009-04-04\n2007-03-01\n2011-05-01\n2008-09-01\nUnsupported", :code => "200") }
+ let(:response) { mock("Net::HTTP Response", :body => "1.0\n2009-04-04\n2007-03-01\n2011-05-01\n2008-09-01\nUnsupported", :code => "200") }
it "returns the most recent version (using string sort)" do
mixin.best_api_version.should == "2011-05-01"
@@ -46,7 +46,7 @@ describe Ohai::Mixin::Ec2Metadata do
end
context "when no supported versions are found" do
- let(:response) { double("Net::HTTP Response", :body => "2020-01-01\nUnsupported", :code => "200") }
+ let(:response) { mock("Net::HTTP Response", :body => "2020-01-01\nUnsupported", :code => "200") }
it "raises an error" do
lambda { mixin.best_api_version}.should raise_error
@@ -54,7 +54,7 @@ describe Ohai::Mixin::Ec2Metadata do
end
context "when the response code is 404" do
- let(:response) { double("Net::HTTP Response", :body => "1.0\n2011-05-01\n2012-01-12\nUnsupported", :code => "404") }
+ let(:response) { mock("Net::HTTP Response", :body => "1.0\n2011-05-01\n2012-01-12\nUnsupported", :code => "404") }
it "raises an error" do
lambda { mixin.best_api_version}.should raise_error
@@ -62,7 +62,7 @@ describe Ohai::Mixin::Ec2Metadata do
end
context "when the response code is unexpected" do
- let(:response) { double("Net::HTTP Response", :body => "1.0\n2011-05-01\n2012-01-12\nUnsupported", :code => "418") }
+ let(:response) { mock("Net::HTTP Response", :body => "1.0\n2011-05-01\n2012-01-12\nUnsupported", :code => "418") }
it "raises an error" do
lambda { mixin.best_api_version}.should raise_error
@@ -72,7 +72,7 @@ describe Ohai::Mixin::Ec2Metadata do
context "#metadata_get" do
context "when the response code is unexpected" do
- let(:response) { double("Net::HTTP Response", :body => "", :code => "418") }
+ let(:response) { mock("Net::HTTP Response", :body => "", :code => "418") }
it "raises an error" do
lambda { mixin.metadata_get('', '2012-01-12') }.should raise_error(RuntimeError)
diff --git a/spec/unit/mixin/from_file_spec.rb b/spec/unit/mixin/from_file_spec.rb
new file mode 100644
index 00000000..ce8fc421
--- /dev/null
+++ b/spec/unit/mixin/from_file_spec.rb
@@ -0,0 +1,53 @@
+#
+# 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.
+#
+
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
+
+describe Ohai::System, "from_file" do
+ before(:each) do
+ @ohai = Ohai::System.new
+ File.stub!(:exists?).and_return(true)
+ File.stub!(:readable?).and_return(true)
+ IO.stub!(:read).and_return("king 'herod'")
+ end
+
+ it "should check to see that the file exists" do
+ File.should_receive(:exists?).and_return(true)
+ @ohai.from_file("/tmp/foo")
+ end
+
+ it "should check to see that the file is readable" do
+ File.should_receive(:readable?).and_return(true)
+ @ohai.from_file("/tmp/foo")
+ end
+
+ it "should actually read the file" do
+ IO.should_receive(:read).and_return("king 'herod'")
+ @ohai.from_file("/tmp/foo")
+ end
+
+ it "should call instance_eval with the contents of the file, file name, and line 1" do
+ @ohai.should_receive(:instance_eval).with("king 'herod'", "/tmp/foo", 1)
+ @ohai.from_file("/tmp/foo")
+ end
+
+ it "should raise an IOError if it cannot read the file" do
+ File.stub!(:exists?).and_return(false)
+ lambda { @ohai.from_file("/tmp/foo") }.should raise_error(IOError)
+ end
+end
diff --git a/spec/unit/plugins/aix/cpu_spec.rb b/spec/unit/plugins/aix/cpu_spec.rb
deleted file mode 100644
index 2ffb4977..00000000
--- a/spec/unit/plugins/aix/cpu_spec.rb
+++ /dev/null
@@ -1,78 +0,0 @@
-#
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-
-describe Ohai::System, "AIX cpu plugin" do
- before do
- @lsdev_Cc_processor = <<-LSDEV_CC_PROCESSOR
-proc0 Available 00-00 Processor
-proc4 Defined 00-04 Processor
-LSDEV_CC_PROCESSOR
-
- @lsattr_El_proc0 = <<-LSATTR_EL
-frequency 1654344000 Processor Speed False
-smt_enabled true Processor SMT enabled False
-smt_threads 2 Processor SMT threads False
-state enable Processor state False
-type PowerPC_POWER5 Processor type False
-LSATTR_EL
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("aix/cpu.rb", PLUGIN_PATH))
- @plugin.stub(:from).with("lsdev -Cc processor").and_return(@lsdev_Cc_processor)
- @plugin.stub(:from).with("lsattr -El proc0").and_return(@lsattr_El_proc0)
- @plugin.run
- end
-
- it "sets the vendor id to IBM" do
- @plugin[:cpu][:vendor_id].should == "IBM"
- end
-
- it "sets the available attribute" do
- @plugin[:cpu][:available].should == 1
- end
-
- it "sets the total number of devices" do
- @plugin[:cpu][:total].should == 2
- end
-
- it "detects the model" do
- @plugin[:cpu][:model].should == "PowerPC_POWER5"
- end
-
- it "detects the mhz" do
- @plugin[:cpu][:mhz].should == 1615570
- end
-
- it "detects the status of the device" do
- @plugin[:cpu][:proc0][:status].should == "Available"
- end
-
- it "detects the location of the device" do
- @plugin[:cpu][:proc0][:location].should == "00-00"
- end
-
- context "lsattr -El device_name" do
- it "detects all the attributes of the device" do
- @plugin[:cpu][:proc0][:frequency].should == "1654344000"
- @plugin[:cpu][:proc0][:smt_enabled].should == "true"
- @plugin[:cpu][:proc0][:smt_threads].should == "2"
- @plugin[:cpu][:proc0][:state].should == "enable"
- @plugin[:cpu][:proc0][:type].should == "PowerPC_POWER5"
- end
- end
-end
diff --git a/spec/unit/plugins/aix/filesystem_spec.rb b/spec/unit/plugins/aix/filesystem_spec.rb
deleted file mode 100644
index 58a88240..00000000
--- a/spec/unit/plugins/aix/filesystem_spec.rb
+++ /dev/null
@@ -1,117 +0,0 @@
-#
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-
-describe Ohai::System, "AIX filesystem plugin" do
- before do
- @df_P = <<-DF_P
-Filesystem 512-blocks Used Available Capacity Mounted on
-/dev/hd4 786432 495632 290800 64% /
-/dev/hd2 10485760 8743200 1742560 84% /usr
-/dev/hd9var 2621440 1152952 1468488 44% /var
-/dev/hd3 2621440 541928 2079512 21% /tmp
-/dev/hd1 8650752 6098080 2552672 71% /home
-/dev/hd11admin 262144 760 261384 1% /admin
-/proc - - - - /proc
-/dev/hd10opt 3407872 1744384 1663488 52% /opt
-192.168.1.11:/stage/middleware 314572800 177025952 137546848 57% /stage/middleware
-DF_P
-
- @mount = <<-MOUNT
- node mounted mounted over vfs date options
--------- --------------- --------------- ------ ------------ ---------------
- /dev/hd4 / jfs2 Jul 17 13:22 rw,log=/dev/hd8
- /dev/hd2 /usr jfs2 Jul 17 13:22 rw,log=/dev/hd8
- /dev/hd9var /var jfs2 Jul 17 13:22 rw,log=/dev/hd8
- /dev/hd3 /tmp jfs2 Jul 17 13:22 rw,log=/dev/hd8
- /dev/hd1 /home jfs2 Jul 17 13:22 rw,log=/dev/hd8
- /dev/hd11admin /admin jfs2 Jul 17 13:22 rw,log=/dev/hd8
- /proc /proc procfs Jul 17 13:22 rw
- /dev/hd10opt /opt jfs2 Jul 17 13:22 rw,log=/dev/hd8
-192.168.1.11 /stage/middleware /stage/middleware nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
-MOUNT
-
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("aix/filesystem.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:filesystem] = Mash.new
- @plugin.stub(:popen4).with("df -P").and_yield(nil, StringIO.new, StringIO.new(@df_P), nil)
- @plugin.stub(:popen4).with("mount").and_yield(nil, StringIO.new, StringIO.new(@mount), nil)
- end
-
- describe "df -P" do
- before do
- @plugin.run
- end
-
- it "returns the filesystem block size" do
- @plugin[:filesystem]["/dev/hd4"]['kb_size'].should == "786432"
- end
-
- it "returns the filesystem used space in kb" do
- @plugin[:filesystem]["/dev/hd4"]['kb_used'].should == "495632"
- end
-
- it "returns the filesystem available space in kb" do
- @plugin[:filesystem]["/dev/hd4"]['kb_available'].should == "290800"
- end
-
- it "returns the filesystem capacity in percentage" do
- @plugin[:filesystem]["/dev/hd4"]['percent_used'].should == "64%"
- end
-
- it "returns the filesystem mounted location" do
- @plugin[:filesystem]["/dev/hd4"]['mount'].should == "/"
- end
- end
-
- describe "mount" do
- before do
- @plugin.run
- end
-
- it "returns the filesystem mount location" do
- @plugin[:filesystem]["/dev/hd4"]['mount'].should == "/"
- end
-
- it "returns the filesystem type" do
- @plugin[:filesystem]["/dev/hd4"]['fs_type'].should == "jfs2"
- end
-
- it "returns the filesystem mount options" do
- @plugin[:filesystem]["/dev/hd4"]['mount_options'].should == "rw,log=/dev/hd8"
- end
-
- # For entries like 192.168.1.11 /stage/middleware /stage/middleware nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys
- context "having node values" do
- before do
- @plugin.stub(:popen4).with("mount").and_yield(nil, StringIO.new, StringIO.new("192.168.1.11 /stage/middleware /stage/middleware nfs3 Jul 17 13:24 ro,bg,hard,intr,sec=sys"), nil)
- end
- it "returns the filesystem mount location" do
- @plugin[:filesystem]["192.168.1.11:/stage/middleware"]['mount'].should == "/stage/middleware"
- end
-
- it "returns the filesystem type" do
- @plugin[:filesystem]["192.168.1.11:/stage/middleware"]['fs_type'].should == "nfs3"
- end
-
- it "returns the filesystem mount options" do
- @plugin[:filesystem]["192.168.1.11:/stage/middleware"]['mount_options'].should == "ro,bg,hard,intr,sec=sys"
- end
- end
- end
-end
diff --git a/spec/unit/plugins/aix/hostname_spec.rb b/spec/unit/plugins/aix/hostname_spec.rb
deleted file mode 100644
index 495d81fa..00000000
--- a/spec/unit/plugins/aix/hostname_spec.rb
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-
-describe Ohai::System, "Aix hostname plugin" do
- before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("aix/hostname.rb", PLUGIN_PATH))
- @plugin.stub(:from).with("hostname").and_return("aix_admin")
- end
-
- it_should_check_from("aix::hostname", "hostname", "hostname", "aix_admin")
-end
diff --git a/spec/unit/plugins/aix/kernel_spec.rb b/spec/unit/plugins/aix/kernel_spec.rb
deleted file mode 100644
index 48a7d639..00000000
--- a/spec/unit/plugins/aix/kernel_spec.rb
+++ /dev/null
@@ -1,52 +0,0 @@
-#
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-
-describe Ohai::System, "AIX kernel plugin" do
- before do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("aix/kernel.rb", PLUGIN_PATH))
- @plugin.stub(:from).with("uname -s").and_return("AIX")
- @plugin.stub(:from).with("uname -r").and_return(1)
- @plugin.stub(:from).with("uname -v").and_return(6)
- @plugin.stub(:from).with("uname -p").and_return("powerpc")
- @plugin.run
- @modules = Mash.new
- @plugin[:kernel].stub(:modules).and_return(@modules)
- end
-
- it "uname -s detects the name" do
- @plugin[:kernel][:name].should == "aix"
- end
-
- it "uname -r detects the release" do
- @plugin[:kernel][:release].should == 1
- end
-
- it "uname -v detects the version" do
- @plugin[:kernel][:version].should == 6
- end
-
- it "uname -p detects the machine" do
- @plugin[:kernel][:machine].should == "powerpc"
- end
-
- it "detects the modules" do
- @plugin[:kernel][:modules].should == @modules
- end
-end
diff --git a/spec/unit/plugins/aix/network_spec.rb b/spec/unit/plugins/aix/network_spec.rb
deleted file mode 100644
index 7df41feb..00000000
--- a/spec/unit/plugins/aix/network_spec.rb
+++ /dev/null
@@ -1,277 +0,0 @@
-#
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-
-describe Ohai::System, "AIX network plugin" do
-
- before do
- @route_n_get_0 = <<-ROUTE_N_GET_0
- route to: default
-destination: default
- mask: default
- gateway: 172.29.128.13
- interface: en0
-interf addr: 172.29.174.58
- flags: <UP,GATEWAY,DONE>
- recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
- 0 0 0 0 0 0 0 -79
-ROUTE_N_GET_0
-
- @lsdev_Cc_if = <<-LSDEV_CC_IF
-en0 Available Standard Ethernet Network Interface
-LSDEV_CC_IF
-
- @ifconfig_en0 = <<-IFCONFIG_EN0
-en0: flags=1e080863,480<UP,BROADCAST,NOTRAILERS,RUNNING,SIMPLEX,MULTICAST,GROUPRT,64BIT,CHECKSUM_OFFLOAD(ACTIVE),CHAIN> metric 1
- inet 172.29.174.58 netmask 0xffffc000 broadcast 172.29.191.255
- inet 172.29.174.59 broadcast 172.29.191.255
- inet 172.29.174.60 netmask 0xffffc000 broadcast 172.29.191.255
- inet6 ::1%1/0
- tcp_sendspace 262144 tcp_recvspace 262144 rfc1323 1
-IFCONFIG_EN0
-
- @netstat_nrf_inet = <<-NETSTAT_NRF_INET
-Destination Gateway Flags Refs Use If Exp Groups
-Route Tree for Protocol Family 2 (Internet):
-default 172.29.128.13 UG 0 587683 en0 - -
-172.29.128.0 172.29.174.58 UHSb 0 0 en0 - - =>
-172.29.128/18 172.29.174.58 U 7 1035485 en0 - -
-172.29.191.255 172.29.174.58 UHSb 0 1 en0 - -
-NETSTAT_NRF_INET
-
- @aix_arp_an = <<-ARP_AN
- ? (172.29.131.16) at 6e:87:70:0:40:3 [ethernet] stored in bucket 16
-
- ? (10.153.50.202) at 34:40:b5:ab:fb:5a [ethernet] stored in bucket 40
-
- ? (10.153.1.99) at 52:54:0:8e:f2:fb [ethernet] stored in bucket 58
-
- ? (172.29.132.250) at 34:40:b5:a5:d7:1e [ethernet] stored in bucket 59
-
- ? (172.29.132.253) at 34:40:b5:a5:d7:2a [ethernet] stored in bucket 62
-
- ? (172.29.128.13) at 60:73:5c:69:42:44 [ethernet] stored in bucket 139
-
-bucket: 0 contains: 0 entries
-There are 6 entries in the arp table.
-ARP_AN
-
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("aix/network.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:network] = Mash.new
- @plugin.stub(:popen4).with("route -n get 0").and_yield(nil, StringIO.new, StringIO.new(@route_n_get_0), nil)
- @plugin.stub(:popen4).with("lsdev -Cc if").and_yield(nil, StringIO.new, StringIO.new(@lsdev_Cc_if), nil)
- @plugin.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new(@ifconfig_en0), nil)
- @plugin.stub(:popen4).with("entstat -d en0 | grep \"Hardware Address\"").and_yield(nil, StringIO.new, StringIO.new("Hardware Address: be:42:80:00:b0:05"), nil)
- @plugin.stub(:popen4).with("netstat -nrf inet").and_yield(nil, StringIO.new, StringIO.new(@netstat_nrf_inet), nil)
- @plugin.stub(:popen4).with("netstat -nrf inet6").and_yield(nil, StringIO.new, StringIO.new("::1%1 ::1%1 UH 1 109392 en0 - -"), nil)
- @plugin.stub(:popen4).with("arp -an").and_yield(nil, StringIO.new, StringIO.new(@aix_arp_an), nil)
- end
-
- describe "run" do
- before(:each) do
- @plugin.run
- end
-
- it "detects network information" do
- @plugin['network'].should_not be_nil
- end
-
- it "detects the interfaces" do
- @plugin['network']['interfaces'].keys.sort.should == ["en0"]
- end
-
- it "detects the ip addresses of the interfaces" do
- @plugin['network']['interfaces']['en0']['addresses'].keys.should include('172.29.174.58')
- end
- end
-
- describe "route -n get 0" do
- before do
- @plugin.run
- end
-
- it "returns the default gateway of the system's network" do
- @plugin[:network][:default_gateway].should == '172.29.128.13'
- end
-
- it "returns the default interface of the system's network" do
- @plugin[:network][:default_interface].should == 'en0'
- end
- end
-
- describe "lsdev -Cc if" do
- before do
- @plugin.run
- end
-
- it "detects the state of the interfaces in the system" do
- @plugin['network']['interfaces']['en0'][:state].should == "up"
- end
-
- it "detects the description of the interfaces in the system" do
- @plugin['network']['interfaces']['en0'][:description].should == "Standard Ethernet Network Interface"
- end
-
- describe "ifconfig interface" do
- it "detects the CHAIN network flag" do
- @plugin['network']['interfaces']['en0'][:flags].should include('CHAIN')
- end
-
- it "detects the metric network flag" do
- @plugin['network']['interfaces']['en0'][:metric].should == '1'
- end
-
- context "inet entries" do
- before do
- @inet_entry = @plugin['network']['interfaces']['en0'][:addresses]["172.29.174.58"]
- end
- it "detects the family" do
- @inet_entry[:family].should == 'inet'
- end
-
- it "detects the netmask" do
- @inet_entry[:netmask].should == '255.255.192.0'
- end
-
- it "detects the broadcast" do
- @inet_entry[:broadcast].should == '172.29.191.255'
- end
-
- it "detects all key-values" do
- @plugin['network']['interfaces']['en0'][:tcp_sendspace].should == "262144"
- @plugin['network']['interfaces']['en0'][:tcp_recvspace].should == "262144"
- @plugin['network']['interfaces']['en0'][:rfc1323].should == "1"
- end
-
- # For an output with no netmask like inet 172.29.174.59 broadcast 172.29.191.255
- context "with no netmask in the output" do
- before do
- @inet_entry = @plugin['network']['interfaces']['en0'][:addresses]["172.29.174.59"]
- @plugin.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new("inet 172.29.174.59 broadcast 172.29.191.255"), nil)
- end
-
- it "detects the default prefixlen" do
- @inet_entry[:prefixlen].should == '32'
- end
-
- it "detects the default netmask" do
- @inet_entry[:netmask].should == '255.255.255.255'
- end
- end
- end
-
- context "inet6 entries" do
- before do
- @inet_entry = @plugin['network']['interfaces']['en0'][:addresses]["::1%1"]
- @plugin.stub(:popen4).with("ifconfig en0").and_yield(nil, StringIO.new, StringIO.new("inet6 ::1%1/0"), nil)
- end
-
- it "detects the prefixlen" do
- @inet_entry[:prefixlen].should == '0'
- end
-
- it "detects the family" do
- @inet_entry[:family].should == 'inet6'
- end
- end
- end
-
- context "entstat -d interface" do
- before do
- @inet_interface_addresses = @plugin['network']['interfaces']['en0'][:addresses]["BE:42:80:00:B0:05"]
- end
- it "detects the family" do
- @inet_interface_addresses[:family].should == 'lladdr'
- end
- end
- end
-
- describe "netstat -nrf family" do
- context "inet" do
- before do
- @plugin.run
- end
-
- it "detects the route destinations" do
- @plugin['network']['interfaces']['en0'][:routes][0][:destination].should == "default"
- @plugin['network']['interfaces']['en0'][:routes][1][:destination].should == "172.29.128.0"
- end
-
- it "detects the route family" do
- @plugin['network']['interfaces']['en0'][:routes][0][:family].should == "inet"
- end
-
- it "detects the route gateway" do
- @plugin['network']['interfaces']['en0'][:routes][0][:via].should == "172.29.128.13"
- end
-
- it "detects the route flags" do
- @plugin['network']['interfaces']['en0'][:routes][0][:flags].should == "UG"
- end
- end
-
- context "inet6" do
- before do
- @plugin.run
- end
-
- it "detects the route destinations" do
- @plugin['network']['interfaces']['en0'][:routes][4][:destination].should == "::1%1"
- end
-
- it "detects the route family" do
- @plugin['network']['interfaces']['en0'][:routes][4][:family].should == "inet6"
- end
-
- it "detects the route gateway" do
- @plugin['network']['interfaces']['en0'][:routes][4][:via].should == "::1%1"
- end
-
- it "detects the route flags" do
- @plugin['network']['interfaces']['en0'][:routes][4][:flags].should == "UH"
- end
- end
- end
-
- describe "arp -an" do
- before do
- @plugin.run
- end
-
- it "supresses the hostname entries" do
- @plugin['network']['arp'][0][:remote_host].should == "?"
- end
-
- it "detects the remote ip entry" do
- @plugin['network']['arp'][0][:remote_ip].should == "172.29.131.16"
- end
-
- it "detects the remote mac entry" do
- @plugin['network']['arp'][0][:remote_mac].should == "6e:87:70:0:40:3"
- end
- end
-
- describe "hex_to_dec_netmask method" do
- it "converts a netmask from hexadecimal form to decimal form" do
- @plugin.run
- @plugin.hex_to_dec_netmask('0xffff0000').should == "255.255.0.0"
- end
- end
-end
diff --git a/spec/unit/plugins/aix/platform_spec.rb b/spec/unit/plugins/aix/platform_spec.rb
deleted file mode 100644
index aa90411b..00000000
--- a/spec/unit/plugins/aix/platform_spec.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-#
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-
-describe Ohai::System, "Aix plugin platform" do
- before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("aix/platform.rb", PLUGIN_PATH))
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:name] = "aix"
- @plugin[:kernel][:version] = "1"
- @plugin[:kernel][:release] = "0"
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.run
- end
-
- it "should set platform to aix" do
- @plugin[:platform].should == "aix"
- end
-
- it "should set the platform_version" do
- @plugin[:platform_version].should == "1.0"
- end
-
- it "should set platform_family" do
- @plugin[:platform_family].should == @plugin[:platform]
- end
-end
diff --git a/spec/unit/plugins/aix/uptime_spec.rb b/spec/unit/plugins/aix/uptime_spec.rb
deleted file mode 100644
index 77fae16d..00000000
--- a/spec/unit/plugins/aix/uptime_spec.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-#
-# Author:: Prabhu Das (<prabhu.das@clogeny.com>)
-# Copyright:: Copyright (c) 2013 Opscode, Inc.
-# License:: Apache License, Version 2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
-
-describe Ohai::System, "Aix plugin uptime" do
-
- before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("aix/uptime.rb", PLUGIN_PATH))
- @plugin[:os] = "aix"
- @plugin.stub(:popen4).with("who -b").and_yield(nil, StringIO.new, StringIO.new(" . system boot Jul 9 17:51"), nil)
- Time.stub_chain(:now, :to_i).and_return(1374258600)
- DateTime.stub_chain(:parse, :strftime, :to_i).and_return(1373392260)
- end
-
- it "should set uptime_seconds to uptime" do
- @plugin.run
- @plugin[:uptime_seconds].should == 866340
- end
-
- it "should set uptime to a human readable date" do
- @plugin.run
- @plugin[:uptime].should == "10 days 00 hours 39 minutes 00 seconds"
- end
-end
diff --git a/spec/unit/plugins/azure_spec.rb b/spec/unit/plugins/azure_spec.rb
index 30bc8cba..31879546 100644
--- a/spec/unit/plugins/azure_spec.rb
+++ b/spec/unit/plugins/azure_spec.rb
@@ -23,50 +23,50 @@ require 'open-uri'
describe Ohai::System, "plugin azure" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("azure.rb", PLUGIN_PATH))
+ @ohai.stub!(:require_plugin).and_return(true)
end
describe "with azure cloud file" do
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/azure.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/azure.json').and_return('{"public_ip":"137.135.46.202","vm_name":"test-vm","public_fqdn":"service.cloudapp.net","public_ssh_port":"22", "public_winrm_port":"5985"}')
- File.stub(:exist?).with('C:\chef\ohai\hints/azure.json').and_return(true)
- File.stub(:read).with('C:\chef\ohai\hints/azure.json').and_return('{"public_ip":"137.135.46.202","vm_name":"test-vm","public_fqdn":"service.cloudapp.net","public_ssh_port":"22", "public_winrm_port":"5985"}')
- @plugin.run
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/azure.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/azure.json').and_return('{"public_ip":"137.135.46.202","vm_name":"test-vm","public_fqdn":"service.cloudapp.net","public_ssh_port":"22", "public_winrm_port":"5985"}')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/azure.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/azure.json').and_return('{"public_ip":"137.135.46.202","vm_name":"test-vm","public_fqdn":"service.cloudapp.net","public_ssh_port":"22", "public_winrm_port":"5985"}')
+ @ohai._require_plugin("azure")
end
it 'should set the azure cloud attributes' do
- @plugin[:azure].should_not be_nil
- @plugin[:azure]['public_ip'].should == "137.135.46.202"
- @plugin[:azure]['vm_name'].should == "test-vm"
- @plugin[:azure]['public_fqdn'].should == "service.cloudapp.net"
- @plugin[:azure]['public_ssh_port'].should == "22"
- @plugin[:azure]['public_winrm_port'].should == "5985"
+ @ohai[:azure].should_not be_nil
+ @ohai[:azure]['public_ip'].should == "137.135.46.202"
+ @ohai[:azure]['vm_name'].should == "test-vm"
+ @ohai[:azure]['public_fqdn'].should == "service.cloudapp.net"
+ @ohai[:azure]['public_ssh_port'].should == "22"
+ @ohai[:azure]['public_winrm_port'].should == "5985"
end
end
describe "without azure cloud file" do
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/azure.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/azure.json').and_return(false)
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/azure.json').and_return(false)
+ File.stub!(:exist?).with('C:\chef\ohai\hints/azure.json').and_return(false)
end
it 'should not behave like azure' do
- @plugin[:azure].should be_nil
+ @ohai[:azure].should be_nil
end
end
describe "with rackspace cloud file" do
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
- File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
- File.stub(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
end
it 'should not behave like azure' do
- @plugin[:azure].should be_nil
+ @ohai[:azure].should be_nil
end
end
diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb
index a9d7dba0..7083ce44 100644
--- a/spec/unit/plugins/c_spec.rb
+++ b/spec/unit/plugins/c_spec.rb
@@ -104,208 +104,204 @@ describe Ohai::System, "plugin c" do
before(:each) do
@ohai = Ohai::System.new
- @path = File.join(PLUGIN_PATH, "c.rb")
- @plugin = Ohai::DSL::Plugin.new(@ohai, @path)
-
-
- @plugin[:languages] = Mash.new
+ @ohai[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
#gcc
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC])
#glibc
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""])
#ms cl
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL])
#ms vs
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""])
#ibm xlc
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""])
#sun pro
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN])
#hpux cc
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([0, C_HPUX, ""])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([0, C_HPUX, ""])
end
#gcc
it "should get the gcc version from running gcc -v" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC])
+ @ohai._require_plugin("c")
end
it "should set languages[:c][:gcc][:version]" do
- @plugin.run
- @plugin.languages[:c][:gcc][:version].should eql("3.4.6")
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:gcc][:version].should eql("3.4.6")
end
it "should set languages[:c][:gcc][:description]" do
- @plugin.run
- @plugin.languages[:c][:gcc][:description].should eql(C_GCC.split($/).last)
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:gcc][:description].should eql(C_GCC.split($/).last)
end
it "should not set the languages[:c][:gcc] tree up if gcc command fails" do
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([1, "", ""])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:gcc) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([1, "", ""])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:gcc) if @ohai[:languages][:c]
end
#glibc
it "should get the glibc x.x.x version from running /lib/libc.so.6" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""])
+ @ohai._require_plugin("c")
end
it "should set languages[:c][:glibc][:version]" do
- @plugin.run
- @plugin.languages[:c][:glibc][:version].should eql("2.3.4")
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:glibc][:version].should eql("2.3.4")
end
it "should set languages[:c][:glibc][:description]" do
- @plugin.run
- @plugin.languages[:c][:glibc][:description].should eql(C_GLIBC_2_3_4.split($/).first)
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:glibc][:description].should eql(C_GLIBC_2_3_4.split($/).first)
end
it "should not set the languages[:c][:glibc] tree up if glibc command fails" do
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([1, "", ""])
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"/lib64/libc.so.6"}).and_return([1, "", ""])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:glibc) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([1, "", ""])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:glibc) if @ohai[:languages][:c]
end
it "should get the glibc x.x version from running /lib/libc.so.6" do
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_5, ""])
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_5, ""])
- @plugin.run
- @plugin.languages[:c][:glibc][:version].should eql("2.5")
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_5, ""])
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_5, ""])
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:glibc][:version].should eql("2.5")
end
#ms cl
it "should get the cl version from running cl /?" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL])
+ @ohai._require_plugin("c")
end
it "should set languages[:c][:cl][:version]" do
- @plugin.run
- @plugin.languages[:c][:cl][:version].should eql("14.00.50727.762")
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:cl][:version].should eql("14.00.50727.762")
end
it "should set languages[:c][:cl][:description]" do
- @plugin.run
- @plugin.languages[:c][:cl][:description].should eql(C_CL.split($/).first)
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:cl][:description].should eql(C_CL.split($/).first)
end
it "should not set the languages[:c][:cl] tree up if cl command fails" do
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([1, "", ""])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:cl) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([1, "", ""])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:cl) if @ohai[:languages][:c]
end
#ms vs
it "should get the vs version from running devenv.com /?" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""])
+ @ohai._require_plugin("c")
end
it "should set languages[:c][:vs][:version]" do
- @plugin.run
- @plugin.languages[:c][:vs][:version].should eql("8.0.50727.762")
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:vs][:version].should eql("8.0.50727.762")
end
it "should set languages[:c][:vs][:description]" do
- @plugin.run
- @plugin.languages[:c][:vs][:description].should eql(C_VS.split($/)[1])
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:vs][:description].should eql(C_VS.split($/)[1])
end
it "should not set the languages[:c][:vs] tree up if devenv command fails" do
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([1, "", ""])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:vs) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([1, "", ""])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:vs) if @ohai[:languages][:c]
end
#ibm xlc
it "should get the xlc version from running xlc -qversion" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""])
+ @ohai._require_plugin("c")
end
it "should set languages[:c][:xlc][:version]" do
- @plugin.run
- @plugin.languages[:c][:xlc][:version].should eql("9.0")
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:xlc][:version].should eql("9.0")
end
it "should set languages[:c][:xlc][:description]" do
- @plugin.run
- @plugin.languages[:c][:xlc][:description].should eql(C_XLC.split($/).first)
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:xlc][:description].should eql(C_XLC.split($/).first)
end
it "should not set the languages[:c][:xlc] tree up if xlc command fails" do
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([1, "", ""])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:xlc) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([1, "", ""])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:xlc) if @ohai[:languages][:c]
end
it "should set the languages[:c][:xlc] tree up if xlc exit status is 249" do
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([63744, "", ""])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:xlc) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([63744, "", ""])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:xlc) if @ohai[:languages][:c]
end
#sun pro
it "should get the cc version from running cc -V -flags" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN])
+ @ohai._require_plugin("c")
end
it "should set languages[:c][:sunpro][:version]" do
- @plugin.run
- @plugin.languages[:c][:sunpro][:version].should eql("5.8")
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:sunpro][:version].should eql("5.8")
end
it "should set languages[:c][:sunpro][:description]" do
- @plugin.run
- @plugin.languages[:c][:sunpro][:description].should eql(C_SUN.chomp)
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:sunpro][:description].should eql(C_SUN.chomp)
end
it "should not set the languages[:c][:sunpro] tree up if cc command fails" do
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([1, "", ""])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:sunpro) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([1, "", ""])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:sunpro) if @ohai[:languages][:c]
end
it "should not set the languages[:c][:sunpro] tree if the corresponding cc command fails on linux" do
fedora_error_message = "cc: error trying to exec 'i686-redhat-linux-gcc--flags': execvp: No such file or directory"
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", fedora_error_message])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:sunpro) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", fedora_error_message])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:sunpro) if @ohai[:languages][:c]
end
it "should not set the languages[:c][:sunpro] tree if the corresponding cc command fails on hpux" do
hpux_error_message = "cc: warning 901: unknown option: `-flags': use +help for online documentation.\ncc: HP C/aC++ B3910B A.06.25 [Nov 30 2009]"
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", hpux_error_message])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:sunpro) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", hpux_error_message])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:sunpro) if @ohai[:languages][:c]
end
#hpux cc
it "should get the cc version from running what cc" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([0, C_HPUX, ""])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([0, C_HPUX, ""])
+ @ohai._require_plugin("c")
end
it "should set languages[:c][:hpcc][:version]" do
- @plugin.run
- @plugin.languages[:c][:hpcc][:version].should eql("B.11.11.16")
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:hpcc][:version].should eql("B.11.11.16")
end
it "should set languages[:c][:hpcc][:description]" do
- @plugin.run
- @plugin.languages[:c][:hpcc][:description].should eql(C_HPUX.split($/)[3].strip)
+ @ohai._require_plugin("c")
+ @ohai.languages[:c][:hpcc][:description].should eql(C_HPUX.split($/)[3].strip)
end
it "should not set the languages[:c][:hpcc] tree up if cc command fails" do
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([1, "", ""])
- @plugin.run
- @plugin[:languages][:c].should_not have_key(:hpcc) if @plugin[:languages][:c]
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([1, "", ""])
+ @ohai._require_plugin("c")
+ @ohai[:languages][:c].should_not have_key(:hpcc) if @ohai[:languages][:c]
end
end
diff --git a/spec/unit/plugins/chef_spec.rb b/spec/unit/plugins/chef_spec.rb
index 1f402e6f..5d76c095 100644
--- a/spec/unit/plugins/chef_spec.rb
+++ b/spec/unit/plugins/chef_spec.rb
@@ -26,17 +26,17 @@ begin
describe Ohai::System, "plugin chef" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "chef.rb"))
+ @ohai.stub!(:require_plugin).and_return(true)
end
it "should set [:chef_packages][:chef][:version] to the current chef version", :if => defined?(Chef) do
- @plugin.run
- @plugin[:chef_packages][:chef][:version].should == Chef::VERSION
+ @ohai._require_plugin("chef")
+ @ohai[:chef_packages][:chef][:version].should == Chef::VERSION
end
pending "would set [:chef_packages][:chef][:version] if chef was available", :unless => defined?(Chef)
- end
+ end
rescue LoadError
# the chef module is not available, ignoring.
diff --git a/spec/unit/plugins/cloud_spec.rb b/spec/unit/plugins/cloud_spec.rb
index 07e14b0e..00e0c179 100644
--- a/spec/unit/plugins/cloud_spec.rb
+++ b/spec/unit/plugins/cloud_spec.rb
@@ -20,188 +20,187 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin cloud" do
before do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("cloud.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin)
+ @ohai.stub!(:require_plugin).and_return(true)
end
describe "with no cloud mashes" do
it "doesn't populate the cloud data" do
- @plugin[:ec2] = nil
- @plugin[:rackspace] = nil
- @plugin[:eucalyptus] = nil
- @plugin[:linode] = nil
- @plugin[:azure] = nil
- @plugin.run
- @plugin[:cloud].should be_nil
+ @ohai[:ec2] = nil
+ @ohai[:rackspace] = nil
+ @ohai[:eucalyptus] = nil
+ @ohai[:linode] = nil
+ @ohai[:azure] = nil
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud].should be_nil
end
end
describe "with EC2 mash" do
before do
- @plugin[:ec2] = Mash.new()
+ @ohai[:ec2] = Mash.new()
end
it "populates cloud public ip" do
- @plugin[:ec2]['public_ipv4'] = "174.129.150.8"
- @plugin.run
- @plugin[:cloud][:public_ips][0].should == @plugin[:ec2]['public_ipv4']
+ @ohai[:ec2]['public_ipv4'] = "174.129.150.8"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ips][0].should == @ohai[:ec2]['public_ipv4']
end
it "populates cloud private ip" do
- @plugin[:ec2]['local_ipv4'] = "10.252.42.149"
- @plugin.run
- @plugin[:cloud][:private_ips][0].should == @plugin[:ec2]['local_ipv4']
+ @ohai[:ec2]['local_ipv4'] = "10.252.42.149"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:private_ips][0].should == @ohai[:ec2]['local_ipv4']
end
it "populates cloud provider" do
- @plugin.run
- @plugin[:cloud][:provider].should == "ec2"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:provider].should == "ec2"
end
end
describe "with rackspace" do
before do
- @plugin[:rackspace] = Mash.new()
+ @ohai[:rackspace] = Mash.new()
end
it "populates cloud public ip" do
- @plugin[:rackspace][:public_ipv4] = "174.129.150.8"
- @plugin.run
- @plugin[:cloud][:public_ipv4].should == @plugin[:rackspace][:public_ipv4]
+ @ohai[:rackspace][:public_ipv4] = "174.129.150.8"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ipv4].should == @ohai[:rackspace][:public_ipv4]
end
it "populates cloud public ipv6" do
- @plugin[:rackspace][:public_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75"
- @plugin.run
- @plugin[:cloud][:public_ipv6].should == @plugin[:rackspace][:public_ipv6]
+ @ohai[:rackspace][:public_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ipv6].should == @ohai[:rackspace][:public_ipv6]
end
it "populates cloud private ip" do
- @plugin[:rackspace][:local_ipv4] = "10.252.42.149"
- @plugin.run
- @plugin[:cloud][:local_ipv4].should == @plugin[:rackspace][:local_ipv4]
+ @ohai[:rackspace][:local_ipv4] = "10.252.42.149"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:local_ipv4].should == @ohai[:rackspace][:local_ipv4]
end
it "populates cloud private ipv6" do
- @plugin[:rackspace][:local_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75"
- @plugin.run
- @plugin[:cloud][:local_ipv6].should == @plugin[:rackspace][:local_ipv6]
+ @ohai[:rackspace][:local_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:local_ipv6].should == @ohai[:rackspace][:local_ipv6]
end
it "populates first cloud public ip" do
- @plugin[:rackspace][:public_ipv4] = "174.129.150.8"
- @plugin.run
- @plugin[:cloud][:public_ips].first.should == @plugin[:rackspace][:public_ipv4]
+ @ohai[:rackspace][:public_ipv4] = "174.129.150.8"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ips].first.should == @ohai[:rackspace][:public_ipv4]
end
it "populates first cloud public ip" do
- @plugin[:rackspace][:local_ipv4] = "174.129.150.8"
- @plugin.run
- @plugin[:cloud][:private_ips].first.should == @plugin[:rackspace][:local_ipv4]
+ @ohai[:rackspace][:local_ipv4] = "174.129.150.8"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:private_ips].first.should == @ohai[:rackspace][:local_ipv4]
end
it "populates cloud provider" do
- @plugin.run
- @plugin[:cloud][:provider].should == "rackspace"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:provider].should == "rackspace"
end
end
describe "with linode mash" do
before do
- @plugin[:linode] = Mash.new()
+ @ohai[:linode] = Mash.new()
end
it "populates cloud public ip" do
- @plugin[:linode]['public_ip'] = "174.129.150.8"
- @plugin.run
- @plugin[:cloud][:public_ips][0].should == @plugin[:linode][:public_ip]
+ @ohai[:linode]['public_ip'] = "174.129.150.8"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ips][0].should == @ohai[:linode][:public_ip]
end
it "populates cloud private ip" do
- @plugin[:linode]['private_ip'] = "10.252.42.149"
- @plugin.run
- @plugin[:cloud][:private_ips][0].should == @plugin[:linode][:private_ip]
+ @ohai[:linode]['private_ip'] = "10.252.42.149"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:private_ips][0].should == @ohai[:linode][:private_ip]
end
it "populates first cloud public ip" do
- @plugin[:linode]['public_ip'] = "174.129.150.8"
- @plugin.run
- @plugin[:cloud][:public_ips].first.should == @plugin[:linode][:public_ip]
+ @ohai[:linode]['public_ip'] = "174.129.150.8"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ips].first.should == @ohai[:linode][:public_ip]
end
it "populates cloud provider" do
- @plugin.run
- @plugin[:cloud][:provider].should == "linode"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:provider].should == "linode"
end
end
describe "with eucalyptus mash" do
before do
- @plugin[:eucalyptus] = Mash.new()
+ @ohai[:eucalyptus] = Mash.new()
end
it "populates cloud public ip" do
- @plugin[:eucalyptus]['public_ipv4'] = "174.129.150.8"
- @plugin.run
- @plugin[:cloud][:public_ips][0].should == @plugin[:eucalyptus]['public_ipv4']
+ @ohai[:eucalyptus]['public_ipv4'] = "174.129.150.8"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ips][0].should == @ohai[:eucalyptus]['public_ipv4']
end
it "populates cloud private ip" do
- @plugin[:eucalyptus]['local_ipv4'] = "10.252.42.149"
- @plugin.run
- @plugin[:cloud][:private_ips][0].should == @plugin[:eucalyptus]['local_ipv4']
+ @ohai[:eucalyptus]['local_ipv4'] = "10.252.42.149"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:private_ips][0].should == @ohai[:eucalyptus]['local_ipv4']
end
it "populates cloud provider" do
- @plugin.run
- @plugin[:cloud][:provider].should == "eucalyptus"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:provider].should == "eucalyptus"
end
end
describe "with Azure mash" do
before do
- @plugin[:azure] = Mash.new()
+ @ohai[:azure] = Mash.new()
end
it "populates cloud public ip" do
- @plugin[:azure]['public_ip'] = "174.129.150.8"
- @plugin.run
- @plugin[:cloud][:public_ips][0].should == @plugin[:azure]['public_ip']
+ @ohai[:azure]['public_ip'] = "174.129.150.8"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ips][0].should == @ohai[:azure]['public_ip']
end
it "populates cloud vm_name" do
- @plugin[:azure]['vm_name'] = "linux-vm"
- @plugin.run
- @plugin[:cloud][:vm_name].should == @plugin[:azure]['vm_name']
+ @ohai[:azure]['vm_name'] = "linux-vm"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:vm_name].should == @ohai[:azure]['vm_name']
end
it "populates cloud public_fqdn" do
- @plugin[:azure]['public_fqdn'] = "linux-vm-svc.cloudapp.net"
- @plugin.run
- @plugin[:cloud][:public_fqdn].should == @plugin[:azure]['public_fqdn']
+ @ohai[:azure]['public_fqdn'] = "linux-vm-svc.cloudapp.net"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_fqdn].should == @ohai[:azure]['public_fqdn']
end
it "populates cloud public_ssh_port" do
- @plugin[:azure]['public_ssh_port'] = "22"
- @plugin.run
- @plugin[:cloud][:public_ssh_port].should == @plugin[:azure]['public_ssh_port']
+ @ohai[:azure]['public_ssh_port'] = "22"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ssh_port].should == @ohai[:azure]['public_ssh_port']
end
it "should not populate cloud public_ssh_port when winrm is used" do
- @plugin[:azure]['public_winrm_port'] = "5985"
- @plugin.run
- @plugin[:cloud][:public_ssh_port].should be_nil
+ @ohai[:azure]['public_winrm_port'] = "5985"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_ssh_port].should be_nil
end
it "populates cloud public_winrm_port" do
- @plugin[:azure]['public_winrm_port'] = "5985"
- @plugin.run
- @plugin[:cloud][:public_winrm_port].should == @plugin[:azure]['public_winrm_port']
+ @ohai[:azure]['public_winrm_port'] = "5985"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:public_winrm_port].should == @ohai[:azure]['public_winrm_port']
end
it "populates cloud provider" do
- @plugin.run
- @plugin[:cloud][:provider].should == "azure"
+ @ohai._require_plugin("cloud")
+ @ohai[:cloud][:provider].should == "azure"
end
end
diff --git a/spec/unit/plugins/darwin/cpu_spec.rb b/spec/unit/plugins/darwin/cpu_spec.rb
index dd94b144..1989d35d 100644
--- a/spec/unit/plugins/darwin/cpu_spec.rb
+++ b/spec/unit/plugins/darwin/cpu_spec.rb
@@ -22,18 +22,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Darwin cpu plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("darwin/cpu.rb", PLUGIN_PATH))
- @plugin.stub(:from).with("sysctl -n hw.physicalcpu").and_return("1")
- @plugin.stub(:from).with("sysctl -n hw.logicalcpu").and_return("2")
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "darwin"
+ @ohai.stub(:from).with("sysctl -n hw.physicalcpu").and_return("1")
+ @ohai.stub(:from).with("sysctl -n hw.logicalcpu").and_return("2")
end
it "should set cpu[:total] to 2" do
- @plugin.run
- @plugin[:cpu][:total].should == 2
+ @ohai._require_plugin("darwin::cpu")
+ @ohai[:cpu][:total].should == 2
end
it "should set cpu[:real] to 1" do
- @plugin.run
- @plugin[:cpu][:real].should == 1
+ @ohai._require_plugin("darwin::cpu")
+ @ohai[:cpu][:real].should == 1
end
end
diff --git a/spec/unit/plugins/darwin/hostname_spec.rb b/spec/unit/plugins/darwin/hostname_spec.rb
index f3d9e4f9..3136af10 100644
--- a/spec/unit/plugins/darwin/hostname_spec.rb
+++ b/spec/unit/plugins/darwin/hostname_spec.rb
@@ -22,14 +22,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Darwin hostname plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("darwin/hostname.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "darwin"
- @plugin.stub(:from).with("hostname -s").and_return("katie")
- @plugin.stub(:from).with("hostname").and_return("katie.bethell")
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "darwin"
+ @ohai.stub!(:from).with("hostname -s").and_return("katie")
+ @ohai.stub!(:from).with("hostname").and_return("katie.bethell")
end
it_should_check_from("darwin::hostname", "hostname", "hostname -s", "katie")
it_should_check_from("darwin::hostname", "fqdn", "hostname", "katie.bethell")
-end
+end \ No newline at end of file
diff --git a/spec/unit/plugins/darwin/kernel_spec.rb b/spec/unit/plugins/darwin/kernel_spec.rb
index 694c9488..9954f968 100644
--- a/spec/unit/plugins/darwin/kernel_spec.rb
+++ b/spec/unit/plugins/darwin/kernel_spec.rb
@@ -21,28 +21,26 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Darwin kernel plugin" do
before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("darwin/kernel.rb", PLUGIN_PATH))
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:name] = "darwin"
- @plugin.should_receive(:popen4).with("kextstat -k -l").and_yield(1, StringIO.new, StringIO.new, StringIO.new)
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:kernel] = Mash.new
+ @ohai[:kernel][:name] = "darwin"
end
-
+
it "should not set kernel_machine to x86_64" do
- @plugin.stub(:from).with("sysctl -n hw.optional.x86_64").and_return("0")
- @plugin.run
- @plugin[:kernel][:machine].should_not == 'x86_64'
+ @ohai.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("0")
+ @ohai._require_plugin("darwin::kernel")
+ @ohai[:kernel][:machine].should_not == 'x86_64'
end
-
+
it "should set kernel_machine to x86_64" do
- @plugin.stub(:from).with("sysctl -n hw.optional.x86_64").and_return("1")
- @plugin.run
- @plugin[:kernel][:machine].should == 'x86_64'
+ @ohai.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("1")
+ @ohai._require_plugin("darwin::kernel")
+ @ohai[:kernel][:machine].should == 'x86_64'
end
-
+
it "should set the kernel_os to the kernel_name value" do
- @plugin.stub(:from).with("sysctl -n hw.optional.x86_64").and_return("1")
- @plugin.run
- @plugin[:kernel][:os].should == @plugin[:kernel][:name]
+ @ohai._require_plugin("darwin::kernel")
+ @ohai[:kernel][:os].should == @ohai[:kernel][:name]
end
-end
+end \ No newline at end of file
diff --git a/spec/unit/plugins/darwin/network_spec.rb b/spec/unit/plugins/darwin/network_spec.rb
index 26371ba2..52ab355f 100644
--- a/spec/unit/plugins/darwin/network_spec.rb
+++ b/spec/unit/plugins/darwin/network_spec.rb
@@ -413,7 +413,7 @@ net.smb.fs.tcprcvbuf: 261120
DARWIN_SYSCTL
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("darwin/network.rb", PLUGIN_PATH))
+ @ohai.stub!(:require_plugin).and_return(true)
@stdin_ifconfig = StringIO.new
@stdin_arp = StringIO.new
@@ -425,429 +425,429 @@ net.smb.fs.tcprcvbuf: 261120
@netstat_lines = darwin_netstat.split("\n")
@sysctl_lines = darwin_sysctl.split("\n")
- @plugin.stub(:from).with("route -n get default").and_return(darwin_route)
- @plugin.stub(:popen4).with("netstat -i -d -l -b -n")
+ @ohai.stub(:from).with("route -n get default").and_return(darwin_route)
+ @ohai.stub(:popen4).with("netstat -i -d -l -b -n")
- Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(6).times
- @plugin.require_plugin("network")
+ Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(3).times
+ @ohai._require_plugin("network")
end
describe "gathering IP layer address info" do
before do
- @plugin.stub(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
- @plugin.stub(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
- @plugin.stub(:popen4).with("netstat -i -d -l -b -n").and_yield(nil, @stdin_netstat, @netstat_lines, nil)
- @plugin.stub(:popen4).with("sysctl net").and_yield(nil, @stdin_sysctl, @sysctl_lines, nil)
- @plugin.run
+ @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
+ @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
+ @ohai.stub(:popen4).with("netstat -i -d -l -b -n").and_yield(nil, @stdin_netstat, @netstat_lines, nil)
+ @ohai.stub(:popen4).with("sysctl net").and_yield(nil, @stdin_sysctl, @sysctl_lines, nil)
+ @ohai._require_plugin("darwin::network")
end
it "completes the run" do
- @plugin['network'].should_not be_nil
+ @ohai['network'].should_not be_nil
end
it "detects the interfaces" do
- @plugin['network']['interfaces'].keys.sort.should == ["en0", "en1", "fw0", "gif0", "lo0", "p2p0", "stf0", "utun0"]
+ @ohai['network']['interfaces'].keys.sort.should == ["en0", "en1", "fw0", "gif0", "lo0", "p2p0", "stf0", "utun0"]
end
it "detects the ipv4 addresses of the ethernet interface" do
- @plugin['network']['interfaces']['en1']['addresses'].keys.should include('10.20.10.144')
- @plugin['network']['interfaces']['en1']['addresses']['10.20.10.144']['netmask'].should == '255.255.255.0'
- @plugin['network']['interfaces']['en1']['addresses']['10.20.10.144']['broadcast'].should == '10.20.10.255'
- @plugin['network']['interfaces']['en1']['addresses']['10.20.10.144']['family'].should == 'inet'
+ @ohai['network']['interfaces']['en1']['addresses'].keys.should include('10.20.10.144')
+ @ohai['network']['interfaces']['en1']['addresses']['10.20.10.144']['netmask'].should == '255.255.255.0'
+ @ohai['network']['interfaces']['en1']['addresses']['10.20.10.144']['broadcast'].should == '10.20.10.255'
+ @ohai['network']['interfaces']['en1']['addresses']['10.20.10.144']['family'].should == 'inet'
end
it "detects the ipv6 addresses of the ethernet interface" do
- @plugin['network']['interfaces']['en1']['addresses'].keys.should include('fe80::ba8d:12ff:fe3a:32de')
- @plugin['network']['interfaces']['en1']['addresses']['fe80::ba8d:12ff:fe3a:32de']['scope'].should == 'Link'
- @plugin['network']['interfaces']['en1']['addresses']['fe80::ba8d:12ff:fe3a:32de']['prefixlen'].should == '64'
- @plugin['network']['interfaces']['en1']['addresses']['fe80::ba8d:12ff:fe3a:32de']['family'].should == 'inet6'
-
- @plugin['network']['interfaces']['en1']['addresses'].keys.should include('2001:44b8:4186:1100:ba8d:12ff:fe3a:32de')
- @plugin['network']['interfaces']['en1']['addresses']['2001:44b8:4186:1100:ba8d:12ff:fe3a:32de']['scope'].should == 'Global'
- @plugin['network']['interfaces']['en1']['addresses']['2001:44b8:4186:1100:ba8d:12ff:fe3a:32de']['prefixlen'].should == '64'
- @plugin['network']['interfaces']['en1']['addresses']['2001:44b8:4186:1100:ba8d:12ff:fe3a:32de']['family'].should == 'inet6'
+ @ohai['network']['interfaces']['en1']['addresses'].keys.should include('fe80::ba8d:12ff:fe3a:32de')
+ @ohai['network']['interfaces']['en1']['addresses']['fe80::ba8d:12ff:fe3a:32de']['scope'].should == 'Link'
+ @ohai['network']['interfaces']['en1']['addresses']['fe80::ba8d:12ff:fe3a:32de']['prefixlen'].should == '64'
+ @ohai['network']['interfaces']['en1']['addresses']['fe80::ba8d:12ff:fe3a:32de']['family'].should == 'inet6'
+
+ @ohai['network']['interfaces']['en1']['addresses'].keys.should include('2001:44b8:4186:1100:ba8d:12ff:fe3a:32de')
+ @ohai['network']['interfaces']['en1']['addresses']['2001:44b8:4186:1100:ba8d:12ff:fe3a:32de']['scope'].should == 'Global'
+ @ohai['network']['interfaces']['en1']['addresses']['2001:44b8:4186:1100:ba8d:12ff:fe3a:32de']['prefixlen'].should == '64'
+ @ohai['network']['interfaces']['en1']['addresses']['2001:44b8:4186:1100:ba8d:12ff:fe3a:32de']['family'].should == 'inet6'
end
it "detects the mac addresses of the ethernet interface" do
- @plugin['network']['interfaces']['en1']['addresses'].keys.should include('b8:8d:12:3a:32:de')
- @plugin['network']['interfaces']['en1']['addresses']['b8:8d:12:3a:32:de']['family'].should == 'lladdr'
+ @ohai['network']['interfaces']['en1']['addresses'].keys.should include('b8:8d:12:3a:32:de')
+ @ohai['network']['interfaces']['en1']['addresses']['b8:8d:12:3a:32:de']['family'].should == 'lladdr'
end
it "detects the encapsulation type of the ethernet interface" do
- @plugin['network']['interfaces']['en1']['encapsulation'].should == 'Ethernet'
+ @ohai['network']['interfaces']['en1']['encapsulation'].should == 'Ethernet'
end
it "detects the flags of the ethernet interface" do
- @plugin['network']['interfaces']['en1']['flags'].sort.should == ["BROADCAST", "MULTICAST", "RUNNING", "SIMPLEX", "SMART", "UP"]
+ @ohai['network']['interfaces']['en1']['flags'].sort.should == ["BROADCAST", "MULTICAST", "RUNNING", "SIMPLEX", "SMART", "UP"]
end
it "detects the mtu of the ethernet interface" do
- @plugin['network']['interfaces']['en1']['mtu'].should == "1500"
+ @ohai['network']['interfaces']['en1']['mtu'].should == "1500"
end
it "detects the ipv4 addresses of the loopback interface" do
- @plugin['network']['interfaces']['lo0']['addresses'].keys.should include('127.0.0.1')
- @plugin['network']['interfaces']['lo0']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0'
- @plugin['network']['interfaces']['lo0']['addresses']['127.0.0.1']['family'].should == 'inet'
+ @ohai['network']['interfaces']['lo0']['addresses'].keys.should include('127.0.0.1')
+ @ohai['network']['interfaces']['lo0']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0'
+ @ohai['network']['interfaces']['lo0']['addresses']['127.0.0.1']['family'].should == 'inet'
end
it "detects the ipv6 addresses of the loopback interface" do
- @plugin['network']['interfaces']['lo0']['addresses'].keys.should include('::1')
- @plugin['network']['interfaces']['lo0']['addresses']['::1']['scope'].should == 'Node'
- @plugin['network']['interfaces']['lo0']['addresses']['::1']['prefixlen'].should == '128'
- @plugin['network']['interfaces']['lo0']['addresses']['::1']['family'].should == 'inet6'
+ @ohai['network']['interfaces']['lo0']['addresses'].keys.should include('::1')
+ @ohai['network']['interfaces']['lo0']['addresses']['::1']['scope'].should == 'Node'
+ @ohai['network']['interfaces']['lo0']['addresses']['::1']['prefixlen'].should == '128'
+ @ohai['network']['interfaces']['lo0']['addresses']['::1']['family'].should == 'inet6'
end
it "detects the encapsulation type of the loopback interface" do
- @plugin['network']['interfaces']['lo0']['encapsulation'].should == 'Loopback'
+ @ohai['network']['interfaces']['lo0']['encapsulation'].should == 'Loopback'
end
it "detects the flags of the ethernet interface" do
- @plugin['network']['interfaces']['lo0']['flags'].sort.should == ["LOOPBACK", "MULTICAST", "RUNNING", "UP"]
+ @ohai['network']['interfaces']['lo0']['flags'].sort.should == ["LOOPBACK", "MULTICAST", "RUNNING", "UP"]
end
it "detects the mtu of the loopback interface" do
- @plugin['network']['interfaces']['lo0']['mtu'].should == "16384"
+ @ohai['network']['interfaces']['lo0']['mtu'].should == "16384"
end
it "detects the arp entries" do
- @plugin['network']['interfaces']['en1']['arp']['10.20.10.1'].should == '0:4:ed:de:41:bf'
+ @ohai['network']['interfaces']['en1']['arp']['10.20.10.1'].should == '0:4:ed:de:41:bf'
end
it "detects the ethernet counters" do
- @plugin['counters']['network']['interfaces']['en1']['tx']['bytes'].should == "18228234970"
- @plugin['counters']['network']['interfaces']['en1']['tx']['packets'].should == "14314573"
- @plugin['counters']['network']['interfaces']['en1']['tx']['collisions'].should == "0"
- @plugin['counters']['network']['interfaces']['en1']['tx']['errors'].should == "0"
- @plugin['counters']['network']['interfaces']['en1']['tx']['carrier'].should == 0
- @plugin['counters']['network']['interfaces']['en1']['tx']['drop'].should == 0
-
- @plugin['counters']['network']['interfaces']['en1']['rx']['bytes'].should == "2530556736"
- @plugin['counters']['network']['interfaces']['en1']['rx']['packets'].should == "5921903"
- @plugin['counters']['network']['interfaces']['en1']['rx']['errors'].should == "0"
- @plugin['counters']['network']['interfaces']['en1']['rx']['overrun'].should == 0
- @plugin['counters']['network']['interfaces']['en1']['rx']['drop'].should == 0
+ @ohai['counters']['network']['interfaces']['en1']['tx']['bytes'].should == "18228234970"
+ @ohai['counters']['network']['interfaces']['en1']['tx']['packets'].should == "14314573"
+ @ohai['counters']['network']['interfaces']['en1']['tx']['collisions'].should == "0"
+ @ohai['counters']['network']['interfaces']['en1']['tx']['errors'].should == "0"
+ @ohai['counters']['network']['interfaces']['en1']['tx']['carrier'].should == 0
+ @ohai['counters']['network']['interfaces']['en1']['tx']['drop'].should == 0
+
+ @ohai['counters']['network']['interfaces']['en1']['rx']['bytes'].should == "2530556736"
+ @ohai['counters']['network']['interfaces']['en1']['rx']['packets'].should == "5921903"
+ @ohai['counters']['network']['interfaces']['en1']['rx']['errors'].should == "0"
+ @ohai['counters']['network']['interfaces']['en1']['rx']['overrun'].should == 0
+ @ohai['counters']['network']['interfaces']['en1']['rx']['drop'].should == 0
end
it "detects the loopback counters" do
- @plugin['counters']['network']['interfaces']['lo0']['tx']['bytes'].should == "25774844"
- @plugin['counters']['network']['interfaces']['lo0']['tx']['packets'].should == "174982"
- @plugin['counters']['network']['interfaces']['lo0']['tx']['collisions'].should == "0"
- @plugin['counters']['network']['interfaces']['lo0']['tx']['errors'].should == "0"
- @plugin['counters']['network']['interfaces']['lo0']['tx']['carrier'].should == 0
- @plugin['counters']['network']['interfaces']['lo0']['tx']['drop'].should == 0
-
- @plugin['counters']['network']['interfaces']['lo0']['rx']['bytes'].should == "25774844"
- @plugin['counters']['network']['interfaces']['lo0']['rx']['packets'].should == "174982"
- @plugin['counters']['network']['interfaces']['lo0']['rx']['errors'].should == "0"
- @plugin['counters']['network']['interfaces']['lo0']['rx']['overrun'].should == 0
- @plugin['counters']['network']['interfaces']['lo0']['rx']['drop'].should == 0
+ @ohai['counters']['network']['interfaces']['lo0']['tx']['bytes'].should == "25774844"
+ @ohai['counters']['network']['interfaces']['lo0']['tx']['packets'].should == "174982"
+ @ohai['counters']['network']['interfaces']['lo0']['tx']['collisions'].should == "0"
+ @ohai['counters']['network']['interfaces']['lo0']['tx']['errors'].should == "0"
+ @ohai['counters']['network']['interfaces']['lo0']['tx']['carrier'].should == 0
+ @ohai['counters']['network']['interfaces']['lo0']['tx']['drop'].should == 0
+
+ @ohai['counters']['network']['interfaces']['lo0']['rx']['bytes'].should == "25774844"
+ @ohai['counters']['network']['interfaces']['lo0']['rx']['packets'].should == "174982"
+ @ohai['counters']['network']['interfaces']['lo0']['rx']['errors'].should == "0"
+ @ohai['counters']['network']['interfaces']['lo0']['rx']['overrun'].should == 0
+ @ohai['counters']['network']['interfaces']['lo0']['rx']['drop'].should == 0
end
it "finds the default interface by asking which iface has the default route" do
- @plugin['network'][:default_interface].should == 'en1'
+ @ohai['network'][:default_interface].should == 'en1'
end
it "finds the default interface by asking which iface has the default route" do
- @plugin['network'][:default_gateway].should == '10.20.10.1'
+ @ohai['network'][:default_gateway].should == '10.20.10.1'
end
it "should detect network settings" do
- @plugin['network']['settings']['net.local.stream.sendspace'].should == '8192'
- @plugin["network"]["settings"]['net.local.stream.recvspace'].should == '8192'
- @plugin["network"]["settings"]['net.local.stream.tracemdns'].should == '0'
- @plugin["network"]["settings"]['net.local.dgram.maxdgram'].should == '2048'
- @plugin["network"]["settings"]['net.local.dgram.recvspace'].should == '4096'
- @plugin["network"]["settings"]['net.local.inflight'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.portrange.lowfirst'].should == '1023'
- @plugin["network"]["settings"]['net.inet.ip.portrange.lowlast'].should == '600'
- @plugin["network"]["settings"]['net.inet.ip.portrange.first'].should == '49152'
- @plugin["network"]["settings"]['net.inet.ip.portrange.last'].should == '65535'
- @plugin["network"]["settings"]['net.inet.ip.portrange.hifirst'].should == '49152'
- @plugin["network"]["settings"]['net.inet.ip.portrange.hilast'].should == '65535'
- @plugin["network"]["settings"]['net.inet.ip.forwarding'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.redirect'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.ttl'].should == '64'
- @plugin["network"]["settings"]['net.inet.ip.rtexpire'].should == '12'
- @plugin["network"]["settings"]['net.inet.ip.rtminexpire'].should == '10'
- @plugin["network"]["settings"]['net.inet.ip.rtmaxcache'].should == '128'
- @plugin["network"]["settings"]['net.inet.ip.sourceroute'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.intr_queue_maxlen'].should == '50'
- @plugin["network"]["settings"]['net.inet.ip.intr_queue_drops'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.accept_sourceroute'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.keepfaith'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.gifttl'].should == '30'
- @plugin["network"]["settings"]['net.inet.ip.subnets_are_local'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.mcast.maxgrpsrc'].should == '512'
- @plugin["network"]["settings"]['net.inet.ip.mcast.maxsocksrc'].should == '128'
- @plugin["network"]["settings"]['net.inet.ip.mcast.loop'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.check_route_selfref'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.use_route_genid'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.hash_size'].should == '64'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.curr_time'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.ready_heap'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.extract_heap'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.searches'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.search_steps'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.expire'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.max_chain_len'].should == '16'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.red_lookup_depth'].should == '256'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.red_avg_pkt_size'].should == '512'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.red_max_pkt_size'].should == '1500'
- @plugin["network"]["settings"]['net.inet.ip.dummynet.debug'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.fw.enable'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.fw.autoinc_step'].should == '100'
- @plugin["network"]["settings"]['net.inet.ip.fw.one_pass'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.fw.debug'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.fw.verbose'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.fw.verbose_limit'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_buckets'].should == '256'
- @plugin["network"]["settings"]['net.inet.ip.fw.curr_dyn_buckets'].should == '256'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_count'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_max'].should == '4096'
- @plugin["network"]["settings"]['net.inet.ip.fw.static_count'].should == '2'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_ack_lifetime'].should == '300'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_syn_lifetime'].should == '20'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_fin_lifetime'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_rst_lifetime'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_udp_lifetime'].should == '10'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_short_lifetime'].should == '5'
- @plugin["network"]["settings"]['net.inet.ip.fw.dyn_keepalive'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.maxfragpackets'].should == '1536'
- @plugin["network"]["settings"]['net.inet.ip.maxfragsperpacket'].should == '128'
- @plugin["network"]["settings"]['net.inet.ip.maxfrags'].should == '3072'
- @plugin["network"]["settings"]['net.inet.ip.scopedroute'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.check_interface'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.linklocal.in.allowbadttl'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.random_id'].should == '1'
- @plugin["network"]["settings"]['net.inet.ip.maxchainsent'].should == '0'
- @plugin["network"]["settings"]['net.inet.ip.select_srcif_debug'].should == '0'
- @plugin["network"]["settings"]['net.inet.icmp.maskrepl'].should == '0'
- @plugin["network"]["settings"]['net.inet.icmp.icmplim'].should == '250'
- @plugin["network"]["settings"]['net.inet.icmp.timestamp'].should == '0'
- @plugin["network"]["settings"]['net.inet.icmp.drop_redirect'].should == '0'
- @plugin["network"]["settings"]['net.inet.icmp.log_redirect'].should == '0'
- @plugin["network"]["settings"]['net.inet.icmp.bmcastecho'].should == '1'
- @plugin["network"]["settings"]['net.inet.igmp.recvifkludge'].should == '1'
- @plugin["network"]["settings"]['net.inet.igmp.sendra'].should == '1'
- @plugin["network"]["settings"]['net.inet.igmp.sendlocal'].should == '1'
- @plugin["network"]["settings"]['net.inet.igmp.v1enable'].should == '1'
- @plugin["network"]["settings"]['net.inet.igmp.v2enable'].should == '1'
- @plugin["network"]["settings"]['net.inet.igmp.legacysupp'].should == '0'
- @plugin["network"]["settings"]['net.inet.igmp.default_version'].should == '3'
- @plugin["network"]["settings"]['net.inet.igmp.gsrdelay'].should == '10'
- @plugin["network"]["settings"]['net.inet.igmp.debug'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.rfc1323'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.rfc1644'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.mssdflt'].should == '512'
- @plugin["network"]["settings"]['net.inet.tcp.keepidle'].should == '7200000'
- @plugin["network"]["settings"]['net.inet.tcp.keepintvl'].should == '75000'
- @plugin["network"]["settings"]['net.inet.tcp.sendspace'].should == '65536'
- @plugin["network"]["settings"]['net.inet.tcp.recvspace'].should == '65536'
- @plugin["network"]["settings"]['net.inet.tcp.keepinit'].should == '75000'
- @plugin["network"]["settings"]['net.inet.tcp.v6mssdflt'].should == '1024'
- @plugin["network"]["settings"]['net.inet.tcp.log_in_vain'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.blackhole'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.delayed_ack'].should == '3'
- @plugin["network"]["settings"]['net.inet.tcp.tcp_lq_overflow'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.recvbg'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.drop_synfin'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.reass.maxsegments'].should == '3072'
- @plugin["network"]["settings"]['net.inet.tcp.reass.cursegments'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.reass.overflows'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.slowlink_wsize'].should == '8192'
- @plugin["network"]["settings"]['net.inet.tcp.maxseg_unacked'].should == '8'
- @plugin["network"]["settings"]['net.inet.tcp.rfc3465'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.rfc3465_lim2'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.rtt_samples_per_slot'].should == '20'
- @plugin["network"]["settings"]['net.inet.tcp.recv_allowed_iaj'].should == '5'
- @plugin["network"]["settings"]['net.inet.tcp.acc_iaj_high_thresh'].should == '100'
- @plugin["network"]["settings"]['net.inet.tcp.rexmt_thresh'].should == '2'
- @plugin["network"]["settings"]['net.inet.tcp.path_mtu_discovery'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.slowstart_flightsize'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.local_slowstart_flightsize'].should == '8'
- @plugin["network"]["settings"]['net.inet.tcp.tso'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.ecn_initiate_out'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.ecn_negotiate_in'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.packetchain'].should == '50'
- @plugin["network"]["settings"]['net.inet.tcp.socket_unlocked_on_output'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.rfc3390'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.min_iaj_win'].should == '4'
- @plugin["network"]["settings"]['net.inet.tcp.acc_iaj_react_limit'].should == '200'
- @plugin["network"]["settings"]['net.inet.tcp.sack'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.sack_maxholes'].should == '128'
- @plugin["network"]["settings"]['net.inet.tcp.sack_globalmaxholes'].should == '65536'
- @plugin["network"]["settings"]['net.inet.tcp.sack_globalholes'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.minmss'].should == '216'
- @plugin["network"]["settings"]['net.inet.tcp.minmssoverload'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.do_tcpdrain'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.pcbcount'].should == '86'
- @plugin["network"]["settings"]['net.inet.tcp.icmp_may_rst'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.strict_rfc1948'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.isn_reseed_interval'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.background_io_enabled'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.rtt_min'].should == '100'
- @plugin["network"]["settings"]['net.inet.tcp.rexmt_slop'].should == '200'
- @plugin["network"]["settings"]['net.inet.tcp.randomize_ports'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.newreno_sockets'].should == '81'
- @plugin["network"]["settings"]['net.inet.tcp.background_sockets'].should == '-1'
- @plugin["network"]["settings"]['net.inet.tcp.tcbhashsize'].should == '4096'
- @plugin["network"]["settings"]['net.inet.tcp.background_io_trigger'].should == '5'
- @plugin["network"]["settings"]['net.inet.tcp.msl'].should == '15000'
- @plugin["network"]["settings"]['net.inet.tcp.max_persist_timeout'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.always_keepalive'].should == '0'
- @plugin["network"]["settings"]['net.inet.tcp.timer_fastmode_idlemax'].should == '20'
- @plugin["network"]["settings"]['net.inet.tcp.broken_peer_syn_rxmit_thres'].should == '7'
- @plugin["network"]["settings"]['net.inet.tcp.tcp_timer_advanced'].should == '5'
- @plugin["network"]["settings"]['net.inet.tcp.tcp_resched_timerlist'].should == '12209'
- @plugin["network"]["settings"]['net.inet.tcp.pmtud_blackhole_detection'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.pmtud_blackhole_mss'].should == '1200'
- @plugin["network"]["settings"]['net.inet.tcp.timer_fastquantum'].should == '100'
- @plugin["network"]["settings"]['net.inet.tcp.timer_slowquantum'].should == '500'
- @plugin["network"]["settings"]['net.inet.tcp.win_scale_factor'].should == '3'
- @plugin["network"]["settings"]['net.inet.tcp.sockthreshold'].should == '64'
- @plugin["network"]["settings"]['net.inet.tcp.bg_target_qdelay'].should == '100'
- @plugin["network"]["settings"]['net.inet.tcp.bg_allowed_increase'].should == '2'
- @plugin["network"]["settings"]['net.inet.tcp.bg_tether_shift'].should == '1'
- @plugin["network"]["settings"]['net.inet.tcp.bg_ss_fltsz'].should == '2'
- @plugin["network"]["settings"]['net.inet.udp.checksum'].should == '1'
- @plugin["network"]["settings"]['net.inet.udp.maxdgram'].should == '9216'
- @plugin["network"]["settings"]['net.inet.udp.recvspace'].should == '42080'
- @plugin["network"]["settings"]['net.inet.udp.log_in_vain'].should == '0'
- @plugin["network"]["settings"]['net.inet.udp.blackhole'].should == '0'
- @plugin["network"]["settings"]['net.inet.udp.pcbcount'].should == '72'
- @plugin["network"]["settings"]['net.inet.udp.randomize_ports'].should == '1'
- @plugin["network"]["settings"]['net.inet.ipsec.def_policy'].should == '1'
- @plugin["network"]["settings"]['net.inet.ipsec.esp_trans_deflev'].should == '1'
- @plugin["network"]["settings"]['net.inet.ipsec.esp_net_deflev'].should == '1'
- @plugin["network"]["settings"]['net.inet.ipsec.ah_trans_deflev'].should == '1'
- @plugin["network"]["settings"]['net.inet.ipsec.ah_net_deflev'].should == '1'
- @plugin["network"]["settings"]['net.inet.ipsec.ah_cleartos'].should == '1'
- @plugin["network"]["settings"]['net.inet.ipsec.ah_offsetmask'].should == '0'
- @plugin["network"]["settings"]['net.inet.ipsec.dfbit'].should == '0'
- @plugin["network"]["settings"]['net.inet.ipsec.ecn'].should == '0'
- @plugin["network"]["settings"]['net.inet.ipsec.debug'].should == '0'
- @plugin["network"]["settings"]['net.inet.ipsec.esp_randpad'].should == '-1'
- @plugin["network"]["settings"]['net.inet.ipsec.bypass'].should == '0'
- @plugin["network"]["settings"]['net.inet.ipsec.esp_port'].should == '4500'
- @plugin["network"]["settings"]['net.inet.raw.maxdgram'].should == '8192'
- @plugin["network"]["settings"]['net.inet.raw.recvspace'].should == '8192'
- @plugin["network"]["settings"]['net.link.generic.system.ifcount'].should == '10'
- @plugin["network"]["settings"]['net.link.generic.system.dlil_verbose'].should == '0'
- @plugin["network"]["settings"]['net.link.generic.system.multi_threaded_input'].should == '1'
- @plugin["network"]["settings"]['net.link.generic.system.dlil_input_sanity_check'].should == '0'
- @plugin["network"]["settings"]['net.link.ether.inet.prune_intvl'].should == '300'
- @plugin["network"]["settings"]['net.link.ether.inet.max_age'].should == '1200'
- @plugin["network"]["settings"]['net.link.ether.inet.host_down_time'].should == '20'
- @plugin["network"]["settings"]['net.link.ether.inet.apple_hwcksum_tx'].should == '1'
- @plugin["network"]["settings"]['net.link.ether.inet.apple_hwcksum_rx'].should == '1'
- @plugin["network"]["settings"]['net.link.ether.inet.arp_llreach_base'].should == '30'
- @plugin["network"]["settings"]['net.link.ether.inet.maxtries'].should == '5'
- @plugin["network"]["settings"]['net.link.ether.inet.useloopback'].should == '1'
- @plugin["network"]["settings"]['net.link.ether.inet.proxyall'].should == '0'
- @plugin["network"]["settings"]['net.link.ether.inet.sendllconflict'].should == '0'
- @plugin["network"]["settings"]['net.link.ether.inet.log_arp_warnings'].should == '0'
- @plugin["network"]["settings"]['net.link.ether.inet.keep_announcements'].should == '1'
- @plugin["network"]["settings"]['net.link.ether.inet.send_conflicting_probes'].should == '1'
- @plugin["network"]["settings"]['net.link.bridge.log_stp'].should == '0'
- @plugin["network"]["settings"]['net.link.bridge.debug'].should == '0'
- @plugin["network"]["settings"]['net.key.debug'].should == '0'
- @plugin["network"]["settings"]['net.key.spi_trycnt'].should == '1000'
- @plugin["network"]["settings"]['net.key.spi_minval'].should == '256'
- @plugin["network"]["settings"]['net.key.spi_maxval'].should == '268435455'
- @plugin["network"]["settings"]['net.key.int_random'].should == '60'
- @plugin["network"]["settings"]['net.key.larval_lifetime'].should == '30'
- @plugin["network"]["settings"]['net.key.blockacq_count'].should == '10'
- @plugin["network"]["settings"]['net.key.blockacq_lifetime'].should == '20'
- @plugin["network"]["settings"]['net.key.esp_keymin'].should == '256'
- @plugin["network"]["settings"]['net.key.esp_auth'].should == '0'
- @plugin["network"]["settings"]['net.key.ah_keymin'].should == '128'
- @plugin["network"]["settings"]['net.key.prefered_oldsa'].should == '0'
- @plugin["network"]["settings"]['net.key.natt_keepalive_interval'].should == '20'
- @plugin["network"]["settings"]['net.inet6.ip6.forwarding'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.redirect'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.hlim'].should == '64'
- @plugin["network"]["settings"]['net.inet6.ip6.maxfragpackets'].should == '1536'
- @plugin["network"]["settings"]['net.inet6.ip6.accept_rtadv'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.keepfaith'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.log_interval'].should == '5'
- @plugin["network"]["settings"]['net.inet6.ip6.hdrnestlimit'].should == '15'
- @plugin["network"]["settings"]['net.inet6.ip6.dad_count'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.auto_flowlabel'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.defmcasthlim'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.gifhlim'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.kame_version'].should == '2009/apple-darwin'
- @plugin["network"]["settings"]['net.inet6.ip6.use_deprecated'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.rr_prune'].should == '5'
- @plugin["network"]["settings"]['net.inet6.ip6.v6only'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.rtexpire'].should == '3600'
- @plugin["network"]["settings"]['net.inet6.ip6.rtminexpire'].should == '10'
- @plugin["network"]["settings"]['net.inet6.ip6.rtmaxcache'].should == '128'
- @plugin["network"]["settings"]['net.inet6.ip6.use_tempaddr'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.temppltime'].should == '86400'
- @plugin["network"]["settings"]['net.inet6.ip6.tempvltime'].should == '604800'
- @plugin["network"]["settings"]['net.inet6.ip6.auto_linklocal'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.prefer_tempaddr'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.use_defaultzone'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.maxfrags'].should == '12288'
- @plugin["network"]["settings"]['net.inet6.ip6.mcast_pmtu'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.neighborgcthresh'].should == '1024'
- @plugin["network"]["settings"]['net.inet6.ip6.maxifprefixes'].should == '16'
- @plugin["network"]["settings"]['net.inet6.ip6.maxifdefrouters'].should == '16'
- @plugin["network"]["settings"]['net.inet6.ip6.maxdynroutes'].should == '1024'
- @plugin["network"]["settings"]['net.inet6.ip6.fw.enable'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.fw.debug'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.fw.verbose'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.fw.verbose_limit'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.scopedroute'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.select_srcif_debug'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ip6.mcast.maxgrpsrc'].should == '512'
- @plugin["network"]["settings"]['net.inet6.ip6.mcast.maxsocksrc'].should == '128'
- @plugin["network"]["settings"]['net.inet6.ip6.mcast.loop'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ip6.only_allow_rfc4193_prefixes'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ipsec6.def_policy'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ipsec6.esp_trans_deflev'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ipsec6.esp_net_deflev'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ipsec6.ah_trans_deflev'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ipsec6.ah_net_deflev'].should == '1'
- @plugin["network"]["settings"]['net.inet6.ipsec6.ecn'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ipsec6.debug'].should == '0'
- @plugin["network"]["settings"]['net.inet6.ipsec6.esp_randpad'].should == '-1'
- @plugin["network"]["settings"]['net.inet6.icmp6.rediraccept'].should == '1'
- @plugin["network"]["settings"]['net.inet6.icmp6.redirtimeout'].should == '600'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_prune'].should == '1'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_delay'].should == '5'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_umaxtries'].should == '3'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_mmaxtries'].should == '3'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_useloopback'].should == '1'
- @plugin["network"]["settings"]['net.inet6.icmp6.nodeinfo'].should == '3'
- @plugin["network"]["settings"]['net.inet6.icmp6.errppslimit'].should == '500'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_maxnudhint'].should == '0'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_debug'].should == '0'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_accept_6to4'].should == '1'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_onlink_ns_rfc4861'].should == '0'
- @plugin["network"]["settings"]['net.inet6.icmp6.nd6_llreach_base'].should == '30'
- @plugin["network"]["settings"]['net.inet6.mld.gsrdelay'].should == '10'
- @plugin["network"]["settings"]['net.inet6.mld.v1enable'].should == '1'
- @plugin["network"]["settings"]['net.inet6.mld.use_allow'].should == '1'
- @plugin["network"]["settings"]['net.inet6.mld.debug'].should == '0'
- @plugin["network"]["settings"]['net.idle.route.expire_timeout'].should == '30'
- @plugin["network"]["settings"]['net.idle.route.drain_interval'].should == '10'
- @plugin["network"]["settings"]['net.statistics'].should == '1'
- @plugin["network"]["settings"]['net.alf.loglevel'].should == '55'
- @plugin["network"]["settings"]['net.alf.perm'].should == '0'
- @plugin["network"]["settings"]['net.alf.defaultaction'].should == '1'
- @plugin["network"]["settings"]['net.alf.mqcount'].should == '0'
- @plugin["network"]["settings"]['net.smb.fs.version'].should == '107000'
- @plugin["network"]["settings"]['net.smb.fs.loglevel'].should == '0'
- @plugin["network"]["settings"]['net.smb.fs.kern_ntlmssp'].should == '0'
- @plugin["network"]["settings"]['net.smb.fs.kern_deprecatePreXPServers'].should == '1'
- @plugin["network"]["settings"]['net.smb.fs.kern_deadtimer'].should == '60'
- @plugin["network"]["settings"]['net.smb.fs.kern_hard_deadtimer'].should == '600'
- @plugin["network"]["settings"]['net.smb.fs.kern_soft_deadtimer'].should == '30'
- @plugin["network"]["settings"]['net.smb.fs.tcpsndbuf'].should == '261120'
- @plugin["network"]["settings"]['net.smb.fs.tcprcvbuf'].should == '261120'
+ @ohai['network']['settings']['net.local.stream.sendspace'].should == '8192'
+ @ohai["network"]["settings"]['net.local.stream.recvspace'].should == '8192'
+ @ohai["network"]["settings"]['net.local.stream.tracemdns'].should == '0'
+ @ohai["network"]["settings"]['net.local.dgram.maxdgram'].should == '2048'
+ @ohai["network"]["settings"]['net.local.dgram.recvspace'].should == '4096'
+ @ohai["network"]["settings"]['net.local.inflight'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.portrange.lowfirst'].should == '1023'
+ @ohai["network"]["settings"]['net.inet.ip.portrange.lowlast'].should == '600'
+ @ohai["network"]["settings"]['net.inet.ip.portrange.first'].should == '49152'
+ @ohai["network"]["settings"]['net.inet.ip.portrange.last'].should == '65535'
+ @ohai["network"]["settings"]['net.inet.ip.portrange.hifirst'].should == '49152'
+ @ohai["network"]["settings"]['net.inet.ip.portrange.hilast'].should == '65535'
+ @ohai["network"]["settings"]['net.inet.ip.forwarding'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.redirect'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.ttl'].should == '64'
+ @ohai["network"]["settings"]['net.inet.ip.rtexpire'].should == '12'
+ @ohai["network"]["settings"]['net.inet.ip.rtminexpire'].should == '10'
+ @ohai["network"]["settings"]['net.inet.ip.rtmaxcache'].should == '128'
+ @ohai["network"]["settings"]['net.inet.ip.sourceroute'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.intr_queue_maxlen'].should == '50'
+ @ohai["network"]["settings"]['net.inet.ip.intr_queue_drops'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.accept_sourceroute'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.keepfaith'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.gifttl'].should == '30'
+ @ohai["network"]["settings"]['net.inet.ip.subnets_are_local'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.mcast.maxgrpsrc'].should == '512'
+ @ohai["network"]["settings"]['net.inet.ip.mcast.maxsocksrc'].should == '128'
+ @ohai["network"]["settings"]['net.inet.ip.mcast.loop'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.check_route_selfref'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.use_route_genid'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.hash_size'].should == '64'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.curr_time'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.ready_heap'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.extract_heap'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.searches'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.search_steps'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.expire'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.max_chain_len'].should == '16'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.red_lookup_depth'].should == '256'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.red_avg_pkt_size'].should == '512'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.red_max_pkt_size'].should == '1500'
+ @ohai["network"]["settings"]['net.inet.ip.dummynet.debug'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.fw.enable'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.fw.autoinc_step'].should == '100'
+ @ohai["network"]["settings"]['net.inet.ip.fw.one_pass'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.fw.debug'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.fw.verbose'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.fw.verbose_limit'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_buckets'].should == '256'
+ @ohai["network"]["settings"]['net.inet.ip.fw.curr_dyn_buckets'].should == '256'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_count'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_max'].should == '4096'
+ @ohai["network"]["settings"]['net.inet.ip.fw.static_count'].should == '2'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_ack_lifetime'].should == '300'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_syn_lifetime'].should == '20'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_fin_lifetime'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_rst_lifetime'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_udp_lifetime'].should == '10'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_short_lifetime'].should == '5'
+ @ohai["network"]["settings"]['net.inet.ip.fw.dyn_keepalive'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.maxfragpackets'].should == '1536'
+ @ohai["network"]["settings"]['net.inet.ip.maxfragsperpacket'].should == '128'
+ @ohai["network"]["settings"]['net.inet.ip.maxfrags'].should == '3072'
+ @ohai["network"]["settings"]['net.inet.ip.scopedroute'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.check_interface'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.linklocal.in.allowbadttl'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.random_id'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ip.maxchainsent'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ip.select_srcif_debug'].should == '0'
+ @ohai["network"]["settings"]['net.inet.icmp.maskrepl'].should == '0'
+ @ohai["network"]["settings"]['net.inet.icmp.icmplim'].should == '250'
+ @ohai["network"]["settings"]['net.inet.icmp.timestamp'].should == '0'
+ @ohai["network"]["settings"]['net.inet.icmp.drop_redirect'].should == '0'
+ @ohai["network"]["settings"]['net.inet.icmp.log_redirect'].should == '0'
+ @ohai["network"]["settings"]['net.inet.icmp.bmcastecho'].should == '1'
+ @ohai["network"]["settings"]['net.inet.igmp.recvifkludge'].should == '1'
+ @ohai["network"]["settings"]['net.inet.igmp.sendra'].should == '1'
+ @ohai["network"]["settings"]['net.inet.igmp.sendlocal'].should == '1'
+ @ohai["network"]["settings"]['net.inet.igmp.v1enable'].should == '1'
+ @ohai["network"]["settings"]['net.inet.igmp.v2enable'].should == '1'
+ @ohai["network"]["settings"]['net.inet.igmp.legacysupp'].should == '0'
+ @ohai["network"]["settings"]['net.inet.igmp.default_version'].should == '3'
+ @ohai["network"]["settings"]['net.inet.igmp.gsrdelay'].should == '10'
+ @ohai["network"]["settings"]['net.inet.igmp.debug'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.rfc1323'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.rfc1644'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.mssdflt'].should == '512'
+ @ohai["network"]["settings"]['net.inet.tcp.keepidle'].should == '7200000'
+ @ohai["network"]["settings"]['net.inet.tcp.keepintvl'].should == '75000'
+ @ohai["network"]["settings"]['net.inet.tcp.sendspace'].should == '65536'
+ @ohai["network"]["settings"]['net.inet.tcp.recvspace'].should == '65536'
+ @ohai["network"]["settings"]['net.inet.tcp.keepinit'].should == '75000'
+ @ohai["network"]["settings"]['net.inet.tcp.v6mssdflt'].should == '1024'
+ @ohai["network"]["settings"]['net.inet.tcp.log_in_vain'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.blackhole'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.delayed_ack'].should == '3'
+ @ohai["network"]["settings"]['net.inet.tcp.tcp_lq_overflow'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.recvbg'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.drop_synfin'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.reass.maxsegments'].should == '3072'
+ @ohai["network"]["settings"]['net.inet.tcp.reass.cursegments'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.reass.overflows'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.slowlink_wsize'].should == '8192'
+ @ohai["network"]["settings"]['net.inet.tcp.maxseg_unacked'].should == '8'
+ @ohai["network"]["settings"]['net.inet.tcp.rfc3465'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.rfc3465_lim2'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.rtt_samples_per_slot'].should == '20'
+ @ohai["network"]["settings"]['net.inet.tcp.recv_allowed_iaj'].should == '5'
+ @ohai["network"]["settings"]['net.inet.tcp.acc_iaj_high_thresh'].should == '100'
+ @ohai["network"]["settings"]['net.inet.tcp.rexmt_thresh'].should == '2'
+ @ohai["network"]["settings"]['net.inet.tcp.path_mtu_discovery'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.slowstart_flightsize'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.local_slowstart_flightsize'].should == '8'
+ @ohai["network"]["settings"]['net.inet.tcp.tso'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.ecn_initiate_out'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.ecn_negotiate_in'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.packetchain'].should == '50'
+ @ohai["network"]["settings"]['net.inet.tcp.socket_unlocked_on_output'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.rfc3390'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.min_iaj_win'].should == '4'
+ @ohai["network"]["settings"]['net.inet.tcp.acc_iaj_react_limit'].should == '200'
+ @ohai["network"]["settings"]['net.inet.tcp.sack'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.sack_maxholes'].should == '128'
+ @ohai["network"]["settings"]['net.inet.tcp.sack_globalmaxholes'].should == '65536'
+ @ohai["network"]["settings"]['net.inet.tcp.sack_globalholes'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.minmss'].should == '216'
+ @ohai["network"]["settings"]['net.inet.tcp.minmssoverload'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.do_tcpdrain'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.pcbcount'].should == '86'
+ @ohai["network"]["settings"]['net.inet.tcp.icmp_may_rst'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.strict_rfc1948'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.isn_reseed_interval'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.background_io_enabled'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.rtt_min'].should == '100'
+ @ohai["network"]["settings"]['net.inet.tcp.rexmt_slop'].should == '200'
+ @ohai["network"]["settings"]['net.inet.tcp.randomize_ports'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.newreno_sockets'].should == '81'
+ @ohai["network"]["settings"]['net.inet.tcp.background_sockets'].should == '-1'
+ @ohai["network"]["settings"]['net.inet.tcp.tcbhashsize'].should == '4096'
+ @ohai["network"]["settings"]['net.inet.tcp.background_io_trigger'].should == '5'
+ @ohai["network"]["settings"]['net.inet.tcp.msl'].should == '15000'
+ @ohai["network"]["settings"]['net.inet.tcp.max_persist_timeout'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.always_keepalive'].should == '0'
+ @ohai["network"]["settings"]['net.inet.tcp.timer_fastmode_idlemax'].should == '20'
+ @ohai["network"]["settings"]['net.inet.tcp.broken_peer_syn_rxmit_thres'].should == '7'
+ @ohai["network"]["settings"]['net.inet.tcp.tcp_timer_advanced'].should == '5'
+ @ohai["network"]["settings"]['net.inet.tcp.tcp_resched_timerlist'].should == '12209'
+ @ohai["network"]["settings"]['net.inet.tcp.pmtud_blackhole_detection'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.pmtud_blackhole_mss'].should == '1200'
+ @ohai["network"]["settings"]['net.inet.tcp.timer_fastquantum'].should == '100'
+ @ohai["network"]["settings"]['net.inet.tcp.timer_slowquantum'].should == '500'
+ @ohai["network"]["settings"]['net.inet.tcp.win_scale_factor'].should == '3'
+ @ohai["network"]["settings"]['net.inet.tcp.sockthreshold'].should == '64'
+ @ohai["network"]["settings"]['net.inet.tcp.bg_target_qdelay'].should == '100'
+ @ohai["network"]["settings"]['net.inet.tcp.bg_allowed_increase'].should == '2'
+ @ohai["network"]["settings"]['net.inet.tcp.bg_tether_shift'].should == '1'
+ @ohai["network"]["settings"]['net.inet.tcp.bg_ss_fltsz'].should == '2'
+ @ohai["network"]["settings"]['net.inet.udp.checksum'].should == '1'
+ @ohai["network"]["settings"]['net.inet.udp.maxdgram'].should == '9216'
+ @ohai["network"]["settings"]['net.inet.udp.recvspace'].should == '42080'
+ @ohai["network"]["settings"]['net.inet.udp.log_in_vain'].should == '0'
+ @ohai["network"]["settings"]['net.inet.udp.blackhole'].should == '0'
+ @ohai["network"]["settings"]['net.inet.udp.pcbcount'].should == '72'
+ @ohai["network"]["settings"]['net.inet.udp.randomize_ports'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ipsec.def_policy'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ipsec.esp_trans_deflev'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ipsec.esp_net_deflev'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ipsec.ah_trans_deflev'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ipsec.ah_net_deflev'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ipsec.ah_cleartos'].should == '1'
+ @ohai["network"]["settings"]['net.inet.ipsec.ah_offsetmask'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ipsec.dfbit'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ipsec.ecn'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ipsec.debug'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ipsec.esp_randpad'].should == '-1'
+ @ohai["network"]["settings"]['net.inet.ipsec.bypass'].should == '0'
+ @ohai["network"]["settings"]['net.inet.ipsec.esp_port'].should == '4500'
+ @ohai["network"]["settings"]['net.inet.raw.maxdgram'].should == '8192'
+ @ohai["network"]["settings"]['net.inet.raw.recvspace'].should == '8192'
+ @ohai["network"]["settings"]['net.link.generic.system.ifcount'].should == '10'
+ @ohai["network"]["settings"]['net.link.generic.system.dlil_verbose'].should == '0'
+ @ohai["network"]["settings"]['net.link.generic.system.multi_threaded_input'].should == '1'
+ @ohai["network"]["settings"]['net.link.generic.system.dlil_input_sanity_check'].should == '0'
+ @ohai["network"]["settings"]['net.link.ether.inet.prune_intvl'].should == '300'
+ @ohai["network"]["settings"]['net.link.ether.inet.max_age'].should == '1200'
+ @ohai["network"]["settings"]['net.link.ether.inet.host_down_time'].should == '20'
+ @ohai["network"]["settings"]['net.link.ether.inet.apple_hwcksum_tx'].should == '1'
+ @ohai["network"]["settings"]['net.link.ether.inet.apple_hwcksum_rx'].should == '1'
+ @ohai["network"]["settings"]['net.link.ether.inet.arp_llreach_base'].should == '30'
+ @ohai["network"]["settings"]['net.link.ether.inet.maxtries'].should == '5'
+ @ohai["network"]["settings"]['net.link.ether.inet.useloopback'].should == '1'
+ @ohai["network"]["settings"]['net.link.ether.inet.proxyall'].should == '0'
+ @ohai["network"]["settings"]['net.link.ether.inet.sendllconflict'].should == '0'
+ @ohai["network"]["settings"]['net.link.ether.inet.log_arp_warnings'].should == '0'
+ @ohai["network"]["settings"]['net.link.ether.inet.keep_announcements'].should == '1'
+ @ohai["network"]["settings"]['net.link.ether.inet.send_conflicting_probes'].should == '1'
+ @ohai["network"]["settings"]['net.link.bridge.log_stp'].should == '0'
+ @ohai["network"]["settings"]['net.link.bridge.debug'].should == '0'
+ @ohai["network"]["settings"]['net.key.debug'].should == '0'
+ @ohai["network"]["settings"]['net.key.spi_trycnt'].should == '1000'
+ @ohai["network"]["settings"]['net.key.spi_minval'].should == '256'
+ @ohai["network"]["settings"]['net.key.spi_maxval'].should == '268435455'
+ @ohai["network"]["settings"]['net.key.int_random'].should == '60'
+ @ohai["network"]["settings"]['net.key.larval_lifetime'].should == '30'
+ @ohai["network"]["settings"]['net.key.blockacq_count'].should == '10'
+ @ohai["network"]["settings"]['net.key.blockacq_lifetime'].should == '20'
+ @ohai["network"]["settings"]['net.key.esp_keymin'].should == '256'
+ @ohai["network"]["settings"]['net.key.esp_auth'].should == '0'
+ @ohai["network"]["settings"]['net.key.ah_keymin'].should == '128'
+ @ohai["network"]["settings"]['net.key.prefered_oldsa'].should == '0'
+ @ohai["network"]["settings"]['net.key.natt_keepalive_interval'].should == '20'
+ @ohai["network"]["settings"]['net.inet6.ip6.forwarding'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.redirect'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.hlim'].should == '64'
+ @ohai["network"]["settings"]['net.inet6.ip6.maxfragpackets'].should == '1536'
+ @ohai["network"]["settings"]['net.inet6.ip6.accept_rtadv'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.keepfaith'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.log_interval'].should == '5'
+ @ohai["network"]["settings"]['net.inet6.ip6.hdrnestlimit'].should == '15'
+ @ohai["network"]["settings"]['net.inet6.ip6.dad_count'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.auto_flowlabel'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.defmcasthlim'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.gifhlim'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.kame_version'].should == '2009/apple-darwin'
+ @ohai["network"]["settings"]['net.inet6.ip6.use_deprecated'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.rr_prune'].should == '5'
+ @ohai["network"]["settings"]['net.inet6.ip6.v6only'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.rtexpire'].should == '3600'
+ @ohai["network"]["settings"]['net.inet6.ip6.rtminexpire'].should == '10'
+ @ohai["network"]["settings"]['net.inet6.ip6.rtmaxcache'].should == '128'
+ @ohai["network"]["settings"]['net.inet6.ip6.use_tempaddr'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.temppltime'].should == '86400'
+ @ohai["network"]["settings"]['net.inet6.ip6.tempvltime'].should == '604800'
+ @ohai["network"]["settings"]['net.inet6.ip6.auto_linklocal'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.prefer_tempaddr'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.use_defaultzone'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.maxfrags'].should == '12288'
+ @ohai["network"]["settings"]['net.inet6.ip6.mcast_pmtu'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.neighborgcthresh'].should == '1024'
+ @ohai["network"]["settings"]['net.inet6.ip6.maxifprefixes'].should == '16'
+ @ohai["network"]["settings"]['net.inet6.ip6.maxifdefrouters'].should == '16'
+ @ohai["network"]["settings"]['net.inet6.ip6.maxdynroutes'].should == '1024'
+ @ohai["network"]["settings"]['net.inet6.ip6.fw.enable'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.fw.debug'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.fw.verbose'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.fw.verbose_limit'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.scopedroute'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.select_srcif_debug'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ip6.mcast.maxgrpsrc'].should == '512'
+ @ohai["network"]["settings"]['net.inet6.ip6.mcast.maxsocksrc'].should == '128'
+ @ohai["network"]["settings"]['net.inet6.ip6.mcast.loop'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ip6.only_allow_rfc4193_prefixes'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ipsec6.def_policy'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ipsec6.esp_trans_deflev'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ipsec6.esp_net_deflev'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ipsec6.ah_trans_deflev'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ipsec6.ah_net_deflev'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.ipsec6.ecn'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ipsec6.debug'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.ipsec6.esp_randpad'].should == '-1'
+ @ohai["network"]["settings"]['net.inet6.icmp6.rediraccept'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.icmp6.redirtimeout'].should == '600'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_prune'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_delay'].should == '5'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_umaxtries'].should == '3'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_mmaxtries'].should == '3'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_useloopback'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nodeinfo'].should == '3'
+ @ohai["network"]["settings"]['net.inet6.icmp6.errppslimit'].should == '500'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_maxnudhint'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_debug'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_accept_6to4'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_onlink_ns_rfc4861'].should == '0'
+ @ohai["network"]["settings"]['net.inet6.icmp6.nd6_llreach_base'].should == '30'
+ @ohai["network"]["settings"]['net.inet6.mld.gsrdelay'].should == '10'
+ @ohai["network"]["settings"]['net.inet6.mld.v1enable'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.mld.use_allow'].should == '1'
+ @ohai["network"]["settings"]['net.inet6.mld.debug'].should == '0'
+ @ohai["network"]["settings"]['net.idle.route.expire_timeout'].should == '30'
+ @ohai["network"]["settings"]['net.idle.route.drain_interval'].should == '10'
+ @ohai["network"]["settings"]['net.statistics'].should == '1'
+ @ohai["network"]["settings"]['net.alf.loglevel'].should == '55'
+ @ohai["network"]["settings"]['net.alf.perm'].should == '0'
+ @ohai["network"]["settings"]['net.alf.defaultaction'].should == '1'
+ @ohai["network"]["settings"]['net.alf.mqcount'].should == '0'
+ @ohai["network"]["settings"]['net.smb.fs.version'].should == '107000'
+ @ohai["network"]["settings"]['net.smb.fs.loglevel'].should == '0'
+ @ohai["network"]["settings"]['net.smb.fs.kern_ntlmssp'].should == '0'
+ @ohai["network"]["settings"]['net.smb.fs.kern_deprecatePreXPServers'].should == '1'
+ @ohai["network"]["settings"]['net.smb.fs.kern_deadtimer'].should == '60'
+ @ohai["network"]["settings"]['net.smb.fs.kern_hard_deadtimer'].should == '600'
+ @ohai["network"]["settings"]['net.smb.fs.kern_soft_deadtimer'].should == '30'
+ @ohai["network"]["settings"]['net.smb.fs.tcpsndbuf'].should == '261120'
+ @ohai["network"]["settings"]['net.smb.fs.tcprcvbuf'].should == '261120'
end
end
end
diff --git a/spec/unit/plugins/darwin/platform_spec.rb b/spec/unit/plugins/darwin/platform_spec.rb
index f98b4cf5..1a63b697 100644
--- a/spec/unit/plugins/darwin/platform_spec.rb
+++ b/spec/unit/plugins/darwin/platform_spec.rb
@@ -21,79 +21,79 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Darwin plugin platform" do
before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("darwin/platform.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "darwin"
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "darwin"
@pid = 10
- @stdin = double("STDIN", { :close => true })
- @stdout = double("STDOUT")
- @stdout.stub(:each).
+ @stdin = mock("STDIN", { :close => true })
+ @stdout = mock("STDOUT")
+ @stdout.stub!(:each).
and_yield("ProductName: Mac OS X").
and_yield("ProductVersion: 10.5.5").
and_yield("BuildVersion: 9F33")
- @stderr = double("STDERR")
- @plugin.stub(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr)
+ @stderr = mock("STDERR")
+ @ohai.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr)
end
it "should run sw_vers" do
- @plugin.should_receive(:popen4).with("/usr/bin/sw_vers").and_return(true)
- @plugin.run
+ @ohai.should_receive(:popen4).with("/usr/bin/sw_vers").and_return(true)
+ @ohai._require_plugin("darwin::platform")
end
it "should close sw_vers stdin" do
@stdin.should_receive(:close)
- @plugin.run
+ @ohai._require_plugin("darwin::platform")
end
it "should iterate over each line of sw_vers stdout" do
@stdout.should_receive(:each).and_return(true)
- @plugin.run
+ @ohai._require_plugin("darwin::platform")
end
it "should set platform to ProductName, downcased with _ for \\s" do
- @plugin.run
- @plugin[:platform].should == "mac_os_x"
+ @ohai._require_plugin("darwin::platform")
+ @ohai[:platform].should == "mac_os_x"
end
it "should set platform_version to ProductVersion" do
- @plugin.run
- @plugin[:platform_version].should == "10.5.5"
+ @ohai._require_plugin("darwin::platform")
+ @ohai[:platform_version].should == "10.5.5"
end
it "should set platform_build to BuildVersion" do
- @plugin.run
- @plugin[:platform_build].should == "9F33"
+ @ohai._require_plugin("darwin::platform")
+ @ohai[:platform_build].should == "9F33"
end
it "should set platform_family to mac_os_x" do
- @plugin.run
- @plugin[:platform_family].should == "mac_os_x"
+ @ohai._require_plugin("darwin::platform")
+ @ohai[:platform_family].should == "mac_os_x"
end
describe "on os x server" do
before(:each) do
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "darwin"
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "darwin"
@pid = 10
- @stdin = double("STDIN", { :close => true })
- @stdout = double("STDOUT")
- @stdout.stub(:each).
+ @stdin = mock("STDIN", { :close => true })
+ @stdout = mock("STDOUT")
+ @stdout.stub!(:each).
and_yield("ProductName: Mac OS X Server").
and_yield("ProductVersion: 10.6.8").
and_yield("BuildVersion: 10K549")
- @stderr = double("STDERR")
- @plugin.stub(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr)
+ @stderr = mock("STDERR")
+ @ohai.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr)
end
it "should set platform to mac_os_x_server" do
- @plugin.run
- @plugin[:platform].should == "mac_os_x_server"
+ @ohai._require_plugin("darwin::platform")
+ @ohai[:platform].should == "mac_os_x_server"
end
it "should set platform_family to mac_os_x" do
- @plugin.run
- @plugin[:platform_family].should == "mac_os_x"
+ @ohai._require_plugin("darwin::platform")
+ @ohai[:platform_family].should == "mac_os_x"
end
end
end
diff --git a/spec/unit/plugins/darwin/system_profiler_spec.rb b/spec/unit/plugins/darwin/system_profiler_spec.rb
index fae624bb..73fdd942 100644
--- a/spec/unit/plugins/darwin/system_profiler_spec.rb
+++ b/spec/unit/plugins/darwin/system_profiler_spec.rb
@@ -29,7 +29,8 @@ end
describe Ohai::System, "Darwin system_profiler plugin", :unix_only do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("darwin/system_profiler.rb", PLUGIN_PATH))
+
+ @ohai.stub!(:require_plugin).and_return(true)
end
it "should return the right serial number" do
@@ -39,9 +40,9 @@ describe Ohai::System, "Darwin system_profiler plugin", :unix_only do
mini_cmd += " SPPCIData SPParallelSCSIData SPPrintersSoftwareData SPPrintersData SPSASData SPSerialATAData"
mini_cmd += " SPSoftwareData SPThunderboltData SPUSBData SPWWANData SPAirPortData"
full_cmd = "system_profiler -xml -detailLevel full SPHardwareDataType"
- @plugin.stub(:popen4).with(full_cmd).and_yield(nil, StringIO.new, StringIO.new(SystemProfilerOutput::Full), nil)
- @plugin.stub(:popen4).with(mini_cmd).and_yield(nil, StringIO.new, StringIO.new(SystemProfilerOutput::Mini), nil)
- @plugin.run
- @plugin['system_profile'][18]["_items"][0]["serial_number"].should == 'ABCDEFG12345'
+ @ohai.stub!(:popen4).with(full_cmd).and_yield(nil, StringIO.new, StringIO.new(SystemProfilerOutput::Full), nil)
+ @ohai.stub!(:popen4).with(mini_cmd).and_yield(nil, StringIO.new, StringIO.new(SystemProfilerOutput::Mini), nil)
+ @ohai._require_plugin("darwin::system_profiler")
+ @ohai['system_profile'][18]["_items"][0]["serial_number"].should == 'ABCDEFG12345'
end
end
diff --git a/spec/unit/plugins/dmi_spec.rb b/spec/unit/plugins/dmi_spec.rb
index 8f233d72..c761df25 100644
--- a/spec/unit/plugins/dmi_spec.rb
+++ b/spec/unit/plugins/dmi_spec.rb
@@ -94,19 +94,18 @@ EOS
describe Ohai::System, "plugin dmi" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "dmi.rb"))
- @plugin.stub(:require_plugin).and_return(true)
- @stdin = double("STDIN", { :close => true })
+ @ohai.stub!(:require_plugin).and_return(true)
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
+ @stderr = mock("STDERR")
@stdout = StringIO.new(DMI_OUT)
@status = 0
- @plugin.stub(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
end
it "should run dmidecode" do
- @plugin.should_receive(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
+ @ohai.should_receive(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("dmi")
end
# Test some simple sample data
@@ -126,8 +125,8 @@ describe Ohai::System, "plugin dmi" do
}.each do |id, data|
data.each do |attribute, value|
it "should have [:dmi][:#{id}][:#{attribute}] set" do
- @plugin.run
- @plugin[:dmi][id][attribute].should eql(value)
+ @ohai._require_plugin("dmi")
+ @ohai[:dmi][id][attribute].should eql(value)
end
end
end
diff --git a/spec/unit/plugins/ec2_spec.rb b/spec/unit/plugins/ec2_spec.rb
index ae018f0e..e27788f4 100644
--- a/spec/unit/plugins/ec2_spec.rb
+++ b/spec/unit/plugins/ec2_spec.rb
@@ -23,110 +23,103 @@ require 'open-uri'
describe Ohai::System, "plugin ec2" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ec2.rb"))
- @plugin.stub(:require_plugin)
- @plugin[:network] = {:interfaces => {:eth0 => {} } }
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:network] = {:interfaces => {:eth0 => {} } }
end
shared_examples_for "!ec2" do
it "should NOT attempt to fetch the ec2 metadata" do
- @plugin.should_not_receive(:http_client)
- @plugin.run
+ @ohai.should_not_receive(:http_client)
+ @ohai._require_plugin("ec2")
end
end
shared_examples_for "ec2" do
before(:each) do
- @http_client = double("Net::HTTP client")
- @plugin.stub(:http_client).and_return(@http_client)
- IO.stub(:select).and_return([[],[1],[]])
- t = double("connection")
- t.stub(:connect_nonblock).and_raise(Errno::EINPROGRESS)
- Socket.stub(:new).and_return(t)
+ @http_client = mock("Net::HTTP client")
+ @ohai.stub!(:http_client).and_return(@http_client)
+ IO.stub!(:select).and_return([[],[1],[]])
+ t = mock("connection")
+ t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS)
+ Socket.stub!(:new).and_return(t)
@http_client.should_receive(:get).
with("/").twice.
- and_return(double("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
end
it "should recursively fetch all the ec2 metadata" do
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/").
- and_return(double("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/instance_type").
- and_return(double("Net::HTTP Response", :body => "c1.medium", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "c1.medium", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/ami_id").
- and_return(double("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/security-groups").
- and_return(double("Net::HTTP Response", :body => "group1\ngroup2", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "group1\ngroup2", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/user-data/").
- and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
+ @ohai._require_plugin("ec2")
- @plugin.run
- @plugin[:ec2].should_not be_nil
- @plugin[:ec2]['instance_type'].should == "c1.medium"
- @plugin[:ec2]['ami_id'].should == "ami-5d2dc934"
- @plugin[:ec2]['security_groups'].should eql ['group1', 'group2']
+ @ohai[:ec2].should_not be_nil
+ @ohai[:ec2]['instance_type'].should == "c1.medium"
+ @ohai[:ec2]['ami_id'].should == "ami-5d2dc934"
+ @ohai[:ec2]['security_groups'].should eql ['group1', 'group2']
end
it "should parse ec2 network/ directory as a multi-level hash" do
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/").
- and_return(double("Net::HTTP Response", :body => "network/", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "network/", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/network/").
- and_return(double("Net::HTTP Response", :body => "interfaces/", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "interfaces/", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/network/interfaces/").
- and_return(double("Net::HTTP Response", :body => "macs/", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "macs/", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/network/interfaces/macs/").
- and_return(double("Net::HTTP Response", :body => "12:34:56:78:9a:bc/", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "12:34:56:78:9a:bc/", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/").
- and_return(double("Net::HTTP Response", :body => "public_hostname", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "public_hostname", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/public_hostname").
- and_return(double("Net::HTTP Response", :body => "server17.opscode.com", :code => "200"))
- @http_client.should_receive(:get).
- with("/2012-01-12/user-data/").
- and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
- @plugin.run
+ and_return(mock("Net::HTTP Response", :body => "server17.opscode.com", :code => "200"))
+ @ohai._require_plugin("ec2")
- @plugin[:ec2].should_not be_nil
- @plugin[:ec2]['network_interfaces_macs']['12:34:56:78:9a:bc']['public_hostname'].should eql('server17.opscode.com')
+ @ohai[:ec2].should_not be_nil
+ @ohai[:ec2]['network_interfaces_macs']['12:34:56:78:9a:bc']['public_hostname'].should eql('server17.opscode.com')
end
it "should parse ec2 iam/ directory and its JSON files properly" do
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/").
- and_return(double("Net::HTTP Response", :body => "iam/", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "iam/", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/iam/").
- and_return(double("Net::HTTP Response", :body => "security-credentials/", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "security-credentials/", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/iam/security-credentials/").
- and_return(double("Net::HTTP Response", :body => "MyRole", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "MyRole", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/iam/security-credentials/MyRole").
- and_return(double("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200"))
- @http_client.should_receive(:get).
- with("/2012-01-12/user-data/").
- and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
- @plugin.run
+ and_return(mock("Net::HTTP Response", :body => "{\n \"Code\" : \"Success\",\n \"LastUpdated\" : \"2012-08-22T07:47:22Z\",\n \"Type\" : \"AWS-HMAC\",\n \"AccessKeyId\" : \"AAAAAAAA\",\n \"SecretAccessKey\" : \"SSSSSSSS\",\n \"Token\" : \"12345678\",\n \"Expiration\" : \"2012-08-22T11:25:52Z\"\n}", :code => "200"))
+ @ohai._require_plugin("ec2")
- @plugin[:ec2].should_not be_nil
- @plugin[:ec2]['iam']['security-credentials']['MyRole']['Code'].should eql 'Success'
- @plugin[:ec2]['iam']['security-credentials']['MyRole']['Token'].should eql '12345678'
+ @ohai[:ec2].should_not be_nil
+ @ohai[:ec2]['iam']['security-credentials']['MyRole']['Code'].should eql 'Success'
+ @ohai[:ec2]['iam']['security-credentials']['MyRole']['Token'].should eql '12345678'
end
it "should ignore \"./\" and \"../\" on ec2 metadata paths to avoid infinity loops" do
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/").
- and_return(double("Net::HTTP Response", :body => ".\n./\n..\n../\npath1/.\npath2/./\npath3/..\npath4/../", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => ".\n./\n..\n../\npath1/.\npath2/./\npath3/..\npath4/../", :code => "200"))
@http_client.should_not_receive(:get).
with("/2012-01-12/meta-data/.")
@@ -141,23 +134,20 @@ describe Ohai::System, "plugin ec2" do
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/path1/").
- and_return(double("Net::HTTP Response", :body => "", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/path2/").
- and_return(double("Net::HTTP Response", :body => "", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/path3/").
- and_return(double("Net::HTTP Response", :body => "", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/path4/").
- and_return(double("Net::HTTP Response", :body => "", :code => "200"))
- @http_client.should_receive(:get).
- with("/2012-01-12/user-data/").
- and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "", :code => "200"))
- @plugin.run
+ @ohai._require_plugin("ec2")
- @plugin[:ec2].should_not be_nil
+ @ohai[:ec2].should_not be_nil
end
end
@@ -165,8 +155,8 @@ describe Ohai::System, "plugin ec2" do
it_should_behave_like "ec2"
before(:each) do
- IO.stub(:select).and_return([[],[1],[]])
- @plugin[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"}
+ IO.stub!(:select).and_return([[],[1],[]])
+ @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"}
end
end
@@ -174,7 +164,7 @@ describe Ohai::System, "plugin ec2" do
it_should_behave_like "!ec2"
before(:each) do
- @plugin[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"}
+ @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"}
end
end
@@ -182,10 +172,10 @@ describe Ohai::System, "plugin ec2" do
it_should_behave_like "ec2"
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
- File.stub(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
- File.stub(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
end
end
@@ -193,8 +183,8 @@ describe Ohai::System, "plugin ec2" do
it_should_behave_like "!ec2"
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false)
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(false)
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false)
end
end
@@ -202,13 +192,10 @@ describe Ohai::System, "plugin ec2" do
it_should_behave_like "!ec2"
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(false)
-
- File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
- File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
- File.stub(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
end
end
diff --git a/spec/unit/plugins/erlang_spec.rb b/spec/unit/plugins/erlang_spec.rb
index 7f1b2f00..3eaba4f7 100644
--- a/spec/unit/plugins/erlang_spec.rb
+++ b/spec/unit/plugins/erlang_spec.rb
@@ -23,41 +23,41 @@ describe Ohai::System, "plugin erlang" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "erlang.rb"))
- @plugin[:languages] = Mash.new
+ @ohai[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
@status = 0
@stdin = ""
@stderr = "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"
- @plugin.stub(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([@status, @stdout, @stderr])
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([@status, @stdout, @stderr])
end
it "should get the erlang version from erl +V" do
- @plugin.should_receive(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([0, "", "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([0, "", "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"])
+ @ohai._require_plugin("erlang")
end
it "should set languages[:erlang][:version]" do
- @plugin.run
- @plugin.languages[:erlang][:version].should eql("5.6.2")
+ @ohai._require_plugin("erlang")
+ @ohai.languages[:erlang][:version].should eql("5.6.2")
end
it "should set languages[:erlang][:options]" do
- @plugin.run
- @plugin.languages[:erlang][:options].should eql(["ASYNC_THREADS", "SMP", "HIPE"])
+ @ohai._require_plugin("erlang")
+ @ohai.languages[:erlang][:options].should eql(["ASYNC_THREADS", "SMP", "HIPE"])
end
it "should set languages[:erlang][:emulator]" do
- @plugin.run
- @plugin.languages[:erlang][:emulator].should eql("BEAM")
+ @ohai._require_plugin("erlang")
+ @ohai.languages[:erlang][:emulator].should eql("BEAM")
end
it "should not set the languages[:erlang] tree up if erlang command fails" do
@status = 1
@stdin = ""
@stderr = "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n"
- @plugin.stub(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([@status, @stdout, @stderr])
- @plugin.run
- @plugin.languages.should_not have_key(:erlang)
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([@status, @stdout, @stderr])
+ @ohai._require_plugin("erlang")
+ @ohai.languages.should_not have_key(:erlang)
end
end
diff --git a/spec/unit/plugins/eucalyptus_spec.rb b/spec/unit/plugins/eucalyptus_spec.rb
index 310f0990..afe80ed4 100644
--- a/spec/unit/plugins/eucalyptus_spec.rb
+++ b/spec/unit/plugins/eucalyptus_spec.rb
@@ -23,52 +23,51 @@ require 'open-uri'
describe Ohai::System, "plugin eucalyptus" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "eucalyptus.rb"))
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai.stub!(:require_plugin).and_return(true)
end
shared_examples_for "!eucalyptus" do
it "should NOT attempt to fetch the eucalyptus metadata" do
OpenURI.should_not_receive(:open)
- @plugin.run
+ @ohai._require_plugin("eucalyptus")
end
end
shared_examples_for "eucalyptus" do
before(:each) do
- @http_client = double("Net::HTTP client")
- @plugin.stub(:http_client).and_return(@http_client)
+ @http_client = mock("Net::HTTP client")
+ @ohai.stub!(:http_client).and_return(@http_client)
@http_client.should_receive(:get).
with("/").twice.
- and_return(double("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/").
- and_return(double("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "instance_type\nami_id\nsecurity-groups", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/instance_type").
- and_return(double("Net::HTTP Response", :body => "c1.medium", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "c1.medium", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/ami_id").
- and_return(double("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "ami-5d2dc934", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/meta-data/security-groups").
- and_return(double("Net::HTTP Response", :body => "group1\ngroup2", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "group1\ngroup2", :code => "200"))
@http_client.should_receive(:get).
with("/2012-01-12/user-data/").
- and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
+ and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200"))
end
it "should recursively fetch all the eucalyptus metadata" do
- IO.stub(:select).and_return([[],[1],[]])
- t = double("connection")
- t.stub(:connect_nonblock).and_raise(Errno::EINPROGRESS)
- Socket.stub(:new).and_return(t)
- @plugin.run
- @plugin[:eucalyptus].should_not be_nil
- @plugin[:eucalyptus]['instance_type'].should == "c1.medium"
- @plugin[:eucalyptus]['ami_id'].should == "ami-5d2dc934"
- @plugin[:eucalyptus]['security_groups'].should eql ['group1', 'group2']
+ IO.stub!(:select).and_return([[],[1],[]])
+ t = mock("connection")
+ t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS)
+ Socket.stub!(:new).and_return(t)
+ @ohai._require_plugin("eucalyptus")
+ @ohai[:eucalyptus].should_not be_nil
+ @ohai[:eucalyptus]['instance_type'].should == "c1.medium"
+ @ohai[:eucalyptus]['ami_id'].should == "ami-5d2dc934"
+ @ohai[:eucalyptus]['security_groups'].should eql ['group1', 'group2']
end
end
@@ -76,8 +75,8 @@ describe Ohai::System, "plugin eucalyptus" do
it_should_behave_like "eucalyptus"
before(:each) do
- IO.stub(:select).and_return([[],[1],[]])
- @plugin[:network] = { "interfaces" => { "eth0" => { "addresses" => { "d0:0d:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
+ IO.stub!(:select).and_return([[],[1],[]])
+ @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "d0:0d:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
end
end
@@ -85,7 +84,7 @@ describe Ohai::System, "plugin eucalyptus" do
it_should_behave_like "!eucalyptus"
before(:each) do
- @plugin[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
+ @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } }
end
end
@@ -93,10 +92,10 @@ describe Ohai::System, "plugin eucalyptus" do
it_should_behave_like "eucalyptus"
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/eucalyptus.json').and_return('')
- File.stub(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(true)
- File.stub(:read).with('C:\chef\ohai\hints/eucalyptus.json').and_return('')
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/eucalyptus.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/eucalyptus.json').and_return('')
end
end
@@ -104,9 +103,8 @@ describe Ohai::System, "plugin eucalyptus" do
it_should_behave_like "!eucalyptus"
before(:each) do
- @plugin[:network] = {:interfaces => {}}
- File.stub(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false)
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false)
+ File.stub!(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false)
end
end
@@ -114,14 +112,10 @@ describe Ohai::System, "plugin eucalyptus" do
it_should_behave_like "!eucalyptus"
before(:each) do
- @plugin[:network] = {:interfaces => {}}
-
- File.stub(:exist?).with('/etc/chef/ohai/hints/eucalyptus.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/eucalyptus.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
- File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
- File.stub(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
end
end
diff --git a/spec/unit/plugins/freebsd/hostname_spec.rb b/spec/unit/plugins/freebsd/hostname_spec.rb
index c4b74f81..a11629f1 100644
--- a/spec/unit/plugins/freebsd/hostname_spec.rb
+++ b/spec/unit/plugins/freebsd/hostname_spec.rb
@@ -22,11 +22,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "FreeBSD hostname plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("freebsd/hostname.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "freebsd"
- @plugin.stub(:from).with("hostname -s").and_return("katie")
- @plugin.stub(:from).with("hostname -f").and_return("katie.bethell")
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "freebsd"
+ @ohai.stub!(:from).with("hostname -s").and_return("katie")
+ @ohai.stub!(:from).with("hostname -f").and_return("katie.bethell")
end
it_should_check_from("freebsd::hostname", "hostname", "hostname -s", "katie")
diff --git a/spec/unit/plugins/freebsd/kernel_spec.rb b/spec/unit/plugins/freebsd/kernel_spec.rb
index 8f660d5f..ea6423eb 100644
--- a/spec/unit/plugins/freebsd/kernel_spec.rb
+++ b/spec/unit/plugins/freebsd/kernel_spec.rb
@@ -21,19 +21,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "FreeBSD kernel plugin" do
before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("freebsd/kernel.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.stub(:from).with("uname -i").and_return("foo")
- @plugin.stub(:from_with_regex).with("sysctl kern.securelevel", /kern.securelevel: (.+)$/).and_return("kern.securelevel: 1")
- @plugin.stub(:popen4).with("/sbin/kldstat").and_yield(0, StringIO.new, StringIO.new, StringIO.new)
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:name] = "freebsd"
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.stub!(:from).with("uname -i").and_return("foo")
+ @ohai.stub!(:from_with_regex).with("sysctl kern.securelevel").and_return("kern.securelevel: 1")
+ @ohai[:kernel] = Mash.new
+ @ohai[:kernel][:name] = "freebsd"
end
it "should set the kernel_os to the kernel_name value" do
- @plugin.run
- @plugin[:kernel][:os].should == @plugin[:kernel][:name]
+ @ohai._require_plugin("freebsd::kernel")
+ @ohai[:kernel][:os].should == @ohai[:kernel][:name]
end
end
diff --git a/spec/unit/plugins/freebsd/platform_spec.rb b/spec/unit/plugins/freebsd/platform_spec.rb
index 80cbbb3d..c3ca8f54 100644
--- a/spec/unit/plugins/freebsd/platform_spec.rb
+++ b/spec/unit/plugins/freebsd/platform_spec.rb
@@ -22,20 +22,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "FreeBSD plugin platform" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("freebsd/platform.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.stub(:from).with("uname -s").and_return("FreeBSD")
- @plugin.stub(:from).with("uname -r").and_return("7.1")
- @plugin[:os] = "freebsd"
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.stub!(:from).with("uname -s").and_return("FreeBSD")
+ @ohai.stub!(:from).with("uname -r").and_return("7.1")
+ @ohai[:os] = "freebsd"
end
it "should set platform to lowercased lsb[:id]" do
- @plugin.run
- @plugin[:platform].should == "freebsd"
+ @ohai._require_plugin("freebsd::platform")
+ @ohai[:platform].should == "freebsd"
end
it "should set platform_version to lsb[:release]" do
- @plugin.run
- @plugin[:platform_version].should == "7.1"
+ @ohai._require_plugin("freebsd::platform")
+ @ohai[:platform_version].should == "7.1"
end
end
diff --git a/spec/unit/plugins/freebsd/virtualization_spec.rb b/spec/unit/plugins/freebsd/virtualization_spec.rb
index 53fb9ada..fdd5bf4f 100644
--- a/spec/unit/plugins/freebsd/virtualization_spec.rb
+++ b/spec/unit/plugins/freebsd/virtualization_spec.rb
@@ -22,30 +22,29 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "FreeBSD virtualization plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "freebsd/virtualization.rb"))
- @plugin.stub(:require_plugin)
- @plugin[:os] = "freebsd"
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "freebsd"
@stderr = StringIO.new
@stdin = StringIO.new
@status = 0
@pid = 42
- @plugin.stub(:popen4).with("/sbin/kldstat")
- @plugin.stub(:from)
+ @ohai.stub(:popen4).with("/sbin/kldstat")
+ @ohai.stub(:from)
end
context "jails" do
it "detects we are in a jail" do
- @plugin.stub(:from).with("sysctl -n security.jail.jailed").and_return("1")
- @plugin.run
- @plugin[:virtualization][:system].should == "jail"
- @plugin[:virtualization][:role].should == "guest"
+ @ohai.stub(:from).with("sysctl -n security.jail.jailed").and_return("1")
+ @ohai._require_plugin("freebsd::virtualization")
+ @ohai[:virtualization][:system].should == "jail"
+ @ohai[:virtualization][:role].should == "guest"
end
it "detects we are hosing jails" do
- @plugin.stub(:from).with("jls -n \| wc -l").and_return("1")
- @plugin.run
- @plugin[:virtualization][:system].should == "jail"
- @plugin[:virtualization][:role].should == "host"
+ @ohai.stub(:from).with("jls -n \| wc -l").and_return("1")
+ @ohai._require_plugin("freebsd::virtualization")
+ @ohai[:virtualization][:system].should == "jail"
+ @ohai[:virtualization][:role].should == "host"
end
end
@@ -57,13 +56,13 @@ Id Refs Address Size Name
1 40 0xffffffff80100000 d20428 kernel
7 3 0xffffffff81055000 41e88 vboxguest.ko
OUT
- @plugin.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
end
it "detects we are a guest" do
- @plugin.run
- @plugin[:virtualization][:system].should == "vbox"
- @plugin[:virtualization][:role].should == "guest"
+ @ohai._require_plugin("freebsd::virtualization")
+ @ohai[:virtualization][:system].should == "vbox"
+ @ohai[:virtualization][:role].should == "guest"
end
end
@@ -74,22 +73,22 @@ Id Refs Address Size Name
1 40 0xffffffff80100000 d20428 kernel
7 3 0xffffffff81055000 41e88 vboxdrv.ko
OUT
- @plugin.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
end
it "detects we are a host" do
- @plugin.run
- @plugin[:virtualization][:system].should == "vbox"
- @plugin[:virtualization][:role].should == "host"
+ @ohai._require_plugin("freebsd::virtualization")
+ @ohai[:virtualization][:system].should == "vbox"
+ @ohai[:virtualization][:role].should == "host"
end
end
context "when on a QEMU guest" do
it "detects we are a guest" do
- @plugin.stub(:from).with("sysctl -n hw.model").and_return('QEMU Virtual CPU version (cpu64-rhel6) ("GenuineIntel" 686-class)')
- @plugin.run
- @plugin[:virtualization][:system].should == "kvm"
- @plugin[:virtualization][:role].should == "guest"
+ @ohai.stub(:from).with("sysctl -n hw.model").and_return('QEMU Virtual CPU version (cpu64-rhel6) ("GenuineIntel" 686-class)')
+ @ohai._require_plugin("freebsd::virtualization")
+ @ohai[:virtualization][:system].should == "kvm"
+ @ohai[:virtualization][:role].should == "guest"
end
end
diff --git a/spec/unit/plugins/gce_spec.rb b/spec/unit/plugins/gce_spec.rb
index 64eb58ec..090d24ae 100644
--- a/spec/unit/plugins/gce_spec.rb
+++ b/spec/unit/plugins/gce_spec.rb
@@ -16,69 +16,68 @@
#
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-require 'open-uri'
+require 'ohai/mixin/gce_metadata'
describe Ohai::System, "plugin gce" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "gce.rb"))
- @plugin.stub(:require_plugin)
+ @ohai.stub!(:require_plugin).and_return(true)
end
shared_examples_for "!gce" do
it "should NOT attempt to fetch the gce metadata" do
- @plugin.should_not_receive(:http_client)
- @plugin.run
+ Ohai::Mixin::GCEMetadata.should_not_receive(:http_client)
+ @ohai._require_plugin("gce")
end
end
shared_examples_for "gce" do
before(:each) do
- @http_client = double("Net::HTTP client")
- @plugin.stub(:http_client).and_return(@http_client)
- IO.stub(:select).and_return([[],[1],[]])
- t = double("connection")
- t.stub(:connect_nonblock).and_raise(Errno::EINPROGRESS)
- Socket.stub(:new).and_return(t)
- Socket.stub(:pack_sockaddr_in).and_return(nil)
+ @http_client = mock("Net::HTTP client")
+ Ohai::Mixin::GCEMetadata.stub(:http_client).and_return(@http_client)
+ IO.stub!(:select).and_return([[],[1],[]])
+ t = mock("connection")
+ t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS)
+ Socket.stub!(:new).and_return(t)
+ Socket.stub!(:pack_sockaddr_in).and_return(nil)
end
it "should recursively fetch metadata" do
@http_client.should_receive(:get).
with("/0.1/meta-data/").
- and_return(double("Net::HTTPOK",
+ and_return(mock("Net::HTTPOK",
:body => "domain\nhostname\ndescription", :code=>"200"))
@http_client.should_receive(:get).
with("/0.1/meta-data/domain").
- and_return(double("Net::HTTPOK", :body => "test-domain", :code=>"200"))
+ and_return(mock("Net::HTTPOK", :body => "test-domain", :code=>"200"))
@http_client.should_receive(:get).
with("/0.1/meta-data/hostname").
- and_return(double("Net::HTTPOK", :body => "test-host", :code=>"200"))
+ and_return(mock("Net::HTTPOK", :body => "test-host", :code=>"200"))
@http_client.should_receive(:get).
with("/0.1/meta-data/description").
- and_return(double("Net::HTTPOK", :body => "test-description", :code=>"200"))
+ and_return(mock("Net::HTTPOK", :body => "test-description", :code=>"200"))
- @plugin.run
+ @ohai._require_plugin("gce")
- @plugin[:gce].should_not be_nil
- @plugin[:gce]['hostname'].should == "test-host"
- @plugin[:gce]['domain'].should == "test-domain"
- @plugin[:gce]['description'].should == "test-description"
+ @ohai[:gce].should_not be_nil
+ @ohai[:gce]['hostname'].should == "test-host"
+ @ohai[:gce]['domain'].should == "test-domain"
+ @ohai[:gce]['description'].should == "test-description"
end
it "should properly parse json metadata" do
@http_client.should_receive(:get).
with("/0.1/meta-data/").
- and_return(double("Net::HTTP Response", :body => "attached-disks\n", :code=>"200"))
+ and_return(mock("Net::HTTP Response", :body => "attached-disks\n", :code=>"200"))
@http_client.should_receive(:get).
with("/0.1/meta-data/attached-disks").
- and_return(double("Net::HTTP Response", :body => '{"disks":[{"deviceName":"boot",
+ and_return(mock("Net::HTTP Response", :body => '{"disks":[{"deviceName":"boot",
"index":0,"mode":"READ_WRITE","type":"EPHEMERAL"}]}', :code=>"200"))
- @plugin.run
+ @ohai._require_plugin("gce")
- @plugin[:gce].should_not be_nil
- @plugin[:gce]['attached_disks'].should eq({"disks"=>[{"deviceName"=>"boot",
+ @ohai[:gce].should_not be_nil
+ @ohai[:gce]['attached_disks'].should eq({"disks"=>[{"deviceName"=>"boot",
"index"=>0,"mode"=>"READ_WRITE",
"type"=>"EPHEMERAL"}]})
end
@@ -102,10 +101,10 @@ describe Ohai::System, "plugin gce" do
it_should_behave_like "gce"
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/gce.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/gce.json').and_return('')
- File.stub(:exist?).with('C:\chef\ohai\hints/gce.json').and_return(true)
- File.stub(:read).with('C:\chef\ohai\hints/gce.json').and_return('')
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/gce.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/gce.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/gce.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/gce.json').and_return('')
end
end
@@ -113,10 +112,8 @@ describe Ohai::System, "plugin gce" do
it_should_behave_like "!gce"
before(:each) do
- File.should_receive(:read).with('/sys/firmware/dmi/entries/1-0/raw').and_return('Test')
-
- File.stub(:exist?).with('/etc/chef/ohai/hints/gce.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/gce.json').and_return(false)
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/gce.json').and_return(false)
+ File.stub!(:exist?).with('C:\chef\ohai\hints/gce.json').and_return(false)
end
end
@@ -124,15 +121,10 @@ describe Ohai::System, "plugin gce" do
it_should_behave_like "!gce"
before(:each) do
- File.should_receive(:read).with('/sys/firmware/dmi/entries/1-0/raw').and_return('Test')
-
- File.stub(:exist?).with('/etc/chef/ohai/hints/gce.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/gce.json').and_return(false)
-
- File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
- File.stub(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
- File.stub(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
end
end
end
diff --git a/spec/unit/plugins/groovy_spec.rb b/spec/unit/plugins/groovy_spec.rb
index 02ff0e65..6c7f93fc 100644
--- a/spec/unit/plugins/groovy_spec.rb
+++ b/spec/unit/plugins/groovy_spec.rb
@@ -23,32 +23,31 @@ describe Ohai::System, "plugin groovy" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "groovy.rb"))
- @plugin[:languages] = Mash.new
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
@status = 0
@stdout = "Groovy Version: 1.6.3 JVM: 1.6.0_0\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([@status, @stdout, @stderr])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([@status, @stdout, @stderr])
end
it "should get the groovy version from running groovy -v" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([0, "Groovy Version: 1.6.3 JVM: 1.6.0_0\n", ""])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([0, "Groovy Version: 1.6.3 JVM: 1.6.0_0\n", ""])
+ @ohai._require_plugin("groovy")
end
it "should set languages[:groovy][:version]" do
- @plugin.run
- @plugin.languages[:groovy][:version].should eql("1.6.3")
+ @ohai._require_plugin("groovy")
+ @ohai.languages[:groovy][:version].should eql("1.6.3")
end
it "should not set the languages[:groovy] tree up if groovy command fails" do
@status = 1
@stdout = "Groovy Version: 1.6.3 JVM: 1.6.0_0\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([@status, @stdout, @stderr])
- @plugin.run
- @plugin.languages.should_not have_key(:groovy)
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([@status, @stdout, @stderr])
+ @ohai._require_plugin("groovy")
+ @ohai.languages.should_not have_key(:groovy)
end
end
diff --git a/spec/unit/plugins/hostname_spec.rb b/spec/unit/plugins/hostname_spec.rb
index 2098fead..1ac8dc53 100644
--- a/spec/unit/plugins/hostname_spec.rb
+++ b/spec/unit/plugins/hostname_spec.rb
@@ -21,20 +21,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "hostname plugin" do
before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "hostname.rb"))
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
end
it "should set the domain to everything after the first dot of the fqdn" do
- @plugin[:fqdn] = "katie.bethell"
- @plugin.run
- @plugin.domain.should == "bethell"
+ @ohai[:fqdn] = "katie.bethell"
+ @ohai._require_plugin("hostname")
+ @ohai.domain.should == "bethell"
end
it "should not set a domain if fqdn is not set" do
- @plugin.run
- @plugin.domain.should == nil
+ @ohai._require_plugin("hostname")
+ @ohai.domain.should == nil
end
end
diff --git a/spec/unit/plugins/java_spec.rb b/spec/unit/plugins/java_spec.rb
index 1f4a9913..45a6bdff 100644
--- a/spec/unit/plugins/java_spec.rb
+++ b/spec/unit/plugins/java_spec.rb
@@ -21,104 +21,102 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin java (Java5 Client VM)" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "java.rb"))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
@status = 0
@stdout = ""
@stderr = "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)"
- @plugin.stub(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
end
it "should run java -version" do
- @plugin.should_receive(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([0, "", "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)"])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([0, "", "java version \"1.5.0_16\"\nJava(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284)\nJava HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)"])
+ @ohai._require_plugin("java")
end
it "should set java[:version]" do
- @plugin.run
- @plugin.languages[:java][:version].should eql("1.5.0_16")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:version].should eql("1.5.0_16")
end
it "should set java[:runtime][:name] to runtime name" do
- @plugin.run
- @plugin.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment, Standard Edition")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment, Standard Edition")
end
it "should set java[:runtime][:build] to runtime build" do
- @plugin.run
- @plugin.languages[:java][:runtime][:build].should eql("1.5.0_16-b06-284")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:runtime][:build].should eql("1.5.0_16-b06-284")
end
it "should set java[:hotspot][:name] to hotspot name" do
- @plugin.run
- @plugin.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Client VM")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Client VM")
end
it "should set java[:hotspot][:build] to hotspot build" do
- @plugin.run
- @plugin.languages[:java][:hotspot][:build].should eql("1.5.0_16-133, mixed mode, sharing")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:hotspot][:build].should eql("1.5.0_16-133, mixed mode, sharing")
end
it "should not set the languages[:java] tree up if java command fails" do
@status = 1
@stdout = ""
@stderr = "Some error output here"
- @plugin.stub(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
- @plugin.run
- @plugin.languages.should_not have_key(:java)
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
+ @ohai._require_plugin("java")
+ @ohai.languages.should_not have_key(:java)
end
end
describe Ohai::System, "plugin java (Java6 Server VM)" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "java.rb"))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
@status = 0
@stdout = ""
@stderr = "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)"
- @plugin.stub(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
end
it "should run java -version" do
- @plugin.should_receive(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([0, "", "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)"])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([0, "", "java version \"1.6.0_22\"\nJava(TM) 2 Runtime Environment (build 1.6.0_22-b04)\nJava HotSpot(TM) Server VM (build 17.1-b03, mixed mode)"])
+ @ohai._require_plugin("java")
end
it "should set java[:version]" do
- @plugin.run
- @plugin.languages[:java][:version].should eql("1.6.0_22")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:version].should eql("1.6.0_22")
end
it "should set java[:runtime][:name] to runtime name" do
- @plugin.run
- @plugin.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment")
end
it "should set java[:runtime][:build] to runtime build" do
- @plugin.run
- @plugin.languages[:java][:runtime][:build].should eql("1.6.0_22-b04")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:runtime][:build].should eql("1.6.0_22-b04")
end
it "should set java[:hotspot][:name] to hotspot name" do
- @plugin.run
- @plugin.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Server VM")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Server VM")
end
it "should set java[:hotspot][:build] to hotspot build" do
- @plugin.run
- @plugin.languages[:java][:hotspot][:build].should eql("17.1-b03, mixed mode")
+ @ohai._require_plugin("java")
+ @ohai.languages[:java][:hotspot][:build].should eql("17.1-b03, mixed mode")
end
it "should not set the languages[:java] tree up if java command fails" do
@status = 1
@stdout = ""
@stderr = "Some error output here"
- @plugin.stub(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
- @plugin.run
- @plugin.languages.should_not have_key(:java)
+ @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr])
+ @ohai._require_plugin("java")
+ @ohai.languages.should_not have_key(:java)
end
end
diff --git a/spec/unit/plugins/kernel_spec.rb b/spec/unit/plugins/kernel_spec.rb
index fe85c5cc..3c982ae9 100644
--- a/spec/unit/plugins/kernel_spec.rb
+++ b/spec/unit/plugins/kernel_spec.rb
@@ -21,17 +21,15 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin kernel" do
before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "kernel.rb"))
-
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:languages] = Mash.new
- @plugin[:languages][:ruby] = Mash.new
- @plugin.stub(:from).with("uname -s").and_return("Darwin")
- @plugin.stub(:from).with("uname -r").and_return("9.5.0")
- @plugin.stub(:from).with("uname -v").and_return("Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386")
- @plugin.stub(:from).with("uname -m").and_return("i386")
- @plugin.stub(:from).with("uname -o").and_return("Linux")
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
+ @ohai[:languages][:ruby] = Mash.new
+ @ohai.stub!(:from).with("uname -s").and_return("Darwin")
+ @ohai.stub!(:from).with("uname -r").and_return("9.5.0")
+ @ohai.stub!(:from).with("uname -v").and_return("Darwin Kernel Version 9.5.0: Wed Sep 3 11:29:43 PDT 2008; root:xnu-1228.7.58~1\/RELEASE_I386")
+ @ohai.stub!(:from).with("uname -m").and_return("i386")
+ @ohai.stub!(:from).with("uname -o").and_return("Linux")
end
it_should_check_from_mash("kernel", "name", "uname -s", "Darwin")
diff --git a/spec/unit/plugins/linode_spec.rb b/spec/unit/plugins/linode_spec.rb
index 00c6bbf5..6f189971 100644
--- a/spec/unit/plugins/linode_spec.rb
+++ b/spec/unit/plugins/linode_spec.rb
@@ -23,9 +23,8 @@ describe Ohai::System, "plugin linode" do
before do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "linode.rb"))
- @plugin.stub(:require_plugin)
- @plugin[:network] = {
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:network] = {
"interfaces"=> {
"eth0"=> {
"addresses"=> {
@@ -50,32 +49,32 @@ describe Ohai::System, "plugin linode" do
shared_examples_for "!linode" do
it "does not create the linode mash" do
- @plugin.run
- @plugin[:linode].should be_nil
+ @ohai._require_plugin("linode")
+ @ohai[:linode].should be_nil
end
end
shared_examples_for "linode" do
it "creates a linode mash" do
- @plugin.run
- @plugin[:linode].should_not be_nil
+ @ohai._require_plugin("linode")
+ @ohai[:linode].should_not be_nil
end
it "has all required attributes" do
- @plugin.run
- @plugin[:linode][:public_ip].should_not be_nil
+ @ohai._require_plugin("linode")
+ @ohai[:linode][:public_ip].should_not be_nil
end
it "has correct values for all attributes" do
- @plugin.run
- @plugin[:linode][:public_ip].should == "1.2.3.4"
+ @ohai._require_plugin("linode")
+ @ohai[:linode][:public_ip].should == "1.2.3.4"
end
end
context "without linode kernel" do
before do
- @plugin[:kernel] = { "release" => "3.5.2-x86_64" }
+ @ohai[:kernel] = { "release" => "3.5.2-x86_64" }
end
it_should_behave_like "!linode"
@@ -83,7 +82,7 @@ describe Ohai::System, "plugin linode" do
context "with linode kernel" do
before do
- @plugin[:kernel] = { "release" => "3.5.2-x86_64-linode24" }
+ @ohai[:kernel] = { "release" => "3.5.2-x86_64-linode24" }
end
it_should_behave_like "linode"
@@ -92,7 +91,7 @@ describe Ohai::System, "plugin linode" do
# http://library.linode.com/networking/configuring-static-ip-interfaces
context "with configured private ip address as suggested by linode" do
before do
- @plugin[:network][:interfaces]["eth0:1"] = {
+ @ohai[:network][:interfaces]["eth0:1"] = {
"addresses" => {
"5.6.7.8"=> {
"broadcast"=> "10.176.191.255",
@@ -112,9 +111,9 @@ describe Ohai::System, "plugin linode" do
end
it "detects and sets the private ip" do
- @plugin.run
- @plugin[:linode][:private_ip].should_not be_nil
- @plugin[:linode][:private_ip].should == "5.6.7.8"
+ @ohai._require_plugin("linode")
+ @ohai[:linode][:private_ip].should_not be_nil
+ @ohai[:linode][:private_ip].should == "5.6.7.8"
end
end
@@ -122,10 +121,10 @@ describe Ohai::System, "plugin linode" do
describe "with linode cloud file" do
before do
- File.stub(:exist?).with(hint_path_nix).and_return(true)
- File.stub(:read).with(hint_path_nix).and_return('')
- File.stub(:exist?).with(hint_path_win).and_return(true)
- File.stub(:read).with(hint_path_win).and_return('')
+ File.stub!(:exist?).with(hint_path_nix).and_return(true)
+ File.stub!(:read).with(hint_path_nix).and_return('')
+ File.stub!(:exist?).with(hint_path_win).and_return(true)
+ File.stub!(:read).with(hint_path_win).and_return('')
end
it_should_behave_like "linode"
@@ -133,25 +132,22 @@ describe Ohai::System, "plugin linode" do
describe "without cloud file" do
before do
- File.stub(:exist?).with(hint_path_nix).and_return(false)
- File.stub(:exist?).with(hint_path_win).and_return(false)
+ File.stub!(:exist?).with(hint_path_nix).and_return(false)
+ File.stub!(:exist?).with(hint_path_win).and_return(false)
end
it_should_behave_like "!linode"
end
context "with ec2 cloud file" do
- let(:ec2_hint_path_nix) { '/etc/chef/ohai/hints/ec2.json' }
- let(:ec2_hint_path_win) { 'C:\chef\ohai\hints/ec2.json' }
+ let(:hint_path_nix) { '/etc/chef/ohai/hints/ec2.json' }
+ let(:hint_path_win) { 'C:\chef\ohai\hints/ec2.json' }
before do
- File.stub(:exist?).with(hint_path_nix).and_return(false)
- File.stub(:exist?).with(hint_path_win).and_return(false)
-
- File.stub(:exist?).with(ec2_hint_path_nix).and_return(true)
- File.stub(:read).with(ec2_hint_path_nix).and_return('')
- File.stub(:exist?).with(ec2_hint_path_win).and_return(true)
- File.stub(:read).with(ec2_hint_path_win).and_return('')
+ File.stub!(:exist?).with(hint_path_nix).and_return(true)
+ File.stub!(:read).with(hint_path_nix).and_return('')
+ File.stub!(:exist?).with(hint_path_win).and_return(true)
+ File.stub!(:read).with(hint_path_win).and_return('')
end
it_should_behave_like "!linode"
diff --git a/spec/unit/plugins/linux/cpu_spec.rb b/spec/unit/plugins/linux/cpu_spec.rb
index 74a6d60a..7a4f92e8 100644
--- a/spec/unit/plugins/linux/cpu_spec.rb
+++ b/spec/unit/plugins/linux/cpu_spec.rb
@@ -22,11 +22,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux cpu plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/cpu.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "linux"
- @double_file = double("/proc/cpuinfo")
- @double_file.stub(:each).
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "linux"
+ @mock_file = mock("/proc/cpuinfo")
+ @mock_file.stub!(:each).
and_yield("processor : 0").
and_yield("vendor_id : GenuineIntel").
and_yield("cpu family : 6").
@@ -46,84 +45,84 @@ describe Ohai::System, "Linux cpu plugin" do
and_yield("flags : fpu pse tsc msr mce cx8 sep mtrr pge cmov").
and_yield("bogomips : 2575.86").
and_yield("clflush size : 32")
- File.stub(:open).with("/proc/cpuinfo").and_return(@double_file)
+ File.stub!(:open).with("/proc/cpuinfo").and_return(@mock_file)
end
it "should set cpu[:total] to 1" do
- @plugin.run
- @plugin[:cpu][:total].should == 1
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu][:total].should == 1
end
it "should set cpu[:real] to 0" do
- @plugin.run
- @plugin[:cpu][:real].should == 0
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu][:real].should == 0
end
it "should have a cpu 0" do
- @plugin.run
- @plugin[:cpu].should have_key("0")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu].should have_key("0")
end
it "should have a vendor_id for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should have_key("vendor_id")
- @plugin[:cpu]["0"]["vendor_id"].should eql("GenuineIntel")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should have_key("vendor_id")
+ @ohai[:cpu]["0"]["vendor_id"].should eql("GenuineIntel")
end
it "should have a family for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should have_key("family")
- @plugin[:cpu]["0"]["family"].should eql("6")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should have_key("family")
+ @ohai[:cpu]["0"]["family"].should eql("6")
end
it "should have a model for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should have_key("model")
- @plugin[:cpu]["0"]["model"].should eql("23")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should have_key("model")
+ @ohai[:cpu]["0"]["model"].should eql("23")
end
it "should have a stepping for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should have_key("stepping")
- @plugin[:cpu]["0"]["stepping"].should eql("6")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should have_key("stepping")
+ @ohai[:cpu]["0"]["stepping"].should eql("6")
end
it "should not have a phyiscal_id for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should_not have_key("physical_id")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should_not have_key("physical_id")
end
it "should not have a core_id for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should_not have_key("core_id")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should_not have_key("core_id")
end
it "should not have a cores for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should_not have_key("cores")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should_not have_key("cores")
end
it "should have a model name for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should have_key("model_name")
- @plugin[:cpu]["0"]["model_name"].should eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should have_key("model_name")
+ @ohai[:cpu]["0"]["model_name"].should eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz")
end
it "should have a mhz for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should have_key("mhz")
- @plugin[:cpu]["0"]["mhz"].should eql("1968.770")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should have_key("mhz")
+ @ohai[:cpu]["0"]["mhz"].should eql("1968.770")
end
it "should have a cache_size for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should have_key("cache_size")
- @plugin[:cpu]["0"]["cache_size"].should eql("64 KB")
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should have_key("cache_size")
+ @ohai[:cpu]["0"]["cache_size"].should eql("64 KB")
end
it "should have flags for cpu 0" do
- @plugin.run
- @plugin[:cpu]["0"].should have_key("flags")
- @plugin[:cpu]["0"]["flags"].should == %w{fpu pse tsc msr mce cx8 sep mtrr pge cmov}
+ @ohai._require_plugin("linux::cpu")
+ @ohai[:cpu]["0"].should have_key("flags")
+ @ohai[:cpu]["0"]["flags"].should == %w{fpu pse tsc msr mce cx8 sep mtrr pge cmov}
end
-end
+end \ No newline at end of file
diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb
index e424174a..492a83de 100644
--- a/spec/unit/plugins/linux/filesystem_spec.rb
+++ b/spec/unit/plugins/linux/filesystem_spec.rb
@@ -21,29 +21,28 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux filesystem plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/filesystem.rb", PLUGIN_PATH))
- @plugin[:os] = "linux"
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.extend(SimpleFromFile)
-
- @plugin.stub(:popen4).with("df -P").and_return(false)
- @plugin.stub(:popen4).with("mount").and_return(false)
- @plugin.stub(:popen4).with("blkid -s TYPE").and_return(false)
- @plugin.stub(:popen4).with("blkid -s UUID").and_return(false)
- @plugin.stub(:popen4).with("blkid -s LABEL").and_return(false)
-
- File.stub(:exists?).with("/proc/mounts").and_return(false)
+ @ohai[:os] = "linux"
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.extend(SimpleFromFile)
+
+ @ohai.stub!(:popen4).with("df -P").and_return(false)
+ @ohai.stub!(:popen4).with("mount").and_return(false)
+ @ohai.stub!(:popen4).with("blkid -s TYPE").and_return(false)
+ @ohai.stub!(:popen4).with("blkid -s UUID").and_return(false)
+ @ohai.stub!(:popen4).with("blkid -s LABEL").and_return(false)
+
+ File.stub!(:exists?).with("/proc/mounts").and_return(false)
end
describe "when gathering filesystem usage data from df" do
before(:each) do
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
- @stdout = double("STDOUT")
+ @stderr = mock("STDERR")
+ @stdout = mock("STDOUT")
@status = 0
- @stdout.stub(:each).
+ @stdout.stub!(:each).
and_yield("Filesystem 1024-blocks Used Available Capacity Mounted on").
and_yield("/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /").
and_yield("tmpfs 2030944 0 2030944 0% /lib/init/rw").
@@ -58,50 +57,50 @@ describe Ohai::System, "Linux filesystem plugin" do
end
it "should run df -P" do
- @plugin.should_receive(:popen4).with("df -P").and_return(true)
- @plugin.run
+ @ohai.should_receive(:popen4).with("df -P").and_return(true)
+ @ohai._require_plugin("linux::filesystem")
end
it "should set kb_size to value from df -P" do
- @plugin.stub(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_size].should be == "97605057"
+ @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_size].should be == "97605057"
end
it "should set kb_used to value from df -P" do
- @plugin.stub(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_used].should be == "53563253"
+ @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_used].should be == "53563253"
end
it "should set kb_available to value from df -P" do
- @plugin.stub(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_available].should be == "44041805"
+ @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_available].should be == "44041805"
end
it "should set percent_used to value from df -P" do
- @plugin.stub(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:percent_used].should be == "56%"
+ @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:percent_used].should be == "56%"
end
it "should set mount to value from df -P" do
- @plugin.stub(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
+ @ohai.stub!(:popen4).with("df -P").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
end
end
describe "when gathering mounted filesystem data from mount" do
before(:each) do
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
- @stdout = double("STDOUT")
+ @stderr = mock("STDERR")
+ @stdout = mock("STDOUT")
@status = 0
- @stdout.stub(:each).
+ @stdout.stub!(:each).
and_yield("/dev/mapper/sys.vg-root.lv on / type ext4 (rw,noatime,errors=remount-ro)").
and_yield("tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)").
and_yield("proc on /proc type proc (rw,noexec,nosuid,nodev)").
@@ -120,38 +119,38 @@ describe Ohai::System, "Linux filesystem plugin" do
end
it "should run mount" do
- @plugin.should_receive(:popen4).with("mount").and_return(true)
- @plugin.run
+ @ohai.should_receive(:popen4).with("mount").and_return(true)
+ @ohai._require_plugin("linux::filesystem")
end
it "should set mount to value from mount" do
- @plugin.stub(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
+ @ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
end
it "should set fs_type to value from mount" do
- @plugin.stub(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
+ @ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
end
it "should set mount_options to an array of values from mount" do
- @plugin.stub(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime" ]
+ @ohai.stub!(:popen4).with("mount").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime" ]
end
end
describe "when gathering filesystem type data from blkid" do
before(:each) do
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
- @stdout = double("STDOUT")
+ @stderr = mock("STDERR")
+ @stdout = mock("STDOUT")
@status = 0
- @stdout.stub(:each).
+ @stdout.stub!(:each).
and_yield("/dev/sdb1: TYPE=\"linux_raid_member\" ").
and_yield("/dev/sdb2: TYPE=\"linux_raid_member\" ").
and_yield("/dev/sda1: TYPE=\"linux_raid_member\" ").
@@ -167,26 +166,26 @@ describe Ohai::System, "Linux filesystem plugin" do
end
it "should run blkid -s TYPE" do
- @plugin.should_receive(:popen4).with("blkid -s TYPE").and_return(true)
- @plugin.run
+ @ohai.should_receive(:popen4).with("blkid -s TYPE").and_return(true)
+ @ohai._require_plugin("linux::filesystem")
end
it "should set kb_size to value from blkid -s TYPE" do
- @plugin.stub(:popen4).with("blkid -s TYPE").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/md1"][:fs_type].should be == "LVM2_member"
+ @ohai.stub!(:popen4).with("blkid -s TYPE").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/md1"][:fs_type].should be == "LVM2_member"
end
end
describe "when gathering filesystem uuid data from blkid" do
before(:each) do
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
- @stdout = double("STDOUT")
+ @stderr = mock("STDERR")
+ @stdout = mock("STDOUT")
@status = 0
- @stdout.stub(:each).
+ @stdout.stub!(:each).
and_yield("/dev/sdb1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" ").
and_yield("/dev/sdb2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" ").
and_yield("/dev/sda1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" ").
@@ -202,26 +201,26 @@ describe Ohai::System, "Linux filesystem plugin" do
end
it "should run blkid -s UUID" do
- @plugin.should_receive(:popen4).with("blkid -s UUID").and_return(true)
- @plugin.run
+ @ohai.should_receive(:popen4).with("blkid -s UUID").and_return(true)
+ @ohai._require_plugin("linux::filesystem")
end
it "should set kb_size to value from blkid -s UUID" do
- @plugin.stub(:popen4).with("blkid -s UUID").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/sda2"][:uuid].should be == "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa"
+ @ohai.stub!(:popen4).with("blkid -s UUID").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/sda2"][:uuid].should be == "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa"
end
end
describe "when gathering filesystem label data from blkid" do
before(:each) do
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
- @stdout = double("STDOUT")
+ @stderr = mock("STDERR")
+ @stdout = mock("STDOUT")
@status = 0
- @stdout.stub(:each).
+ @stdout.stub!(:each).
and_yield("/dev/sda1: LABEL=\"fuego:0\" ").
and_yield("/dev/sda2: LABEL=\"fuego:1\" ").
and_yield("/dev/sdb1: LABEL=\"fuego:0\" ").
@@ -235,23 +234,23 @@ describe Ohai::System, "Linux filesystem plugin" do
end
it "should run blkid -s LABEL" do
- @plugin.should_receive(:popen4).with("blkid -s LABEL").and_return(true)
- @plugin.run
+ @ohai.should_receive(:popen4).with("blkid -s LABEL").and_return(true)
+ @ohai._require_plugin("linux::filesystem")
end
it "should set kb_size to value from blkid -s LABEL" do
- @plugin.stub(:popen4).with("blkid -s LABEL").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:filesystem]["/dev/md0"][:label].should be == "/boot"
+ @ohai.stub!(:popen4).with("blkid -s LABEL").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/md0"][:label].should be == "/boot"
end
end
describe "when gathering data from /proc/mounts" do
before(:each) do
- File.stub(:exists?).with("/proc/mounts").and_return(true)
- @double_file = double("/proc/mounts")
- @double_file.stub(:read_nonblock).and_return(@double_file)
- @double_file.stub(:each_line).
+ File.stub!(:exists?).with("/proc/mounts").and_return(true)
+ @mock_file = mock("/proc/mounts")
+ @mock_file.stub!(:read_nonblock).and_return(@mock_file)
+ @mock_file.stub!(:each_line).
and_yield("rootfs / rootfs rw 0 0").
and_yield("none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0").
and_yield("none /proc proc rw,nosuid,nodev,noexec,relatime 0 0").
@@ -268,22 +267,22 @@ describe Ohai::System, "Linux filesystem plugin" do
and_yield("/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0").
and_yield("fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0").
and_yield("binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0")
- File.stub(:open).with("/proc/mounts").and_return(@double_file)
+ File.stub!(:open).with("/proc/mounts").and_return(@mock_file)
end
it "should set mount to value from /proc/mounts" do
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special"
end
it "should set fs_type to value from /proc/mounts" do
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs"
end
it "should set mount_options to an array of values from /proc/mounts" do
- @plugin.run
- @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime", "attr2", "noquota" ]
+ @ohai._require_plugin("linux::filesystem")
+ @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime", "attr2", "noquota" ]
end
end
diff --git a/spec/unit/plugins/linux/hostname_spec.rb b/spec/unit/plugins/linux/hostname_spec.rb
index 70ec0af4..33ab866b 100644
--- a/spec/unit/plugins/linux/hostname_spec.rb
+++ b/spec/unit/plugins/linux/hostname_spec.rb
@@ -22,11 +22,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux hostname plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/hostname.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "linux"
- @plugin.stub(:from).with("hostname -s").and_return("katie")
- @plugin.stub(:from).with("hostname --fqdn").and_return("katie.bethell")
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "linux"
+ @ohai.stub!(:from).with("hostname -s").and_return("katie")
+ @ohai.stub!(:from).with("hostname --fqdn").and_return("katie.bethell")
end
it_should_check_from("linux::hostname", "hostname", "hostname -s", "katie")
@@ -35,16 +34,16 @@ describe Ohai::System, "Linux hostname plugin" do
describe "when domain name is unset" do
before(:each) do
- @plugin.should_receive(:from).with("hostname --fqdn").and_raise("Ohai::Exception::Exec")
+ @ohai.should_receive(:from).with("hostname --fqdn").and_raise("Ohai::Exception::Exec")
end
it "should not raise an error" do
- lambda { @plugin.run }.should_not raise_error
+ lambda { @ohai._require_plugin("linux::hostname") }.should_not raise_error
end
it "should not set fqdn" do
- @plugin.run
- @plugin.fqdn.should == nil
+ @ohai._require_plugin("linux::hostname")
+ @ohai.fqdn.should == nil
end
end
diff --git a/spec/unit/plugins/linux/kernel_spec.rb b/spec/unit/plugins/linux/kernel_spec.rb
index f33aea80..a0beb9e1 100644
--- a/spec/unit/plugins/linux/kernel_spec.rb
+++ b/spec/unit/plugins/linux/kernel_spec.rb
@@ -22,13 +22,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux kernel plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/kernel.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.stub(:from).with("uname -o").and_return("Linux")
- @plugin.should_receive(:popen4).with("env lsmod").at_least(1).times
- @plugin[:kernel] = {}
- @plugin.run
+ @ohai._require_plugin("kernel")
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.stub!(:from).with("uname -o").and_return("Linux")
end
it_should_check_from_deep_mash("linux::kernel", "kernel", "os", "uname -o", "Linux")
-end
+end \ No newline at end of file
diff --git a/spec/unit/plugins/linux/lsb_spec.rb b/spec/unit/plugins/linux/lsb_spec.rb
index 8f2646c7..53f95df0 100644
--- a/spec/unit/plugins/linux/lsb_spec.rb
+++ b/spec/unit/plugins/linux/lsb_spec.rb
@@ -24,128 +24,127 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux lsb plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/lsb.rb", PLUGIN_PATH))
- @plugin[:os] = "linux"
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.extend(SimpleFromFile)
+ @ohai[:os] = "linux"
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.extend(SimpleFromFile)
end
describe "on systems with /etc/lsb-release" do
before(:each) do
- @double_file = double("/etc/lsb-release")
- @double_file.stub(:each).
+ @mock_file = mock("/etc/lsb-release")
+ @mock_file.stub!(:each).
and_yield("DISTRIB_ID=Ubuntu").
and_yield("DISTRIB_RELEASE=8.04").
and_yield("DISTRIB_CODENAME=hardy").
and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"')
- File.stub(:open).with("/etc/lsb-release").and_return(@double_file)
- File.stub(:exists?).with("/etc/lsb-release").and_return(true)
+ File.stub!(:open).with("/etc/lsb-release").and_return(@mock_file)
+ File.stub!(:exists?).with("/etc/lsb-release").and_return(true)
end
it "should set lsb[:id]" do
- @plugin.run
- @plugin[:lsb][:id].should == "Ubuntu"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:id].should == "Ubuntu"
end
it "should set lsb[:release]" do
- @plugin.run
- @plugin[:lsb][:release].should == "8.04"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:release].should == "8.04"
end
it "should set lsb[:codename]" do
- @plugin.run
- @plugin[:lsb][:codename].should == "hardy"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:codename].should == "hardy"
end
it "should set lsb[:description]" do
- @plugin.run
- @plugin[:lsb][:description].should == "Ubuntu 8.04"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:description].should == "Ubuntu 8.04"
end
end
describe "on systems with /usr/bin/lsb_release" do
before(:each) do
- File.stub(:exists?).with("/etc/lsb-release").and_return(false)
- File.stub(:exists?).with("/usr/bin/lsb_release").and_return(true)
+ File.stub!(:exists?).with("/etc/lsb-release").and_return(false)
+ File.stub!(:exists?).with("/usr/bin/lsb_release").and_return(true)
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
- @stdout = double("STDOUT")
+ @stderr = mock("STDERR")
+ @stdout = mock("STDOUT")
@status = 0
end
describe "on Centos 5.4 correctly" do
before(:each) do
- @stdout.stub(:each).
+ @stdout.stub!(:each).
and_yield("LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch").
and_yield("Distributor ID: CentOS").
and_yield("Description: CentOS release 5.4 (Final)").
and_yield("Release: 5.4").
and_yield("Codename: Final")
- @plugin.stub(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
end
it "should set lsb[:id]" do
- @plugin.run
- @plugin[:lsb][:id].should == "CentOS"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:id].should == "CentOS"
end
it "should set lsb[:release]" do
- @plugin.run
- @plugin[:lsb][:release].should == "5.4"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:release].should == "5.4"
end
it "should set lsb[:codename]" do
- @plugin.run
- @plugin[:lsb][:codename].should == "Final"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:codename].should == "Final"
end
it "should set lsb[:description]" do
- @plugin.run
- @plugin[:lsb][:description].should == "CentOS release 5.4 (Final)"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:description].should == "CentOS release 5.4 (Final)"
end
end
describe "on Fedora 14 correctly" do
before(:each) do
- @stdout.stub(:each).
+ @stdout.stub!(:each).
and_yield("LSB Version: :core-4.0-ia32:core-4.0-noarch").
and_yield("Distributor ID: Fedora").
and_yield("Description: Fedora release 14 (Laughlin)").
and_yield("Release: 14").
and_yield("Codename: Laughlin")
- @plugin.stub(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
end
it "should set lsb[:id]" do
- @plugin.run
- @plugin[:lsb][:id].should == "Fedora"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:id].should == "Fedora"
end
it "should set lsb[:release]" do
- @plugin.run
- @plugin[:lsb][:release].should == "14"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:release].should == "14"
end
it "should set lsb[:codename]" do
- @plugin.run
- @plugin[:lsb][:codename].should == "Laughlin"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:codename].should == "Laughlin"
end
it "should set lsb[:description]" do
- @plugin.run
- @plugin[:lsb][:description].should == "Fedora release 14 (Laughlin)"
+ @ohai._require_plugin("linux::lsb")
+ @ohai[:lsb][:description].should == "Fedora release 14 (Laughlin)"
end
end
end
it "should not set any lsb values if /etc/lsb-release or /usr/bin/lsb_release do not exist " do
- File.stub(:exists?).with("/etc/lsb-release").and_return(false)
- File.stub(:exists?).with("/usr/bin/lsb_release").and_return(false)
- @plugin.attribute?(:lsb).should be(false)
+ File.stub!(:exists?).with("/etc/lsb-release").and_return(false)
+ File.stub!(:exists?).with("/usr/bin/lsb_release").and_return(false)
+ @ohai.attribute?(:lsb).should be(false)
end
end
diff --git a/spec/unit/plugins/linux/network_spec.rb b/spec/unit/plugins/linux/network_spec.rb
index a4a825ee..caf7ebf1 100644
--- a/spec/unit/plugins/linux/network_spec.rb
+++ b/spec/unit/plugins/linux/network_spec.rb
@@ -38,15 +38,15 @@ def prepare_data
end
def do_stubs
- @plugin.stub(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
- @plugin.stub(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
- @plugin.stub(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
- @plugin.stub(:popen4).with("ip -f inet neigh show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
- @plugin.stub(:popen4).with("ip -f inet6 neigh show").and_yield(nil, @stdin_ipneighbor_inet6, @ipneighbor_lines_inet6, nil)
- @plugin.stub(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
- @plugin.stub(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
- @plugin.stub(:popen4).with("ip -f inet route show").and_yield(nil, @stdin_ip_route, @ip_route_lines, nil)
- @plugin.stub(:popen4).with("ip -f inet6 route show").and_yield(nil, @stdin_ip_route_inet6, @ip_route_inet6_lines, nil)
+ @ohai.stub!(:from).with("route -n \| grep -m 1 ^0.0.0.0").and_return(@route_lines.last)
+ @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin_ifconfig, @ifconfig_lines, nil)
+ @ohai.stub!(:popen4).with("arp -an").and_yield(nil, @stdin_arp, @arp_lines, nil)
+ @ohai.stub!(:popen4).with("ip -f inet neigh show").and_yield(nil, @stdin_ipneighbor, @ipneighbor_lines, nil)
+ @ohai.stub!(:popen4).with("ip -f inet6 neigh show").and_yield(nil, @stdin_ipneighbor_inet6, @ipneighbor_lines_inet6, nil)
+ @ohai.stub!(:popen4).with("ip addr").and_yield(nil, @stdin_ipaddr, @ipaddr_lines, nil)
+ @ohai.stub!(:popen4).with("ip -d -s link").and_yield(nil, @stdin_iplink, @iplink_lines, nil)
+ @ohai.stub!(:popen4).with("ip -f inet route show").and_yield(nil, @stdin_ip_route, @ip_route_lines, nil)
+ @ohai.stub!(:popen4).with("ip -f inet6 route show").and_yield(nil, @stdin_ip_route_inet6, @ip_route_inet6_lines, nil)
end
describe Ohai::System, "Linux Network Plugin" do
@@ -278,197 +278,196 @@ IP_ROUTE_SCOPE
prepare_data
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/network.rb", PLUGIN_PATH))
+ @ohai.stub!(:require_plugin).and_return(true)
- @plugin.stub(:popen4).with("ifconfig -a")
- @plugin.stub(:popen4).with("arp -an")
+ @ohai.stub(:popen4).with("ifconfig -a")
+ @ohai.stub(:popen4).with("arp -an")
- Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(6).times
- @plugin.require_plugin("network")
- @plugin.stub(:require_plugin).and_return(true)
+ Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(3).times
+ @ohai._require_plugin("network")
end
["ifconfig","iproute2"].each do |network_method|
describe "gathering IP layer address info via #{network_method}" do
before do
- File.stub(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
+ File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
do_stubs
end
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "detects the interfaces" do
- @plugin.run
- @plugin['network']['interfaces'].keys.sort.should == ["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "foo:veth0@eth0", "lo", "tun0", "venet0", "venet0:0"]
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces'].keys.sort.should == ["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "foo:veth0@eth0", "lo", "tun0", "venet0", "venet0:0"]
end
it "detects the ipv4 addresses of the ethernet interface" do
- @plugin.run
- @plugin['network']['interfaces']['eth0']['addresses'].keys.should include('10.116.201.76')
- @plugin['network']['interfaces']['eth0']['addresses']['10.116.201.76']['netmask'].should == '255.255.255.0'
- @plugin['network']['interfaces']['eth0']['addresses']['10.116.201.76']['broadcast'].should == '10.116.201.255'
- @plugin['network']['interfaces']['eth0']['addresses']['10.116.201.76']['family'].should == 'inet'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('10.116.201.76')
+ @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['netmask'].should == '255.255.255.0'
+ @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['broadcast'].should == '10.116.201.255'
+ @ohai['network']['interfaces']['eth0']['addresses']['10.116.201.76']['family'].should == 'inet'
end
it "detects the ipv4 addresses of an ethernet subinterface" do
- @plugin.run
- @plugin['network']['interfaces']['eth0.11']['addresses'].keys.should include('192.168.0.16')
- @plugin['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['netmask'].should == '255.255.255.0'
- @plugin['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['broadcast'].should == '192.168.0.255'
- @plugin['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['family'].should == 'inet'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0.11']['addresses'].keys.should include('192.168.0.16')
+ @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['netmask'].should == '255.255.255.0'
+ @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['broadcast'].should == '192.168.0.255'
+ @ohai['network']['interfaces']['eth0.11']['addresses']['192.168.0.16']['family'].should == 'inet'
end
it "detects the ipv6 addresses of the ethernet interface" do
- @plugin.run
- @plugin['network']['interfaces']['eth0']['addresses'].keys.should include('fe80::1031:3dff:fe02:bea2')
- @plugin['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['scope'].should == 'Link'
- @plugin['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['prefixlen'].should == '64'
- @plugin['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['family'].should == 'inet6'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('fe80::1031:3dff:fe02:bea2')
+ @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['scope'].should == 'Link'
+ @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['prefixlen'].should == '64'
+ @ohai['network']['interfaces']['eth0']['addresses']['fe80::1031:3dff:fe02:bea2']['family'].should == 'inet6'
end
it "detects the ipv6 addresses of an ethernet subinterface" do
- @plugin.run
+ @ohai._require_plugin("linux::network")
%w[ 1111:2222:3333:4444::2 1111:2222:3333:4444::3 ].each do |addr|
- @plugin['network']['interfaces']['eth0.11']['addresses'].keys.should include(addr)
- @plugin['network']['interfaces']['eth0.11']['addresses'][addr]['scope'].should == 'Global'
- @plugin['network']['interfaces']['eth0.11']['addresses'][addr]['prefixlen'].should == '64'
- @plugin['network']['interfaces']['eth0.11']['addresses'][addr]['family'].should == 'inet6'
+ @ohai['network']['interfaces']['eth0.11']['addresses'].keys.should include(addr)
+ @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['scope'].should == 'Global'
+ @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['prefixlen'].should == '64'
+ @ohai['network']['interfaces']['eth0.11']['addresses'][addr]['family'].should == 'inet6'
end
end
it "detects the mac addresses of the ethernet interface" do
- @plugin.run
- @plugin['network']['interfaces']['eth0']['addresses'].keys.should include('12:31:3D:02:BE:A2')
- @plugin['network']['interfaces']['eth0']['addresses']['12:31:3D:02:BE:A2']['family'].should == 'lladdr'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0']['addresses'].keys.should include('12:31:3D:02:BE:A2')
+ @ohai['network']['interfaces']['eth0']['addresses']['12:31:3D:02:BE:A2']['family'].should == 'lladdr'
end
it "detects the encapsulation type of the ethernet interface" do
- @plugin.run
- @plugin['network']['interfaces']['eth0']['encapsulation'].should == 'Ethernet'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0']['encapsulation'].should == 'Ethernet'
end
it "detects the flags of the ethernet interface" do
- @plugin.run
+ @ohai._require_plugin("linux::network")
if network_method == "ifconfig"
- @plugin['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','MULTICAST','RUNNING','UP']
+ @ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','MULTICAST','RUNNING','UP']
else
- @plugin['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','LOWER_UP','MULTICAST','UP']
+ @ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','LOWER_UP','MULTICAST','UP']
end
end
it "detects the number of the ethernet interface" do
- @plugin.run
- @plugin['network']['interfaces']['eth0']['number'].should == "0"
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0']['number'].should == "0"
end
it "detects the mtu of the ethernet interface" do
- @plugin.run
- @plugin['network']['interfaces']['eth0']['mtu'].should == "1500"
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0']['mtu'].should == "1500"
end
it "detects the ipv4 addresses of the loopback interface" do
- @plugin.run
- @plugin['network']['interfaces']['lo']['addresses'].keys.should include('127.0.0.1')
- @plugin['network']['interfaces']['lo']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0'
- @plugin['network']['interfaces']['lo']['addresses']['127.0.0.1']['family'].should == 'inet'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['lo']['addresses'].keys.should include('127.0.0.1')
+ @ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['netmask'].should == '255.0.0.0'
+ @ohai['network']['interfaces']['lo']['addresses']['127.0.0.1']['family'].should == 'inet'
end
it "detects the ipv6 addresses of the loopback interface" do
- @plugin.run
- @plugin['network']['interfaces']['lo']['addresses'].keys.should include('::1')
- @plugin['network']['interfaces']['lo']['addresses']['::1']['scope'].should == 'Node'
- @plugin['network']['interfaces']['lo']['addresses']['::1']['prefixlen'].should == '128'
- @plugin['network']['interfaces']['lo']['addresses']['::1']['family'].should == 'inet6'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['lo']['addresses'].keys.should include('::1')
+ @ohai['network']['interfaces']['lo']['addresses']['::1']['scope'].should == 'Node'
+ @ohai['network']['interfaces']['lo']['addresses']['::1']['prefixlen'].should == '128'
+ @ohai['network']['interfaces']['lo']['addresses']['::1']['family'].should == 'inet6'
end
it "detects the encapsulation type of the loopback interface" do
- @plugin.run
- @plugin['network']['interfaces']['lo']['encapsulation'].should == 'Loopback'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['lo']['encapsulation'].should == 'Loopback'
end
it "detects the flags of the ethernet interface" do
- @plugin.run
+ @ohai._require_plugin("linux::network")
if network_method == "ifconfig"
- @plugin['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','RUNNING','UP']
+ @ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','RUNNING','UP']
else
- @plugin['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','LOWER_UP','UP']
+ @ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','LOWER_UP','UP']
end
end
it "detects the mtu of the loopback interface" do
- @plugin.run
- @plugin['network']['interfaces']['lo']['mtu'].should == "16436"
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['lo']['mtu'].should == "16436"
end
it "detects the arp entries" do
- @plugin.run
- @plugin['network']['interfaces']['eth0']['arp']['10.116.201.1'].should == 'fe:ff:ff:ff:ff:ff'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0']['arp']['10.116.201.1'].should == 'fe:ff:ff:ff:ff:ff'
end
end
describe "gathering interface counters via #{network_method}" do
before do
- File.stub(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
+ File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
do_stubs
- @plugin.run
+ @ohai._require_plugin("linux::network")
end
it "detects the ethernet counters" do
- @plugin['counters']['network']['interfaces']['eth0']['tx']['bytes'].should == "691785313"
- @plugin['counters']['network']['interfaces']['eth0']['tx']['packets'].should == "1919690"
- @plugin['counters']['network']['interfaces']['eth0']['tx']['collisions'].should == "0"
- @plugin['counters']['network']['interfaces']['eth0']['tx']['queuelen'].should == "1000"
- @plugin['counters']['network']['interfaces']['eth0']['tx']['errors'].should == "0"
- @plugin['counters']['network']['interfaces']['eth0']['tx']['carrier'].should == "0"
- @plugin['counters']['network']['interfaces']['eth0']['tx']['drop'].should == "0"
+ @ohai['counters']['network']['interfaces']['eth0']['tx']['bytes'].should == "691785313"
+ @ohai['counters']['network']['interfaces']['eth0']['tx']['packets'].should == "1919690"
+ @ohai['counters']['network']['interfaces']['eth0']['tx']['collisions'].should == "0"
+ @ohai['counters']['network']['interfaces']['eth0']['tx']['queuelen'].should == "1000"
+ @ohai['counters']['network']['interfaces']['eth0']['tx']['errors'].should == "0"
+ @ohai['counters']['network']['interfaces']['eth0']['tx']['carrier'].should == "0"
+ @ohai['counters']['network']['interfaces']['eth0']['tx']['drop'].should == "0"
- @plugin['counters']['network']['interfaces']['eth0']['rx']['bytes'].should == "1392844460"
- @plugin['counters']['network']['interfaces']['eth0']['rx']['packets'].should == "2659966"
- @plugin['counters']['network']['interfaces']['eth0']['rx']['errors'].should == "0"
- @plugin['counters']['network']['interfaces']['eth0']['rx']['overrun'].should == "0"
- @plugin['counters']['network']['interfaces']['eth0']['rx']['drop'].should == "0"
+ @ohai['counters']['network']['interfaces']['eth0']['rx']['bytes'].should == "1392844460"
+ @ohai['counters']['network']['interfaces']['eth0']['rx']['packets'].should == "2659966"
+ @ohai['counters']['network']['interfaces']['eth0']['rx']['errors'].should == "0"
+ @ohai['counters']['network']['interfaces']['eth0']['rx']['overrun'].should == "0"
+ @ohai['counters']['network']['interfaces']['eth0']['rx']['drop'].should == "0"
end
it "detects the loopback counters" do
- @plugin['counters']['network']['interfaces']['lo']['tx']['bytes'].should == "35224"
- @plugin['counters']['network']['interfaces']['lo']['tx']['packets'].should == "524"
- @plugin['counters']['network']['interfaces']['lo']['tx']['collisions'].should == "0"
- @plugin['counters']['network']['interfaces']['lo']['tx']['errors'].should == "0"
- @plugin['counters']['network']['interfaces']['lo']['tx']['carrier'].should == "0"
- @plugin['counters']['network']['interfaces']['lo']['tx']['drop'].should == "0"
-
- @plugin['counters']['network']['interfaces']['lo']['rx']['bytes'].should == "35224"
- @plugin['counters']['network']['interfaces']['lo']['rx']['packets'].should == "524"
- @plugin['counters']['network']['interfaces']['lo']['rx']['errors'].should == "0"
- @plugin['counters']['network']['interfaces']['lo']['rx']['overrun'].should == "0"
- @plugin['counters']['network']['interfaces']['lo']['rx']['drop'].should == "0"
+ @ohai['counters']['network']['interfaces']['lo']['tx']['bytes'].should == "35224"
+ @ohai['counters']['network']['interfaces']['lo']['tx']['packets'].should == "524"
+ @ohai['counters']['network']['interfaces']['lo']['tx']['collisions'].should == "0"
+ @ohai['counters']['network']['interfaces']['lo']['tx']['errors'].should == "0"
+ @ohai['counters']['network']['interfaces']['lo']['tx']['carrier'].should == "0"
+ @ohai['counters']['network']['interfaces']['lo']['tx']['drop'].should == "0"
+
+ @ohai['counters']['network']['interfaces']['lo']['rx']['bytes'].should == "35224"
+ @ohai['counters']['network']['interfaces']['lo']['rx']['packets'].should == "524"
+ @ohai['counters']['network']['interfaces']['lo']['rx']['errors'].should == "0"
+ @ohai['counters']['network']['interfaces']['lo']['rx']['overrun'].should == "0"
+ @ohai['counters']['network']['interfaces']['lo']['rx']['drop'].should == "0"
end
end
describe "setting the node's default IP address attribute with #{network_method}" do
before do
- File.stub(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
+ File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" )
do_stubs
end
describe "without a subinterface" do
before do
- @plugin.run
+ @ohai._require_plugin("linux::network")
end
it "finds the default interface by asking which iface has the default route" do
- @plugin['network']['default_interface'].should == 'eth0'
+ @ohai['network']['default_interface'].should == 'eth0'
end
it "finds the default gateway by asking which iface has the default route" do
- @plugin['network']['default_gateway'].should == '10.116.201.1'
+ @ohai['network']['default_gateway'].should == '10.116.201.1'
end
end
@@ -487,15 +486,15 @@ ROUTE_N
prepare_data
do_stubs
- @plugin.run
+ @ohai._require_plugin("linux::network")
end
it "finds the default interface by asking which iface has the default route" do
- @plugin['network']['default_interface'].should == 'eth0'
+ @ohai['network']['default_interface'].should == 'eth0'
end
it "finds the default interface by asking which iface has the default route" do
- @plugin['network']['default_gateway'].should == '0.0.0.0'
+ @ohai['network']['default_gateway'].should == '0.0.0.0'
end
end
@@ -515,15 +514,15 @@ ROUTE_N
prepare_data
do_stubs
- @plugin.run
+ @ohai._require_plugin("linux::network")
end
it "finds the default interface by asking which iface has the default route" do
- @plugin['network']["default_interface"].should == 'eth0.11'
+ @ohai['network']["default_interface"].should == 'eth0.11'
end
it "finds the default interface by asking which iface has the default route" do
- @plugin['network']["default_gateway"].should == '192.168.0.15'
+ @ohai['network']["default_gateway"].should == '192.168.0.15'
end
end
end
@@ -531,80 +530,80 @@ ROUTE_N
describe "for newer network features using iproute2 only" do
before do
- File.stub(:exist?).with("/sbin/ip").and_return(true) # iproute2 only
+ File.stub!(:exist?).with("/sbin/ip").and_return(true) # iproute2 only
do_stubs
end
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "finds the default inet6 interface if there's a inet6 default route" do
- @plugin.run
- @plugin['network']['default_inet6_interface'].should == 'eth0.11'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['default_inet6_interface'].should == 'eth0.11'
end
it "finds the default inet6 gateway if there's a inet6 default route" do
- @plugin.run
- @plugin['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::1'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::1'
end
it "finds inet6 neighbours" do
- @plugin.run
- @plugin['network']['interfaces']['eth0.11']['neighbour_inet6']['1111:2222:3333:4444::1'].should == '00:1c:0e:12:34:56'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0.11']['neighbour_inet6']['1111:2222:3333:4444::1'].should == '00:1c:0e:12:34:56'
end
it "detects the ipv4 addresses of an ethernet interface with a crazy name" do
- @plugin.run
- @plugin['network']['interfaces']['foo:veth0@eth0']['addresses'].keys.should include('192.168.212.2')
- @plugin['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['netmask'].should == '255.255.255.0'
- @plugin['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['family'].should == 'inet'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['foo:veth0@eth0']['addresses'].keys.should include('192.168.212.2')
+ @ohai['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['netmask'].should == '255.255.255.0'
+ @ohai['network']['interfaces']['foo:veth0@eth0']['addresses']['192.168.212.2']['family'].should == 'inet'
end
it "generates a fake interface for ip aliases for backward compatibility" do
- @plugin.run
- @plugin['network']['interfaces']['eth0:5']['addresses'].keys.should include('192.168.5.1')
- @plugin['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['netmask'].should == '255.255.255.0'
- @plugin['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['family'].should == 'inet'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0:5']['addresses'].keys.should include('192.168.5.1')
+ @ohai['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['netmask'].should == '255.255.255.0'
+ @ohai['network']['interfaces']['eth0:5']['addresses']['192.168.5.1']['family'].should == 'inet'
end
it "adds the vlan information of an interface" do
- @plugin.run
- @plugin['network']['interfaces']['eth0.11']['vlan']['id'].should == '11'
- @plugin['network']['interfaces']['eth0.11']['vlan']['flags'].should == [ 'REORDER_HDR' ]
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0.11']['vlan']['id'].should == '11'
+ @ohai['network']['interfaces']['eth0.11']['vlan']['flags'].should == [ 'REORDER_HDR' ]
end
it "adds the state of an interface" do
- @plugin.run
- @plugin['network']['interfaces']['eth0.11']['state'].should == 'up'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0.11']['state'].should == 'up'
end
describe "when dealing with routes" do
it "adds routes" do
- @plugin.run
- @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.116.201.0/24", :proto => "kernel", :family =>"inet" )
- @plugin['network']['interfaces']['foo:veth0@eth0']['routes'].should include Mash.new( :destination => "192.168.212.0/24", :proto => "kernel", :src => "192.168.212.2", :family =>"inet" )
- @plugin['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "fe80::/64", :metric => "256", :proto => "kernel", :family => "inet6" )
- @plugin['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "1111:2222:3333:4444::/64", :metric => "1024", :family => "inet6" )
- @plugin['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "default", :via => "1111:2222:3333:4444::1", :metric => "1024", :family => "inet6")
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "10.116.201.0/24", :proto => "kernel", :family =>"inet" )
+ @ohai['network']['interfaces']['foo:veth0@eth0']['routes'].should include Mash.new( :destination => "192.168.212.0/24", :proto => "kernel", :src => "192.168.212.2", :family =>"inet" )
+ @ohai['network']['interfaces']['eth0']['routes'].should include Mash.new( :destination => "fe80::/64", :metric => "256", :proto => "kernel", :family => "inet6" )
+ @ohai['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "1111:2222:3333:4444::/64", :metric => "1024", :family => "inet6" )
+ @ohai['network']['interfaces']['eth0.11']['routes'].should include Mash.new( :destination => "default", :via => "1111:2222:3333:4444::1", :metric => "1024", :family => "inet6")
end
describe "when there isn't a source field in route entries " do
it "doesn't set ipaddress" do
- @plugin.run
- @plugin['ipaddress'].should be nil
+ @ohai._require_plugin("linux::network")
+ @ohai['ipaddress'].should be nil
end
it "doesn't set macaddress" do
- @plugin.run
- @plugin['macaddress'].should be nil
+ @ohai._require_plugin("linux::network")
+ @ohai['macaddress'].should be nil
end
it "doesn't set ip6address" do
- @plugin.run
- @plugin['ip6address'].should be nil
+ @ohai._require_plugin("linux::network")
+ @ohai['ip6address'].should be nil
end
end
@@ -632,18 +631,18 @@ IP_ROUTE_SCOPE
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "sets ipaddress" do
- @plugin.run
- @plugin['ipaddress'].should == "10.116.201.76"
+ @ohai._require_plugin("linux::network")
+ @ohai['ipaddress'].should == "10.116.201.76"
end
it "sets ip6address" do
- @plugin.run
- @plugin['ip6address'].should == "1111:2222:3333:4444::3"
+ @ohai._require_plugin("linux::network")
+ @ohai['ip6address'].should == "1111:2222:3333:4444::3"
end
end
@@ -673,20 +672,20 @@ IP_ROUTE_SCOPE
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "sets default ipv4 interface and gateway" do
- @plugin.run
- @plugin['network']['default_interface'].should == 'eth0'
- @plugin['network']['default_gateway'].should == '10.116.201.254'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['default_interface'].should == 'eth0'
+ @ohai['network']['default_gateway'].should == '10.116.201.254'
end
it "sets default ipv6 interface and gateway" do
- @plugin.run
- @plugin['network']['default_inet6_interface'].should == 'eth0.11'
- @plugin['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::ffff'
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['default_inet6_interface'].should == 'eth0.11'
+ @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::ffff'
end
end
@@ -716,18 +715,18 @@ IP_ROUTE_SCOPE
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "sets ipaddress" do
- @plugin.run
- @plugin["ipaddress"].should == "10.116.201.74"
+ @ohai._require_plugin("linux::network")
+ @ohai["ipaddress"].should == "10.116.201.74"
end
it "sets ip6address" do
- @plugin.run
- @plugin["ip6address"].should == "1111:2222:3333:4444::2"
+ @ohai._require_plugin("linux::network")
+ @ohai["ip6address"].should == "1111:2222:3333:4444::2"
end
end
@@ -755,19 +754,19 @@ IP_ROUTE_SCOPE
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "sets ipaddress" do
- @plugin.run
- @plugin['ipaddress'].should == "10.116.201.76"
+ @ohai._require_plugin("linux::network")
+ @ohai['ipaddress'].should == "10.116.201.76"
end
describe "when about to set macaddress" do
it "sets macaddress" do
- @plugin.run
- @plugin['macaddress'].should == "12:31:3D:02:BE:A2"
+ @ohai._require_plugin("linux::network")
+ @ohai['macaddress'].should == "12:31:3D:02:BE:A2"
end
describe "when then interface has the NOARP flag" do
@@ -783,20 +782,20 @@ IP_ROUTE
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "doesn't set macaddress" do
- @plugin.run
- @plugin['macaddress'].should be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['macaddress'].should be_nil
end
end
end
it "sets ip6address" do
- @plugin.run
- @plugin['ip6address'].should == "1111:2222:3333:4444::3"
+ @ohai._require_plugin("linux::network")
+ @ohai['ip6address'].should == "1111:2222:3333:4444::3"
end
end
@@ -812,13 +811,13 @@ IP_ROUTE
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "doesn't set ipaddress" do
- @plugin.run
- @plugin['ipaddress'].should be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['ipaddress'].should be_nil
end
end
@@ -835,13 +834,13 @@ IP_ROUTE_SCOPE
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "doesn't set ip6address" do
- @plugin.run
- @plugin['ip6address'].should be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['ip6address'].should be_nil
end
end
@@ -868,18 +867,18 @@ IP_ROUTE
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "doesn't set ipaddress" do
- @plugin.run
- @plugin['ipaddress'].should be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['ipaddress'].should be_nil
end
it "doesn't set ip6address" do
- @plugin.run
- @plugin['ip6address'].should be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['ip6address'].should be_nil
end
end
@@ -906,25 +905,25 @@ IP_ROUTE
it "completes the run" do
Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/)
- @plugin.run
- @plugin['network'].should_not be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['network'].should_not be_nil
end
it "doesn't add bogus routes" do
- @plugin.run
- @plugin['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.116.201.0/26", :proto => "kernel", :family => "inet", :via => "10.116.201.39" )
- @plugin['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.118.19.0/26", :proto => "kernel", :family => "inet", :via => "10.118.19.39" )
- @plugin['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "1111:2222:3333:4444::/64", :family => "inet6", :metric => "1024" )
+ @ohai._require_plugin("linux::network")
+ @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.116.201.0/26", :proto => "kernel", :family => "inet", :via => "10.116.201.39" )
+ @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "10.118.19.0/26", :proto => "kernel", :family => "inet", :via => "10.118.19.39" )
+ @ohai['network']['interfaces']['eth0']['routes'].should_not include Mash.new( :destination => "1111:2222:3333:4444::/64", :family => "inet6", :metric => "1024" )
end
it "doesn't set ipaddress" do
- @plugin.run
- @plugin['ipaddress'].should be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['ipaddress'].should be_nil
end
it "doesn't set ip6address" do
- @plugin.run
- @plugin['ip6address'].should be_nil
+ @ohai._require_plugin("linux::network")
+ @ohai['ip6address'].should be_nil
end
end
@@ -940,8 +939,8 @@ IP_ROUTE
it "logs a message and skips previously unseen interfaces in 'ip route show'" do
Ohai::Log.should_receive(:debug).with("Skipping previously unseen interface from 'ip route show': virbr0").once
- Ohai::Log.stub(:debug) # Catches the 'Loading plugin network' type messages
- @plugin.run
+ Ohai::Log.should_receive(:debug).any_number_of_times # Catches the 'Loading plugin network' type messages
+ @ohai._require_plugin("linux::network")
end
end
end
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index 10b3dd73..189b3430 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -23,262 +23,269 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux plugin platform" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/platform.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.extend(SimpleFromFile)
- @plugin[:os] = "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)
- File.stub(:exists?).with("/etc/gentoo-release").and_return(false)
- File.stub(:exists?).with("/etc/SuSE-release").and_return(false)
- File.stub(:exists?).with("/etc/arch-release").and_return(false)
- File.stub(:exists?).with("/etc/system-release").and_return(false)
- File.stub(:exists?).with("/etc/slackware-version").and_return(false)
- File.stub(:exists?).with("/etc/enterprise-release").and_return(false)
- File.stub(:exists?).with("/etc/oracle-release").and_return(false)
- File.stub(:exists?).with("/usr/bin/raspi-config").and_return(false)
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.extend(SimpleFromFile)
+ @ohai[:os] = "linux"
+ @ohai[:lsb] = Mash.new
+ File.stub!(:exists?).with("/etc/debian_version").and_return(false)
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(false)
+ File.stub!(:exists?).with("/etc/gentoo-release").and_return(false)
+ File.stub!(:exists?).with("/etc/SuSE-release").and_return(false)
+ File.stub!(:exists?).with("/etc/arch-release").and_return(false)
+ File.stub!(:exists?).with("/etc/system-release").and_return(false)
+ File.stub!(:exists?).with("/etc/slackware-version").and_return(false)
+ File.stub!(:exists?).with("/etc/enterprise-release").and_return(false)
+ File.stub!(:exists?).with("/etc/oracle-release").and_return(false)
+ File.stub!(:exists?).with("/usr/bin/raspi-config").and_return(false)
end
it "should require the lsb plugin" do
- @plugin.should_receive(:require_plugin).with("linux::lsb").and_return(true)
- @plugin.run
+ @ohai.should_receive(:require_plugin).with("linux::lsb").and_return(true)
+ @ohai._require_plugin("linux::platform")
end
describe "on lsb compliant distributions" do
before(:each) do
- @plugin[:lsb][:id] = "Ubuntu"
- @plugin[:lsb][:release] = "8.04"
+ @ohai[:lsb][:id] = "Ubuntu"
+ @ohai[:lsb][:release] = "8.04"
end
it "should set platform to lowercased lsb[:id]" do
- @plugin.run
- @plugin[:platform].should == "ubuntu"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "ubuntu"
end
it "should set platform_version to lsb[:release]" do
- @plugin.run
- @plugin[:platform_version].should == "8.04"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform_version].should == "8.04"
end
it "should set platform to ubuntu and platform_family to debian [:lsb][:id] contains Ubuntu" do
- @plugin[:lsb][:id] = "Ubuntu"
- @plugin.run
- @plugin[:platform].should == "ubuntu"
- @plugin[:platform_family].should == "debian"
+ @ohai[:lsb][:id] = "Ubuntu"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "ubuntu"
+ @ohai[:platform_family].should == "debian"
end
it "should set platform to linuxmint and platform_family to debian [:lsb][:id] contains LinuxMint" do
- @plugin[:lsb][:id] = "LinuxMint"
- @plugin.run
- @plugin[:platform].should == "linuxmint"
- @plugin[:platform_family].should == "debian"
+ @ohai[:lsb][:id] = "LinuxMint"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "linuxmint"
+ @ohai[:platform_family].should == "debian"
end
it "should set platform to gcel and platform_family to debian [:lsb][:id] contains GCEL" do
- @plugin[:lsb][:id] = "GCEL"
- @plugin.run
- @plugin[:platform].should == "gcel"
- @plugin[:platform_family].should == "debian"
+ @ohai[:lsb][:id] = "GCEL"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "gcel"
+ @ohai[:platform_family].should == "debian"
end
it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do
- @plugin[:lsb][:id] = "Debian"
- @plugin.run
- @plugin[:platform].should == "debian"
- @plugin[:platform_family].should == "debian"
+ @ohai[:lsb][:id] = "Debian"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "debian"
+ @ohai[:platform_family].should == "debian"
end
it "should set platform to redhat and platform_family to rhel when [:lsb][:id] contains Redhat" do
- @plugin[:lsb][:id] = "RedHatEnterpriseServer"
- @plugin[:lsb][:release] = "5.7"
- @plugin.run
- @plugin[:platform].should == "redhat"
- @plugin[:platform_family].should == "rhel"
+ @ohai[:lsb][:id] = "RedHatEnterpriseServer"
+ @ohai[:lsb][:release] = "5.7"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "redhat"
+ @ohai[:platform_family].should == "rhel"
end
it "should set platform to amazon and platform_family to rhel when [:lsb][:id] contains Amazon" do
- @plugin[:lsb][:id] = "AmazonAMI"
- @plugin[:lsb][:release] = "2011.09"
- @plugin.run
- @plugin[:platform].should == "amazon"
- @plugin[:platform_family].should == "rhel"
+ @ohai[:lsb][:id] = "AmazonAMI"
+ @ohai[:lsb][:release] = "2011.09"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "amazon"
+ @ohai[:platform_family].should == "rhel"
end
it "should set platform to scientific when [:lsb][:id] contains ScientificSL" do
- @plugin[:lsb][:id] = "ScientificSL"
- @plugin[:lsb][:release] = "5.7"
- @plugin.run
- @plugin[:platform].should == "scientific"
+ @ohai[:lsb][:id] = "ScientificSL"
+ @ohai[:lsb][:release] = "5.7"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "scientific"
end
end
describe "on debian" do
before(:each) do
- @plugin.lsb = nil
+ @ohai.lsb = nil
File.should_receive(:exists?).with("/etc/debian_version").and_return(true)
end
+
+ it "should check for the existance of debian_version" do
+ @ohai._require_plugin("linux::platform")
+ end
it "should read the version from /etc/debian_version" do
File.should_receive(:read).with("/etc/debian_version").and_return("5.0")
- @plugin.run
- @plugin[:platform_version].should == "5.0"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform_version].should == "5.0"
end
it "should correctly strip any newlines" do
File.should_receive(:read).with("/etc/debian_version").and_return("5.0\n")
- @plugin.run
- @plugin[:platform_version].should == "5.0"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform_version].should == "5.0"
end
# Ubuntu has /etc/debian_version as well
it "should detect Ubuntu as itself rather than debian" do
- @plugin[:lsb][:id] = "Ubuntu"
- @plugin[:lsb][:release] = "8.04"
- @plugin.run
- @plugin[:platform].should == "ubuntu"
+ @ohai[:lsb][:id] = "Ubuntu"
+ @ohai[:lsb][:release] = "8.04"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "ubuntu"
end
# Raspbian is a debian clone
it "should detect Raspbian as itself with debian as the family" do
File.should_receive(:exists?).with("/usr/bin/raspi-config").and_return(true)
File.should_receive(:read).with("/etc/debian_version").and_return("wheezy/sid")
- @plugin.run
- @plugin[:platform].should == "raspbian"
- @plugin[:platform_family].should == "debian"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "raspbian"
+ @ohai[:platform_family].should == "debian"
end
end
describe "on slackware" do
before(:each) do
- @plugin.lsb = nil
+ @ohai.lsb = nil
File.should_receive(:exists?).with("/etc/slackware-version").and_return(true)
end
it "should set platform and platform_family to slackware" do
File.should_receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0")
- @plugin.run
- @plugin[:platform].should == "slackware"
- @plugin[:platform_family].should == "slackware"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "slackware"
+ @ohai[:platform_family].should == "slackware"
end
end
describe "on arch" do
before(:each) do
- @plugin.lsb = nil
+ @ohai.lsb = nil
File.should_receive(:exists?).with("/etc/arch-release").and_return(true)
end
it "should set platform to arch and platform_family to arch" do
- @plugin.run
- @plugin[:platform].should == "arch"
- @plugin[:platform_family].should == "arch"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "arch"
+ @ohai[:platform_family].should == "arch"
end
end
describe "on gentoo" do
before(:each) do
- @plugin.lsb = nil
+ @ohai.lsb = nil
File.should_receive(:exists?).with("/etc/gentoo-release").and_return(true)
end
it "should set platform and platform_family to gentoo" do
File.should_receive(:read).with("/etc/gentoo-release").and_return("Gentoo Base System release 1.20.1.1")
- @plugin.run
- @plugin[:platform].should == "gentoo"
- @plugin[:platform_family].should == "gentoo"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "gentoo"
+ @ohai[:platform_family].should == "gentoo"
end
end
describe "on redhat breeds" do
describe "with lsb_release results" do
it "should set the platform to redhat and platform_family to rhel even if the LSB name is something absurd but redhat like" do
- @plugin[:lsb][:id] = "RedHatEnterpriseServer"
- @plugin[:lsb][:release] = "6.1"
- @plugin.run
- @plugin[:platform].should == "redhat"
- @plugin[:platform_version].should == "6.1"
- @plugin[:platform_family].should == "rhel"
+ @ohai[:lsb][:id] = "RedHatEnterpriseServer"
+ @ohai[:lsb][:release] = "6.1"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "redhat"
+ @ohai[:platform_version].should == "6.1"
+ @ohai[:platform_family].should == "rhel"
end
it "should set the platform to centos and platform_family to rhel" do
- @plugin[:lsb][:id] = "CentOS"
- @plugin[:lsb][:release] = "5.4"
- @plugin.run
- @plugin[:platform].should == "centos"
- @plugin[:platform_version].should == "5.4"
- @plugin[:platform_family].should == "rhel"
+ @ohai[:lsb][:id] = "CentOS"
+ @ohai[:lsb][:release] = "5.4"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "centos"
+ @ohai[:platform_version].should == "5.4"
+ @ohai[:platform_family].should == "rhel"
end
it "should set the platform_family to rhel if the LSB name is oracle-ish" do
- @plugin[:lsb][:id] = "EnterpriseEnterpriseServer"
- @plugin.run
- @plugin[:platform_family].should == "rhel"
+ @ohai[:lsb][:id] = "EnterpriseEnterpriseServer"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform_family].should == "rhel"
end
it "should set the platform_family to rhel if the LSB name is amazon-ish" do
- @plugin[:lsb][:id] = "Amazon"
- @plugin.run
- @plugin[:platform_family].should == "rhel"
+ @ohai[:lsb][:id] = "Amazon"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform_family].should == "rhel"
end
it "should set the platform_family to fedora if the LSB name is fedora-ish" do
- @plugin[:lsb][:id] = "Fedora"
- @plugin.run
- @plugin[:platform_family].should == "fedora"
+ @ohai[:lsb][:id] = "Fedora"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform_family].should == "fedora"
end
it "should set the platform_family to redhat if the LSB name is scientific-ish" do
- @plugin[:lsb][:id] = "Scientific"
- @plugin.run
- @plugin[:platform_family].should == "rhel"
+ @ohai[:lsb][:id] = "Scientific"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform_family].should == "rhel"
end
end
describe "without lsb_release results" do
before(:each) do
- @plugin.lsb = nil
+ @ohai.lsb = nil
File.should_receive(:exists?).with("/etc/redhat-release").and_return(true)
end
+ it "should check for the existance of redhat-release" do
+ @ohai._require_plugin("linux::platform")
+ end
+
it "should read the platform as centos and version as 5.3" do
File.should_receive(:read).with("/etc/redhat-release").and_return("CentOS release 5.3")
- @plugin.run
- @plugin[:platform].should == "centos"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "centos"
end
it "may be that someone munged Red Hat to be RedHat" do
File.should_receive(:read).with("/etc/redhat-release").and_return("RedHat release 5.3")
- @plugin.run
- @plugin[:platform].should == "redhat"
- @plugin[:platform_version].should == "5.3"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "redhat"
+ @ohai[:platform_version].should == "5.3"
end
it "should read the platform as redhat and version as 5.3" do
File.should_receive(:read).with("/etc/redhat-release").and_return("Red Hat release 5.3")
- @plugin.run
- @plugin[:platform].should == "redhat"
- @plugin[:platform_version].should == "5.3"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "redhat"
+ @ohai[:platform_version].should == "5.3"
end
it "should read the platform as fedora and version as 13 (rawhide)" do
File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)")
- @plugin.run
- @plugin[:platform].should == "fedora"
- @plugin[:platform_version].should == "13 (rawhide)"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "fedora"
+ @ohai[:platform_version].should == "13 (rawhide)"
end
it "should read the platform as fedora and version as 10" do
File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 10")
- @plugin.run
- @plugin[:platform].should == "fedora"
- @plugin[:platform_version].should == "10"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "fedora"
+ @ohai[:platform_version].should == "10"
end
it "should read the platform as fedora and version as 13 using to_i" do
File.should_receive(:read).with("/etc/redhat-release").and_return("Fedora release 13 (Rawhide)")
- @plugin.run
- @plugin[:platform].should == "fedora"
- @plugin[:platform_version].to_i.should == 13
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "fedora"
+ @ohai[:platform_version].to_i.should == 13
end
end
end
@@ -286,83 +293,83 @@ describe Ohai::System, "Linux plugin platform" do
describe "on oracle enterprise linux" do
describe "with lsb_results" do
it "should read the platform as oracle and version as 5.7" do
- @plugin[:lsb][:id] = "EnterpriseEnterpriseServer"
- @plugin[:lsb][:release] = "5.7"
- File.stub(:exists?).with("/etc/redhat-release").and_return(true)
- File.stub(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
+ @ohai[:lsb][:id] = "EnterpriseEnterpriseServer"
+ @ohai[:lsb][:release] = "5.7"
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true)
File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
- @plugin.run
- @plugin[:platform].should == "oracle"
- @plugin[:platform_version].should == "5.7"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "oracle"
+ @ohai[:platform_version].should == "5.7"
end
it "should read the platform as oracle and version as 6.1" do
- @plugin[:lsb][:id] = "OracleServer"
- @plugin[:lsb][:release] = "6.1"
- File.stub(:exists?).with("/etc/redhat-release").and_return(true)
- File.stub(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
+ @ohai[:lsb][:id] = "OracleServer"
+ @ohai[:lsb][:release] = "6.1"
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
File.should_receive(:exists?).with("/etc/oracle-release").and_return(true)
File.should_receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
- @plugin.run
- @plugin[:platform].should == "oracle"
- @plugin[:platform_version].should == "6.1"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "oracle"
+ @ohai[:platform_version].should == "6.1"
end
end
describe "without lsb_results" do
before(:each) do
- @plugin.lsb = nil
+ @ohai.lsb = nil
end
it "should read the platform as oracle and version as 5" do
- File.stub(:exists?).with("/etc/redhat-release").and_return(true)
- File.stub(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
+ File.stub!(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true)
File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5 (Carthage)")
- @plugin.run
- @plugin[:platform].should == "oracle"
- @plugin[:platform_version].should == "5"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "oracle"
+ @ohai[:platform_version].should == "5"
end
it "should read the platform as oracle and version as 5.1" do
- File.stub(:exists?).with("/etc/redhat-release").and_return(true)
- File.stub(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
+ File.stub!(:read).with("/etc/redhat-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true)
File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.1 (Carthage)")
- @plugin.run
- @plugin[:platform].should == "oracle"
- @plugin[:platform_version].should == "5.1"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "oracle"
+ @ohai[:platform_version].should == "5.1"
end
it "should read the platform as oracle and version as 5.7" do
- File.stub(:exists?).with("/etc/redhat-release").and_return(true)
- File.stub(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 5.7 (Tikanga)")
File.should_receive(:exists?).with("/etc/enterprise-release").and_return(true)
File.should_receive(:read).with("/etc/enterprise-release").and_return("Enterprise Linux Enterprise Linux Server release 5.7 (Carthage)")
- @plugin.run
- @plugin[:platform].should == "oracle"
- @plugin[:platform_version].should == "5.7"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "oracle"
+ @ohai[:platform_version].should == "5.7"
end
it "should read the platform as oracle and version as 6.0" do
- File.stub(:exists?).with("/etc/redhat-release").and_return(true)
- File.stub(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)")
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.0 (Santiago)")
File.should_receive(:exists?).with("/etc/oracle-release").and_return(true)
File.should_receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.0")
- @plugin.run
- @plugin[:platform].should == "oracle"
- @plugin[:platform_version].should == "6.0"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "oracle"
+ @ohai[:platform_version].should == "6.0"
end
it "should read the platform as oracle and version as 6.1" do
- File.stub(:exists?).with("/etc/redhat-release").and_return(true)
- File.stub(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
+ File.stub!(:exists?).with("/etc/redhat-release").and_return(true)
+ File.stub!(:read).with("/etc/redhat-release").and_return("Red Hat Enterprise Linux Server release 6.1 (Santiago)")
File.should_receive(:exists?).with("/etc/oracle-release").and_return(true)
File.should_receive(:read).with("/etc/oracle-release").and_return("Oracle Linux Server release 6.1")
- @plugin.run
- @plugin[:platform].should == "oracle"
- @plugin[:platform_version].should == "6.1"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "oracle"
+ @ohai[:platform_version].should == "6.1"
end
end
end
@@ -374,69 +381,73 @@ describe Ohai::System, "Linux plugin platform" do
describe "with lsb_release results" do
before(:each) do
- @plugin[:lsb][:id] = "SUSE LINUX"
+ @ohai[:lsb][:id] = "SUSE LINUX"
end
it "should read the platform as suse" do
- @plugin[:lsb][:release] = "12.1"
- File.should_receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
- @plugin.run
- @plugin[:platform].should == "suse"
- @plugin[:platform_version].should == "12.1"
- @plugin[:platform_family].should == "suse"
+ @ohai[:lsb][:release] = "12.1"
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n")
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "suse"
+ @ohai[:platform_version].should == "12.1"
+ @ohai[:platform_family].should == "suse"
end
end
describe "without lsb_release results" do
before(:each) do
- @plugin.lsb = nil
+ @ohai.lsb = nil
+ end
+
+ it "should check for the existance of SuSE-release" do
+ @ohai._require_plugin("linux::platform")
end
it "should set platform and platform_family to suse and bogus verion to 10.0" do
File.should_receive(:read).with("/etc/SuSE-release").at_least(:once).and_return("VERSION = 10.0")
- @plugin.run
- @plugin[:platform].should == "suse"
- @plugin[:platform_family].should == "suse"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "suse"
+ @ohai[:platform_family].should == "suse"
end
it "should read the version as 10.1 for bogus SLES 10" do
File.should_receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 10 (i586)\nVERSION = 10\nPATCHLEVEL = 1\n")
- @plugin.run
- @plugin[:platform].should == "suse"
- @plugin[:platform_version].should == "10.1"
- @plugin[:platform_family].should == "suse"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "suse"
+ @ohai[:platform_version].should == "10.1"
+ @ohai[:platform_family].should == "suse"
end
it "should read the version as 11.2" do
File.should_receive(:read).with("/etc/SuSE-release").and_return("SUSE Linux Enterprise Server 11.2 (i586)\nVERSION = 11\nPATCHLEVEL = 2\n")
- @plugin.run
- @plugin[:platform].should == "suse"
- @plugin[:platform_version].should == "11.2"
- @plugin[:platform_family].should == "suse"
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "suse"
+ @ohai[:platform_version].should == "11.2"
+ @ohai[:platform_family].should == "suse"
end
it "[OHAI-272] should read the version as 11.3" do
- File.should_receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
- @plugin.run
- @plugin[:platform].should == "suse"
- @plugin[:platform_version].should == "11.3"
- @plugin[:platform_family].should == "suse"
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3")
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "suse"
+ @ohai[:platform_version].should == "11.3"
+ @ohai[:platform_family].should == "suse"
end
it "[OHAI-272] should read the version as 9.1" do
- File.should_receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
- @plugin.run
- @plugin[:platform].should == "suse"
- @plugin[:platform_version].should == "9.1"
- @plugin[:platform_family].should == "suse"
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1")
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "suse"
+ @ohai[:platform_version].should == "9.1"
+ @ohai[:platform_family].should == "suse"
end
it "[OHAI-272] should read the version as 11.4" do
- File.should_receive(:read).with("/etc/SuSE-release").exactly(1).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
- @plugin.run
- @plugin[:platform].should == "suse"
- @plugin[:platform_version].should == "11.4"
- @plugin[:platform_family].should == "suse"
+ File.should_receive(:read).with("/etc/SuSE-release").and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon")
+ @ohai._require_plugin("linux::platform")
+ @ohai[:platform].should == "suse"
+ @ohai[:platform_version].should == "11.4"
+ @ohai[:platform_family].should == "suse"
end
end
end
diff --git a/spec/unit/plugins/linux/uptime_spec.rb b/spec/unit/plugins/linux/uptime_spec.rb
index 2c8fbcde..e705a5ad 100644
--- a/spec/unit/plugins/linux/uptime_spec.rb
+++ b/spec/unit/plugins/linux/uptime_spec.rb
@@ -22,31 +22,40 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux plugin uptime" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/uptime.rb", PLUGIN_PATH))
- @plugin[:os] = "linux"
- @plugin.require_plugin("uptime")
- @double_file = double("/proc/uptime", { :gets => "18423 989" })
- File.stub(:open).with("/proc/uptime").and_return(@double_file)
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "linux"
+ @ohai._require_plugin("uptime")
+ @mock_file = mock("/proc/uptime", { :gets => "18423 989" })
+ File.stub!(:open).with("/proc/uptime").and_return(@mock_file)
end
+ it "should check /proc/uptime for the uptime and idletime" do
+ File.should_receive(:open).with("/proc/uptime").and_return(@mock_file)
+ @ohai._require_plugin("linux::uptime")
+ end
+
+ it "should split the value of /proc uptime" do
+ @mock_file.gets.should_receive(:split).with(" ").and_return(["18423", "989"])
+ @ohai._require_plugin("linux::uptime")
+ end
+
it "should set uptime_seconds to uptime" do
- @plugin.run
- @plugin[:uptime_seconds].should == 18423
+ @ohai._require_plugin("linux::uptime")
+ @ohai[:uptime_seconds].should == 18423
end
it "should set uptime to a human readable date" do
- @plugin.run
- @plugin[:uptime].should == "5 hours 07 minutes 03 seconds"
+ @ohai._require_plugin("linux::uptime")
+ @ohai[:uptime].should == "5 hours 07 minutes 03 seconds"
end
it "should set idletime_seconds to uptime" do
- @plugin.run
- @plugin[:idletime_seconds].should == 989
+ @ohai._require_plugin("linux::uptime")
+ @ohai[:idletime_seconds].should == 989
end
it "should set idletime to a human readable date" do
- @plugin.run
- @plugin[:idletime].should == "16 minutes 29 seconds"
+ @ohai._require_plugin("linux::uptime")
+ @ohai[:idletime].should == "16 minutes 29 seconds"
end
-end
+end \ No newline at end of file
diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb
index 800f37f9..17624531 100644
--- a/spec/unit/plugins/linux/virtualization_spec.rb
+++ b/spec/unit/plugins/linux/virtualization_spec.rb
@@ -21,117 +21,116 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Linux virtualization platform" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/virtualization.rb", PLUGIN_PATH))
- @plugin[:os] = "linux"
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.extend(SimpleFromFile)
+ @ohai[:os] = "linux"
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.extend(SimpleFromFile)
# default to all requested Files not existing
- File.stub(:exists?).with("/proc/xen").and_return(false)
- File.stub(:exists?).with("/proc/xen/capabilities").and_return(false)
- File.stub(:exists?).with("/proc/modules").and_return(false)
- File.stub(:exists?).with("/proc/cpuinfo").and_return(false)
- File.stub(:exists?).with("/usr/sbin/dmidecode").and_return(false)
- File.stub(:exists?).with("/proc/self/status").and_return(false)
- File.stub(:exists?).with("/proc/bc/0").and_return(false)
- File.stub(:exists?).with("/proc/vz").and_return(false)
+ File.stub!(:exists?).with("/proc/xen").and_return(false)
+ File.stub!(:exists?).with("/proc/xen/capabilities").and_return(false)
+ File.stub!(:exists?).with("/proc/modules").and_return(false)
+ File.stub!(:exists?).with("/proc/cpuinfo").and_return(false)
+ File.stub!(:exists?).with("/usr/sbin/dmidecode").and_return(false)
+ File.stub!(:exists?).with("/proc/self/status").and_return(false)
+ File.stub!(:exists?).with("/proc/bc/0").and_return(false)
+ File.stub!(:exists?).with("/proc/vz").and_return(false)
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)
File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(false)
- @plugin.run
- @plugin[:virtualization][:system].should == "xen"
- @plugin[:virtualization][:role].should == "guest"
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "xen"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should set xen host if /proc/xen/capabilities contains control_d " do
File.should_receive(:exists?).with("/proc/xen").and_return(true)
File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
- File.stub(:read).with("/proc/xen/capabilities").and_return("control_d")
- @plugin.run
- @plugin[:virtualization][:system].should == "xen"
- @plugin[:virtualization][:role].should == "host"
+ File.stub!(:read).with("/proc/xen/capabilities").and_return("control_d")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "xen"
+ @ohai[:virtualization][:role].should == "host"
end
it "should set xen guest if /proc/xen/capabilities exists but is empty" do
File.should_receive(:exists?).with("/proc/xen").and_return(true)
File.should_receive(:exists?).with("/proc/xen/capabilities").and_return(true)
- File.stub(:read).with("/proc/xen/capabilities").and_return("")
- @plugin.run
- @plugin[:virtualization][:system].should == "xen"
- @plugin[:virtualization][:role].should == "guest"
+ File.stub!(:read).with("/proc/xen/capabilities").and_return("")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "xen"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should not set virtualization if xen isn't there" do
File.should_receive(:exists?).at_least(:once).and_return(false)
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization].should == {}
end
end
describe "when we are checking for kvm" do
it "should set kvm host if /proc/modules contains kvm" do
File.should_receive(:exists?).with("/proc/modules").and_return(true)
- File.stub(:read).with("/proc/modules").and_return("kvm 165872 1 kvm_intel")
- @plugin.run
- @plugin[:virtualization][:system].should == "kvm"
- @plugin[:virtualization][:role].should == "host"
+ File.stub!(:read).with("/proc/modules").and_return("kvm 165872 1 kvm_intel")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "kvm"
+ @ohai[:virtualization][:role].should == "host"
end
it "should set kvm guest if /proc/cpuinfo contains QEMU Virtual CPU" do
File.should_receive(:exists?).with("/proc/cpuinfo").and_return(true)
- File.stub(:read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU")
- @plugin.run
- @plugin[:virtualization][:system].should == "kvm"
- @plugin[:virtualization][:role].should == "guest"
+ File.stub!(:read).with("/proc/cpuinfo").and_return("QEMU Virtual CPU")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "kvm"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should not set virtualization if kvm isn't there" do
File.should_receive(:exists?).at_least(:once).and_return(false)
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization].should == {}
end
end
describe "when we are checking for VirtualBox" do
it "should set vbox host if /proc/modules contains vboxdrv" do
File.should_receive(:exists?).with("/proc/modules").and_return(true)
- File.stub(:read).with("/proc/modules").and_return("vboxdrv 268268 3 vboxnetadp,vboxnetflt")
- @plugin.run
- @plugin[:virtualization][:system].should == "vbox"
- @plugin[:virtualization][:role].should == "host"
+ File.stub!(:read).with("/proc/modules").and_return("vboxdrv 268268 3 vboxnetadp,vboxnetflt")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "vbox"
+ @ohai[:virtualization][:role].should == "host"
end
it "should set vbox guest if /proc/modules contains vboxguest" do
File.should_receive(:exists?).with("/proc/modules").and_return(true)
- File.stub(:read).with("/proc/modules").and_return("vboxguest 177749 2 vboxsf")
- @plugin.run
- @plugin[:virtualization][:system].should == "vbox"
- @plugin[:virtualization][:role].should == "guest"
+ File.stub!(:read).with("/proc/modules").and_return("vboxguest 177749 2 vboxsf")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "vbox"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should not set virtualization if vbox isn't there" do
File.should_receive(:exists?).at_least(:once).and_return(false)
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization].should == {}
end
end
describe "when we are parsing dmidecode" do
before(:each) do
File.should_receive(:exists?).with("/usr/sbin/dmidecode").and_return(true)
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
- @stdout = double("STDOUT")
+ @stderr = mock("STDERR")
+ @stdout = mock("STDOUT")
@status = 0
end
it "should run dmidecode" do
- @plugin.should_receive(:popen4).with("dmidecode").and_return(true)
- @plugin.run
+ @ohai.should_receive(:popen4).with("dmidecode").and_return(true)
+ @ohai._require_plugin("linux::virtualization")
end
it "should set virtualpc guest if dmidecode detects Microsoft Virtual Machine" do
@@ -144,12 +143,12 @@ System Information
UUID: D29974A4-BE51-044C-BDC6-EFBC4B87A8E9
Wake-up Type: Power Switch
MSVPC
- @stdout.stub(:read).and_return(ms_vpc_dmidecode)
+ @stdout.stub!(:read).and_return(ms_vpc_dmidecode)
- @plugin.stub(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:virtualization][:system].should == "virtualpc"
- @plugin[:virtualization][:role].should == "guest"
+ @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "virtualpc"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should set vmware guest if dmidecode detects VMware Virtual Platform" do
@@ -164,86 +163,86 @@ System Information
SKU Number: Not Specified
Family: Not Specified
VMWARE
- @stdout.stub(:read).and_return(vmware_dmidecode)
- @plugin.stub(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:virtualization][:system].should == "vmware"
- @plugin[:virtualization][:role].should == "guest"
+ @stdout.stub!(:read).and_return(vmware_dmidecode)
+ @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "vmware"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should run dmidecode and not set virtualization if nothing is detected" do
- @plugin.should_receive(:popen4).with("dmidecode").and_return(true)
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai.should_receive(:popen4).with("dmidecode").and_return(true)
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization].should == {}
end
end
describe "when we are checking for Linux-VServer" do
it "should set Linux-VServer host if /proc/self/status contains s_context: 0" do
File.should_receive(:exists?).with("/proc/self/status").and_return(true)
- File.stub(:read).with("/proc/self/status").and_return("s_context: 0")
- @plugin.run
- @plugin[:virtualization][:system].should == "linux-vserver"
- @plugin[:virtualization][:role].should == "host"
+ File.stub!(:read).with("/proc/self/status").and_return("s_context: 0")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "linux-vserver"
+ @ohai[:virtualization][:role].should == "host"
end
it "should set Linux-VServer host if /proc/self/status contains VxID: 0" do
File.should_receive(:exists?).with("/proc/self/status").and_return(true)
- File.stub(:read).with("/proc/self/status").and_return("VxID: 0")
- @plugin.run
- @plugin[:virtualization][:system].should == "linux-vserver"
- @plugin[:virtualization][:role].should == "host"
+ File.stub!(:read).with("/proc/self/status").and_return("VxID: 0")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "linux-vserver"
+ @ohai[:virtualization][:role].should == "host"
end
it "should set Linux-VServer guest if /proc/self/status contains s_context > 0" do
File.should_receive(:exists?).with("/proc/self/status").and_return(true)
- File.stub(:read).with("/proc/self/status").and_return("s_context: 2")
- @plugin.run
- @plugin[:virtualization][:system].should == "linux-vserver"
- @plugin[:virtualization][:role].should == "guest"
+ File.stub!(:read).with("/proc/self/status").and_return("s_context: 2")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "linux-vserver"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should set Linux-VServer guest if /proc/self/status contains VxID > 0" do
File.should_receive(:exists?).with("/proc/self/status").and_return(true)
- File.stub(:read).with("/proc/self/status").and_return("VxID: 2")
- @plugin.run
- @plugin[:virtualization][:system].should == "linux-vserver"
- @plugin[:virtualization][:role].should == "guest"
+ File.stub!(:read).with("/proc/self/status").and_return("VxID: 2")
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "linux-vserver"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should not set virtualization if Linux-VServer isn't there" do
File.should_receive(:exists?).at_least(:once).and_return(false)
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization].should == {}
end
end
describe "when we are checking for openvz" do
it "should set openvz host if /proc/bc/0 exists" do
File.should_receive(:exists?).with("/proc/bc/0").and_return(true)
- @plugin.run
- @plugin[:virtualization][:system].should == "openvz"
- @plugin[:virtualization][:role].should == "host"
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "openvz"
+ @ohai[:virtualization][:role].should == "host"
end
it "should set openvz guest if /proc/bc/0 doesn't exist and /proc/vz exists" do
File.should_receive(:exists?).with("/proc/bc/0").and_return(false)
File.should_receive(:exists?).with("/proc/vz").and_return(true)
- @plugin.run
- @plugin[:virtualization][:system].should == "openvz"
- @plugin[:virtualization][:role].should == "guest"
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization][:system].should == "openvz"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should not set virtualization if openvz isn't there" do
File.should_receive(:exists?).with("/proc/bc/0").and_return(false)
File.should_receive(:exists?).with("/proc/vz").and_return(false)
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization].should == {}
end
end
it "should not set virtualization if no tests match" do
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai._require_plugin("linux::virtualization")
+ @ohai[:virtualization].should == {}
end
end
diff --git a/spec/unit/plugins/lua_spec.rb b/spec/unit/plugins/lua_spec.rb
index 3883aabf..7a48ca46 100644
--- a/spec/unit/plugins/lua_spec.rb
+++ b/spec/unit/plugins/lua_spec.rb
@@ -23,32 +23,31 @@ describe Ohai::System, "plugin lua" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "lua.rb"))
- @plugin[:languages] = Mash.new
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
@status = 0
@stdout = ""
@stderr = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n"
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([@status, @stdout, @stderr])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([@status, @stdout, @stderr])
end
it "should get the lua version from running lua -v" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([0, "", "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n"])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([0, "", "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n"])
+ @ohai._require_plugin("lua")
end
it "should set languages[:lua][:version]" do
- @plugin.run
- @plugin.languages[:lua][:version].should eql("5.1.2")
+ @ohai._require_plugin("lua")
+ @ohai.languages[:lua][:version].should eql("5.1.2")
end
it "should not set the languages[:lua] tree up if lua command fails" do
@status = 1
@stdout = ""
@stderr = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n"
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([@status, @stdout, @stderr])
- @plugin.run
- @plugin.languages.should_not have_key(:lua)
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([@status, @stdout, @stderr])
+ @ohai._require_plugin("lua")
+ @ohai.languages.should_not have_key(:lua)
end
end
diff --git a/spec/unit/plugins/mono_spec.rb b/spec/unit/plugins/mono_spec.rb
index a7543aec..fe79bdfc 100644
--- a/spec/unit/plugins/mono_spec.rb
+++ b/spec/unit/plugins/mono_spec.rb
@@ -23,32 +23,31 @@ describe Ohai::System, "plugin mono" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "mono.rb"))
- @plugin[:languages] = Mash.new
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
@status = 0
@stdout = "Mono JIT compiler version 1.2.6 (tarball)\nCopyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([@status, @stdout, @stderr])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([@status, @stdout, @stderr])
end
it "should get the mono version from running mono -V" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([0, "Mono JIT compiler version 1.2.6 (tarball)\nCopyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com\n", ""])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([0, "Mono JIT compiler version 1.2.6 (tarball)\nCopyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com\n", ""])
+ @ohai._require_plugin("mono")
end
it "should set languages[:mono][:version]" do
- @plugin.run
- @plugin.languages[:mono][:version].should eql("1.2.6")
+ @ohai._require_plugin("mono")
+ @ohai.languages[:mono][:version].should eql("1.2.6")
end
it "should not set the languages[:mono] tree up if mono command fails" do
@status = 1
@stdout = "Mono JIT compiler version 1.2.6 (tarball)\nCopyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([@status, @stdout, @stderr])
- @plugin.run
- @plugin.languages.should_not have_key(:mono)
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([@status, @stdout, @stderr])
+ @ohai._require_plugin("mono")
+ @ohai.languages.should_not have_key(:mono)
end
end
diff --git a/spec/unit/plugins/netbsd/hostname_spec.rb b/spec/unit/plugins/netbsd/hostname_spec.rb
index caaf864b..7606ab22 100644
--- a/spec/unit/plugins/netbsd/hostname_spec.rb
+++ b/spec/unit/plugins/netbsd/hostname_spec.rb
@@ -22,11 +22,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "NetBSD hostname plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("netbsd/hostname.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "netbsd"
- @plugin.stub(:from).with("hostname -s").and_return("katie")
- @plugin.stub(:from).with("hostname").and_return("katie.bethell")
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "netbsd"
+ @ohai.stub!(:from).with("hostname -s").and_return("katie")
+ @ohai.stub!(:from).with("hostname").and_return("katie.bethell")
end
it_should_check_from("netbsd::hostname", "hostname", "hostname -s", "katie")
diff --git a/spec/unit/plugins/netbsd/kernel_spec.rb b/spec/unit/plugins/netbsd/kernel_spec.rb
index 8ec33dc3..4e41ae76 100644
--- a/spec/unit/plugins/netbsd/kernel_spec.rb
+++ b/spec/unit/plugins/netbsd/kernel_spec.rb
@@ -22,17 +22,15 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "NetBSD kernel plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("netbsd/kernel.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.stub(:from).with("uname -i").and_return("foo")
- @plugin.stub(:from_with_regex).with("sysctl kern.securelevel", /kern.securelevel=(.+)$/).and_return("kern.securelevel: 1")
- @plugin.should_receive(:popen4).with("/usr/bin/modstat").and_yield(1, StringIO.new, StringIO.new, StringIO.new)
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:name] = "netbsd"
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.stub!(:from).with("uname -i").and_return("foo")
+ @ohai.stub!(:from_with_regex).with("sysctl kern.securelevel").and_return("kern.securelevel: 1")
+ @ohai[:kernel] = Mash.new
+ @ohai[:kernel][:name] = "netbsd"
end
it "should set the kernel_os to the kernel_name value" do
- @plugin.run
- @plugin[:kernel][:os].should == @plugin[:kernel][:name]
+ @ohai._require_plugin("netbsd::kernel")
+ @ohai[:kernel][:os].should == @ohai[:kernel][:name]
end
end
diff --git a/spec/unit/plugins/netbsd/platform_spec.rb b/spec/unit/plugins/netbsd/platform_spec.rb
index cf14cfb9..113b1e88 100644
--- a/spec/unit/plugins/netbsd/platform_spec.rb
+++ b/spec/unit/plugins/netbsd/platform_spec.rb
@@ -22,20 +22,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "NetBSD plugin platform" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("netbsd/platform.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.stub(:from).with("uname -s").and_return("NetBSD")
- @plugin.stub(:from).with("uname -r").and_return("4.5")
- @plugin[:os] = "netbsd"
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.stub!(:from).with("uname -s").and_return("NetBSD")
+ @ohai.stub!(:from).with("uname -r").and_return("4.5")
+ @ohai[:os] = "netbsd"
end
it "should set platform to lowercased lsb[:id]" do
- @plugin.run
- @plugin[:platform].should == "netbsd"
+ @ohai._require_plugin("netbsd::platform")
+ @ohai[:platform].should == "netbsd"
end
it "should set platform_version to lsb[:release]" do
- @plugin.run
- @plugin[:platform_version].should == "4.5"
+ @ohai._require_plugin("netbsd::platform")
+ @ohai[:platform_version].should == "4.5"
end
end
diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb
index a5fc58be..945bab81 100644
--- a/spec/unit/plugins/network_spec.rb
+++ b/spec/unit/plugins/network_spec.rb
@@ -20,11 +20,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
def it_does_not_fail
it "doesn't fail" do
- Ohai::Log.stub(:warn)
+ Ohai::Log.should_receive(:warn).any_number_of_times
Ohai::Log.should_not_receive(:debug).with(/^Plugin network threw exception/)
- @plugin.run
+ @ohai._require_plugin("network")
%w[ ipaddress, macaddress, ip6address ].each do |attribute|
- @plugin.should have_key(attribute)
+ @ohai.should have_key(attribute)
end
end
end
@@ -150,77 +150,83 @@ describe Ohai::System, "Network Plugin" do
describe "with linux" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "network.rb"))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin["network"] = basic_data["linux"]["network"]
+ @ohai.stub!(:require_plugin).twice.and_return(true)
+ @ohai["network"] = basic_data["linux"]["network"]
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
+ it "logs 2 debug messages" do
+ Ohai::Log.should_receive(:debug).with(/^Loading plugin network/).once
+ Ohai::Log.should_receive(:debug).with(/^\[inet\] Using default/).once
+ Ohai::Log.should_receive(:debug).with(/^\[inet6\] Using default/).once
+ @ohai._require_plugin("network")
+ end
+
it "detects {ip,ip6,mac}address" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.66.33"
- @plugin["macaddress"].should == "00:16:3E:2F:36:79"
- @plugin["ip6address"].should == "3ffe:1111:2222::33"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.66.33"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:79"
+ @ohai["ip6address"].should == "3ffe:1111:2222::33"
end
end
describe "default ipv4 and ipv6 gateway on different interfaces" do
describe "both interfaces have an ARP" do
before do
- @plugin["network"]["default_inet6_gateway"] = "3ffe:1111:3333::"
- @plugin["network"]["default_inet6_interface"] = "eth1"
+ @ohai["network"]["default_inet6_gateway"] = "3ffe:1111:3333::"
+ @ohai["network"]["default_inet6_interface"] = "eth1"
end
it_does_not_fail
it "detects {ip,ip6}address" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.66.33"
- @plugin["ip6address"].should == "3ffe:1111:3333::1"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.66.33"
+ @ohai["ip6address"].should == "3ffe:1111:3333::1"
end
it "set macaddress from the ipv4 setup" do
- @plugin.run
- @plugin["macaddress"].should == "00:16:3E:2F:36:79"
+ @ohai._require_plugin("network")
+ @ohai["macaddress"].should == "00:16:3E:2F:36:79"
end
it "informs about this setup" do
Ohai::Log.should_receive(:debug).with(/^ipaddress and ip6address are set from different interfaces/)
- Ohai::Log.stub(:debug)
- @plugin.run
+ Ohai::Log.should_receive(:debug).any_number_of_times
+ @ohai._require_plugin("network")
end
end
describe "ipv4 interface has no ARP" do
before do
- @plugin["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,kv| kv["family"] == "lladdr" }
+ @ohai["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,kv| kv["family"] == "lladdr" }
# not really checked by this pluging
- @plugin["network"]["interfaces"]["eth0"]["flags"] << "NOARP"
- @plugin["network"]["default_inet6_gateway"] = "3ffe:1111:3333::"
- @plugin["network"]["default_inet6_interface"] = "eth1"
+ @ohai["network"]["interfaces"]["eth0"]["flags"] << "NOARP"
+ @ohai["network"]["default_inet6_gateway"] = "3ffe:1111:3333::"
+ @ohai["network"]["default_inet6_interface"] = "eth1"
end
it_does_not_fail
it "detects {ip,ip6}address" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.66.33"
- @plugin["ip6address"].should == "3ffe:1111:3333::1"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.66.33"
+ @ohai["ip6address"].should == "3ffe:1111:3333::1"
end
it "doesn't set macaddress, ipv4 setup is valid and has precedence over ipv6" do
Ohai::Log.should_not_receive(:warn).with(/^unable to detect macaddress/)
- @plugin.run
- @plugin["macaddress"].should be_nil
+ @ohai._require_plugin("network")
+ @ohai["macaddress"].should be_nil
end
it "informs about this setup" do
Ohai::Log.should_receive(:debug).with(/^ipaddress and ip6address are set from different interfaces/)
- Ohai::Log.stub(:debug)
- @plugin.run
+ Ohai::Log.should_receive(:debug).any_number_of_times
+ @ohai._require_plugin("network")
end
end
end
@@ -228,56 +234,61 @@ describe Ohai::System, "Network Plugin" do
describe "conflicting results from the linux::network plugin" do
describe "default interface doesn't match the default_gateway" do
before do
- @plugin["network"]["default_interface"] = "eth1"
- @plugin["network"]["default_inet6_interface"] = "eth1"
+ @ohai["network"]["default_interface"] = "eth1"
+ @ohai["network"]["default_inet6_interface"] = "eth1"
end
it_does_not_fail
it "picks {ip,ip6,mac}address" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ipaddress"].should == "192.168.99.11"
- @plugin["macaddress"].should == "00:16:3E:2F:36:80"
- @plugin["ip6address"].should == "3ffe:1111:3333::1"
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.99.11"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:80"
+ @ohai["ip6address"].should == "3ffe:1111:3333::1"
end
it "warns about this conflict" do
Ohai::Log.should_receive(:warn).with(/^\[inet\] no ipaddress\/mask on eth1/).once
Ohai::Log.should_receive(:warn).with(/^\[inet6\] no ipaddress\/mask on eth1/).once
- @plugin.run
+ @ohai._require_plugin("network")
end
end
describe "there's a default gateway, none of the configured ip/mask theorically allows to reach it" do
before do
- @plugin["network"]["default_gateway"] = "172.16.12.42"
- @plugin["network"]["default_inet6_gateway"] = "3ffe:12:42::7070"
+ @ohai["network"]["default_gateway"] = "172.16.12.42"
+ @ohai["network"]["default_inet6_gateway"] = "3ffe:12:42::7070"
end
it "picks {ip,ip6,mac}address" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ipaddress"].should == "192.168.66.33"
- @plugin["macaddress"].should == "00:16:3E:2F:36:79"
- @plugin["ip6address"].should == "3ffe:1111:2222::33"
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.66.33"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:79"
+ @ohai["ip6address"].should == "3ffe:1111:2222::33"
end
+ it "warns about this conflict" do
+ Ohai::Log.should_receive(:warn).with(/^\[inet\] no ipaddress\/mask on eth0/).once
+ Ohai::Log.should_receive(:warn).with(/^\[inet6\] no ipaddress\/mask on eth0/).once
+ @ohai._require_plugin("network")
+ end
end
describe "no ip address for the given default interface/gateway" do
before do
- @plugin["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,v| %w[inet inet6].include? v["family"]}
+ @ohai["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,v| %w[inet inet6].include? v["family"]}
end
it_does_not_fail
it "doesn't detect {ip,ip6,mac}address" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ipaddress"].should be_nil
- @plugin["macaddress"].should be_nil
- @plugin["ip6address"].should be_nil
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should be_nil
+ @ohai["macaddress"].should be_nil
+ @ohai["ip6address"].should be_nil
end
it "warns about this conflict" do
@@ -286,17 +297,17 @@ describe Ohai::System, "Network Plugin" do
Ohai::Log.should_receive(:warn).with(/^\[inet\] no ip address on eth0/).once
Ohai::Log.should_receive(:warn).with(/^unable to detect ip6address/).once
Ohai::Log.should_receive(:warn).with(/^\[inet6\] no ip address on eth0/).once
- @plugin.run
+ @ohai._require_plugin("network")
end
end
describe "no ip at all" do
before do
- @plugin["network"]["default_gateway"] = nil
- @plugin["network"]["default_interface"] = nil
- @plugin["network"]["default_inet6_gateway"] = nil
- @plugin["network"]["default_inet6_interface"] = nil
- @plugin["network"]["interfaces"].each do |i,iv|
+ @ohai["network"]["default_gateway"] = nil
+ @ohai["network"]["default_interface"] = nil
+ @ohai["network"]["default_inet6_gateway"] = nil
+ @ohai["network"]["default_inet6_interface"] = nil
+ @ohai["network"]["interfaces"].each do |i,iv|
iv["addresses"].delete_if{|k,kv| %w[inet inet6].include? kv["family"]}
end
end
@@ -304,18 +315,18 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
it "doesn't detect {ip,ip6,mac}address" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ipaddress"].should be_nil
- @plugin["macaddress"].should be_nil
- @plugin["ip6address"].should be_nil
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should be_nil
+ @ohai["macaddress"].should be_nil
+ @ohai["ip6address"].should be_nil
end
it "should warn about it" do
Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
Ohai::Log.should_receive(:warn).with(/^unable to detect ip6address/).once
- @plugin.run
+ @ohai._require_plugin("network")
end
end
end
@@ -323,7 +334,7 @@ describe Ohai::System, "Network Plugin" do
describe "several ipaddresses matching the default route" do
describe "bigger prefix not set on the default interface" do
before do
- @plugin["network"]["interfaces"]["eth2"] = {
+ @ohai["network"]["interfaces"]["eth2"] = {
"flags" => ["BROADCAST", "MULTICAST", "UP"],
"number" => "2",
"addresses" => {
@@ -352,23 +363,23 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
it "sets {ip,ip6,mac}address correctly" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.66.33"
- @plugin["macaddress"].should == "00:16:3E:2F:36:79"
- @plugin["ip6address"].should == "3ffe:1111:2222::33"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.66.33"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:79"
+ @ohai["ip6address"].should == "3ffe:1111:2222::33"
end
end
describe "bigger prefix set on the default interface" do
before do
- @plugin["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.99"] = {
+ @ohai["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.99"] = {
"scope" => "Global",
"netmask" => "255.255.255.128",
"broadcast" => "192.168.66.127",
"prefixlen" => "25",
"family" => "inet"
}
- @plugin["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222:0:4444::1"] = {
+ @ohai["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222:0:4444::1"] = {
"prefixlen" => "64",
"family" => "inet6",
"scope" => "Global"
@@ -378,16 +389,16 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
it "sets {ip,ip6,mac}address correctly" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.66.99"
- @plugin["macaddress"].should == "00:16:3E:2F:36:79"
- @plugin["ip6address"].should == "3ffe:1111:2222:0:4444::1"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.66.99"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:79"
+ @ohai["ip6address"].should == "3ffe:1111:2222:0:4444::1"
end
end
describe "smallest ip not set on the default_interface" do
before do
- @plugin["network"]["interfaces"]["eth2"] = {
+ @ohai["network"]["interfaces"]["eth2"] = {
"flags" => ["BROADCAST", "MULTICAST", "UP"],
"number" => "2",
"addresses" => {
@@ -416,23 +427,23 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
it "sets {ip,ip6,mac}address correctly" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.66.33"
- @plugin["macaddress"].should == "00:16:3E:2F:36:79"
- @plugin["ip6address"].should == "3ffe:1111:2222::33"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.66.33"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:79"
+ @ohai["ip6address"].should == "3ffe:1111:2222::33"
end
end
describe "smallest ip set on the default_interface" do
before do
- @plugin["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.32"] = {
+ @ohai["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.32"] = {
"scope" => "Global",
"netmask" => "255.255.255.0",
"broadcast" => "192.168.66.255",
"prefixlen" => "24",
"family" => "inet"
}
- @plugin["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222::32"] = {
+ @ohai["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222::32"] = {
"prefixlen" => "48",
"family" => "inet6",
"scope" => "Global"
@@ -442,10 +453,10 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
it "sets {ip,ip6,mac}address correctly" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.66.32"
- @plugin["macaddress"].should == "00:16:3E:2F:36:79"
- @plugin["ip6address"].should == "3ffe:1111:2222::32"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.66.32"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:79"
+ @ohai["ip6address"].should == "3ffe:1111:2222::32"
end
end
end
@@ -453,12 +464,12 @@ describe Ohai::System, "Network Plugin" do
describe "no default route" do
describe "first interface is not the best choice" do
before do
- @plugin["network"]["default_gateway"] = nil
- @plugin["network"]["default_interface"] = nil
- @plugin["network"]["default_inet6_gateway"] = nil
- @plugin["network"]["default_inet6_interface"] = nil
+ @ohai["network"]["default_gateway"] = nil
+ @ohai["network"]["default_interface"] = nil
+ @ohai["network"]["default_inet6_gateway"] = nil
+ @ohai["network"]["default_inet6_interface"] = nil
# removing inet* addresses from eth0, to complicate things a bit
- @plugin["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,v| %w[inet inet6].include? v["family"]}
+ @ohai["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,v| %w[inet inet6].include? v["family"]}
end
it_does_not_fail
@@ -466,22 +477,22 @@ describe Ohai::System, "Network Plugin" do
it "picks {ip,mac,ip6}address from the first interface" do
Ohai::Log.should_receive(:debug).with(/^\[inet\] no default interface/).once
Ohai::Log.should_receive(:debug).with(/^\[inet6\] no default interface/).once
- Ohai::Log.stub(:debug)
- @plugin.run
- @plugin["ipaddress"].should == "192.168.99.11"
- @plugin["macaddress"].should == "00:16:3E:2F:36:80"
- @plugin["ip6address"].should == "3ffe:1111:3333::1"
+ Ohai::Log.should_receive(:debug).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.99.11"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:80"
+ @ohai["ip6address"].should == "3ffe:1111:3333::1"
end
end
describe "can choose from addresses with different scopes" do
before do
- @plugin["network"]["default_gateway"] = nil
- @plugin["network"]["default_interface"] = nil
- @plugin["network"]["default_inet6_gateway"] = nil
- @plugin["network"]["default_inet6_interface"] = nil
+ @ohai["network"]["default_gateway"] = nil
+ @ohai["network"]["default_interface"] = nil
+ @ohai["network"]["default_inet6_gateway"] = nil
+ @ohai["network"]["default_inet6_interface"] = nil
# just changing scopes to lInK for eth0 addresses
- @plugin["network"]["interfaces"]["eth0"]["addresses"].each{|k,v| v[:scope]="lInK" if %w[inet inet6].include? v["family"]}
+ @ohai["network"]["interfaces"]["eth0"]["addresses"].each{|k,v| v[:scope]="lInK" if %w[inet inet6].include? v["family"]}
end
it_does_not_fail
@@ -489,11 +500,11 @@ describe Ohai::System, "Network Plugin" do
it "prefers global scope addressses to set {ip,mac,ip6}address" do
Ohai::Log.should_receive(:debug).with(/^\[inet\] no default interface/).once
Ohai::Log.should_receive(:debug).with(/^\[inet6\] no default interface/).once
- Ohai::Log.stub(:debug)
- @plugin.run
- @plugin["ipaddress"].should == "192.168.99.11"
- @plugin["macaddress"].should == "00:16:3E:2F:36:80"
- @plugin["ip6address"].should == "3ffe:1111:3333::1"
+ Ohai::Log.should_receive(:debug).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.99.11"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:80"
+ @ohai["ip6address"].should == "3ffe:1111:3333::1"
end
end
end
@@ -501,29 +512,36 @@ describe Ohai::System, "Network Plugin" do
describe "link level default route" do
describe "simple setup" do
before do
- @plugin["network"]["default_gateway"] = "0.0.0.0"
- @plugin["network"]["default_interface"] = "eth1"
- @plugin["network"]["default_inet6_gateway"] = "::"
- @plugin["network"]["default_inet6_interface"] = "eth1"
+ @ohai["network"]["default_gateway"] = "0.0.0.0"
+ @ohai["network"]["default_interface"] = "eth1"
+ @ohai["network"]["default_inet6_gateway"] = "::"
+ @ohai["network"]["default_inet6_interface"] = "eth1"
end
it_does_not_fail
+ it "displays debug messages" do
+ Ohai::Log.should_receive(:debug).with(/^Loading plugin network/).once
+ Ohai::Log.should_receive(:debug).with(/^link level default inet /).once
+ Ohai::Log.should_receive(:debug).with(/^link level default inet6 /).once
+ @ohai._require_plugin("network")
+ end
+
it "picks {ip,mac,ip6}address from the default interface" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.99.11"
- @plugin["macaddress"].should == "00:16:3E:2F:36:80"
- @plugin["ip6address"].should == "3ffe:1111:3333::1"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.99.11"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:80"
+ @ohai["ip6address"].should == "3ffe:1111:3333::1"
end
end
describe "can choose from addresses with different scopes" do
before do
- @plugin["network"]["default_gateway"] = "0.0.0.0"
- @plugin["network"]["default_interface"] = "eth1"
- @plugin["network"]["default_inet6_gateway"] = "::"
- @plugin["network"]["default_inet6_interface"] = "eth1"
- @plugin["network"]["interfaces"]["eth1"]["addresses"]["127.0.0.2"] = {
+ @ohai["network"]["default_gateway"] = "0.0.0.0"
+ @ohai["network"]["default_interface"] = "eth1"
+ @ohai["network"]["default_inet6_gateway"] = "::"
+ @ohai["network"]["default_inet6_interface"] = "eth1"
+ @ohai["network"]["interfaces"]["eth1"]["addresses"]["127.0.0.2"] = {
"scope" => "host",
"netmask" => "255.255.255.255",
"prefixlen" => "32",
@@ -533,18 +551,25 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
+ it "displays debug messages" do
+ Ohai::Log.should_receive(:debug).with(/^Loading plugin network/).once
+ Ohai::Log.should_receive(:debug).with(/^link level default inet /).once
+ Ohai::Log.should_receive(:debug).with(/^link level default inet6 /).once
+ @ohai._require_plugin("network")
+ end
+
it "picks {ip,mac,ip6}address from the default interface" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.99.11"
- @plugin["macaddress"].should == "00:16:3E:2F:36:80"
- @plugin["ip6address"].should == "3ffe:1111:3333::1"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.99.11"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:80"
+ @ohai["ip6address"].should == "3ffe:1111:3333::1"
end
end
end
describe "point to point address" do
before do
- @plugin["network"]["interfaces"]["eth2"] = {
+ @ohai["network"]["interfaces"]["eth2"] = {
"flags" => ["POINTOPOINT", "BROADCAST", "MULTICAST", "UP"],
"number" => "2",
"addresses" => {
@@ -569,27 +594,27 @@ describe Ohai::System, "Network Plugin" do
}
}
}
- @plugin["network"]["default_gateway"] = "192.168.99.126"
- @plugin["network"]["default_interface"] = "eth2"
- @plugin["network"]["default_inet6_gateway"] = "3ffe:1111:2222:0:4444::2"
- @plugin["network"]["default_inet6_interface"] = "eth2"
+ @ohai["network"]["default_gateway"] = "192.168.99.126"
+ @ohai["network"]["default_interface"] = "eth2"
+ @ohai["network"]["default_inet6_gateway"] = "3ffe:1111:2222:0:4444::2"
+ @ohai["network"]["default_inet6_interface"] = "eth2"
end
it_does_not_fail
it "picks {ip,mac,ip6}address from the default interface" do
- @plugin.run
- @plugin["ipaddress"].should == "192.168.66.99"
- @plugin["macaddress"].should == "00:16:3E:2F:36:81"
- @plugin["ip6address"].should == "3ffe:1111:2222:0:4444::1"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "192.168.66.99"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:81"
+ @ohai["ip6address"].should == "3ffe:1111:2222:0:4444::1"
end
end
describe "ipv6 only node" do
before do
- @plugin["network"]["default_gateway"] = nil
- @plugin["network"]["default_interface"] = nil
- @plugin["network"]["interfaces"].each do |i,iv|
+ @ohai["network"]["default_gateway"] = nil
+ @ohai["network"]["default_interface"] = nil
+ @ohai["network"]["interfaces"].each do |i,iv|
iv["addresses"].delete_if{|k,kv| kv["family"] == "inet" }
end
end
@@ -597,28 +622,28 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
it "can't detect ipaddress" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ipaddress"].should be_nil
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should be_nil
end
it "warns about not being able to set {ip,mac}address (ipv4)" do
Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
- @plugin.run
+ @ohai._require_plugin("network")
end
it "sets {ip6,mac}address" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ip6address"].should == "3ffe:1111:2222::33"
- @plugin["macaddress"].should == "00:16:3E:2F:36:79"
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ip6address"].should == "3ffe:1111:2222::33"
+ @ohai["macaddress"].should == "00:16:3E:2F:36:79"
end
it "informs about macaddress being set using the ipv6 setup" do
Ohai::Log.should_receive(:debug).with(/^macaddress set to 00:16:3E:2F:36:79 from the ipv6 setup/).once
- Ohai::Log.stub(:debug)
- @plugin.run
+ Ohai::Log.should_receive(:debug).any_number_of_times
+ @ohai._require_plugin("network")
end
end
@@ -627,14 +652,15 @@ describe Ohai::System, "Network Plugin" do
basic_data.keys.sort.each do |os|
describe "the #{os}::network has already set some of the {ip,mac,ip6}address attributes" do
before(:each) do
- @plugin.stub(:require_plugin).twice.and_return(true)
- @plugin["network"] = basic_data[os]["network"]
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).twice.and_return(true)
+ @ohai["network"] = basic_data[os]["network"]
end
describe "{ip,mac}address are already set" do
before do
- @plugin["ipaddress"] = "10.11.12.13"
- @plugin["macaddress"] = "00:AA:BB:CC:DD:EE"
+ @ohai["ipaddress"] = "10.11.12.13"
+ @ohai["macaddress"] = "00:AA:BB:CC:DD:EE"
@expected_results = {
"linux" => {
"ip6address" => "3ffe:1111:2222::33"
@@ -648,21 +674,21 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
it "detects ip6address" do
- @plugin.run
- @plugin["ip6address"].should == @expected_results[os]["ip6address"]
+ @ohai._require_plugin("network")
+ @ohai["ip6address"].should == @expected_results[os]["ip6address"]
end
it "doesn't overwrite {ip,mac}address" do
- @plugin.run
- @plugin["ipaddress"].should == "10.11.12.13"
- @plugin["macaddress"].should == "00:AA:BB:CC:DD:EE"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "10.11.12.13"
+ @ohai["macaddress"].should == "00:AA:BB:CC:DD:EE"
end
end
describe "ip6address is already set" do
describe "node has ipv4 and ipv6" do
before do
- @plugin["ip6address"] = "3ffe:8888:9999::1"
+ @ohai["ip6address"] = "3ffe:8888:9999::1"
@expected_results = {
"linux" => {
"ipaddress" => "192.168.66.33",
@@ -678,51 +704,51 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
it "detects {ip,mac}address" do
- @plugin.run
- @plugin["ipaddress"].should == @expected_results[os]["ipaddress"]
- @plugin["macaddress"].should == @expected_results[os]["macaddress"]
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == @expected_results[os]["ipaddress"]
+ @ohai["macaddress"].should == @expected_results[os]["macaddress"]
end
it "doesn't overwrite ip6address" do
- @plugin.run
- @plugin["ip6address"].should == "3ffe:8888:9999::1"
+ @ohai._require_plugin("network")
+ @ohai["ip6address"].should == "3ffe:8888:9999::1"
end
end
describe "ipv6 only node" do
before do
- @plugin["network"]["default_gateway"] = nil
- @plugin["network"]["default_interface"] = nil
- @plugin["network"]["interfaces"].each do |i,iv|
+ @ohai["network"]["default_gateway"] = nil
+ @ohai["network"]["default_interface"] = nil
+ @ohai["network"]["interfaces"].each do |i,iv|
iv["addresses"].delete_if{|k,kv| kv["family"] == "inet" }
end
- @plugin["ip6address"] = "3ffe:8888:9999::1"
+ @ohai["ip6address"] = "3ffe:8888:9999::1"
end
it_does_not_fail
it "can't detect ipaddress (ipv4)" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ipaddress"].should be_nil
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should be_nil
end
it "can't detect macaddress either" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["macaddress"].should be_nil
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["macaddress"].should be_nil
end
it "warns about not being able to set {ip,mac}address" do
Ohai::Log.should_receive(:warn).with(/^unable to detect ipaddress/).once
Ohai::Log.should_receive(:warn).with(/^unable to detect macaddress/).once
- @plugin.run
+ @ohai._require_plugin("network")
end
it "doesn't overwrite ip6address" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ip6address"].should == "3ffe:8888:9999::1"
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ip6address"].should == "3ffe:8888:9999::1"
end
end
end
@@ -730,8 +756,8 @@ describe Ohai::System, "Network Plugin" do
describe "{mac,ip6}address are already set" do
describe "valid ipv4 setup" do
before do
- @plugin["macaddress"] = "00:AA:BB:CC:DD:EE"
- @plugin["ip6address"] = "3ffe:8888:9999::1"
+ @ohai["macaddress"] = "00:AA:BB:CC:DD:EE"
+ @ohai["ip6address"] = "3ffe:8888:9999::1"
@expected_results = {
"linux" => {
"ipaddress" => "192.168.66.33",
@@ -747,75 +773,75 @@ describe Ohai::System, "Network Plugin" do
it_does_not_fail
it "detects ipaddress and overwrite macaddress" do
- @plugin.run
- @plugin["ipaddress"].should == @expected_results[os]["ipaddress"]
- @plugin["macaddress"].should == @expected_results[os]["macaddress"]
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == @expected_results[os]["ipaddress"]
+ @ohai["macaddress"].should == @expected_results[os]["macaddress"]
end
it "doesn't overwrite ip6address" do
- @plugin.run
- @plugin["ip6address"].should == "3ffe:8888:9999::1"
+ @ohai._require_plugin("network")
+ @ohai["ip6address"].should == "3ffe:8888:9999::1"
end
end
describe "ipv6 only node" do
before do
- @plugin["network"]["default_gateway"] = nil
- @plugin["network"]["default_interface"] = nil
- @plugin["network"]["interfaces"].each do |i,iv|
+ @ohai["network"]["default_gateway"] = nil
+ @ohai["network"]["default_interface"] = nil
+ @ohai["network"]["interfaces"].each do |i,iv|
iv["addresses"].delete_if{|k,kv| kv["family"] == "inet" }
end
- @plugin["macaddress"] = "00:AA:BB:CC:DD:EE"
- @plugin["ip6address"] = "3ffe:8888:9999::1"
+ @ohai["macaddress"] = "00:AA:BB:CC:DD:EE"
+ @ohai["ip6address"] = "3ffe:8888:9999::1"
end
it_does_not_fail
it "can't set ipaddress" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ipaddress"].should be_nil
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should be_nil
end
it "doesn't overwrite {ip6,mac}address" do
- Ohai::Log.stub(:warn)
- @plugin.run
- @plugin["ip6address"].should == "3ffe:8888:9999::1"
- @plugin["macaddress"].should == "00:AA:BB:CC:DD:EE"
+ Ohai::Log.should_receive(:warn).any_number_of_times
+ @ohai._require_plugin("network")
+ @ohai["ip6address"].should == "3ffe:8888:9999::1"
+ @ohai["macaddress"].should == "00:AA:BB:CC:DD:EE"
end
end
end
describe "{ip,mac,ip6}address are already set" do
before do
- @plugin["ipaddress"] = "10.11.12.13"
- @plugin["macaddress"] = "00:AA:BB:CC:DD:EE"
- @plugin["ip6address"] = "3ffe:8888:9999::1"
+ @ohai["ipaddress"] = "10.11.12.13"
+ @ohai["macaddress"] = "00:AA:BB:CC:DD:EE"
+ @ohai["ip6address"] = "3ffe:8888:9999::1"
end
it_does_not_fail
it "doesn't overwrite {ip,mac,ip6}address" do
- @plugin.run
- @plugin["ipaddress"].should == "10.11.12.13"
- @plugin["macaddress"].should == "00:AA:BB:CC:DD:EE"
- @plugin["ip6address"].should == "3ffe:8888:9999::1"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "10.11.12.13"
+ @ohai["macaddress"].should == "00:AA:BB:CC:DD:EE"
+ @ohai["ip6address"].should == "3ffe:8888:9999::1"
end
end
describe "{ip,ip6}address are already set" do
before do
- @plugin["ipaddress"] = "10.11.12.13"
- @plugin["ip6address"] = "3ffe:8888:9999::1"
+ @ohai["ipaddress"] = "10.11.12.13"
+ @ohai["ip6address"] = "3ffe:8888:9999::1"
end
it_does_not_fail
it "doesn't overwrite {ip,mac,ip6}address" do
- @plugin.run
- @plugin["ipaddress"].should == "10.11.12.13"
- @plugin["macaddress"].should == nil
- @plugin["ip6address"].should == "3ffe:8888:9999::1"
+ @ohai._require_plugin("network")
+ @ohai["ipaddress"].should == "10.11.12.13"
+ @ohai["macaddress"].should == nil
+ @ohai["ip6address"].should == "3ffe:8888:9999::1"
end
end
diff --git a/spec/unit/plugins/nodejs_spec.rb b/spec/unit/plugins/nodejs_spec.rb
index 0159bdad..fad4d404 100644
--- a/spec/unit/plugins/nodejs_spec.rb
+++ b/spec/unit/plugins/nodejs_spec.rb
@@ -22,31 +22,30 @@ describe Ohai::System, "plugin nodejs" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "nodejs.rb"))
- @plugin.stub(:require_plugin)
- @plugin[:languages] = Mash.new
+ @ohai[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
@status = 0
@stdout = "v0.8.11\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"node -v"}).and_return([@status, @stdout, @stderr])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"node -v"}).and_return([@status, @stdout, @stderr])
end
it "should get the nodejs version from running node -v" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"node -v"}).and_return([0, "v0.8.11\n", ""])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"node -v"}).and_return([0, "v0.8.11\n", ""])
+ @ohai._require_plugin("nodejs")
end
it "should set languages[:nodejs][:version]" do
- @plugin.run
- @plugin.languages[:nodejs][:version].should eql("0.8.11")
+ @ohai._require_plugin("nodejs")
+ @ohai.languages[:nodejs][:version].should eql("0.8.11")
end
it "should not set the languages[:nodejs] tree up if node command fails" do
@status = 1
@stdout = "v0.8.11\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"node -v"}).and_return([@status, @stdout, @stderr])
- @plugin.run
- @plugin.languages.should_not have_key(:nodejs)
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"node -v"}).and_return([@status, @stdout, @stderr])
+ @ohai._require_plugin("nodejs")
+ @ohai.languages.should_not have_key(:nodejs)
end
end
diff --git a/spec/unit/plugins/ohai_spec.rb b/spec/unit/plugins/ohai_spec.rb
index c5cbd995..c9ccad4e 100644
--- a/spec/unit/plugins/ohai_spec.rb
+++ b/spec/unit/plugins/ohai_spec.rb
@@ -23,12 +23,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin ohai" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ohai.rb"))
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai.stub!(:require_plugin).and_return(true)
end
it "should set [:chef_packages][:ohai][:version] to the current version" do
- @plugin.run
- @plugin[:chef_packages][:ohai][:version].should == Ohai::VERSION
+ @ohai._require_plugin("ohai")
+ @ohai[:chef_packages][:ohai][:version].should == Ohai::VERSION
end
end
diff --git a/spec/unit/plugins/ohai_time_spec.rb b/spec/unit/plugins/ohai_time_spec.rb
index 12a5d7b0..a51817f5 100644
--- a/spec/unit/plugins/ohai_time_spec.rb
+++ b/spec/unit/plugins/ohai_time_spec.rb
@@ -22,26 +22,25 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin ohai_time" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ohai_time.rb"))
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai.stub!(:require_plugin).and_return(true)
end
it "should get the current time" do
Time.should_receive(:now)
- @plugin.run
+ @ohai._require_plugin("ohai_time")
end
it "should turn the time into a floating point number" do
time = Time.now
time.should_receive(:to_f)
- Time.stub(:now).and_return(time)
- @plugin.run
+ Time.stub!(:now).and_return(time)
+ @ohai._require_plugin("ohai_time")
end
it "should set ohai_time to the current time" do
time = Time.now
- Time.stub(:now).and_return(time)
- @plugin.run
- @plugin[:ohai_time].should == time.to_f
+ Time.stub!(:now).and_return(time)
+ @ohai._require_plugin("ohai_time")
+ @ohai[:ohai_time].should == time.to_f
end
-end
+end \ No newline at end of file
diff --git a/spec/unit/plugins/openbsd/hostname_spec.rb b/spec/unit/plugins/openbsd/hostname_spec.rb
index f50b04c2..419822d1 100644
--- a/spec/unit/plugins/openbsd/hostname_spec.rb
+++ b/spec/unit/plugins/openbsd/hostname_spec.rb
@@ -21,12 +21,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "OpenBSD hostname plugin" do
before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("openbsd/hostname.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "openbsd"
- @plugin.stub(:from).with("hostname -s").and_return("katie")
- @plugin.stub(:from).with("hostname").and_return("katie.bethell")
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "openbsd"
+ @ohai.stub!(:from).with("hostname -s").and_return("katie")
+ @ohai.stub!(:from).with("hostname").and_return("katie.bethell")
end
it_should_check_from("openbsd::hostname", "hostname", "hostname -s", "katie")
diff --git a/spec/unit/plugins/openbsd/kernel_spec.rb b/spec/unit/plugins/openbsd/kernel_spec.rb
index afcf1406..0ba22433 100644
--- a/spec/unit/plugins/openbsd/kernel_spec.rb
+++ b/spec/unit/plugins/openbsd/kernel_spec.rb
@@ -21,19 +21,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "OpenBSD kernel plugin" do
before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("openbsd/kernel.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.stub(:from).with("uname -i").and_return("foo")
- @plugin.stub(:from_with_regex).with("sysctl kern.securelevel", /kern.securelevel=(.+)$/).and_return("kern.securelevel: 1")
- @plugin.should_receive(:popen4).with("/usr/bin/modstat").and_yield(1, StringIO.new, StringIO.new, StringIO.new)
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:name] = "openbsd"
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.stub!(:from).with("uname -i").and_return("foo")
+ @ohai.stub!(:from_with_regex).with("sysctl kern.securelevel").and_return("kern.securelevel: 1")
+ @ohai[:kernel] = Mash.new
+ @ohai[:kernel][:name] = "openbsd"
end
it "should set the kernel_os to the kernel_name value" do
- @plugin.run
- @plugin[:kernel][:os].should == @plugin[:kernel][:name]
+ @ohai._require_plugin("openbsd::kernel")
+ @ohai[:kernel][:os].should == @ohai[:kernel][:name]
end
end
diff --git a/spec/unit/plugins/openbsd/platform_spec.rb b/spec/unit/plugins/openbsd/platform_spec.rb
index 7de37054..9fb24fa4 100644
--- a/spec/unit/plugins/openbsd/platform_spec.rb
+++ b/spec/unit/plugins/openbsd/platform_spec.rb
@@ -21,21 +21,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "OpenBSD plugin platform" do
before(:each) do
- @ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("openbsd/platform.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.stub(:from).with("uname -s").and_return("OpenBSD")
- @plugin.stub(:from).with("uname -r").and_return("4.5")
- @plugin[:os] = "openbsd"
+ @ohai = Ohai::System.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.stub!(:from).with("uname -s").and_return("OpenBSD")
+ @ohai.stub!(:from).with("uname -r").and_return("4.5")
+ @ohai[:os] = "openbsd"
end
it "should set platform to lowercased lsb[:id]" do
- @plugin.run
- @plugin[:platform].should == "openbsd"
+ @ohai._require_plugin("openbsd::platform")
+ @ohai[:platform].should == "openbsd"
end
it "should set platform_version to lsb[:release]" do
- @plugin.run
- @plugin[:platform_version].should == "4.5"
+ @ohai._require_plugin("openbsd::platform")
+ @ohai[:platform_version].should == "4.5"
end
end
diff --git a/spec/unit/plugins/os_spec.rb b/spec/unit/plugins/os_spec.rb
index 5ed74ea7..52c5d1b9 100644
--- a/spec/unit/plugins/os_spec.rb
+++ b/spec/unit/plugins/os_spec.rb
@@ -24,12 +24,11 @@ ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG['host_os']
describe Ohai::System, "plugin os" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "os.rb"))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:languages] = Mash.new
- @plugin[:languages][:ruby] = Mash.new
- @plugin[:kernel] = Mash.new
- @plugin[:kernel][:release] = "kings of leon"
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
+ @ohai[:languages][:ruby] = Mash.new
+ @ohai[:kernel] = Mash.new
+ @ohai[:kernel][:release] = "kings of leon"
end
after do
@@ -37,8 +36,8 @@ describe Ohai::System, "plugin os" do
end
it "should set os_version to kernel_release" do
- @plugin.run
- @plugin[:os_version].should == @plugin[:kernel][:release]
+ @ohai._require_plugin("os")
+ @ohai[:os_version].should == @ohai[:kernel][:release]
end
describe "on linux" do
@@ -47,8 +46,8 @@ describe Ohai::System, "plugin os" do
end
it "should set the os to linux" do
- @plugin.run
- @plugin[:os].should == "linux"
+ @ohai._require_plugin("os")
+ @ohai[:os].should == "linux"
end
end
@@ -58,8 +57,8 @@ describe Ohai::System, "plugin os" do
end
it "should set the os to darwin" do
- @plugin.run
- @plugin[:os].should == "darwin"
+ @ohai._require_plugin("os")
+ @ohai[:os].should == "darwin"
end
end
@@ -69,8 +68,8 @@ describe Ohai::System, "plugin os" do
end
it "sets the os to solaris2" do
- @plugin.run
- @plugin[:os].should == "solaris2"
+ @ohai._require_plugin("os")
+ @ohai[:os].should == "solaris2"
end
end
@@ -80,8 +79,8 @@ describe Ohai::System, "plugin os" do
end
it "sets the os to the ruby 'host_os'" do
- @plugin.run
- @plugin[:os].should == "tron"
+ @ohai._require_plugin("os")
+ @ohai[:os].should == "tron"
end
end
end
diff --git a/spec/unit/plugins/passwd_spec.rb b/spec/unit/plugins/passwd_spec.rb
index 51cc912b..ef8c4558 100644
--- a/spec/unit/plugins/passwd_spec.rb
+++ b/spec/unit/plugins/passwd_spec.rb
@@ -3,8 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin etc" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "passwd.rb"))
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai.stub!(:require_plugin).and_return(true)
end
PasswdEntry = Struct.new(:name, :uid, :gid, :dir, :shell, :gecos)
@@ -13,31 +12,31 @@ describe Ohai::System, "plugin etc" do
it "should include a list of all users" do
Etc.should_receive(:passwd).and_yield(PasswdEntry.new("root", 1, 1, '/root', '/bin/zsh', 'BOFH')).
and_yield(PasswdEntry.new('www', 800, 800, '/var/www', '/bin/false', 'Serving the web since 1970'))
- @plugin.run
- @plugin[:etc][:passwd]['root'].should == Mash.new(:shell => '/bin/zsh', :gecos => 'BOFH', :gid => 1, :uid => 1, :dir => '/root')
- @plugin[:etc][:passwd]['www'].should == Mash.new(:shell => '/bin/false', :gecos => 'Serving the web since 1970', :gid => 800, :uid => 800, :dir => '/var/www')
+ @ohai._require_plugin("passwd")
+ @ohai[:etc][:passwd]['root'].should == Mash.new(:shell => '/bin/zsh', :gecos => 'BOFH', :gid => 1, :uid => 1, :dir => '/root')
+ @ohai[:etc][:passwd]['www'].should == Mash.new(:shell => '/bin/false', :gecos => 'Serving the web since 1970', :gid => 800, :uid => 800, :dir => '/var/www')
end
it "should set the current user" do
Etc.should_receive(:getlogin).and_return('chef')
- @plugin.run
- @plugin[:current_user].should == 'chef'
+ @ohai._require_plugin("passwd")
+ @ohai[:current_user].should == 'chef'
end
it "should set the available groups" do
Etc.should_receive(:group).and_yield(GroupEntry.new("admin", 100, ['root', 'chef'])).and_yield(GroupEntry.new('www', 800, ['www', 'deploy']))
- @plugin.run
- @plugin[:etc][:group]['admin'].should == Mash.new(:gid => 100, :members => ['root', 'chef'])
- @plugin[:etc][:group]['www'].should == Mash.new(:gid => 800, :members => ['www', 'deploy'])
+ @ohai._require_plugin("passwd")
+ @ohai[:etc][:group]['admin'].should == Mash.new(:gid => 100, :members => ['root', 'chef'])
+ @ohai[:etc][:group]['www'].should == Mash.new(:gid => 800, :members => ['www', 'deploy'])
end
if "".respond_to?(:force_encoding)
it "sets the encoding of strings to the default external encoding" do
fields = ["root", 1, 1, '/root', '/bin/zsh', 'BOFH']
fields.each {|f| f.force_encoding(Encoding::ASCII_8BIT) if f.respond_to?(:force_encoding) }
- Etc.stub(:passwd).and_yield(PasswdEntry.new(*fields))
- @plugin.run
- root = @plugin[:etc][:passwd]['root']
+ Etc.stub!(:passwd).and_yield(PasswdEntry.new(*fields))
+ @ohai._require_plugin("passwd")
+ root = @ohai[:etc][:passwd]['root']
root['gecos'].encoding.should == Encoding.default_external
end
end
diff --git a/spec/unit/plugins/perl_spec.rb b/spec/unit/plugins/perl_spec.rb
index 4c95ea93..7be7a5fa 100644
--- a/spec/unit/plugins/perl_spec.rb
+++ b/spec/unit/plugins/perl_spec.rb
@@ -21,9 +21,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin perl" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "perl.rb"))
- @plugin[:languages] = Mash.new
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
@pid = 2342
@stderr = StringIO.new
@stdout = StringIO.new(<<-OUT)
@@ -32,7 +31,7 @@ archname='darwin-thread-multi-2level';
OUT
@stdin = StringIO.new
@status = 0
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
@status,
@stdout,
@stderr
@@ -40,44 +39,44 @@ OUT
end
it "should run perl -V:version -V:archname" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return(true)
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return(true)
+ @ohai._require_plugin("perl")
end
it "should iterate over each line of perl command's stdout" do
@stdout.should_receive(:each_line).and_return(true)
- @plugin.run
+ @ohai._require_plugin("perl")
end
it "should set languages[:perl][:version]" do
- @plugin.run
- @plugin.languages[:perl][:version].should eql("5.8.8")
+ @ohai._require_plugin("perl")
+ @ohai.languages[:perl][:version].should eql("5.8.8")
end
it "should set languages[:perl][:archname]" do
- @plugin.run
- @plugin.languages[:perl][:archname].should eql("darwin-thread-multi-2level")
+ @ohai._require_plugin("perl")
+ @ohai.languages[:perl][:archname].should eql("darwin-thread-multi-2level")
end
it "should set languages[:perl] if perl command succeeds" do
@status = 0
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
@status,
@stdout,
@stderr
])
- @plugin.run
- @plugin.languages.should have_key(:perl)
+ @ohai._require_plugin("perl")
+ @ohai.languages.should have_key(:perl)
end
it "should not set languages[:perl] if perl command fails" do
@status = 1
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([
@status,
@stdout,
@stderr
])
- @plugin.run
- @plugin.languages.should_not have_key(:perl)
+ @ohai._require_plugin("perl")
+ @ohai.languages.should_not have_key(:perl)
end
end
diff --git a/spec/unit/plugins/php_spec.rb b/spec/unit/plugins/php_spec.rb
index 084fa496..fa084768 100644
--- a/spec/unit/plugins/php_spec.rb
+++ b/spec/unit/plugins/php_spec.rb
@@ -22,32 +22,31 @@ describe Ohai::System, "plugin php" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "php.rb"))
- @plugin[:languages] = Mash.new
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
@status = 0
@stdout = "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([@status, @stdout, @stderr])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([@status, @stdout, @stderr])
end
it "should get the php version from running php -V" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([0, "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n", ""])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([0, "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n", ""])
+ @ohai._require_plugin("php")
end
it "should set languages[:php][:version]" do
- @plugin.run
- @plugin.languages[:php][:version].should eql("5.1.6")
+ @ohai._require_plugin("php")
+ @ohai.languages[:php][:version].should eql("5.1.6")
end
it "should not set the languages[:php] tree up if php command fails" do
@status = 1
@stdout = "PHP 5.1.6 (cli) (built: Jul 16 2008 19:52:52)\nCopyright (c) 1997-2006 The PHP Group\nZend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([@status, @stdout, @stderr])
- @plugin.run
- @plugin.languages.should_not have_key(:php)
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([@status, @stdout, @stderr])
+ @ohai._require_plugin("php")
+ @ohai.languages.should_not have_key(:php)
end
end
diff --git a/spec/unit/plugins/platform_spec.rb b/spec/unit/plugins/platform_spec.rb
index e33b46a4..776709b7 100644
--- a/spec/unit/plugins/platform_spec.rb
+++ b/spec/unit/plugins/platform_spec.rb
@@ -22,51 +22,50 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin platform" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "platform.rb"))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = 'monkey'
- @plugin[:os_version] = 'poop'
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = 'monkey'
+ @ohai[:os_version] = 'poop'
end
it "should require the os platform plugin" do
- @plugin.should_receive(:require_plugin).with("monkey::platform")
- @plugin.run
+ @ohai.should_receive(:require_plugin).with("monkey::platform")
+ @ohai._require_plugin("platform")
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")
- @plugin[:platform_family].should eql("monkey")
+ @ohai._require_plugin("platform")
+ @ohai[:platform].should eql("monkey")
+ @ohai[:platform_family].should eql("monkey")
end
it "should not set the platform to the os if it was set earlier" do
- @plugin[:platform] = 'lars'
- @plugin.run
- @plugin[:platform].should eql("lars")
+ @ohai[:platform] = 'lars'
+ @ohai._require_plugin("platform")
+ @ohai[:platform].should eql("lars")
end
it "should set the platform_family to the platform if platform was set earlier but not platform_family" do
- @plugin[:platform] = 'lars'
- @plugin[:platform_family] = 'jack'
- @plugin.run
- @plugin[:platform_family].should eql("jack")
+ @ohai[:platform] = 'lars'
+ @ohai[:platform_family] = 'jack'
+ @ohai._require_plugin("platform")
+ @ohai[:platform_family].should eql("jack")
end
it "should not set the platform_family if the platform_family was set earlier." do
- @plugin[:platform] = 'lars'
- @plugin.run
- @plugin[:platform].should eql("lars")
- @plugin[:platform_family].should eql("lars")
+ @ohai[:platform] = 'lars'
+ @ohai._require_plugin("platform")
+ @ohai[:platform].should eql("lars")
+ @ohai[:platform_family].should eql("lars")
end
it "should set the platform_version to the os_version if it was not set earlier" do
- @plugin.run
- @plugin[:os_version].should eql("poop")
+ @ohai._require_plugin("platform")
+ @ohai[:os_version].should eql("poop")
end
it "should not set the platform to the os if it was set earlier" do
- @plugin[:platform_version] = 'ulrich'
- @plugin.run
- @plugin[:platform_version].should eql("ulrich")
+ @ohai[:platform_version] = 'ulrich'
+ @ohai._require_plugin("platform")
+ @ohai[:platform_version].should eql("ulrich")
end
end
diff --git a/spec/unit/plugins/python_spec.rb b/spec/unit/plugins/python_spec.rb
index 45725ab8..c1e4b321 100644
--- a/spec/unit/plugins/python_spec.rb
+++ b/spec/unit/plugins/python_spec.rb
@@ -23,32 +23,31 @@ describe Ohai::System, "plugin python" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "python.rb"))
- @plugin[:languages] = Mash.new
- @plugin.stub(:require_plugin).and_return(true)
+ @ohai[:languages] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
@status = 0
@stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr])
end
it "should get the python version from printing sys.version and sys.platform" do
- @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([0, "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n", ""])
- @plugin.run
+ @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([0, "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n", ""])
+ @ohai._require_plugin("python")
end
it "should set languages[:python][:version]" do
- @plugin.run
- @plugin.languages[:python][:version].should eql("2.5.2")
+ @ohai._require_plugin("python")
+ @ohai.languages[:python][:version].should eql("2.5.2")
end
it "should not set the languages[:python] tree up if python command fails" do
@status = 1
@stdout = "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n"
@stderr = ""
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr])
- @plugin.run
- @plugin.languages.should_not have_key(:python)
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr])
+ @ohai._require_plugin("python")
+ @ohai.languages.should_not have_key(:python)
end
end
diff --git a/spec/unit/plugins/rackspace_spec.rb b/spec/unit/plugins/rackspace_spec.rb
index e66820c1..a58c257b 100644
--- a/spec/unit/plugins/rackspace_spec.rb
+++ b/spec/unit/plugins/rackspace_spec.rb
@@ -20,9 +20,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
describe Ohai::System, "plugin rackspace" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "rackspace.rb"))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:network] = {:interfaces => {:eth0 => {"addresses"=> {
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:network] = {:interfaces => {:eth0 => {"addresses"=> {
"1.2.3.4"=> {
"broadcast"=> "67.23.20.255",
"netmask"=> "255.255.255.0",
@@ -41,66 +40,64 @@ describe Ohai::System, "plugin rackspace" do
"40:40:95:47:6E:ED"=> {
"family"=> "lladdr"
}
- }}
- }
- }
-
- @plugin[:network][:interfaces][:eth1] = {:addresses => {
- "fe80::4240:f5ff:feab:2836" => {
- "scope"=> "Link",
- "prefixlen"=> "64",
- "family"=> "inet6"
- },
- "5.6.7.8"=> {
- "broadcast"=> "10.176.191.255",
- "netmask"=> "255.255.224.0",
- "family"=> "inet"
- },
- "40:40:F5:AB:28:36" => {
- "family"=> "lladdr"
- }
+ }}}}
+
+ @ohai[:network][:interfaces][:eth1] = {:addresses => {
+ "fe80::4240:f5ff:feab:2836" => {
+ "scope"=> "Link",
+ "prefixlen"=> "64",
+ "family"=> "inet6"
+ },
+ "5.6.7.8"=> {
+ "broadcast"=> "10.176.191.255",
+ "netmask"=> "255.255.224.0",
+ "family"=> "inet"
+ },
+ "40:40:F5:AB:28:36" => {
+ "family"=> "lladdr"
+ }
}}
# In olden days we could detect rackspace by a -rscloud suffix on the kernel
# This is here to make #has_rackspace_kernel? fail until we remove that check
- @plugin[:kernel] = { :release => "1.2.13-not-rackspace" }
+ @ohai[:kernel] = { :release => "1.2.13-not-rackspace" }
# We need a generic stub here for the later stubs with arguments to work
# Because, magic.
- @plugin.stub(:run_command).and_return(false)
+ @ohai.stub(:run_command).and_return(false)
end
shared_examples_for "!rackspace" do
it "should NOT create rackspace" do
- @plugin.run
- @plugin[:rackspace].should be_nil
+ @ohai._require_plugin("rackspace")
+ @ohai[:rackspace].should be_nil
end
end
shared_examples_for "rackspace" do
it "should create rackspace" do
- @plugin.run
- @plugin[:rackspace].should_not be_nil
+ @ohai._require_plugin("rackspace")
+ @ohai[:rackspace].should_not be_nil
end
it "should have all required attributes" do
- @plugin.run
- @plugin[:rackspace][:public_ip].should_not be_nil
- @plugin[:rackspace][:private_ip].should_not be_nil
- @plugin[:rackspace][:public_ipv4].should_not be_nil
- @plugin[:rackspace][:local_ipv4].should_not be_nil
- @plugin[:rackspace][:public_ipv6].should_not be_nil
- @plugin[:rackspace][:local_ipv6].should be_nil
+ @ohai._require_plugin("rackspace")
+ @ohai[:rackspace][:public_ip].should_not be_nil
+ @ohai[:rackspace][:private_ip].should_not be_nil
+ @ohai[:rackspace][:public_ipv4].should_not be_nil
+ @ohai[:rackspace][:local_ipv4].should_not be_nil
+ @ohai[:rackspace][:public_ipv6].should_not be_nil
+ @ohai[:rackspace][:local_ipv6].should be_nil
end
it "should have correct values for all attributes" do
- @plugin.run
- @plugin[:rackspace][:public_ip].should == "1.2.3.4"
- @plugin[:rackspace][:private_ip].should == "5.6.7.8"
- @plugin[:rackspace][:public_ipv4].should == "1.2.3.4"
- @plugin[:rackspace][:local_ipv4].should == "5.6.7.8"
- @plugin[:rackspace][:public_ipv6].should == "2a00:1a48:7805:111:e875:efaf:ff08:75"
+ @ohai._require_plugin("rackspace")
+ @ohai[:rackspace][:public_ip].should == "1.2.3.4"
+ @ohai[:rackspace][:private_ip].should == "5.6.7.8"
+ @ohai[:rackspace][:public_ipv4].should == "1.2.3.4"
+ @ohai[:rackspace][:local_ipv4].should == "5.6.7.8"
+ @ohai[:rackspace][:public_ipv6].should == "2a00:1a48:7805:111:e875:efaf:ff08:75"
end
it "should capture region information" do
@@ -111,9 +108,9 @@ server_id = "21301000"
created_at = "2012-12-06T22:08:16Z"
region = "dfw"
OUT
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"xenstore-ls vm-data/provider_data"}).and_return([ 0, provider_data, ""])
- @plugin.run
- @plugin[:rackspace][:region].should == "dfw"
+ @ohai.stub(:run_command).with({:no_status_check=>true, :command=>"xenstore-ls vm-data/provider_data"}).and_return([ 0, provider_data, ""])
+ @ohai._require_plugin("rackspace")
+ @ohai[:rackspace][:region].should == "dfw"
end
end
@@ -121,10 +118,10 @@ OUT
it_should_behave_like "rackspace"
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
- File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
- File.stub(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/rackspace.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/rackspace.json').and_return('')
end
end
@@ -132,8 +129,8 @@ OUT
it_should_behave_like "!rackspace"
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(false)
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(false)
+ File.stub!(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(false)
end
end
@@ -141,13 +138,10 @@ OUT
it_should_behave_like "!rackspace"
before(:each) do
- File.stub(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
- File.stub(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
- File.stub(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
- File.stub(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
-
- File.stub(:exist?).with('/etc/chef/ohai/hints/rackspace.json').and_return(false)
- File.stub(:exist?).with('C:\chef\ohai\hints/rackspace.json').and_return(false)
+ File.stub!(:exist?).with('/etc/chef/ohai/hints/ec2.json').and_return(true)
+ File.stub!(:read).with('/etc/chef/ohai/hints/ec2.json').and_return('')
+ File.stub!(:exist?).with('C:\chef\ohai\hints/ec2.json').and_return(true)
+ File.stub!(:read).with('C:\chef\ohai\hints/ec2.json').and_return('')
end
end
@@ -158,7 +152,7 @@ OUT
stderr = StringIO.new
stdout = "Rackspace\n"
status = 0
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"xenstore-read vm-data/provider_data/provider"}).and_return([ status, stdout, stderr ])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xenstore-read vm-data/provider_data/provider"}).and_return([ status, stdout, stderr ])
end
end
@@ -169,7 +163,7 @@ OUT
stderr = StringIO.new
stdout = "cumulonimbus\n"
status = 0
- @plugin.stub(:run_command).with({:no_status_check=>true, :command=>"xenstore-read vm-data/provider_data/provider"}).and_return([ status, stdout, stderr ])
+ @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xenstore-read vm-data/provider_data/provider"}).and_return([ status, stdout, stderr ])
end
end
end
diff --git a/spec/unit/plugins/root_group_spec.rb b/spec/unit/plugins/root_group_spec.rb
index 501264f2..90c02306 100644
--- a/spec/unit/plugins/root_group_spec.rb
+++ b/spec/unit/plugins/root_group_spec.rb
@@ -23,8 +23,6 @@ ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG['host_os']
describe Ohai::System, 'root_group' do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "root_group.rb"))
- @plugin.stub(:require_plugin)
end
describe 'unix platform', :unix_only do
@@ -33,49 +31,49 @@ describe Ohai::System, 'root_group' do
# apparently didn't apply to this api. we're just trying to fake
# Etc.getgrgid(Etc.getpwnam('root').gid).name
@pwnam = Object.new
- @pwnam.stub(:gid).and_return(0)
- Etc.stub(:getpwnam).with('root').and_return(@pwnam)
+ @pwnam.stub!(:gid).and_return(0)
+ Etc.stub!(:getpwnam).with('root').and_return(@pwnam)
@grgid = Object.new
- Etc.stub(:getgrgid).and_return(@grgid)
+ Etc.stub!(:getgrgid).and_return(@grgid)
end
describe 'with wheel group' do
before(:each) do
- @grgid.stub(:name).and_return('wheel')
+ @grgid.stub!(:name).and_return('wheel')
end
it 'should have a root_group of wheel' do
- @plugin.run
- @plugin[:root_group].should == 'wheel'
+ @ohai._require_plugin('root_group')
+ @ohai[:root_group].should == 'wheel'
end
end
describe 'with root group' do
before(:each) do
- @grgid.stub(:name).and_return('root')
+ @grgid.stub!(:name).and_return('root')
end
it 'should have a root_group of root' do
- @plugin.run
- @plugin[:root_group].should == 'root'
+ @ohai._require_plugin('root_group')
+ @ohai[:root_group].should == 'root'
end
end
describe 'platform hpux with sys group' do
before(:each) do
- @pwnam.stub(:gid).and_return(3)
- @grgid.stub(:name).and_return('sys')
+ @pwnam.stub!(:gid).and_return(3)
+ @grgid.stub!(:name).and_return('sys')
end
it 'should have a root_group of sys' do
- @plugin.run
- @plugin[:root_group].should == 'sys'
+ @ohai._require_plugin('root_group')
+ @ohai[:root_group].should == 'sys'
end
end
describe 'platform aix with system group' do
before(:each) do
- @grgid.stub(:name).and_return('system')
+ @grgid.stub!(:name).and_return('system')
end
it 'should have a root_group of system' do
- @plugin.run
- @plugin[:root_group].should == 'system'
+ @ohai._require_plugin('root_group')
+ @ohai[:root_group].should == 'system'
end
end
end
diff --git a/spec/unit/plugins/ruby_spec.rb b/spec/unit/plugins/ruby_spec.rb
index 3db81dd3..b97057f9 100644
--- a/spec/unit/plugins/ruby_spec.rb
+++ b/spec/unit/plugins/ruby_spec.rb
@@ -19,18 +19,17 @@
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb')
-ruby_bin = File.join(::RbConfig::CONFIG['bindir'], ::RbConfig::CONFIG['ruby_install_name'])
+ruby_bin = File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name'])
describe Ohai::System, "plugin ruby" do
before(:all) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ruby.rb"))
- @plugin[:languages] = Mash.new
+ @ohai[:languages] = Mash.new
- @plugin.require_plugin("ruby")
+ @ohai.require_plugin("ruby")
- @ruby_ohai_data_pristine = @plugin[:languages][:ruby]
+ @ruby_ohai_data_pristine = @ohai[:languages][:ruby]
end
before(:each) do
@@ -41,16 +40,16 @@ describe Ohai::System, "plugin ruby" do
:platform => RUBY_PLATFORM,
:version => RUBY_VERSION,
:release_date => RUBY_RELEASE_DATE,
- :target => ::RbConfig::CONFIG['target'],
- :target_cpu => ::RbConfig::CONFIG['target_cpu'],
- :target_vendor => ::RbConfig::CONFIG['target_vendor'],
- :target_os => ::RbConfig::CONFIG['target_os'],
- :host => ::RbConfig::CONFIG['host'],
- :host_cpu => ::RbConfig::CONFIG['host_cpu'],
- :host_os => ::RbConfig::CONFIG['host_os'],
- :host_vendor => ::RbConfig::CONFIG['host_vendor'],
- :gems_dir => %x{#{ruby_bin} #{::RbConfig::CONFIG['bindir']}/gem env gemdir}.chomp!,
- :gem_bin => [ ::Gem.default_exec_format % 'gem', 'gem' ].map{|bin| "#{::RbConfig::CONFIG['bindir']}/#{bin}"
+ :target => ::Config::CONFIG['target'],
+ :target_cpu => ::Config::CONFIG['target_cpu'],
+ :target_vendor => ::Config::CONFIG['target_vendor'],
+ :target_os => ::Config::CONFIG['target_os'],
+ :host => ::Config::CONFIG['host'],
+ :host_cpu => ::Config::CONFIG['host_cpu'],
+ :host_os => ::Config::CONFIG['host_os'],
+ :host_vendor => ::Config::CONFIG['host_vendor'],
+ :gems_dir => %x{#{ruby_bin} #{::Config::CONFIG['bindir']}/gem env gemdir}.chomp!,
+ :gem_bin => [ ::Gem.default_exec_format % 'gem', 'gem' ].map{|bin| "#{::Config::CONFIG['bindir']}/#{bin}"
}.find{|bin| ::File.exists? bin},
:ruby_bin => ruby_bin
}.each do |attribute, value|
diff --git a/spec/unit/plugins/sigar/network_route_spec.rb b/spec/unit/plugins/sigar/network_route_spec.rb
index a2ce993c..7005c70d 100644
--- a/spec/unit/plugins/sigar/network_route_spec.rb
+++ b/spec/unit/plugins/sigar/network_route_spec.rb
@@ -33,7 +33,6 @@ describe Ohai::System, "Sigar network route plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("sigar/network_route_spec.rb", PLUGIN_PATH))
@sigar = double("Sigar")
@net_info_conf={
:default_gateway => "192.168.1.254",
@@ -118,29 +117,29 @@ describe Ohai::System, "Sigar network route plugin" do
@sigar.should_receive(:net_interface_stat).with("eth0").and_return(net_stat)
@sigar.should_receive(:arp_list).once.and_return([net_arp])
- # Since we double net_route_list here, flags never gets called
+ # Since we mock 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)
- @plugin.require_plugin("os")
- @plugin[:os]="sigar"
+ @ohai.require_plugin("os")
+ @ohai[:os]="sigar"
Ohai::Log.should_receive(:warn).with(/unable to detect ip6address/).once
- @plugin.require_plugin("network")
- @plugin.require_plugin("sigar::network_route")
+ @ohai.require_plugin("network")
+ @ohai.require_plugin("sigar::network_route")
end
it "should set the routes" do
- @plugin[:network][:interfaces][:eth0].should have_key(:route)
+ @ohai[:network][:interfaces][:eth0].should have_key(:route)
end
it "should set the route details" do
@net_route_conf.each_pair do |k,v|
- # Work around the above doubleing of net_route_list skipping the call to flags()
+ # Work around the above mocking of net_route_list skipping the call to flags()
if k == :flags
v="U"
- @plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v
+ @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v
end
- @plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"].should have_key(k)
- @plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"][k].should eql(v)
+ @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"].should have_key(k)
+ @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k].should eql(v)
end
end
diff --git a/spec/unit/plugins/solaris2/hostname_spec.rb b/spec/unit/plugins/solaris2/hostname_spec.rb
index c7082213..5bf40b2e 100644
--- a/spec/unit/plugins/solaris2/hostname_spec.rb
+++ b/spec/unit/plugins/solaris2/hostname_spec.rb
@@ -21,19 +21,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Solaris2.X hostname plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("solaris2/hostname.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "solaris2"
- @plugin.stub(:from).with("hostname").and_return("kitteh")
- Socket.stub(:getaddrinfo).and_return( [["AF_INET", 0, "kitteh.inurfridge.eatinurfoodz", "10.1.2.3", 2, 0, 0]] );
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "solaris2"
+ @ohai.stub!(:from).with("hostname").and_return("kitteh")
+ Socket.stub!(:getaddrinfo).and_return( [["AF_INET", 0, "kitteh.inurfridge.eatinurfoodz", "10.1.2.3", 2, 0, 0]] );
end
it_should_check_from("solaris2::hostname", "hostname", "hostname", "kitteh")
it "should get the fqdn value from socket getaddrinfo" do
Socket.should_receive(:getaddrinfo)
- @plugin.run
- @plugin["fqdn"].should == "kitteh.inurfridge.eatinurfoodz"
+ @ohai._require_plugin("solaris2::hostname")
+ @ohai["fqdn"].should == "kitteh.inurfridge.eatinurfoodz"
end
-end
+end \ No newline at end of file
diff --git a/spec/unit/plugins/solaris2/kernel_spec.rb b/spec/unit/plugins/solaris2/kernel_spec.rb
index 18bd9b6c..7b50db68 100644
--- a/spec/unit/plugins/solaris2/kernel_spec.rb
+++ b/spec/unit/plugins/solaris2/kernel_spec.rb
@@ -135,29 +135,30 @@ describe Ohai::System, "Solaris2.X kernel plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("solaris2/kernel.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:kernel] = Mash.new
- @plugin.stub(:from).with("uname -s").and_return("SunOS")
- stdin = StringIO.new
- @modinfo_stdout = StringIO.new(MODINFO)
- @plugin.stub(:popen4).with("modinfo").and_yield(nil, stdin, @modinfo_stdout, nil)
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:kernel] = Mash.new
+ @ohai.stub(:from).with("uname -s").and_return("SunOS")
end
it_should_check_from_deep_mash("solaris2::kernel", "kernel", "os", "uname -s", "SunOS")
it "gives excruciating detail about kernel modules" do
- @plugin.run
+ stdin = StringIO.new
+ @modinfo_stdout = StringIO.new(MODINFO)
+ @ohai.stub!(:popen4).with("modinfo").and_yield(nil, stdin, @modinfo_stdout, nil)
+
+ @ohai._require_plugin("solaris2::kernel")
- @plugin[:kernel][:modules].should have(107).modules
+ @ohai[:kernel][:modules].should have(107).modules
# Teh daterz
# Id Loadaddr Size Info Rev Module Name
# 6 1180000 4623 1 1 specfs (filesystem for specfs)
teh_daterz = { "id" => 6, "loadaddr" => "1180000", "size" => 17955, "description" => "filesystem for specfs"}
- @plugin[:kernel][:modules].keys.should include("specfs")
- @plugin[:kernel][:modules].keys.should_not include("Module")
- @plugin[:kernel][:modules]["specfs"].should == teh_daterz
+ @ohai[:kernel][:modules].keys.should include("specfs")
+ @ohai[:kernel][:modules].keys.should_not include("Module")
+ @ohai[:kernel][:modules]["specfs"].should == teh_daterz
end
+
end
diff --git a/spec/unit/plugins/solaris2/network_spec.rb b/spec/unit/plugins/solaris2/network_spec.rb
index a06f43d2..b151502f 100644
--- a/spec/unit/plugins/solaris2/network_spec.rb
+++ b/spec/unit/plugins/solaris2/network_spec.rb
@@ -87,43 +87,41 @@ destination: default
0 0 0 0 0 0 1500 0
ROUTE_GET
+ @stdin = StringIO.new
@ifconfig_lines = solaris_ifconfig.split("\n")
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("solaris2/network.rb", PLUGIN_PATH))
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:network] = Mash.new
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:network] = Mash.new
- @plugin.stub(:popen4).with("ifconfig -a")
- @plugin.stub(:popen4).with("arp -an")
+ @ohai.stub(:popen4).with("ifconfig -a")
+ @ohai.stub(:popen4).with("arp -an")
end
describe "gathering IP layer address info" do
before do
- @stdout = double("Pipe, stdout, cmd=`route get default`", :read => @solaris_route_get)
- @plugin.stub(:popen4).with("route -n get default").and_yield(nil,StringIO.new, @stdout, nil)
- @plugin.stub(:popen4).with("ifconfig -a").and_yield(nil, StringIO.new, @ifconfig_lines, nil)
- @plugin.run
+ @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin, @ifconfig_lines, nil)
+ @ohai._require_plugin("solaris2::network")
end
it "completes the run" do
- @plugin['network'].should_not be_nil
+ @ohai['network'].should_not be_nil
end
it "detects the interfaces" do
- @plugin['network']['interfaces'].keys.sort.should == ["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "lo0", "lo0:3","net0", "qfe1"]
+ @ohai['network']['interfaces'].keys.sort.should == ["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "lo0", "lo0:3", "net0", "qfe1"]
end
it "detects the ip addresses of the interfaces" do
- @plugin['network']['interfaces']['e1000g0:3']['addresses'].keys.should include('72.2.115.28')
+ @ohai['network']['interfaces']['e1000g0:3']['addresses'].keys.should include('72.2.115.28')
end
it "detects the encapsulation type of the interfaces" do
- @plugin['network']['interfaces']['e1000g0:3']['encapsulation'].should == 'Ethernet'
+ @ohai['network']['interfaces']['e1000g0:3']['encapsulation'].should == 'Ethernet'
end
it "detects the L3PROTECT network flag" do
- @plugin['network']['interfaces']['net0']['flags'].should include('L3PROTECT')
+ @ohai['network']['interfaces']['net0']['flags'].should include('L3PROTECT')
end
end
@@ -131,13 +129,13 @@ ROUTE_GET
describe "setting the node's default IP address attribute" do
before do
- @stdout = double("Pipe, stdout, cmd=`route get default`", :read => @solaris_route_get)
- @plugin.stub(:popen4).with("route -n get default").and_yield(nil,StringIO.new, @stdout, nil)
- @plugin.run
+ @stdout = mock("Pipe, stdout, cmd=`route get default`", :read => @solaris_route_get)
+ @ohai.stub!(:popen4).with("route -n get default").and_yield(nil,@stdin, @stdout, nil)
+ @ohai._require_plugin("solaris2::network")
end
it "finds the default interface by asking which iface has the default route" do
- @plugin[:network][:default_interface].should == 'e1000g0'
+ @ohai[:network][:default_interface].should == 'e1000g0'
end
end
end
diff --git a/spec/unit/plugins/solaris2/platform_spec.rb b/spec/unit/plugins/solaris2/platform_spec.rb
index 9739e033..faafc692 100644
--- a/spec/unit/plugins/solaris2/platform_spec.rb
+++ b/spec/unit/plugins/solaris2/platform_spec.rb
@@ -21,11 +21,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Solaris plugin platform" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("solaris2/platform.rb", PLUGIN_PATH))
- @plugin.extend(SimpleFromFile)
- @plugin.stub(:require_plugin).and_return(true)
- @plugin[:os] = "solaris2"
- @plugin.stub(:popen4).with("/sbin/uname -X")
+ @ohai.extend(SimpleFromFile)
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai[:os] = "solaris2"
+ @ohai.stub!(:popen4).with("/sbin/uname -X")
end
describe "on SmartOS" do
@@ -43,33 +42,34 @@ OEM# = 0
Origin# = 1
NumCPU = 16
UNAME_X
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
+ @stderr = mock("STDERR")
@status = 0
@uname_x_lines = uname_x.split("\n")
- File.stub(:exists?).with("/sbin/uname").and_return(true)
- @plugin.stub(:popen4).with("/sbin/uname -X").and_yield(@pid, @stdin, @uname_x_lines, @stderr).and_return(@status)
+ File.stub!(:exists?).with("/sbin/uname").and_return(true)
+ @ohai.stub(:popen4).with("/sbin/uname -X").and_yield(@pid, @stdin, @uname_x_lines, @stderr).and_return(@status)
@release = StringIO.new(" SmartOS 20120130T201844Z x86_64\n")
- File.stub(:open).with("/etc/release").and_yield(@release)
+ @mock_file.stub!(:close).and_return(0)
+ File.stub!(:open).with("/etc/release").and_yield(@release)
end
it "should run uname and set platform and build" do
- @plugin.run
- @plugin[:platform_build].should == "joyent_20120130T201844Z"
+ @ohai._require_plugin("solaris2::platform")
+ @ohai[:platform_build].should == "joyent_20120130T201844Z"
end
it "should set the platform" do
- @plugin.run
- @plugin[:platform].should == "smartos"
+ @ohai._require_plugin("solaris2::platform")
+ @ohai[:platform].should == "smartos"
end
it "should set the platform_version" do
- @plugin.run
- @plugin[:platform_version].should == "5.11"
+ @ohai._require_plugin("solaris2::platform")
+ @ohai[:platform_version].should == "5.11"
end
end
diff --git a/spec/unit/plugins/solaris2/virtualization_spec.rb b/spec/unit/plugins/solaris2/virtualization_spec.rb
index 8a568d8e..53955a15 100644
--- a/spec/unit/plugins/solaris2/virtualization_spec.rb
+++ b/spec/unit/plugins/solaris2/virtualization_spec.rb
@@ -21,60 +21,59 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb')
describe Ohai::System, "Solaris virtualization platform" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("solaris2/virtualization.rb", PLUGIN_PATH))
- @plugin[:os] = "solaris2"
- @plugin.stub(:require_plugin).and_return(true)
- @plugin.extend(SimpleFromFile)
+ @ohai[:os] = "solaris2"
+ @ohai.stub!(:require_plugin).and_return(true)
+ @ohai.extend(SimpleFromFile)
# default to all requested Files not existing
- File.stub(:exists?).with("/usr/sbin/psrinfo").and_return(false)
- File.stub(:exists?).with("/usr/sbin/smbios").and_return(false)
- File.stub(:exists?).with("/usr/sbin/zoneadm").and_return(false)
+ File.stub!(:exists?).with("/usr/sbin/psrinfo").and_return(false)
+ File.stub!(:exists?).with("/usr/sbin/smbios").and_return(false)
+ File.stub!(:exists?).with("/usr/sbin/zoneadm").and_return(false)
end
describe "when we are checking for kvm" do
before(:each) do
File.should_receive(:exists?).with("/usr/sbin/psrinfo").and_return(true)
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 10
- @stderr = double("STDERR")
- @stdout = double("STDOUT")
+ @stderr = mock("STDERR")
+ @stdout = mock("STDOUT")
@status = 0
end
it "should run psrinfo -pv" do
- @plugin.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true)
- @plugin.run
+ @ohai.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true)
+ @ohai._require_plugin("solaris2::virtualization")
end
it "Should set kvm guest if psrinfo -pv contains QEMU Virtual CPU" do
- @stdout.stub(:read).and_return("QEMU Virtual CPU")
- @plugin.stub(:popen4).with("/usr/sbin/psrinfo -pv").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:virtualization][:system].should == "kvm"
- @plugin[:virtualization][:role].should == "guest"
+ @stdout.stub!(:read).and_return("QEMU Virtual CPU")
+ @ohai.stub!(:popen4).with("/usr/sbin/psrinfo -pv").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("solaris2::virtualization")
+ @ohai[:virtualization][:system].should == "kvm"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should not set virtualization if kvm isn't there" do
- @plugin.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true)
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true)
+ @ohai._require_plugin("solaris2::virtualization")
+ @ohai[:virtualization].should == {}
end
end
describe "when we are parsing smbios" do
before(:each) do
File.should_receive(:exists?).with("/usr/sbin/smbios").and_return(true)
- @stdin = double("STDIN", { :close => true })
+ @stdin = mock("STDIN", { :close => true })
@pid = 20
- @stderr = double("STDERR")
- @stdout = double("STDOUT")
+ @stderr = mock("STDERR")
+ @stdout = mock("STDOUT")
@status = 0
end
it "should run smbios" do
- @plugin.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true)
- @plugin.run
+ @ohai.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true)
+ @ohai._require_plugin("solaris2::virtualization")
end
it "should set virtualpc guest if smbios detects Microsoft Virtual Machine" do
@@ -90,12 +89,12 @@ ID SIZE TYPE
UUID: D29974A4-BE51-044C-BDC6-EFBC4B87A8E9
Wake-Up Event: 0x6 (power switch)
MSVPC
- @stdout.stub(:read).and_return(ms_vpc_smbios)
+ @stdout.stub!(:read).and_return(ms_vpc_smbios)
- @plugin.stub(:popen4).with("/usr/sbin/smbios").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:virtualization][:system].should == "virtualpc"
- @plugin[:virtualization][:role].should == "guest"
+ @ohai.stub!(:popen4).with("/usr/sbin/smbios").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("solaris2::virtualization")
+ @ohai[:virtualization][:system].should == "virtualpc"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should set vmware guest if smbios detects VMware Virtual Platform" do
@@ -111,23 +110,23 @@ ID SIZE TYPE
UUID: a86cc405-e1b9-447b-ad05-6f8db39d876a
Wake-Up Event: 0x6 (power switch)
VMWARE
- @stdout.stub(:read).and_return(vmware_smbios)
- @plugin.stub(:popen4).with("/usr/sbin/smbios").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
- @plugin.run
- @plugin[:virtualization][:system].should == "vmware"
- @plugin[:virtualization][:role].should == "guest"
+ @stdout.stub!(:read).and_return(vmware_smbios)
+ @ohai.stub!(:popen4).with("/usr/sbin/smbios").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status)
+ @ohai._require_plugin("solaris2::virtualization")
+ @ohai[:virtualization][:system].should == "vmware"
+ @ohai[:virtualization][:role].should == "guest"
end
it "should run smbios and not set virtualization if nothing is detected" do
- @plugin.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true)
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true)
+ @ohai._require_plugin("solaris2::virtualization")
+ @ohai[:virtualization].should == {}
end
end
it "should not set virtualization if no tests match" do
- @plugin.run
- @plugin[:virtualization].should == {}
+ @ohai._require_plugin("solaris2::virtualization")
+ @ohai[:virtualization].should == {}
end
end
diff --git a/spec/unit/plugins/ssh_host_keys_spec.rb b/spec/unit/plugins/ssh_host_keys_spec.rb
index 16303591..ab7fa098 100644
--- a/spec/unit/plugins/ssh_host_keys_spec.rb
+++ b/spec/unit/plugins/ssh_host_keys_spec.rb
@@ -22,12 +22,11 @@ describe Ohai::System, "ssh_host_key plugin" do
before(:each) do
@ohai = Ohai::System.new
- @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ssh_host_key.rb"))
- @plugin.stub(:require_plugin)
- @plugin[:keys] = Mash.new
+ @ohai[:keys] = Mash.new
+ @ohai.stub(:require_plugin).and_return(true)
# Avoid using the real from_file to load the plugin => less stubbing required
- @plugin.extend(SimpleFromFile)
+ @ohai.extend(SimpleFromFile)
File.stub(:exists?).with("/etc/ssh/sshd_config").and_return(true)
File.stub(:open).with("/etc/ssh/sshd_config").and_yield(sshd_config_file)
@@ -51,21 +50,21 @@ describe Ohai::System, "ssh_host_key plugin" do
shared_examples "loads keys" do
it "reads the key and sets the dsa attribute correctly" do
- @plugin.run
- @plugin[:keys][:ssh][:host_dsa_public].should eql(@dsa_key.split[1])
- @plugin[:keys][:ssh][:host_dsa_type].should be_nil
+ @ohai._require_plugin("ssh_host_key")
+ @ohai[:keys][:ssh][:host_dsa_public].should eql(@dsa_key.split[1])
+ @ohai[:keys][:ssh][:host_dsa_type].should be_nil
end
it "reads the key and sets the rsa attribute correctly" do
- @plugin.run
- @plugin[:keys][:ssh][:host_rsa_public].should eql(@rsa_key.split[1])
- @plugin[:keys][:ssh][:host_rsa_type].should be_nil
+ @ohai._require_plugin("ssh_host_key")
+ @ohai[:keys][:ssh][:host_rsa_public].should eql(@rsa_key.split[1])
+ @ohai[:keys][:ssh][:host_rsa_type].should be_nil
end
it "reads the key and sets the ecdsa attribute correctly" do
- @plugin.run
- @plugin[:keys][:ssh][:host_ecdsa_public].should eql(@ecdsa_key.split[1])
- @plugin[:keys][:ssh][:host_ecdsa_type].should eql(@ecdsa_key.split[0])
+ @ohai._require_plugin("ssh_host_key")
+ @ohai[:keys][:ssh][:host_ecdsa_public].should eql(@ecdsa_key.split[1])
+ @ohai[:keys][:ssh][:host_ecdsa_type].should eql(@ecdsa_key.split[0])
end
end
diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb
index b2fcd536..fcaf8b74 100644
--- a/spec/unit/system_spec.rb
+++ b/spec/unit/system_spec.rb
@@ -22,44 +22,109 @@ describe Ohai::System, "initialize" do
it "should return an Ohai::System object" do
Ohai::System.new.should be_a_kind_of(Ohai::System)
end
-
+
it "should set @data to a Mash" do
Ohai::System.new.data.should be_a_kind_of(Mash)
end
-
+
it "should set @seen_plugins to a Hash" do
Ohai::System.new.seen_plugins.should be_a_kind_of(Hash)
end
end
+describe Ohai::System, "method_missing" do
+ before(:each) do
+ @ohai = Ohai::System.new
+ end
+
+ it "should take a missing method and store the method name as a key, with its arguments as values" do
+ @ohai.guns_n_roses("chinese democracy")
+ @ohai.data["guns_n_roses"].should eql("chinese democracy")
+ end
+
+ it "should return the current value of the method name" do
+ @ohai.guns_n_roses("chinese democracy").should eql("chinese democracy")
+ end
+
+ it "should allow you to get the value of a key by calling method_missing with no arguments" do
+ @ohai.guns_n_roses("chinese democracy")
+ @ohai.guns_n_roses.should eql("chinese democracy")
+ end
+end
+
+describe Ohai::System, "attribute?" do
+ before(:each) do
+ @ohai = Ohai::System.new
+ @ohai.metallica("death magnetic")
+ end
+
+ it "should return true if an attribute exists with the given name" do
+ @ohai.attribute?("metallica").should eql(true)
+ end
+
+ it "should return false if an attribute does not exist with the given name" do
+ @ohai.attribute?("alice in chains").should eql(false)
+ end
+end
+
+describe Ohai::System, "set_attribute" do
+ before(:each) do
+ @ohai = Ohai::System.new
+ end
+
+ it "should let you set an attribute" do
+ @ohai.set_attribute(:tea, "is soothing")
+ @ohai.data["tea"].should eql("is soothing")
+ end
+end
+
+describe Ohai::System, "get_attribute" do
+ before(:each) do
+ @ohai = Ohai::System.new
+ @ohai.set_attribute(:tea, "is soothing")
+ end
+
+ it "should let you get an attribute" do
+ @ohai.get_attribute("tea").should eql("is soothing")
+ end
+end
+
describe Ohai::System, "require_plugin" do
tmp = ENV['TMPDIR'] || ENV['TMP'] || ENV['TEMP'] || '/tmp'
before(:each) do
@plugin_path = Ohai::Config[:plugin_path]
- Ohai::Config[:plugin_path] = [SPEC_PLUGIN_PATH]
+ Ohai::Config[:plugin_path] = ["#{tmp}/plugins"]
+ File.stub!(:exists?).and_return(true)
@ohai = Ohai::System.new
+ @ohai.stub!(:from_file).and_return(true)
end
after(:each) do
Ohai::Config[:plugin_path] = @plugin_path
end
-
+
+ it "should convert the name of the plugin to a file path" do
+ plugin_name = "foo::bar"
+ plugin_name.should_receive(:gsub).with("::", File::SEPARATOR)
+ @ohai.require_plugin(plugin_name)
+ end
+
it "should check each part of the Ohai::Config[:plugin_path] for the plugin_filename.rb" do
- plugin = @ohai.plugin_for("foo")
- plugin.file.should == File.expand_path("foo.rb", SPEC_PLUGIN_PATH)
+ @ohai.should_receive(:from_file).with(File.expand_path("#{tmp}/plugins/foo.rb")).and_return(true)
+ @ohai.require_plugin("foo")
end
it "should add a found plugin to the list of seen plugins" do
@ohai.require_plugin("foo")
@ohai.seen_plugins["foo"].should eql(true)
end
-
+
it "should return true if the plugin has been seen" do
@ohai.seen_plugins["foo"] = true
@ohai.require_plugin("foo")
end
-
+
it "should return true if the plugin has been loaded" do
@ohai.require_plugin("foo").should eql(true)
end
@@ -74,8 +139,8 @@ end
describe Ohai::System, "all_plugins" do
before(:each) do
@ohai = Ohai::System.new
- @ohai.stub(:from_file).and_return(true)
- @ohai.stub(:require_plugin).and_return(false)
+ @ohai.stub!(:from_file).and_return(true)
+ @ohai.stub!(:require_plugin).and_return(false)
@ohai.data[:os] = "ubuntu"
end