diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 7670f394..5393ac33 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -55,6 +55,8 @@ String[1] $template = 'python/gunicorn.erb', Array $args = [], ) { + $processor_count = fact('processors.count') + if $manage_config_dir { file { $config_dir: ensure => directory, diff --git a/spec/defines/gunicorn_spec.rb b/spec/defines/gunicorn_spec.rb index 13284087..de36c580 100644 --- a/spec/defines/gunicorn_spec.rb +++ b/spec/defines/gunicorn_spec.rb @@ -5,37 +5,42 @@ describe 'python::gunicorn', type: :define do let(:title) { 'test-app' } - context 'on Debian OS' do - let :facts do - { - id: 'root', - kernel: 'Linux', - lsbdistcodename: 'squeeze', - osfamily: 'Debian', - operatingsystem: 'Debian', - operatingsystemrelease: '6', - path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - concat_basedir: '/dne' - } - end + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) { facts } - describe 'test-app with default parameter values' do - context 'configures test app with default parameter values' do - let(:params) { { dir: '/srv/testapp' } } + describe 'test-app with default parameter values' do + context 'configures test app with default parameter values' do + let(:params) { { dir: '/srv/testapp' } } + let(:expected_workers) do + # manifests/gunicorn.pp + processor_count = facts.dig(:processors, 'count') - it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--log-level=error}) } - end + # templates/gunicorn.erb + (processor_count.to_i * 2) + 1 + end - context 'test-app with custom log level' do - let(:params) { { dir: '/srv/testapp', log_level: 'info' } } + it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--log-level=error}) } + it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--workers=#{expected_workers}}) } + end - it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--log-level=info}) } - end + context 'test-app with custom log level' do + let(:params) { { dir: '/srv/testapp', log_level: 'info' } } + + it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--log-level=info}) } + end + + context 'test-app with custom gunicorn preload arguments' do + let(:params) { { dir: '/srv/testapp', args: ['--preload'] } } + + it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--preload}) } + end - context 'test-app with custom gunicorn preload arguments' do - let(:params) { { dir: '/srv/testapp', args: ['--preload'] } } + context 'test-app with custom workers count' do + let(:params) { { dir: '/srv/testapp', workers: 42 } } - it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--preload}) } + it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--workers=#{params[:workers]}}) } + end end end end diff --git a/templates/gunicorn.erb b/templates/gunicorn.erb index 07605ade..57dd4748 100644 --- a/templates/gunicorn.erb +++ b/templates/gunicorn.erb @@ -39,7 +39,7 @@ CONFIG = { <% if @workers -%> '--workers=<%= @workers %>', <% else -%> - '--workers=<%= @processorcount.to_i*2 + 1 %>', + '--workers=<%= @processor_count.to_i*2 + 1 %>', <% end -%> '--timeout=<%= @timeout %>', <% if @access_log_format -%>