From eabf8ac23e75a229a5fa12d8447bef5d4d26bda0 Mon Sep 17 00:00:00 2001 From: Dimitris Stafylarakis Date: Tue, 15 Dec 2015 11:36:43 +0100 Subject: [PATCH 1/3] add configurable log level for gunicorn and unit tests --- manifests/gunicorn.pp | 3 +++ spec/defines/gunicorn_spec.rb | 31 +++++++++++++++++++++++++++++++ templates/gunicorn.erb | 3 +++ 3 files changed, 37 insertions(+) create mode 100644 spec/defines/gunicorn_spec.rb diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index cb0ea4fd..cba3964e 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -80,6 +80,7 @@ $access_log_format = false, $accesslog = false, $errorlog = false, + $loglevel = 'error', $template = 'python/gunicorn.erb', ) { @@ -88,6 +89,8 @@ fail('python::gunicorn: dir parameter must not be empty') } + validate_re($loglevel, 'debug|info|warning|error|critical', "Invalid \$loglevel value ${loglevel}") + 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..393240ea --- /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 'gunicorn as' 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 'configures test app with custom log level' do + let(:params) { { dir: '/srv/testapp', loglevel: '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..59becea8 100644 --- a/templates/gunicorn.erb +++ b/templates/gunicorn.erb @@ -42,6 +42,9 @@ CONFIG = { <% if @errorlog -%> '--error-logfile=<%= @errorlog %>', <% end -%> +<% if @loglevel %> + '--log-level=<%= @loglevel %>', +<% end -%> <% if @mode != 'django' -%> '<%= @appmodule %>', <% end -%> From ded90de78da3ddda6e324e16345d00870a83e8e3 Mon Sep 17 00:00:00 2001 From: Dimitris Stafylarakis Date: Tue, 15 Dec 2015 15:13:34 +0100 Subject: [PATCH 2/3] change parameter name loglevel -> log_level --- manifests/gunicorn.pp | 4 ++-- templates/gunicorn.erb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index cba3964e..37739875 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -80,7 +80,7 @@ $access_log_format = false, $accesslog = false, $errorlog = false, - $loglevel = 'error', + $log_level = 'error', $template = 'python/gunicorn.erb', ) { @@ -89,7 +89,7 @@ fail('python::gunicorn: dir parameter must not be empty') } - validate_re($loglevel, 'debug|info|warning|error|critical', "Invalid \$loglevel value ${loglevel}") + validate_re($log_level, 'debug|info|warning|error|critical', "Invalid \$log_level value ${log_level}") file { "/etc/gunicorn.d/${name}": ensure => $ensure, diff --git a/templates/gunicorn.erb b/templates/gunicorn.erb index 59becea8..ca01e7d7 100644 --- a/templates/gunicorn.erb +++ b/templates/gunicorn.erb @@ -42,8 +42,8 @@ CONFIG = { <% if @errorlog -%> '--error-logfile=<%= @errorlog %>', <% end -%> -<% if @loglevel %> - '--log-level=<%= @loglevel %>', +<% if @log_level %> + '--log-level=<%= @log_level %>', <% end -%> <% if @mode != 'django' -%> '<%= @appmodule %>', From 6c301dad353f605d44b8809067e752545069831e Mon Sep 17 00:00:00 2001 From: Dimitris Stafylarakis Date: Tue, 15 Dec 2015 22:37:06 +0100 Subject: [PATCH 3/3] set rspec test back to Ruby 1.8 style --- spec/defines/gunicorn_spec.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/defines/gunicorn_spec.rb b/spec/defines/gunicorn_spec.rb index 393240ea..5e51bb21 100644 --- a/spec/defines/gunicorn_spec.rb +++ b/spec/defines/gunicorn_spec.rb @@ -1,29 +1,29 @@ require 'spec_helper' -describe 'python::gunicorn', type: :define do +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' + :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 'gunicorn as' do + describe 'test-app with default parameter values' do context 'configures test app with default parameter values' do - let(:params) { { dir: '/srv/testapp' } } + 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 'configures test app with custom log level' do - let(:params) { { dir: '/srv/testapp', loglevel: 'info' } } + 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