Skip to content

Commit

Permalink
reduse code resuse in AIX virt plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Isa Farnik committed Dec 10, 2015
1 parent 36aaa28 commit ea9d23f
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions spec/unit/plugins/aix/virtualization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
describe Ohai::System, "AIX virtualization plugin" do

context "inside an LPAR" do

let(:plugin) do
p = get_plugin("aix/virtualization")
allow(p).to receive(:collect_os).and_return(:aix)
allow(p).to receive(:shell_out).with("uname -L").and_return(mock_shell_out(0, "29 l273pp027", nil))
allow(p).to receive(:shell_out).with("uname -W").and_return(mock_shell_out(0, "0", nil))
allow(p).to receive(:shell_out).with("lswpar -L").and_return(mock_shell_out(0, @lswpar_L, nil))
p
end

before(:each) do
@lswpar_L = <<-LSWPAR_L
=================================================================
Expand Down Expand Up @@ -237,68 +247,56 @@
LSWPAR_L

end
let(:plugin) do
p = get_plugin("aix/virtualization")
allow(p).to receive(:collect_os).and_return(:aix)
allow(p).to receive(:shell_out).with("uname -L").and_return(mock_shell_out(0, "29 l273pp027", nil))
allow(p).to receive(:shell_out).with("uname -W").and_return(mock_shell_out(0, "0", nil))
allow(p).to receive(:shell_out).with("lswpar -L").and_return(mock_shell_out(0, @lswpar_L, nil))
p.run
p
end

it "uname -L detects the LPAR number and name" do
plugin.run
expect(plugin[:virtualization][:lpar_no]).to eq("29")
expect(plugin[:virtualization][:lpar_name]).to eq("l273pp027")
end

context 'when WPARs exist on the LPAR' do
before do
@plugin = get_plugin("aix/virtualization")
allow(@plugin).to receive(:collect_os).and_return(:aix)
allow(@plugin).to receive(:shell_out).with("uname -L").and_return(mock_shell_out(0, "29 l273pp027", nil))
allow(@plugin).to receive(:shell_out).with("uname -W").and_return(mock_shell_out(0, "0", nil))
allow(@plugin).to receive(:shell_out).with("lswpar -L").and_return(mock_shell_out(0, @lswpar_L, nil))
@plugin.run
@wpar1 = @plugin[:virtualization][:wpars]['applejack-541ba3']
@wpar2 = @plugin[:virtualization][:wpars]['fluttershy-5c969f']
plugin.run
end

let(:wpar1) do
plugin[:virtualization][:wpars]['applejack-541ba3']
end

let(:wpar2) do
plugin[:virtualization][:wpars]['fluttershy-5c969f']
end

it 'detects all WPARs present (2)' do
expect(@plugin[:virtualization][:wpars].length).to eq(2)
expect(plugin[:virtualization][:wpars].length).to eq(2)
end

context 'when collecting WPAR info' do
it 'finds the WPAR\'s hostname correctly' do
expect(@wpar1[:hostname]).to eq("applejack-pony-541ba3.ponyville.com")
expect(@wpar2[:hostname]).to eq("fluttershy-pony-5c969f.ponyville.com")
expect(wpar1[:hostname]).to eq("applejack-pony-541ba3.ponyville.com")
expect(wpar2[:hostname]).to eq("fluttershy-pony-5c969f.ponyville.com")
end

it 'finds the WPAR\'s IP correctly' do
expect(@wpar1[:address]).to eq("192.168.0.231")
expect(@wpar2[:address]).to eq("192.168.0.18")
expect(wpar1[:address]).to eq("192.168.0.231")
expect(wpar2[:address]).to eq("192.168.0.18")
end

it 'parses device exports properly' do
expect(@wpar1['device exports']['/dev/nvram']['type']).to eq("pseudo")
expect(@wpar1['device exports']['/dev/nvram']['status']).to eq("EXPORTED")
expect(wpar1['device exports']['/dev/nvram']['type']).to eq("pseudo")
expect(wpar1['device exports']['/dev/nvram']['status']).to eq("EXPORTED")
end
end
end

context 'when WPARs don\'t exist on the LPAR' do
before do
@no_wpars_plugin = get_plugin("aix/virtualization")
allow(@no_wpars_plugin).to receive(:collect_os).and_return(:aix)
allow(@no_wpars_plugin).to receive(:shell_out).with("uname -L").and_return(mock_shell_out(0, "29 l273pp027", nil))
allow(@no_wpars_plugin).to receive(:shell_out).with("uname -W").and_return(mock_shell_out(0, "0", nil))
allow(@no_wpars_plugin).to receive(:shell_out).with("lswpar -L").and_return(mock_shell_out(0, '', nil))
@no_wpars_plugin.run
allow(plugin).to receive(:shell_out).with("lswpar -L").and_return(mock_shell_out(0, '', nil))
plugin.run
end

it 'detects all WPARs present (0)' do
expect(@no_wpars_plugin[:wpars]).to be_nil
expect(@no_wpars_plugin[:virtualization][:wpars]).to be_nil
expect(plugin[:virtualization][:wpars]).to be_nil
end
end
end
Expand Down

0 comments on commit ea9d23f

Please sign in to comment.