diff options
author | danielsdeleo <dan@opscode.com> | 2013-07-11 19:33:40 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-07-15 11:59:23 -0700 |
commit | 8461a90b96c74d0ae35616d3b1ad0c327838bb3f (patch) | |
tree | 305020076ec20222595f51dd68b165e51c4dec01 | |
parent | 7ec92d42808b0158f78749e6411045682a1ad848 (diff) | |
download | ohai-8461a90b96c74d0ae35616d3b1ad0c327838bb3f.tar.gz |
Update new specs for plugin class split
Rebased from 3967b5a3fd619dc392b8bf5dd2554d822a8fd400 to
d338698f288d08379bb36611f93a3a8db7ff45f5. Fix tests added in the interim
to correctly setup Ohai::System and plugin classes.
-rw-r--r-- | lib/ohai/plugins/linode.rb | 10 | ||||
-rw-r--r-- | spec/unit/plugins/azure_spec.rb | 20 | ||||
-rw-r--r-- | spec/unit/plugins/cloud_spec.rb | 161 | ||||
-rw-r--r-- | spec/unit/plugins/darwin/cpu_spec.rb | 15 | ||||
-rw-r--r-- | spec/unit/plugins/darwin/system_profiler_spec.rb | 11 | ||||
-rw-r--r-- | spec/unit/plugins/ec2_spec.rb | 55 | ||||
-rw-r--r-- | spec/unit/plugins/freebsd/virtualization_spec.rb | 49 | ||||
-rw-r--r-- | spec/unit/plugins/gce_spec.rb | 32 | ||||
-rw-r--r-- | spec/unit/plugins/linode_spec.rb | 48 | ||||
-rw-r--r-- | spec/unit/plugins/linux/platform_spec.rb | 22 | ||||
-rw-r--r-- | spec/unit/plugins/network_spec.rb | 1 | ||||
-rw-r--r-- | spec/unit/plugins/nodejs_spec.rb | 21 | ||||
-rw-r--r-- | spec/unit/plugins/rackspace_spec.rb | 42 | ||||
-rw-r--r-- | spec/unit/plugins/root_group_spec.rb | 26 | ||||
-rw-r--r-- | spec/unit/plugins/solaris2/network_spec.rb | 4 | ||||
-rw-r--r-- | spec/unit/plugins/ssh_host_keys_spec.rb | 25 |
16 files changed, 270 insertions, 272 deletions
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/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/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/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/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/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/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/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index 58da0de1..e90f29ea 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -74,10 +74,10 @@ describe Ohai::System, "Linux plugin platform" do @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 @plugin[:lsb][:id] = "Debian" @@ -139,9 +139,9 @@ describe Ohai::System, "Linux plugin platform" do 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 @@ -379,7 +379,7 @@ describe Ohai::System, "Linux plugin platform" do it "should read the platform as suse" do @plugin[:lsb][:release] = "12.1" - File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 12.1 (x86_64)\nVERSION = 12.1\nCODENAME = Asparagus\n") + 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" @@ -416,7 +416,7 @@ describe Ohai::System, "Linux plugin platform" do end it "[OHAI-272] should read the version as 11.3" do - File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.3 (x86_64)\nVERSION = 11.3") + 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" @@ -424,7 +424,7 @@ describe Ohai::System, "Linux plugin platform" do end it "[OHAI-272] should read the version as 9.1" do - File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("SuSE Linux 9.1 (i586)\nVERSION = 9.1") + 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" @@ -432,7 +432,7 @@ describe Ohai::System, "Linux plugin platform" do end it "[OHAI-272] should read the version as 11.4" do - File.should_receive(:read).with("/etc/SuSE-release").exactly(2).times.and_return("openSUSE 11.4 (i586)\nVERSION = 11.4\nCODENAME = Celadon") + 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" diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb index 8ec0c155..ad184d86 100644 --- a/spec/unit/plugins/network_spec.rb +++ b/spec/unit/plugins/network_spec.rb @@ -245,7 +245,6 @@ describe Ohai::System, "Network Plugin" do 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::Log.should_receive(:warn).with(/^unable to detect ip6address/).once @plugin.run 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/rackspace_spec.rb b/spec/unit/plugins/rackspace_spec.rb index 36dfd8da..f868cf9c 100644 --- a/spec/unit/plugins/rackspace_spec.rb +++ b/spec/unit/plugins/rackspace_spec.rb @@ -63,11 +63,11 @@ describe Ohai::System, "plugin rackspace" do # 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 @@ -117,35 +117,6 @@ OUT end end - describe "with rackspace mac and hostname" do - it_should_behave_like "rackspace" - - before(:each) do - IO.stub!(:select).and_return([[],[1],[]]) - @plugin[:hostname] = "slice74976" - @plugin[:network][:interfaces][:eth0][:arp] = {"67.23.20.1" => "00:00:0c:07:ac:01"} - end - end - - describe "without rackspace mac" do - it_should_behave_like "!rackspace" - - before(:each) do - @plugin[:kernel] = {:release => "foo" } - @plugin[:hostname] = "slice74976" - @plugin[:network][:interfaces][:eth0][:arp] = {"169.254.1.0"=>"fe:ff:ff:ff:ff:ff"} - end - end - - describe "without rackspace hostname" do - it_should_behave_like "rackspace" - - before(:each) do - @plugin[:hostname] = "bubba" - @plugin[:network][:interfaces][:eth0][:arp] = {"67.23.20.1" => "00:00:0c:07:ac:01"} - end - end - describe "with rackspace cloud file" do it_should_behave_like "rackspace" @@ -161,8 +132,6 @@ OUT it_should_behave_like "!rackspace" before(:each) do - @plugin[:network] = {:interfaces => {} } - @plugin[:kernel] = {:release => "foo" } 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 @@ -172,9 +141,6 @@ OUT it_should_behave_like "!rackspace" before(:each) do - @plugin[:network] = {:interfaces => {} } - @plugin[:kernel] = {:release => "foo" } - 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) @@ -192,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 @@ -203,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/solaris2/network_spec.rb b/spec/unit/plugins/solaris2/network_spec.rb index f2071e59..17457ad9 100644 --- a/spec/unit/plugins/solaris2/network_spec.rb +++ b/spec/unit/plugins/solaris2/network_spec.rb @@ -111,7 +111,7 @@ ROUTE_GET end it "detects the interfaces" do - @plugin['network']['interfaces'].keys.sort.should == ["e1000g0:3", "e1000g2:1", "eri0", "ip.tun0", "ip.tun0:1", "lo0", "lo0:3", "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 @@ -123,7 +123,7 @@ ROUTE_GET 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 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 |