mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
Update directory structure & allow to configure paths (tmp, log, cache)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
Specs
|
||||
=====
|
||||
|
||||
The Puppet project uses RSpec for testing.
|
||||
|
||||
For more information on RSpec, see http://rspec.info/
|
||||
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -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
|
@@ -0,0 +1,46 @@
|
||||
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
|
||||
end
|
@@ -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
|
@@ -0,0 +1,531 @@
|
||||
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
|
||||
let(:facts) {{ :osfamily => 'Debian' }}
|
||||
it 'should add a repo with defaults values' do
|
||||
contain_file('/etc/apt/sources.list.d/rabbitmq.list')\
|
||||
.with_content(%r|deb http\://www\.rabbitmq.com/debian/ testing main|)
|
||||
end
|
||||
end
|
||||
|
||||
describe 'apt::source custom values' do
|
||||
let(:params) {
|
||||
{ :location => 'http://www.foorepo.com/debian',
|
||||
:release => 'unstable',
|
||||
:repos => 'main'
|
||||
}}
|
||||
it 'should add a repo with custom new values' do
|
||||
contain_file('/etc/apt/sources.list.d/rabbitmq.list')\
|
||||
.with_content(%r|deb http\://www\.foorepo.com/debian/ unstable 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]'
|
||||
)
|
||||
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
|
||||
contain_file('rabbitmq-env.config').with({
|
||||
'content' => '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
|
||||
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
|
||||
contain_file('rabbitmq.config').with({
|
||||
'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\]/,
|
||||
})
|
||||
end
|
||||
end
|
||||
describe 'stomp when set with ssl' do
|
||||
let(:params) {{ :config_stomp => true, :stomp_port => 5679, :ssl_stomp_port => 5680 }}
|
||||
it 'should specify stomp port and ssl stomp port in rabbitmq.config' do
|
||||
contain_file('rabbitmq.config').with({
|
||||
'content' => /rabbitmq_stomp.*tcp_listeners, \[5679\].*ssl_listeners, \[5680\]/,
|
||||
})
|
||||
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
|
||||
contain_file('rabbitmq.config').with({
|
||||
'content' => /default_user, <<"foo">>.*default_pass, <<"bar">>/,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ssl 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'
|
||||
} }
|
||||
|
||||
it 'should set ssl options to specified values' do
|
||||
contain_file('rabbitmq.config').with({
|
||||
'content' => %r|ssl_listeners, \[3141\].*
|
||||
ssl_options, \[{cacertfile,"/path/to/cacert".*
|
||||
certfile="/path/to/cert".*
|
||||
keyfile,"/path/to/key|,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ssl options with ssl_only' do
|
||||
let(:params) {
|
||||
{ :ssl => true,
|
||||
:ssl_only => true,
|
||||
:ssl_management_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
|
||||
contain_file('rabbitmq.config').with({
|
||||
'content' => %r|tcp_listeners, \[\].*
|
||||
ssl_listeners, \[3141\].*
|
||||
ssl_options, \[{cacertfile,"/path/to/cacert".*
|
||||
certfile="/path/to/cert".*
|
||||
keyfile,"/path/to/key|,
|
||||
})
|
||||
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
|
||||
|
||||
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
|
6
resources/vagrant/vms/phraseanet-php54-nginx/puphpet/puppet/modules/rabbitmq/spec/spec.opts
vendored
Normal file
6
resources/vagrant/vms/phraseanet-php54-nginx/puphpet/puppet/modules/rabbitmq/spec/spec.opts
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
@@ -0,0 +1 @@
|
||||
require 'puppetlabs_spec_helper/module_spec_helper'
|
@@ -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
|
||||
|
@@ -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
|
@@ -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
|
@@ -0,0 +1,236 @@
|
||||
require 'puppet'
|
||||
require 'mocha'
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
||||
provider_class = Puppet::Type.type(:rabbitmq_user).provider(:rabbitmqctl)
|
||||
describe provider_class do
|
||||
before :each do
|
||||
@resource = Puppet::Type::Rabbitmq_user.new(
|
||||
{:name => 'foo', :password => 'bar'}
|
||||
)
|
||||
@provider = provider_class.new(@resource)
|
||||
end
|
||||
it 'should match user names' do
|
||||
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
|
||||
Listing users ...
|
||||
foo
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?.should == 'foo'
|
||||
end
|
||||
it 'should match user names with 2.4.1 syntax' do
|
||||
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
|
||||
Listing users ...
|
||||
foo bar
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?.should == 'foo bar'
|
||||
end
|
||||
it 'should not match if no users on system' do
|
||||
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
|
||||
Listing users ...
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?.should be_nil
|
||||
end
|
||||
it 'should not match if no matching users on system' do
|
||||
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
|
||||
Listing users ...
|
||||
fooey
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?.should be_nil
|
||||
end
|
||||
it 'should match user names from list' do
|
||||
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
|
||||
Listing users ...
|
||||
one
|
||||
two three
|
||||
foo
|
||||
bar
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?.should == 'foo'
|
||||
end
|
||||
it 'should create user and set password' do
|
||||
@resource[:password] = 'bar'
|
||||
@provider.expects(:rabbitmqctl).with('add_user', 'foo', 'bar')
|
||||
@provider.create
|
||||
end
|
||||
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('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
|
||||
@provider.expects(:rabbitmqctl).with('delete_user', 'foo')
|
||||
@provider.destroy
|
||||
end
|
||||
it 'should be able to retrieve admin value' do
|
||||
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
|
||||
Listing users ...
|
||||
foo [administrator]
|
||||
...done.
|
||||
EOT
|
||||
@provider.admin.should == :true
|
||||
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
|
||||
Listing users ...
|
||||
one [administrator]
|
||||
foo []
|
||||
...done.
|
||||
EOT
|
||||
@provider.admin.should == :false
|
||||
end
|
||||
it 'should fail if admin value is invalid' do
|
||||
@provider.expects(:rabbitmqctl).with('list_users').returns <<-EOT
|
||||
Listing users ...
|
||||
foo fail
|
||||
...done.
|
||||
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('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('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
|
@@ -0,0 +1,109 @@
|
||||
require 'puppet'
|
||||
require 'mocha'
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
||||
describe 'Puppet::Type.type(:rabbitmq_user_permissions).provider(:rabbitmqctl)' do
|
||||
before :each do
|
||||
@provider_class = Puppet::Type.type(:rabbitmq_user_permissions).provider(:rabbitmqctl)
|
||||
@resource = Puppet::Type::Rabbitmq_user_permissions.new(
|
||||
{:name => 'foo@bar'}
|
||||
)
|
||||
@provider = @provider_class.new(@resource)
|
||||
end
|
||||
after :each do
|
||||
@provider_class.instance_variable_set(:@users, nil)
|
||||
end
|
||||
it 'should match user permissions from list' do
|
||||
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
|
||||
Listing users ...
|
||||
bar 1 2 3
|
||||
...done.
|
||||
EOT
|
||||
@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
|
||||
Listing users ...
|
||||
bar 1 2 3 4
|
||||
...done.
|
||||
EOT
|
||||
expect { @provider.exists? }.to raise_error(Puppet::Error, /cannot parse line from list_user_permissions/)
|
||||
end
|
||||
it 'should not match an empty list' do
|
||||
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
|
||||
Listing users ...
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?.should == nil
|
||||
end
|
||||
it 'should create default permissions' do
|
||||
@provider.instance_variable_set(:@should_vhost, "bar")
|
||||
@provider.instance_variable_set(:@should_user, "foo")
|
||||
@provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', "''", "''", "''")
|
||||
@provider.create
|
||||
end
|
||||
it 'should destroy permissions' do
|
||||
@provider.instance_variable_set(:@should_vhost, "bar")
|
||||
@provider.instance_variable_set(:@should_user, "foo")
|
||||
@provider.expects(:rabbitmqctl).with('clear_permissions', '-p', 'bar', 'foo')
|
||||
@provider.destroy
|
||||
end
|
||||
{: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 ...
|
||||
bar 1 2 3
|
||||
...done.
|
||||
EOT
|
||||
@provider.send(k).should == v
|
||||
end
|
||||
end
|
||||
{: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 ...
|
||||
bar 1 2 3
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?
|
||||
@provider.send(k).should == v
|
||||
end
|
||||
end
|
||||
{:configure_permission => ['foo', '2', '3'],
|
||||
: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
|
||||
Listing users ...
|
||||
bar 1 2 3
|
||||
...done.
|
||||
EOT
|
||||
@provider.resource[perm] = 'foo'
|
||||
@provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', *columns)
|
||||
@provider.send("#{perm}=".to_sym, 'foo')
|
||||
end
|
||||
end
|
||||
it 'should only call set_permissions once' do
|
||||
@provider.class.expects(:rabbitmqctl).with('list_user_permissions', 'foo').returns <<-EOT
|
||||
Listing users ...
|
||||
bar 1 2 3
|
||||
...done.
|
||||
EOT
|
||||
@provider.resource[:configure_permission] = 'foo'
|
||||
@provider.resource[:read_permission] = 'foo'
|
||||
@provider.expects(:rabbitmqctl).with('set_permissions', '-p', 'bar', 'foo', 'foo', '2', 'foo').once
|
||||
@provider.configure_permission='foo'
|
||||
@provider.read_permission='foo'
|
||||
end
|
||||
end
|
||||
|
@@ -0,0 +1,45 @@
|
||||
require 'puppet'
|
||||
require 'mocha'
|
||||
RSpec.configure do |config|
|
||||
config.mock_with :mocha
|
||||
end
|
||||
provider_class = Puppet::Type.type(:rabbitmq_vhost).provider(:rabbitmqctl)
|
||||
describe provider_class do
|
||||
before :each do
|
||||
@resource = Puppet::Type::Rabbitmq_vhost.new(
|
||||
{:name => 'foo'}
|
||||
)
|
||||
@provider = provider_class.new(@resource)
|
||||
end
|
||||
it 'should match vhost names' do
|
||||
@provider.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT
|
||||
Listing vhosts ...
|
||||
foo
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?.should == 'foo'
|
||||
end
|
||||
it 'should not match if no vhosts on system' do
|
||||
@provider.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT
|
||||
Listing vhosts ...
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?.should be_nil
|
||||
end
|
||||
it 'should not match if no matching vhosts on system' do
|
||||
@provider.expects(:rabbitmqctl).with('list_vhosts').returns <<-EOT
|
||||
Listing vhosts ...
|
||||
fooey
|
||||
...done.
|
||||
EOT
|
||||
@provider.exists?.should be_nil
|
||||
end
|
||||
it 'should call rabbitmqctl to create' do
|
||||
@provider.expects(:rabbitmqctl).with('add_vhost', 'foo')
|
||||
@provider.create
|
||||
end
|
||||
it 'should call rabbitmqctl to create' do
|
||||
@provider.expects(:rabbitmqctl).with('delete_vhost', 'foo')
|
||||
@provider.destroy
|
||||
end
|
||||
end
|
@@ -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
|
@@ -0,0 +1,55 @@
|
||||
require 'puppet'
|
||||
require 'puppet/type/rabbitmq_user_permissions'
|
||||
describe Puppet::Type.type(:rabbitmq_user_permissions) do
|
||||
before :each do
|
||||
@perms = Puppet::Type.type(:rabbitmq_user_permissions).new(:name => 'foo@bar')
|
||||
end
|
||||
it 'should accept a valid hostname name' do
|
||||
@perms[:name] = 'dan@bar'
|
||||
@perms[:name].should == 'dan@bar'
|
||||
end
|
||||
it 'should require a name' do
|
||||
expect {
|
||||
Puppet::Type.type(:rabbitmq_user_permissions).new({})
|
||||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
it 'should fail when names dont have a @' do
|
||||
expect {
|
||||
@perms[:name] = 'bar'
|
||||
}.to raise_error(Puppet::Error, /Valid values match/)
|
||||
end
|
||||
[:configure_permission, :read_permission, :write_permission].each do |param|
|
||||
it 'should not default to anything' do
|
||||
@perms[param].should == nil
|
||||
end
|
||||
it "should accept a valid regex for #{param}" 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] = '*'
|
||||
}.to raise_error(Puppet::Error, /Invalid regexp/)
|
||||
end
|
||||
end
|
||||
{:rabbitmq_vhost => 'dan@test', :rabbitmq_user => 'test@dan'}.each do |k,v|
|
||||
it "should autorequire #{k}" do
|
||||
if k == :rabbitmq_vhost
|
||||
vhost = Puppet::Type.type(k).new(:name => "test")
|
||||
else
|
||||
vhost = Puppet::Type.type(k).new(:name => "test", :password => 'pass')
|
||||
end
|
||||
perm = Puppet::Type.type(:rabbitmq_user_permissions).new(:name => v)
|
||||
config = Puppet::Resource::Catalog.new :testing do |conf|
|
||||
[vhost, perm].each { |resource| conf.add_resource resource }
|
||||
end
|
||||
rel = perm.autorequire[0]
|
||||
rel.source.ref.should == vhost.ref
|
||||
rel.target.ref.should == perm.ref
|
||||
end
|
||||
end
|
||||
end
|
@@ -0,0 +1,42 @@
|
||||
require 'puppet'
|
||||
require 'puppet/type/rabbitmq_user'
|
||||
describe Puppet::Type.type(:rabbitmq_user) do
|
||||
before :each do
|
||||
@user = Puppet::Type.type(:rabbitmq_user).new(:name => 'foo', :password => 'pass')
|
||||
end
|
||||
it 'should accept a user name' do
|
||||
@user[:name] = 'dan'
|
||||
@user[:name].should == 'dan'
|
||||
@user[:admin].should == :false
|
||||
end
|
||||
it 'should accept a password' do
|
||||
@user[:password] = 'foo'
|
||||
@user[:password].should == 'foo'
|
||||
end
|
||||
it 'should require a password' do
|
||||
expect {
|
||||
Puppet::Type.type(:rabbitmq_user).new(:name => 'foo')
|
||||
}.to raise_error(/must set password/)
|
||||
end
|
||||
it 'should require a name' do
|
||||
expect {
|
||||
Puppet::Type.type(:rabbitmq_user).new({})
|
||||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
it 'should not allow whitespace in the name' do
|
||||
expect {
|
||||
@user[:name] = 'b r'
|
||||
}.to raise_error(Puppet::Error, /Valid values match/)
|
||||
end
|
||||
[true, false, 'true', 'false'].each do |val|
|
||||
it "admin property should accept #{val}" do
|
||||
@user[:admin] = val
|
||||
@user[:admin].should == val.to_s.to_sym
|
||||
end
|
||||
end
|
||||
it 'should not accept non-boolean values for admin' do
|
||||
expect {
|
||||
@user[:admin] = 'yes'
|
||||
}.to raise_error(Puppet::Error, /Invalid value/)
|
||||
end
|
||||
end
|
@@ -0,0 +1,21 @@
|
||||
require 'puppet'
|
||||
require 'puppet/type/rabbitmq_vhost'
|
||||
describe Puppet::Type.type(:rabbitmq_vhost) do
|
||||
before :each do
|
||||
@vhost = Puppet::Type.type(:rabbitmq_vhost).new(:name => 'foo')
|
||||
end
|
||||
it 'should accept a vhost name' do
|
||||
@vhost[:name] = 'dan'
|
||||
@vhost[:name].should == 'dan'
|
||||
end
|
||||
it 'should require a name' do
|
||||
expect {
|
||||
Puppet::Type.type(:rabbitmq_vhost).new({})
|
||||
}.to raise_error(Puppet::Error, 'Title or name must be provided')
|
||||
end
|
||||
it 'should not allow whitespace in the name' do
|
||||
expect {
|
||||
@vhost[:name] = 'b r'
|
||||
}.to raise_error(Puppet::Error, /Valid values match/)
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user