Skip to content

Commit ecb8d77

Browse files
authored
Merge pull request #724 from notCalle/gunicorn-legacy-facts
Replace legacy fact in gunicorn config templating
2 parents ac5fd04 + 67c1a82 commit ecb8d77

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

manifests/gunicorn.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
String[1] $template = 'python/gunicorn.erb',
5656
Array $args = [],
5757
) {
58+
$processor_count = fact('processors.count')
59+
5860
if $manage_config_dir {
5961
file { $config_dir:
6062
ensure => directory,

spec/defines/gunicorn_spec.rb

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,42 @@
55
describe 'python::gunicorn', type: :define do
66
let(:title) { 'test-app' }
77

8-
context 'on Debian OS' do
9-
let :facts do
10-
{
11-
id: 'root',
12-
kernel: 'Linux',
13-
lsbdistcodename: 'squeeze',
14-
osfamily: 'Debian',
15-
operatingsystem: 'Debian',
16-
operatingsystemrelease: '6',
17-
path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
18-
concat_basedir: '/dne'
19-
}
20-
end
8+
on_supported_os.each do |os, facts|
9+
context "on #{os}" do
10+
let(:facts) { facts }
2111

22-
describe 'test-app with default parameter values' do
23-
context 'configures test app with default parameter values' do
24-
let(:params) { { dir: '/srv/testapp' } }
12+
describe 'test-app with default parameter values' do
13+
context 'configures test app with default parameter values' do
14+
let(:params) { { dir: '/srv/testapp' } }
15+
let(:expected_workers) do
16+
# manifests/gunicorn.pp
17+
processor_count = facts.dig(:processors, 'count')
2518

26-
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--log-level=error}) }
27-
end
19+
# templates/gunicorn.erb
20+
(processor_count.to_i * 2) + 1
21+
end
2822

29-
context 'test-app with custom log level' do
30-
let(:params) { { dir: '/srv/testapp', log_level: 'info' } }
23+
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--log-level=error}) }
24+
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--workers=#{expected_workers}}) }
25+
end
3126

32-
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--log-level=info}) }
33-
end
27+
context 'test-app with custom log level' do
28+
let(:params) { { dir: '/srv/testapp', log_level: 'info' } }
29+
30+
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--log-level=info}) }
31+
end
32+
33+
context 'test-app with custom gunicorn preload arguments' do
34+
let(:params) { { dir: '/srv/testapp', args: ['--preload'] } }
35+
36+
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--preload}) }
37+
end
3438

35-
context 'test-app with custom gunicorn preload arguments' do
36-
let(:params) { { dir: '/srv/testapp', args: ['--preload'] } }
39+
context 'test-app with custom workers count' do
40+
let(:params) { { dir: '/srv/testapp', workers: 42 } }
3741

38-
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--preload}) }
42+
it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(%r{--workers=#{params[:workers]}}) }
43+
end
3944
end
4045
end
4146
end

templates/gunicorn.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ CONFIG = {
3939
<% if @workers -%>
4040
'--workers=<%= @workers %>',
4141
<% else -%>
42-
'--workers=<%= @processorcount.to_i*2 + 1 %>',
42+
'--workers=<%= @processor_count.to_i*2 + 1 %>',
4343
<% end -%>
4444
'--timeout=<%= @timeout %>',
4545
<% if @access_log_format -%>

0 commit comments

Comments
 (0)