diff options
author | danielsdeleo <dan@opscode.com> | 2013-07-15 12:00:48 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-07-15 12:00:48 -0700 |
commit | 8fb18d853f19a4bc2cc01dfb80bf025a54ef8d76 (patch) | |
tree | ba0c13b22a208ad909e52e43bd884018e1a59dff | |
parent | 17aaf51cf13f770242ef59fe4c8cc60502d8926a (diff) | |
parent | 8d6c195b3bf99090383acc9fa36248f76afcaf54 (diff) | |
download | ohai-8fb18d853f19a4bc2cc01dfb80bf025a54ef8d76.tar.gz |
Merge branch 'OHAI-412' into OHAI-412-plus
79 files changed, 2300 insertions, 2214 deletions
diff --git a/lib/ohai/dsl/plugin.rb b/lib/ohai/dsl/plugin.rb new file mode 100644 index 00000000..edc02af5 --- /dev/null +++ b/lib/ohai/dsl/plugin.rb @@ -0,0 +1,136 @@ +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/seconds_to_human.rb b/lib/ohai/mixin/seconds_to_human.rb new file mode 100644 index 00000000..c5fad1b8 --- /dev/null +++ b/lib/ohai/mixin/seconds_to_human.rb @@ -0,0 +1,48 @@ +# +# 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/darwin/uptime.rb b/lib/ohai/plugins/darwin/uptime.rb index d9cf01f5..ea258ec4 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 self._seconds_to_human(uptime_seconds) + uptime 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 7d0da153..ea49fa09 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 self._seconds_to_human(uptime_seconds) + uptime seconds_to_human(uptime_seconds) end end end diff --git a/lib/ohai/plugins/linode.rb b/lib/ohai/plugins/linode.rb index 69613857..2be916e5 100644 --- a/lib/ohai/plugins/linode.rb +++ b/lib/ohai/plugins/linode.rb @@ -23,7 +23,9 @@ require_plugin "network" # # Returns true or false def has_linode_kernel? - kernel[:release].split('-').last =~ /linode/ + if kernel_data = kernel + kernel_data[:release].split('-').last =~ /linode/ + end end # Identifies the linode cloud by preferring the hint, then @@ -40,8 +42,10 @@ end # # Alters linode mash with new interface based on name parameter def get_ip_address(name, eth) - network[:interfaces][eth][:addresses].each do |key, info| - linode[name] = key if info['family'] == 'inet' + if eth_iface = network[:interfaces][eth] + eth_iface[:addresses].each do |key, info| + linode[name] = key if info['family'] == 'inet' + end end end diff --git a/lib/ohai/plugins/linux/uptime.rb b/lib/ohai/plugins/linux/uptime.rb index 047cfc19..29f48eec 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 self._seconds_to_human(uptime.to_i) +uptime seconds_to_human(uptime.to_i) idletime_seconds idletime.to_i -idletime self._seconds_to_human(idletime.to_i) +idletime seconds_to_human(idletime.to_i) diff --git a/lib/ohai/plugins/netbsd/uptime.rb b/lib/ohai/plugins/netbsd/uptime.rb index 85f3588a..75470735 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 self._seconds_to_human(uptime_seconds) + uptime 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 3d903321..6028d1e7 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 self._seconds_to_human(uptime_seconds) + uptime 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 5d2923d1..8d43d73a 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 self._seconds_to_human(uptime.to_i) +uptime seconds_to_human(uptime.to_i) diff --git a/lib/ohai/plugins/solaris2/uptime.rb b/lib/ohai/plugins/solaris2/uptime.rb index e39dfcf8..804e9da5 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 self._seconds_to_human(uptime_seconds) + uptime seconds_to_human(uptime_seconds) break end end diff --git a/lib/ohai/plugins/uptime.rb b/lib/ohai/plugins/uptime.rb index 1930a746..c5f9c58f 100644 --- a/lib/ohai/plugins/uptime.rb +++ b/lib/ohai/plugins/uptime.rb @@ -16,27 +16,4 @@ # 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 7ad4ab75..2dcc0e48 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 self._seconds_to_human(uptime_seconds) +uptime seconds_to_human(uptime_seconds) diff --git a/lib/ohai/system.rb b/lib/ohai/system.rb index 8721be32..8e5e212a 100644 --- a/lib/ohai/system.rb +++ b/lib/ohai/system.rb @@ -18,6 +18,7 @@ require 'ohai/mash' require 'ohai/log' +require 'ohai/dsl/plugin' require 'ohai/mixin/from_file' require 'ohai/mixin/command' require 'ohai/mixin/string' @@ -27,10 +28,10 @@ require 'yajl' module Ohai class System - attr_accessor :data, :seen_plugins, :hints - - include Ohai::Mixin::FromFile - include Ohai::Mixin::Command + attr_accessor :data + attr_reader :seen_plugins + attr_reader :hints + attr_reader :providers def initialize @data = Mash.new @@ -44,87 +45,6 @@ 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') @@ -204,30 +124,37 @@ module Ohai return false end - @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)) + if plugin = plugin_for(plugin_name) + @seen_plugins[plugin_name] = true begin - @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}") + plugin.run + true 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 - # 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 + 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 # Serialize this object as a hash def to_json @@ -259,18 +186,6 @@ 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/spec/data/plugins/foo.rb b/spec/data/plugins/foo.rb new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/spec/data/plugins/foo.rb diff --git a/spec/ohai/dsl/plugin_spec.rb b/spec/ohai/dsl/plugin_spec.rb new file mode 100644 index 00000000..d0c30747 --- /dev/null +++ b/spec/ohai/dsl/plugin_spec.rb @@ -0,0 +1,76 @@ +# +# 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 8f41764f..2119dc7b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,41 +7,44 @@ 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 - @ohai._require_plugin(plugin) - @ohai[attribute].should == value + @plugin.run + @plugin[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 - @ohai.should_receive(:from).with(from).and_return(value) - @ohai._require_plugin(plugin) + @plugin.should_receive(:from).with(from).and_return(value) + @plugin.run end it "should set the #{plugin}[:#{attribute}] to the value from '#{from}'" do - @ohai._require_plugin(plugin) - @ohai[plugin][attribute].should == value + @plugin.run + @plugin[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 - @ohai.should_receive(:from).with(from).and_return(value) - @ohai._require_plugin(plugin) + @plugin.should_receive(:from).with(from).and_return(value) + @plugin.run end it "should set the #{mash.inspect}[:#{attribute}] to the value from '#{from}'" do - @ohai._require_plugin(plugin) + @plugin.run if mash.is_a?(String) - @ohai[mash][attribute].should == value + @plugin[mash][attribute].should == value elsif mash.is_a?(Array) if mash.length == 2 - @ohai[mash[0]][mash[1]][attribute].should == value + @plugin[mash[0]][mash[1]][attribute].should == value elsif mash.length == 3 - @ohai[mash[0]][mash[1]][mash[2]][attribute].should == value + @plugin[mash[0]][mash[1]][mash[2]][attribute].should == value else return nil end diff --git a/spec/unit/mixin/from_file_spec.rb b/spec/unit/mixin/from_file_spec.rb deleted file mode 100644 index ce8fc421..00000000 --- a/spec/unit/mixin/from_file_spec.rb +++ /dev/null @@ -1,53 +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. -# - -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/azure_spec.rb b/spec/unit/plugins/azure_spec.rb index 31879546..c347a273 100644 --- a/spec/unit/plugins/azure_spec.rb +++ b/spec/unit/plugins/azure_spec.rb @@ -23,7 +23,7 @@ require 'open-uri' describe Ohai::System, "plugin azure" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("azure.rb", PLUGIN_PATH)) end describe "with azure cloud file" do @@ -32,16 +32,16 @@ describe Ohai::System, "plugin azure" do 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") + @plugin.run end it 'should set the azure cloud attributes' do - @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" + @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" end end @@ -53,7 +53,7 @@ describe Ohai::System, "plugin azure" do end it 'should not behave like azure' do - @ohai[:azure].should be_nil + @plugin[:azure].should be_nil end end @@ -66,7 +66,7 @@ describe Ohai::System, "plugin azure" do end it 'should not behave like azure' do - @ohai[:azure].should be_nil + @plugin[:azure].should be_nil end end diff --git a/spec/unit/plugins/c_spec.rb b/spec/unit/plugins/c_spec.rb index 7083ce44..7cd832e7 100644 --- a/spec/unit/plugins/c_spec.rb +++ b/spec/unit/plugins/c_spec.rb @@ -104,204 +104,208 @@ describe Ohai::System, "plugin c" do before(:each) do @ohai = Ohai::System.new - @ohai[:languages] = Mash.new - @ohai.stub!(:require_plugin).and_return(true) + @path = File.join(PLUGIN_PATH, "c.rb") + @plugin = Ohai::DSL::Plugin.new(@ohai, @path) + + + @plugin[:languages] = Mash.new #gcc - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC]) + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC]) #glibc - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""]) + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"/lib/libc.so.6"}).and_return([0, C_GLIBC_2_3_4, ""]) #ms cl - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL]) + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL]) #ms vs - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""]) + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""]) #ibm xlc - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""]) + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""]) #sun pro - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN]) + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN]) #hpux cc - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([0, C_HPUX, ""]) + @plugin.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 - @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC]) - @ohai._require_plugin("c") + @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"gcc -v"}).and_return([0, "", C_GCC]) + @plugin.run end it "should set languages[:c][:gcc][:version]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:gcc][:version].should eql("3.4.6") + @plugin.run + @plugin.languages[:c][:gcc][:version].should eql("3.4.6") end it "should set languages[:c][:gcc][:description]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:gcc][:description].should eql(C_GCC.split($/).last) + @plugin.run + @plugin.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 - @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] + @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] end #glibc it "should get the glibc x.x.x version from running /lib/libc.so.6" do - @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") + @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 end it "should set languages[:c][:glibc][:version]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:glibc][:version].should eql("2.3.4") + @plugin.run + @plugin.languages[:c][:glibc][:version].should eql("2.3.4") end it "should set languages[:c][:glibc][:description]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:glibc][:description].should eql(C_GLIBC_2_3_4.split($/).first) + @plugin.run + @plugin.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 - @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] + @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] end it "should get the glibc x.x version from running /lib/libc.so.6" do - @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") + @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") end #ms cl it "should get the cl version from running cl /?" do - @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL]) - @ohai._require_plugin("c") + @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"cl /\?"}).and_return([0, "", C_CL]) + @plugin.run end it "should set languages[:c][:cl][:version]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:cl][:version].should eql("14.00.50727.762") + @plugin.run + @plugin.languages[:c][:cl][:version].should eql("14.00.50727.762") end it "should set languages[:c][:cl][:description]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:cl][:description].should eql(C_CL.split($/).first) + @plugin.run + @plugin.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 - @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] + @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] end #ms vs it "should get the vs version from running devenv.com /?" do - @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""]) - @ohai._require_plugin("c") + @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"devenv.com /\?"}).and_return([0, C_VS, ""]) + @plugin.run end it "should set languages[:c][:vs][:version]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:vs][:version].should eql("8.0.50727.762") + @plugin.run + @plugin.languages[:c][:vs][:version].should eql("8.0.50727.762") end it "should set languages[:c][:vs][:description]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:vs][:description].should eql(C_VS.split($/)[1]) + @plugin.run + @plugin.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 - @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] + @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] end #ibm xlc it "should get the xlc version from running xlc -qversion" do - @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""]) - @ohai._require_plugin("c") + @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"xlc -qversion"}).and_return([0, C_XLC, ""]) + @plugin.run end it "should set languages[:c][:xlc][:version]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:xlc][:version].should eql("9.0") + @plugin.run + @plugin.languages[:c][:xlc][:version].should eql("9.0") end it "should set languages[:c][:xlc][:description]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:xlc][:description].should eql(C_XLC.split($/).first) + @plugin.run + @plugin.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 - @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] + @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] end it "should set the languages[:c][:xlc] tree up if xlc exit status is 249" do - @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] + @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] end #sun pro it "should get the cc version from running cc -V -flags" do - @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN]) - @ohai._require_plugin("c") + @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"cc -V -flags"}).and_return([0, "", C_SUN]) + @plugin.run end it "should set languages[:c][:sunpro][:version]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:sunpro][:version].should eql("5.8") + @plugin.run + @plugin.languages[:c][:sunpro][:version].should eql("5.8") end it "should set languages[:c][:sunpro][:description]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:sunpro][:description].should eql(C_SUN.chomp) + @plugin.run + @plugin.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 - @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] + @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] 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" - @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] + @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] 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]" - @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] + @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] end #hpux cc it "should get the cc version from running what cc" do - @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") + @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"what /opt/ansic/bin/cc"}).and_return([0, C_HPUX, ""]) + @plugin.run end it "should set languages[:c][:hpcc][:version]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:hpcc][:version].should eql("B.11.11.16") + @plugin.run + @plugin.languages[:c][:hpcc][:version].should eql("B.11.11.16") end it "should set languages[:c][:hpcc][:description]" do - @ohai._require_plugin("c") - @ohai.languages[:c][:hpcc][:description].should eql(C_HPUX.split($/)[3].strip) + @plugin.run + @plugin.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 - @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] + @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] end end diff --git a/spec/unit/plugins/chef_spec.rb b/spec/unit/plugins/chef_spec.rb index 5d76c095..716876b9 100644 --- a/spec/unit/plugins/chef_spec.rb +++ b/spec/unit/plugins/chef_spec.rb @@ -26,7 +26,7 @@ begin describe Ohai::System, "plugin chef" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "chef.rb")) end it "should set [:chef_packages][:chef][:version] to the current chef version", :if => defined?(Chef) do @@ -35,8 +35,8 @@ begin end pending "would set [:chef_packages][:chef][:version] if chef was available", :unless => defined?(Chef) - 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 00e0c179..07e14b0e 100644 --- a/spec/unit/plugins/cloud_spec.rb +++ b/spec/unit/plugins/cloud_spec.rb @@ -20,187 +20,188 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin cloud" do before do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("cloud.rb", PLUGIN_PATH)) + @plugin.stub(:require_plugin) end describe "with no cloud mashes" do it "doesn't populate the cloud data" do - @ohai[:ec2] = nil - @ohai[:rackspace] = nil - @ohai[:eucalyptus] = nil - @ohai[:linode] = nil - @ohai[:azure] = nil - @ohai._require_plugin("cloud") - @ohai[:cloud].should be_nil + @plugin[:ec2] = nil + @plugin[:rackspace] = nil + @plugin[:eucalyptus] = nil + @plugin[:linode] = nil + @plugin[:azure] = nil + @plugin.run + @plugin[:cloud].should be_nil end end describe "with EC2 mash" do before do - @ohai[:ec2] = Mash.new() + @plugin[:ec2] = Mash.new() end it "populates cloud public ip" do - @ohai[:ec2]['public_ipv4'] = "174.129.150.8" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_ips][0].should == @ohai[:ec2]['public_ipv4'] + @plugin[:ec2]['public_ipv4'] = "174.129.150.8" + @plugin.run + @plugin[:cloud][:public_ips][0].should == @plugin[:ec2]['public_ipv4'] end it "populates cloud private ip" do - @ohai[:ec2]['local_ipv4'] = "10.252.42.149" - @ohai._require_plugin("cloud") - @ohai[:cloud][:private_ips][0].should == @ohai[:ec2]['local_ipv4'] + @plugin[:ec2]['local_ipv4'] = "10.252.42.149" + @plugin.run + @plugin[:cloud][:private_ips][0].should == @plugin[:ec2]['local_ipv4'] end it "populates cloud provider" do - @ohai._require_plugin("cloud") - @ohai[:cloud][:provider].should == "ec2" + @plugin.run + @plugin[:cloud][:provider].should == "ec2" end end describe "with rackspace" do before do - @ohai[:rackspace] = Mash.new() + @plugin[:rackspace] = Mash.new() end it "populates cloud public ip" do - @ohai[:rackspace][:public_ipv4] = "174.129.150.8" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_ipv4].should == @ohai[:rackspace][:public_ipv4] + @plugin[:rackspace][:public_ipv4] = "174.129.150.8" + @plugin.run + @plugin[:cloud][:public_ipv4].should == @plugin[:rackspace][:public_ipv4] end it "populates cloud public ipv6" do - @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] + @plugin[:rackspace][:public_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75" + @plugin.run + @plugin[:cloud][:public_ipv6].should == @plugin[:rackspace][:public_ipv6] end it "populates cloud private ip" do - @ohai[:rackspace][:local_ipv4] = "10.252.42.149" - @ohai._require_plugin("cloud") - @ohai[:cloud][:local_ipv4].should == @ohai[:rackspace][:local_ipv4] + @plugin[:rackspace][:local_ipv4] = "10.252.42.149" + @plugin.run + @plugin[:cloud][:local_ipv4].should == @plugin[:rackspace][:local_ipv4] end it "populates cloud private ipv6" do - @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] + @plugin[:rackspace][:local_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75" + @plugin.run + @plugin[:cloud][:local_ipv6].should == @plugin[:rackspace][:local_ipv6] end it "populates first cloud public ip" do - @ohai[:rackspace][:public_ipv4] = "174.129.150.8" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_ips].first.should == @ohai[:rackspace][:public_ipv4] + @plugin[:rackspace][:public_ipv4] = "174.129.150.8" + @plugin.run + @plugin[:cloud][:public_ips].first.should == @plugin[:rackspace][:public_ipv4] end it "populates first cloud public ip" do - @ohai[:rackspace][:local_ipv4] = "174.129.150.8" - @ohai._require_plugin("cloud") - @ohai[:cloud][:private_ips].first.should == @ohai[:rackspace][:local_ipv4] + @plugin[:rackspace][:local_ipv4] = "174.129.150.8" + @plugin.run + @plugin[:cloud][:private_ips].first.should == @plugin[:rackspace][:local_ipv4] end it "populates cloud provider" do - @ohai._require_plugin("cloud") - @ohai[:cloud][:provider].should == "rackspace" + @plugin.run + @plugin[:cloud][:provider].should == "rackspace" end end describe "with linode mash" do before do - @ohai[:linode] = Mash.new() + @plugin[:linode] = Mash.new() end it "populates cloud public ip" do - @ohai[:linode]['public_ip'] = "174.129.150.8" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_ips][0].should == @ohai[:linode][:public_ip] + @plugin[:linode]['public_ip'] = "174.129.150.8" + @plugin.run + @plugin[:cloud][:public_ips][0].should == @plugin[:linode][:public_ip] end it "populates cloud private ip" do - @ohai[:linode]['private_ip'] = "10.252.42.149" - @ohai._require_plugin("cloud") - @ohai[:cloud][:private_ips][0].should == @ohai[:linode][:private_ip] + @plugin[:linode]['private_ip'] = "10.252.42.149" + @plugin.run + @plugin[:cloud][:private_ips][0].should == @plugin[:linode][:private_ip] end it "populates first cloud public ip" do - @ohai[:linode]['public_ip'] = "174.129.150.8" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_ips].first.should == @ohai[:linode][:public_ip] + @plugin[:linode]['public_ip'] = "174.129.150.8" + @plugin.run + @plugin[:cloud][:public_ips].first.should == @plugin[:linode][:public_ip] end it "populates cloud provider" do - @ohai._require_plugin("cloud") - @ohai[:cloud][:provider].should == "linode" + @plugin.run + @plugin[:cloud][:provider].should == "linode" end end describe "with eucalyptus mash" do before do - @ohai[:eucalyptus] = Mash.new() + @plugin[:eucalyptus] = Mash.new() end it "populates cloud public ip" do - @ohai[:eucalyptus]['public_ipv4'] = "174.129.150.8" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_ips][0].should == @ohai[:eucalyptus]['public_ipv4'] + @plugin[:eucalyptus]['public_ipv4'] = "174.129.150.8" + @plugin.run + @plugin[:cloud][:public_ips][0].should == @plugin[:eucalyptus]['public_ipv4'] end it "populates cloud private ip" do - @ohai[:eucalyptus]['local_ipv4'] = "10.252.42.149" - @ohai._require_plugin("cloud") - @ohai[:cloud][:private_ips][0].should == @ohai[:eucalyptus]['local_ipv4'] + @plugin[:eucalyptus]['local_ipv4'] = "10.252.42.149" + @plugin.run + @plugin[:cloud][:private_ips][0].should == @plugin[:eucalyptus]['local_ipv4'] end it "populates cloud provider" do - @ohai._require_plugin("cloud") - @ohai[:cloud][:provider].should == "eucalyptus" + @plugin.run + @plugin[:cloud][:provider].should == "eucalyptus" end end describe "with Azure mash" do before do - @ohai[:azure] = Mash.new() + @plugin[:azure] = Mash.new() end it "populates cloud public ip" do - @ohai[:azure]['public_ip'] = "174.129.150.8" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_ips][0].should == @ohai[:azure]['public_ip'] + @plugin[:azure]['public_ip'] = "174.129.150.8" + @plugin.run + @plugin[:cloud][:public_ips][0].should == @plugin[:azure]['public_ip'] end it "populates cloud vm_name" do - @ohai[:azure]['vm_name'] = "linux-vm" - @ohai._require_plugin("cloud") - @ohai[:cloud][:vm_name].should == @ohai[:azure]['vm_name'] + @plugin[:azure]['vm_name'] = "linux-vm" + @plugin.run + @plugin[:cloud][:vm_name].should == @plugin[:azure]['vm_name'] end it "populates cloud public_fqdn" do - @ohai[:azure]['public_fqdn'] = "linux-vm-svc.cloudapp.net" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_fqdn].should == @ohai[:azure]['public_fqdn'] + @plugin[:azure]['public_fqdn'] = "linux-vm-svc.cloudapp.net" + @plugin.run + @plugin[:cloud][:public_fqdn].should == @plugin[:azure]['public_fqdn'] end it "populates cloud public_ssh_port" do - @ohai[:azure]['public_ssh_port'] = "22" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_ssh_port].should == @ohai[:azure]['public_ssh_port'] + @plugin[:azure]['public_ssh_port'] = "22" + @plugin.run + @plugin[:cloud][:public_ssh_port].should == @plugin[:azure]['public_ssh_port'] end it "should not populate cloud public_ssh_port when winrm is used" do - @ohai[:azure]['public_winrm_port'] = "5985" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_ssh_port].should be_nil + @plugin[:azure]['public_winrm_port'] = "5985" + @plugin.run + @plugin[:cloud][:public_ssh_port].should be_nil end it "populates cloud public_winrm_port" do - @ohai[:azure]['public_winrm_port'] = "5985" - @ohai._require_plugin("cloud") - @ohai[:cloud][:public_winrm_port].should == @ohai[:azure]['public_winrm_port'] + @plugin[:azure]['public_winrm_port'] = "5985" + @plugin.run + @plugin[:cloud][:public_winrm_port].should == @plugin[:azure]['public_winrm_port'] end it "populates cloud provider" do - @ohai._require_plugin("cloud") - @ohai[:cloud][:provider].should == "azure" + @plugin.run + @plugin[: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 1989d35d..dd94b144 100644 --- a/spec/unit/plugins/darwin/cpu_spec.rb +++ b/spec/unit/plugins/darwin/cpu_spec.rb @@ -22,19 +22,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin cpu plugin" do before(:each) do @ohai = Ohai::System.new - @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") + @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") end it "should set cpu[:total] to 2" do - @ohai._require_plugin("darwin::cpu") - @ohai[:cpu][:total].should == 2 + @plugin.run + @plugin[:cpu][:total].should == 2 end it "should set cpu[:real] to 1" do - @ohai._require_plugin("darwin::cpu") - @ohai[:cpu][:real].should == 1 + @plugin.run + @plugin[: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 3136af10..493bf861 100644 --- a/spec/unit/plugins/darwin/hostname_spec.rb +++ b/spec/unit/plugins/darwin/hostname_spec.rb @@ -22,13 +22,14 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin hostname plugin" do before(:each) do @ohai = Ohai::System.new - @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") + @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") end it_should_check_from("darwin::hostname", "hostname", "hostname -s", "katie") it_should_check_from("darwin::hostname", "fqdn", "hostname", "katie.bethell") -end
\ No newline at end of file +end diff --git a/spec/unit/plugins/darwin/kernel_spec.rb b/spec/unit/plugins/darwin/kernel_spec.rb index 9954f968..5ce7c1ba 100644 --- a/spec/unit/plugins/darwin/kernel_spec.rb +++ b/spec/unit/plugins/darwin/kernel_spec.rb @@ -21,26 +21,28 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin kernel plugin" do before(:each) do - @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:kernel] = Mash.new - @ohai[:kernel][:name] = "darwin" + @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) end - + it "should not set kernel_machine to x86_64" do - @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' + @plugin.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("0") + @plugin.run + @plugin[:kernel][:machine].should_not == 'x86_64' end - + it "should set kernel_machine to x86_64" do - @ohai.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("1") - @ohai._require_plugin("darwin::kernel") - @ohai[:kernel][:machine].should == 'x86_64' + @plugin.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("1") + @plugin.run + @plugin[:kernel][:machine].should == 'x86_64' end - + it "should set the kernel_os to the kernel_name value" do - @ohai._require_plugin("darwin::kernel") - @ohai[:kernel][:os].should == @ohai[:kernel][:name] + @plugin.stub!(:from).with("sysctl -n hw.optional.x86_64").and_return("1") + @plugin.run + @plugin[:kernel][:os].should == @plugin[:kernel][:name] end -end
\ No newline at end of file +end diff --git a/spec/unit/plugins/darwin/network_spec.rb b/spec/unit/plugins/darwin/network_spec.rb index 52ab355f..d475e8e2 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 - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("darwin/network.rb", PLUGIN_PATH)) @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") - @ohai.stub(:from).with("route -n get default").and_return(darwin_route) - @ohai.stub(:popen4).with("netstat -i -d -l -b -n") + @plugin.stub(:from).with("route -n get default").and_return(darwin_route) + @plugin.stub(:popen4).with("netstat -i -d -l -b -n") - Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(3).times - @ohai._require_plugin("network") + Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(6).times + @plugin.require_plugin("network") end describe "gathering IP layer address info" do before do - @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") + @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 end it "completes the run" do - @ohai['network'].should_not be_nil + @plugin['network'].should_not be_nil end it "detects the interfaces" do - @ohai['network']['interfaces'].keys.sort.should == ["en0", "en1", "fw0", "gif0", "lo0", "p2p0", "stf0", "utun0"] + @plugin['network']['interfaces'].keys.sort.should == ["en0", "en1", "fw0", "gif0", "lo0", "p2p0", "stf0", "utun0"] end it "detects the ipv4 addresses of the ethernet interface" do - @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' + @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' end it "detects the ipv6 addresses of the ethernet interface" do - @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' + @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' end it "detects the mac addresses of the ethernet interface" do - @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' + @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' end it "detects the encapsulation type of the ethernet interface" do - @ohai['network']['interfaces']['en1']['encapsulation'].should == 'Ethernet' + @plugin['network']['interfaces']['en1']['encapsulation'].should == 'Ethernet' end it "detects the flags of the ethernet interface" do - @ohai['network']['interfaces']['en1']['flags'].sort.should == ["BROADCAST", "MULTICAST", "RUNNING", "SIMPLEX", "SMART", "UP"] + @plugin['network']['interfaces']['en1']['flags'].sort.should == ["BROADCAST", "MULTICAST", "RUNNING", "SIMPLEX", "SMART", "UP"] end it "detects the mtu of the ethernet interface" do - @ohai['network']['interfaces']['en1']['mtu'].should == "1500" + @plugin['network']['interfaces']['en1']['mtu'].should == "1500" end it "detects the ipv4 addresses of the loopback interface" do - @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' + @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' end it "detects the ipv6 addresses of the loopback interface" do - @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' + @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' end it "detects the encapsulation type of the loopback interface" do - @ohai['network']['interfaces']['lo0']['encapsulation'].should == 'Loopback' + @plugin['network']['interfaces']['lo0']['encapsulation'].should == 'Loopback' end it "detects the flags of the ethernet interface" do - @ohai['network']['interfaces']['lo0']['flags'].sort.should == ["LOOPBACK", "MULTICAST", "RUNNING", "UP"] + @plugin['network']['interfaces']['lo0']['flags'].sort.should == ["LOOPBACK", "MULTICAST", "RUNNING", "UP"] end it "detects the mtu of the loopback interface" do - @ohai['network']['interfaces']['lo0']['mtu'].should == "16384" + @plugin['network']['interfaces']['lo0']['mtu'].should == "16384" end it "detects the arp entries" do - @ohai['network']['interfaces']['en1']['arp']['10.20.10.1'].should == '0:4:ed:de:41:bf' + @plugin['network']['interfaces']['en1']['arp']['10.20.10.1'].should == '0:4:ed:de:41:bf' end it "detects the ethernet counters" do - @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 + @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 end it "detects the loopback counters" do - @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 + @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 end it "finds the default interface by asking which iface has the default route" do - @ohai['network'][:default_interface].should == 'en1' + @plugin['network'][:default_interface].should == 'en1' end it "finds the default interface by asking which iface has the default route" do - @ohai['network'][:default_gateway].should == '10.20.10.1' + @plugin['network'][:default_gateway].should == '10.20.10.1' end it "should detect network settings" do - @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' + @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' end end end diff --git a/spec/unit/plugins/darwin/platform_spec.rb b/spec/unit/plugins/darwin/platform_spec.rb index 1a63b697..ba5aeba9 100644 --- a/spec/unit/plugins/darwin/platform_spec.rb +++ b/spec/unit/plugins/darwin/platform_spec.rb @@ -21,9 +21,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Darwin plugin platform" do before(:each) do - @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:os] = "darwin" + @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" @pid = 10 @stdin = mock("STDIN", { :close => true }) @stdout = mock("STDOUT") @@ -32,49 +33,48 @@ describe Ohai::System, "Darwin plugin platform" do and_yield("ProductVersion: 10.5.5"). and_yield("BuildVersion: 9F33") @stderr = mock("STDERR") - @ohai.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr) + @plugin.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr) end it "should run sw_vers" do - @ohai.should_receive(:popen4).with("/usr/bin/sw_vers").and_return(true) - @ohai._require_plugin("darwin::platform") + @plugin.should_receive(:popen4).with("/usr/bin/sw_vers").and_return(true) + @plugin.run end it "should close sw_vers stdin" do @stdin.should_receive(:close) - @ohai._require_plugin("darwin::platform") + @plugin.run end it "should iterate over each line of sw_vers stdout" do @stdout.should_receive(:each).and_return(true) - @ohai._require_plugin("darwin::platform") + @plugin.run end it "should set platform to ProductName, downcased with _ for \\s" do - @ohai._require_plugin("darwin::platform") - @ohai[:platform].should == "mac_os_x" + @plugin.run + @plugin[:platform].should == "mac_os_x" end it "should set platform_version to ProductVersion" do - @ohai._require_plugin("darwin::platform") - @ohai[:platform_version].should == "10.5.5" + @plugin.run + @plugin[:platform_version].should == "10.5.5" end it "should set platform_build to BuildVersion" do - @ohai._require_plugin("darwin::platform") - @ohai[:platform_build].should == "9F33" + @plugin.run + @plugin[:platform_build].should == "9F33" end it "should set platform_family to mac_os_x" do - @ohai._require_plugin("darwin::platform") - @ohai[:platform_family].should == "mac_os_x" + @plugin.run + @plugin[:platform_family].should == "mac_os_x" end describe "on os x server" do before(:each) do - @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:os] = "darwin" + @plugin.stub!(:require_plugin).and_return(true) + @plugin[:os] = "darwin" @pid = 10 @stdin = mock("STDIN", { :close => true }) @stdout = mock("STDOUT") @@ -83,17 +83,17 @@ describe Ohai::System, "Darwin plugin platform" do and_yield("ProductVersion: 10.6.8"). and_yield("BuildVersion: 10K549") @stderr = mock("STDERR") - @ohai.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr) + @plugin.stub!(:popen4).with("/usr/bin/sw_vers").and_yield(@pid, @stdin, @stdout, @stderr) end it "should set platform to mac_os_x_server" do - @ohai._require_plugin("darwin::platform") - @ohai[:platform].should == "mac_os_x_server" + @plugin.run + @plugin[:platform].should == "mac_os_x_server" end it "should set platform_family to mac_os_x" do - @ohai._require_plugin("darwin::platform") - @ohai[:platform_family].should == "mac_os_x" + @plugin.run + @plugin[: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 73fdd942..d8cb6008 100644 --- a/spec/unit/plugins/darwin/system_profiler_spec.rb +++ b/spec/unit/plugins/darwin/system_profiler_spec.rb @@ -29,8 +29,7 @@ end describe Ohai::System, "Darwin system_profiler plugin", :unix_only do before(:each) do @ohai = Ohai::System.new - - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("darwin/system_profiler.rb", PLUGIN_PATH)) end it "should return the right serial number" do @@ -40,9 +39,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" - @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' + @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' end end diff --git a/spec/unit/plugins/dmi_spec.rb b/spec/unit/plugins/dmi_spec.rb index c761df25..25f8fc2a 100644 --- a/spec/unit/plugins/dmi_spec.rb +++ b/spec/unit/plugins/dmi_spec.rb @@ -94,18 +94,19 @@ EOS describe Ohai::System, "plugin dmi" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "dmi.rb")) + @plugin.stub!(:require_plugin).and_return(true) @stdin = mock("STDIN", { :close => true }) @pid = 10 @stderr = mock("STDERR") @stdout = StringIO.new(DMI_OUT) @status = 0 - @ohai.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @plugin.stub!(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "should run dmidecode" do - @ohai.should_receive(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) - @ohai._require_plugin("dmi") + @plugin.should_receive(:popen4).with("dmidecode").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @plugin.run end # Test some simple sample data @@ -125,8 +126,8 @@ describe Ohai::System, "plugin dmi" do }.each do |id, data| data.each do |attribute, value| it "should have [:dmi][:#{id}][:#{attribute}] set" do - @ohai._require_plugin("dmi") - @ohai[:dmi][id][attribute].should eql(value) + @plugin.run + @plugin[: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 e27788f4..828c28cb 100644 --- a/spec/unit/plugins/ec2_spec.rb +++ b/spec/unit/plugins/ec2_spec.rb @@ -23,21 +23,22 @@ require 'open-uri' describe Ohai::System, "plugin ec2" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:network] = {:interfaces => {:eth0 => {} } } + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ec2.rb")) + @plugin.stub(:require_plugin) + @plugin[:network] = {:interfaces => {:eth0 => {} } } end shared_examples_for "!ec2" do it "should NOT attempt to fetch the ec2 metadata" do - @ohai.should_not_receive(:http_client) - @ohai._require_plugin("ec2") + @plugin.should_not_receive(:http_client) + @plugin.run end end shared_examples_for "ec2" do before(:each) do @http_client = mock("Net::HTTP client") - @ohai.stub!(:http_client).and_return(@http_client) + @plugin.stub!(:http_client).and_return(@http_client) IO.stub!(:select).and_return([[],[1],[]]) t = mock("connection") t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS) @@ -63,12 +64,12 @@ describe Ohai::System, "plugin ec2" do @http_client.should_receive(:get). with("/2012-01-12/user-data/"). and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) - @ohai._require_plugin("ec2") - @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'] + @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'] end it "should parse ec2 network/ directory as a multi-level hash" do @@ -90,10 +91,13 @@ describe Ohai::System, "plugin ec2" do @http_client.should_receive(:get). with("/2012-01-12/meta-data/network/interfaces/macs/12:34:56:78:9a:bc/public_hostname"). and_return(mock("Net::HTTP Response", :body => "server17.opscode.com", :code => "200")) - @ohai._require_plugin("ec2") + @http_client.should_receive(:get). + with("/2012-01-12/user-data/"). + and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) + @plugin.run - @ohai[:ec2].should_not be_nil - @ohai[:ec2]['network_interfaces_macs']['12:34:56:78:9a:bc']['public_hostname'].should eql('server17.opscode.com') + @plugin[:ec2].should_not be_nil + @plugin[: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 @@ -109,11 +113,14 @@ describe Ohai::System, "plugin ec2" do @http_client.should_receive(:get). with("/2012-01-12/meta-data/iam/security-credentials/MyRole"). 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") + @http_client.should_receive(:get). + with("/2012-01-12/user-data/"). + and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) + @plugin.run - @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' + @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' end it "should ignore \"./\" and \"../\" on ec2 metadata paths to avoid infinity loops" do @@ -144,10 +151,13 @@ describe Ohai::System, "plugin ec2" do @http_client.should_receive(:get). with("/2012-01-12/meta-data/path4/"). and_return(mock("Net::HTTP Response", :body => "", :code => "200")) + @http_client.should_receive(:get). + with("/2012-01-12/user-data/"). + and_return(mock("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) - @ohai._require_plugin("ec2") + @plugin.run - @ohai[:ec2].should_not be_nil + @plugin[:ec2].should_not be_nil end end @@ -156,7 +166,7 @@ describe Ohai::System, "plugin ec2" do before(:each) do IO.stub!(:select).and_return([[],[1],[]]) - @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"} + @plugin[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"} end end @@ -164,7 +174,7 @@ describe Ohai::System, "plugin ec2" do it_should_behave_like "!ec2" before(:each) do - @ohai[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"} + @plugin[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"00:50:56:c0:00:08"} end end @@ -192,6 +202,9 @@ 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) diff --git a/spec/unit/plugins/erlang_spec.rb b/spec/unit/plugins/erlang_spec.rb index 3eaba4f7..f7e2702f 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 - @ohai[:languages] = Mash.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "erlang.rb")) + @plugin[:languages] = Mash.new @status = 0 @stdin = "" @stderr = "Erlang (ASYNC_THREADS,SMP,HIPE) (BEAM) emulator version 5.6.2\n" - @ohai.stub!(:run_command).with({:no_status_check => true, :command => "erl +V"}).and_return([@status, @stdout, @stderr]) + @plugin.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 - @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") + @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 end it "should set languages[:erlang][:version]" do - @ohai._require_plugin("erlang") - @ohai.languages[:erlang][:version].should eql("5.6.2") + @plugin.run + @plugin.languages[:erlang][:version].should eql("5.6.2") end it "should set languages[:erlang][:options]" do - @ohai._require_plugin("erlang") - @ohai.languages[:erlang][:options].should eql(["ASYNC_THREADS", "SMP", "HIPE"]) + @plugin.run + @plugin.languages[:erlang][:options].should eql(["ASYNC_THREADS", "SMP", "HIPE"]) end it "should set languages[:erlang][:emulator]" do - @ohai._require_plugin("erlang") - @ohai.languages[:erlang][:emulator].should eql("BEAM") + @plugin.run + @plugin.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" - @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) + @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) end end diff --git a/spec/unit/plugins/eucalyptus_spec.rb b/spec/unit/plugins/eucalyptus_spec.rb index afe80ed4..2269a22c 100644 --- a/spec/unit/plugins/eucalyptus_spec.rb +++ b/spec/unit/plugins/eucalyptus_spec.rb @@ -23,20 +23,21 @@ require 'open-uri' describe Ohai::System, "plugin eucalyptus" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "eucalyptus.rb")) + @plugin.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) - @ohai._require_plugin("eucalyptus") + @plugin.run end end shared_examples_for "eucalyptus" do before(:each) do @http_client = mock("Net::HTTP client") - @ohai.stub!(:http_client).and_return(@http_client) + @plugin.stub!(:http_client).and_return(@http_client) @http_client.should_receive(:get). with("/").twice. @@ -63,11 +64,11 @@ describe Ohai::System, "plugin eucalyptus" do 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'] + @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'] end end @@ -76,7 +77,7 @@ describe Ohai::System, "plugin eucalyptus" do before(:each) do IO.stub!(:select).and_return([[],[1],[]]) - @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "d0:0d:95:47:6E:ED"=> { "family" => "lladdr" } } } } } + @plugin[:network] = { "interfaces" => { "eth0" => { "addresses" => { "d0:0d:95:47:6E:ED"=> { "family" => "lladdr" } } } } } end end @@ -84,7 +85,7 @@ describe Ohai::System, "plugin eucalyptus" do it_should_behave_like "!eucalyptus" before(:each) do - @ohai[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } } + @plugin[:network] = { "interfaces" => { "eth0" => { "addresses" => { "ff:ff:95:47:6E:ED"=> { "family" => "lladdr" } } } } } end end @@ -103,6 +104,7 @@ 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) end @@ -112,9 +114,13 @@ 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!(: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 a11629f1..938239d6 100644 --- a/spec/unit/plugins/freebsd/hostname_spec.rb +++ b/spec/unit/plugins/freebsd/hostname_spec.rb @@ -22,10 +22,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "FreeBSD hostname plugin" do before(:each) do @ohai = Ohai::System.new - @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") + @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") 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 ea6423eb..1cf0cc20 100644 --- a/spec/unit/plugins/freebsd/kernel_spec.rb +++ b/spec/unit/plugins/freebsd/kernel_spec.rb @@ -21,17 +21,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "FreeBSD kernel plugin" do before(:each) do - @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" + @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" end it "should set the kernel_os to the kernel_name value" do - @ohai._require_plugin("freebsd::kernel") - @ohai[:kernel][:os].should == @ohai[:kernel][:name] + @plugin.run + @plugin[:kernel][:os].should == @plugin[:kernel][:name] end end diff --git a/spec/unit/plugins/freebsd/platform_spec.rb b/spec/unit/plugins/freebsd/platform_spec.rb index c3ca8f54..cbae5559 100644 --- a/spec/unit/plugins/freebsd/platform_spec.rb +++ b/spec/unit/plugins/freebsd/platform_spec.rb @@ -22,19 +22,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "FreeBSD plugin platform" do before(:each) do @ohai = Ohai::System.new - @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" + @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" end it "should set platform to lowercased lsb[:id]" do - @ohai._require_plugin("freebsd::platform") - @ohai[:platform].should == "freebsd" + @plugin.run + @plugin[:platform].should == "freebsd" end it "should set platform_version to lsb[:release]" do - @ohai._require_plugin("freebsd::platform") - @ohai[:platform_version].should == "7.1" + @plugin.run + @plugin[: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 fdd5bf4f..53fb9ada 100644 --- a/spec/unit/plugins/freebsd/virtualization_spec.rb +++ b/spec/unit/plugins/freebsd/virtualization_spec.rb @@ -22,29 +22,30 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "FreeBSD virtualization plugin" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:os] = "freebsd" + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "freebsd/virtualization.rb")) + @plugin.stub(:require_plugin) + @plugin[:os] = "freebsd" @stderr = StringIO.new @stdin = StringIO.new @status = 0 @pid = 42 - @ohai.stub(:popen4).with("/sbin/kldstat") - @ohai.stub(:from) + @plugin.stub(:popen4).with("/sbin/kldstat") + @plugin.stub(:from) end context "jails" do it "detects we are in a jail" do - @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" + @plugin.stub(:from).with("sysctl -n security.jail.jailed").and_return("1") + @plugin.run + @plugin[:virtualization][:system].should == "jail" + @plugin[:virtualization][:role].should == "guest" end it "detects we are hosing jails" do - @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" + @plugin.stub(:from).with("jls -n \| wc -l").and_return("1") + @plugin.run + @plugin[:virtualization][:system].should == "jail" + @plugin[:virtualization][:role].should == "host" end end @@ -56,13 +57,13 @@ Id Refs Address Size Name 1 40 0xffffffff80100000 d20428 kernel 7 3 0xffffffff81055000 41e88 vboxguest.ko OUT - @ohai.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @plugin.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "detects we are a guest" do - @ohai._require_plugin("freebsd::virtualization") - @ohai[:virtualization][:system].should == "vbox" - @ohai[:virtualization][:role].should == "guest" + @plugin.run + @plugin[:virtualization][:system].should == "vbox" + @plugin[:virtualization][:role].should == "guest" end end @@ -73,22 +74,22 @@ Id Refs Address Size Name 1 40 0xffffffff80100000 d20428 kernel 7 3 0xffffffff81055000 41e88 vboxdrv.ko OUT - @ohai.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @plugin.stub(:popen4).with("/sbin/kldstat").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "detects we are a host" do - @ohai._require_plugin("freebsd::virtualization") - @ohai[:virtualization][:system].should == "vbox" - @ohai[:virtualization][:role].should == "host" + @plugin.run + @plugin[:virtualization][:system].should == "vbox" + @plugin[:virtualization][:role].should == "host" end end context "when on a QEMU guest" do it "detects we are a guest" do - @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" + @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" end end diff --git a/spec/unit/plugins/gce_spec.rb b/spec/unit/plugins/gce_spec.rb index f1908e50..4c01480d 100644 --- a/spec/unit/plugins/gce_spec.rb +++ b/spec/unit/plugins/gce_spec.rb @@ -21,20 +21,21 @@ require 'open-uri' describe Ohai::System, "plugin gce" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "gce.rb")) + @plugin.stub(:require_plugin) end shared_examples_for "!gce" do it "should NOT attempt to fetch the gce metadata" do - @ohai.should_not_receive(:http_client) - @ohai._require_plugin("gce") + @plugin.should_not_receive(:http_client) + @plugin.run end end shared_examples_for "gce" do before(:each) do @http_client = mock("Net::HTTP client") - @ohai.stub!(:http_client).and_return(@http_client) + @plugin.stub!(:http_client).and_return(@http_client) IO.stub!(:select).and_return([[],[1],[]]) t = mock("connection") t.stub!(:connect_nonblock).and_raise(Errno::EINPROGRESS) @@ -57,12 +58,12 @@ describe Ohai::System, "plugin gce" do with("/0.1/meta-data/description"). and_return(mock("Net::HTTPOK", :body => "test-description", :code=>"200")) - @ohai._require_plugin("gce") + @plugin.run - @ohai[:gce].should_not be_nil - @ohai[:gce]['hostname'].should == "test-host" - @ohai[:gce]['domain'].should == "test-domain" - @ohai[:gce]['description'].should == "test-description" + @plugin[:gce].should_not be_nil + @plugin[:gce]['hostname'].should == "test-host" + @plugin[:gce]['domain'].should == "test-domain" + @plugin[:gce]['description'].should == "test-description" end it "should properly parse json metadata" do @@ -74,10 +75,10 @@ describe Ohai::System, "plugin gce" do and_return(mock("Net::HTTP Response", :body => '{"disks":[{"deviceName":"boot", "index":0,"mode":"READ_WRITE","type":"EPHEMERAL"}]}', :code=>"200")) - @ohai._require_plugin("gce") + @plugin.run - @ohai[:gce].should_not be_nil - @ohai[:gce]['attached_disks'].should eq({"disks"=>[{"deviceName"=>"boot", + @plugin[:gce].should_not be_nil + @plugin[:gce]['attached_disks'].should eq({"disks"=>[{"deviceName"=>"boot", "index"=>0,"mode"=>"READ_WRITE", "type"=>"EPHEMERAL"}]}) end @@ -112,6 +113,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) end @@ -121,6 +124,11 @@ 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) diff --git a/spec/unit/plugins/groovy_spec.rb b/spec/unit/plugins/groovy_spec.rb index 6c7f93fc..6c8cfca6 100644 --- a/spec/unit/plugins/groovy_spec.rb +++ b/spec/unit/plugins/groovy_spec.rb @@ -23,31 +23,32 @@ describe Ohai::System, "plugin groovy" do before(:each) do @ohai = Ohai::System.new - @ohai[:languages] = Mash.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "groovy.rb")) + @plugin[:languages] = Mash.new + @plugin.stub!(:require_plugin).and_return(true) @status = 0 @stdout = "Groovy Version: 1.6.3 JVM: 1.6.0_0\n" @stderr = "" - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"groovy -v"}).and_return([@status, @stdout, @stderr]) + @plugin.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 - @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") + @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 end it "should set languages[:groovy][:version]" do - @ohai._require_plugin("groovy") - @ohai.languages[:groovy][:version].should eql("1.6.3") + @plugin.run + @plugin.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 = "" - @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) + @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) end end diff --git a/spec/unit/plugins/hostname_spec.rb b/spec/unit/plugins/hostname_spec.rb index 1ac8dc53..adde2b30 100644 --- a/spec/unit/plugins/hostname_spec.rb +++ b/spec/unit/plugins/hostname_spec.rb @@ -21,19 +21,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "hostname plugin" do before(:each) do - @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @ohai = Ohai::System.new + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "hostname.rb")) + @plugin.stub!(:require_plugin).and_return(true) end it "should set the domain to everything after the first dot of the fqdn" do - @ohai[:fqdn] = "katie.bethell" - @ohai._require_plugin("hostname") - @ohai.domain.should == "bethell" + @plugin[:fqdn] = "katie.bethell" + @plugin.run + @plugin.domain.should == "bethell" end it "should not set a domain if fqdn is not set" do - @ohai._require_plugin("hostname") - @ohai.domain.should == nil + @plugin.run + @plugin.domain.should == nil end end diff --git a/spec/unit/plugins/java_spec.rb b/spec/unit/plugins/java_spec.rb index 45a6bdff..6b9bd607 100644 --- a/spec/unit/plugins/java_spec.rb +++ b/spec/unit/plugins/java_spec.rb @@ -21,102 +21,104 @@ 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 - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:languages] = Mash.new + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "java.rb")) + @plugin.stub!(:require_plugin).and_return(true) + @plugin[: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)" - @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr]) + @plugin.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr]) end it "should run java -version" do - @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") + @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 end it "should set java[:version]" do - @ohai._require_plugin("java") - @ohai.languages[:java][:version].should eql("1.5.0_16") + @plugin.run + @plugin.languages[:java][:version].should eql("1.5.0_16") end it "should set java[:runtime][:name] to runtime name" do - @ohai._require_plugin("java") - @ohai.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment, Standard Edition") + @plugin.run + @plugin.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment, Standard Edition") end it "should set java[:runtime][:build] to runtime build" do - @ohai._require_plugin("java") - @ohai.languages[:java][:runtime][:build].should eql("1.5.0_16-b06-284") + @plugin.run + @plugin.languages[:java][:runtime][:build].should eql("1.5.0_16-b06-284") end it "should set java[:hotspot][:name] to hotspot name" do - @ohai._require_plugin("java") - @ohai.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Client VM") + @plugin.run + @plugin.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Client VM") end it "should set java[:hotspot][:build] to hotspot build" do - @ohai._require_plugin("java") - @ohai.languages[:java][:hotspot][:build].should eql("1.5.0_16-133, mixed mode, sharing") + @plugin.run + @plugin.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" - @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) + @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) end end describe Ohai::System, "plugin java (Java6 Server VM)" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:languages] = Mash.new + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "java.rb")) + @plugin.stub!(:require_plugin).and_return(true) + @plugin[: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)" - @ohai.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr]) + @plugin.stub!(:run_command).with({:no_status_check => true, :command => "java -version"}).and_return([@status, @stdout, @stderr]) end it "should run java -version" do - @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") + @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 end it "should set java[:version]" do - @ohai._require_plugin("java") - @ohai.languages[:java][:version].should eql("1.6.0_22") + @plugin.run + @plugin.languages[:java][:version].should eql("1.6.0_22") end it "should set java[:runtime][:name] to runtime name" do - @ohai._require_plugin("java") - @ohai.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment") + @plugin.run + @plugin.languages[:java][:runtime][:name].should eql("Java(TM) 2 Runtime Environment") end it "should set java[:runtime][:build] to runtime build" do - @ohai._require_plugin("java") - @ohai.languages[:java][:runtime][:build].should eql("1.6.0_22-b04") + @plugin.run + @plugin.languages[:java][:runtime][:build].should eql("1.6.0_22-b04") end it "should set java[:hotspot][:name] to hotspot name" do - @ohai._require_plugin("java") - @ohai.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Server VM") + @plugin.run + @plugin.languages[:java][:hotspot][:name].should eql("Java HotSpot(TM) Server VM") end it "should set java[:hotspot][:build] to hotspot build" do - @ohai._require_plugin("java") - @ohai.languages[:java][:hotspot][:build].should eql("17.1-b03, mixed mode") + @plugin.run + @plugin.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" - @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) + @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) end end diff --git a/spec/unit/plugins/kernel_spec.rb b/spec/unit/plugins/kernel_spec.rb index 3c982ae9..70579537 100644 --- a/spec/unit/plugins/kernel_spec.rb +++ b/spec/unit/plugins/kernel_spec.rb @@ -21,15 +21,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin kernel" do before(:each) do - @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") + @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") 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 6f189971..1566b97a 100644 --- a/spec/unit/plugins/linode_spec.rb +++ b/spec/unit/plugins/linode_spec.rb @@ -23,8 +23,9 @@ describe Ohai::System, "plugin linode" do before do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:network] = { + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "linode.rb")) + @plugin.stub(:require_plugin) + @plugin[:network] = { "interfaces"=> { "eth0"=> { "addresses"=> { @@ -49,32 +50,32 @@ describe Ohai::System, "plugin linode" do shared_examples_for "!linode" do it "does not create the linode mash" do - @ohai._require_plugin("linode") - @ohai[:linode].should be_nil + @plugin.run + @plugin[:linode].should be_nil end end shared_examples_for "linode" do it "creates a linode mash" do - @ohai._require_plugin("linode") - @ohai[:linode].should_not be_nil + @plugin.run + @plugin[:linode].should_not be_nil end it "has all required attributes" do - @ohai._require_plugin("linode") - @ohai[:linode][:public_ip].should_not be_nil + @plugin.run + @plugin[:linode][:public_ip].should_not be_nil end it "has correct values for all attributes" do - @ohai._require_plugin("linode") - @ohai[:linode][:public_ip].should == "1.2.3.4" + @plugin.run + @plugin[:linode][:public_ip].should == "1.2.3.4" end end context "without linode kernel" do before do - @ohai[:kernel] = { "release" => "3.5.2-x86_64" } + @plugin[:kernel] = { "release" => "3.5.2-x86_64" } end it_should_behave_like "!linode" @@ -82,7 +83,7 @@ describe Ohai::System, "plugin linode" do context "with linode kernel" do before do - @ohai[:kernel] = { "release" => "3.5.2-x86_64-linode24" } + @plugin[:kernel] = { "release" => "3.5.2-x86_64-linode24" } end it_should_behave_like "linode" @@ -91,7 +92,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 - @ohai[:network][:interfaces]["eth0:1"] = { + @plugin[:network][:interfaces]["eth0:1"] = { "addresses" => { "5.6.7.8"=> { "broadcast"=> "10.176.191.255", @@ -111,9 +112,9 @@ describe Ohai::System, "plugin linode" do end it "detects and sets the private ip" do - @ohai._require_plugin("linode") - @ohai[:linode][:private_ip].should_not be_nil - @ohai[:linode][:private_ip].should == "5.6.7.8" + @plugin.run + @plugin[:linode][:private_ip].should_not be_nil + @plugin[:linode][:private_ip].should == "5.6.7.8" end end @@ -140,14 +141,17 @@ describe Ohai::System, "plugin linode" do end context "with ec2 cloud file" do - let(:hint_path_nix) { '/etc/chef/ohai/hints/ec2.json' } - let(:hint_path_win) { 'C:\chef\ohai\hints/ec2.json' } + let(:ec2_hint_path_nix) { '/etc/chef/ohai/hints/ec2.json' } + let(:ec2_hint_path_win) { 'C:\chef\ohai\hints/ec2.json' } 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(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('') 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 7a4f92e8..e2744d0a 100644 --- a/spec/unit/plugins/linux/cpu_spec.rb +++ b/spec/unit/plugins/linux/cpu_spec.rb @@ -22,8 +22,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux cpu plugin" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:os] = "linux" + @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/cpu.rb", PLUGIN_PATH)) + @plugin.stub!(:require_plugin).and_return(true) + @plugin[:os] = "linux" @mock_file = mock("/proc/cpuinfo") @mock_file.stub!(:each). and_yield("processor : 0"). @@ -49,80 +50,80 @@ describe Ohai::System, "Linux cpu plugin" do end it "should set cpu[:total] to 1" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu][:total].should == 1 + @plugin.run + @plugin[:cpu][:total].should == 1 end it "should set cpu[:real] to 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu][:real].should == 0 + @plugin.run + @plugin[:cpu][:real].should == 0 end it "should have a cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu].should have_key("0") + @plugin.run + @plugin[:cpu].should have_key("0") end it "should have a vendor_id for cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu]["0"].should have_key("vendor_id") - @ohai[:cpu]["0"]["vendor_id"].should eql("GenuineIntel") + @plugin.run + @plugin[:cpu]["0"].should have_key("vendor_id") + @plugin[:cpu]["0"]["vendor_id"].should eql("GenuineIntel") end it "should have a family for cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu]["0"].should have_key("family") - @ohai[:cpu]["0"]["family"].should eql("6") + @plugin.run + @plugin[:cpu]["0"].should have_key("family") + @plugin[:cpu]["0"]["family"].should eql("6") end it "should have a model for cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu]["0"].should have_key("model") - @ohai[:cpu]["0"]["model"].should eql("23") + @plugin.run + @plugin[:cpu]["0"].should have_key("model") + @plugin[:cpu]["0"]["model"].should eql("23") end it "should have a stepping for cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu]["0"].should have_key("stepping") - @ohai[:cpu]["0"]["stepping"].should eql("6") + @plugin.run + @plugin[:cpu]["0"].should have_key("stepping") + @plugin[:cpu]["0"]["stepping"].should eql("6") end it "should not have a phyiscal_id for cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu]["0"].should_not have_key("physical_id") + @plugin.run + @plugin[:cpu]["0"].should_not have_key("physical_id") end it "should not have a core_id for cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu]["0"].should_not have_key("core_id") + @plugin.run + @plugin[:cpu]["0"].should_not have_key("core_id") end it "should not have a cores for cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu]["0"].should_not have_key("cores") + @plugin.run + @plugin[:cpu]["0"].should_not have_key("cores") end it "should have a model name for cpu 0" do - @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") + @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") end it "should have a mhz for cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu]["0"].should have_key("mhz") - @ohai[:cpu]["0"]["mhz"].should eql("1968.770") + @plugin.run + @plugin[:cpu]["0"].should have_key("mhz") + @plugin[:cpu]["0"]["mhz"].should eql("1968.770") end it "should have a cache_size for cpu 0" do - @ohai._require_plugin("linux::cpu") - @ohai[:cpu]["0"].should have_key("cache_size") - @ohai[:cpu]["0"]["cache_size"].should eql("64 KB") + @plugin.run + @plugin[:cpu]["0"].should have_key("cache_size") + @plugin[:cpu]["0"]["cache_size"].should eql("64 KB") end it "should have flags for cpu 0" do - @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} + @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} end -end
\ No newline at end of file +end diff --git a/spec/unit/plugins/linux/filesystem_spec.rb b/spec/unit/plugins/linux/filesystem_spec.rb index 492a83de..44b46e89 100644 --- a/spec/unit/plugins/linux/filesystem_spec.rb +++ b/spec/unit/plugins/linux/filesystem_spec.rb @@ -21,15 +21,16 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux filesystem plugin" do before(:each) do @ohai = Ohai::System.new - @ohai[:os] = "linux" - @ohai.stub!(:require_plugin).and_return(true) - @ohai.extend(SimpleFromFile) + @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) - @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) + @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) end @@ -57,38 +58,38 @@ describe Ohai::System, "Linux filesystem plugin" do end it "should run df -P" do - @ohai.should_receive(:popen4).with("df -P").and_return(true) - @ohai._require_plugin("linux::filesystem") + @plugin.should_receive(:popen4).with("df -P").and_return(true) + @plugin.run end it "should set kb_size to value from df -P" do - @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" + @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" end it "should set kb_used to value from df -P" do - @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" + @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" end it "should set kb_available to value from df -P" do - @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" + @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" end it "should set percent_used to value from df -P" do - @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%" + @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%" end it "should set mount to value from df -P" do - @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" + @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" end end @@ -119,26 +120,26 @@ describe Ohai::System, "Linux filesystem plugin" do end it "should run mount" do - @ohai.should_receive(:popen4).with("mount").and_return(true) - @ohai._require_plugin("linux::filesystem") + @plugin.should_receive(:popen4).with("mount").and_return(true) + @plugin.run end it "should set mount to value from mount" do - @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" + @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" end it "should set fs_type to value from mount" do - @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" + @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" end it "should set mount_options to an array of values from mount" do - @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" ] + @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" ] end end @@ -166,14 +167,14 @@ describe Ohai::System, "Linux filesystem plugin" do end it "should run blkid -s TYPE" do - @ohai.should_receive(:popen4).with("blkid -s TYPE").and_return(true) - @ohai._require_plugin("linux::filesystem") + @plugin.should_receive(:popen4).with("blkid -s TYPE").and_return(true) + @plugin.run end it "should set kb_size to value from blkid -s TYPE" do - @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" + @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" end end @@ -201,14 +202,14 @@ describe Ohai::System, "Linux filesystem plugin" do end it "should run blkid -s UUID" do - @ohai.should_receive(:popen4).with("blkid -s UUID").and_return(true) - @ohai._require_plugin("linux::filesystem") + @plugin.should_receive(:popen4).with("blkid -s UUID").and_return(true) + @plugin.run end it "should set kb_size to value from blkid -s UUID" do - @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" + @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" end end @@ -234,14 +235,14 @@ describe Ohai::System, "Linux filesystem plugin" do end it "should run blkid -s LABEL" do - @ohai.should_receive(:popen4).with("blkid -s LABEL").and_return(true) - @ohai._require_plugin("linux::filesystem") + @plugin.should_receive(:popen4).with("blkid -s LABEL").and_return(true) + @plugin.run end it "should set kb_size to value from blkid -s LABEL" do - @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" + @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" end end @@ -271,18 +272,18 @@ describe Ohai::System, "Linux filesystem plugin" do end it "should set mount to value from /proc/mounts" do - @ohai._require_plugin("linux::filesystem") - @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special" + @plugin.run + @plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount].should be == "/special" end it "should set fs_type to value from /proc/mounts" do - @ohai._require_plugin("linux::filesystem") - @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type].should be == "xfs" + @plugin.run + @plugin[: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 - @ohai._require_plugin("linux::filesystem") - @ohai[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options].should be == [ "ro", "noatime", "attr2", "noquota" ] + @plugin.run + @plugin[: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 33ab866b..61db03b8 100644 --- a/spec/unit/plugins/linux/hostname_spec.rb +++ b/spec/unit/plugins/linux/hostname_spec.rb @@ -22,10 +22,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux hostname plugin" do before(:each) do @ohai = Ohai::System.new - @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") + @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") end it_should_check_from("linux::hostname", "hostname", "hostname -s", "katie") @@ -34,16 +35,16 @@ describe Ohai::System, "Linux hostname plugin" do describe "when domain name is unset" do before(:each) do - @ohai.should_receive(:from).with("hostname --fqdn").and_raise("Ohai::Exception::Exec") + @plugin.should_receive(:from).with("hostname --fqdn").and_raise("Ohai::Exception::Exec") end it "should not raise an error" do - lambda { @ohai._require_plugin("linux::hostname") }.should_not raise_error + lambda { @plugin.run }.should_not raise_error end it "should not set fqdn" do - @ohai._require_plugin("linux::hostname") - @ohai.fqdn.should == nil + @plugin.run + @plugin.fqdn.should == nil end end diff --git a/spec/unit/plugins/linux/kernel_spec.rb b/spec/unit/plugins/linux/kernel_spec.rb index a0beb9e1..afd0349f 100644 --- a/spec/unit/plugins/linux/kernel_spec.rb +++ b/spec/unit/plugins/linux/kernel_spec.rb @@ -22,10 +22,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux kernel plugin" do before(:each) do @ohai = Ohai::System.new - @ohai._require_plugin("kernel") - @ohai.stub!(:require_plugin).and_return(true) - @ohai.stub!(:from).with("uname -o").and_return("Linux") + @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 end it_should_check_from_deep_mash("linux::kernel", "kernel", "os", "uname -o", "Linux") -end
\ No newline at end of file +end diff --git a/spec/unit/plugins/linux/lsb_spec.rb b/spec/unit/plugins/linux/lsb_spec.rb index 53f95df0..56acb135 100644 --- a/spec/unit/plugins/linux/lsb_spec.rb +++ b/spec/unit/plugins/linux/lsb_spec.rb @@ -24,9 +24,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux lsb plugin" do before(:each) do @ohai = Ohai::System.new - @ohai[:os] = "linux" - @ohai.stub!(:require_plugin).and_return(true) - @ohai.extend(SimpleFromFile) + @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) end describe "on systems with /etc/lsb-release" do @@ -42,23 +43,23 @@ describe Ohai::System, "Linux lsb plugin" do end it "should set lsb[:id]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:id].should == "Ubuntu" + @plugin.run + @plugin[:lsb][:id].should == "Ubuntu" end it "should set lsb[:release]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:release].should == "8.04" + @plugin.run + @plugin[:lsb][:release].should == "8.04" end it "should set lsb[:codename]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:codename].should == "hardy" + @plugin.run + @plugin[:lsb][:codename].should == "hardy" end it "should set lsb[:description]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:description].should == "Ubuntu 8.04" + @plugin.run + @plugin[:lsb][:description].should == "Ubuntu 8.04" end end @@ -84,27 +85,27 @@ describe Ohai::System, "Linux lsb plugin" do and_yield("Release: 5.4"). and_yield("Codename: Final") - @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @plugin.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "should set lsb[:id]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:id].should == "CentOS" + @plugin.run + @plugin[:lsb][:id].should == "CentOS" end it "should set lsb[:release]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:release].should == "5.4" + @plugin.run + @plugin[:lsb][:release].should == "5.4" end it "should set lsb[:codename]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:codename].should == "Final" + @plugin.run + @plugin[:lsb][:codename].should == "Final" end it "should set lsb[:description]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:description].should == "CentOS release 5.4 (Final)" + @plugin.run + @plugin[:lsb][:description].should == "CentOS release 5.4 (Final)" end end @@ -117,27 +118,27 @@ describe Ohai::System, "Linux lsb plugin" do and_yield("Release: 14"). and_yield("Codename: Laughlin") - @ohai.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) + @plugin.stub!(:popen4).with("lsb_release -a").and_yield(@pid, @stdin, @stdout, @stderr).and_return(@status) end it "should set lsb[:id]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:id].should == "Fedora" + @plugin.run + @plugin[:lsb][:id].should == "Fedora" end it "should set lsb[:release]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:release].should == "14" + @plugin.run + @plugin[:lsb][:release].should == "14" end it "should set lsb[:codename]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:codename].should == "Laughlin" + @plugin.run + @plugin[:lsb][:codename].should == "Laughlin" end it "should set lsb[:description]" do - @ohai._require_plugin("linux::lsb") - @ohai[:lsb][:description].should == "Fedora release 14 (Laughlin)" + @plugin.run + @plugin[:lsb][:description].should == "Fedora release 14 (Laughlin)" end end end @@ -145,6 +146,6 @@ describe Ohai::System, "Linux lsb plugin" do 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) - @ohai.attribute?(:lsb).should be(false) + @plugin.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 caf7ebf1..a53d37ae 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 - @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) + @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) end describe Ohai::System, "Linux Network Plugin" do @@ -278,13 +278,14 @@ IP_ROUTE_SCOPE prepare_data @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/network.rb", PLUGIN_PATH)) - @ohai.stub(:popen4).with("ifconfig -a") - @ohai.stub(:popen4).with("arp -an") + @plugin.stub(:popen4).with("ifconfig -a") + @plugin.stub(:popen4).with("arp -an") - Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(3).times - @ohai._require_plugin("network") + Ohai::Log.should_receive(:warn).with(/unable to detect/).exactly(6).times + @plugin.require_plugin("network") + @plugin.stub!(:require_plugin).and_return(true) end ["ifconfig","iproute2"].each do |network_method| @@ -297,117 +298,117 @@ IP_ROUTE_SCOPE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "detects the interfaces" do - @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"] + @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"] end it "detects the ipv4 addresses of the ethernet interface" do - @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' + @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' end it "detects the ipv4 addresses of an ethernet subinterface" do - @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' + @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' end it "detects the ipv6 addresses of the ethernet interface" do - @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' + @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' end it "detects the ipv6 addresses of an ethernet subinterface" do - @ohai._require_plugin("linux::network") + @plugin.run %w[ 1111:2222:3333:4444::2 1111:2222:3333:4444::3 ].each do |addr| - @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' + @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' end end it "detects the mac addresses of the ethernet interface" do - @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' + @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' end it "detects the encapsulation type of the ethernet interface" do - @ohai._require_plugin("linux::network") - @ohai['network']['interfaces']['eth0']['encapsulation'].should == 'Ethernet' + @plugin.run + @plugin['network']['interfaces']['eth0']['encapsulation'].should == 'Ethernet' end it "detects the flags of the ethernet interface" do - @ohai._require_plugin("linux::network") + @plugin.run if network_method == "ifconfig" - @ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','MULTICAST','RUNNING','UP'] + @plugin['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','MULTICAST','RUNNING','UP'] else - @ohai['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','LOWER_UP','MULTICAST','UP'] + @plugin['network']['interfaces']['eth0']['flags'].sort.should == ['BROADCAST','LOWER_UP','MULTICAST','UP'] end end it "detects the number of the ethernet interface" do - @ohai._require_plugin("linux::network") - @ohai['network']['interfaces']['eth0']['number'].should == "0" + @plugin.run + @plugin['network']['interfaces']['eth0']['number'].should == "0" end it "detects the mtu of the ethernet interface" do - @ohai._require_plugin("linux::network") - @ohai['network']['interfaces']['eth0']['mtu'].should == "1500" + @plugin.run + @plugin['network']['interfaces']['eth0']['mtu'].should == "1500" end it "detects the ipv4 addresses of the loopback interface" do - @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' + @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' end it "detects the ipv6 addresses of the loopback interface" do - @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' + @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' end it "detects the encapsulation type of the loopback interface" do - @ohai._require_plugin("linux::network") - @ohai['network']['interfaces']['lo']['encapsulation'].should == 'Loopback' + @plugin.run + @plugin['network']['interfaces']['lo']['encapsulation'].should == 'Loopback' end it "detects the flags of the ethernet interface" do - @ohai._require_plugin("linux::network") + @plugin.run if network_method == "ifconfig" - @ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','RUNNING','UP'] + @plugin['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','RUNNING','UP'] else - @ohai['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','LOWER_UP','UP'] + @plugin['network']['interfaces']['lo']['flags'].sort.should == ['LOOPBACK','LOWER_UP','UP'] end end it "detects the mtu of the loopback interface" do - @ohai._require_plugin("linux::network") - @ohai['network']['interfaces']['lo']['mtu'].should == "16436" + @plugin.run + @plugin['network']['interfaces']['lo']['mtu'].should == "16436" end it "detects the arp entries" do - @ohai._require_plugin("linux::network") - @ohai['network']['interfaces']['eth0']['arp']['10.116.201.1'].should == 'fe:ff:ff:ff:ff:ff' + @plugin.run + @plugin['network']['interfaces']['eth0']['arp']['10.116.201.1'].should == 'fe:ff:ff:ff:ff:ff' end end @@ -416,38 +417,38 @@ IP_ROUTE_SCOPE before do File.stub!(:exist?).with("/sbin/ip").and_return( network_method == "iproute2" ) do_stubs - @ohai._require_plugin("linux::network") + @plugin.run end it "detects the ethernet counters" do - @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']['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']['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" + @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" end it "detects the loopback counters" do - @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" + @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" end end @@ -459,15 +460,15 @@ IP_ROUTE_SCOPE describe "without a subinterface" do before do - @ohai._require_plugin("linux::network") + @plugin.run end it "finds the default interface by asking which iface has the default route" do - @ohai['network']['default_interface'].should == 'eth0' + @plugin['network']['default_interface'].should == 'eth0' end it "finds the default gateway by asking which iface has the default route" do - @ohai['network']['default_gateway'].should == '10.116.201.1' + @plugin['network']['default_gateway'].should == '10.116.201.1' end end @@ -486,15 +487,15 @@ ROUTE_N prepare_data do_stubs - @ohai._require_plugin("linux::network") + @plugin.run end it "finds the default interface by asking which iface has the default route" do - @ohai['network']['default_interface'].should == 'eth0' + @plugin['network']['default_interface'].should == 'eth0' end it "finds the default interface by asking which iface has the default route" do - @ohai['network']['default_gateway'].should == '0.0.0.0' + @plugin['network']['default_gateway'].should == '0.0.0.0' end end @@ -514,15 +515,15 @@ ROUTE_N prepare_data do_stubs - @ohai._require_plugin("linux::network") + @plugin.run end it "finds the default interface by asking which iface has the default route" do - @ohai['network']["default_interface"].should == 'eth0.11' + @plugin['network']["default_interface"].should == 'eth0.11' end it "finds the default interface by asking which iface has the default route" do - @ohai['network']["default_gateway"].should == '192.168.0.15' + @plugin['network']["default_gateway"].should == '192.168.0.15' end end end @@ -536,74 +537,74 @@ ROUTE_N it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "finds the default inet6 interface if there's a inet6 default route" do - @ohai._require_plugin("linux::network") - @ohai['network']['default_inet6_interface'].should == 'eth0.11' + @plugin.run + @plugin['network']['default_inet6_interface'].should == 'eth0.11' end it "finds the default inet6 gateway if there's a inet6 default route" do - @ohai._require_plugin("linux::network") - @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::1' + @plugin.run + @plugin['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::1' end it "finds inet6 neighbours" do - @ohai._require_plugin("linux::network") - @ohai['network']['interfaces']['eth0.11']['neighbour_inet6']['1111:2222:3333:4444::1'].should == '00:1c:0e:12:34:56' + @plugin.run + @plugin['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 - @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' + @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' end it "generates a fake interface for ip aliases for backward compatibility" do - @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' + @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' end it "adds the vlan information of an interface" do - @ohai._require_plugin("linux::network") - @ohai['network']['interfaces']['eth0.11']['vlan']['id'].should == '11' - @ohai['network']['interfaces']['eth0.11']['vlan']['flags'].should == [ 'REORDER_HDR' ] + @plugin.run + @plugin['network']['interfaces']['eth0.11']['vlan']['id'].should == '11' + @plugin['network']['interfaces']['eth0.11']['vlan']['flags'].should == [ 'REORDER_HDR' ] end it "adds the state of an interface" do - @ohai._require_plugin("linux::network") - @ohai['network']['interfaces']['eth0.11']['state'].should == 'up' + @plugin.run + @plugin['network']['interfaces']['eth0.11']['state'].should == 'up' end describe "when dealing with routes" do it "adds routes" do - @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") + @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") end describe "when there isn't a source field in route entries " do it "doesn't set ipaddress" do - @ohai._require_plugin("linux::network") - @ohai['ipaddress'].should be nil + @plugin.run + @plugin['ipaddress'].should be nil end it "doesn't set macaddress" do - @ohai._require_plugin("linux::network") - @ohai['macaddress'].should be nil + @plugin.run + @plugin['macaddress'].should be nil end it "doesn't set ip6address" do - @ohai._require_plugin("linux::network") - @ohai['ip6address'].should be nil + @plugin.run + @plugin['ip6address'].should be nil end end @@ -631,18 +632,18 @@ IP_ROUTE_SCOPE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "sets ipaddress" do - @ohai._require_plugin("linux::network") - @ohai['ipaddress'].should == "10.116.201.76" + @plugin.run + @plugin['ipaddress'].should == "10.116.201.76" end it "sets ip6address" do - @ohai._require_plugin("linux::network") - @ohai['ip6address'].should == "1111:2222:3333:4444::3" + @plugin.run + @plugin['ip6address'].should == "1111:2222:3333:4444::3" end end @@ -672,20 +673,20 @@ IP_ROUTE_SCOPE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "sets default ipv4 interface and gateway" do - @ohai._require_plugin("linux::network") - @ohai['network']['default_interface'].should == 'eth0' - @ohai['network']['default_gateway'].should == '10.116.201.254' + @plugin.run + @plugin['network']['default_interface'].should == 'eth0' + @plugin['network']['default_gateway'].should == '10.116.201.254' end it "sets default ipv6 interface and gateway" do - @ohai._require_plugin("linux::network") - @ohai['network']['default_inet6_interface'].should == 'eth0.11' - @ohai['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::ffff' + @plugin.run + @plugin['network']['default_inet6_interface'].should == 'eth0.11' + @plugin['network']['default_inet6_gateway'].should == '1111:2222:3333:4444::ffff' end end @@ -715,18 +716,18 @@ IP_ROUTE_SCOPE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "sets ipaddress" do - @ohai._require_plugin("linux::network") - @ohai["ipaddress"].should == "10.116.201.74" + @plugin.run + @plugin["ipaddress"].should == "10.116.201.74" end it "sets ip6address" do - @ohai._require_plugin("linux::network") - @ohai["ip6address"].should == "1111:2222:3333:4444::2" + @plugin.run + @plugin["ip6address"].should == "1111:2222:3333:4444::2" end end @@ -754,19 +755,19 @@ IP_ROUTE_SCOPE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "sets ipaddress" do - @ohai._require_plugin("linux::network") - @ohai['ipaddress'].should == "10.116.201.76" + @plugin.run + @plugin['ipaddress'].should == "10.116.201.76" end describe "when about to set macaddress" do it "sets macaddress" do - @ohai._require_plugin("linux::network") - @ohai['macaddress'].should == "12:31:3D:02:BE:A2" + @plugin.run + @plugin['macaddress'].should == "12:31:3D:02:BE:A2" end describe "when then interface has the NOARP flag" do @@ -782,20 +783,20 @@ IP_ROUTE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "doesn't set macaddress" do - @ohai._require_plugin("linux::network") - @ohai['macaddress'].should be_nil + @plugin.run + @plugin['macaddress'].should be_nil end end end it "sets ip6address" do - @ohai._require_plugin("linux::network") - @ohai['ip6address'].should == "1111:2222:3333:4444::3" + @plugin.run + @plugin['ip6address'].should == "1111:2222:3333:4444::3" end end @@ -811,13 +812,13 @@ IP_ROUTE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "doesn't set ipaddress" do - @ohai._require_plugin("linux::network") - @ohai['ipaddress'].should be_nil + @plugin.run + @plugin['ipaddress'].should be_nil end end @@ -834,13 +835,13 @@ IP_ROUTE_SCOPE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "doesn't set ip6address" do - @ohai._require_plugin("linux::network") - @ohai['ip6address'].should be_nil + @plugin.run + @plugin['ip6address'].should be_nil end end @@ -867,18 +868,18 @@ IP_ROUTE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "doesn't set ipaddress" do - @ohai._require_plugin("linux::network") - @ohai['ipaddress'].should be_nil + @plugin.run + @plugin['ipaddress'].should be_nil end it "doesn't set ip6address" do - @ohai._require_plugin("linux::network") - @ohai['ip6address'].should be_nil + @plugin.run + @plugin['ip6address'].should be_nil end end @@ -905,25 +906,25 @@ IP_ROUTE it "completes the run" do Ohai::Log.should_not_receive(:debug).with(/Plugin linux::network threw exception/) - @ohai._require_plugin("linux::network") - @ohai['network'].should_not be_nil + @plugin.run + @plugin['network'].should_not be_nil end it "doesn't add bogus routes" do - @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" ) + @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" ) end it "doesn't set ipaddress" do - @ohai._require_plugin("linux::network") - @ohai['ipaddress'].should be_nil + @plugin.run + @plugin['ipaddress'].should be_nil end it "doesn't set ip6address" do - @ohai._require_plugin("linux::network") - @ohai['ip6address'].should be_nil + @plugin.run + @plugin['ip6address'].should be_nil end end @@ -940,7 +941,7 @@ 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.should_receive(:debug).any_number_of_times # Catches the 'Loading plugin network' type messages - @ohai._require_plugin("linux::network") + @plugin.run end end end diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index 189b3430..e90f29ea 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -23,10 +23,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux plugin platform" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai.extend(SimpleFromFile) - @ohai[:os] = "linux" - @ohai[:lsb] = Mash.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) @@ -40,252 +41,244 @@ describe Ohai::System, "Linux plugin platform" do end it "should require the lsb plugin" do - @ohai.should_receive(:require_plugin).with("linux::lsb").and_return(true) - @ohai._require_plugin("linux::platform") + @plugin.should_receive(:require_plugin).with("linux::lsb").and_return(true) + @plugin.run end describe "on lsb compliant distributions" do before(:each) do - @ohai[:lsb][:id] = "Ubuntu" - @ohai[:lsb][:release] = "8.04" + @plugin[:lsb][:id] = "Ubuntu" + @plugin[:lsb][:release] = "8.04" end it "should set platform to lowercased lsb[:id]" do - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "ubuntu" + @plugin.run + @plugin[:platform].should == "ubuntu" end it "should set platform_version to lsb[:release]" do - @ohai._require_plugin("linux::platform") - @ohai[:platform_version].should == "8.04" + @plugin.run + @plugin[:platform_version].should == "8.04" end it "should set platform to ubuntu and platform_family to debian [:lsb][:id] contains Ubuntu" do - @ohai[:lsb][:id] = "Ubuntu" - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "ubuntu" - @ohai[:platform_family].should == "debian" + @plugin[:lsb][:id] = "Ubuntu" + @plugin.run + @plugin[:platform].should == "ubuntu" + @plugin[:platform_family].should == "debian" end it "should set platform to linuxmint and platform_family to debian [:lsb][:id] contains LinuxMint" do - @ohai[:lsb][:id] = "LinuxMint" - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "linuxmint" - @ohai[:platform_family].should == "debian" + @plugin[:lsb][:id] = "LinuxMint" + @plugin.run + @plugin[:platform].should == "linuxmint" + @plugin[:platform_family].should == "debian" end it "should set platform to gcel and platform_family to debian [:lsb][:id] contains GCEL" do - @ohai[:lsb][:id] = "GCEL" - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "gcel" - @ohai[:platform_family].should == "debian" + @plugin[:lsb][:id] = "GCEL" + @plugin.run + @plugin[:platform].should == "gcel" + @plugin[:platform_family].should == "debian" end it "should set platform to debian and platform_family to debian [:lsb][:id] contains Debian" do - @ohai[:lsb][:id] = "Debian" - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "debian" - @ohai[:platform_family].should == "debian" + @plugin[:lsb][:id] = "Debian" + @plugin.run + @plugin[:platform].should == "debian" + @plugin[:platform_family].should == "debian" end it "should set platform to redhat and platform_family to rhel when [:lsb][:id] contains Redhat" do - @ohai[:lsb][:id] = "RedHatEnterpriseServer" - @ohai[:lsb][:release] = "5.7" - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "redhat" - @ohai[:platform_family].should == "rhel" + @plugin[:lsb][:id] = "RedHatEnterpriseServer" + @plugin[:lsb][:release] = "5.7" + @plugin.run + @plugin[:platform].should == "redhat" + @plugin[:platform_family].should == "rhel" end it "should set platform to amazon and platform_family to rhel when [:lsb][:id] contains Amazon" do - @ohai[:lsb][:id] = "AmazonAMI" - @ohai[:lsb][:release] = "2011.09" - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "amazon" - @ohai[:platform_family].should == "rhel" + @plugin[:lsb][:id] = "AmazonAMI" + @plugin[:lsb][:release] = "2011.09" + @plugin.run + @plugin[:platform].should == "amazon" + @plugin[:platform_family].should == "rhel" end it "should set platform to scientific when [:lsb][:id] contains ScientificSL" do - @ohai[:lsb][:id] = "ScientificSL" - @ohai[:lsb][:release] = "5.7" - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "scientific" + @plugin[:lsb][:id] = "ScientificSL" + @plugin[:lsb][:release] = "5.7" + @plugin.run + @plugin[:platform].should == "scientific" end end describe "on debian" do before(:each) do - @ohai.lsb = nil + @plugin.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") - @ohai._require_plugin("linux::platform") - @ohai[:platform_version].should == "5.0" + @plugin.run + @plugin[: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") - @ohai._require_plugin("linux::platform") - @ohai[:platform_version].should == "5.0" + @plugin.run + @plugin[:platform_version].should == "5.0" end # Ubuntu has /etc/debian_version as well it "should detect Ubuntu as itself rather than debian" do - @ohai[:lsb][:id] = "Ubuntu" - @ohai[:lsb][:release] = "8.04" - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "ubuntu" + @plugin[:lsb][:id] = "Ubuntu" + @plugin[:lsb][:release] = "8.04" + @plugin.run + @plugin[: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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "raspbian" - @ohai[:platform_family].should == "debian" + @plugin.run + @plugin[:platform].should == "raspbian" + @plugin[:platform_family].should == "debian" end end describe "on slackware" do before(:each) do - @ohai.lsb = nil + @plugin.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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "slackware" - @ohai[:platform_family].should == "slackware" + @plugin.run + @plugin[:platform].should == "slackware" + @plugin[:platform_family].should == "slackware" end end describe "on arch" do before(:each) do - @ohai.lsb = nil + @plugin.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 - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "arch" - @ohai[:platform_family].should == "arch" + @plugin.run + @plugin[:platform].should == "arch" + @plugin[:platform_family].should == "arch" end end describe "on gentoo" do before(:each) do - @ohai.lsb = nil + @plugin.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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "gentoo" - @ohai[:platform_family].should == "gentoo" + @plugin.run + @plugin[:platform].should == "gentoo" + @plugin[: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 - @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" + @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" end it "should set the platform to centos and platform_family to rhel" do - @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" + @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" end it "should set the platform_family to rhel if the LSB name is oracle-ish" do - @ohai[:lsb][:id] = "EnterpriseEnterpriseServer" - @ohai._require_plugin("linux::platform") - @ohai[:platform_family].should == "rhel" + @plugin[:lsb][:id] = "EnterpriseEnterpriseServer" + @plugin.run + @plugin[:platform_family].should == "rhel" end it "should set the platform_family to rhel if the LSB name is amazon-ish" do - @ohai[:lsb][:id] = "Amazon" - @ohai._require_plugin("linux::platform") - @ohai[:platform_family].should == "rhel" + @plugin[:lsb][:id] = "Amazon" + @plugin.run + @plugin[:platform_family].should == "rhel" end it "should set the platform_family to fedora if the LSB name is fedora-ish" do - @ohai[:lsb][:id] = "Fedora" - @ohai._require_plugin("linux::platform") - @ohai[:platform_family].should == "fedora" + @plugin[:lsb][:id] = "Fedora" + @plugin.run + @plugin[:platform_family].should == "fedora" end it "should set the platform_family to redhat if the LSB name is scientific-ish" do - @ohai[:lsb][:id] = "Scientific" - @ohai._require_plugin("linux::platform") - @ohai[:platform_family].should == "rhel" + @plugin[:lsb][:id] = "Scientific" + @plugin.run + @plugin[:platform_family].should == "rhel" end end describe "without lsb_release results" do before(:each) do - @ohai.lsb = nil + @plugin.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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "centos" + @plugin.run + @plugin[: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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "redhat" - @ohai[:platform_version].should == "5.3" + @plugin.run + @plugin[:platform].should == "redhat" + @plugin[: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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "redhat" - @ohai[:platform_version].should == "5.3" + @plugin.run + @plugin[:platform].should == "redhat" + @plugin[: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)") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "fedora" - @ohai[:platform_version].should == "13 (rawhide)" + @plugin.run + @plugin[:platform].should == "fedora" + @plugin[: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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "fedora" - @ohai[:platform_version].should == "10" + @plugin.run + @plugin[:platform].should == "fedora" + @plugin[: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)") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "fedora" - @ohai[:platform_version].to_i.should == 13 + @plugin.run + @plugin[:platform].should == "fedora" + @plugin[:platform_version].to_i.should == 13 end end end @@ -293,33 +286,33 @@ 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 - @ohai[:lsb][:id] = "EnterpriseEnterpriseServer" - @ohai[:lsb][:release] = "5.7" + @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)") 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)") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "oracle" - @ohai[:platform_version].should == "5.7" + @plugin.run + @plugin[:platform].should == "oracle" + @plugin[:platform_version].should == "5.7" end it "should read the platform as oracle and version as 6.1" do - @ohai[:lsb][:id] = "OracleServer" - @ohai[:lsb][:release] = "6.1" + @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)") 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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "oracle" - @ohai[:platform_version].should == "6.1" + @plugin.run + @plugin[:platform].should == "oracle" + @plugin[:platform_version].should == "6.1" end end describe "without lsb_results" do before(:each) do - @ohai.lsb = nil + @plugin.lsb = nil end it "should read the platform as oracle and version as 5" do @@ -327,9 +320,9 @@ describe Ohai::System, "Linux plugin platform" do 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)") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "oracle" - @ohai[:platform_version].should == "5" + @plugin.run + @plugin[:platform].should == "oracle" + @plugin[:platform_version].should == "5" end it "should read the platform as oracle and version as 5.1" do @@ -337,9 +330,9 @@ describe Ohai::System, "Linux plugin platform" do 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)") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "oracle" - @ohai[:platform_version].should == "5.1" + @plugin.run + @plugin[:platform].should == "oracle" + @plugin[:platform_version].should == "5.1" end it "should read the platform as oracle and version as 5.7" do @@ -347,9 +340,9 @@ describe Ohai::System, "Linux plugin platform" do 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)") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "oracle" - @ohai[:platform_version].should == "5.7" + @plugin.run + @plugin[:platform].should == "oracle" + @plugin[:platform_version].should == "5.7" end it "should read the platform as oracle and version as 6.0" do @@ -357,9 +350,9 @@ describe Ohai::System, "Linux plugin platform" do 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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "oracle" - @ohai[:platform_version].should == "6.0" + @plugin.run + @plugin[:platform].should == "oracle" + @plugin[:platform_version].should == "6.0" end it "should read the platform as oracle and version as 6.1" do @@ -367,9 +360,9 @@ describe Ohai::System, "Linux plugin platform" do 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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "oracle" - @ohai[:platform_version].should == "6.1" + @plugin.run + @plugin[:platform].should == "oracle" + @plugin[:platform_version].should == "6.1" end end end @@ -381,73 +374,69 @@ describe Ohai::System, "Linux plugin platform" do describe "with lsb_release results" do before(:each) do - @ohai[:lsb][:id] = "SUSE LINUX" + @plugin[:lsb][:id] = "SUSE LINUX" end it "should read the platform as suse" do - @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" + @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" end end describe "without lsb_release results" do before(:each) do - @ohai.lsb = nil - end - - it "should check for the existance of SuSE-release" do - @ohai._require_plugin("linux::platform") + @plugin.lsb = nil 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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "suse" - @ohai[:platform_family].should == "suse" + @plugin.run + @plugin[:platform].should == "suse" + @plugin[: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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "suse" - @ohai[:platform_version].should == "10.1" - @ohai[:platform_family].should == "suse" + @plugin.run + @plugin[:platform].should == "suse" + @plugin[:platform_version].should == "10.1" + @plugin[: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") - @ohai._require_plugin("linux::platform") - @ohai[:platform].should == "suse" - @ohai[:platform_version].should == "11.2" - @ohai[:platform_family].should == "suse" + @plugin.run + @plugin[:platform].should == "suse" + @plugin[:platform_version].should == "11.2" + @plugin[:platform_family].should == "suse" end it "[OHAI-272] should read the version as 11.3" do - 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" + 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" end it "[OHAI-272] should read the version as 9.1" do - 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" + 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" end it "[OHAI-272] should read the version as 11.4" do - 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" + 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" end end end diff --git a/spec/unit/plugins/linux/uptime_spec.rb b/spec/unit/plugins/linux/uptime_spec.rb index e705a5ad..764dc1b8 100644 --- a/spec/unit/plugins/linux/uptime_spec.rb +++ b/spec/unit/plugins/linux/uptime_spec.rb @@ -22,40 +22,31 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux plugin uptime" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:os] = "linux" - @ohai._require_plugin("uptime") + @plugin = Ohai::DSL::Plugin.new(@ohai, File.expand_path("linux/uptime.rb", PLUGIN_PATH)) + @plugin[:os] = "linux" + @plugin.require_plugin("uptime") @mock_file = mock("/proc/uptime", { :gets => "18423 989" }) File.stub!(:open).with("/proc/uptime").and_return(@mock_file) + @plugin.stub!(:require_plugin).and_return(true) 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 - @ohai._require_plugin("linux::uptime") - @ohai[:uptime_seconds].should == 18423 + @plugin.run + @plugin[:uptime_seconds].should == 18423 end it "should set uptime to a human readable date" do - @ohai._require_plugin("linux::uptime") - @ohai[:uptime].should == "5 hours 07 minutes 03 seconds" + @plugin.run + @plugin[:uptime].should == "5 hours 07 minutes 03 seconds" end it "should set idletime_seconds to uptime" do - @ohai._require_plugin("linux::uptime") - @ohai[:idletime_seconds].should == 989 + @plugin.run + @plugin[:idletime_seconds].should == 989 end it "should set idletime to a human readable date" do - @ohai._require_plugin("linux::uptime") - @ohai[:idletime].should == "16 minutes 29 seconds" + @plugin.run + @plugin[:idletime].should == "16 minutes 29 seconds" end -end
\ No newline at end of file +end diff --git a/spec/unit/plugins/linux/virtualization_spec.rb b/spec/unit/plugins/linux/virtualization_spec.rb index 17624531..62ec73bf 100644 --- a/spec/unit/plugins/linux/virtualization_spec.rb +++ b/spec/unit/plugins/linux/virtualization_spec.rb @@ -21,9 +21,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Linux virtualization platform" do before(:each) do @ohai = Ohai::System.new - @ohai[:os] = "linux" - @ohai.stub!(:require_plugin).and_return(true) - @ohai.extend(SimpleFromFile) + @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) # default to all requested Files not existing File.stub!(:exists?).with("/proc/xen").and_return(false) @@ -40,33 +41,33 @@ describe Ohai::System, "Linux virtualization platform" 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) - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "xen" - @ohai[:virtualization][:role].should == "guest" + @plugin.run + @plugin[:virtualization][:system].should == "xen" + @plugin[: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") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "xen" - @ohai[:virtualization][:role].should == "host" + @plugin.run + @plugin[:virtualization][:system].should == "xen" + @plugin[: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("") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "xen" - @ohai[:virtualization][:role].should == "guest" + @plugin.run + @plugin[:virtualization][:system].should == "xen" + @plugin[: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) - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization].should == {} + @plugin.run + @plugin[:virtualization].should == {} end end @@ -74,23 +75,23 @@ describe Ohai::System, "Linux virtualization platform" 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") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "kvm" - @ohai[:virtualization][:role].should == "host" + @plugin.run + @plugin[:virtualization][:system].should == "kvm" + @plugin[: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") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "kvm" - @ohai[:virtualization][:role].should == "guest" + @plugin.run + @plugin[:virtualization][:system].should == "kvm" + @plugin[: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) - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization].should == {} + @plugin.run + @plugin[:virtualization].should == {} end end @@ -98,23 +99,23 @@ describe Ohai::System, "Linux virtualization platform" 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") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "vbox" - @ohai[:virtualization][:role].should == "host" + @plugin.run + @plugin[:virtualization][:system].should == "vbox" + @plugin[: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") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "vbox" - @ohai[:virtualization][:role].should == "guest" + @plugin.run + @plugin[:virtualization][:system].should == "vbox" + @plugin[: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) - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization].should == {} + @plugin.run + @plugin[:virtualization].should == {} end end @@ -129,8 +130,8 @@ describe Ohai::System, "Linux virtualization platform" do end it "should run dmidecode" do - @ohai.should_receive(:popen4).with("dmidecode").and_return(true) - @ohai._require_plugin("linux::virtualization") + @plugin.should_receive(:popen4).with("dmidecode").and_return(true) + @plugin.run end it "should set virtualpc guest if dmidecode detects Microsoft Virtual Machine" do @@ -145,10 +146,10 @@ System Information MSVPC @stdout.stub!(:read).and_return(ms_vpc_dmidecode) - @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" + @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" end it "should set vmware guest if dmidecode detects VMware Virtual Platform" do @@ -164,16 +165,16 @@ System Information Family: Not Specified VMWARE @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" + @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" end it "should run dmidecode and not set virtualization if nothing is detected" do - @ohai.should_receive(:popen4).with("dmidecode").and_return(true) - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization].should == {} + @plugin.should_receive(:popen4).with("dmidecode").and_return(true) + @plugin.run + @plugin[:virtualization].should == {} end end @@ -181,68 +182,68 @@ VMWARE 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") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "linux-vserver" - @ohai[:virtualization][:role].should == "host" + @plugin.run + @plugin[:virtualization][:system].should == "linux-vserver" + @plugin[: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") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "linux-vserver" - @ohai[:virtualization][:role].should == "host" + @plugin.run + @plugin[:virtualization][:system].should == "linux-vserver" + @plugin[: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") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "linux-vserver" - @ohai[:virtualization][:role].should == "guest" + @plugin.run + @plugin[:virtualization][:system].should == "linux-vserver" + @plugin[: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") - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "linux-vserver" - @ohai[:virtualization][:role].should == "guest" + @plugin.run + @plugin[:virtualization][:system].should == "linux-vserver" + @plugin[: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) - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization].should == {} + @plugin.run + @plugin[: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) - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "openvz" - @ohai[:virtualization][:role].should == "host" + @plugin.run + @plugin[:virtualization][:system].should == "openvz" + @plugin[: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) - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization][:system].should == "openvz" - @ohai[:virtualization][:role].should == "guest" + @plugin.run + @plugin[:virtualization][:system].should == "openvz" + @plugin[: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) - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization].should == {} + @plugin.run + @plugin[:virtualization].should == {} end end it "should not set virtualization if no tests match" do - @ohai._require_plugin("linux::virtualization") - @ohai[:virtualization].should == {} + @plugin.run + @plugin[:virtualization].should == {} end end diff --git a/spec/unit/plugins/lua_spec.rb b/spec/unit/plugins/lua_spec.rb index 7a48ca46..008f70bb 100644 --- a/spec/unit/plugins/lua_spec.rb +++ b/spec/unit/plugins/lua_spec.rb @@ -23,31 +23,32 @@ describe Ohai::System, "plugin lua" do before(:each) do @ohai = Ohai::System.new - @ohai[:languages] = Mash.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "lua.rb")) + @plugin[:languages] = Mash.new + @plugin.stub!(:require_plugin).and_return(true) @status = 0 @stdout = "" @stderr = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"lua -v"}).and_return([@status, @stdout, @stderr]) + @plugin.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 - @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") + @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 end it "should set languages[:lua][:version]" do - @ohai._require_plugin("lua") - @ohai.languages[:lua][:version].should eql("5.1.2") + @plugin.run + @plugin.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" - @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) + @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) end end diff --git a/spec/unit/plugins/mono_spec.rb b/spec/unit/plugins/mono_spec.rb index fe79bdfc..ca4c515e 100644 --- a/spec/unit/plugins/mono_spec.rb +++ b/spec/unit/plugins/mono_spec.rb @@ -23,31 +23,32 @@ describe Ohai::System, "plugin mono" do before(:each) do @ohai = Ohai::System.new - @ohai[:languages] = Mash.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "mono.rb")) + @plugin[:languages] = Mash.new + @plugin.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 = "" - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"mono -V"}).and_return([@status, @stdout, @stderr]) + @plugin.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 - @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") + @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 end it "should set languages[:mono][:version]" do - @ohai._require_plugin("mono") - @ohai.languages[:mono][:version].should eql("1.2.6") + @plugin.run + @plugin.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 = "" - @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) + @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) end end diff --git a/spec/unit/plugins/netbsd/hostname_spec.rb b/spec/unit/plugins/netbsd/hostname_spec.rb index 7606ab22..9cb0c7f5 100644 --- a/spec/unit/plugins/netbsd/hostname_spec.rb +++ b/spec/unit/plugins/netbsd/hostname_spec.rb @@ -22,10 +22,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "NetBSD hostname plugin" do before(:each) do @ohai = Ohai::System.new - @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") + @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") 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 4e41ae76..0169c340 100644 --- a/spec/unit/plugins/netbsd/kernel_spec.rb +++ b/spec/unit/plugins/netbsd/kernel_spec.rb @@ -22,15 +22,17 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "NetBSD kernel plugin" do before(:each) do @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] = "netbsd" + @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" end it "should set the kernel_os to the kernel_name value" do - @ohai._require_plugin("netbsd::kernel") - @ohai[:kernel][:os].should == @ohai[:kernel][:name] + @plugin.run + @plugin[:kernel][:os].should == @plugin[:kernel][:name] end end diff --git a/spec/unit/plugins/netbsd/platform_spec.rb b/spec/unit/plugins/netbsd/platform_spec.rb index 113b1e88..13edd0ef 100644 --- a/spec/unit/plugins/netbsd/platform_spec.rb +++ b/spec/unit/plugins/netbsd/platform_spec.rb @@ -22,19 +22,20 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "NetBSD plugin platform" do before(:each) do @ohai = Ohai::System.new - @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" + @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" end it "should set platform to lowercased lsb[:id]" do - @ohai._require_plugin("netbsd::platform") - @ohai[:platform].should == "netbsd" + @plugin.run + @plugin[:platform].should == "netbsd" end it "should set platform_version to lsb[:release]" do - @ohai._require_plugin("netbsd::platform") - @ohai[:platform_version].should == "4.5" + @plugin.run + @plugin[:platform_version].should == "4.5" end end diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb index 945bab81..ad184d86 100644 --- a/spec/unit/plugins/network_spec.rb +++ b/spec/unit/plugins/network_spec.rb @@ -22,9 +22,9 @@ def it_does_not_fail it "doesn't fail" do Ohai::Log.should_receive(:warn).any_number_of_times Ohai::Log.should_not_receive(:debug).with(/^Plugin network threw exception/) - @ohai._require_plugin("network") + @plugin.run %w[ ipaddress, macaddress, ip6address ].each do |attribute| - @ohai.should have_key(attribute) + @plugin.should have_key(attribute) end end end @@ -150,83 +150,77 @@ describe Ohai::System, "Network Plugin" do describe "with linux" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).twice.and_return(true) - @ohai["network"] = basic_data["linux"]["network"] + @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"] 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 - @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" + @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" end end describe "default ipv4 and ipv6 gateway on different interfaces" do describe "both interfaces have an ARP" do before do - @ohai["network"]["default_inet6_gateway"] = "3ffe:1111:3333::" - @ohai["network"]["default_inet6_interface"] = "eth1" + @plugin["network"]["default_inet6_gateway"] = "3ffe:1111:3333::" + @plugin["network"]["default_inet6_interface"] = "eth1" end it_does_not_fail it "detects {ip,ip6}address" do - @ohai._require_plugin("network") - @ohai["ipaddress"].should == "192.168.66.33" - @ohai["ip6address"].should == "3ffe:1111:3333::1" + @plugin.run + @plugin["ipaddress"].should == "192.168.66.33" + @plugin["ip6address"].should == "3ffe:1111:3333::1" end it "set macaddress from the ipv4 setup" do - @ohai._require_plugin("network") - @ohai["macaddress"].should == "00:16:3E:2F:36:79" + @plugin.run + @plugin["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.should_receive(:debug).any_number_of_times - @ohai._require_plugin("network") + @plugin.run end end describe "ipv4 interface has no ARP" do before do - @ohai["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,kv| kv["family"] == "lladdr" } + @plugin["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,kv| kv["family"] == "lladdr" } # not really checked by this pluging - @ohai["network"]["interfaces"]["eth0"]["flags"] << "NOARP" - @ohai["network"]["default_inet6_gateway"] = "3ffe:1111:3333::" - @ohai["network"]["default_inet6_interface"] = "eth1" + @plugin["network"]["interfaces"]["eth0"]["flags"] << "NOARP" + @plugin["network"]["default_inet6_gateway"] = "3ffe:1111:3333::" + @plugin["network"]["default_inet6_interface"] = "eth1" end it_does_not_fail it "detects {ip,ip6}address" do - @ohai._require_plugin("network") - @ohai["ipaddress"].should == "192.168.66.33" - @ohai["ip6address"].should == "3ffe:1111:3333::1" + @plugin.run + @plugin["ipaddress"].should == "192.168.66.33" + @plugin["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/) - @ohai._require_plugin("network") - @ohai["macaddress"].should be_nil + @plugin.run + @plugin["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.should_receive(:debug).any_number_of_times - @ohai._require_plugin("network") + @plugin.run end end end @@ -234,61 +228,56 @@ 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 - @ohai["network"]["default_interface"] = "eth1" - @ohai["network"]["default_inet6_interface"] = "eth1" + @plugin["network"]["default_interface"] = "eth1" + @plugin["network"]["default_inet6_interface"] = "eth1" end it_does_not_fail it "picks {ip,ip6,mac}address" do 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" + @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" 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 - @ohai._require_plugin("network") + @plugin.run end end describe "there's a default gateway, none of the configured ip/mask theorically allows to reach it" do before do - @ohai["network"]["default_gateway"] = "172.16.12.42" - @ohai["network"]["default_inet6_gateway"] = "3ffe:12:42::7070" + @plugin["network"]["default_gateway"] = "172.16.12.42" + @plugin["network"]["default_inet6_gateway"] = "3ffe:12:42::7070" end it "picks {ip,ip6,mac}address" do 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" + @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" 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 - @ohai["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,v| %w[inet inet6].include? v["family"]} + @plugin["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.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 + @plugin.run + @plugin["ipaddress"].should be_nil + @plugin["macaddress"].should be_nil + @plugin["ip6address"].should be_nil end it "warns about this conflict" do @@ -297,17 +286,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 - @ohai._require_plugin("network") + @plugin.run end end describe "no ip at all" do before do - @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| + @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| iv["addresses"].delete_if{|k,kv| %w[inet inet6].include? kv["family"]} end end @@ -316,17 +305,17 @@ describe Ohai::System, "Network Plugin" do it "doesn't detect {ip,ip6,mac}address" do 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 + @plugin.run + @plugin["ipaddress"].should be_nil + @plugin["macaddress"].should be_nil + @plugin["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 - @ohai._require_plugin("network") + @plugin.run end end end @@ -334,7 +323,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 - @ohai["network"]["interfaces"]["eth2"] = { + @plugin["network"]["interfaces"]["eth2"] = { "flags" => ["BROADCAST", "MULTICAST", "UP"], "number" => "2", "addresses" => { @@ -363,23 +352,23 @@ describe Ohai::System, "Network Plugin" do it_does_not_fail it "sets {ip,ip6,mac}address correctly" do - @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" + @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" end end describe "bigger prefix set on the default interface" do before do - @ohai["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.99"] = { + @plugin["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.99"] = { "scope" => "Global", "netmask" => "255.255.255.128", "broadcast" => "192.168.66.127", "prefixlen" => "25", "family" => "inet" } - @ohai["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222:0:4444::1"] = { + @plugin["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222:0:4444::1"] = { "prefixlen" => "64", "family" => "inet6", "scope" => "Global" @@ -389,16 +378,16 @@ describe Ohai::System, "Network Plugin" do it_does_not_fail it "sets {ip,ip6,mac}address correctly" do - @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" + @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" end end describe "smallest ip not set on the default_interface" do before do - @ohai["network"]["interfaces"]["eth2"] = { + @plugin["network"]["interfaces"]["eth2"] = { "flags" => ["BROADCAST", "MULTICAST", "UP"], "number" => "2", "addresses" => { @@ -427,23 +416,23 @@ describe Ohai::System, "Network Plugin" do it_does_not_fail it "sets {ip,ip6,mac}address correctly" do - @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" + @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" end end describe "smallest ip set on the default_interface" do before do - @ohai["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.32"] = { + @plugin["network"]["interfaces"]["eth0"]["addresses"]["192.168.66.32"] = { "scope" => "Global", "netmask" => "255.255.255.0", "broadcast" => "192.168.66.255", "prefixlen" => "24", "family" => "inet" } - @ohai["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222::32"] = { + @plugin["network"]["interfaces"]["eth0"]["addresses"]["3ffe:1111:2222::32"] = { "prefixlen" => "48", "family" => "inet6", "scope" => "Global" @@ -453,10 +442,10 @@ describe Ohai::System, "Network Plugin" do it_does_not_fail it "sets {ip,ip6,mac}address correctly" do - @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" + @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" end end end @@ -464,12 +453,12 @@ describe Ohai::System, "Network Plugin" do describe "no default route" do describe "first interface is not the best choice" do before do - @ohai["network"]["default_gateway"] = nil - @ohai["network"]["default_interface"] = nil - @ohai["network"]["default_inet6_gateway"] = nil - @ohai["network"]["default_inet6_interface"] = nil + @plugin["network"]["default_gateway"] = nil + @plugin["network"]["default_interface"] = nil + @plugin["network"]["default_inet6_gateway"] = nil + @plugin["network"]["default_inet6_interface"] = nil # removing inet* addresses from eth0, to complicate things a bit - @ohai["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,v| %w[inet inet6].include? v["family"]} + @plugin["network"]["interfaces"]["eth0"]["addresses"].delete_if{|k,v| %w[inet inet6].include? v["family"]} end it_does_not_fail @@ -478,21 +467,21 @@ describe Ohai::System, "Network Plugin" 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.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" + @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" end end describe "can choose from addresses with different scopes" do before do - @ohai["network"]["default_gateway"] = nil - @ohai["network"]["default_interface"] = nil - @ohai["network"]["default_inet6_gateway"] = nil - @ohai["network"]["default_inet6_interface"] = nil + @plugin["network"]["default_gateway"] = nil + @plugin["network"]["default_interface"] = nil + @plugin["network"]["default_inet6_gateway"] = nil + @plugin["network"]["default_inet6_interface"] = nil # just changing scopes to lInK for eth0 addresses - @ohai["network"]["interfaces"]["eth0"]["addresses"].each{|k,v| v[:scope]="lInK" if %w[inet inet6].include? v["family"]} + @plugin["network"]["interfaces"]["eth0"]["addresses"].each{|k,v| v[:scope]="lInK" if %w[inet inet6].include? v["family"]} end it_does_not_fail @@ -501,10 +490,10 @@ describe Ohai::System, "Network Plugin" 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.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" + @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" end end end @@ -512,36 +501,29 @@ describe Ohai::System, "Network Plugin" do describe "link level default route" do describe "simple setup" do before do - @ohai["network"]["default_gateway"] = "0.0.0.0" - @ohai["network"]["default_interface"] = "eth1" - @ohai["network"]["default_inet6_gateway"] = "::" - @ohai["network"]["default_inet6_interface"] = "eth1" + @plugin["network"]["default_gateway"] = "0.0.0.0" + @plugin["network"]["default_interface"] = "eth1" + @plugin["network"]["default_inet6_gateway"] = "::" + @plugin["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 - @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" + @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" end end describe "can choose from addresses with different scopes" do before do - @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"] = { + @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"] = { "scope" => "host", "netmask" => "255.255.255.255", "prefixlen" => "32", @@ -551,25 +533,18 @@ 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 - @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" + @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" end end end describe "point to point address" do before do - @ohai["network"]["interfaces"]["eth2"] = { + @plugin["network"]["interfaces"]["eth2"] = { "flags" => ["POINTOPOINT", "BROADCAST", "MULTICAST", "UP"], "number" => "2", "addresses" => { @@ -594,27 +569,27 @@ describe Ohai::System, "Network Plugin" do } } } - @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" + @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" end it_does_not_fail it "picks {ip,mac,ip6}address from the default interface" do - @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" + @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" end end describe "ipv6 only node" do before do - @ohai["network"]["default_gateway"] = nil - @ohai["network"]["default_interface"] = nil - @ohai["network"]["interfaces"].each do |i,iv| + @plugin["network"]["default_gateway"] = nil + @plugin["network"]["default_interface"] = nil + @plugin["network"]["interfaces"].each do |i,iv| iv["addresses"].delete_if{|k,kv| kv["family"] == "inet" } end end @@ -623,27 +598,27 @@ describe Ohai::System, "Network Plugin" do it "can't detect ipaddress" do Ohai::Log.should_receive(:warn).any_number_of_times - @ohai._require_plugin("network") - @ohai["ipaddress"].should be_nil + @plugin.run + @plugin["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 - @ohai._require_plugin("network") + @plugin.run end it "sets {ip6,mac}address" do 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" + @plugin.run + @plugin["ip6address"].should == "3ffe:1111:2222::33" + @plugin["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.should_receive(:debug).any_number_of_times - @ohai._require_plugin("network") + @plugin.run end end @@ -652,15 +627,14 @@ 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 - @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).twice.and_return(true) - @ohai["network"] = basic_data[os]["network"] + @plugin.stub!(:require_plugin).twice.and_return(true) + @plugin["network"] = basic_data[os]["network"] end describe "{ip,mac}address are already set" do before do - @ohai["ipaddress"] = "10.11.12.13" - @ohai["macaddress"] = "00:AA:BB:CC:DD:EE" + @plugin["ipaddress"] = "10.11.12.13" + @plugin["macaddress"] = "00:AA:BB:CC:DD:EE" @expected_results = { "linux" => { "ip6address" => "3ffe:1111:2222::33" @@ -674,21 +648,21 @@ describe Ohai::System, "Network Plugin" do it_does_not_fail it "detects ip6address" do - @ohai._require_plugin("network") - @ohai["ip6address"].should == @expected_results[os]["ip6address"] + @plugin.run + @plugin["ip6address"].should == @expected_results[os]["ip6address"] end it "doesn't overwrite {ip,mac}address" do - @ohai._require_plugin("network") - @ohai["ipaddress"].should == "10.11.12.13" - @ohai["macaddress"].should == "00:AA:BB:CC:DD:EE" + @plugin.run + @plugin["ipaddress"].should == "10.11.12.13" + @plugin["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 - @ohai["ip6address"] = "3ffe:8888:9999::1" + @plugin["ip6address"] = "3ffe:8888:9999::1" @expected_results = { "linux" => { "ipaddress" => "192.168.66.33", @@ -704,51 +678,51 @@ describe Ohai::System, "Network Plugin" do it_does_not_fail it "detects {ip,mac}address" do - @ohai._require_plugin("network") - @ohai["ipaddress"].should == @expected_results[os]["ipaddress"] - @ohai["macaddress"].should == @expected_results[os]["macaddress"] + @plugin.run + @plugin["ipaddress"].should == @expected_results[os]["ipaddress"] + @plugin["macaddress"].should == @expected_results[os]["macaddress"] end it "doesn't overwrite ip6address" do - @ohai._require_plugin("network") - @ohai["ip6address"].should == "3ffe:8888:9999::1" + @plugin.run + @plugin["ip6address"].should == "3ffe:8888:9999::1" end end describe "ipv6 only node" do before do - @ohai["network"]["default_gateway"] = nil - @ohai["network"]["default_interface"] = nil - @ohai["network"]["interfaces"].each do |i,iv| + @plugin["network"]["default_gateway"] = nil + @plugin["network"]["default_interface"] = nil + @plugin["network"]["interfaces"].each do |i,iv| iv["addresses"].delete_if{|k,kv| kv["family"] == "inet" } end - @ohai["ip6address"] = "3ffe:8888:9999::1" + @plugin["ip6address"] = "3ffe:8888:9999::1" end it_does_not_fail it "can't detect ipaddress (ipv4)" do Ohai::Log.should_receive(:warn).any_number_of_times - @ohai._require_plugin("network") - @ohai["ipaddress"].should be_nil + @plugin.run + @plugin["ipaddress"].should be_nil end it "can't detect macaddress either" do Ohai::Log.should_receive(:warn).any_number_of_times - @ohai._require_plugin("network") - @ohai["macaddress"].should be_nil + @plugin.run + @plugin["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 - @ohai._require_plugin("network") + @plugin.run end it "doesn't overwrite ip6address" do Ohai::Log.should_receive(:warn).any_number_of_times - @ohai._require_plugin("network") - @ohai["ip6address"].should == "3ffe:8888:9999::1" + @plugin.run + @plugin["ip6address"].should == "3ffe:8888:9999::1" end end end @@ -756,8 +730,8 @@ describe Ohai::System, "Network Plugin" do describe "{mac,ip6}address are already set" do describe "valid ipv4 setup" do before do - @ohai["macaddress"] = "00:AA:BB:CC:DD:EE" - @ohai["ip6address"] = "3ffe:8888:9999::1" + @plugin["macaddress"] = "00:AA:BB:CC:DD:EE" + @plugin["ip6address"] = "3ffe:8888:9999::1" @expected_results = { "linux" => { "ipaddress" => "192.168.66.33", @@ -773,75 +747,75 @@ describe Ohai::System, "Network Plugin" do it_does_not_fail it "detects ipaddress and overwrite macaddress" do - @ohai._require_plugin("network") - @ohai["ipaddress"].should == @expected_results[os]["ipaddress"] - @ohai["macaddress"].should == @expected_results[os]["macaddress"] + @plugin.run + @plugin["ipaddress"].should == @expected_results[os]["ipaddress"] + @plugin["macaddress"].should == @expected_results[os]["macaddress"] end it "doesn't overwrite ip6address" do - @ohai._require_plugin("network") - @ohai["ip6address"].should == "3ffe:8888:9999::1" + @plugin.run + @plugin["ip6address"].should == "3ffe:8888:9999::1" end end describe "ipv6 only node" do before do - @ohai["network"]["default_gateway"] = nil - @ohai["network"]["default_interface"] = nil - @ohai["network"]["interfaces"].each do |i,iv| + @plugin["network"]["default_gateway"] = nil + @plugin["network"]["default_interface"] = nil + @plugin["network"]["interfaces"].each do |i,iv| iv["addresses"].delete_if{|k,kv| kv["family"] == "inet" } end - @ohai["macaddress"] = "00:AA:BB:CC:DD:EE" - @ohai["ip6address"] = "3ffe:8888:9999::1" + @plugin["macaddress"] = "00:AA:BB:CC:DD:EE" + @plugin["ip6address"] = "3ffe:8888:9999::1" end it_does_not_fail it "can't set ipaddress" do Ohai::Log.should_receive(:warn).any_number_of_times - @ohai._require_plugin("network") - @ohai["ipaddress"].should be_nil + @plugin.run + @plugin["ipaddress"].should be_nil end it "doesn't overwrite {ip6,mac}address" do 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" + @plugin.run + @plugin["ip6address"].should == "3ffe:8888:9999::1" + @plugin["macaddress"].should == "00:AA:BB:CC:DD:EE" end end end describe "{ip,mac,ip6}address are already set" do before do - @ohai["ipaddress"] = "10.11.12.13" - @ohai["macaddress"] = "00:AA:BB:CC:DD:EE" - @ohai["ip6address"] = "3ffe:8888:9999::1" + @plugin["ipaddress"] = "10.11.12.13" + @plugin["macaddress"] = "00:AA:BB:CC:DD:EE" + @plugin["ip6address"] = "3ffe:8888:9999::1" end it_does_not_fail it "doesn't overwrite {ip,mac,ip6}address" do - @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" + @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" end end describe "{ip,ip6}address are already set" do before do - @ohai["ipaddress"] = "10.11.12.13" - @ohai["ip6address"] = "3ffe:8888:9999::1" + @plugin["ipaddress"] = "10.11.12.13" + @plugin["ip6address"] = "3ffe:8888:9999::1" end it_does_not_fail it "doesn't overwrite {ip,mac,ip6}address" do - @ohai._require_plugin("network") - @ohai["ipaddress"].should == "10.11.12.13" - @ohai["macaddress"].should == nil - @ohai["ip6address"].should == "3ffe:8888:9999::1" + @plugin.run + @plugin["ipaddress"].should == "10.11.12.13" + @plugin["macaddress"].should == nil + @plugin["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 fad4d404..10e7e87c 100644 --- a/spec/unit/plugins/nodejs_spec.rb +++ b/spec/unit/plugins/nodejs_spec.rb @@ -22,30 +22,31 @@ describe Ohai::System, "plugin nodejs" do before(:each) do @ohai = Ohai::System.new - @ohai[:languages] = Mash.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "nodejs.rb")) + @plugin.stub(:require_plugin) + @plugin[:languages] = Mash.new @status = 0 @stdout = "v0.8.11\n" @stderr = "" - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"node -v"}).and_return([@status, @stdout, @stderr]) + @plugin.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 - @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"node -v"}).and_return([0, "v0.8.11\n", ""]) - @ohai._require_plugin("nodejs") + @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"node -v"}).and_return([0, "v0.8.11\n", ""]) + @plugin.run end it "should set languages[:nodejs][:version]" do - @ohai._require_plugin("nodejs") - @ohai.languages[:nodejs][:version].should eql("0.8.11") + @plugin.run + @plugin.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 = "" - @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) + @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) end end diff --git a/spec/unit/plugins/ohai_spec.rb b/spec/unit/plugins/ohai_spec.rb index c9ccad4e..7f51821d 100644 --- a/spec/unit/plugins/ohai_spec.rb +++ b/spec/unit/plugins/ohai_spec.rb @@ -23,11 +23,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin ohai" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ohai.rb")) + @plugin.stub!(:require_plugin).and_return(true) end it "should set [:chef_packages][:ohai][:version] to the current version" do - @ohai._require_plugin("ohai") - @ohai[:chef_packages][:ohai][:version].should == Ohai::VERSION + @plugin.run + @plugin[: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 a51817f5..044c5145 100644 --- a/spec/unit/plugins/ohai_time_spec.rb +++ b/spec/unit/plugins/ohai_time_spec.rb @@ -22,25 +22,26 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin ohai_time" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ohai_time.rb")) + @plugin.stub!(:require_plugin).and_return(true) end it "should get the current time" do Time.should_receive(:now) - @ohai._require_plugin("ohai_time") + @plugin.run 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) - @ohai._require_plugin("ohai_time") + @plugin.run end it "should set ohai_time to the current time" do time = Time.now Time.stub!(:now).and_return(time) - @ohai._require_plugin("ohai_time") - @ohai[:ohai_time].should == time.to_f + @plugin.run + @plugin[:ohai_time].should == time.to_f end -end
\ No newline at end of file +end diff --git a/spec/unit/plugins/openbsd/hostname_spec.rb b/spec/unit/plugins/openbsd/hostname_spec.rb index 419822d1..95cc1739 100644 --- a/spec/unit/plugins/openbsd/hostname_spec.rb +++ b/spec/unit/plugins/openbsd/hostname_spec.rb @@ -21,11 +21,12 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "OpenBSD hostname plugin" do before(:each) do - @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") + @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") 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 0ba22433..1c09a1a6 100644 --- a/spec/unit/plugins/openbsd/kernel_spec.rb +++ b/spec/unit/plugins/openbsd/kernel_spec.rb @@ -21,17 +21,19 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "OpenBSD kernel plugin" do before(:each) do - @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" + @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" end it "should set the kernel_os to the kernel_name value" do - @ohai._require_plugin("openbsd::kernel") - @ohai[:kernel][:os].should == @ohai[:kernel][:name] + @plugin.run + @plugin[:kernel][:os].should == @plugin[:kernel][:name] end end diff --git a/spec/unit/plugins/openbsd/platform_spec.rb b/spec/unit/plugins/openbsd/platform_spec.rb index 9fb24fa4..b84876fc 100644 --- a/spec/unit/plugins/openbsd/platform_spec.rb +++ b/spec/unit/plugins/openbsd/platform_spec.rb @@ -21,20 +21,21 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "OpenBSD plugin platform" do before(:each) do - @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" + @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" end it "should set platform to lowercased lsb[:id]" do - @ohai._require_plugin("openbsd::platform") - @ohai[:platform].should == "openbsd" + @plugin.run + @plugin[:platform].should == "openbsd" end it "should set platform_version to lsb[:release]" do - @ohai._require_plugin("openbsd::platform") - @ohai[:platform_version].should == "4.5" + @plugin.run + @plugin[:platform_version].should == "4.5" end end diff --git a/spec/unit/plugins/os_spec.rb b/spec/unit/plugins/os_spec.rb index 52c5d1b9..87c3d93f 100644 --- a/spec/unit/plugins/os_spec.rb +++ b/spec/unit/plugins/os_spec.rb @@ -24,11 +24,12 @@ ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG['host_os'] describe Ohai::System, "plugin os" do before(:each) do @ohai = Ohai::System.new - @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" + @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" end after do @@ -36,8 +37,8 @@ describe Ohai::System, "plugin os" do end it "should set os_version to kernel_release" do - @ohai._require_plugin("os") - @ohai[:os_version].should == @ohai[:kernel][:release] + @plugin.run + @plugin[:os_version].should == @plugin[:kernel][:release] end describe "on linux" do @@ -46,8 +47,8 @@ describe Ohai::System, "plugin os" do end it "should set the os to linux" do - @ohai._require_plugin("os") - @ohai[:os].should == "linux" + @plugin.run + @plugin[:os].should == "linux" end end @@ -57,8 +58,8 @@ describe Ohai::System, "plugin os" do end it "should set the os to darwin" do - @ohai._require_plugin("os") - @ohai[:os].should == "darwin" + @plugin.run + @plugin[:os].should == "darwin" end end @@ -68,8 +69,8 @@ describe Ohai::System, "plugin os" do end it "sets the os to solaris2" do - @ohai._require_plugin("os") - @ohai[:os].should == "solaris2" + @plugin.run + @plugin[:os].should == "solaris2" end end @@ -79,8 +80,8 @@ describe Ohai::System, "plugin os" do end it "sets the os to the ruby 'host_os'" do - @ohai._require_plugin("os") - @ohai[:os].should == "tron" + @plugin.run + @plugin[:os].should == "tron" end end end diff --git a/spec/unit/plugins/passwd_spec.rb b/spec/unit/plugins/passwd_spec.rb index ef8c4558..b3470ea1 100644 --- a/spec/unit/plugins/passwd_spec.rb +++ b/spec/unit/plugins/passwd_spec.rb @@ -3,7 +3,8 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin etc" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "passwd.rb")) + @plugin.stub!(:require_plugin).and_return(true) end PasswdEntry = Struct.new(:name, :uid, :gid, :dir, :shell, :gecos) @@ -12,22 +13,22 @@ 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')) - @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') + @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') end it "should set the current user" do Etc.should_receive(:getlogin).and_return('chef') - @ohai._require_plugin("passwd") - @ohai[:current_user].should == 'chef' + @plugin.run + @plugin[: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'])) - @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']) + @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']) end if "".respond_to?(:force_encoding) @@ -35,8 +36,8 @@ describe Ohai::System, "plugin etc" 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)) - @ohai._require_plugin("passwd") - root = @ohai[:etc][:passwd]['root'] + @plugin.run + root = @plugin[: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 7be7a5fa..d5d48846 100644 --- a/spec/unit/plugins/perl_spec.rb +++ b/spec/unit/plugins/perl_spec.rb @@ -21,8 +21,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin perl" do before(:each) do @ohai = Ohai::System.new - @ohai[:languages] = Mash.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "perl.rb")) + @plugin[:languages] = Mash.new + @plugin.stub!(:require_plugin).and_return(true) @pid = 2342 @stderr = StringIO.new @stdout = StringIO.new(<<-OUT) @@ -31,7 +32,7 @@ archname='darwin-thread-multi-2level'; OUT @stdin = StringIO.new @status = 0 - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ @status, @stdout, @stderr @@ -39,44 +40,44 @@ OUT end it "should run perl -V:version -V:archname" do - @ohai.should_receive(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return(true) - @ohai._require_plugin("perl") + @plugin.should_receive(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return(true) + @plugin.run end it "should iterate over each line of perl command's stdout" do @stdout.should_receive(:each_line).and_return(true) - @ohai._require_plugin("perl") + @plugin.run end it "should set languages[:perl][:version]" do - @ohai._require_plugin("perl") - @ohai.languages[:perl][:version].should eql("5.8.8") + @plugin.run + @plugin.languages[:perl][:version].should eql("5.8.8") end it "should set languages[:perl][:archname]" do - @ohai._require_plugin("perl") - @ohai.languages[:perl][:archname].should eql("darwin-thread-multi-2level") + @plugin.run + @plugin.languages[:perl][:archname].should eql("darwin-thread-multi-2level") end it "should set languages[:perl] if perl command succeeds" do @status = 0 - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ @status, @stdout, @stderr ]) - @ohai._require_plugin("perl") - @ohai.languages.should have_key(:perl) + @plugin.run + @plugin.languages.should have_key(:perl) end it "should not set languages[:perl] if perl command fails" do @status = 1 - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"perl -V:version -V:archname"}).and_return([ @status, @stdout, @stderr ]) - @ohai._require_plugin("perl") - @ohai.languages.should_not have_key(:perl) + @plugin.run + @plugin.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 fa084768..d673214d 100644 --- a/spec/unit/plugins/php_spec.rb +++ b/spec/unit/plugins/php_spec.rb @@ -22,31 +22,32 @@ describe Ohai::System, "plugin php" do before(:each) do @ohai = Ohai::System.new - @ohai[:languages] = Mash.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "php.rb")) + @plugin[:languages] = Mash.new + @plugin.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 = "" - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"php -v"}).and_return([@status, @stdout, @stderr]) + @plugin.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 - @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") + @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 end it "should set languages[:php][:version]" do - @ohai._require_plugin("php") - @ohai.languages[:php][:version].should eql("5.1.6") + @plugin.run + @plugin.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 = "" - @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) + @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) end end diff --git a/spec/unit/plugins/platform_spec.rb b/spec/unit/plugins/platform_spec.rb index 776709b7..69c029ae 100644 --- a/spec/unit/plugins/platform_spec.rb +++ b/spec/unit/plugins/platform_spec.rb @@ -22,50 +22,51 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin platform" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:os] = 'monkey' - @ohai[:os_version] = 'poop' + @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' end it "should require the os platform plugin" do - @ohai.should_receive(:require_plugin).with("monkey::platform") - @ohai._require_plugin("platform") + @plugin.should_receive(:require_plugin).with("monkey::platform") + @plugin.run end it "should set the platform and platform family to the os if it was not set earlier" do - @ohai._require_plugin("platform") - @ohai[:platform].should eql("monkey") - @ohai[:platform_family].should eql("monkey") + @plugin.run + @plugin[:platform].should eql("monkey") + @plugin[:platform_family].should eql("monkey") end it "should not set the platform to the os if it was set earlier" do - @ohai[:platform] = 'lars' - @ohai._require_plugin("platform") - @ohai[:platform].should eql("lars") + @plugin[:platform] = 'lars' + @plugin.run + @plugin[:platform].should eql("lars") end it "should set the platform_family to the platform if platform was set earlier but not platform_family" do - @ohai[:platform] = 'lars' - @ohai[:platform_family] = 'jack' - @ohai._require_plugin("platform") - @ohai[:platform_family].should eql("jack") + @plugin[:platform] = 'lars' + @plugin[:platform_family] = 'jack' + @plugin.run + @plugin[:platform_family].should eql("jack") end it "should not set the platform_family if the platform_family was set earlier." do - @ohai[:platform] = 'lars' - @ohai._require_plugin("platform") - @ohai[:platform].should eql("lars") - @ohai[:platform_family].should eql("lars") + @plugin[:platform] = 'lars' + @plugin.run + @plugin[:platform].should eql("lars") + @plugin[:platform_family].should eql("lars") end it "should set the platform_version to the os_version if it was not set earlier" do - @ohai._require_plugin("platform") - @ohai[:os_version].should eql("poop") + @plugin.run + @plugin[:os_version].should eql("poop") end it "should not set the platform to the os if it was set earlier" do - @ohai[:platform_version] = 'ulrich' - @ohai._require_plugin("platform") - @ohai[:platform_version].should eql("ulrich") + @plugin[:platform_version] = 'ulrich' + @plugin.run + @plugin[:platform_version].should eql("ulrich") end end diff --git a/spec/unit/plugins/python_spec.rb b/spec/unit/plugins/python_spec.rb index c1e4b321..6d6f69eb 100644 --- a/spec/unit/plugins/python_spec.rb +++ b/spec/unit/plugins/python_spec.rb @@ -23,31 +23,32 @@ describe Ohai::System, "plugin python" do before(:each) do @ohai = Ohai::System.new - @ohai[:languages] = Mash.new - @ohai.stub!(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "python.rb")) + @plugin[:languages] = Mash.new + @plugin.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 = "" - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"python -c \"import sys; print sys.version\""}).and_return([@status, @stdout, @stderr]) + @plugin.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 - @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") + @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 end it "should set languages[:python][:version]" do - @ohai._require_plugin("python") - @ohai.languages[:python][:version].should eql("2.5.2") + @plugin.run + @plugin.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 = "" - @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) + @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) end end diff --git a/spec/unit/plugins/rackspace_spec.rb b/spec/unit/plugins/rackspace_spec.rb index a58c257b..f868cf9c 100644 --- a/spec/unit/plugins/rackspace_spec.rb +++ b/spec/unit/plugins/rackspace_spec.rb @@ -20,8 +20,9 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') describe Ohai::System, "plugin rackspace" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:network] = {:interfaces => {:eth0 => {"addresses"=> { + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "rackspace.rb")) + @plugin.stub!(:require_plugin).and_return(true) + @plugin[:network] = {:interfaces => {:eth0 => {"addresses"=> { "1.2.3.4"=> { "broadcast"=> "67.23.20.255", "netmask"=> "255.255.255.0", @@ -40,64 +41,66 @@ describe Ohai::System, "plugin rackspace" do "40:40:95:47:6E:ED"=> { "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" - } + }} + } + } + + @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" + } }} # 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 - @ohai[:kernel] = { :release => "1.2.13-not-rackspace" } + @plugin[:kernel] = { :release => "1.2.13-not-rackspace" } # We need a generic stub here for the later stubs with arguments to work # Because, magic. - @ohai.stub(:run_command).and_return(false) + @plugin.stub(:run_command).and_return(false) end shared_examples_for "!rackspace" do it "should NOT create rackspace" do - @ohai._require_plugin("rackspace") - @ohai[:rackspace].should be_nil + @plugin.run + @plugin[:rackspace].should be_nil end end shared_examples_for "rackspace" do it "should create rackspace" do - @ohai._require_plugin("rackspace") - @ohai[:rackspace].should_not be_nil + @plugin.run + @plugin[:rackspace].should_not be_nil end it "should have all required attributes" do - @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 + @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 end it "should have correct values for all attributes" do - @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" + @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" end it "should capture region information" do @@ -108,9 +111,9 @@ server_id = "21301000" created_at = "2012-12-06T22:08:16Z" region = "dfw" OUT - @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" + @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" end end @@ -142,6 +145,9 @@ OUT 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) end end @@ -152,7 +158,7 @@ OUT stderr = StringIO.new stdout = "Rackspace\n" status = 0 - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xenstore-read vm-data/provider_data/provider"}).and_return([ status, stdout, stderr ]) + @plugin.stub!(:run_command).with({:no_status_check=>true, :command=>"xenstore-read vm-data/provider_data/provider"}).and_return([ status, stdout, stderr ]) end end @@ -163,7 +169,7 @@ OUT stderr = StringIO.new stdout = "cumulonimbus\n" status = 0 - @ohai.stub!(:run_command).with({:no_status_check=>true, :command=>"xenstore-read vm-data/provider_data/provider"}).and_return([ status, stdout, stderr ]) + @plugin.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 42c767f8..31043d09 100644 --- a/spec/unit/plugins/root_group_spec.rb +++ b/spec/unit/plugins/root_group_spec.rb @@ -23,6 +23,8 @@ 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 @@ -42,8 +44,8 @@ describe Ohai::System, 'root_group' do @grgid.stub!(:name).and_return('wheel') end it 'should have a root_group of wheel' do - @ohai._require_plugin('root_group') - @ohai[:root_group].should == 'wheel' + @plugin.run + @plugin[:root_group].should == 'wheel' end end @@ -52,8 +54,8 @@ describe Ohai::System, 'root_group' do @grgid.stub!(:name).and_return('root') end it 'should have a root_group of root' do - @ohai._require_plugin('root_group') - @ohai[:root_group].should == 'root' + @plugin.run + @plugin[:root_group].should == 'root' end end @@ -63,8 +65,8 @@ describe Ohai::System, 'root_group' do @grgid.stub!(:name).and_return('sys') end it 'should have a root_group of sys' do - @ohai._require_plugin('root_group') - @ohai[:root_group].should == 'sys' + @plugin.run + @plugin[:root_group].should == 'sys' end end describe 'platform aix with system group' do @@ -72,8 +74,8 @@ describe Ohai::System, 'root_group' do @grgid.stub!(:name).and_return('system') end it 'should have a root_group of system' do - @ohai._require_plugin('root_group') - @ohai[:root_group].should == 'system' + @plugin.run + @plugin[:root_group].should == 'system' end end end @@ -110,8 +112,8 @@ describe Ohai::System, 'root_group' do and_return('Administrator') end it 'should have a root_group of system' do - @ohai._require_plugin('root_group') - @ohai[:root_group].should == 'Administrator' + @plugin.run + @plugin[:root_group].should == 'Administrator' end end @@ -123,8 +125,8 @@ describe Ohai::System, 'root_group' do and_return('BOFH') end it 'should have a root_group of system' do - @ohai._require_plugin('root_group') - @ohai[:root_group].should == 'BOFH' + @plugin.run + @plugin[:root_group].should == 'BOFH' end end end diff --git a/spec/unit/plugins/ruby_spec.rb b/spec/unit/plugins/ruby_spec.rb index b97057f9..3db81dd3 100644 --- a/spec/unit/plugins/ruby_spec.rb +++ b/spec/unit/plugins/ruby_spec.rb @@ -19,17 +19,18 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper.rb') -ruby_bin = File.join(::Config::CONFIG['bindir'], ::Config::CONFIG['ruby_install_name']) +ruby_bin = File.join(::RbConfig::CONFIG['bindir'], ::RbConfig::CONFIG['ruby_install_name']) describe Ohai::System, "plugin ruby" do before(:all) do @ohai = Ohai::System.new - @ohai[:languages] = Mash.new + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ruby.rb")) + @plugin[:languages] = Mash.new - @ohai.require_plugin("ruby") + @plugin.require_plugin("ruby") - @ruby_ohai_data_pristine = @ohai[:languages][:ruby] + @ruby_ohai_data_pristine = @plugin[:languages][:ruby] end before(:each) do @@ -40,16 +41,16 @@ describe Ohai::System, "plugin ruby" do :platform => RUBY_PLATFORM, :version => RUBY_VERSION, :release_date => RUBY_RELEASE_DATE, - :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}" + :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}" }.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 7005c70d..98f6c600 100644 --- a/spec/unit/plugins/sigar/network_route_spec.rb +++ b/spec/unit/plugins/sigar/network_route_spec.rb @@ -33,6 +33,7 @@ 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", @@ -120,15 +121,15 @@ describe Ohai::System, "Sigar network route plugin" do # 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) - @ohai.require_plugin("os") - @ohai[:os]="sigar" + @plugin.require_plugin("os") + @plugin[:os]="sigar" Ohai::Log.should_receive(:warn).with(/unable to detect ip6address/).once - @ohai.require_plugin("network") - @ohai.require_plugin("sigar::network_route") + @plugin.require_plugin("network") + @plugin.require_plugin("sigar::network_route") end it "should set the routes" do - @ohai[:network][:interfaces][:eth0].should have_key(:route) + @plugin[:network][:interfaces][:eth0].should have_key(:route) end it "should set the route details" do @@ -136,10 +137,10 @@ describe Ohai::System, "Sigar network route plugin" do # Work around the above mocking of net_route_list skipping the call to flags() if k == :flags v="U" - @ohai[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v + @plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v end - @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) + @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) end end diff --git a/spec/unit/plugins/solaris2/hostname_spec.rb b/spec/unit/plugins/solaris2/hostname_spec.rb index 5bf40b2e..cc6c9572 100644 --- a/spec/unit/plugins/solaris2/hostname_spec.rb +++ b/spec/unit/plugins/solaris2/hostname_spec.rb @@ -21,9 +21,10 @@ 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 - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:os] = "solaris2" - @ohai.stub!(:from).with("hostname").and_return("kitteh") + @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]] ); end @@ -31,8 +32,8 @@ describe Ohai::System, "Solaris2.X hostname plugin" do it "should get the fqdn value from socket getaddrinfo" do Socket.should_receive(:getaddrinfo) - @ohai._require_plugin("solaris2::hostname") - @ohai["fqdn"].should == "kitteh.inurfridge.eatinurfoodz" + @plugin.run + @plugin["fqdn"].should == "kitteh.inurfridge.eatinurfoodz" end -end
\ No newline at end of file +end diff --git a/spec/unit/plugins/solaris2/kernel_spec.rb b/spec/unit/plugins/solaris2/kernel_spec.rb index 7b50db68..052b97c7 100644 --- a/spec/unit/plugins/solaris2/kernel_spec.rb +++ b/spec/unit/plugins/solaris2/kernel_spec.rb @@ -135,30 +135,29 @@ describe Ohai::System, "Solaris2.X kernel plugin" do before(:each) do @ohai = Ohai::System.new - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:kernel] = Mash.new - @ohai.stub(:from).with("uname -s").and_return("SunOS") + @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) end it_should_check_from_deep_mash("solaris2::kernel", "kernel", "os", "uname -s", "SunOS") it "gives excruciating detail about kernel modules" do - 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.run - @ohai[:kernel][:modules].should have(107).modules + @plugin[: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"} - @ohai[:kernel][:modules].keys.should include("specfs") - @ohai[:kernel][:modules].keys.should_not include("Module") - @ohai[:kernel][:modules]["specfs"].should == teh_daterz + @plugin[:kernel][:modules].keys.should include("specfs") + @plugin[:kernel][:modules].keys.should_not include("Module") + @plugin[: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 b151502f..17457ad9 100644 --- a/spec/unit/plugins/solaris2/network_spec.rb +++ b/spec/unit/plugins/solaris2/network_spec.rb @@ -87,41 +87,43 @@ 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 - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:network] = Mash.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(:popen4).with("ifconfig -a") - @ohai.stub(:popen4).with("arp -an") + @plugin.stub(:popen4).with("ifconfig -a") + @plugin.stub(:popen4).with("arp -an") end describe "gathering IP layer address info" do before do - @ohai.stub!(:popen4).with("ifconfig -a").and_yield(nil, @stdin, @ifconfig_lines, nil) - @ohai._require_plugin("solaris2::network") + @stdout = mock("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 end it "completes the run" do - @ohai['network'].should_not be_nil + @plugin['network'].should_not be_nil end it "detects the interfaces" do - @ohai['network']['interfaces'].keys.sort.should == ["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "lo0", "lo0:3", "net0", "qfe1"] + @plugin['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 - @ohai['network']['interfaces']['e1000g0:3']['addresses'].keys.should include('72.2.115.28') + @plugin['network']['interfaces']['e1000g0:3']['addresses'].keys.should include('72.2.115.28') end it "detects the encapsulation type of the interfaces" do - @ohai['network']['interfaces']['e1000g0:3']['encapsulation'].should == 'Ethernet' + @plugin['network']['interfaces']['e1000g0:3']['encapsulation'].should == 'Ethernet' end it "detects the L3PROTECT network flag" do - @ohai['network']['interfaces']['net0']['flags'].should include('L3PROTECT') + @plugin['network']['interfaces']['net0']['flags'].should include('L3PROTECT') end end @@ -130,12 +132,12 @@ ROUTE_GET describe "setting the node's default IP address attribute" do before do @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") + @plugin.stub!(:popen4).with("route -n get default").and_yield(nil,StringIO.new, @stdout, nil) + @plugin.run end it "finds the default interface by asking which iface has the default route" do - @ohai[:network][:default_interface].should == 'e1000g0' + @plugin[: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 faafc692..8c853efd 100644 --- a/spec/unit/plugins/solaris2/platform_spec.rb +++ b/spec/unit/plugins/solaris2/platform_spec.rb @@ -21,10 +21,11 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Solaris plugin platform" do before(:each) do @ohai = Ohai::System.new - @ohai.extend(SimpleFromFile) - @ohai.stub!(:require_plugin).and_return(true) - @ohai[:os] = "solaris2" - @ohai.stub!(:popen4).with("/sbin/uname -X") + @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") end describe "on SmartOS" do @@ -50,26 +51,25 @@ UNAME_X @uname_x_lines = uname_x.split("\n") 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) + @plugin.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") - @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 - @ohai._require_plugin("solaris2::platform") - @ohai[:platform_build].should == "joyent_20120130T201844Z" + @plugin.run + @plugin[:platform_build].should == "joyent_20120130T201844Z" end it "should set the platform" do - @ohai._require_plugin("solaris2::platform") - @ohai[:platform].should == "smartos" + @plugin.run + @plugin[:platform].should == "smartos" end it "should set the platform_version" do - @ohai._require_plugin("solaris2::platform") - @ohai[:platform_version].should == "5.11" + @plugin.run + @plugin[: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 53955a15..498f65d7 100644 --- a/spec/unit/plugins/solaris2/virtualization_spec.rb +++ b/spec/unit/plugins/solaris2/virtualization_spec.rb @@ -21,9 +21,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper.rb') describe Ohai::System, "Solaris virtualization platform" do before(:each) do @ohai = Ohai::System.new - @ohai[:os] = "solaris2" - @ohai.stub!(:require_plugin).and_return(true) - @ohai.extend(SimpleFromFile) + @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) # default to all requested Files not existing File.stub!(:exists?).with("/usr/sbin/psrinfo").and_return(false) @@ -42,22 +43,22 @@ describe Ohai::System, "Solaris virtualization platform" do end it "should run psrinfo -pv" do - @ohai.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true) - @ohai._require_plugin("solaris2::virtualization") + @plugin.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true) + @plugin.run end it "Should set kvm guest if psrinfo -pv contains QEMU Virtual CPU" do @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" + @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" end it "should not set virtualization if kvm isn't there" do - @ohai.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true) - @ohai._require_plugin("solaris2::virtualization") - @ohai[:virtualization].should == {} + @plugin.should_receive(:popen4).with("/usr/sbin/psrinfo -pv").and_return(true) + @plugin.run + @plugin[:virtualization].should == {} end end @@ -72,8 +73,8 @@ describe Ohai::System, "Solaris virtualization platform" do end it "should run smbios" do - @ohai.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true) - @ohai._require_plugin("solaris2::virtualization") + @plugin.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true) + @plugin.run end it "should set virtualpc guest if smbios detects Microsoft Virtual Machine" do @@ -91,10 +92,10 @@ ID SIZE TYPE MSVPC @stdout.stub!(:read).and_return(ms_vpc_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 == "virtualpc" - @ohai[:virtualization][:role].should == "guest" + @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" end it "should set vmware guest if smbios detects VMware Virtual Platform" do @@ -111,22 +112,22 @@ ID SIZE TYPE Wake-Up Event: 0x6 (power switch) VMWARE @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" + @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" end it "should run smbios and not set virtualization if nothing is detected" do - @ohai.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true) - @ohai._require_plugin("solaris2::virtualization") - @ohai[:virtualization].should == {} + @plugin.should_receive(:popen4).with("/usr/sbin/smbios").and_return(true) + @plugin.run + @plugin[:virtualization].should == {} end end it "should not set virtualization if no tests match" do - @ohai._require_plugin("solaris2::virtualization") - @ohai[:virtualization].should == {} + @plugin.run + @plugin[: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 ab7fa098..16303591 100644 --- a/spec/unit/plugins/ssh_host_keys_spec.rb +++ b/spec/unit/plugins/ssh_host_keys_spec.rb @@ -22,11 +22,12 @@ describe Ohai::System, "ssh_host_key plugin" do before(:each) do @ohai = Ohai::System.new - @ohai[:keys] = Mash.new - @ohai.stub(:require_plugin).and_return(true) + @plugin = Ohai::DSL::Plugin.new(@ohai, File.join(PLUGIN_PATH, "ssh_host_key.rb")) + @plugin.stub(:require_plugin) + @plugin[:keys] = Mash.new # Avoid using the real from_file to load the plugin => less stubbing required - @ohai.extend(SimpleFromFile) + @plugin.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) @@ -50,21 +51,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 - @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 + @plugin.run + @plugin[:keys][:ssh][:host_dsa_public].should eql(@dsa_key.split[1]) + @plugin[:keys][:ssh][:host_dsa_type].should be_nil end it "reads the key and sets the rsa attribute correctly" do - @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 + @plugin.run + @plugin[:keys][:ssh][:host_rsa_public].should eql(@rsa_key.split[1]) + @plugin[:keys][:ssh][:host_rsa_type].should be_nil end it "reads the key and sets the ecdsa attribute correctly" do - @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]) + @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]) end end diff --git a/spec/unit/system_spec.rb b/spec/unit/system_spec.rb index fcaf8b74..3f2ecc26 100644 --- a/spec/unit/system_spec.rb +++ b/spec/unit/system_spec.rb @@ -22,109 +22,44 @@ 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] = ["#{tmp}/plugins"] - File.stub!(:exists?).and_return(true) + Ohai::Config[:plugin_path] = [SPEC_PLUGIN_PATH] @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 - @ohai.should_receive(:from_file).with(File.expand_path("#{tmp}/plugins/foo.rb")).and_return(true) - @ohai.require_plugin("foo") + plugin = @ohai.plugin_for("foo") + plugin.file.should == File.expand_path("foo.rb", SPEC_PLUGIN_PATH) 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 |