diff --git a/spec/acceptance/keepalived_spec.rb b/spec/acceptance/keepalived_spec.rb index ad0a4b0d6..f00c39e62 100644 --- a/spec/acceptance/keepalived_spec.rb +++ b/spec/acceptance/keepalived_spec.rb @@ -3,73 +3,35 @@ require 'spec_helper_acceptance' describe 'keepalived class' do - context 'with default parameters' do - pp = <<-EOS - class { 'keepalived': - sysconf_options => '-D --vrrp', - } - - notify { "Keepalived version was: ${facts['keepalived_version']}": - require => Class['keepalived'], - } - EOS - - it 'works with no error' do - apply_manifest(pp, catch_failures: true) - end - - it 'works idempotently' do - pp2 = <<-EOS - class { 'keepalived': - sysconf_options => '-D --vrrp', - } - EOS - apply_manifest(pp2, catch_changes: true) - end - - it 'creates fact keepalived_version' do - service_fact = apply_manifest(pp, catch_failures: true) - expect(service_fact.output).to match %r{.*Keepalived version was: (\d.\d.\d).*} + context 'on master with vrrp instance' do + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'keepalived': + sysconf_options => '-D --vrrp', + } + + keepalived::vrrp::instance { 'VI_50': + interface => $facts['networking']['primary'], + state => 'MASTER', + virtual_router_id => 50, + priority => 101, + auth_type => 'PASS', + auth_pass => 'secret', + virtual_ipaddress => [ '10.0.0.1/16' ], + } + PUPPET + end end describe package('keepalived') do it { is_expected.to be_installed } end - describe file('/etc/keepalived/keepalived.conf') do - it { is_expected.to be_file } - its(:content) { is_expected.not_to contain('include ') } - end - end - - context 'on master with vrrp instance' do - pp = <<-EOS - class { 'keepalived': - sysconf_options => '-D --vrrp', - } - - keepalived::vrrp::instance { 'VI_50': - interface => $facts['networking']['primary'], - state => 'MASTER', - virtual_router_id => 50, - priority => 101, - auth_type => 'PASS', - auth_pass => 'secret', - virtual_ipaddress => [ '10.0.0.1/16' ], - } - EOS - - it 'works with no error' do - apply_manifest(pp, catch_failures: true) - end - - it 'works idempotently' do - apply_manifest(pp, catch_changes: true) - end - describe file('/etc/keepalived/keepalived.conf') do it { is_expected.to be_file } its(:content) { is_expected.to match %r{.*MASTER.*} } + its(:content) { is_expected.not_to contain('include ') } end describe service('keepalived') do @@ -78,63 +40,94 @@ class { 'keepalived': end # Works around any timing issues - it 'has acquired the ip' do - ip_result = shell('sleep 10; ip addr') - expect(ip_result.stdout).to match %r{.*inet 10\.0\.0\.1/16 .*} + describe 'when service running' do + it 'has acquired the ip' do + ip_result = shell('sleep 10; ip addr') + expect(ip_result.stdout).to match %r{.*inet 10\.0\.0\.1/16 .*} + end end end context 'on master with globalconf' do - pp = <<-EOS - class { 'keepalived': - sysconf_options => '-D --vrrp', - } - class { 'keepalived::global_defs': - notification_email => 'nospan@example.com', - } - EOS + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + class { 'keepalived': + sysconf_options => '-D --vrrp', + } + + keepalived::vrrp::instance { 'VI_50': + interface => $facts['networking']['primary'], + state => 'MASTER', + virtual_router_id => 50, + priority => 101, + auth_type => 'PASS', + auth_pass => 'secret', + virtual_ipaddress => [ '10.0.0.1/16' ], + } + class { 'keepalived::global_defs': + notification_email => 'nospan@example.com', + } + PUPPET + end + end - it 'works with no error' do - apply_manifest(pp, catch_failures: true) + describe file('/etc/keepalived/keepalived.conf') do + it { is_expected.to be_file } + its(:content) { is_expected.to contain('notification_email').from('global_defs').to('nospan@example.com') } end + end - it 'works idempotently' do - apply_manifest(pp, catch_changes: true) + context 'with unmanaged external config' do + it_behaves_like 'an idempotent resource' do + let(:manifest) do + <<-PUPPET + file { '/etc/keepalived/myconfig.conf': + owner => 'root', + group => 'root', + mode => '0644', + content => "vrrp_instance VI_50 { interface ${facts['networking']['primary']} + virtual_router_id 50 }", + notify => Class['keepalived::service'] + } + + class { 'keepalived': + include_external_conf_files => ['/etc/keepalived/myconfig.conf'], + sysconf_options => '-D --vrrp', + } + PUPPET + end end describe file('/etc/keepalived/keepalived.conf') do it { is_expected.to be_file } - its(:content) { is_expected.to contain('notification_email').from('global_defs').to('nospan@example.com') } + its(:content) { is_expected.to contain('include /etc/keepalived/myconfig.conf') } end end - context 'with unmanaged external config' do + context 'with minimal parameters' do pp = <<-EOS - file { '/etc/keepalived/myconfig.conf': - owner => 'root', - group => 'root', - mode => '0644', - content => '', - notify => Class['keepalived::service'] - } - class { 'keepalived': - include_external_conf_files => ['/etc/keepalived/myconfig.conf'], - sysconf_options => '-D --vrrp', + sysconf_options => '-D --vrrp', } - EOS - it 'works with no error' do - apply_manifest(pp, catch_failures: true) - end - - it 'works idempotently' do - apply_manifest(pp, catch_changes: true) - end + keepalived::vrrp::instance { 'VI_50': + interface => $facts['networking']['primary'], + state => 'MASTER', + virtual_router_id => 50, + priority => 101, + auth_type => 'PASS', + auth_pass => 'secret', + virtual_ipaddress => [ '10.0.0.1/16' ], + } - describe file('/etc/keepalived/keepalived.conf') do - it { is_expected.to be_file } - its(:content) { is_expected.to contain('include /etc/keepalived/myconfig.conf') } + notify { "Keepalived version was: ${facts['keepalived_version']}": + require => Class['keepalived'], + } + EOS + it 'creates fact keepalived_version' do + service_fact = apply_manifest(pp, catch_failures: true) + expect(service_fact.output).to match %r{.*Keepalived version was: (\d.\d.\d).*} end end end