diff options
author | Cody Herriges <c.a.herriges@gmail.com> | 2012-08-30 09:52:12 -0700 |
---|---|---|
committer | Cody Herriges <c.a.herriges@gmail.com> | 2012-08-30 09:52:12 -0700 |
commit | 83592cd211efbbcd278e6faec350cdaa456fbc62 (patch) | |
tree | 71367a4ce50c542427cf976b64fc4888eadd7b6e | |
parent | e5e01c43c33ab5f139449477c9997cb2ee21ea74 (diff) | |
parent | 12a8a5d6e0419f26265e325a8cf1e4019dc23895 (diff) |
Merge pull request #3 from hunner/add_debian_support
Add debian support
-rw-r--r-- | manifests/data.pp | 18 | ||||
-rw-r--r-- | manifests/init.pp | 19 | ||||
-rw-r--r-- | spec/classes/haproxy_spec.rb | 152 |
3 files changed, 139 insertions, 50 deletions
diff --git a/manifests/data.pp b/manifests/data.pp index aa49285..6b27068 100644 --- a/manifests/data.pp +++ b/manifests/data.pp @@ -24,6 +24,24 @@ class haproxy::data { 'maxconn' => '8000' } } + Debian: { + $haproxy_global_options = { 'log' => "${::ipaddress} local0", + 'chroot' => '/var/lib/haproxy', + 'pidfile' => '/var/run/haproxy.pid', + 'maxconn' => '4000', + 'user' => 'haproxy', + 'group' => 'haproxy', + 'daemon' => '', + 'stats' => 'socket /var/lib/haproxy/stats' + } + $haproxy_defaults_options = { 'log' => 'global', + 'stats' => 'enable', + 'option' => 'redispatch', + 'retries' => '3', + 'timeout' => ['http-request 10s', 'queue 1m', 'connect 10s', 'client 1m', 'server 1m', 'check 10s'], + 'maxconn' => '8000' + } + } default: { fail("The $::operatingsystem operating system is not supported with the haproxy module") } } } diff --git a/manifests/init.pp b/manifests/init.pp index 8005aec..f75051c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -97,6 +97,20 @@ class haproxy ( order => '10', content => template('haproxy/haproxy-base.cfg.erb'), } + + if ($::osfamily == 'Debian') { + file { '/etc/default/haproxy': + content => 'ENABLED=1', + require => Package['haproxy'], + before => Service['haproxy'], + } + } + + file { $haproxy_global_options['chroot']: + ensure => directory, + before => Service['haproxy'], + } + } service { 'haproxy': @@ -111,6 +125,9 @@ class haproxy ( name => 'haproxy', hasrestart => true, hasstatus => true, - require => Concat['/etc/haproxy/haproxy.cfg'], + require => [ + Concat['/etc/haproxy/haproxy.cfg'], + File[$haproxy_global_options['chroot']], + ], } } diff --git a/spec/classes/haproxy_spec.rb b/spec/classes/haproxy_spec.rb index 46c8124..fa171f3 100644 --- a/spec/classes/haproxy_spec.rb +++ b/spec/classes/haproxy_spec.rb @@ -1,59 +1,113 @@ require 'spec_helper' describe 'haproxy', :type => :class do - - context 'on Redhat family operatingsystems' do - let(:facts) do - { - :osfamily => 'Redhat', - :concat_basedir => '/dne' - } - end - it { should include_class('concat::setup') } - - it 'should install the haproxy package' do - subject.should contain_package('haproxy').with( - 'ensure' => 'present' - ) - end - - it 'should install the haproxy service' do - subject.should contain_service('haproxy').with( - 'ensure' => 'running', - 'enable' => 'true', - 'hasrestart' => 'true', - 'hasstatus' => 'true' - ) - end - - it 'should set up /etc/haproxy/haproxy.cfg as a concat resource' do - subject.should contain_concat('/etc/haproxy/haproxy.cfg').with( - 'owner' => '0', - 'group' => '0', - 'mode' => '0644' - ) - end - - it 'should contain a header concat fragment' do - subject.should contain_concat__fragment('00-header').with( - 'target' => '/etc/haproxy/haproxy.cfg', - 'order' => '01', - 'content' => "# This file managed by Puppet\n" - ) + let(:default_facts) do + { + :concat_basedir => '/dne', + :ipaddress => '10.10.10.10' + } + end + context 'on supported platforms' do + describe 'for OS-agnostic configuration' do + ['Debian', 'RedHat'].each do |osfamily| + context "on #{osfamily} family operatingsystems" do + let(:facts) do + { :osfamily => osfamily }.merge default_facts + end + let(:params) do + {'enable' => true} + end + it { should include_class('concat::setup') } + it 'should install the haproxy package' do + subject.should contain_package('haproxy').with( + 'ensure' => 'present' + ) + end + it 'should install the haproxy service' do + subject.should contain_service('haproxy').with( + 'ensure' => 'running', + 'enable' => 'true', + 'hasrestart' => 'true', + 'hasstatus' => 'true', + 'require' => [ + 'Concat[/etc/haproxy/haproxy.cfg]', + 'File[/var/lib/haproxy]' + ] + ) + end + it 'should set up /etc/haproxy/haproxy.cfg as a concat resource' do + subject.should contain_concat('/etc/haproxy/haproxy.cfg').with( + 'owner' => '0', + 'group' => '0', + 'mode' => '0644' + ) + end + it 'should manage the chroot directory' do + subject.should contain_file('/var/lib/haproxy').with( + 'ensure' => 'directory' + ) + end + it 'should contain a header concat fragment' do + subject.should contain_concat__fragment('00-header').with( + 'target' => '/etc/haproxy/haproxy.cfg', + 'order' => '01', + 'content' => "# This file managed by Puppet\n" + ) + end + it 'should contain a haproxy-base concat fragment' do + subject.should contain_concat__fragment('haproxy-base').with( + 'target' => '/etc/haproxy/haproxy.cfg', + 'order' => '10' + ) + end + describe 'Base concat fragment contents' do + let(:contents) { param_value(subject, 'concat::fragment', 'haproxy-base', 'content').split("\n") } + it 'should contain global and defaults sections' do + contents.should include('global') + contents.should include('defaults') + end + it 'should log to an ip address for local0' do + contents.should be_any { |match| match =~ / log \d+(\.\d+){3} local0/ } + end + it 'should specify the default chroot' do + contents.should include(' chroot /var/lib/haproxy') + end + it 'should specify the correct user' do + contents.should include(' user haproxy') + end + it 'should specify the correct group' do + contents.should include(' group haproxy') + end + it 'should specify the correct pidfile' do + contents.should include(' pidfile /var/run/haproxy.pid') + end + end + end + end end - - it 'should contain a haproxy-base concat fragment' do - subject.should contain_concat__fragment('haproxy-base').with( - 'target' => '/etc/haproxy/haproxy.cfg', - 'order' => '10', - 'content' => "global\n chroot /var/lib/haproxy\n daemon \n group haproxy\n log local0\n maxconn 4000\n pidfile /var/run/haproxy.pid\n stats socket /var/lib/haproxy/stats\n user haproxy\n\ndefaults\n log global\n maxconn 8000\n option redispatch\n retries 3\n stats enable\n timeout http-request 10s\n timeout queue 1m\n timeout connect 10s\n timeout client 1m\n timeout server 1m\n timeout check 10s\n" - ) + describe 'for OS-specific configuration' do + context 'only on Debian family operatingsystems' do + let(:facts) do + { :osfamily => 'Debian' }.merge default_facts + end + it 'should manage haproxy service defaults' do + subject.should contain_file('/etc/default/haproxy').with( + 'before' => 'Service[haproxy]', + 'require' => 'Package[haproxy]' + ) + verify_contents(subject, '/etc/default/haproxy', ['ENABLED=1']) + end + end + context 'only on RedHat family operatingsystems' do + let(:facts) do + { :osfamily => 'RedHat' }.merge default_facts + end + end end end - - context 'on non-Redhat family operatingsystems' do + context 'on unsupported operatingsystems' do let(:facts) do - { :osfamily => 'Debian' } + { :osfamily => 'RainbowUnicorn' }.merge default_facts end it do expect { |