Updating with patterns used in ops-database
We had two reviews which added an ops-messaging cookbook. Updating this cookbook with patterns we estabished from the database cookbook. Craig already did most of the work, however, updated the tests to use the chefspec find_provider, added clustering support, and attempted to follow the service_type attribute patterns used in database cookbook. Since these cookbooks are not complete, added a larger commit than would have. Change-Id: I0edfc996df413c6e41a31d53f964d7f5fc9e0aeb
This commit is contained in:
parent
8540f839e5
commit
1c0e58dc33
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.bundle/
|
25
.tailor
Normal file
25
.tailor
Normal file
@ -0,0 +1,25 @@
|
||||
Tailor.config do |config|
|
||||
config.formatters "text"
|
||||
config.file_set '**/*.rb' do |style|
|
||||
style.max_line_length 80, level: :off
|
||||
style.allow_camel_case_methods false, level: :error
|
||||
style.allow_hard_tabs false, level: :error
|
||||
style.allow_screaming_snake_case_classes false, level: :error
|
||||
style.allow_trailing_line_spaces false, level: :error
|
||||
style.allow_invalid_ruby false, level: :warn
|
||||
style.indentation_spaces 2, level: :error
|
||||
style.max_code_lines_in_class 300, level: :error
|
||||
style.max_code_lines_in_method 30, level: :error
|
||||
style.spaces_after_comma 1, level: :error
|
||||
style.spaces_after_lbrace 1, level: :error
|
||||
style.spaces_after_lbracket 0, level: :error
|
||||
style.spaces_after_lparen 0, level: :error
|
||||
style.spaces_before_comma 0, level: :error
|
||||
style.spaces_before_lbrace 1, level: :error
|
||||
style.spaces_before_rbrace 1, level: :error
|
||||
style.spaces_before_rbracket 0, level: :error
|
||||
style.spaces_before_rparen 0, level: :error
|
||||
style.spaces_in_empty_braces 0, level: :error
|
||||
style.trailing_newlines 1, level: :error
|
||||
end
|
||||
end
|
46
Berksfile.lock
Normal file
46
Berksfile.lock
Normal file
@ -0,0 +1,46 @@
|
||||
{
|
||||
"sha": "db43c403a1eba40c4c3e7833bc8586191ed34ac7",
|
||||
"sources": {
|
||||
"openstack-ops-messaging": {
|
||||
"path": "."
|
||||
},
|
||||
"openstack-common": {
|
||||
"locked_version": "0.2.2",
|
||||
"git": "git://github.com/stackforge/cookbook-openstack-common.git",
|
||||
"ref": "0c771cfab3147489e7dffcf9b9b067f2aa9d0f8b"
|
||||
},
|
||||
"rabbitmq": {
|
||||
"locked_version": "2.1.0"
|
||||
},
|
||||
"erlang": {
|
||||
"locked_version": "1.3.0"
|
||||
},
|
||||
"apt": {
|
||||
"locked_version": "1.10.0"
|
||||
},
|
||||
"yum": {
|
||||
"locked_version": "2.2.2"
|
||||
},
|
||||
"build-essential": {
|
||||
"locked_version": "1.4.0"
|
||||
},
|
||||
"database": {
|
||||
"locked_version": "1.4.0"
|
||||
},
|
||||
"mysql": {
|
||||
"locked_version": "3.0.0"
|
||||
},
|
||||
"openssl": {
|
||||
"locked_version": "1.0.2"
|
||||
},
|
||||
"postgresql": {
|
||||
"locked_version": "3.0.0"
|
||||
},
|
||||
"aws": {
|
||||
"locked_version": "0.101.0"
|
||||
},
|
||||
"xfs": {
|
||||
"locked_version": "1.1.0"
|
||||
}
|
||||
}
|
||||
}
|
71
Gemfile.lock
71
Gemfile.lock
@ -1,26 +1,35 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
activesupport (3.2.13)
|
||||
i18n (= 0.6.1)
|
||||
multi_json (~> 1.0)
|
||||
addressable (2.3.4)
|
||||
activesupport (4.0.0)
|
||||
i18n (~> 0.6, >= 0.6.4)
|
||||
minitest (~> 4.2)
|
||||
multi_json (~> 1.3)
|
||||
thread_safe (~> 0.1)
|
||||
tzinfo (~> 0.3.37)
|
||||
addressable (2.3.5)
|
||||
akami (1.2.0)
|
||||
gyoku (>= 0.4.0)
|
||||
nokogiri (>= 1.4.0)
|
||||
berkshelf (2.0.3)
|
||||
atomic (1.1.10)
|
||||
berkshelf (2.0.5)
|
||||
activesupport (>= 3.2.0)
|
||||
addressable (~> 2.3.4)
|
||||
buff-shell_out (~> 0.1)
|
||||
celluloid (>= 0.14.0)
|
||||
chozo (>= 0.6.1)
|
||||
faraday (>= 0.8.5)
|
||||
hashie (>= 2.0.2)
|
||||
minitar (~> 0.5.4)
|
||||
rbzip2 (~> 0.2.0)
|
||||
retryable (~> 1.3.3)
|
||||
ridley (~> 1.0.2)
|
||||
solve (>= 0.4.4)
|
||||
test-kitchen (>= 1.0.0.alpha7)
|
||||
ridley (~> 1.2.1)
|
||||
solve (>= 0.5.0)
|
||||
thor (~> 0.18.0)
|
||||
buff-extensions (0.5.0)
|
||||
buff-ruby_engine (0.1.0)
|
||||
buff-shell_out (0.1.0)
|
||||
buff-ruby_engine (~> 0.1.0)
|
||||
builder (3.2.2)
|
||||
celluloid (0.14.1)
|
||||
timers (>= 1.0.0)
|
||||
@ -53,7 +62,6 @@ GEM
|
||||
multi_json (>= 1.3.0)
|
||||
ci_reporter (1.8.4)
|
||||
builder (>= 2.1.2)
|
||||
coderay (1.0.9)
|
||||
diff-lcs (1.2.4)
|
||||
erubis (2.7.0)
|
||||
faraday (0.8.7)
|
||||
@ -84,17 +92,16 @@ GEM
|
||||
httpclient (2.2.0.2)
|
||||
httpi (0.9.7)
|
||||
rack
|
||||
i18n (0.6.1)
|
||||
i18n (0.6.4)
|
||||
ipaddress (0.8.0)
|
||||
json (1.6.1)
|
||||
json (1.7.7)
|
||||
little-plugger (1.1.3)
|
||||
log_switch (0.4.0)
|
||||
logging (1.6.2)
|
||||
little-plugger (>= 1.1.3)
|
||||
method_source (0.8.1)
|
||||
mime-types (1.23)
|
||||
minitar (0.5.4)
|
||||
minitest (4.7.4)
|
||||
minitest (4.7.5)
|
||||
minitest-chef-handler (1.0.1)
|
||||
chef
|
||||
ci_reporter
|
||||
@ -105,12 +112,10 @@ GEM
|
||||
mixlib-config (1.1.2)
|
||||
mixlib-log (1.6.0)
|
||||
mixlib-shellout (1.1.0)
|
||||
multi_json (1.7.4)
|
||||
multi_json (1.7.7)
|
||||
multi_xml (0.5.4)
|
||||
multipart-post (1.2.0)
|
||||
net-http-persistent (2.8)
|
||||
net-scp (1.1.1)
|
||||
net-ssh (>= 2.6.5)
|
||||
net-ssh (2.6.7)
|
||||
net-ssh-gateway (1.2.0)
|
||||
net-ssh (>= 2.6.5)
|
||||
@ -118,7 +123,7 @@ GEM
|
||||
net-ssh (>= 2.1.4)
|
||||
net-ssh-gateway (>= 0.99.0)
|
||||
nio4r (0.4.6)
|
||||
nokogiri (1.5.9)
|
||||
nokogiri (1.5.10)
|
||||
nori (1.1.5)
|
||||
ohai (6.16.0)
|
||||
ipaddress
|
||||
@ -129,28 +134,28 @@ GEM
|
||||
systemu
|
||||
yajl-ruby
|
||||
polyglot (0.3.3)
|
||||
pry (0.9.12.2)
|
||||
coderay (~> 1.0.5)
|
||||
method_source (~> 0.8)
|
||||
slop (~> 3.4)
|
||||
rack (1.5.2)
|
||||
rak (1.4)
|
||||
rbzip2 (0.2.0)
|
||||
rest-client (1.6.7)
|
||||
mime-types (>= 1.16)
|
||||
retryable (1.3.3)
|
||||
ridley (1.0.2)
|
||||
ridley (1.2.3)
|
||||
addressable
|
||||
buff-extensions (~> 0.3)
|
||||
buff-shell_out (~> 0.1)
|
||||
celluloid (~> 0.14.0)
|
||||
celluloid-io (~> 0.14.0)
|
||||
chozo (>= 0.6.0)
|
||||
erubis
|
||||
faraday (>= 0.8.4)
|
||||
hashie (>= 2.0.2)
|
||||
json (>= 1.7.7)
|
||||
mixlib-authentication (>= 1.3.0)
|
||||
net-http-persistent (>= 2.8)
|
||||
net-ssh
|
||||
retryable
|
||||
solve (>= 0.4.4)
|
||||
varia_model (~> 0.1)
|
||||
winrm (~> 1.1.0)
|
||||
rspec (2.13.0)
|
||||
rspec-core (~> 2.13.0)
|
||||
@ -161,7 +166,6 @@ GEM
|
||||
diff-lcs (>= 1.1.3, < 2.0)
|
||||
rspec-mocks (2.13.1)
|
||||
rubyntlm (0.1.1)
|
||||
safe_yaml (0.9.3)
|
||||
savon (0.9.5)
|
||||
akami (~> 1.0)
|
||||
builder (>= 2.1.2)
|
||||
@ -170,8 +174,7 @@ GEM
|
||||
nokogiri (>= 1.4.0)
|
||||
nori (~> 1.0)
|
||||
wasabi (~> 1.0)
|
||||
slop (3.4.5)
|
||||
solve (0.5.0)
|
||||
solve (0.6.0)
|
||||
strainer (3.0.3)
|
||||
berkshelf (~> 2.0)
|
||||
systemu (2.5.2)
|
||||
@ -181,22 +184,20 @@ GEM
|
||||
text-table (>= 1.2.2)
|
||||
term-ansicolor (1.2.2)
|
||||
tins (~> 0.8)
|
||||
test-kitchen (1.0.0.alpha.7)
|
||||
celluloid
|
||||
mixlib-shellout
|
||||
net-scp
|
||||
net-ssh
|
||||
pry
|
||||
safe_yaml
|
||||
thor
|
||||
text-table (1.2.3)
|
||||
thor (0.18.1)
|
||||
thread_safe (0.1.0)
|
||||
atomic
|
||||
timers (1.1.0)
|
||||
tins (0.8.2)
|
||||
treetop (1.4.12)
|
||||
treetop (1.4.14)
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.37)
|
||||
uuidtools (2.1.4)
|
||||
varia_model (0.1.0)
|
||||
buff-extensions (~> 0.1)
|
||||
hashie (>= 2.0.2)
|
||||
wasabi (1.0.0)
|
||||
nokogiri (>= 1.4.0)
|
||||
winrm (1.1.2)
|
||||
|
30
README.md
30
README.md
@ -14,8 +14,12 @@ Chef 11 with Ruby 1.9.x required.
|
||||
|
||||
The following cookbooks are dependencies:
|
||||
|
||||
* rabbitmq
|
||||
* openstack-common
|
||||
* rabbitmq
|
||||
|
||||
# Usage #
|
||||
|
||||
The usage of this cookbook is optional, you may choose to set up your own messaging service without using this cookbook. If you choose to do so, you will need to provide all of the attributes listed under the [Attributes](#attributes).
|
||||
|
||||
# Resources/Providers #
|
||||
|
||||
@ -37,13 +41,23 @@ None
|
||||
|
||||
# Attributes #
|
||||
|
||||
* `openstack['messaging']['server_role']` - the role name to search for the messaging service
|
||||
* `openstack['messaging']['service']` - the messaging service to use; currently supports RabbitMQ
|
||||
* `openstack["mq"]["server_role"]` - which role should other nodes search on to find the messaging service, defaults to 'os-ops-messaging'
|
||||
* `openstack["mq"]["service_type"]` - which service to use, defaults to 'rabbitmq'
|
||||
* `openstack["mq"]["bind_interface"]` - bind to interfaces IPv4 address
|
||||
* `openstack["mq"]["port"]` - which service port to use
|
||||
|
||||
* `openstack['messaging']['rabbitmq_options']['port']` - the port to use for RabbitMQ; default 5672
|
||||
* `openstack['messaging']['rabbitmq_options']['address']` - the address for RabbitMQ to listen on; default 0.0.0.0
|
||||
* `openstack['messaging']['rabbitmq_options']['user']` - the RabbitMQ user to use for OpenStack; default 'guest'
|
||||
* `openstack['messaging']['rabbitmq_options']['vhost']` - the RabbitMQ vhost to use for OpenStack; default '/'
|
||||
Testing
|
||||
=====
|
||||
|
||||
This cookbook uses [bundler](http://gembundler.com/), [berkshelf](http://berkshelf.com/), and [strainer](https://github.com/customink/strainer) to isolate dependencies and run tests.
|
||||
|
||||
Tests are defined in Strainerfile.
|
||||
|
||||
To run tests:
|
||||
|
||||
$ bundle install # install gem dependencies
|
||||
$ bundle exec berks install # install cookbook dependencies
|
||||
$ bundle exec strainer test # run tests
|
||||
|
||||
License and Author
|
||||
==================
|
||||
@ -54,9 +68,9 @@ License and Author
|
||||
| **Author** | Matt Ray (<matt@opscode.com>) |
|
||||
| **Author** | Craig Tracey (<craigtracey@gmail.com>) |
|
||||
| | |
|
||||
| **Copyright** | Copyright (c) 2012, John Dewey |
|
||||
| **Copyright** | Copyright (c) 2013, Opscode, Inc. |
|
||||
| **Copyright** | Copyright (c) 2013, Craig Tracey |
|
||||
| **Copyright** | Copyright (c) 2013, AT&T Services, Inc. |
|
||||
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -1,11 +1,24 @@
|
||||
default['openstack']['messaging']['server_role'] = 'os-ops-messaging'
|
||||
default['openstack']['messaging']['service'] = 'rabbitmq'
|
||||
#
|
||||
# Cookbook Name:: openstack-ops-messaging
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2013, AT&T Services, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
case default['openstack']['messaging']['service']
|
||||
when "rabbitmq"
|
||||
default['openstack']['messaging']['rabbitmq_options'] = {}
|
||||
default['openstack']['messaging']['rabbitmq_options']['port'] = 5672
|
||||
default['openstack']['messaging']['rabbitmq_options']['address'] = "0.0.0.0"
|
||||
default['openstack']['messaging']['rabbitmq_options']['user'] = "guest"
|
||||
default['openstack']['messaging']['rabbitmq_options']['vhost'] = "/"
|
||||
end
|
||||
default["openstack"]["mq"]["bind_interface"] = "lo"
|
||||
# TODO(retr0h): Delete when these attributes are merged into openstack-common
|
||||
default["openstack"]["mq"]["server_role"] = "os-ops-messaging"
|
||||
default["openstack"]["mq"]["service_type"] = "rabbitmq"
|
||||
default["openstack"]["mq"]["port"] = "5672"
|
||||
|
@ -8,9 +8,9 @@ version "7.0.0"
|
||||
recipe "server", "Installs and configures server packages for messaging queue used by the deployment."
|
||||
recipe "rabbitmq-server", "Installs and configures RabbitMQ and is called via the server recipe"
|
||||
|
||||
%w{ ubuntu }.each do |os|
|
||||
%w{ fedora ubuntu redhat centos }.each do |os|
|
||||
supports os
|
||||
end
|
||||
|
||||
depends "openstack-common", "~> 0.3.0"
|
||||
depends "rabbitmq", ">= 2.1.0"
|
||||
depends "openstack-common", "~> 0.2.4"
|
||||
|
@ -2,11 +2,9 @@
|
||||
# Cookbook Name:: openstack-ops-messaging
|
||||
# Recipe:: rabbitmq-server
|
||||
#
|
||||
# Copyright 2012, John Dewey
|
||||
# Copyright 2013, Opscode, Inc.
|
||||
# Copyright 2013, AT&T Services, Inc.
|
||||
# Copyright 2013, Craig Tracey <craigtracey@gmail.com>
|
||||
#
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
@ -24,45 +22,78 @@ class ::Chef::Recipe
|
||||
include ::Openstack
|
||||
end
|
||||
|
||||
node.set["rabbitmq"]["port"] = node["openstack"]["messaging"]["rabbitmq_options"]["port"]
|
||||
node.set["rabbitmq"]["address"] = node["openstack"]["messaging"]["rabbitmq_options"]["address"]
|
||||
node.set["rabbitmq"]["use_distro_version"] = true
|
||||
rabbit_server_role = node["openstack"]["mq"]["server_role"]
|
||||
user = node["openstack"]["mq"]["user"]
|
||||
pass = user_password user
|
||||
cookie = service_password "rabbit_cookie"
|
||||
vhost = node["openstack"]["mq"]["vhost"]
|
||||
bind_interface = node["openstack"]["mq"]["bind_interface"]
|
||||
listen_address = address_for node["openstack"]["mq"]["bind_interface"]
|
||||
|
||||
include_recipe "rabbitmq::default"
|
||||
# Used by OpenStack#rabbit_servers/#rabbit_server
|
||||
node.set["openstack"]["mq"]["listen"] = listen_address
|
||||
|
||||
node.override["rabbitmq"]["port"] = node["openstack"]["mq"]["port"]
|
||||
node.override["rabbitmq"]["address"] = listen_address
|
||||
node.override["rabbitmq"]["default_user"] = user
|
||||
node.override["rabbitmq"]["default_pass"] = pass
|
||||
node.override["rabbitmq"]["erlang_cookie"] = cookie
|
||||
node.override["rabbitmq"]["use_distro_version"] = true
|
||||
node.override["rabbitmq"]["cluster"] = true
|
||||
qs = "roles:#{rabbit_server_role} AND environment:#{node.chef_environment}"
|
||||
node.override["rabbitmq"]["cluster_disk_nodes"] = search(:node, qs).map do |n|
|
||||
"#{user}@#{n['hostname']}"
|
||||
end
|
||||
|
||||
include_recipe "rabbitmq"
|
||||
include_recipe "rabbitmq::mgmt_console"
|
||||
|
||||
rabbit_password = user_password "rabbit"
|
||||
rabbit_user = node["openstack"]["messaging"]["rabbitmq_options"]["user"]
|
||||
rabbit_vhost = node["openstack"]["messaging"]["rabbitmq_options"]["vhost"]
|
||||
|
||||
# remove the guest user if we dont need it
|
||||
rabbitmq_user "remove rabbit guest user" do
|
||||
user 'guest'
|
||||
user "guest"
|
||||
action :delete
|
||||
not_if { rabbit_user.eql?('guest') }
|
||||
|
||||
not_if { user == "guest" }
|
||||
end
|
||||
|
||||
rabbitmq_user "add openstack rabbit user" do
|
||||
user rabbit_user
|
||||
password rabbit_password
|
||||
user user
|
||||
password pass
|
||||
|
||||
action :add
|
||||
end
|
||||
|
||||
rabbitmq_vhost "add openstack rabbit vhost" do
|
||||
vhost rabbit_vhost
|
||||
vhost vhost
|
||||
|
||||
action :add
|
||||
end
|
||||
|
||||
rabbitmq_user "set openstack user permissions" do
|
||||
user rabbit_user
|
||||
vhost rabbit_vhost
|
||||
user user
|
||||
vhost vhost
|
||||
permissions '.* .* .*'
|
||||
action :set_permissions
|
||||
end
|
||||
|
||||
# Necessary for graphing.
|
||||
rabbitmq_user "set rabbit administrator tag" do
|
||||
user rabbit_user
|
||||
user user
|
||||
tag "administrator"
|
||||
|
||||
action :set_tags
|
||||
end
|
||||
|
||||
# Remove the mnesia database. This is necessary so the nodes
|
||||
# in the cluster will be able to recognize one another.
|
||||
# TODO(retr0h): This should be handled upstream.
|
||||
execute "Reset mnesia" do
|
||||
cwd "/var/lib/rabbitmq"
|
||||
command <<-EOH.gsub(/^\s+/, "")
|
||||
service rabbitmq-server stop;
|
||||
rm -rf mnesia/;
|
||||
touch .reset_mnesia_database;
|
||||
service rabbitmq-server start
|
||||
EOH
|
||||
|
||||
not_if { ::File.exists? "/var/lib/rabbitmq/.reset_mnesia_database" }
|
||||
end
|
||||
|
@ -4,12 +4,13 @@
|
||||
#
|
||||
# Copyright 2013, Opscode, Inc.
|
||||
# Copyright 2013, Craig Tracey <craigtracey@gmail.com>
|
||||
# Copyright 2013, AT&T Services, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@ -18,4 +19,4 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe "openstack-ops-messaging::#{node['openstack']['messaging']['service']}-server"
|
||||
include_recipe "openstack-ops-messaging::#{node["openstack"]["mq"]["service_type"]}-server"
|
||||
|
@ -1,119 +1,160 @@
|
||||
require_relative 'spec_helper'
|
||||
require_relative "spec_helper"
|
||||
|
||||
describe 'openstack-ops-messaging::rabbitmq-server' do
|
||||
describe 'ubuntu' do
|
||||
describe "openstack-ops-messaging::rabbitmq-server" do
|
||||
before { ops_messaging_stubs }
|
||||
describe "ubuntu" do
|
||||
before do
|
||||
messaging_stubs
|
||||
@chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |node|
|
||||
node.set['lsb'] = {'codename' => 'precise'}
|
||||
node.set['openstack']= {'messaging' => {
|
||||
'service' => 'rabbitmq',
|
||||
'rabbitmq_options' => {
|
||||
'user' => 'openstack_rabbit_user',
|
||||
'vhost' => '/openstack_rabbit_vhost'
|
||||
}
|
||||
}
|
||||
}
|
||||
node.set['rabbitmq'] = {
|
||||
'erlang_cookie_path' => '/path/to/nowhere'
|
||||
@chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |n|
|
||||
n.set["openstack"]["mq"] = {
|
||||
"user" => "rabbit-user",
|
||||
"vhost" => "/test-vhost"
|
||||
}
|
||||
end
|
||||
|
||||
@rabbitmq_user_mock = double "rabbitmq_user"
|
||||
@rabbitmq_vhost_mock = double "rabbitmq_vhost"
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
end
|
||||
|
||||
it "rabbitmq-server basic test" do
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
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
|
||||
|
||||
expect(@chef_run).to include_recipe "openstack-ops-messaging::rabbitmq-server"
|
||||
expect(@chef_run).to include_recipe "rabbitmq::default"
|
||||
it "includes rabbit recipes" do
|
||||
expect(@chef_run).to include_recipe "rabbitmq"
|
||||
expect(@chef_run).to include_recipe "rabbitmq::mgmt_console"
|
||||
end
|
||||
|
||||
it "removes the rabbit guest user" do
|
||||
::Chef::Recipe.any_instance.stub(:rabbitmq_user)
|
||||
::Chef::Recipe.any_instance.should_receive(:rabbitmq_user).
|
||||
with("remove rabbit guest user") do |&arg|
|
||||
@rabbitmq_user_mock.should_receive(:user).
|
||||
with "guest"
|
||||
@rabbitmq_user_mock.should_receive(:action).
|
||||
with :delete
|
||||
@rabbitmq_user_mock.should_receive(:not_if)
|
||||
describe "lwrps" do
|
||||
it "deletes guest user" do
|
||||
resource = @chef_run.find_resource(
|
||||
"rabbitmq_user",
|
||||
"remove rabbit guest user"
|
||||
).to_hash
|
||||
|
||||
@rabbitmq_user_mock.instance_eval &arg
|
||||
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"
|
||||
}
|
||||
end
|
||||
chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
resource = chef_run.find_resource(
|
||||
"rabbitmq_user",
|
||||
"remove rabbit guest user"
|
||||
)
|
||||
|
||||
expect(resource).to be_nil
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
it "adds vhost" do
|
||||
resource = @chef_run.find_resource(
|
||||
"rabbitmq_vhost",
|
||||
"add openstack rabbit vhost"
|
||||
).to_hash
|
||||
|
||||
expect(resource).to include(
|
||||
:vhost => "/test-vhost",
|
||||
:action => [:add]
|
||||
)
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
it "adds the openstack rabbit user" do
|
||||
::Chef::Recipe.any_instance.stub(:rabbitmq_user)
|
||||
::Chef::Recipe.any_instance.should_receive(:rabbitmq_user).
|
||||
with("add openstack rabbit user") do |&arg|
|
||||
@rabbitmq_user_mock.should_receive(:user).
|
||||
with "openstack_rabbit_user"
|
||||
@rabbitmq_user_mock.should_receive(:password).
|
||||
with "rabbitpassword"
|
||||
@rabbitmq_user_mock.should_receive(:action).
|
||||
with :add
|
||||
|
||||
@rabbitmq_user_mock.instance_eval &arg
|
||||
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"
|
||||
}
|
||||
end
|
||||
@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
|
||||
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
it "resets database" do
|
||||
::File.should_receive(:exists?).
|
||||
with(@file).
|
||||
and_return(false)
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
|
||||
expect(@chef_run).to execute_command(@cmd).with(
|
||||
:cwd => "/var/lib/rabbitmq"
|
||||
)
|
||||
end
|
||||
|
||||
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"
|
||||
|
||||
expect(@chef_run).not_to execute_command(@cmd)
|
||||
end
|
||||
end
|
||||
|
||||
it "adds the openstack rabbit vhost" do
|
||||
::Chef::Recipe.any_instance.stub(:rabbitmq_vhost)
|
||||
::Chef::Recipe.any_instance.should_receive(:rabbitmq_vhost).
|
||||
with("add openstack rabbit vhost") do |&arg|
|
||||
@rabbitmq_vhost_mock.should_receive(:vhost).
|
||||
with "/openstack_rabbit_vhost"
|
||||
@rabbitmq_vhost_mock.should_receive(:action).
|
||||
with :add
|
||||
|
||||
@rabbitmq_vhost_mock.instance_eval &arg
|
||||
end
|
||||
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
end
|
||||
|
||||
it "set openstack user permissions" do
|
||||
::Chef::Recipe.any_instance.stub(:rabbitmq_user)
|
||||
::Chef::Recipe.any_instance.should_receive(:rabbitmq_user).
|
||||
with("set openstack user permissions") do |&arg|
|
||||
@rabbitmq_user_mock.should_receive(:user).
|
||||
with "openstack_rabbit_user"
|
||||
@rabbitmq_user_mock.should_receive(:vhost).
|
||||
with "/openstack_rabbit_vhost"
|
||||
@rabbitmq_user_mock.should_receive(:permissions).
|
||||
with ".* .* .*"
|
||||
@rabbitmq_user_mock.should_receive(:action).
|
||||
with :set_permissions
|
||||
|
||||
@rabbitmq_user_mock.instance_eval &arg
|
||||
end
|
||||
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
end
|
||||
|
||||
it "set rabbit administrator tag" do
|
||||
::Chef::Recipe.any_instance.stub(:rabbitmq_user)
|
||||
::Chef::Recipe.any_instance.should_receive(:rabbitmq_user).
|
||||
with("set rabbit administrator tag") do |&arg|
|
||||
@rabbitmq_user_mock.should_receive(:user).
|
||||
with "openstack_rabbit_user"
|
||||
@rabbitmq_user_mock.should_receive(:tag).
|
||||
with "administrator"
|
||||
@rabbitmq_user_mock.should_receive(:action).
|
||||
with :set_tags
|
||||
|
||||
@rabbitmq_user_mock.instance_eval &arg
|
||||
end
|
||||
|
||||
@chef_run.converge "openstack-ops-messaging::rabbitmq-server"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,27 +1,19 @@
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-ops-messaging::server' do
|
||||
describe 'ubuntu' do
|
||||
describe "openstack-ops-messaging::server" do
|
||||
before { ops_messaging_stubs }
|
||||
describe "ubuntu" do
|
||||
|
||||
before do
|
||||
messaging_stubs
|
||||
end
|
||||
|
||||
it "select 'rabbitmq-server' recipe" do
|
||||
chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |node|
|
||||
node.set['lsb'] = {'codename' => 'precise'}
|
||||
node.set['openstack'] = {
|
||||
'messaging' => {
|
||||
'service' => 'rabbitmq'
|
||||
}
|
||||
}
|
||||
node.set['rabbitmq'] = {
|
||||
'erlang_cookie_path' => '/path/to/nowhere'
|
||||
it "uses proper messaging server recipe" do
|
||||
chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |n|
|
||||
n.set["openstack"]["mq"] = {
|
||||
"user" => "rabbit-user",
|
||||
"vhost" => "/test-vhost"
|
||||
}
|
||||
end
|
||||
chef_run.converge 'openstack-ops-messaging::server'
|
||||
chef_run.converge "openstack-ops-messaging::server"
|
||||
|
||||
expect(chef_run).to include_recipe "openstack-ops-messaging::rabbitmq-server"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
@ -1,12 +1,30 @@
|
||||
require "chefspec"
|
||||
|
||||
::LOG_LEVEL = :fatal
|
||||
::REDHAT_OPTS = {
|
||||
:platform => "redhat",
|
||||
:version => "6.3",
|
||||
:log_level => ::LOG_LEVEL
|
||||
}
|
||||
::UBUNTU_OPTS = {
|
||||
:platform => "ubuntu",
|
||||
:version => "12.04",
|
||||
:log_level => ::LOG_LEVEL
|
||||
}
|
||||
|
||||
def messaging_stubs
|
||||
::Chef::Recipe.any_instance.stub(:user_password).and_return("rabbitpassword")
|
||||
def ops_messaging_stubs
|
||||
::Chef::Recipe.any_instance.stub(:address_for).
|
||||
with("lo").
|
||||
and_return "127.0.0.1"
|
||||
::Chef::Recipe.any_instance.stub(:search).
|
||||
with(:node, "roles:os-ops-messaging AND environment:_default").
|
||||
and_return [
|
||||
{ 'hostname' => 'host1' },
|
||||
{ 'hostname' => 'host2' }
|
||||
]
|
||||
::Chef::Recipe.any_instance.stub(:user_password).
|
||||
and_return "rabbit-pass"
|
||||
::Chef::Recipe.any_instance.stub(:service_password).
|
||||
with("rabbit_cookie").
|
||||
and_return "erlang-cookie"
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user