From cc4956d32776ce8a5510be0befd5a5fe50ef0ac7 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Thu, 28 May 2015 16:58:17 -0700 Subject: [PATCH 1/3] Fix 2.8.1 acceptance tests Arch and Suse are not supported operating systems, so we do not need to run this test on them. Ubuntu is supported, but the problem these tests seek to solve is not relevant because Ubuntu does not have rabbitmq 2.8.1 available. This patch modifies the 2.8.1 acceptance spec test to only test on RedHat. --- spec/acceptance/zz281_spec.rb | 366 ++++++++++++++++------------------ 1 file changed, 175 insertions(+), 191 deletions(-) diff --git a/spec/acceptance/zz281_spec.rb b/spec/acceptance/zz281_spec.rb index 05e5ef40c..75637485b 100644 --- a/spec/acceptance/zz281_spec.rb +++ b/spec/acceptance/zz281_spec.rb @@ -3,209 +3,193 @@ # 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... +# These tests only apply to RedHat because 2.8.1 is not available in either the +# distro or upstream repos for Debian/Ubuntu. # - 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 } + if fact('osfamily') == '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' + + 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 - describe service(service_name) do - it { should be_enabled } - it { should be_running } + 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 - 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) + 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 - describe service(service_name) do - it { should_not be_enabled } - it { should_not 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('/usr/local/bin/rabbitmqadmin --help') do + its(:exit_status) { should eq 0 } + 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('/usr/local/bin/rabbitmqadmin --help') do - its(:exit_status) { should eq 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 + 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('/usr/local/bin/rabbitmqadmin --help') do + its(:exit_status) { should eq 0 } + end - describe command('/usr/local/bin/rabbitmqadmin --help') do - its(:exit_status) { should eq 0 } end end From d019865b05be4ebe253e72f39301c2cf86b06c99 Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Thu, 28 May 2015 18:32:23 -0700 Subject: [PATCH 2/3] Fix rabbitmq_exchange create command Without this patch, the rabbitmq_exchange provider tries to call rabbitmqadmin with the optional parameters internal, auto_delete, and durable parameters set to empty, which results in an error: `[u'not_boolean', u'']`. This patch changes the command to only use call those parameters if they were specified by the user, otherwise the default values will be used. --- lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb b/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb index c1cff0957..583b7bc60 100644 --- a/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb +++ b/lib/puppet/provider/rabbitmq_exchange/rabbitmqadmin.rb @@ -98,7 +98,12 @@ def create if arguments.nil? arguments = {} end - rabbitmqadmin('declare', 'exchange', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}", "type=#{resource[:type]}", "internal=#{resource[:internal]}", "durable=#{resource[:durable]}", "auto_delete=#{resource[:auto_delete]}", "arguments=#{arguments.to_json}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf') + cmd = ['declare', 'exchange', vhost_opt, "--user=#{resource[:user]}", "--password=#{resource[:password]}", "name=#{name}", "type=#{resource[:type]}",] + cmd << "internal=#{resource[:internal]}" if resource[:internal] + cmd << "durable=#{resource[:durable]}" if resource[:durable] + cmd << "auto_delete=#{resource[:auto_delete]}" if resource[:auto_delete] + cmd += ["arguments=#{arguments.to_json}", '-c', '/etc/rabbitmq/rabbitmqadmin.conf'] + rabbitmqadmin(*cmd) @property_hash[:ensure] = :present end From 48d379f418ce4315a2854365ffae57e94d20b57e Mon Sep 17 00:00:00 2001 From: Colleen Murphy Date: Thu, 28 May 2015 20:18:40 -0700 Subject: [PATCH 3/3] Swap order of rabbitmqadmin tests On Ubuntu, the rabbitmq-server package will automatically start the service, but the 'does nothing if service is unmanaged' will change the rabbitmq config file without restarting the service. The following test, 'downloads the cli tools' will also not refresh the service because the config file has not changed since the last test, but the server will not be listening on the right port and the staging resource fill fail. This patch swaps the order of the tests so that the service will be listening correctly on the first test, but then will correctly do nothing on the second test. --- spec/acceptance/rabbitmqadmin_spec.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/spec/acceptance/rabbitmqadmin_spec.rb b/spec/acceptance/rabbitmqadmin_spec.rb index e9d619cd4..dcf62402d 100644 --- a/spec/acceptance/rabbitmqadmin_spec.rb +++ b/spec/acceptance/rabbitmqadmin_spec.rb @@ -1,12 +1,12 @@ require 'spec_helper_acceptance' describe 'rabbitmq::install::rabbitmqadmin class' do - context 'does nothing if service is unmanaged' do + context 'downloads the cli tools' do it 'should run successfully' do pp = <<-EOS class { 'rabbitmq': admin_enable => true, - service_manage => false, + service_manage => true, } if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true} @@ -14,21 +14,20 @@ class { 'erlang': epel_enable => true} } 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 } + it { should be_file } end end - context 'downloads the cli tools' do + context 'does nothing if service is unmanaged' do it 'should run successfully' do pp = <<-EOS class { 'rabbitmq': admin_enable => true, - service_manage => true, + service_manage => false, } if $::osfamily == 'RedHat' { class { 'erlang': epel_enable => true} @@ -36,11 +35,12 @@ class { 'erlang': epel_enable => true} } EOS + shell('rm -f /var/lib/rabbitmq/rabbitmqadmin') apply_manifest(pp, :catch_failures => true) end describe file('/var/lib/rabbitmq/rabbitmqadmin') do - it { should be_file } + it { should_not be_file } end end