Skip to content

Instantly share code, notes, and snippets.

@swalberg
Created November 21, 2014 17:48
Show Gist options
  • Save swalberg/b8204b3d2da51ae65ab0 to your computer and use it in GitHub Desktop.
Save swalberg/b8204b3d2da51ae65ab0 to your computer and use it in GitHub Desktop.
action :create do
chef_gem 'f5-icontrol'
if pool_does_not_exist?
converge_by("Create pool #{pool}") do
create_pool
Chef::Log.info("#{new_resource} created pool #{pool}")
end
end
if pool_is_missing_node?
converge_by("Add #{new_resource.host} to pool #{pool}") do
add_host_to_pool
Chef::Log.info("#{new_resource} added #{new_resource.host} to pool #{pool}")
end
end
end
describe 'f5_test::test_create_pool' do
let(:api) { double('F5::Icontrol') }
let(:chef_run) { ChefSpec::SoloRunner.new(step_into: ['f5_pool']) do |node|
node.set[:f5][:credentials][:default] = { host: '1.2.3.4', username: 'api', password: 'testing' }
end.converge(described_recipe) }
before do
allow(F5::Icontrol::API).to receive(:new) { api }
end
context 'managing the pool' do
before do
allow_any_instance_of(Chef::Provider::F5Pool).to receive(:pool_is_missing_node?).and_return(false)
end
context 'the pool does not exist' do
before do
allow(api).to receive_message_chain("LocalLB.Pool.get_list") {
{:item=>["/Common/test1", "/Common/mchan01"], :"@s:type"=>"A:Array", :"@a:array_type"=>"y:string[2]"}
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment