Skip to content

Replace legacy fact in gunicorn config templating #724

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions manifests/gunicorn.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
55 changes: 30 additions & 25 deletions spec/defines/gunicorn_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion templates/gunicorn.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 -%>
Expand Down