Permalink
Browse files

Update new specs for plugin class split

Rebased from 3967b5a to
d338698. Fix tests added in the interim
to correctly setup Ohai::System and plugin classes.
  • Loading branch information...
1 parent 2e46efe commit cd2bc2eb29109ea447271efd8af44d80c10096d5 @danielsdeleo danielsdeleo committed Jul 12, 2013
@@ -23,7 +23,9 @@
#
# 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 @@ def looks_like_linode?
#
# 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
@@ -23,7 +23,7 @@
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 @@
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 @@
end
it 'should not behave like azure' do
- @ohai[:azure].should be_nil
+ @plugin[:azure].should be_nil
end
end
@@ -66,7 +66,7 @@
end
it 'should not behave like azure' do
- @ohai[:azure].should be_nil
+ @plugin[:azure].should be_nil
end
end
@@ -20,187 +20,188 @@
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
@@ -22,19 +22,18 @@
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
@@ -29,8 +29,7 @@
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 @@
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
Oops, something went wrong.

0 comments on commit cd2bc2e

Please sign in to comment.