Skip to content

Commit dc8f8b7

Browse files
committed
Validates given virtualenv path is valid
The issue was from voxpupuli#165, the virtualenv given didn't give the full path, we now fail early to catch this. Also adds an rspec to catch this, and a beaker test based on the scenario given in voxpupuli#165
1 parent 87fde47 commit dc8f8b7

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

manifests/pip.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
default => $virtualenv,
8888
}
8989

90+
validate_absolute_path($cwd)
91+
9092
$log = $virtualenv ? {
9193
'system' => $log_dir,
9294
default => $virtualenv,

spec/acceptance/virtualenv_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'python class' do
4+
5+
context 'default parameters' do
6+
# Using puppet_apply as a helper
7+
it 'should work with no errors' do
8+
pp = <<-EOS
9+
class { 'python' :
10+
version => 'system',
11+
pip => true,
12+
virtualenv => true,
13+
}
14+
->
15+
python::virtualenv { 'venv' :
16+
ensure => present,
17+
systempkgs => false,
18+
venv_dir => '/opt/venv',
19+
owner => 'root',
20+
group => 'root',
21+
}
22+
->
23+
python::pip { 'rpyc' :
24+
ensure => '3.2.3',
25+
virtualenv => '/opt/venv',
26+
}
27+
EOS
28+
29+
# Run it twice and test for idempotency
30+
apply_manifest(pp, :catch_failures => true)
31+
apply_manifest(pp, :catch_changes => true)
32+
end
33+
end
34+
end

spec/defines/pip_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper'
2+
3+
describe 'python::pip', :type => :define do
4+
let (:title) { 'rpyc' }
5+
context "on Debian OS" do
6+
let :facts do
7+
{
8+
:id => 'root',
9+
:kernel => 'Linux',
10+
:lsbdistcodename => 'squeeze',
11+
:osfamily => 'Debian',
12+
:operatingsystem => 'Debian',
13+
:operatingsystemrelease => '6',
14+
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
15+
:concat_basedir => '/dne',
16+
}
17+
end
18+
19+
describe "virtualenv as" do
20+
context "fails with non qualified path" do
21+
let (:params) {{ :virtualenv => "venv" }}
22+
it { is_expected.to raise_error(/"venv" is not an absolute path./) }
23+
end
24+
context "suceeds with qualified path" do
25+
let (:params) {{ :virtualenv => "/opt/venv" }}
26+
it { is_expected.to contain_exec("pip_install_rpyc").with_cwd('/opt/venv') }
27+
end
28+
context "defaults to system" do
29+
let (:params) {{ }}
30+
it { is_expected.to contain_exec("pip_install_rpyc").with_cwd('/') }
31+
end
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)