Sync puppetlabs rabbitmq module

commit 4832bd61b5b1bfea7c9cc985508e65cd10081652
Source: https://github.com/puppetlabs/puppetlabs-rabbitmq.git

Related blueprint merge-openstack-puppet-modules

Fuel-CI: disable
Change-Id: I924a2a4489dc329fefbee859a4b4bde0b79e86d1
Signed-off-by: Bogdan Dobrelya <bdobrelia@mirantis.com>
This commit is contained in:
Bogdan Dobrelya 2014-10-08 17:38:05 +02:00
parent 129d4644b6
commit 57d51bbae2
67 changed files with 3188 additions and 1257 deletions

View File

@ -2,5 +2,8 @@ fixtures:
repositories:
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git"
"staging": "git://github.com/nanliu/puppet-staging.git"
erlang:
repo: "https://github.com/garethr/garethr-erlang.git"
symlinks:
"rabbitmq": "#{source_dir}"

View File

@ -1,5 +0,0 @@
source :rubygems
puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.1.0'

View File

@ -1,6 +1,8 @@
*.swp
pkg/
.DS_Store
coverage/
metadata.json
spec/fixtures/modules/*
.pkg
Gemfile.lock
vendor
spec/fixtures
.rspec_system
.bundle
.vagrant
.*sw*

View File

@ -0,0 +1,35 @@
---
default_set: 'centos-64-x64'
sets:
'centos-59-x64':
nodes:
"main.foo.vm":
prefab: 'centos-59-x64'
'centos-64-x64':
nodes:
"main.foo.vm":
prefab: 'centos-64-x64'
'fedora-18-x64':
nodes:
"main.foo.vm":
prefab: 'fedora-18-x64'
'debian-607-x64':
nodes:
"main.foo.vm":
prefab: 'debian-607-x64'
'debian-70rc1-x64':
nodes:
"main.foo.vm":
prefab: 'debian-70rc1-x64'
'ubuntu-server-10044-x64':
nodes:
"main.foo.vm":
prefab: 'ubuntu-server-10044-x64'
'ubuntu-server-12042-x64':
nodes:
"main.foo.vm":
prefab: 'ubuntu-server-12042-x64'
'sles-11sp1-x64':
nodes:
"main.foo.vm":
prefab: 'sles-11sp1-x64'

View File

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>rabbitmq</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.cloudsmith.geppetto.pp.dsl.ui.modulefileBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.cloudsmith.geppetto.pp.dsl.ui.puppetNature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>

View File

@ -1,16 +1,17 @@
---
language: ruby
rvm:
- 1.8.7
before_script:
after_script:
script: "rake spec"
branches:
only:
- master
env:
- PUPPET_VERSION=2.7.13
- PUPPET_VERSION=2.7.6
- PUPPET_VERSION=2.6.9
bundler_args: --without development
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'"
matrix:
fast_finish: true
include:
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
- rvm: 1.8.7
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.0"
notifications:
email: false
gemfile: .gemfile

View File

@ -1,3 +1,110 @@
2014-08-20 - Version 4.1.0
Summary:
This release adds several new features, fixes bugs, and improves tests and
documentation.
Features:
- Autorequire the rabbitmq-server service in the rabbitmq_vhost type
- Add credentials to rabbitmqadmin URL
- Added $ssl_only parameter to rabbitmq, rabbitmq::params, and
rabbitmq::config
- Added property tags to rabbitmq_user provider
Bugfixes:
- Fix erroneous commas in rabbitmq::config
- Use correct ensure value for the rabbitmq_stomp rabbitmq_plugin
- Set HOME env variable to nil when leveraging rabbitmq to remove type error
from Python script
- Fix location for rabbitmq-plugins for RHEL
- Remove validation for package_source to allow it to be set to false
- Allow LDAP auth configuration without configuring stomp
- Added missing $ssl_verify and $ssl_fail_if_no_peer_cert to rabbitmq::config
2014-05-16 - Version 4.0.0
Summary:
This release includes many new features and bug fixes. With the exception of
erlang management this should be backwards compatible with 3.1.0.
Backwards-incompatible Changes:
- erlang_manage was removed. You will need to manage erlang separately. See
the README for more information on how to configure this.
Features:
- Improved SSL support
- Add LDAP support
- Add ability to manage RabbitMQ repositories
- Add ability to manage Erlang kernel configuration options
- Improved handling of user tags
- Use nanliu-staging module instead of hardcoded 'curl'
- Switch to yum or zypper provider instead of rpm
- Add ability to manage STOMP plugin installation.
- Allow empty permission fields
- Convert existing system tests to beaker acceptance tests.
Bugfixes:
- exchanges no longer recreated on each puppet run if non-default vhost is used
- Allow port to be UNSET
- Re-added rabbitmq::server class
- Deprecated previously unused manage_service variable in favor of
service_manage
- Use correct key for rabbitmq apt::source
- config_mirrored_queues variable removed
- It previously did nothing, will now at least throw a warning if you try to
use it
- Remove unnecessary dependency on Class['rabbitmq::repo::rhel'] in
rabbitmq::install
2013-09-14 - Version 3.1.0
Summary:
This release focuses on a few small (but critical) bugfixes as well as extends
the amount of custom RabbitMQ configuration you can do with the module.
Features:
- You can now change RabbitMQ 'Config Variables' via the parameter `config_variables`.
- You can now change RabbitMQ 'Environment Variables' via the parameter `environment_variables`.
- ArchLinux support added.
Fixes:
- Make use of the user/password parameters in rabbitmq_exchange{}
- Correct the read/write parameter order on set_permissions/list_permissions as
they were reversed.
- Make the module pull down 3.1.5 by default.
* 2013-07-18 3.0.0
Summary:
This release heavily refactors the RabbitMQ and changes functionality in
several key ways. Please pay attention to the new README.md file for
details of how to interact with the class now. Puppet 3 and RHEL are
now fully supported. The default version of RabbitMQ has changed to
a 3.x release.
Bugfixes:
- Improve travis testing options.
- Stop reimporting the GPG key on every run on RHEL and Debian.
- Fix documentation to make it clear you don't have to set provider => each time.
- Reference the standard rabbitmq port in the documentation instead of a custom port.
- Fixes to the README formatting.
Features:
- Refactor the module to fix RHEL support. All interaction with the module
is now done through the main rabbitmq class.
- Add support for mirrored queues (Only on Debian family distributions currently)
- Add rabbitmq_exchange provider (using rabbitmqadmin)
- Add new `rabbitmq` class parameters:
- `manage_service`: Boolean to choose if Puppet should manage the service. (For pacemaker/HA setups)
- Add SuSE support.
Incompatible Changes:
- Rabbitmq::server has been removed and is now rabbitmq::config. You should
not use this class directly, only via the main rabbitmq class.
* 2013-04-11 2.1.0
- remove puppetversion from rabbitmq.config template
- add cluster support

View File

@ -0,0 +1,26 @@
source 'https://rubygems.org'
group :development, :test do
gem 'rake', '10.1.1', :require => false
gem 'rspec-puppet', '>=1.0.0', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'serverspec', :require => false
gem 'beaker', :require => false
gem 'beaker-rspec', :require => false
gem 'pry', :require => false
end
if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
else
gem 'facter', :require => false
end
if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end
# vim:ft=ruby

View File

@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Copyright 2013 Puppet Labs
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -1,12 +0,0 @@
name 'puppetlabs-rabbitmq'
version '2.1.0'
source 'git://github.com/puppetlabs/puppetlabs-rabbitmq.git'
author 'puppetlabs'
license 'Apache'
summary 'RabbitMQ Puppet Module'
description 'This module manages RabbitMQ. Tested on Debian/Ubuntu'
project_page 'http://github.com/puppetlabs/puppetlabs-rabbitmq'
## Add dependencies, if any:
dependency 'puppetlabs/stdlib', '>= 2.0.0'
dependency 'puppetlabs/apt', '>= 0.0.3'

View File

@ -1,94 +1,493 @@
# RabbitMQ Puppet Module
This module manages the RabbitMQ Middleware service.
#rabbitmq
####Table of Contents
1. [Overview](#overview)
2. [Module Description - What the module does and why it is useful](#module-description)
3. [Setup - The basics of getting started with rabbitmq](#setup)
* [What rabbitmq affects](#what-rabbitmq-affects)
* [Setup requirements](#setup-requirements)
* [Beginning with rabbitmq](#beginning-with-rabbitmq)
4. [Usage - Configuration options and additional functionality](#usage)
5. [Reference - An under-the-hood peek at what the module is doing and how](#reference)
5. [Limitations - OS compatibility, etc.](#limitations)
* [RedHat module dependencies](#redhat-module-dependecies)
6. [Development - Guide for contributing to the module](#development)
##Overview
This module manages RabbitMQ (www.rabbitmq.com)
##Module Description
The rabbitmq module sets up rabbitmq and has a number of providers to manage
everything from vhosts to exchanges after setup.
This module has been tested against 2.7.1 and is known to not support
all features against earlier versions.
##Setup
###What rabbitmq affects
* rabbitmq repository files.
* rabbitmq package.
* rabbitmq configuration file.
* rabbitmq service.
###Beginning with rabbitmq
```puppet
include '::rabbitmq'
```
##Usage
All options and configuration can be done through interacting with the parameters
on the main rabbitmq class. These are documented below.
##rabbitmq class
To begin with the rabbitmq class controls the installation of rabbitmq. In here
you can control many parameters relating to the package and service, such as
disabling puppet support of the service:
```puppet
class { '::rabbitmq':
service_manage => false,
port => '5672',
delete_guest_user => true,
}
```
Or such as offline installation from intranet or local mirrors:
```puppet
class { '::rabbitmq':
key_content => template('openstack/rabbit.pub.key'),
package_gpg_key => '/tmp/rabbit.pub.key',
}
```
And this one will use external package key source for any (apt/rpm) package provider:
```puppet
class { '::rabbitmq':
package_gpg_key => 'http://www.some_site.some_domain/some_key.pub.key',
}
```
### Environment Variables
To use RabbitMQ Environment Variables, use the parameters `environment_variables` e.g.:
```puppet
class { 'rabbitmq':
port => '5672',
environment_variables => {
'RABBITMQ_NODENAME' => 'node01',
'RABBITMQ_SERVICENAME' => 'RabbitMQ'
}
}
```
### Variables Configurable in rabbitmq.config
To change RabbitMQ Config Variables in rabbitmq.config, use the parameters `config_variables` e.g.:
```puppet
class { 'rabbitmq':
port => '5672',
config_variables => {
'hipe_compile' => true,
'frame_max' => 131072,
'log_levels' => "[{connection, info}]"
}
}
```
To change Erlang Kernel Config Variables in rabbitmq.config, use the parameters
`config_kernel_variables` e.g.:
```puppet
class { 'rabbitmq':
port => '5672',
config_kernel_variables => {
'inet_dist_listen_min' => 9100,
'inet_dist_listen_max' => 9105,
}
}
```
### Clustering
To use RabbitMQ clustering facilities, use the rabbitmq parameters
`config_cluster`, `cluster_nodes`, and `cluster_node_type`, e.g.:
```puppet
class { 'rabbitmq':
config_cluster => true,
cluster_nodes => ['rabbit1', 'rabbit2'],
cluster_node_type => 'ram',
}
```
##Reference
##Classes
* rabbitmq: Main class for installation and service management.
* rabbitmq::config: Main class for rabbitmq configuration/management.
* rabbitmq::install: Handles package installation.
* rabbitmq::params: Different configuration data for different systems.
* rabbitmq::service: Handles the rabbitmq service.
* rabbitmq::repo::apt: Handles apt repo for Debian systems.
* rabbitmq::repo::rhel: Handles yum repo for Redhat systems.
###Parameters
####`admin_enable`
Boolean, if enabled sets up the management interface/plugin for RabbitMQ.
####`cluster_disk_nodes`
DEPRECATED AND REPLACED BY CLUSTER_NODES.
####`cluster_node_type`
Choose between disk and ram nodes.
####`cluster_nodes`
An array of nodes for clustering.
####`cluster_partition_handling`
Value to set for `cluster_partition_handling` RabbitMQ configuration variable.
####`config`
The file to use as the rabbitmq.config template.
####`config_cluster`
Boolean to enable or disable clustering support.
####`config_kernel_variables`
Hash of Erlang kernel configuration variables to set (see [Variables Configurable in rabbitmq.config](#variables-configurable-in-rabbitmq.config)).
####`config_mirrored_queues`
DEPRECATED
Configuring queue mirroring should be done by setting the according policy for
the queue. You can read more about it
[here](http://www.rabbitmq.com/ha.html#genesis)
####`config_path`
The path to write the RabbitMQ configuration file to.
####`config_stomp`
Boolean to enable or disable stomp.
####`config_variables`
To set config variables in rabbitmq.config
####`default_user`
Username to set for the `default_user` in rabbitmq.config.
####`default_pass`
Password to set for the `default_user` in rabbitmq.config.
####`delete_guest_user`
Boolean to decide if we should delete the default guest user.
####`env_config`
The template file to use for rabbitmq_env.config.
####`env_config_path`
The path to write the rabbitmq_env.config file to.
####`environment_variables`
RabbitMQ Environment Variables in rabbitmq_env.config
####`erlang_cookie`
The erlang cookie to use for clustering - must be the same between all nodes.
###`key_content`
Uses content method for Debian OS family. Should be a template for apt::source
class. Overrides `package_gpg_key` behavior, if enabled. Undefined by default.
####`ldap_auth`
Boolean, set to true to enable LDAP auth.
####`ldap_server`
LDAP server to use for auth.
####`ldap_user_dn_pattern`
User DN pattern for LDAP auth.
####`ldap_use_ssl`
Boolean, set to true to use SSL for the LDAP server.
####`ldap_port`
Numeric port for LDAP server.
####`ldap_log`
Boolean, set to true to log LDAP auth.
####`manage_repos`
Boolean, whether or not to manage package repositories.
####`management_port`
The port for the RabbitMQ management interface.
####`node_ip_address`
The value of RABBITMQ_NODE_IP_ADDRESS in rabbitmq_env.config
####`package_ensure`
Determines the ensure state of the package. Set to installed by default, but could
be changed to latest.
####`package_gpg_key`
RPM package GPG key to import. Uses source method. Should be a URL for Debian/RedHat
OS family, or a file name for RedHat OS family.
Set to http://www.rabbitmq.com/rabbitmq-signing-key-public.asc by default.
Note, that `key_content`, if specified, would override this parameter for Debian OS family.
####`package_name`
The name of the package to install.
####`package_provider`
What provider to use to install the package.
####`package_source`
Where should the package be installed from?
####`plugin_dir`
Location of RabbitMQ plugins.
####`port`
The RabbitMQ port.
####`service_ensure`
The state of the service.
####`service_manage`
Determines if the service is managed.
####`service_name`
The name of the service to manage.
####`ssl`
Configures the service for using SSL.
####`ssl_only`
Configures the service to only use SSL. No cleartext TCP listeners will be created.
Requires that ssl => true also.
####`ssl_cacert`
CA cert path to use for SSL.
####`ssl_cert`
Cert to use for SSL.
####`ssl_key`
Key to use for SSL.
####`ssl_management_port`
SSL management port.
####`ssl_stomp_port`
SSL stomp port.
####`ssl_verify`
rabbitmq.config SSL verify setting.
####`ssl_fail_if_no_peer_cert`
rabbitmq.config `fail_if_no_peer_cert` setting.
####`stomp_port`
The port to use for Stomp.
####`stomp_ensure`
Boolean to install the stomp plugin.
####`tcp_keepalive`
Boolean to enable TCP connection keepalive for RabbitMQ service.
####`version`
Sets the version to install.
####`wipe_db_on_cookie_change`
Boolean to determine if we should DESTROY AND DELETE the RabbitMQ database.
##Native Types
### rabbitmq\_user
query all current users: `$ puppet resource rabbitmq_user`
```
rabbitmq_user { 'dan':
admin => true,
password => 'bar',
}
```
Optional parameter tags will set further rabbitmq tags like monitoring, policymaker, etc.
To set the administrator tag use admin-flag.
```puppet
rabbitmq_user { 'dan':
admin => true,
password => 'bar',
tags => ['monitoring', 'tag1'],
}
```
### rabbitmq\_vhost
query all current vhosts: `$ puppet resource rabbitmq_vhost`
```puppet
rabbitmq_vhost { 'myhost':
ensure => present,
}
```
### rabbitmq\_exchange
```puppet
rabbitmq_exchange { 'myexchange@myhost':
user => 'dan',
password => 'bar',
type => 'topic',
ensure => present,
}
```
### rabbitmq\_user\_permissions
```puppet
rabbitmq_user_permissions { 'dan@myhost':
configure_permission => '.*',
read_permission => '.*',
write_permission => '.*',
}
```
### rabbitmq\_plugin
query all currently enabled plugins `$ puppet resource rabbitmq_plugin`
```puppet
rabbitmq_plugin {'rabbitmq_stomp':
ensure => present,
}
```
##Limitations
This module has been built on and tested against Puppet 2.7 and higher.
The module has been tested on:
* RedHat Enterprise Linux 5/6
* Debian 6/7
* CentOS 5/6
* Ubuntu 12.04
Testing on other platforms has been light and cannot be guaranteed.
### Module dependencies
To have a suitable erlang version installed on RedHat and Debian systems,
you have to install another puppet module from http://forge.puppetlabs.com/garethr/erlang with:
puppet module install garethr-erlang
This module handles the packages for erlang.
To use the module, add the following snippet to your site.pp or an appropriate profile class:
For RedHat systems:
include 'erlang'
class { 'erlang': epel_enable => true}
For Debian systems:
include 'erlang'
package { 'erlang-base':
ensure => 'latest',
}
### Downgrade Issues
Be advised that there were configuration file syntax and other changes made between RabbitMQ
versions 2 and 3. In order to downgrade from 3 to 2 (not that this is a terribly good idea)
you will need to manually remove all RabbitMQ configuration files (``/etc/rabbitmq``) and
the mnesia directory (usually ``/var/lib/rabbitmq/mnesia``). The latter action will delete
any and all messages stored to disk.
Failure to do this will result in RabbitMQ failing to start with a cryptic error message about
"init terminating in do_boot", containing "rabbit_upgrade,maybe_upgrade_mnesia".
##Development
Puppet Labs modules on the Puppet Forge are open projects, and community
contributions are essential for keeping them great. We cant access the
huge number of platforms and myriad of hardware, software, and deployment
configurations that Puppet is intended to serve.
We want to keep it as easy as possible to contribute changes so that our
modules work in your environment. There are a few guidelines that we need
contributors to follow so that we can have a chance of keeping on top of things.
You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing)
### Authors
* Jeff McCune <jeff@puppetlabs.com>
* Dan Bode <dan@puppetlabs.com>
* RPM/RHEL packages by Vincent Janelle <randomfrequency@gmail.com>
## Classes
This module provides its core functionality through two main classes:
### rabbitmq::repo::rhel
Installs the RPM from rabbitmq upstream, and imports their signing key
class { 'rabbitmq::repo::rhel':
$version => "2.8.4",
$relversion => "1",
}
### rabbitmq::repo::apt
Sets up an apt repo source for the vendor rabbitmq packages
class { 'rabbitmq::repo::apt':
pin => 900,
before => Class['rabbitmq::server']
}
### rabbitmq::server
Class for installing rabbitmq-server:
class { 'rabbitmq::server':
port => '5673',
delete_guest_user => true,
}
### Clustering
To use RabbitMQ clustering and H/A facilities, use the rabbitmq::server
parameters `config_cluster` and `cluster_disk_nodes`, e.g.:
class { 'rabbitmq::server':
config_cluster => true,
cluster_disk_nodes => ['rabbit1', 'rabbit2'],
}
Currently all cluster nodes are registered as disk nodes (not ram).
**NOTE:** You still need to use `x-ha-policy: all` in your client
applications for any particular queue to take advantage of H/A, this module
merely clusters RabbitMQ instances.
## Native Types
**NOTE:** Unfortunately, you must specify the provider explicitly for these types
### rabbitmq_user
query all current users: `$ puppet resource rabbitmq_user`
rabbitmq_user { 'dan':
admin => true,
password => 'bar',
provider => 'rabbitmqctl',
}
### rabbitmq_vhost
query all current vhosts: `$ puppet resource rabbitmq_vhost`
rabbitmq_vhost { 'myhost':
ensure => present,
provider => 'rabbitmqctl',
}
### rabbitmq\_user\_permissions
rabbitmq_user_permissions { 'dan@myhost':
configure_permission => '.*',
read_permission => '.*',
write_permission => '.*',
provider => 'rabbitmqctl',
}
### rabbitmq_plugin
query all currently enabled plugins `$ puppet resource rabbitmq_plugin`
rabbitmq_plugin {'rabbitmq_stomp':
ensure => present,
provider => 'rabbitmqplugins',
}
* Puppetlabs Module Team

View File

@ -1 +1,10 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
PuppetLint.configuration.fail_on_warnings
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_class_parameter_defaults')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]

View File

@ -0,0 +1,16 @@
# Fact: rabbitmq_erlang_cookie
#
# Purpose: To determine the current erlang cookie value.
#
# Resolution: Returns the cookie.
Facter.add(:rabbitmq_erlang_cookie) do
confine :osfamily => %w[Debian RedHat Suse]
setcode do
if File.exists?('/var/lib/rabbitmq/.erlang.cookie')
File.read('/var/lib/rabbitmq/.erlang.cookie')
else
nil
end
end
end

View File

@ -0,0 +1,96 @@
require 'puppet'
Puppet::Type.type(:rabbitmq_exchange).provide(:rabbitmqadmin) do
if Puppet::PUPPETVERSION.to_f < 3
commands :rabbitmqctl => 'rabbitmqctl'
commands :rabbitmqadmin => '/usr/local/bin/rabbitmqadmin'
else
has_command(:rabbitmqctl, 'rabbitmqctl') do
environment :HOME => "/tmp"
end
has_command(:rabbitmqadmin, '/usr/local/bin/rabbitmqadmin') do
environment :HOME => "/tmp"
end
end
defaultfor :feature => :posix
def should_vhost
if @should_vhost
@should_vhost
else
@should_vhost = resource[:name].split('@')[1]
end
end
def self.all_vhosts
vhosts = []
parse_command(rabbitmqctl('list_vhosts')).collect do |vhost|
vhosts.push(vhost)
end
vhosts
end
def self.all_exchanges(vhost)
exchanges = []
parse_command(rabbitmqctl('list_exchanges', '-p', vhost, 'name', 'type'))
end
def self.parse_command(cmd_output)
# first line is:
# Listing exchanges/vhosts ...
# while the last line is
# ...done.
#
cmd_output.split(/\n/)[1..-2]
end
def self.instances
resources = []
all_vhosts.each do |vhost|
all_exchanges(vhost).collect do |line|
name, type = line.split()
if type.nil?
# if name is empty, it will wrongly get the type's value.
# This way type will get the correct value
type = name
name = ''
end
exchange = {
:type => type,
:ensure => :present,
:name => "%s@%s" % [name, vhost],
}
resources << new(exchange) if exchange[:type]
end
end
resources
end
def self.prefetch(resources)
packages = instances
resources.keys.each do |name|
if provider = packages.find{ |pkg| pkg.name == name }
resources[name].provider = provider
end
end
end
def exists?
@property_hash[:ensure] == :present
end
def create
vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
name = resource[:name].split('@')[0]
rabbitmqadmin('declare', 'exchange', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}", "type=#{resource[:type]}")
@property_hash[:ensure] = :present
end
def destroy
vhost_opt = should_vhost ? "--vhost=#{should_vhost}" : ''
name = resource[:name].split('@')[0]
rabbitmqadmin('delete', 'exchange', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}")
@property_hash[:ensure] = :absent
end
end

View File

@ -1,22 +0,0 @@
Puppet::Type.type(:rabbitmq_plugin).provide(:default) do
def self.instances
[]
end
def create
default_fail
end
def destroy
default_fail
end
def exists?
default_fail
end
def default_fail
fail('This is just the default provider for rabbitmq_plugin, all it does is fail')
end
end

View File

@ -1,15 +1,27 @@
require File.join File.dirname(__FILE__), '../rabbitmq_common.rb'
Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins, :parent => Puppet::Provider::Rabbitmq_common) do
Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins) do
if Puppet::PUPPETVERSION.to_f < 3
if Facter.value(:osfamily) == 'RedHat'
commands :rabbitmqplugins => '/usr/lib/rabbitmq/bin/rabbitmq-plugins'
else
commands :rabbitmqplugins => 'rabbitmq-plugins'
end
else
if Facter.value(:osfamily) == 'RedHat'
has_command(:rabbitmqplugins, '/usr/lib/rabbitmq/bin/rabbitmq-plugins') do
environment :HOME => "/tmp"
end
else
has_command(:rabbitmqplugins, 'rabbitmq-plugins') do
environment :HOME => "/tmp"
end
end
end
defaultfor :feature => :posix
def self.instances
self.wait_for_online
self.run_with_retries {
rabbitmqplugins('list', '-E')
}.split(/\n/).map do |line|
rabbitmqplugins('list', '-E').split(/\n/).map do |line|
if line.split(/\s+/)[1] =~ /^(\S+)$/
new(:name => $1)
else
@ -27,10 +39,7 @@ Puppet::Type.type(:rabbitmq_plugin).provide(:rabbitmqplugins, :parent => Puppet:
end
def exists?
self.class.wait_for_online
out = self.class.run_with_retries {
rabbitmqplugins('list', '-E')
}.split(/\n/).detect do |line|
rabbitmqplugins('list', '-E').split(/\n/).detect do |line|
line.split(/\s+/)[1].match(/^#{resource[:name]}$/)
end
end

View File

@ -1,22 +0,0 @@
Puppet::Type.type(:rabbitmq_user).provide(:default) do
def self.instances
[]
end
def create
default_fail
end
def destroy
default_fail
end
def exists?
default_fail
end
def default_fail
fail('This is just the default provider for rabbitmq_user, all it does is fail')
end
end

View File

@ -1,18 +1,20 @@
require 'puppet'
require File.join File.dirname(__FILE__), '../rabbitmq_common.rb'
require 'set'
Puppet::Type.type(:rabbitmq_user).provide(:rabbitmqctl) do
Puppet::Type.type(:rabbitmq_user).provide(:rabbitmqctl, :parent => Puppet::Provider::Rabbitmq_common) do
if Puppet::PUPPETVERSION.to_f < 3
commands :rabbitmqctl => 'rabbitmqctl'
else
has_command(:rabbitmqctl, 'rabbitmqctl') do
environment :HOME => "/tmp"
end
end
#TODO: change optional_commands -> commands when puppet >= 3.0
optional_commands :rabbitmqctl => 'rabbitmqctl'
defaultfor :feature => :posix
def self.instances
self.wait_for_online
self.run_with_retries {
rabbitmqctl('-q', 'list_users')
}.split(/\n/).collect do |line|
if line =~ /^(\S+)(\s+\S+|)$/
rabbitmqctl('list_users').split(/\n/)[1..-2].collect do |line|
if line =~ /^(\S+)(\s+\[.*?\]|)$/
new(:name => $1)
else
raise Puppet::Error, "Cannot parse invalid user line: #{line}"
@ -25,6 +27,9 @@ Puppet::Type.type(:rabbitmq_user).provide(:rabbitmqctl, :parent => Puppet::Provi
if resource[:admin] == :true
make_user_admin()
end
if !resource[:tags].nil?
set_user_tags(resource[:tags])
end
end
def destroy
@ -32,22 +37,26 @@ Puppet::Type.type(:rabbitmq_user).provide(:rabbitmqctl, :parent => Puppet::Provi
end
def exists?
self.class.wait_for_online
out = self.class.run_with_retries {
rabbitmqctl('list_users')
}.split(/\n/)[1..-2].detect do |line|
line.match(/^#{Regexp.escape(resource[:name])}(\s+\S+|)$/)
rabbitmqctl('list_users').split(/\n/)[1..-2].detect do |line|
line.match(/^#{Regexp.escape(resource[:name])}(\s+(\[.*?\]|\S+)|)$/)
end
end
def tags
get_user_tags.entries.sort
end
def tags=(tags)
if ! tags.nil?
set_user_tags(tags)
end
end
# def password
# def password=()
def admin
match = rabbitmqctl('list_users').split(/\n/)[1..-2].collect do |line|
line.match(/^#{Regexp.escape(resource[:name])}\s+\[(administrator)?\]/)
end.compact.first
if match
(:true if match[1].to_s == 'administrator') || :false
if usertags = get_user_tags
(:true if usertags.include?('administrator')) || :false
else
raise Puppet::Error, "Could not match line '#{resource[:name]} (true|false)' from list_users (perhaps you are running on an older version of rabbitmq that does not support admin users?)"
end
@ -57,12 +66,33 @@ Puppet::Type.type(:rabbitmq_user).provide(:rabbitmqctl, :parent => Puppet::Provi
if state == :true
make_user_admin()
else
rabbitmqctl('set_user_tags', resource[:name])
usertags = get_user_tags
usertags.delete('administrator')
rabbitmqctl('set_user_tags', resource[:name], usertags.entries.sort)
end
end
def set_user_tags(tags)
is_admin = get_user_tags().member?("administrator") \
|| resource[:admin] == :true
usertags = Set.new(tags)
if is_admin
usertags.add("administrator")
end
rabbitmqctl('set_user_tags', resource[:name], usertags.entries.sort)
end
def make_user_admin
rabbitmqctl('set_user_tags', resource[:name], 'administrator')
usertags = get_user_tags
usertags.add('administrator')
rabbitmqctl('set_user_tags', resource[:name], usertags.entries.sort)
end
private
def get_user_tags
match = rabbitmqctl('list_users').split(/\n/)[1..-2].collect do |line|
line.match(/^#{Regexp.escape(resource[:name])}\s+\[(.*?)\]/)
end.compact.first
Set.new(match[1].split(/, /)) if match
end
end

View File

@ -1,18 +0,0 @@
Puppet::Type.type(:rabbitmq_user_permissions).provide(:default) do
def create
default_fail
end
def destroy
default_fail
end
def exists?
default_fail
end
def default_fail
fail('This is just the default provider for rabbitmq_user, all it does is fail')
end
end

View File

@ -1,27 +1,24 @@
require File.join File.dirname(__FILE__), '../rabbitmq_common.rb'
Puppet::Type.type(:rabbitmq_user_permissions).provide(:rabbitmqctl) do
Puppet::Type.type(:rabbitmq_user_permissions).provide(:rabbitmqctl, :parent => Puppet::Provider::Rabbitmq_common) do
if Puppet::PUPPETVERSION.to_f < 3
commands :rabbitmqctl => 'rabbitmqctl'
else
has_command(:rabbitmqctl, 'rabbitmqctl') do
environment :HOME => "/tmp"
end
end
#TODO: change optional_commands -> commands when puppet >= 3.0
optional_commands :rabbitmqctl => 'rabbitmqctl'
defaultfor :feature=> :posix
#def self.instances
#
#end
# cache users permissions
def self.users(name, vhost)
self.wait_for_online
@users = {} unless @users
unless @users[name]
@users[name] = {}
out = self.run_with_retries {
rabbitmqctl('list_user_permissions', name)
}.split(/\n/)[1..-2].each do |line|
if line =~ /^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)$/
rabbitmqctl('list_user_permissions', name).split(/\n/)[1..-2].each do |line|
if line =~ /^(\S+)\s+(\S*)\s+(\S*)\s+(\S*)$/
@users[name][$1] =
{:configure => $2, :read => $3, :write => $4}
{:configure => $2, :read => $4, :write => $3}
else
raise Puppet::Error, "cannot parse line from list_user_permissions:#{line}"
end
@ -54,7 +51,7 @@ Puppet::Type.type(:rabbitmq_user_permissions).provide(:rabbitmqctl, :parent => P
resource[:configure_permission] ||= "''"
resource[:read_permission] ||= "''"
resource[:write_permission] ||= "''"
rabbitmqctl('set_permissions', '-p', should_vhost, should_user, resource[:configure_permission], resource[:read_permission], resource[:write_permission])
rabbitmqctl('set_permissions', '-p', should_vhost, should_user, resource[:configure_permission], resource[:write_permission], resource[:read_permission])
end
def destroy
@ -99,8 +96,8 @@ Puppet::Type.type(:rabbitmq_user_permissions).provide(:rabbitmqctl, :parent => P
resource[:read_permission] ||= read_permission
resource[:write_permission] ||= write_permission
rabbitmqctl('set_permissions', '-p', should_vhost, should_user,
resource[:configure_permission], resource[:read_permission],
resource[:write_permission]
resource[:configure_permission], resource[:write_permission],
resource[:read_permission]
)
end
end

View File

@ -1,22 +0,0 @@
Puppet::Type.type(:rabbitmq_vhost).provide(:default) do
def self.instances
[]
end
def create
default_fail
end
def destroy
default_fail
end
def exists?
default_fail
end
def default_fail
fail('This is just the default provider for rabbitmq_vhost, all it does is fail')
end
end

View File

@ -1,16 +1,15 @@
require File.join File.dirname(__FILE__), '../rabbitmq_common.rb'
Puppet::Type.type(:rabbitmq_vhost).provide(:rabbitmqctl) do
Puppet::Type.type(:rabbitmq_vhost).provide(:rabbitmqctl, :parent => Puppet::Provider::Rabbitmq_common) do
#TODO: change optional_commands -> commands when puppet >= 3.0
optional_commands :rabbitmqctl => 'rabbitmqctl'
defaultfor :feature => :posix
if Puppet::PUPPETVERSION.to_f < 3
commands :rabbitmqctl => 'rabbitmqctl'
else
has_command(:rabbitmqctl, 'rabbitmqctl') do
environment :HOME => "/tmp"
end
end
def self.instances
self.wait_for_online
self.run_with_retries {
rabbitmqctl('list_vhosts')
}.split(/\n/)[1..-2].map do |line|
rabbitmqctl('list_vhosts').split(/\n/)[1..-2].map do |line|
if line =~ /^(\S+)$/
new(:name => $1)
else
@ -28,10 +27,7 @@ Puppet::Type.type(:rabbitmq_vhost).provide(:rabbitmqctl, :parent => Puppet::Prov
end
def exists?
self.class.wait_for_online
out = self.class.run_with_retries {
rabbitmqctl('list_vhosts')
}.split(/\n/)[1..-2].detect do |line|
out = rabbitmqctl('list_vhosts').split(/\n/)[1..-2].detect do |line|
line.match(/^#{Regexp.escape(resource[:name])}$/)
end
end

View File

@ -0,0 +1,54 @@
Puppet::Type.newtype(:rabbitmq_exchange) do
desc 'Native type for managing rabbitmq exchanges'
ensurable do
defaultto(:present)
newvalue(:present) do
provider.create
end
newvalue(:absent) do
provider.destroy
end
end
newparam(:name, :namevar => true) do
desc 'Name of exchange'
newvalues(/^\S*@\S+$/)
end
newparam(:type) do
desc 'Exchange type to be set *on creation*'
newvalues(/^\S+$/)
end
newparam(:user) do
desc 'The user to use to connect to rabbitmq'
defaultto('guest')
newvalues(/^\S+$/)
end
newparam(:password) do
desc 'The password to use to connect to rabbitmq'
defaultto('guest')
newvalues(/\S+/)
end
validate do
if self[:ensure] == :present and self[:type].nil?
raise ArgumentError, "must set type when creating exchange for #{self[:name]} whose type is #{self[:type]}"
end
end
autorequire(:rabbitmq_vhost) do
[self[:name].split('@')[1]]
end
autorequire(:rabbitmq_user) do
[self[:user]]
end
autorequire(:rabbitmq_user_permissions) do
["#{self[:user]}@#{self[:name].split('@')[1]}"]
end
end

View File

@ -11,6 +11,8 @@ Puppet::Type.newtype(:rabbitmq_user) do
end
end
autorequire(:service) { 'rabbitmq-server' }
newparam(:name, :namevar => true) do
desc 'Name of user'
newvalues(/^\S+$/)
@ -31,6 +33,10 @@ Puppet::Type.newtype(:rabbitmq_user) do
defaultto :false
end
newproperty(:tags, :array_matching => :all) do
desc 'additional tags for the user'
end
validate do
if self[:ensure] == :present and ! self[:password]
raise ArgumentError, 'must set password when creating user' unless self[:password]

View File

@ -11,8 +11,10 @@ Puppet::Type.newtype(:rabbitmq_user_permissions) do
end
end
autorequire(:service) { 'rabbitmq-server' }
newparam(:name, :namevar => true) do
'combination of user@vhost to grant privileges to'
desc 'combination of user@vhost to grant privileges to'
newvalues(/^\S+@\S+$/)
end

View File

@ -11,6 +11,8 @@ Puppet::Type.newtype(:rabbitmq_vhost) do
end
end
autorequire(:service) { 'rabbitmq-server' }
newparam(:name, :namevar => true) do
'name of the vhost to add'
newvalues(/^\S+$/)

View File

@ -0,0 +1,125 @@
class rabbitmq::config {
$admin_enable = $rabbitmq::admin_enable
$cluster_disk_nodes = $rabbitmq::cluster_disk_nodes
$cluster_node_type = $rabbitmq::cluster_node_type
$cluster_nodes = $rabbitmq::cluster_nodes
$config = $rabbitmq::config
$config_cluster = $rabbitmq::config_cluster
$config_path = $rabbitmq::config_path
$config_stomp = $rabbitmq::config_stomp
$default_user = $rabbitmq::default_user
$default_pass = $rabbitmq::default_pass
$env_config = $rabbitmq::env_config
$env_config_path = $rabbitmq::env_config_path
$erlang_cookie = $rabbitmq::erlang_cookie
$management_port = $rabbitmq::management_port
$node_ip_address = $rabbitmq::node_ip_address
$plugin_dir = $rabbitmq::plugin_dir
$port = $rabbitmq::port
$tcp_keepalive = $rabbitmq::tcp_keepalive
$service_name = $rabbitmq::service_name
$ssl = $rabbitmq::ssl
$ssl_only = $rabbitmq::ssl_only
$ssl_cacert = $rabbitmq::ssl_cacert
$ssl_cert = $rabbitmq::ssl_cert
$ssl_key = $rabbitmq::ssl_key
$ssl_port = $rabbitmq::ssl_port
$ssl_management_port = $rabbitmq::ssl_management_port
$ssl_stomp_port = $rabbitmq::ssl_stomp_port
$ssl_verify = $rabbitmq::ssl_verify
$ssl_fail_if_no_peer_cert = $rabbitmq::ssl_fail_if_no_peer_cert
$stomp_port = $rabbitmq::stomp_port
$wipe_db_on_cookie_change = $rabbitmq::wipe_db_on_cookie_change
$config_variables = $rabbitmq::config_variables
$config_kernel_variables = $rabbitmq::config_kernel_variables
$cluster_partition_handling = $rabbitmq::cluster_partition_handling
$default_env_variables = {
'RABBITMQ_NODE_PORT' => $port,
'RABBITMQ_NODE_IP_ADDRESS' => $node_ip_address
}
# Handle env variables.
$environment_variables = merge($default_env_variables, $rabbitmq::environment_variables)
# Handle deprecated option.
if $cluster_disk_nodes != [] {
notify { 'cluster_disk_nodes':
message => 'WARNING: The cluster_disk_nodes is deprecated.
Use cluster_nodes instead.',
}
$r_cluster_nodes = $cluster_disk_nodes
} else {
$r_cluster_nodes = $cluster_nodes
}
file { '/etc/rabbitmq':
ensure => directory,
owner => '0',
group => '0',
mode => '0644',
}
file { '/etc/rabbitmq/ssl':
ensure => directory,
owner => '0',
group => '0',
mode => '0644',
}
file { 'rabbitmq.config':
ensure => file,
path => $config_path,
content => template($config),
owner => '0',
group => '0',
mode => '0644',
notify => Class['rabbitmq::service'],
}
file { 'rabbitmq-env.config':
ensure => file,
path => $env_config_path,
content => template($env_config),
owner => '0',
group => '0',
mode => '0644',
notify => Class['rabbitmq::service'],
}
if $config_cluster {
file { 'erlang_cookie':
ensure => 'present',
path => '/var/lib/rabbitmq/.erlang.cookie',
owner => 'rabbitmq',
group => 'rabbitmq',
mode => '0400',
content => $erlang_cookie,
replace => true,
before => File['rabbitmq.config'],
notify => Class['rabbitmq::service'],
}
# rabbitmq_erlang_cookie is a fact in this module.
if $erlang_cookie != $::rabbitmq_erlang_cookie {
# Safety check.
if $wipe_db_on_cookie_change {
exec { 'wipe_db':
command => "puppet resource service ${service_name} ensure=stopped; rm -rf /var/lib/rabbitmq/mnesia",
path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin',
}
File['erlang_cookie'] {
require => Exec['wipe_db'],
}
} else {
fail("ERROR: The current erlang cookie is ${::rabbitmq_erlang_cookie} and needs to change to ${erlang_cookie}. In order to do this the RabbitMQ database needs to be wiped. Please set the parameter called wipe_db_on_cookie_change to true to allow this to happen automatically.")
}
}
}
}

View File

@ -0,0 +1,186 @@
#
class rabbitmq(
$admin_enable = $rabbitmq::params::admin_enable,
$cluster_disk_nodes = $rabbitmq::params::cluster_disk_nodes,
$cluster_node_type = $rabbitmq::params::cluster_node_type,
$cluster_nodes = $rabbitmq::params::cluster_nodes,
$config = $rabbitmq::params::config,
$config_cluster = $rabbitmq::params::config_cluster,
$config_path = $rabbitmq::params::config_path,
$config_stomp = $rabbitmq::params::config_stomp,
$default_user = $rabbitmq::params::default_user,
$default_pass = $rabbitmq::params::default_pass,
$delete_guest_user = $rabbitmq::params::delete_guest_user,
$env_config = $rabbitmq::params::env_config,
$env_config_path = $rabbitmq::params::env_config_path,
$erlang_cookie = $rabbitmq::params::erlang_cookie,
$management_port = $rabbitmq::params::management_port,
$node_ip_address = $rabbitmq::params::node_ip_address,
$package_apt_pin = $rabbitmq::params::package_apt_pin,
$package_ensure = $rabbitmq::params::package_ensure,
$package_gpg_key = $rabbitmq::params::package_gpg_key,
$package_name = $rabbitmq::params::package_name,
$package_provider = $rabbitmq::params::package_provider,
$package_source = $rabbitmq::params::package_source,
$manage_repos = $rabbitmq::params::manage_repos,
$plugin_dir = $rabbitmq::params::plugin_dir,
$port = $rabbitmq::params::port,
$tcp_keepalive = $rabbitmq::params::tcp_keepalive,
$service_ensure = $rabbitmq::params::service_ensure,
$service_manage = $rabbitmq::params::service_manage,
$service_name = $rabbitmq::params::service_name,
$ssl = $rabbitmq::params::ssl,
$ssl_only = $rabbitmq::params::ssl_only,
$ssl_cacert = $rabbitmq::params::ssl_cacert,
$ssl_cert = $rabbitmq::params::ssl_cert,
$ssl_key = $rabbitmq::params::ssl_key,
$ssl_port = $rabbitmq::params::ssl_port,
$ssl_management_port = $rabbitmq::params::ssl_management_port,
$ssl_stomp_port = $rabbitmq::params::ssl_stomp_port,
$ssl_verify = $rabbitmq::params::ssl_verify,
$ssl_fail_if_no_peer_cert = $rabbitmq::params::ssl_fail_if_no_peer_cert,
$stomp_ensure = $rabbitmq::params::stomp_ensure,
$ldap_auth = $rabbitmq::params::ldap_auth,
$ldap_server = $rabbitmq::params::ldap_server,
$ldap_user_dn_pattern = $rabbitmq::params::ldap_user_dn_pattern,
$ldap_use_ssl = $rabbitmq::params::ldap_use_ssl,
$ldap_port = $rabbitmq::params::ldap_port,
$ldap_log = $rabbitmq::params::ldap_log,
$stomp_port = $rabbitmq::params::stomp_port,
$version = $rabbitmq::params::version,
$wipe_db_on_cookie_change = $rabbitmq::params::wipe_db_on_cookie_change,
$cluster_partition_handling = $rabbitmq::params::cluster_partition_handling,
$environment_variables = $rabbitmq::params::environment_variables,
$config_variables = $rabbitmq::params::config_variables,
$config_kernel_variables = $rabbitmq::params::config_kernel_variables,
$key_content = undef,
) inherits rabbitmq::params {
validate_bool($admin_enable)
# Validate install parameters.
validate_re($package_apt_pin, '^(|\d+)$')
validate_string($package_ensure)
validate_string($package_gpg_key)
validate_string($package_name)
validate_string($package_provider)
validate_bool($manage_repos)
validate_re($version, '^\d+\.\d+\.\d+(-\d+)*$') # Allow 3 digits and optional -n postfix.
# Validate config parameters.
validate_array($cluster_disk_nodes)
validate_re($cluster_node_type, '^(ram|disc)$')
validate_array($cluster_nodes)
validate_string($config)
validate_absolute_path($config_path)
validate_bool($config_cluster)
validate_bool($config_stomp)
validate_string($default_user)
validate_string($default_pass)
validate_bool($delete_guest_user)
validate_string($env_config)
validate_absolute_path($env_config_path)
validate_string($erlang_cookie)
validate_re($management_port, '\d+')
validate_string($node_ip_address)
validate_absolute_path($plugin_dir)
validate_re($port, ['\d+','UNSET'])
validate_re($stomp_port, '\d+')
validate_bool($wipe_db_on_cookie_change)
validate_bool($tcp_keepalive)
# Validate service parameters.
validate_re($service_ensure, '^(running|stopped)$')
validate_bool($service_manage)
validate_string($service_name)
validate_bool($ssl)
validate_bool($ssl_only)
validate_string($ssl_cacert)
validate_string($ssl_cert)
validate_string($ssl_key)
validate_re($ssl_port, '\d+')
validate_re($ssl_management_port, '\d+')
validate_string($ssl_stomp_port)
validate_re($ssl_stomp_port, '\d+')
validate_bool($stomp_ensure)
validate_bool($ldap_auth)
validate_string($ldap_server)
validate_string($ldap_user_dn_pattern)
validate_bool($ldap_use_ssl)
validate_re($ldap_port, '\d+')
validate_bool($ldap_log)
validate_hash($environment_variables)
validate_hash($config_variables)
validate_hash($config_kernel_variables)
if $ssl_only and ! $ssl {
fail('$ssl_only => true requires that $ssl => true')
}
if $config_stomp and $ssl_stomp_port and ! $ssl {
warning('$ssl_stomp_port requires that $ssl => true and will be ignored')
}
include '::rabbitmq::install'
include '::rabbitmq::config'
include '::rabbitmq::service'
include '::rabbitmq::management'
if $rabbitmq::manage_repos == true {
case $::osfamily {
'RedHat', 'SUSE':
{ include '::rabbitmq::repo::rhel' }
'Debian': {
class { '::rabbitmq::repo::apt' :
key_source => $package_gpg_key,
key_content => $key_content,
}
}
default:
{ }
}
}
if $admin_enable and $service_manage {
include '::rabbitmq::install::rabbitmqadmin'
rabbitmq_plugin { 'rabbitmq_management':
ensure => present,
require => Class['rabbitmq::install'],
notify => Class['rabbitmq::service'],
provider => 'rabbitmqplugins'
}
Class['::rabbitmq::service'] -> Class['::rabbitmq::install::rabbitmqadmin']
}
if $stomp_ensure {
rabbitmq_plugin { 'rabbitmq_stomp':
ensure => present,
require => Class['rabbitmq::install'],
notify => Class['rabbitmq::service'],
provider => 'rabbitmqplugins'
}
}
if ($ldap_auth) {
rabbitmq_plugin { 'rabbitmq_auth_backend_ldap':
ensure => present,
require => Class['rabbitmq::install'],
notify => Class['rabbitmq::service'],
provider => 'rabbitmqplugins',
}
}
# Anchor this as per #8040 - this ensures that classes won't float off and
# mess everything up. You can read about this at:
# http://docs.puppetlabs.com/puppet/2.7/reference/lang_containment.html#known-issues
anchor { 'rabbitmq::begin': }
anchor { 'rabbitmq::end': }
Anchor['rabbitmq::begin'] -> Class['::rabbitmq::install']
-> Class['::rabbitmq::config'] ~> Class['::rabbitmq::service']
-> Class['::rabbitmq::management'] -> Anchor['rabbitmq::end']
# Make sure the various providers have their requirements in place.
Class['::rabbitmq::install'] -> Rabbitmq_plugin<| |>
Class['::rabbitmq::install::rabbitmqadmin'] -> Rabbitmq_exchange<| |>
}

View File

@ -0,0 +1,21 @@
class rabbitmq::install {
$package_ensure = $rabbitmq::package_ensure
$package_name = $rabbitmq::package_name
$package_provider = $rabbitmq::package_provider
$package_source = $rabbitmq::package_source
package { 'rabbitmq-server':
ensure => $package_ensure,
name => $package_name,
provider => $package_provider,
notify => Class['rabbitmq::service'],
}
if $package_source {
Package['rabbitmq-server'] {
source => $package_source,
}
}
}

View File

@ -0,0 +1,26 @@
#
class rabbitmq::install::rabbitmqadmin {
$management_port = $rabbitmq::management_port
$default_user = $rabbitmq::default_user
$default_pass = $rabbitmq::default_pass
$protocol = $rabbitmq::ssl ? { false => 'http', default => 'https' }
staging::file { 'rabbitmqadmin':
target => '/var/lib/rabbitmq/rabbitmqadmin',
source => "${protocol}://${default_user}:${default_pass}@localhost:${management_port}/cli/rabbitmqadmin",
require => [
Class['rabbitmq::service'],
Rabbitmq_plugin['rabbitmq_management']
],
}
file { '/usr/local/bin/rabbitmqadmin':
owner => 'root',
group => 'root',
source => '/var/lib/rabbitmq/rabbitmqadmin',
mode => '0755',
require => Staging::File['rabbitmqadmin'],
}
}

View File

@ -0,0 +1,13 @@
#
class rabbitmq::management {
$delete_guest_user = $rabbitmq::delete_guest_user
if $delete_guest_user {
rabbitmq_user{ 'guest':
ensure => absent,
provider => 'rabbitmqctl',
}
}
}

View File

@ -0,0 +1,99 @@
# Class: rabbitmq::params
#
# The RabbitMQ Module configuration settings.
#
class rabbitmq::params {
case $::osfamily {
'Archlinux': {
$package_ensure = 'installed'
$package_name = 'rabbitmq'
$service_name = 'rabbitmq'
$package_source = ''
$version = '3.1.3-1'
$base_version = regsubst($version,'^(.*)-\d$','\1')
# This must remain at the end as we need $base_version and $version defined first
}
'Debian': {
$package_ensure = 'installed'
$package_name = 'rabbitmq-server'
$service_name = 'rabbitmq-server'
$package_provider = 'apt'
$package_source = ''
$version = '3.1.5'
}
'RedHat': {
$package_ensure = 'installed'
$package_name = 'rabbitmq-server'
$service_name = 'rabbitmq-server'
$package_provider = 'yum'
$version = '3.1.5-1'
$base_version = regsubst($version,'^(.*)-\d$','\1')
# This must remain at the end as we need $base_version and $version defined first.
$package_source = "http://www.rabbitmq.com/releases/rabbitmq-server/v${base_version}/rabbitmq-server-${version}.noarch.rpm"
}
'SUSE': {
$package_ensure = 'installed'
$package_name = 'rabbitmq-server'
$service_name = 'rabbitmq-server'
$package_provider = 'zypper'
$version = '3.1.5-1'
$base_version = regsubst($version,'^(.*)-\d$','\1')
# This must remain at the end as we need $base_version and $version defined first.
$package_source = "http://www.rabbitmq.com/releases/rabbitmq-server/v${base_version}/rabbitmq-server-${version}.noarch.rpm"
}
default: {
fail("The ${module_name} module is not supported on an ${::osfamily} based system.")
}
}
#install
$admin_enable = true
$management_port = '15672'
$package_apt_pin = ''
$package_gpg_key = 'http://www.rabbitmq.com/rabbitmq-signing-key-public.asc'
$manage_repos = true
$service_ensure = 'running'
$service_manage = true
#config
$cluster_disk_nodes = []
$cluster_node_type = 'disc'
$cluster_nodes = []
$config = 'rabbitmq/rabbitmq.config.erb'
$config_cluster = false
$config_path = '/etc/rabbitmq/rabbitmq.config'
$config_stomp = false
$default_user = 'guest'
$default_pass = 'guest'
$delete_guest_user = false
$env_config = 'rabbitmq/rabbitmq-env.conf.erb'
$env_config_path = '/etc/rabbitmq/rabbitmq-env.conf'
$erlang_cookie = 'EOKOWXQREETZSHFNTPEY'
$node_ip_address = 'UNSET'
$plugin_dir = "/usr/lib/rabbitmq/lib/rabbitmq_server-${version}/plugins"
$port = '5672'
$tcp_keepalive = false
$ssl = false
$ssl_only = false
$ssl_cacert = 'UNSET'
$ssl_cert = 'UNSET'
$ssl_key = 'UNSET'
$ssl_port = '5671'
$ssl_management_port = '15671'
$ssl_stomp_port = '6164'
$ssl_verify = 'verify_none'
$ssl_fail_if_no_peer_cert = 'false'
$stomp_ensure = false
$ldap_auth = false
$ldap_server = 'ldap'
$ldap_user_dn_pattern = 'cn=${username},ou=People,dc=example,dc=com'
$ldap_use_ssl = false
$ldap_port = '389'
$ldap_log = false
$stomp_port = '6163'
$wipe_db_on_cookie_change = false
$cluster_partition_handling = 'ignore'
$environment_variables = {}
$config_variables = {}
$config_kernel_variables = {}
}

View File

@ -1,24 +1,31 @@
# sets up the vmware hosted apt repo
# requires
# puppetlabs-apt
# puppetlabs-stdlib
class rabbitmq::repo::apt(
$pin = undef
) {
$location = 'http://www.rabbitmq.com/debian/',
$release = 'testing',
$repos = 'main',
$include_src = false,
$key = '056E8E56',
$key_source = 'http://www.rabbitmq.com/rabbitmq-signing-key-public.asc',
$key_content = undef,
) {
$pin = $rabbitmq::package_apt_pin
Class['rabbitmq::repo::apt'] -> Package<| title == 'rabbitmq-server' |>
apt::source { 'rabbitmq':
location => 'http://www.rabbitmq.com/debian/',
release => 'testing',
repos => 'main',
include_src => false,
key => 'RabbitMQ Release Signing Key <info@rabbitmq.com>',
key_content => template('rabbitmq/rabbit.pub.key'),
pin => $pin,
location => $location,
release => $release,
repos => $repos,
include_src => $include_src,
key => $key,
key_source => $key_source,
key_content => $key_content,
}
if ! ($pin == undef) {
if $pin {
validate_re($pin, '\d\d\d')
apt::pin { 'rabbitmq':
packages => 'rabbitmq-server',

View File

@ -1,18 +1,12 @@
class rabbitmq::repo::rhel (
$key = "http://www.rabbitmq.com/rabbitmq-signing-key-public.asc",
$version = "2.8.4",
$relversion = "1",
) {
exec { "rpm --import ${key}":
path => ["/bin","/usr/bin","/sbin","/usr/sbin"],
}
class rabbitmq::repo::rhel {
package { "rabbitmq-server":
provider => rpm,
ensure => installed,
source => "http://www.rabbitmq.com/releases/rabbitmq-server/v${version}/rabbitmq-server-${version}-${relversion}.noarch.rpm",
require => Exec["rpm --import ${key}"],
$package_gpg_key = $rabbitmq::package_gpg_key
Class['rabbitmq::repo::rhel'] -> Package<| title == 'rabbitmq-server' |>
exec { "rpm --import ${package_gpg_key}":
path => ['/bin','/usr/bin','/sbin','/usr/sbin'],
onlyif => 'test `rpm -qa | grep gpg-pubkey-056e8e56-468e43f2 | wc -l` -eq 0',
}
}

View File

@ -14,179 +14,87 @@
# [*config*] - contents of config file
# [*env_config*] - contents of env-config file
# [*config_cluster*] - whether to configure a RabbitMQ cluster
# [*cluster_disk_nodes*] - which nodes to cluster with (including the current one)
# [*config_mirrored_queues*] - DEPRECATED (doesn't do anything)
# [*cluster_disk_nodes*] - DEPRECATED (use cluster_nodes instead)
# [*cluster_nodes*] - which nodes to cluster with (including the current one)
# [*cluster_node_type*] - Type of cluster node (disc or ram)
# [*erlang_cookie*] - erlang cookie, must be the same for all nodes in a cluster
# [*wipe_db_on_cookie_change*] - whether to wipe the RabbitMQ data if the specified
# erlang_cookie differs from the current one. This is a sad parameter: actually,
# if the cookie indeed differs, then wiping the database is the *only* thing you
# can do. You're only required to set this parameter to true as a sign that you
# realise this.
# Requires:
# stdlib
# Sample Usage:
#
#
# This module is used as backward compability layer for modules
# which require rabbitmq::server instead of rabbitmq class.
# It's still common uasge in many modules.
#
#
# [Remember: No empty lines between comments and class definition]
class rabbitmq::server(
$production = 'prod',
$port = '5672',
$delete_guest_user = false,
$package_name = 'rabbitmq-server',
$version = 'UNSET',
$service_name = 'rabbitmq-server',
$service_ensure = 'running',
$service_enabled = true,
$config_stomp = false,
$stomp_port = '6163',
$config_cluster = false,
$cluster_disk_nodes = [],
$node_ip_address = 'UNSET', #getvar("::ipaddress_${::internal_interface}"),
$config='UNSET',
$env_config='UNSET',
$erlang_cookie='EOKOWXQREETZSHFNTPEY',
$wipe_db_on_cookie_change=true,
$inet_dist_listen_min = '41055',
$inet_dist_listen_max = '41055',
$max_retry = '60',
$service_provider = undef
) {
$port = $rabbitmq::params::port,
$delete_guest_user = $rabbitmq::params::delete_guest_user,
$package_name = $rabbitmq::params::package_name,
$version = $rabbitmq::params::version,
$service_name = $rabbitmq::params::service_name,
$service_ensure = $rabbitmq::params::service_ensure,
$service_manage = $rabbitmq::params::service_manage,
$config_stomp = $rabbitmq::params::config_stomp,
$stomp_port = $rabbitmq::params::stomp_port,
$config_cluster = $rabbitmq::params::config_cluster,
$cluster_disk_nodes = $rabbitmq::params::cluster_disk_nodes,
$cluster_nodes = $rabbitmq::params::cluster_nodes,
$cluster_node_type = $rabbitmq::params::cluster_node_type,
$node_ip_address = $rabbitmq::params::node_ip_address,
$config = $rabbitmq::params::config,
$env_config = $rabbitmq::params::env_config,
$erlang_cookie = $rabbitmq::params::erlang_cookie,
$wipe_db_on_cookie_change = $rabbitmq::params::wipe_db_on_cookie_change,
# DEPRECATED
$manage_service = undef,
$config_mirrored_queues = undef,
) inherits rabbitmq::params {
validate_bool($delete_guest_user, $config_stomp)
validate_re($port, '\d+')
validate_re($stomp_port, '\d+')
if $version == 'UNSET' {
$version_real = '2.4.1'
$pkg_ensure_real = 'present'
if $manage_service != undef {
warning('The $manage_service parameter is deprecated; please use $service_manage instead')
$_service_manage = $manage_service
} else {
$version_real = $version
$pkg_ensure_real = $version
}
if $config == 'UNSET' {
$config_real = template("${module_name}/rabbitmq.config")
} else {
$config_real = $config
}
if $env_config == 'UNSET' {
$env_config_real = template("${module_name}/rabbitmq-env.conf.erb")
} else {
$env_config_real = $env_config
$_service_manage = $service_manage
}
$plugin_dir = "/usr/lib/rabbitmq/lib/rabbitmq_server-${version_real}/plugins"
if $::osfamily == 'RedHat' {
package {'qpid-cpp-server': ensure => 'purged' }
Package['qpid-cpp-server'] -> Package[$package_name]
if $config_mirrored_queues != undef {
warning('The $config_mirrored_queues parameter is deprecated; it does not affect anything')
}
package { $package_name:
ensure => $pkg_ensure_real,
notify => Class['rabbitmq::service'],
anchor {'before::rabbimq::class':
before => Class['rabbitmq'],
}
file { '/etc/rabbitmq':
ensure => directory,
owner => '0',
group => '0',
mode => '0644',
require => Package[$package_name],
anchor {'after::rabbimq::class':
require => Class['rabbitmq'],
}
file { 'rabbitmq.config':
ensure => file,
path => '/etc/rabbitmq/rabbitmq.config',
content => $config_real,
owner => '0',
group => '0',
mode => '0644',
require => Package[$package_name],
notify => Class['rabbitmq::service'],
}
if $config_cluster {
file { 'erlang_cookie':
path =>"/var/lib/rabbitmq/.erlang.cookie",
owner => rabbitmq,
group => rabbitmq,
mode => '0400',
content => $erlang_cookie,
replace => true,
before => File['rabbitmq.config'],
require => Exec['wipe_db'], # require => Exec['rabbitmq_stop']
}
# require authorize_cookie_change
if $wipe_db_on_cookie_change {
exec { 'wipe_db':
command => '/etc/init.d/rabbitmq-server stop; /bin/rm -rf /var/lib/rabbitmq/mnesia',
require => Package[$package_name],
unless => "/bin/grep -qx ${erlang_cookie} /var/lib/rabbitmq/.erlang.cookie"
}
} else {
exec { 'wipe_db':
command => '/bin/false "Cookie must be changed but wipe_db is false"', # If the cookie doesn't match, just fail.
require => Package[$package_name],
unless => "/bin/grep -qx ${erlang_cookie} /var/lib/rabbitmq/.erlang.cookie"
}
}
}
file { 'rabbitmq-env.config':
ensure => file,
path => '/etc/rabbitmq/rabbitmq-env.conf',
content => $env_config_real,
owner => '0',
group => '0',
mode => '0644',
notify => Class['rabbitmq::service'],
}
if $production !~ /docker/ {
case $::osfamily {
'RedHat' : {
file { 'rabbitmq-server':
ensure => present,
path => '/etc/init.d/rabbitmq-server',
content => template('rabbitmq/rabbitmq-server_redhat.erb'),
replace => true,
owner => '0',
group => '0',
mode => '0755',
#notify => Class['rabbitmq::service'],
require => Package[$package_name],
}
}
'Debian' : {
file { 'rabbitmq-server':
ensure => present,
path => '/etc/init.d/rabbitmq-server',
content => template('rabbitmq/rabbitmq-server_ubuntu.erb'),
replace => true,
owner => '0',
group => '0',
mode => '0755',
#notify => Class['rabbitmq::service'],
require => Package[$package_name],
}
}
}
}
class { 'rabbitmq::service':
class { 'rabbitmq':
port => $port,
delete_guest_user => $delete_guest_user,
package_name => $package_name,
version => $version,
service_name => $service_name,
ensure => $service_ensure,
enabled => $service_enabled,
service_provider => $service_provider
service_ensure => $service_ensure,
service_manage => $_service_manage,
config_stomp => $config_stomp,
stomp_port => $stomp_port,
config_cluster => $config_cluster,
cluster_disk_nodes => $cluster_disk_nodes,
cluster_nodes => $cluster_nodes,
cluster_node_type => $cluster_node_type,
node_ip_address => $node_ip_address,
config => $config,
env_config => $env_config,
erlang_cookie => $erlang_cookie,
wipe_db_on_cookie_change => $wipe_db_on_cookie_change,
}
if $delete_guest_user {
# delete the default guest user
rabbitmq_user{ 'guest':
ensure => absent,
provider => 'rabbitmqctl',
}
}
}

View File

@ -2,9 +2,6 @@
#
# This class manages the rabbitmq server service itself.
#
# Jeff McCune <jeff@puppetlabs.com>
#
#
# Parameters:
#
# Actions:
@ -14,45 +11,29 @@
# Sample Usage:
#
class rabbitmq::service(
$service_name = 'rabbitmq-server',
$service_provider = undef,
$ensure='running',
$enabled=true
) {
$service_ensure = $rabbitmq::service_ensure,
$service_manage = $rabbitmq::service_manage,
$service_name = $rabbitmq::service_name,
) inherits rabbitmq {
validate_re($ensure, '^(running|stopped)$')
if $ensure == 'running' {
Class['rabbitmq::service'] -> Rabbitmq_user<| |>
Class['rabbitmq::service'] -> Rabbitmq_vhost<| |>
Class['rabbitmq::service'] -> Rabbitmq_user_permissions<| |>
validate_re($service_ensure, '^(running|stopped)$')
validate_bool($service_manage)
if ($service_manage) {
if $service_ensure == 'running' {
$ensure_real = 'running'
$enable_real = $enabled
$enable_real = true
} else {
$ensure_real = 'stopped'
$enable_real = false
}
File <| title == '/etc/rabbitmq/enabled_plugins'|> -> Service[$service_name]
Package<| title == 'rabbitmq-server'|> ~> Service<| title == $service_name|>
if !defined(Service[$service_name]) {
notify{ "Module ${module_name} cannot notify service ${service_name}\
on package rabbitmq-server update": }
}
if ($service_provider) {
service { $service_name:
ensure => $ensure_real,
enable => $enable_real,
hasstatus => true,
hasrestart => true,
provider => $service_provider,
}
} else {
service { $service_name:
service { 'rabbitmq-server':
ensure => $ensure_real,
enable => $enable_real,
hasstatus => true,
hasrestart => true,
name => $service_name,
}
}

View File

@ -0,0 +1,96 @@
require 'spec_helper_acceptance'
describe 'rabbitmq class:' do
case fact('osfamily')
when 'RedHat'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
when 'SUSE'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
when 'Debian'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
when 'Archlinux'
package_name = 'rabbitmq'
service_name = 'rabbitmq'
end
context "default class inclusion" do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq': }
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
# Apply twice to ensure no errors the second time.
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_changes => true).exit_code).to be_zero
end
describe package(package_name) do
it { should be_installed }
end
describe service(service_name) do
it { should be_enabled }
it { should be_running }
end
end
context "disable and stop service" do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq':
service_ensure => 'stopped',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe service(service_name) do
it { should_not be_enabled }
it { should_not be_running }
end
end
context "service is unmanaged" do
it 'should run successfully' do
pp_pre = <<-EOS
class { 'rabbitmq': }
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
pp = <<-EOS
class { 'rabbitmq':
service_manage => false,
service_ensure => 'stopped',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
apply_manifest(pp_pre, :catch_failures => true)
apply_manifest(pp, :catch_failures => true)
end
describe service(service_name) do
it { should be_enabled }
it { should be_running }
end
end
end

View File

@ -0,0 +1,34 @@
require 'spec_helper_acceptance'
describe 'rabbitmq clustering' do
context 'rabbitmq::config_cluster => true' do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq':
config_cluster => true,
cluster_nodes => ['rabbit1', 'rabbit2'],
cluster_node_type => 'ram',
wipe_db_on_cookie_change => true,
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/etc/rabbitmq/rabbitmq.config') do
it { should be_file }
it { should contain 'cluster_nodes' }
it { should contain 'rabbit@rabbit1' }
it { should contain 'rabbit@rabbit2' }
it { should contain 'ram' }
end
describe file('/var/lib/rabbitmq/.erlang.cookie') do
it { should be_file }
end
end
end

View File

@ -0,0 +1,26 @@
require 'spec_helper_acceptance'
describe 'rabbitmq with delete_guest_user' do
context 'delete_guest_user' do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq':
port => '5672',
delete_guest_user => true,
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
apply_manifest(pp, :catch_failures => true)
shell('rabbitmqctl list_users > /tmp/rabbitmqctl_users')
end
describe file('/tmp/rabbitmqctl_users') do
it { should be_file }
it { should_not contain 'guest' }
end
end
end

View File

@ -0,0 +1,11 @@
HOSTS:
centos-64-x64:
roles:
- master
platform: el-6-x86_64
box : centos-64-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
hypervisor : vagrant
CONFIG:
log_level: debug
type: git

View File

@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-1310-x64:
roles:
- master
platform: ubuntu-13.10-amd64
box : ubuntu-server-1310-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-1310-x64-virtualbox-nocm.box
hypervisor : vagrant
CONFIG:
log_level : debug
type: git

View File

@ -0,0 +1,11 @@
HOSTS:
ubuntu-server-1404-x64:
roles:
- master
platform: ubuntu-14.04-amd64
box : trusty-server-cloudimg-amd64-vagrant-disk1
box_url : https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box
hypervisor : vagrant
CONFIG:
log_level : debug
type: git

View File

@ -0,0 +1,85 @@
require 'spec_helper_acceptance'
describe 'rabbitmq::install::rabbitmqadmin class' do
context 'does nothing if service is unmanaged' do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq':
admin_enable => true,
service_manage => false,
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
shell('rm -f /var/lib/rabbitmq/rabbitmqadmin')
apply_manifest(pp, :catch_failures => true)
end
describe file('/var/lib/rabbitmq/rabbitmqadmin') do
it { should_not be_file }
end
end
context 'downloads the cli tools' do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq':
admin_enable => true,
service_manage => true,
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe file('/var/lib/rabbitmq/rabbitmqadmin') do
it { should be_file }
end
end
context 'works with specified default credentials' do
it 'should run successfully' do
# make sure credential change takes effect before admin_enable
pp_pre = <<-EOS
class { 'rabbitmq':
service_manage => true,
default_user => 'foobar',
default_pass => 'bazblam',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
pp = <<-EOS
class { 'rabbitmq':
admin_enable => true,
service_manage => true,
default_user => 'foobar',
default_pass => 'bazblam',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
shell('rm -f /var/lib/rabbitmq/rabbitmqadmin')
apply_manifest(pp_pre, :catch_failures => true)
apply_manifest(pp, :catch_failures => true)
end
describe file('/var/lib/rabbitmq/rabbitmqadmin') do
it { should be_file }
end
end
end

View File

@ -0,0 +1,96 @@
require 'spec_helper_acceptance'
describe 'rabbitmq server:' do
case fact('osfamily')
when 'RedHat'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
when 'SUSE'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
when 'Debian'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
when 'Archlinux'
package_name = 'rabbitmq'
service_name = 'rabbitmq'
end
context "default class inclusion" do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq::server': }
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq::server']
}
EOS
# Apply twice to ensure no errors the second time.
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_changes => true).exit_code).to be_zero
end
describe package(package_name) do
it { should be_installed }
end
describe service(service_name) do
it { should be_enabled }
it { should be_running }
end
end
context "disable and stop service" do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq::server':
service_ensure => 'stopped',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq::server']
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe service(service_name) do
it { should_not be_enabled }
it { should_not be_running }
end
end
context "service is unmanaged" do
it 'should run successfully' do
pp_pre = <<-EOS
class { 'rabbitmq::server': }
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq::server']
}
EOS
pp = <<-EOS
class { 'rabbitmq::server':
service_manage => false,
service_ensure => 'stopped',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq::server']
}
EOS
apply_manifest(pp_pre, :catch_failures => true)
apply_manifest(pp, :catch_failures => true)
end
describe service(service_name) do
it { should be_enabled }
it { should be_running }
end
end
end

View File

@ -0,0 +1,213 @@
require 'spec_helper_acceptance'
#
# beacuse of some serious issues with upgrading and downgrading rabbitmq on RedHat,
# we need to run all of the 2.8.1 tests last.
#
# NOTE that this is only tested on RedHat and probably only works there. But I can't seem
# to get 'confine' to work...
#
describe 'rabbitmq class with 2.8.1:' do
case fact('osfamily')
when 'RedHat'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
package_source = "http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.1/rabbitmq-server-2.8.1-1.noarch.rpm"
package_ensure = '2.8.1-1'
when 'SUSE'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
package_source = "http://www.rabbitmq.com/releases/rabbitmq-server/v2.8.1/rabbitmq-server-2.8.1-1.noarch.rpm"
package_ensure = '2.8.1-1'
when 'Debian'
package_name = 'rabbitmq-server'
service_name = 'rabbitmq-server'
package_source = ''
package_ensure = '2.8.1'
when 'Archlinux'
package_name = 'rabbitmq'
service_name = 'rabbitmq'
package_source = ''
package_ensure = '2.8.1'
end
context "default class inclusion" do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq':
version => '2.8.1-1',
package_source => '#{package_source}',
package_ensure => '#{package_ensure}',
package_provider => 'rpm',
management_port => '55672',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
# clean up previous 3.x install - can't be ungraded cleanly via RPM
shell('service rabbitmq-server stop')
shell('yum -y erase rabbitmq-server')
shell('rm -Rf /var/lib/rabbitmq/mnesia /etc/rabbitmq /var/lib/rabbitmq/rabbitmqadmin')
# Apply twice to ensure no errors the second time.
apply_manifest(pp, :catch_failures => true)
expect(apply_manifest(pp, :catch_changes => true).exit_code).to be_zero
# DEBUG
shell('netstat -lntp')
end
describe command('rabbitmqctl status') do
its(:stdout) { should match /{rabbit,"RabbitMQ","2.8.1"}/ }
end
describe package(package_name) do
it { should be_installed }
end
describe service(service_name) do
it { should be_enabled }
it { should be_running }
end
end
context "disable and stop service" do
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq':
version => '2.8.1-1',
package_source => '#{package_source}',
package_ensure => '#{package_ensure}',
package_provider => 'rpm',
management_port => '55672',
service_ensure => 'stopped',
admin_enable => false,
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
apply_manifest(pp, :catch_failures => true)
end
describe service(service_name) do
it { should_not be_enabled }
it { should_not be_running }
end
end
context "service is unmanaged" do
it 'should run successfully' do
pp_pre = <<-EOS
class { 'rabbitmq':
version => '2.8.1-1',
package_source => '#{package_source}',
package_ensure => '#{package_ensure}',
package_provider => 'rpm',
management_port => '55672',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
pp = <<-EOS
class { 'rabbitmq':
service_manage => false,
service_ensure => 'stopped',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
apply_manifest(pp_pre, :catch_failures => true)
apply_manifest(pp, :catch_failures => true)
end
describe service(service_name) do
it { should be_enabled }
it { should be_running }
end
end
context 'rabbitmqadmin' do
#confine :to, :platform => 'el-6-x86'
it 'should run successfully' do
pp = <<-EOS
class { 'rabbitmq':
admin_enable => true,
service_manage => true,
version => '2.8.1-1',
package_source => '#{package_source}',
package_ensure => '#{package_ensure}',
package_provider => 'rpm',
management_port => '55672',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
shell('rm -f /var/lib/rabbitmq/rabbitmqadmin')
apply_manifest(pp, :catch_failures => true)
end
# since serverspec (used by beaker-rspec) can only tell present/absent for packages
describe file('/var/lib/rabbitmq/rabbitmqadmin') do
it { should be_file }
end
describe command('rabbitmqadmin --help') do
it { should return_exit_status 0 }
end
end
context 'rabbitmqadmin with specified default credentials' do
it 'should run successfully' do
# make sure credential change takes effect before admin_enable
pp = <<-EOS
class { 'rabbitmq':
admin_enable => true,
service_manage => true,
version => '2.8.1-1',
package_source => '#{package_source}',
package_ensure => '#{package_ensure}',
package_provider => 'rpm',
management_port => '55672',
default_user => 'foobar',
default_pass => 'bazblam',
}
if $::osfamily == 'RedHat' {
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']
}
EOS
# next 3 lines - see MODULES-1085
shell('service rabbitmq-server stop')
shell('rm -Rf /var/lib/rabbitmq/mnesia /var/lib/rabbitmq/rabbitmqadmin')
apply_manifest(pp, :catch_failures => true)
end
# since serverspec (used by beaker-rspec) can only tell present/absent for packages
describe file('/var/lib/rabbitmq/rabbitmqadmin') do
it { should be_file }
end
describe command('rabbitmqadmin --help') do
it { should return_exit_status 0 }
end
end
end

View File

@ -1,23 +0,0 @@
require 'spec_helper'
describe 'rabbitmq::repo::rhel' do
describe 'package with params' do
let :params do
{
:key => "http://www.rabbitmq.com/rabbitmq-signing-key-public.asc",
:version => "2.8.4",
:relversion => "1",
}
end
it { should contain_exec("rpm --import #{params[:key]}").with(
'path' => ["/bin","/usr/bin","/sbin","/usr/sbin"],
) }
it { should contain_package('rabbitmq-server').with(
'provider' => 'rpm',
'ensure' => 'installed',
'source' => "http://www.rabbitmq.com/releases/rabbitmq-server/v#{params[:version]}/rabbitmq-server-#{params[:version]}-#{params[:relversion]}.noarch.rpm",
'require' => "Exec[rpm --import #{params[:key]}]",
) }
end
end

View File

@ -1,117 +0,0 @@
require 'spec_helper'
describe 'rabbitmq::server' do
let :facts do
# Needed for statement in rabbitmq.config template.
{ :puppetversion => '2.7.14' }
end
describe 'package with default params' do
it { should contain_package('rabbitmq-server').with(
'ensure' => 'present'
) }
end
describe 'package with specified ensure' do
let :params do
{ :version => "2.3.0" }
end
it { should contain_package('rabbitmq-server').with(
'ensure' => '2.3.0'
) }
end
describe 'not deleting guest user by default' do
it { should_not contain_rabbitmq_user('guest') }
end
describe 'deleting guest user' do
let :params do
{ :delete_guest_user => true }
end
it { should contain_rabbitmq_user('guest').with(
'ensure' => 'absent',
'provider' => 'rabbitmqctl'
) }
end
describe 'default service include' do
it { should contain_class('rabbitmq::service').with(
'service_name' => 'rabbitmq-server',
'ensure' => 'running'
) }
end
describe 'overriding service paramters' do
let :params do
{ 'service_name' => 'custom-rabbitmq-server',
'service_ensure' => 'stopped'
}
end
it { should contain_class('rabbitmq::service').with(
'service_name' => 'custom-rabbitmq-server',
'ensure' => 'stopped'
) }
end
describe 'specifing node_ip_address' do
let :params do
{ :node_ip_address => '172.0.0.1' }
end
it 'should set RABBITMQ_NODE_IP_ADDRESS to specified value' do
verify_contents(subject, 'rabbitmq-env.config',
['RABBITMQ_NODE_IP_ADDRESS=172.0.0.1'])
end
end
describe 'not configuring stomp by default' do
it 'should not specify stomp parameters in rabbitmq.config' do
verify_contents(subject, 'rabbitmq.config',
['[','].'])
end
end
describe 'configuring stomp' do
let :params do
{ :config_stomp => true,
:stomp_port => 5679
}
end
it 'should specify stomp port in rabbitmq.config' do
verify_contents(subject, 'rabbitmq.config',
['[','{rabbitmq_stomp, [{tcp_listeners, [5679]} ]}','].'])
end
end
describe 'configuring cluster' do
let :params do
{ :config_cluster => true,
:cluster_disk_nodes => ['hare-1', 'hare-2']
}
end
it 'should specify cluster nodes in rabbitmq.config' do
verify_contents(subject, 'rabbitmq.config',
['[',"{rabbit, [{cluster_nodes, ['rabbit@hare-1', 'rabbit@hare-2']}]}", '].'])
end
it 'should have the default erlang cookie' do
verify_contents(subject, 'erlang_cookie',
['EOKOWXQREETZSHFNTPEY'])
end
end
describe 'specifying custom erlang cookie in cluster mode' do
let :params do
{ :config_cluster => true,
:erlang_cookie => 'YOKOWXQREETZSHFNTPEY' }
end
it 'should set .erlang.cookie to the specified value' do
verify_contents(subject, 'erlang_cookie',
['YOKOWXQREETZSHFNTPEY'])
end
end
end

View File

@ -0,0 +1,644 @@
require 'spec_helper'
describe 'rabbitmq' do
context 'on unsupported distributions' do
let(:facts) {{ :osfamily => 'Unsupported' }}
it 'we fail' do
expect { subject }.to raise_error(/not supported on an Unsupported/)
end
end
context 'on Debian' do
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
it 'includes rabbitmq::repo::apt' do
should contain_class('rabbitmq::repo::apt')
end
describe 'apt::source default values' do
it 'should add a repo with defaults values' do
should contain_apt__source('rabbitmq').with( {
:location => 'http://www.rabbitmq.com/debian/',
:release => 'testing',
:repos => 'main',
})
end
end
end
context 'on Debian' do
let(:params) {{ :manage_repos => false }}
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'squeeze' }}
it 'does not include rabbitmq::repo::apt when manage_repos is false' do
should_not contain_class('rabbitmq::repo::apt')
end
end
context 'on Redhat' do
let(:facts) {{ :osfamily => 'RedHat' }}
it 'includes rabbitmq::repo::rhel' do
should contain_class('rabbitmq::repo::rhel')
end
end
context 'on Redhat' do
let(:params) {{ :manage_repos => false }}
let(:facts) {{ :osfamily => 'RedHat' }}
it 'does not include rabbitmq::repo::rhel when manage_repos is false' do
should_not contain_class('rabbitmq::repo::rhel')
end
end
['Debian', 'RedHat', 'SUSE', 'Archlinux'].each do |distro|
context "on #{distro}" do
let(:facts) {{
:osfamily => distro,
:rabbitmq_erlang_cookie => 'EOKOWXQREETZSHFNTPEY',
:lsbdistcodename => 'squeeze',
:lsbdistid => 'Debian'
}}
it { should contain_class('rabbitmq::install') }
it { should contain_class('rabbitmq::config') }
it { should contain_class('rabbitmq::service') }
context 'with admin_enable set to true' do
let(:params) {{ :admin_enable => true }}
context 'with service_manage set to true' do
it 'we enable the admin interface by default' do
should contain_class('rabbitmq::install::rabbitmqadmin')
should contain_rabbitmq_plugin('rabbitmq_management').with(
'require' => 'Class[Rabbitmq::Install]',
'notify' => 'Class[Rabbitmq::Service]'
)
should contain_staging__file('rabbitmqadmin').with_source("http://guest:guest@localhost:15672/cli/rabbitmqadmin")
end
end
context 'with service_manage set to true and default user/pass specified' do
let(:params) {{ :admin_enable => true, :default_user => 'foobar', :default_pass => 'hunter2' }}
it 'we use the correct URL to rabbitmqadmin' do
should contain_staging__file('rabbitmqadmin').with_source("http://foobar:hunter2@localhost:15672/cli/rabbitmqadmin")
end
end
context 'with service_manage set to true and management port specified' do
# note that the 2.x management port is 55672 not 15672
let(:params) {{ :admin_enable => true, :management_port => '55672' }}
it 'we use the correct URL to rabbitmqadmin' do
should contain_staging__file('rabbitmqadmin').with_source("http://guest:guest@localhost:55672/cli/rabbitmqadmin")
end
end
context 'with service_manage set to false' do
let(:params) {{ :admin_enable => true, :service_manage => false }}
it 'should do nothing' do
should_not contain_class('rabbitmq::install::rabbitmqadmin')
should_not contain_rabbitmq_plugin('rabbitmq_management')
end
end
end
context 'deprecated parameters' do
describe 'cluster_disk_nodes' do
let(:params) {{ :cluster_disk_nodes => ['node1', 'node2'] }}
it { should contain_notify('cluster_disk_nodes') }
end
end
describe 'manages configuration directory correctly' do
it { should contain_file('/etc/rabbitmq').with(
'ensure' => 'directory'
)}
end
describe 'manages configuration file correctly' do
it { should contain_file('rabbitmq.config') }
end
context 'configures config_cluster' do
let(:facts) {{ :osfamily => distro, :rabbitmq_erlang_cookie => 'ORIGINAL', :lsbdistid => 'Debian' }}
let(:params) {{
:config_cluster => true,
:cluster_nodes => ['hare-1', 'hare-2'],
:cluster_node_type => 'ram',
:erlang_cookie => 'TESTCOOKIE',
:wipe_db_on_cookie_change => false
}}
describe 'with defaults' do
it 'fails' do
expect{subject}.to raise_error(/^ERROR: The current erlang cookie is ORIGINAL/)
end
end
describe 'with wipe_db_on_cookie_change set' do
let(:params) {{
:config_cluster => true,
:cluster_nodes => ['hare-1', 'hare-2'],
:cluster_node_type => 'ram',
:erlang_cookie => 'TESTCOOKIE',
:wipe_db_on_cookie_change => true
}}
it 'wipes the database' do
should contain_exec('wipe_db')
should contain_file('erlang_cookie')
end
end
describe 'correctly when cookies match' do
let(:params) {{
:config_cluster => true,
:cluster_nodes => ['hare-1', 'hare-2'],
:cluster_node_type => 'ram',
:erlang_cookie => 'ORIGINAL',
:wipe_db_on_cookie_change => true
}}
it 'and doesnt wipe anything' do
should contain_file('erlang_cookie')
end
end
describe 'and sets appropriate configuration' do
let(:params) {{
:config_cluster => true,
:cluster_nodes => ['hare-1', 'hare-2'],
:cluster_node_type => 'ram',
:erlang_cookie => 'ORIGINAL',
:wipe_db_on_cookie_change => true
}}
it 'for cluster_nodes' do
should contain_file('rabbitmq.config').with({
'content' => /cluster_nodes.*\['rabbit@hare-1', 'rabbit@hare-2'\], ram/,
})
end
it 'for erlang_cookie' do
should contain_file('erlang_cookie').with({
'content' => 'ORIGINAL',
})
end
end
end
describe 'rabbitmq-env configuration' do
let(:params) {{ :environment_variables => {
'RABBITMQ_NODE_IP_ADDRESS' => '1.1.1.1',
'RABBITMQ_NODE_PORT' => '5656',
'RABBITMQ_NODENAME' => 'HOSTNAME',
'RABBITMQ_SERVICENAME' => 'RabbitMQ',
'RABBITMQ_CONSOLE_LOG' => 'RabbitMQ.debug',
'RABBITMQ_CTL_ERL_ARGS' => 'verbose',
'RABBITMQ_SERVER_ERL_ARGS' => 'v',
'RABBITMQ_SERVER_START_ARGS' => 'debug'
}}}
it 'should set environment variables' do
should contain_file('rabbitmq-env.config') \
.with_content(/RABBITMQ_NODE_IP_ADDRESS=1.1.1.1/) \
.with_content(/RABBITMQ_NODE_PORT=5656/) \
.with_content(/RABBITMQ_NODENAME=HOSTNAME/) \
.with_content(/RABBITMQ_SERVICENAME=RabbitMQ/) \
.with_content(/RABBITMQ_CONSOLE_LOG=RabbitMQ.debug/) \
.with_content(/RABBITMQ_CTL_ERL_ARGS=verbose/) \
.with_content(/RABBITMQ_SERVER_ERL_ARGS=v/) \
.with_content(/RABBITMQ_SERVER_START_ARGS=debug/)
end
end
context 'delete_guest_user' do
describe 'should do nothing by default' do
it { should_not contain_rabbitmq_user('guest') }
end
describe 'delete user when delete_guest_user set' do
let(:params) {{ :delete_guest_user => true }}
it 'removes the user' do
should contain_rabbitmq_user('guest').with(
'ensure' => 'absent',
'provider' => 'rabbitmqctl'
)
end
end
end
context 'configuration setting' do
describe 'node_ip_address when set' do
let(:params) {{ :node_ip_address => '172.0.0.1' }}
it 'should set RABBITMQ_NODE_IP_ADDRESS to specified value' do
should contain_file('rabbitmq-env.config').
with_content(%r{RABBITMQ_NODE_IP_ADDRESS=172\.0\.0\.1})
end
end
describe 'stomp by default' do
it 'should not specify stomp parameters in rabbitmq.config' do
should contain_file('rabbitmq.config').without({
'content' => /stomp/,})
end
end
describe 'stomp when set' do
let(:params) {{ :config_stomp => true, :stomp_port => 5679 }}
it 'should specify stomp port in rabbitmq.config' do
should contain_file('rabbitmq.config').with({
'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\]/m,
})
end
end
describe 'stomp when set ssl port w/o ssl enabled' do
let(:params) {{ :config_stomp => true, :stomp_port => 5679, :ssl => false, :ssl_stomp_port => 5680 }}
it 'should not configure ssl_listeners in rabbitmq.config' do
should contain_file('rabbitmq.config').without({
'content' => /rabbitmq_stomp.*ssl_listeners, \[5680\]/m,
})
end
end
describe 'stomp when set with ssl' do
let(:params) {{ :config_stomp => true, :stomp_port => 5679, :ssl => true, :ssl_stomp_port => 5680 }}
it 'should specify stomp port and ssl stomp port in rabbitmq.config' do
should contain_file('rabbitmq.config').with({
'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\].*ssl_listeners, \[5680\]/m,
})
end
end
end
describe 'configuring ldap authentication' do
let :params do
{ :config_stomp => true,
:ldap_auth => true,
:ldap_server => 'ldap.example.com',
:ldap_user_dn_pattern => 'ou=users,dc=example,dc=com',
:ldap_use_ssl => false,
:ldap_port => '389',
:ldap_log => true
}
end
it { should contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') }
it 'should contain ldap parameters' do
verify_contents(subject, 'rabbitmq.config',
['[', ' {rabbit, [', ' {auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},', ' ]}',
' {rabbitmq_auth_backend_ldap, [', ' {other_bind, anon},',
' {servers, ["ldap.example.com"]},',
' {user_dn_pattern, "ou=users,dc=example,dc=com"},', ' {use_ssl, false},',
' {port, 389},', ' {log, true}'])
end
end
describe 'configuring ldap authentication' do
let :params do
{ :config_stomp => false,
:ldap_auth => true,
:ldap_server => 'ldap.example.com',
:ldap_user_dn_pattern => 'ou=users,dc=example,dc=com',
:ldap_use_ssl => false,
:ldap_port => '389',
:ldap_log => true
}
end
it { should contain_rabbitmq_plugin('rabbitmq_auth_backend_ldap') }
it 'should contain ldap parameters' do
verify_contents(subject, 'rabbitmq.config',
['[', ' {rabbit, [', ' {auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},', ' ]}',
' {rabbitmq_auth_backend_ldap, [', ' {other_bind, anon},',
' {servers, ["ldap.example.com"]},',
' {user_dn_pattern, "ou=users,dc=example,dc=com"},', ' {use_ssl, false},',
' {port, 389},', ' {log, true}'])
end
end
describe 'default_user and default_pass set' do
let(:params) {{ :default_user => 'foo', :default_pass => 'bar' }}
it 'should set default_user and default_pass to specified values' do
should contain_file('rabbitmq.config').with({
'content' => /default_user, <<"foo">>.*default_pass, <<"bar">>/m,
})
end
end
describe 'ssl options' do
let(:params) {
{ :ssl => true,
:ssl_port => 3141,
:ssl_cacert => '/path/to/cacert',
:ssl_cert => '/path/to/cert',
:ssl_key => '/path/to/key'
} }
it 'should set ssl options to specified values' do
should contain_file('rabbitmq.config').with_content(
%r{ssl_listeners, \[3141\]}
)
should contain_file('rabbitmq.config').with_content(
%r{ssl_options, \[\{cacertfile,"/path/to/cacert"}
)
should contain_file('rabbitmq.config').with_content(
%r{certfile,"/path/to/cert"}
)
should contain_file('rabbitmq.config').with_content(
%r{keyfile,"/path/to/key"}
)
end
end
describe 'ssl options with ssl_only' do
let(:params) {
{ :ssl => true,
:ssl_only => true,
:ssl_port => 3141,
:ssl_cacert => '/path/to/cacert',
:ssl_cert => '/path/to/cert',
:ssl_key => '/path/to/key'
} }
it 'should set ssl options to specified values' do
should contain_file('rabbitmq.config').with_content(%r{tcp_listeners, \[\]})
should contain_file('rabbitmq.config').with_content(%r{ssl_listeners, \[3141\]})
should contain_file('rabbitmq.config').with_content(%r{ssl_options, \[\{cacertfile,"/path/to/cacert"})
should contain_file('rabbitmq.config').with_content(%r{certfile,"/path/to/cert"})
should contain_file('rabbitmq.config').with_content(%r{keyfile,"/path/to/key})
end
end
describe 'ssl admin options' do
let(:params) {
{ :ssl => true,
:ssl_management_port => 3141,
:ssl_cacert => '/path/to/cacert',
:ssl_cert => '/path/to/cert',
:ssl_key => '/path/to/key',
:admin_enable => true
} }
it 'should set rabbitmq_management ssl options to specified values' do
should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
should contain_file('rabbitmq.config').with_content(%r{listener, \[})
should contain_file('rabbitmq.config').with_content(%r{port, 3141\}})
should contain_file('rabbitmq.config').with_content(%r{ssl, true\}})
should contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[\{cacertfile, "/path/to/cacert"\},})
should contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},})
should contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}\]\}})
end
end
describe 'admin without ssl' do
let(:params) {
{ :ssl => false,
:management_port => 3141,
:admin_enable => true
} }
it 'should set rabbitmq_management options to specified values' do
should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
should contain_file('rabbitmq.config').with_content(%r{listener, \[})
should contain_file('rabbitmq.config').with_content(%r{port, 3141\}})
end
end
describe 'ssl admin options' do
let(:params) {
{ :ssl => true,
:ssl_management_port => 3141,
:ssl_cacert => '/path/to/cacert',
:ssl_cert => '/path/to/cert',
:ssl_key => '/path/to/key',
:admin_enable => true
} }
it 'should set rabbitmq_management ssl options to specified values' do
should contain_file('rabbitmq.config').with_content(%r{rabbitmq_management, \[})
should contain_file('rabbitmq.config').with_content(%r{listener, \[})
should contain_file('rabbitmq.config').with_content(%r{port, 3141\},})
should contain_file('rabbitmq.config').with_content(%r{ssl, true\},})
should contain_file('rabbitmq.config').with_content(%r{ssl_opts, \[\{cacertfile, "/path/to/cacert"\},})
should contain_file('rabbitmq.config').with_content(%r{certfile, "/path/to/cert"\},})
should contain_file('rabbitmq.config').with_content(%r{keyfile, "/path/to/key"\}\]\}})
end
end
describe 'admin without ssl' do
let(:params) {
{ :ssl => false,
:management_port => 3141,
:admin_enable => true
} }
it 'should set rabbitmq_management options to specified values' do
should contain_file('rabbitmq.config') \
.with_content(/\{rabbitmq_management, \[/) \
.with_content(/\{listener, \[/) \
.with_content(/\{port, 3141\}/)
end
end
describe 'config_variables options' do
let(:params) {{ :config_variables => {
'hipe_compile' => true,
'vm_memory_high_watermark' => 0.4,
'frame_max' => 131072,
'collect_statistics' => "none",
'auth_mechanisms' => "['PLAIN', 'AMQPLAIN']",
}}}
it 'should set environment variables' do
should contain_file('rabbitmq.config') \
.with_content(/\{hipe_compile, true\}/) \
.with_content(/\{vm_memory_high_watermark, 0.4\}/) \
.with_content(/\{frame_max, 131072\}/) \
.with_content(/\{collect_statistics, none\}/) \
.with_content(/\{auth_mechanisms, \['PLAIN', 'AMQPLAIN'\]\}/)
end
end
describe 'config_kernel_variables options' do
let(:params) {{ :config_kernel_variables => {
'inet_dist_listen_min' => 9100,
'inet_dist_listen_max' => 9105,
}}}
it 'should set config variables' do
should contain_file('rabbitmq.config') \
.with_content(/\{inet_dist_listen_min, 9100\}/) \
.with_content(/\{inet_dist_listen_max, 9105\}/)
end
end
describe 'tcp_keepalive enabled' do
let(:params) {{ :tcp_keepalive => true }}
it 'should set tcp_listen_options keepalive true' do
should contain_file('rabbitmq.config') \
.with_content(/\{tcp_listen_options, \[\{keepalive, true\}\]\},/)
end
end
describe 'tcp_keepalive disabled (default)' do
it 'should not set tcp_listen_options' do
should contain_file('rabbitmq.config') \
.without_content(/\{tcp_listen_options, \[\{keepalive, true\}\]\},/)
end
end
describe 'non-bool tcp_keepalive parameter' do
let :params do
{ :tcp_keepalive => 'string' }
end
it 'should raise an error' do
expect {
should contain_file('rabbitmq.config')
}.to raise_error(Puppet::Error, /is not a boolean/)
end
end
context 'delete_guest_user' do
describe 'should do nothing by default' do
it { should_not contain_rabbitmq_user('guest') }
end
describe 'delete user when delete_guest_user set' do
let(:params) {{ :delete_guest_user => true }}
it 'removes the user' do
should contain_rabbitmq_user('guest').with(
'ensure' => 'absent',
'provider' => 'rabbitmqctl'
)
end
end
end
##
## rabbitmq::service
##
describe 'service with default params' do
it { should contain_service('rabbitmq-server').with(
'ensure' => 'running',
'enable' => 'true',
'hasstatus' => 'true',
'hasrestart' => 'true'
)}
end
describe 'service with ensure stopped' do
let :params do
{ :service_ensure => 'stopped' }
end
it { should contain_service('rabbitmq-server').with(
'ensure' => 'stopped',
'enable' => false
) }
end
describe 'service with ensure neither running neither stopped' do
let :params do
{ :service_ensure => 'foo' }
end
it 'should raise an error' do
expect {
should contain_service('rabbitmq-server').with(
'ensure' => 'stopped' )
}.to raise_error(Puppet::Error, /validate_re\(\): "foo" does not match "\^\(running\|stopped\)\$"/)
end
end
describe 'service with service_manage equal to false' do
let :params do
{ :service_manage => false }
end
it { should_not contain_service('rabbitmq-server') }
end
end
end
##
## rabbitmq::install
##
context "on RHEL" do
let(:facts) {{ :osfamily => 'RedHat' }}
let(:params) {{ :package_source => 'http://www.rabbitmq.com/releases/rabbitmq-server/v3.2.3/rabbitmq-server-3.2.3-1.noarch.rpm' }}
it 'installs the rabbitmq package' do
should contain_package('rabbitmq-server').with(
'ensure' => 'installed',
'name' => 'rabbitmq-server',
'provider' => 'yum',
'source' => 'http://www.rabbitmq.com/releases/rabbitmq-server/v3.2.3/rabbitmq-server-3.2.3-1.noarch.rpm'
)
end
end
context "on Debian" do
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian', :lsbdistcodename => 'precise' }}
it 'installs the rabbitmq package' do
should contain_package('rabbitmq-server').with(
'ensure' => 'installed',
'name' => 'rabbitmq-server',
'provider' => 'apt'
)
end
end
context "on Archlinux" do
let(:facts) {{ :osfamily => 'Archlinux' }}
it 'installs the rabbitmq package' do
should contain_package('rabbitmq-server').with(
'ensure' => 'installed',
'name' => 'rabbitmq')
end
end
describe 'repo management on Debian' do
let(:facts) {{ :osfamily => 'Debian', :lsbdistid => 'Debian' }}
context 'with no pin' do
let(:params) {{ :package_apt_pin => '' }}
describe 'it sets up an apt::source' do
it { should contain_apt__source('rabbitmq').with(
'location' => 'http://www.rabbitmq.com/debian/',
'release' => 'testing',
'repos' => 'main',
'include_src' => false,
'key' => '056E8E56'
) }
end
end
context 'with pin' do
let(:params) {{ :package_apt_pin => '700' }}
describe 'it sets up an apt::source and pin' do
it { should contain_apt__source('rabbitmq').with(
'location' => 'http://www.rabbitmq.com/debian/',
'release' => 'testing',
'repos' => 'main',
'include_src' => false,
'key' => '056E8E56'
) }
it { should contain_apt__pin('rabbitmq').with(
'packages' => 'rabbitmq-server',
'priority' => '700'
) }
end
end
end
['RedHat', 'SuSE'].each do |distro|
describe "repo management on #{distro}" do
describe 'imports the key' do
let(:facts) {{ :osfamily => distro }}
let(:params) {{ :package_gpg_key => 'http://www.rabbitmq.com/rabbitmq-signing-key-public.asc' }}
it { should contain_exec("rpm --import #{params[:package_gpg_key]}").with(
'path' => ['/bin','/usr/bin','/sbin','/usr/sbin']
) }
end
end
end
end

View File

@ -0,0 +1,38 @@
require 'beaker-rspec'
UNSUPPORTED_PLATFORMS = []
unless ENV['RS_PROVISION'] == 'no' or ENV['BEAKER_provision'] == 'no'
if hosts.first.is_pe?
install_pe
else
install_puppet
end
hosts.each do |host|
on hosts, "mkdir -p #{host['distmoduledir']}"
end
end
RSpec.configure do |c|
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Readable test descriptions
c.formatter = :documentation
c.before :suite do
puppet_module_install(:source => proj_root, :module_name => 'rabbitmq')
hosts.each do |host|
shell("/bin/touch #{default['puppetpath']}/hiera.yaml")
shell('puppet module install puppetlabs-stdlib', { :acceptable_exit_codes => [0,1] })
if fact('osfamily') == 'Debian'
shell('puppet module install puppetlabs-apt', { :acceptable_exit_codes => [0,1] })
end
shell('puppet module install nanliu-staging', { :acceptable_exit_codes => [0,1] })
if fact('osfamily') == 'RedHat'
shell('puppet module install garethr-erlang', { :acceptable_exit_codes => [0,1] })
end
end
end
end

View File

@ -0,0 +1,19 @@
require 'spec_helper'
describe 'rabbitmq_erlang_cookie', :type => :fact do
before(:each) { Facter.clear }
it 'works correctly' do
Facter.fact(:osfamily).stubs(:value).returns('RedHat')
File.stubs(:exists?).with('/var/lib/rabbitmq/.erlang.cookie').returns(true)
File.stubs(:read).with('/var/lib/rabbitmq/.erlang.cookie').returns('THISISACOOKIE')
Facter.fact(:rabbitmq_erlang_cookie).value.should == 'THISISACOOKIE'
end
it 'fails if file doesnt exist' do
Facter.fact(:osfamily).stubs(:value).returns('RedHat')
File.stubs(:exists?).with('/var/lib/rabbitmq/.erlang.cookie').returns(false)
Facter.fact(:rabbitmq_erlang_cookie).value.should == nil
end
end

View File

@ -0,0 +1,65 @@
require 'puppet'
require 'mocha'
RSpec.configure do |config|
config.mock_with :mocha
end
provider_class = Puppet::Type.type(:rabbitmq_exchange).provider(:rabbitmqadmin)
describe provider_class do
before :each do
@resource = Puppet::Type::Rabbitmq_exchange.new(
{:name => 'amq.direct@/',
:type => :topic}
)
@provider = provider_class.new(@resource)
end
it 'should return instances' do
provider_class.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT
Listing vhosts ...
/
...done.
EOT
provider_class.expects(:rabbitmqctl).with('list_exchanges', '-p', '/', 'name', 'type').returns <<-EOT
Listing exchanges ...
direct
amq.direct direct
amq.fanout fanout
amq.headers headers
amq.match headers
amq.rabbitmq.log topic
amq.rabbitmq.trace topic
amq.topic topic
...done.
EOT
instances = provider_class.instances
instances.size.should == 8
end
it 'should call rabbitmqadmin to create' do
@provider.expects(:rabbitmqadmin).with('declare', 'exchange', '--vhost=/', '--user=guest', '--password=guest', 'name=amq.direct', 'type=topic')
@provider.create
end
it 'should call rabbitmqadmin to destroy' do
@provider.expects(:rabbitmqadmin).with('delete', 'exchange', '--vhost=/', '--user=guest', '--password=guest', 'name=amq.direct')
@provider.destroy
end
context 'specifying credentials' do
before :each do
@resource = Puppet::Type::Rabbitmq_exchange.new(
{:name => 'amq.direct@/',
:type => :topic,
:user => 'colin',
:password => 'secret',
}
)
@provider = provider_class.new(@resource)
end
it 'should call rabbitmqadmin to create' do
@provider.expects(:rabbitmqadmin).with('declare', 'exchange', '--vhost=/', '--user=colin', '--password=secret', 'name=amq.direct', 'type=topic')
@provider.create
end
end
end

View File

@ -58,11 +58,19 @@ EOT
@provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
@provider.create
end
it 'shoud create user, set password and set to admin' do
it 'should create user, set password and set to admin' do
@resource[:password] = 'bar'
@resource[:admin] = 'true'
@provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', 'administrator')
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
foo []
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator'])
@provider.create
end
it 'should call rabbitmqctl to delete' do
@ -93,11 +101,136 @@ EOT
expect { @provider.admin }.to raise_error(Puppet::Error, /Could not match line/)
end
it 'should be able to set admin value' do
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', 'administrator')
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
foo []
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['administrator'])
@provider.admin=:true
end
it 'should not interfere with existing tags on the user when setting admin value' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
foo [bar, baz]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['bar','baz', 'administrator'].sort)
@provider.admin=:true
end
it 'should be able to unset admin value' do
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo')
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
foo [administrator]
guest [administrator]
icinga []
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', [])
@provider.admin=:false
end
it 'should not interfere with existing tags on the user when unsetting admin value' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
foo [administrator, bar, baz]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['bar','baz'].sort)
@provider.admin=:false
end
it 'should clear all tags on existing user' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
one [administrator]
foo [tag1,tag2]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', [])
@provider.tags=[]
end
it 'should set multiple tags' do
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
one [administrator]
foo []
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ['tag1','tag2'])
@provider.tags=['tag1','tag2']
end
it 'should clear tags while keep admin tag' do
@resource[:admin] = true
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
one [administrator]
foo [administrator, tag1, tag2]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator"])
@provider.tags=[]
end
it 'should change tags while keep admin tag' do
@resource[:admin] = true
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
one [administrator]
foo [administrator, tag1, tag2]
icinga [monitoring]
kitchen []
kitchen2 [abc, def, ghi]
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator","tag1","tag3","tag7"])
@provider.tags=['tag1','tag7','tag3']
end
it 'should create user with tags and without admin' do
@resource[:tags] = [ "tag1", "tag2" ]
@provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["tag1","tag2"])
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
Listing users ...
foo []
...done.
EOT
@provider.create
end
it 'should create user with tags and with admin' do
@resource[:tags] = [ "tag1", "tag2" ]
@resource[:admin] = true
@provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
@provider.expects(:rabbitmqctl).with('list_users').twice.returns <<-EOT
Listing users ...
foo []
...done.
EOT
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator"])
@provider.expects(:rabbitmqctl).with('set_user_tags', 'foo', ["administrator","tag1","tag2"])
@provider.create
end
end

View File

@ -20,7 +20,15 @@ Listing users ...
bar 1 2 3
...done.
EOT
@provider.exists?.should == {:configure=>"1", :write=>"3", :read=>"2"}
@provider.exists?.should == {:configure=>"1", :write=>"2", :read=>"3"}
end
it 'should match user permissions with empty columns' do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
bar 3
...done.
EOT
@provider.exists?.should == {:configure=>"", :write=>"", :read=>"3"}
end
it 'should not match user permissions with more than 3 columns' do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
@ -49,7 +57,7 @@ EOT
@provider.expects(:rabbitmqctl).with('clear_permissions', '-p', 'bar', 'foo')
@provider.destroy
end
{:configure_permission => '1', :write_permission => '3', :read_permission => '2'}.each do |k,v|
{:configure_permission => '1', :write_permission => '2', :read_permission => '3'}.each do |k,v|
it "should be able to retrieve #{k}" do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
@ -59,7 +67,7 @@ EOT
@provider.send(k).should == v
end
end
{:configure_permission => '1', :write_permission => '3', :read_permission => '2'}.each do |k,v|
{:configure_permission => '1', :write_permission => '2', :read_permission => '3'}.each do |k,v|
it "should be able to retrieve #{k} after exists has been called" do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
Listing users ...
@ -71,8 +79,8 @@ EOT
end
end
{:configure_permission => ['foo', '2', '3'],
:read_permission => ['1', 'foo', '3'],
:write_permission => ['1', '2', 'foo']
:read_permission => ['1', '2', 'foo'],
:write_permission => ['1', 'foo', '3']
}.each do |perm, columns|
it "should be able to sync #{perm}" do
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
@ -93,8 +101,9 @@ bar 1 2 3
EOT
@provider.resource[:configure_permission] = 'foo'
@provider.resource[:read_permission] = 'foo'
@provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', 'foo', 'foo', '3').once
@provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', 'foo', '2', 'foo').once
@provider.configure_permission='foo'
@provider.read_permission='foo'
end
end

View File

@ -0,0 +1,54 @@
require 'puppet'
require 'puppet/type/rabbitmq_exchange'
describe Puppet::Type.type(:rabbitmq_exchange) do
before :each do
@exchange = Puppet::Type.type(:rabbitmq_exchange).new(
:name => 'foo@bar',
:type => :topic
)
end
it 'should accept an exchange name' do
@exchange[:name] = 'dan@pl'
@exchange[:name].should == 'dan@pl'
end
it 'should require a name' do
expect {
Puppet::Type.type(:rabbitmq_exchange).new({})
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end
it 'should not allow whitespace in the name' do
expect {
@exchange[:name] = 'b r'
}.to raise_error(Puppet::Error, /Valid values match/)
end
it 'should not allow names without @' do
expect {
@exchange[:name] = 'b_r'
}.to raise_error(Puppet::Error, /Valid values match/)
end
it 'should accept an exchange type' do
@exchange[:type] = :direct
@exchange[:type].should == :direct
end
it 'should require a type' do
expect {
Puppet::Type.type(:rabbitmq_exchange).new(:name => 'foo@bar')
}.to raise_error(/.*must set type when creating exchange.*/)
end
it 'should not require a type when destroying' do
expect {
Puppet::Type.type(:rabbitmq_exchange).new(:name => 'foo@bar', :ensure => :absent)
}.to_not raise_error
end
it 'should accept a user' do
@exchange[:user] = :root
@exchange[:user].should == :root
end
it 'should accept a password' do
@exchange[:password] = :PaSsw0rD
@exchange[:password].should == :PaSsw0rD
end
end

View File

@ -26,6 +26,10 @@ describe Puppet::Type.type(:rabbitmq_user_permissions) do
@perms[param] = '.*?'
@perms[param].should == '.*?'
end
it "should accept an empty string for #{param}" do
@perms[param] = ''
@perms[param].should == ''
end
it "should not accept invalid regex for #{param}" do
expect {
@perms[param] = '*'

View File

@ -14,10 +14,9 @@ describe Puppet::Type.type(:rabbitmq_user) do
@user[:password].should == 'foo'
end
it 'should require a password' do
# TODO: change ArgumentError -> Puppet::ResourceError when when puppet >= 3.0
expect {
Puppet::Type.type(:rabbitmq_user).new(:name => 'foo')
}.to raise_error(ArgumentError, /must set password/)
}.to raise_error(/must set password/)
end
it 'should require a name' do
expect {

View File

@ -1 +1,5 @@
SERVER_ERL_ARGS="+K true +A30 +P 1048576"
<%- @environment_variables.keys.sort.each do |key| -%>
<%- if @environment_variables[key] != 'UNSET' -%>
<%= key %>=<%= @environment_variables[key] %>
<%- end -%>
<%- end -%>

View File

@ -1,272 +0,0 @@
#!/bin/sh
#
# rabbitmq-server RabbitMQ broker
#
# chkconfig: - 80 05
# description: Enable AMQP service provided by RabbitMQ
#
### BEGIN INIT INFO
# Provides: rabbitmq-server
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Description: RabbitMQ broker
# Short-Description: Enable AMQP service provided by RabbitMQ broker
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME=rabbitmq-server
DAEMON=/usr/sbin/${NAME}
CONTROL=/usr/sbin/rabbitmqctl
DESC=rabbitmq-server
USER=rabbitmq
ROTATE_SUFFIX=
INIT_LOG_DIR=/var/log/rabbitmq
PID_FILE=/var/run/rabbitmq/pid
START_PROG="runuser rabbitmq --session-command"
LOCK_FILE=/var/lock/subsys/$NAME
<% if @node_ip_address != 'UNSET' -%>
export RABBITMQ_NODE_IP_ADDRESS="<%= @node_ip_address %>"
<% end -%>
export RABBITMQ_NODE_PORT="<%= @port %>"
test -x $DAEMON || exit 0
test -x $CONTROL || exit 0
RETVAL=0
set -e
[ -f /etc/default/${NAME} ] && . /etc/default/${NAME}
ensure_pid_dir () {
PID_DIR=`dirname ${PID_FILE}`
if [ ! -d ${PID_DIR} ] ; then
mkdir -p ${PID_DIR}
chown -R ${USER}:${USER} ${PID_DIR}
chmod 755 ${PID_DIR}
fi
}
remove_pid () {
rm -f ${PID_FILE}
rmdir `dirname ${PID_FILE}` || :
}
set_nova_rabbit_credentials () {
local NOVA_CONFIG_FILE=/etc/nova/nova.conf
#These variables must be empty in the beginning
local NEW_RABBIT_USER=
local NEW_RABBIT_PASSWORD=
local RABBIT_VIRTUAL_HOST=
if [ -f ${NOVA_CONFIG_FILE} ] ; then
NEW_RABBIT_USER=$(grep -v '^#' $NOVA_CONFIG_FILE \
| grep rabbit_userid \
| awk -F "=" '{print $2}')
NEW_RABBIT_PASSWORD=$(grep -v '^#' $NOVA_CONFIG_FILE \
| grep rabbit_password \
| awk -F "=" '{print $2}')
RABBIT_VIRTUAL_HOST=$(grep -v '^#' $NOVA_CONFIG_FILE \
| grep rabbit_virtual_host \
| awk -F "=" '{print $2}')
fi
if [ "x" != "x${NEW_RABBIT_USER}" ] && [ "x" != "x${NEW_RABBIT_PASSWORD}" ]; then
printf '%s\n' "Restoring Nova user credentials..."
set +e
$CONTROL add_user $NEW_RABBIT_USER $NEW_RABBIT_PASSWORD
$CONTROL set_user_tags $NEW_RABBIT_USER administrator
if [ "x" != "x${RABBIT_VIRTUAL_HOST}" ] ; then
RABBIT_VIRTUAL_HOST=/
fi
if [ ${RABBIT_VIRTUAL_HOST} != '/' ] ; then
$CONTROL add_vhost $RABBIT_VIRTUAL_HOST
fi
$CONTROL set_permissions -p $RABBIT_VIRTUAL_HOST \
$NEW_RABBIT_USER '.*' '.*' '.*'
$CONTROL delete_user guest
set -e
printf '%s\n' "Done restoring user credentials."
fi
}
move_out_rabbit_database_to_backup () {
local RABBIT_DEFAULTS_FILE=/usr/lib/rabbitmq/bin/rabbitmq-defaults
local RABBIT_CONFIG_FILE=/etc/rabbitmq/rabbitmq-env.conf
local DATE=$(date +"%Y-%m-%d_%H-%M-%S")
local C_DIR=$(pwd)
[ -f ${RABBIT_DEFAULTS_FILE} ] && . ${RABBIT_DEFAULTS_FILE}
[ -f ${RABBIT_CONFIG_FILE} ] && . ${RABBIT_CONFIG_FILE}
if [ -d ${MNESIA_BASE} ] ; then
cd ${MNESIA_BASE}/..
local BACKUPS_DIR=`dirname ${MNESIA_BASE}`/backups
if [ ! -d ${BACKUPS_DIR} ] ; then
mkdir -p ${BACKUPS_DIR}
chown -R ${USER}:${USER} ${BACKUPS_DIR}
chmod 755 ${BACKUPS_DIR}
fi
printf '%s\n' " "
printf '%s\n' "Backing up mnesia base in: ${MNESIA_BASE}"
mv `basename ${MNESIA_BASE}` \
${BACKUPS_DIR}/`basename ${MNESIA_BASE}`_${DATE}
printf '%s\n' "Old Mnesia base has moved to " \
${BACKUPS_DIR}/`basename ${MNESIA_BASE}`_${DATE}
cd ${C_DIR}
fi
}
start_rabbitmq () {
status_rabbitmq quiet
if [ $RETVAL = 0 ] ; then
echo RabbitMQ is currently running
else
#Slave nodes fail to start until master is not up and running
#So, give slaves several attempts to start
#Rabbit database will be moved out before last attempt.
local MAX_START_ATTEMPTS=3
printf '%s\n' "RabbitMQ is going to make ${MAX_START_ATTEMPTS} \
attempts to find master node and start."
while test $MAX_START_ATTEMPTS -ne 0
do
RETVAL=0
ensure_pid_dir
printf '%s\n' "${MAX_START_ATTEMPTS} attempts left to start \
RabbitMQ Server before consider start failed."
if [ $MAX_START_ATTEMPTS = 1 ] ; then
move_out_rabbit_database_to_backup
fi
set +e
RABBITMQ_PID_FILE=$PID_FILE $START_PROG $DAEMON \
> "${INIT_LOG_DIR}/startup_log" \
2> "${INIT_LOG_DIR}/startup_err" \
0<&- &
$CONTROL wait $PID_FILE >/dev/null 2>&1
RETVAL=$?
set -e
case "$RETVAL" in
0)
echo SUCCESS
if [ -n "$LOCK_FILE" ] ; then
touch $LOCK_FILE
fi
if [ $MAX_START_ATTEMPTS = 1 ] ; then
set_nova_rabbit_credentials
RETVAL=0
fi
break
;;
*)
remove_pid
if [ $MAX_START_ATTEMPTS = 1 ] ; then
echo FAILED - check ${INIT_LOG_DIR}/startup_\{log, _err\}
fi
RETVAL=1
;;
esac
MAX_START_ATTEMPTS=$((MAX_START_ATTEMPTS - 1))
done
rabbitmqctl set_policy ha-all "." '{"ha-mode":"all", "ha-sync-mode":"automatic"}'
fi
}
stop_rabbitmq () {
status_rabbitmq quiet
if [ $RETVAL = 0 ] ; then
set +e
$CONTROL stop ${PID_FILE} > ${INIT_LOG_DIR}/shutdown_log 2> ${INIT_LOG_DIR}/shutdown_err
RETVAL=$?
set -e
if [ $RETVAL = 0 ] ; then
remove_pid
if [ -n "$LOCK_FILE" ] ; then
rm -f $LOCK_FILE
fi
else
echo FAILED - check ${INIT_LOG_DIR}/shutdown_log, _err
fi
else
echo RabbitMQ is not running
RETVAL=0
fi
}
status_rabbitmq() {
set +e
if [ "$1" != "quiet" ] ; then
$CONTROL status 2>&1
else
$CONTROL status > /dev/null 2>&1
fi
if [ $? != 0 ] ; then
RETVAL=3
fi
set -e
}
rotate_logs_rabbitmq() {
set +e
$CONTROL rotate_logs ${ROTATE_SUFFIX}
if [ $? != 0 ] ; then
RETVAL=1
fi
set -e
}
restart_running_rabbitmq () {
status_rabbitmq quiet
if [ $RETVAL = 0 ] ; then
restart_rabbitmq
else
echo RabbitMQ is not runnning
RETVAL=0
fi
}
restart_rabbitmq() {
stop_rabbitmq
start_rabbitmq
}
case "$1" in
start)
echo -n "Starting $DESC: "
start_rabbitmq
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
stop_rabbitmq
echo "$NAME."
;;
status)
status_rabbitmq
;;
rotate-logs)
echo -n "Rotating log files for $DESC: "
rotate_logs_rabbitmq
;;
force-reload|reload|restart)
echo -n "Restarting $DESC: "
restart_rabbitmq
echo "$NAME."
;;
try-restart)
echo -n "Restarting $DESC: "
restart_running_rabbitmq
echo "$NAME."
;;
*)
echo "Usage: $0 {start|stop|status|rotate-logs|restart|condrestart|try-restart|reload|force-reload}" >&2
RETVAL=1
;;
esac
exit $RETVAL

View File

@ -1,282 +0,0 @@
#!/bin/sh
#
# rabbitmq-server RabbitMQ broker
#
# chkconfig: - 80 05
# description: Enable AMQP service provided by RabbitMQ
#
### BEGIN INIT INFO
# Provides: rabbitmq-server
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: RabbitMQ broker
# Short-Description: Enable AMQP service provided by RabbitMQ broker
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
NAME=rabbitmq-server
DAEMON=/usr/sbin/${NAME}
CONTROL=/usr/sbin/rabbitmqctl
DESC="message broker"
USER=rabbitmq
ROTATE_SUFFIX=
INIT_LOG_DIR=/var/log/rabbitmq
PID_FILE=/var/run/rabbitmq/pid
<% if node_ip_address != 'UNSET' -%>
export RABBITMQ_NODE_IP_ADDRESS="<%= node_ip_address %>"
<% end -%>
export RABBITMQ_NODE_PORT="<%= port %>"
test -x $DAEMON || exit 0
test -x $CONTROL || exit 0
RETVAL=0
set -e
[ -f /etc/default/${NAME} ] && . /etc/default/${NAME}
. /lib/lsb/init-functions
. /lib/init/vars.sh
ensure_pid_dir () {
PID_DIR=`dirname ${PID_FILE}`
if [ ! -d ${PID_DIR} ] ; then
mkdir -p ${PID_DIR}
chown -R ${USER}:${USER} ${PID_DIR}
chmod 755 ${PID_DIR}
fi
}
remove_pid () {
rm -f ${PID_FILE}
rmdir `dirname ${PID_FILE}` || :
}
set_nova_rabbit_credentials () {
local NOVA_CONFIG_FILE=/etc/nova/nova.conf
#These variables must be empty in the beginning
local NEW_RABBIT_USER=
local NEW_RABBIT_PASSWORD=
local RABBIT_VIRTUAL_HOST=
if [ -f ${NOVA_CONFIG_FILE} ] ; then
NEW_RABBIT_USER=$(grep -v '^#' $NOVA_CONFIG_FILE \
| grep rabbit_userid \
| awk -F "=" '{print $2}')
NEW_RABBIT_PASSWORD=$(grep -v '^#' $NOVA_CONFIG_FILE \
| grep rabbit_password \
| awk -F "=" '{print $2}')
RABBIT_VIRTUAL_HOST=$(grep -v '^#' $NOVA_CONFIG_FILE \
| grep rabbit_virtual_host \
| awk -F "=" '{print $2}')
fi
if [ "x" != "x${NEW_RABBIT_USER}" ] && [ "x" != "x${NEW_RABBIT_PASSWORD}" ]; then
printf '%s\n' "Restoring Nova user credentials..."
set +e
$CONTROL add_user $NEW_RABBIT_USER $NEW_RABBIT_PASSWORD
$CONTROL set_user_tags $NEW_RABBIT_USER administrator
if [ "x" != "x${RABBIT_VIRTUAL_HOST}" ] ; then
RABBIT_VIRTUAL_HOST=/
fi
if [ ${RABBIT_VIRTUAL_HOST} != '/' ] ; then
$CONTROL add_vhost $RABBIT_VIRTUAL_HOST
fi
$CONTROL set_permissions -p $RABBIT_VIRTUAL_HOST \
$NEW_RABBIT_USER '.*' '.*' '.*'
$CONTROL delete_user guest
set -e
printf '%s\n' "Done restoring user credentials."
fi
}
move_out_rabbit_database_to_backup () {
local RABBIT_DEFAULTS_FILE=/usr/lib/rabbitmq/bin/rabbitmq-defaults
local RABBIT_CONFIG_FILE=/etc/rabbitmq/rabbitmq-env.conf
local DATE=$(date +"%Y-%m-%d_%H-%M-%S")
local C_DIR=$(pwd)
[ -f ${RABBIT_DEFAULTS_FILE} ] && . ${RABBIT_DEFAULTS_FILE}
[ -f ${RABBIT_CONFIG_FILE} ] && . ${RABBIT_CONFIG_FILE}
if [ -d ${MNESIA_BASE} ] ; then
cd ${MNESIA_BASE}/..
local BACKUPS_DIR=`dirname ${MNESIA_BASE}`/backups
if [ ! -d ${BACKUPS_DIR} ] ; then
mkdir -p ${BACKUPS_DIR}
chown -R ${USER}:${USER} ${BACKUPS_DIR}
chmod 755 ${BACKUPS_DIR}
fi
printf '%s\n' " "
printf '%s\n' "Backing up mnesia base in: ${MNESIA_BASE}"
mv `basename ${MNESIA_BASE}` \
${BACKUPS_DIR}/`basename ${MNESIA_BASE}`_${DATE}
printf '%s\n' "Old Mnesia base has moved to " \
${BACKUPS_DIR}/`basename ${MNESIA_BASE}`_${DATE}
cd ${C_DIR}
fi
}
start_rabbitmq () {
status_rabbitmq quiet
if [ $RETVAL != 0 ] ; then
#Slave nodes fail to start until master is not up and running
#So, give slaves several attempts to start
#Rabbit database will be moved out before last attempt.
local MAX_START_ATTEMPTS=3
printf '%s\n' "RabbitMQ is going to make ${MAX_START_ATTEMPTS} \
attempts to find master node and start."
while test $MAX_START_ATTEMPTS -ne 0
do
RETVAL=0
ensure_pid_dir
printf '%s\n' "${MAX_START_ATTEMPTS} attempts left to start \
RabbitMQ Server before consider start failed."
if [ $MAX_START_ATTEMPTS = 1 ] ; then
move_out_rabbit_database_to_backup
fi
set +e
RABBITMQ_PID_FILE=$PID_FILE start-stop-daemon --quiet \
--chuid rabbitmq --start --exec $DAEMON \
--pidfile "$RABBITMQ_PID_FILE" --background
$CONTROL wait $PID_FILE >/dev/null 2>&1
RETVAL=$?
set -e
if [ $RETVAL != 0 ] ; then
remove_pid
else
if [ $MAX_START_ATTEMPTS = 1 ] ; then
set_nova_rabbit_credentials
RETVAL=0
fi
break
fi
MAX_START_ATTEMPTS=$((MAX_START_ATTEMPTS - 1))
done
rabbitmqctl set_policy ha-all "." '{"ha-mode":"all", "ha-sync-mode":"automatic"}'
else
RETVAL=3
fi
}
stop_rabbitmq () {
status_rabbitmq quiet
if [ $RETVAL = 0 ] ; then
set +e
$CONTROL stop ${PID_FILE} > ${INIT_LOG_DIR}/shutdown_log 2> ${INIT_LOG_DIR}/shutdown_err
RETVAL=$?
set -e
if [ $RETVAL = 0 ] ; then
remove_pid
fi
else
RETVAL=3
fi
}
status_rabbitmq() {
set +e
if [ "$1" != "quiet" ] ; then
$CONTROL status 2>&1
else
$CONTROL status > /dev/null 2>&1
fi
if [ $? != 0 ] ; then
RETVAL=3
fi
set -e
}
rotate_logs_rabbitmq() {
set +e
$CONTROL -q rotate_logs ${ROTATE_SUFFIX}
if [ $? != 0 ] ; then
RETVAL=1
fi
set -e
}
restart_running_rabbitmq () {
status_rabbitmq quiet
if [ $RETVAL = 0 ] ; then
restart_rabbitmq
else
log_warning_msg "${DESC} not running"
fi
}
restart_rabbitmq() {
stop_rabbitmq
start_rabbitmq
}
restart_end() {
if [ $RETVAL = 0 ] ; then
log_end_msg 0
else
log_end_msg 1
fi
}
start_stop_end() {
case "$RETVAL" in
0)
[ -x /sbin/initctl ] && /sbin/initctl emit --no-wait "${NAME}-${1}"
log_end_msg 0
;;
3)
log_warning_msg "${DESC} already ${1}"
log_end_msg 0
RETVAL=0
;;
*)
log_warning_msg "FAILED - check ${INIT_LOG_DIR}/startup_\{log, _err\}"
log_end_msg 1
;;
esac
}
case "$1" in
start)
log_daemon_msg "Starting ${DESC}" $NAME
start_rabbitmq
start_stop_end "running"
;;
stop)
log_daemon_msg "Stopping ${DESC}" $NAME
stop_rabbitmq
start_stop_end "stopped"
;;
status)
status_rabbitmq
;;
rotate-logs)
log_action_begin_msg "Rotating log files for ${DESC} ${NAME}"
rotate_logs_rabbitmq
log_action_end_msg $RETVAL
;;
force-reload|reload|restart)
log_daemon_msg "Restarting ${DESC}" $NAME
restart_rabbitmq
restart_end
;;
try-restart)
log_daemon_msg "Restarting ${DESC}" $NAME
restart_running_rabbitmq
restart_end
;;
*)
echo "Usage: $0 {start|stop|status|rotate-logs|restart|condrestart|try-restart|reload|force-reload}" >&2
RETVAL=1
;;
esac
exit $RETVAL

View File

@ -1,32 +0,0 @@
% This file managed by Puppet <%= @puppetversion %>
% Template Path: <%= @module_name %>/templates/rabbitmq.config
[
{kernel, [
{inet_dist_listen_min, <%= @inet_dist_listen_min %>},
{inet_dist_listen_max, <%= @inet_dist_listen_max %>},
{inet_default_connect_options, [{nodelay,true}]}
]},
{rabbit, [
{log_levels, [connection,debug,info,error]},
{default_vhost, <<"<%= @virtual_host %>">>},
{default_user, <<"<%= @userid %>">>},
{default_pass, <<"<%= @password %>">>},
{default_permissions, [<<".*">>, <<".*">>, <<".*">>]},
{cluster_partition_handling, autoheal},
{tcp_listen_options, [
binary,
{packet, raw},
{reuseaddr, true},
{backlog, 128},
{nodelay, true},
{exit_on_close, false},
{keepalive, true}
]}
]}
<% if @config_stomp -%>
,{rabbitmq_stomp, [
{tcp_listeners, [<%= @stomp_port %>]}
]}
<% end -%>
].
% EOF

View File

@ -0,0 +1,74 @@
% This file managed by Puppet
% Template Path: <%= @module_name %>/templates/rabbitmq.config
[
{rabbit, [
<% if @ldap_auth -%>
{auth_backends, [rabbit_auth_backend_internal, rabbit_auth_backend_ldap]},
<% end -%>
<% if @config_cluster -%>
{cluster_nodes, {[<%= @r_cluster_nodes.map { |n| "\'rabbit@#{n}\'" }.join(', ') %>], <%= @cluster_node_type %>}},
{cluster_partition_handling, <%= @cluster_partition_handling %>},
<% end -%>
<%- if @tcp_keepalive -%>
{tcp_listen_options, [{keepalive, true}]},
<%- end -%>
<%- if @ssl_only -%>
{tcp_listeners, []},
<%- end -%>
<%- if @ssl -%>
{ssl_listeners, [<%= @ssl_port %>]},
{ssl_options, [{cacertfile,"<%= @ssl_cacert %>"},
{certfile,"<%= @ssl_cert %>"},
{keyfile,"<%= @ssl_key %>"},
{verify,<%= @ssl_verify %>},
{fail_if_no_peer_cert,<%= @ssl_fail_if_no_peer_cert %>}]},
<%- end -%>
<% if @config_variables -%>
<%- @config_variables.keys.sort.each do |key| -%>
{<%= key %>, <%= @config_variables[key] %>},
<%- end -%>
<%- end -%>
{default_user, <<"<%= @default_user %>">>},
{default_pass, <<"<%= @default_pass %>">>}
]}<% if @config_kernel_variables -%>,
{kernel, [
<%= @config_kernel_variables.sort.map{|k,v| "{#{k}, #{v}}"}.join(",\n ") %>
]}
<%- end -%>
<%- if @admin_enable -%>,
{rabbitmq_management, [
{listener, [
<%- if @ssl -%>
{port, <%= @ssl_management_port %>},
{ssl, true},
{ssl_opts, [{cacertfile, "<%= @ssl_cacert %>"},
{certfile, "<%= @ssl_cert %>"},
{keyfile, "<%= @ssl_key %>"}]}
<%- else -%>
{port, <%= @management_port %>}
<%- end -%>
]}
]}
<%- end -%>
<% if @config_stomp -%>,
% Configure the Stomp Plugin listening port
{rabbitmq_stomp, [
{tcp_listeners, [<%= @stomp_port %>]}
<%- if @ssl && @ssl_stomp_port -%>,
{ssl_listeners, [<%= @ssl_stomp_port %>]}
<%- end -%>
]}
<% end -%>
<%- if @ldap_auth -%>,
% Configure the LDAP authentication plugin
{rabbitmq_auth_backend_ldap, [
{other_bind, anon},
{servers, ["<%= @ldap_server %>"]},
{user_dn_pattern, "<%= @ldap_user_dn_pattern %>"},
{use_ssl, <%= @ldap_use_ssl %>},
{port, <%= @ldap_port %>},
{log, <%= @ldap_log %>}
]}
<%- end -%>
].
% EOF

View File

@ -0,0 +1,5 @@
# install first the garethr-erlang module. See README.md
include 'erlang'
class { 'erlang': epel_enable => true}
Class['erlang'] -> Class['rabbitmq']

View File

@ -1,5 +1,5 @@
class { 'rabbitmq::server':
port => '5672',
delete_guest_user => true,
version => 'installed',
version => 'latest',
}

View File

@ -1,4 +1,4 @@
rabbitmq_user { ['blah2', 'blah3', 'blah4']:
password => 'phoey!',
# provider => 'rabbitmqctl',
#provider => 'rabbitmqctl',
}