2013-06-22 02:12:04 -07:00
|
|
|
require_relative "spec_helper"
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
describe "openstack-ops-messaging::rabbitmq-server" do
|
|
|
|
before { ops_messaging_stubs }
|
|
|
|
describe "ubuntu" do
|
2013-06-18 19:27:06 -04:00
|
|
|
before do
|
2013-06-22 02:12:04 -07:00
|
|
|
@chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |n|
|
|
|
|
n.set["openstack"]["mq"] = {
|
|
|
|
"user" => "rabbit-user",
|
|
|
|
"vhost" => "/test-vhost"
|
2013-06-18 19:27:06 -04:00
|
|
|
}
|
|
|
|
end
|
2013-06-22 02:12:04 -07:00
|
|
|
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
2013-06-18 19:27:06 -04:00
|
|
|
end
|
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
it "overrides default rabbit attributes" do
|
|
|
|
expect(@chef_run.node["openstack"]["mq"]["port"]).to eql "5672"
|
|
|
|
expect(@chef_run.node["openstack"]["mq"]["listen"]).to eql "127.0.0.1"
|
|
|
|
expect(@chef_run.node["rabbitmq"]["address"]).to eql "127.0.0.1"
|
|
|
|
expect(@chef_run.node["rabbitmq"]["default_user"]).to eql "rabbit-user"
|
|
|
|
expect(@chef_run.node['rabbitmq']['default_pass']).to eql "rabbit-pass"
|
|
|
|
expect(@chef_run.node['rabbitmq']['erlang_cookie']).to eql(
|
|
|
|
"erlang-cookie"
|
|
|
|
)
|
|
|
|
expect(@chef_run.node['rabbitmq']['cluster']).to be_true
|
|
|
|
expect(@chef_run.node['rabbitmq']['cluster_disk_nodes']).to eql(
|
|
|
|
["rabbit-user@host1", "rabbit-user@host2"]
|
|
|
|
)
|
|
|
|
end
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
it "includes rabbit recipes" do
|
|
|
|
expect(@chef_run).to include_recipe "rabbitmq"
|
2013-06-18 19:27:06 -04:00
|
|
|
expect(@chef_run).to include_recipe "rabbitmq::mgmt_console"
|
|
|
|
end
|
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
describe "lwrps" do
|
|
|
|
it "deletes guest user" do
|
|
|
|
resource = @chef_run.find_resource(
|
|
|
|
"rabbitmq_user",
|
|
|
|
"remove rabbit guest user"
|
|
|
|
).to_hash
|
|
|
|
|
|
|
|
expect(resource).to include(
|
|
|
|
:user => "guest",
|
|
|
|
:action => [:delete]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't delete guest user" do
|
|
|
|
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
|
|
|
|
chef_run = ::ChefSpec::ChefRunner.new(opts) do |n|
|
|
|
|
n.set["openstack"]["mq"] = {
|
|
|
|
"user" => "guest",
|
|
|
|
"vhost" => "/test-vhost"
|
|
|
|
}
|
2013-06-18 19:27:06 -04:00
|
|
|
end
|
2013-06-22 02:12:04 -07:00
|
|
|
chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
resource = chef_run.find_resource(
|
|
|
|
"rabbitmq_user",
|
|
|
|
"remove rabbit guest user"
|
|
|
|
)
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
expect(resource).to be_nil
|
|
|
|
end
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
it "adds user" do
|
|
|
|
resource = @chef_run.find_resource(
|
|
|
|
"rabbitmq_user",
|
|
|
|
"add openstack rabbit user"
|
|
|
|
).to_hash
|
|
|
|
|
|
|
|
expect(resource).to include(
|
|
|
|
:user => "rabbit-user",
|
|
|
|
:password => "rabbit-pass",
|
|
|
|
:action => [:add]
|
|
|
|
)
|
|
|
|
end
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
it "adds vhost" do
|
|
|
|
resource = @chef_run.find_resource(
|
|
|
|
"rabbitmq_vhost",
|
|
|
|
"add openstack rabbit vhost"
|
|
|
|
).to_hash
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
expect(resource).to include(
|
|
|
|
:vhost => "/test-vhost",
|
|
|
|
:action => [:add]
|
|
|
|
)
|
|
|
|
end
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
it "sets user permissions" do
|
|
|
|
resource = @chef_run.find_resource(
|
|
|
|
"rabbitmq_user",
|
|
|
|
"set openstack user permissions"
|
|
|
|
).to_hash
|
|
|
|
|
|
|
|
expect(resource).to include(
|
|
|
|
:user => "rabbit-user",
|
|
|
|
:vhost => "/test-vhost",
|
|
|
|
:permissions => '.* .* .*',
|
|
|
|
:action => [:set_permissions]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "sets administrator tag" do
|
|
|
|
resource = @chef_run.find_resource(
|
|
|
|
"rabbitmq_user",
|
|
|
|
"set rabbit administrator tag"
|
|
|
|
).to_hash
|
|
|
|
|
|
|
|
expect(resource).to include(
|
|
|
|
:user => "rabbit-user",
|
|
|
|
:tag => "administrator",
|
|
|
|
:action => [:set_tags]
|
|
|
|
)
|
|
|
|
end
|
2013-06-18 19:27:06 -04:00
|
|
|
end
|
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
describe "mnesia" do
|
|
|
|
before do
|
|
|
|
::File.stub(:exists?).and_call_original
|
|
|
|
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
|
|
|
|
@chef_run = ::ChefSpec::ChefRunner.new opts do |n|
|
|
|
|
n.set["openstack"]["mq"] = {
|
|
|
|
"user" => "rabbit-user",
|
|
|
|
"vhost" => "/test-vhost"
|
|
|
|
}
|
2013-06-18 19:27:06 -04:00
|
|
|
end
|
2013-06-22 02:12:04 -07:00
|
|
|
@cmd = <<-EOH.gsub(/^\s+/, "")
|
|
|
|
service rabbitmq-server stop;
|
|
|
|
rm -rf mnesia/;
|
|
|
|
touch .reset_mnesia_database;
|
|
|
|
service rabbitmq-server start
|
|
|
|
EOH
|
|
|
|
@file = "/var/lib/rabbitmq/.reset_mnesia_database"
|
|
|
|
end
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
it "resets database" do
|
|
|
|
::File.should_receive(:exists?).
|
|
|
|
with(@file).
|
|
|
|
and_return(false)
|
|
|
|
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
expect(@chef_run).to execute_command(@cmd).with(
|
|
|
|
:cwd => "/var/lib/rabbitmq"
|
|
|
|
)
|
|
|
|
end
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
it "doesn't reset database when already did" do
|
|
|
|
::File.should_receive(:exists?).
|
|
|
|
with(@file).
|
|
|
|
and_return(true)
|
|
|
|
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
2013-06-18 19:27:06 -04:00
|
|
|
|
2013-06-22 02:12:04 -07:00
|
|
|
expect(@chef_run).not_to execute_command(@cmd)
|
|
|
|
end
|
|
|
|
end
|
2013-06-18 19:27:06 -04:00
|
|
|
end
|
|
|
|
end
|