Showing with 110 additions and 41 deletions.
  1. +12 −10 README.md
  2. +3 −0 manifests/gunicorn.pp
  3. +26 −14 manifests/install.pp
  4. +1 −1 manifests/params.pp
  5. +19 −7 manifests/pip.pp
  6. +5 −1 manifests/requirements.pp
  7. +5 −7 manifests/virtualenv.pp
  8. +1 −1 metadata.json
  9. +31 −0 spec/defines/gunicorn_spec.rb
  10. +4 −0 spec/defines/requirements_spec.rb
  11. +3 −0 templates/gunicorn.erb
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ Installs and manages python, python-pip, python-dev, python-virtualenv and Gunic

**ensure** - Desired installation state for the Python package. Options are absent, present and latest. Default: present

**version** - Python version to install. Default: system default
**version** - Python version to install. Default: system

**pip** - Desired installation state for the python-pip package. Options are absent, present and latest. Default: present

**dev** - Desired installation state for the python-dev package. Options are absent, present and latest. Default: present
**dev** - Desired installation state for the python-dev package. Options are absent, present and latest. Default: absent

**virtualenv** - Desired installation state for the virtualenv package. Options are absent, present and latest. Default: present
**virtualenv** - Desired installation state for the virtualenv package. Options are absent, present and latest. Default: absent

**gunicorn** - Desired installation state for Gunicorn. Options are absent, present and latest. Default: present
**gunicorn** - Desired installation state for Gunicorn. Options are absent, present and latest. Default: absent

**manage_gunicorn** - Allow Installation / Removal of Gunicorn. Default: true

Expand All @@ -70,9 +70,9 @@ Installs and manages python, python-pip, python-dev, python-virtualenv and Gunic
class { 'python' :
version => 'system',
pip => 'present',
dev => 'present',
virtualenv => 'present',
gunicorn => 'present',
dev => 'absent',
virtualenv => 'absent',
gunicorn => 'absent',
}
```

Expand All @@ -96,9 +96,9 @@ Installs and manages packages from pip.

**egg** - The egg name to use. Default: `$name` of the class, e.g. cx_Oracle

**install_args** - Array of additional flags to pass to pip during installaton. Default: none
**install_args** - String of additional flags to pass to pip during installaton. Default: none

**uninstall_args** - Array of additional flags to pass to pip during uninstall. Default: none
**uninstall_args** - String of additional flags to pass to pip during uninstall. Default: none

**timeout** - Timeout for the pip install command. Defaults to 1800.
```puppet
Expand All @@ -109,7 +109,7 @@ Installs and manages packages from pip.
owner => 'appuser',
proxy => 'http://proxy.domain.com:3128',
environment => 'ORACLE_HOME=/usr/lib/oracle/11.2/client64',
install_args => ['-e'],
install_args => '-e',
timeout => 1800,
}
```
Expand All @@ -128,6 +128,8 @@ Installs and manages Python packages from requirements file.

**group** - The group that was used to create the virtualenv. This is used to create the requirements file with correct permissions if it's not present already.

**manage_requirements** - Create the requirements file if it doesn't exist. Default: true

```puppet
python::requirements { '/var/www/project1/requirements.txt' :
virtualenv => '/var/www/project1',
Expand Down
3 changes: 3 additions & 0 deletions manifests/gunicorn.pp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
$access_log_format = false,
$accesslog = false,
$errorlog = false,
$log_level = 'error',
$template = 'python/gunicorn.erb',
) {

Expand All @@ -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',
Expand Down
40 changes: 26 additions & 14 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$python = $::python::version ? {
'system' => 'python',
'pypy' => 'pypy',
default => "python${python::version}",
default => $python::version,
}

$pythondev = $::osfamily ? {
Expand Down Expand Up @@ -50,23 +50,24 @@
name => $python,
}

package { 'python-dev':
ensure => $dev_ensure,
name => $pythondev,
}

package { 'pip':
ensure => $pip_ensure,
require => Package['python'],
}

package { 'virtualenv':
ensure => $venv_ensure,
require => Package['python'],
}

case $python::provider {
pip: {

package { 'pip':
ensure => $pip_ensure,
require => Package['python'],
}

package { 'python-dev':
ensure => $dev_ensure,
name => $pythondev,
}

# Install pip without pip, see https://pip.pypa.io/en/stable/installing/.
exec { 'bootstrap pip':
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python',
Expand Down Expand Up @@ -116,13 +117,13 @@
# ensure => $venv_ensure,
# require => Package['scl-utils'],
# }
package { "${python::version}-scldev":
package { "${python}-scldevel":
ensure => $dev_ensure,
require => Package['scl-utils'],
}
if $pip_ensure != 'absent' {
exec { 'python-scl-pip-install':
command => "${python::params::exec_prefix}easy_install pip",
command => "${python::exec_prefix}easy_install pip",
path => ['/usr/bin', '/bin'],
creates => "/opt/rh/${python::version}/root/usr/bin/pip",
require => Package['scl-utils'],
Expand All @@ -142,7 +143,7 @@
tag => 'python-scl-package',
}

package { "${python::version}-scldev":
package { "${python}-scldevel":
ensure => $dev_ensure,
tag => 'python-scl-package',
}
Expand All @@ -161,6 +162,17 @@
}

default: {

package { 'pip':
ensure => $pip_ensure,
require => Package['python'],
}

package { 'python-dev':
ensure => $dev_ensure,
name => $pythondev,
}

if $::osfamily == 'RedHat' {
if $pip_ensure != 'absent' {
if $python::use_epel == true {
Expand Down
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
$manage_gunicorn = true
$provider = undef
$valid_versions = $::osfamily ? {
'RedHat' => ['3'],
'RedHat' => ['3','27','33'],
'Debian' => ['3', '3.3', '2.7'],
'Suse' => [],
}
Expand Down
26 changes: 19 additions & 7 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,20 @@
$uninstall_args = '',
$timeout = 1800,
$log_dir = '/tmp',
$path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
) {

$python_provider = getparam(Class['python'], 'provider')
$python_version = getparam(Class['python'], 'version')

# Get SCL exec prefix
# NB: this will not work if you are running puppet from scl enabled shell
$exec_prefix = $python_provider ? {
'scl' => "scl enable ${python_version} -- ",
'rhscl' => "scl enable ${python_version} -- ",
default => '',
}

# Parameter validation
if ! $virtualenv {
fail('python::pip: virtualenv parameter must not be empty')
Expand All @@ -104,7 +116,7 @@
}

$pip_env = $virtualenv ? {
'system' => 'pip',
'system' => "${exec_prefix}pip",
default => "${virtualenv}/bin/pip",
}

Expand Down Expand Up @@ -180,8 +192,8 @@
group => $group,
cwd => $cwd,
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
timeout => $timeout,
path => $path,
}
} else {
exec { "pip_install_${name}":
Expand All @@ -191,8 +203,8 @@
group => $group,
cwd => $cwd,
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
timeout => $timeout,
path => $path,
}
}
} else {
Expand All @@ -207,8 +219,8 @@
group => $group,
cwd => $cwd,
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
timeout => $timeout,
path => $path,
}
}

Expand All @@ -221,8 +233,8 @@
group => $group,
cwd => $cwd,
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
timeout => $timeout,
path => $path,
}
}

Expand All @@ -235,8 +247,8 @@
group => $group,
cwd => $cwd,
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
timeout => $timeout,
path => $path,
}
}

Expand All @@ -249,8 +261,8 @@
group => $group,
cwd => $cwd,
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
timeout => $timeout,
path => $path,
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion manifests/requirements.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
# [*extra_pip_args*]
# Extra arguments to pass to pip after the requirements file
#
# [*manage_requirements*]
# Create the requirements file if it doesn't exist. Default: true
#
# [*fix_requirements_owner*]
# Change owner and group of requirements file. Default: true
#
Expand Down Expand Up @@ -71,6 +74,7 @@
$forceupdate = false,
$cwd = undef,
$extra_pip_args = '',
$manage_requirements = true,
$fix_requirements_owner = true,
$log_dir = '/tmp',
$timeout = 1800,
Expand Down Expand Up @@ -110,7 +114,7 @@

# This will ensure multiple python::virtualenv definitions can share the
# the same requirements file.
if !defined(File[$requirements]) {
if !defined(File[$requirements]) and $manage_requirements == true {
file { $requirements:
ensure => present,
mode => '0644',
Expand Down
12 changes: 5 additions & 7 deletions manifests/virtualenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@
}

if $virtualenv == undef {
$used_virtualenv = $version ? {
'system' => 'virtualenv',
default => "virtualenv-${version}",
}
$used_virtualenv = 'virtualenv'
} else {
$used_virtualenv = $virtualenv
}
Expand All @@ -119,9 +116,9 @@
# --system-site-packages flag, default off for prior versions
# Prior to version 1.7 the default was equal to --system-site-packages
# and the flag --no-site-packages had to be passed to do the opposite
if (( versioncmp($::virtualenv_version,'1.7') > 0 ) and ( $systempkgs == true )) {
if (( versioncmp("${::virtualenv_version}",'1.7') > 0 ) and ( $systempkgs == true )) { # lint:ignore:only_variable_string
$system_pkgs_flag = '--system-site-packages'
} elsif (( versioncmp($::virtualenv_version,'1.7') < 0 ) and ( $systempkgs == false )) {
} elsif (( versioncmp("${::virtualenv_version}",'1.7') < 0 ) and ( $systempkgs == false )) { # lint:ignore:only_variable_string
$system_pkgs_flag = '--no-site-packages'
} else {
$system_pkgs_flag = $systempkgs ? {
Expand Down Expand Up @@ -154,10 +151,11 @@
mode => $mode
}

$virtualenv_cmd = "${python::exec_prefix}${used_virtualenv}"
$pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip"

exec { "python_virtualenv_${venv_dir}":
command => "true ${proxy_command} && ${used_virtualenv} ${system_pkgs_flag} -p ${python} ${venv_dir} && ${pip_cmd} wheel --help > /dev/null 2>&1 && { ${pip_cmd} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_cmd} --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} \$wheel_support_flag --upgrade pip ${distribute_pkg} || ${pip_cmd} --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} --upgrade pip ${distribute_pkg} ;}",
command => "true ${proxy_command} && ${virtualenv_cmd} ${system_pkgs_flag} -p ${python} ${venv_dir} && ${pip_cmd} wheel --help > /dev/null 2>&1 && { ${pip_cmd} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_cmd} --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} \$wheel_support_flag --upgrade pip ${distribute_pkg} || ${pip_cmd} --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} --upgrade pip ${distribute_pkg} ;}",
user => $owner,
creates => "${venv_dir}/bin/activate",
path => $path,
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stankevich-python",
"version": "1.10.0",
"version": "1.11.0",
"author": "stankevich",
"summary": "Python Module",
"license": "Apache-2.0",
Expand Down
31 changes: 31 additions & 0 deletions spec/defines/gunicorn_spec.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions spec/defines/requirements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
let (:params) {{ :requirements => "/requirements.txt" }}
it { is_expected.to contain_file("/requirements.txt").with_mode('0644') }
end
context "/requirements.txt" do
let (:params) {{ :requirements => "/requirements.txt", :manage_requirements => false }}
it { is_expected.not_to contain_file("/requirements.txt") }
end

describe "with owner" do
context "bob:bob" do
Expand Down
3 changes: 3 additions & 0 deletions templates/gunicorn.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ CONFIG = {
<% if @errorlog -%>
'--error-logfile=<%= @errorlog %>',
<% end -%>
<% if @log_level %>
'--log-level=<%= @log_level %>',
<% end -%>
<% if @mode != 'django' -%>
'<%= @appmodule %>',
<% end -%>
Expand Down