Try after unbound.service instead of network-online.target
[mirror/dsa-puppet.git] / 3rdparty / modules / rabbitmq / spec / classes / rabbitmq_spec.rb
index bd00c33..4c2a5be 100644 (file)
@@ -13,27 +13,30 @@ describe 'rabbitmq' do
     end
   end
 
+  # TODO: get Archlinux & OpenBSD facts from facterdb
+
   on_supported_os.each do |os, facts|
     context "on #{os}" do
-      systemd_facts = os_specific_facts(facts)
-      facts = facts.merge(systemd_facts)
-      let :facts do
-        facts
-      end
-
-      name = case facts[:osfamily]
-             when 'Archlinux', 'OpenBSD', 'FreeBSD'
-               'rabbitmq'
-             else
-               'rabbitmq-server'
-             end
+      let(:facts) { facts }
+
+      packagename = case facts[:osfamily]
+                    when 'Archlinux'
+                      'rabbitmq'
+                    else
+                      'rabbitmq-server'
+                    end
+      has_systemd = (
+        (facts[:os]['family'] == 'RedHat' && facts[:os]['release']['major'].to_i >= 7) ||
+        (facts[:os]['family'] == 'Debian' && facts[:os]['release']['full'] == '16.04') ||
+        (facts[:os]['family'] == 'Archlinux')
+      )
 
       it { is_expected.to compile.with_all_deps }
       it { is_expected.to contain_class('rabbitmq::install') }
-      it { is_expected.to contain_class('rabbitmq::config').that_notifies('Class[rabbitmq::service]') }
+      it { is_expected.to contain_class('rabbitmq::config') }
       it { is_expected.to contain_class('rabbitmq::service') }
 
-      it { is_expected.to contain_package(name).with_ensure('installed').with_name(name) }
+      it { is_expected.to contain_package(packagename).with_ensure('installed').with_name(packagename) }
       if facts[:os]['family'] == 'Suse'
         it { is_expected.to contain_package('rabbitmq-server-plugins') }
       end
@@ -45,12 +48,6 @@ describe 'rabbitmq' do
         it { is_expected.not_to contain_yumrepo('rabbitmq') }
       end
 
-      context 'with service_restart => false' do
-        let(:params) { { service_restart: false } }
-
-        it { is_expected.not_to contain_class('rabbitmq::config').that_notifies('Class[rabbitmq::service]') }
-      end
-
       context 'with repos_ensure => true' do
         let(:params) { { repos_ensure: true } }
 
@@ -124,7 +121,7 @@ describe 'rabbitmq' do
         end
       end
 
-      ['infinity', -1, 1234].each do |value|
+      ['unlimited', 'infinity', -1, 1234].each do |value|
         context "with file_limit => '#{value}'" do
           let(:params) { { file_limit: value } }
 
@@ -147,19 +144,22 @@ describe 'rabbitmq' do
             it { is_expected.not_to contain_file('/etc/default/rabbitmq-server') }
           end
 
-          if facts[:systemd]
+          if has_systemd
             it do
-              is_expected.to contain_systemd__service_limits("#{name}.service").
-                with_limits('LimitNOFILE' => value).
-                with_restart_service(false)
+              is_expected.to contain_file("/etc/systemd/system/#{packagename}.service.d/limits.conf").
+                with_owner('0').
+                with_group('0').
+                with_mode('0644').
+                that_notifies('Exec[rabbitmq-systemd-reload]').
+                with_content("[Service]\nLimitNOFILE=#{value}\n")
             end
           else
-            it { is_expected.not_to contain_systemd__service_limits("#{name}.service") }
+            it { is_expected.not_to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf') }
           end
         end
       end
 
-      [-42, '-42', 'foo'].each do |value|
+      [-42, '-42', 'foo', '42'].each do |value|
         context "with file_limit => '#{value}'" do
           let(:params) { { file_limit: value } }
 
@@ -169,15 +169,32 @@ describe 'rabbitmq' do
         end
       end
 
-      context 'on systems with systemd', if: facts[:systemd] do
-        it do
-          is_expected.to contain_systemd__service_limits("#{name}.service").
-            with_restart_service(false)
-        end
+      context 'on systems with systemd', if: has_systemd do
+        it {
+          is_expected.to contain_file("/etc/systemd/system/#{packagename}.service.d").with(
+            'ensure'                  => 'directory',
+            'owner'                   => '0',
+            'group'                   => '0',
+            'mode'                    => '0755',
+            'selinux_ignore_defaults' => true
+          )
+        }
+
+        it { is_expected.to contain_file("/etc/systemd/system/#{packagename}.service.d/limits.conf") }
+
+        it {
+          is_expected.to contain_exec('rabbitmq-systemd-reload').with(
+            command: '/bin/systemctl daemon-reload',
+            notify: 'Class[Rabbitmq::Service]',
+            refreshonly: true
+          )
+        }
       end
 
-      context 'on systems without systemd', unless: facts[:systemd] do
-        it { is_expected.not_to contain_systemd__service_limits("#{name}.service") }
+      context 'on systems without systemd', unless: has_systemd do
+        it { is_expected.not_to contain_file('/etc/systemd/system/rabbitmq-server.service.d') }
+        it { is_expected.not_to contain_file('/etc/systemd/system/rabbitmq-server.service.d/limits.conf') }
+        it { is_expected.not_to contain_exec('rabbitmq-systemd-reload') }
       end
 
       context 'with admin_enable set to true' do
@@ -1394,31 +1411,6 @@ describe 'rabbitmq' do
         end
       end
 
-      describe 'rabbitmq-loopback_users by default' do
-        it 'sets the loopback_users parameter in the config file' do
-          is_expected.to contain_file('rabbitmq.config'). \
-            with_content(%r{\{loopback_users, \[<<"guest">>\]\}})
-        end
-      end
-
-      describe 'rabbitmq-loopback_users allow connections via loopback interfaces' do
-        let(:params) { { loopback_users: [] } }
-
-        it 'sets the loopback_users parameter in the config file' do
-          is_expected.to contain_file('rabbitmq.config'). \
-            with_content(%r{\{loopback_users, \[\]\}})
-        end
-      end
-
-      describe 'rabbitmq-loopback_users allow connections via loopback interfaces to a group of users' do
-        let(:params) { { loopback_users: %w[user1 user2] } }
-
-        it 'sets the loopback_users parameter in the config file' do
-          is_expected.to contain_file('rabbitmq.config'). \
-            with_content(%r{\{loopback_users, \[<<\"user1\">>, <<\"user2\">>\]\}})
-        end
-      end
-
       ##
       ## rabbitmq::service
       ##
@@ -1428,19 +1420,11 @@ describe 'rabbitmq' do
             'ensure'     => 'running',
             'enable'     => 'true',
             'hasstatus'  => 'true',
-            'hasrestart' => 'true',
-            'name'       => name
+            'hasrestart' => 'true'
           )
         }
       end
 
-      context 'on systems with systemd', if: facts[:systemd] do
-        it do
-          is_expected.to contain_service('rabbitmq-server').
-            that_requires('Class[systemd::systemctl::daemon_reload]')
-        end
-      end
-
       describe 'service with ensure stopped' do
         let :params do
           { service_ensure: 'stopped' }