Showing with 373 additions and 6 deletions.
  1. +6 −0 .fixtures.yml
  2. +19 −0 .travis.yml
  3. +25 −0 Gemfile
  4. +1 −1 Modulefile
  5. +2 −0 Rakefile
  6. +1 −1 manifests/pip.pp
  7. +7 −3 manifests/requirements.pp
  8. +6 −1 manifests/virtualenv.pp
  9. +228 −0 spec/classes/python_spec.rb
  10. +53 −0 spec/defines/requirements_spec.rb
  11. +25 −0 spec_helper.rb
6 changes: 6 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fixtures:
repositories:
stdlib: "git://github.com/puppetlabs/puppetlabs-stdlib.git"
# concat: "git://github.com/puppetlabs/puppetlabs-concat.git"
symlinks:
python: "#{source_dir}"
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
language: ruby
bundler_args: --without development
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'"
matrix:
fast_finish: true
include:
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.0"
- rvm: 1.9.3
env: PUPPET_GEM_VERSION="~> 3.5.0" STRICT_VARIABLES="yes"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.5.0" STRICT_VARIABLES="yes"
- rvm: 2.0.0
env: PUPPET_GEM_VERSION="~> 3.6.2" STRICT_VARIABLES="yes"
notifications:
email: false
25 changes: 25 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"

group :development, :test do
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'serverspec', :require => false
gem 'puppet-lint', :require => false
gem 'beaker', :require => false
gem 'beaker-rspec', :require => false
gem 'pry', :require => false
gem 'simplecov', :require => false
end

if facterversion = ENV['FACTER_GEM_VERSION']
gem 'facter', facterversion, :require => false
else
gem 'facter', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
gem 'puppet', puppetversion, :require => false
else
gem 'puppet', :require => false
end
2 changes: 1 addition & 1 deletion Modulefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name 'stankevich-python'
version '1.7.7'
version '1.7.8'

author 'Sergey Stankevich'
license 'Apache License, Version 2.0'
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ PuppetLint.configuration.with_filename = true
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_class_parameter_defaults')
PuppetLint.configuration.send('disable_80chars')

require 'puppetlabs_spec_helper/rake_tasks'
2 changes: 1 addition & 1 deletion manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
default: {
# Anti-action, uninstall.
exec { "pip_uninstall_${name}":
command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${use_pkgname}",
command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag}",
onlyif => "${pip_env} freeze | grep -i -e ${grep_regex}",
user => $owner,
environment => $environment,
Expand Down
10 changes: 7 additions & 3 deletions manifests/requirements.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
# requirements file - Useful for when the requirements file is written as part of a
# resource other than file (E.g vcsrepo)
#
# [*cwd*]
# The directory from which to run the "pip install" command. Default: undef
#
# === Examples
#
# python::requirements { '/var/www/project1/requirements.txt':
Expand All @@ -54,13 +57,14 @@
$src = false,
$environment = [],
$forceupdate = false,
$cwd = undef,
) {

if $virtualenv == 'system' and ($owner != 'root' or $group != 'root') {
fail('python::pip: root user must be used when virtualenv is system')
}

$cwd = $virtualenv ? {
$rootdir = $virtualenv ? {
'system' => '/',
default => $virtualenv,
}
Expand Down Expand Up @@ -96,13 +100,13 @@

exec { "python_requirements${name}":
provider => shell,
command => "${pip_env} --log ${cwd}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements}",
command => "${pip_env} --log ${rootdir}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements}",
refreshonly => !$forceupdate,
timeout => 1800,
cwd => $cwd,
user => $owner,
subscribe => File[$requirements],
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
}

}
7 changes: 6 additions & 1 deletion manifests/virtualenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@
} elsif (( versioncmp($::virtualenv_version,'1.7') < 0 ) and ( $systempkgs == false )) {
$system_pkgs_flag = '--no-site-packages'
} else {
$system_pkgs_flag = ''
$system_pkgs_flag = $systempkgs ? {
true => '--system-site-packages',
false => '--no-site-packages',
default => fail('Invalid value for systempkgs. Boolean value is expected')
}
}

$distribute_pkg = $distribute ? {
Expand Down Expand Up @@ -154,6 +158,7 @@
proxy => $proxy,
owner => $owner,
group => $group,
cwd => $cwd,
require => Exec["python_virtualenv_${venv_dir}"],
}
}
Expand Down
228 changes: 228 additions & 0 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
require_relative '../../spec_helper'

describe 'python', :type => :class do
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

it { is_expected.to contain_class("python::install") }
# Base debian packages.
it { is_expected.to contain_package("python") }
it { is_expected.to contain_package("python-dev") }
it { is_expected.to contain_package("python-pip") }
# Basic python packages (from pip)
it { is_expected.to contain_package("python-virtualenv")}

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => true }}
it { is_expected.to contain_package("python-dev").with(
"ensure" => "present")
}
end
context "empty/default" do
it { is_expected.to contain_package("python-dev").with(
"ensure" => "absent")
}
end
end


describe "with manage_gunicorn" do
context "true" do
let (:params) {{ :manage_gunicorn => true }}
it { is_expected.to contain_package("gunicorn") }
end
context "empty args" do
#let (:params) {{ :manage_gunicorn => '' }}
it { is_expected.to contain_package("gunicorn") }
end
context "false" do
let (:params) {{ :manage_gunicorn => false }}
it {is_expected.not_to contain_package("gunicorn")}
end
end

describe "with python::provider" do
context "pip" do
let (:params) {{ :provider => 'pip' }}
it { is_expected.to contain_package("virtualenv").with(
"provider" => "pip"
)}
it { is_expected.to contain_package("pip").with(
"provider" => "pip"
)}
end

# python::provider
context "default" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("python-virtualenv")}
it { is_expected.to contain_package("python-pip")}

describe "with python::virtualenv" do
context "true" do
let (:params) {{
:provider => '',
:virtualenv => true
}}
it { is_expected.to contain_package("python-virtualenv").with(
"ensure" => "present"
)}
end
end

describe "with python::virtualenv" do
context "default/empty" do
let (:params) {{
:provider => '',
:virtualenv => ''
}}
it { is_expected.to contain_package("python-virtualenv").with(
"ensure" => "absent"
)}
end
end


end
end

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => true }}
it { is_expected.to contain_package("python-dev").with(
"ensure" => "present")
}
end
context "default/empty" do
let (:params) {{ :dev => '' }}
it { is_expected.to contain_package("python-dev").with(
"ensure" => "absent")
}
end

end

context "on a Redhat 5 OS" do
let :facts do
{
:id => 'root',
:kernel => 'Linux',
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemrelease => '5',
:concat_basedir => '/dne',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
}
end
it { is_expected.to contain_class("python::install") }
# Base debian packages.
it { is_expected.to contain_package("python") }
it { is_expected.to contain_package("python-devel") }
it { is_expected.to contain_package("python-pip") }
# Basic python packages (from pip)
it { is_expected.to contain_package("python-virtualenv")}

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => true }}
it { is_expected.to contain_package("python-devel").with(
"ensure" => "present")
}
end
context "empty/default" do
it { is_expected.to contain_package("python-devel").with(
"ensure" => "absent")
}
end
end


describe "with manage_gunicorn" do
context "true" do
let (:params) {{ :manage_gunicorn => true }}
it { is_expected.to contain_package("gunicorn") }
end
context "empty args" do
#let (:params) {{ :manage_gunicorn => '' }}
it { is_expected.to contain_package("gunicorn") }
end
context "false" do
let (:params) {{ :manage_gunicorn => false }}
it {is_expected.not_to contain_package("gunicorn")}
end
end

describe "with python::provider" do
context "pip" do
let (:params) {{ :provider => 'pip' }}
it { is_expected.to contain_package("virtualenv").with(
"provider" => "pip"
)}
it { is_expected.to contain_package("pip").with(
"provider" => "pip"
)}
end

# python::provider
context "default" do
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("python-virtualenv")}
it { is_expected.to contain_package("python-pip")}

describe "with python::virtualenv" do
context "true" do
let (:params) {{
:provider => '',
:virtualenv => true
}}
it { is_expected.to contain_package("python-virtualenv").with(
"ensure" => "present"
)}
end
end

describe "with python::virtualenv" do
context "default/empty" do
let (:params) {{
:provider => '',
:virtualenv => ''
}}
it { is_expected.to contain_package("python-virtualenv").with(
"ensure" => "absent"
)}
end
end


end
end

describe "with python::dev" do
context "true" do
let (:params) {{ :dev => true }}
it { is_expected.to contain_package("python-devel").with(
"ensure" => "present")
}
end
context "default/empty" do
let (:params) {{ :dev => '' }}
it { is_expected.to contain_package("python-devel").with(
"ensure" => "absent")
}
end
end
end
end
end
Loading