diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index cb0ea4fd..37739875 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -80,6 +80,7 @@ $access_log_format = false, $accesslog = false, $errorlog = false, + $log_level = 'error', $template = 'python/gunicorn.erb', ) { @@ -88,6 +89,8 @@ fail('python::gunicorn: dir parameter must not be empty') } + validate_re($log_level, 'debug|info|warning|error|critical', "Invalid \$log_level value ${log_level}") + file { "/etc/gunicorn.d/${name}": ensure => $ensure, mode => '0644', diff --git a/spec/defines/gunicorn_spec.rb b/spec/defines/gunicorn_spec.rb new file mode 100644 index 00000000..5e51bb21 --- /dev/null +++ b/spec/defines/gunicorn_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' + +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 + + describe 'test-app with default parameter values' do + context 'configures test app with default parameter values' do + let(:params) { { :dir => '/srv/testapp' } } + it { is_expected.to contain_file('/etc/gunicorn.d/test-app').with_mode('0644').with_content(/--log-level=error/) } + 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(/--log-level=info/) } + end + end + end +end diff --git a/templates/gunicorn.erb b/templates/gunicorn.erb index 8e435bb8..ca01e7d7 100644 --- a/templates/gunicorn.erb +++ b/templates/gunicorn.erb @@ -42,6 +42,9 @@ CONFIG = { <% if @errorlog -%> '--error-logfile=<%= @errorlog %>', <% end -%> +<% if @log_level %> + '--log-level=<%= @log_level %>', +<% end -%> <% if @mode != 'django' -%> '<%= @appmodule %>', <% end -%>