1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ group :development, :test do
gem 'puppet-lint', :require => false
gem 'pry', :require => false
gem 'simplecov', :require => false
gem 'rspec', '~> 2.99'
end

if facterversion = ENV['FACTER_GEM_VERSION']
Expand Down
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.9.0'
version '1.9.1'
source 'git://github.com/stankevich/puppet-python.git'
author 'stankevich'
license 'Apache License, Version 2.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/facter/pip_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
has_weight 100
setcode do
if Facter::Util::Resolution.which('pip')
Facter::Util::Resolution.exec('pip --version 2>/dev/null').match(/^pip (\d+\.\d+\.?\d*).*$/)[1]
Facter::Util::Resolution.exec('pip --version 2>&1').match(/^pip (\d+\.\d+\.?\d*).*$/)[1]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/facter/virtualenv_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
has_weight 100
setcode do
if Facter::Util::Resolution.which('virtualenv')
Facter::Util::Resolution.exec('virtualenv --version 2>&1')
Facter::Util::Resolution.exec('virtualenv --version 2>&1').match(/^(\d+\.\d+\.?\d*).*$/)[0]
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
default => $virtualenv,
}

validate_absolute_path($cwd)

$log = $virtualenv ? {
'system' => $log_dir,
default => $virtualenv,
Expand Down Expand Up @@ -212,7 +214,7 @@
# Latest version.
exec { "pip_install_${name}":
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${log}/pip.log install --upgrade \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install --upgrade ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
unless => "${pip_env} search ${source} | grep -i INSTALLED | grep -i latest",
unless => "${pip_env} search ${proxy_flag} ${source} | grep -i INSTALLED | grep -i latest",
user => $owner,
cwd => $cwd,
environment => $environment,
Expand Down
2 changes: 1 addition & 1 deletion manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@
purge => true,
}
} else {
fail( "Illegal ensure value: $ensure. Expected (present or absent)")
fail( "Illegal ensure value: ${ensure}. Expected (present or absent)")
}
}
6 changes: 5 additions & 1 deletion manifests/requirements.pp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
# [*log_dir*]
# String. Log directory.
#
# [*timeout*]
# The maximum time in seconds the "pip install" command should take. Default: 1800
#
# === Examples
#
# python::requirements { '/var/www/project1/requirements.txt':
Expand All @@ -70,6 +73,7 @@
$extra_pip_args = '',
$fix_requirements_owner = true,
$log_dir = '/tmp',
$timeout = 1800,
) {

if $virtualenv == 'system' and ($owner != 'root' or $group != 'root') {
Expand Down Expand Up @@ -122,7 +126,7 @@
provider => shell,
command => "${pip_env} --log ${log}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements} ${extra_pip_args}",
refreshonly => !$forceupdate,
timeout => 1800,
timeout => $timeout,
cwd => $cwd,
user => $owner,
subscribe => File[$requirements],
Expand Down
4 changes: 2 additions & 2 deletions manifests/virtualenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
default => 'setuptools',
}
$pypi_index = $index ? {
false => '',
default => "-i ${index}",
false => '',
default => "-i ${index}",
}

# Python 2.6 and older does not support setuptools/distribute > 0.8 which
Expand Down
34 changes: 34 additions & 0 deletions spec/acceptance/virtualenv_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'spec_helper_acceptance'

describe 'python class' do

context 'default parameters' do
# Using puppet_apply as a helper
it 'should work with no errors' do
pp = <<-EOS
class { 'python' :
version => 'system',
pip => true,
virtualenv => true,
}
->
python::virtualenv { 'venv' :
ensure => present,
systempkgs => false,
venv_dir => '/opt/venv',
owner => 'root',
group => 'root',
}
->
python::pip { 'rpyc' :
ensure => '3.2.3',
virtualenv => '/opt/venv',
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true)
end
end
end
56 changes: 56 additions & 0 deletions spec/defines/pip_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
require 'spec_helper'

describe 'python::pip', :type => :define do
let (:title) { 'rpyc' }
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 "virtualenv as" do
context "fails with non qualified path" do
let (:params) {{ :virtualenv => "venv" }}
it { is_expected.to raise_error(/"venv" is not an absolute path./) }
end
context "suceeds with qualified path" do
let (:params) {{ :virtualenv => "/opt/venv" }}
it { is_expected.to contain_exec("pip_install_rpyc").with_cwd('/opt/venv') }
end
context "defaults to system" do
let (:params) {{ }}
it { is_expected.to contain_exec("pip_install_rpyc").with_cwd('/') }
end
end

describe "proxy as" do
context "defaults to empty" do
let (:params) {{ }}
it { is_expected.to contain_exec("pip_install_rpyc").without_command(/--proxy/) }
end
context "does not add proxy to search command if set to latest and proxy is unset" do
let (:params) {{ :ensure => 'latest' }}
it { is_expected.to contain_exec("pip_install_rpyc").without_command(/--proxy/) }
it { is_expected.to contain_exec("pip_install_rpyc").without_unless(/--proxy/) }
end
context "adds proxy to install command if proxy set" do
let (:params) {{ :proxy => "http://my.proxy:3128" }}
it { is_expected.to contain_exec("pip_install_rpyc").with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --proxy=http://my.proxy:3128 rpyc ;}") }
end
context "adds proxy to search command if set to latest" do
let (:params) {{ :proxy => "http://my.proxy:3128", :ensure => 'latest' }}
it { is_expected.to contain_exec("pip_install_rpyc").with_command("pip wheel --help > /dev/null 2>&1 && { pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { pip --log /tmp/pip.log install --upgrade $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --upgrade --proxy=http://my.proxy:3128 rpyc ;}") }
it { is_expected.to contain_exec("pip_install_rpyc").with_unless('pip search --proxy=http://my.proxy:3128 rpyc | grep -i INSTALLED | grep -i latest') }
end
end

end
end
32 changes: 32 additions & 0 deletions spec/unit/facter/pip_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "spec_helper"

describe Facter::Util::Fact do
before {
Facter.clear
}

let(:pip_version_output) { <<-EOS
pip 6.0.6 from /opt/boxen/homebrew/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip-6.0.6-py2.7.egg (python 2.7)
EOS
}

describe "pip_version" do
context 'returns pip version when pip present' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with("pip").returns(true)
Facter::Util::Resolution.expects(:exec).with("pip --version 2>&1").returns(pip_version_output)
Facter.value(:pip_version).should == "6.0.6"
end
end

context 'returns nil when pip not present' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with("pip").returns(false)
Facter.value(:pip_version).should == nil
end
end

end
end
32 changes: 32 additions & 0 deletions spec/unit/facter/python_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "spec_helper"

describe Facter::Util::Fact do
before {
Facter.clear
}

let(:python_version_output) { <<-EOS
Python 2.7.9
EOS
}

describe "python_version" do
context 'returns python version when python present' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with("python").returns(true)
Facter::Util::Resolution.expects(:exec).with("python -V 2>&1").returns(python_version_output)
Facter.value(:python_version).should == "2.7.9"
end
end

context 'returns nil when python not present' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with("python").returns(false)
Facter.value(:python_version).should == nil
end
end

end
end
32 changes: 32 additions & 0 deletions spec/unit/facter/virtualenv_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require "spec_helper"

describe Facter::Util::Fact do
before {
Facter.clear
}

let(:virtualenv_version_output) { <<-EOS
12.0.7
EOS
}

describe "virtualenv_version" do
context 'returns virtualenv version when virtualenv present' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with("virtualenv").returns(true)
Facter::Util::Resolution.expects(:exec).with("virtualenv --version 2>&1").returns(virtualenv_version_output)
Facter.value(:virtualenv_version).should == "12.0.7"
end
end

context 'returns nil when virtualenv not present' do
it do
Facter::Util::Resolution.stubs(:exec)
Facter::Util::Resolution.expects(:which).with("virtualenv").returns(false)
Facter.value(:virtualenv_version).should == nil
end
end

end
end
1 change: 1 addition & 0 deletions tests/requirements.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
python::requirements { '/var/www/project1/requirements.txt':
virtualenv => 'system',
proxy => 'http://proxy.domain.com:3128',
timeout => 2400,
}