Skip to content

Commit 81daea2

Browse files
committed
Add a unit test to illustrate the pyvenv bootstrap issue
This module that manage python needs python to be installed in order to work properly under certain conditions. When python is not installed on a node, the python_version fact does not have a value. When using `python::pyvenv` on such a system without a specific version set, a call of the split() function on this unde value cause an error te be raised: ``` Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, The function 'split' was called with arguments it does not accept. It expects one of: (String str, String pattern) rejected: parameter 'str' expects a String value, got Undef (String str, Regexp pattern) rejected: parameter 'str' expects a String value, got Undef (String str, Type[Regexp] pattern) rejected: parameter 'str' expects a String value, got Undef (Sensitive[String] sensitive, String pattern) rejected: parameter 'sensitive' expects a Sensitive[String] value, got Undef (Sensitive[String] sensitive, Regexp pattern) rejected: parameter 'sensitive' expects a Sensitive[String] value, got Undef (Sensitive[String] sensitive, Type[Regexp] pattern) rejected: parameter 'sensitive' expects a Sensitive[String] value, got Undef (file: /etc/puppetlabs/code/environments/production/modules/python/manifests/pyvenv.pp, line: 48, column: 34) (file: /etc/puppetlabs/code/environments/production/modules/taiga/manifests/back/install.pp, line: 15) on node debian12-64-puppet7.example.com ```
1 parent 16043ea commit 81daea2

File tree

1 file changed

+68
-57
lines changed

1 file changed

+68
-57
lines changed

spec/defines/pyvenv_spec.rb

Lines changed: 68 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,83 +6,94 @@
66
on_supported_os.each do |os, facts|
77
next if os == 'gentoo-3-x86_64'
88

9+
let :title do
10+
'/opt/env'
11+
end
12+
913
context "on #{os}" do
10-
let :facts do
11-
# python3 is required to use pyvenv
12-
facts.merge(
13-
python3_version: '3.5.1'
14-
)
15-
end
16-
let :title do
17-
'/opt/env'
14+
context 'with default parameters' do
15+
let :facts do
16+
facts
17+
end
18+
19+
it { is_expected.to compile }
1820
end
1921

20-
context 'with default parameters' do
21-
it { is_expected.to contain_file('/opt/env').that_requires('Class[python::install]') }
22-
it { is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.5 --clear /opt/env && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade pip && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade setuptools') }
22+
context 'with a specific python3 version' do
23+
let :facts do
24+
# python3 is required to use pyvenv
25+
facts.merge(
26+
python3_version: '3.5.1'
27+
)
28+
end
29+
30+
context 'with default parameters' do
31+
it { is_expected.to contain_file('/opt/env').that_requires('Class[python::install]') }
32+
it { is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.5 --clear /opt/env && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade pip && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade setuptools') }
33+
end
34+
35+
describe 'when ensure' do
36+
context 'is absent' do
37+
let :params do
38+
{
39+
ensure: 'absent'
40+
}
41+
end
42+
43+
it {
44+
expect(subject).to contain_file('/opt/env').with_ensure('absent').with_purge(true)
45+
}
46+
end
47+
end
2348
end
2449

25-
describe 'when ensure' do
26-
context 'is absent' do
50+
context "prompt on #{os} with python 3.6" do
51+
let :facts do
52+
# python 3.6 is required for venv and prompt
53+
facts.merge(
54+
python3_version: '3.6.1'
55+
)
56+
end
57+
let :title do
58+
'/opt/env'
59+
end
60+
61+
context 'with prompt' do
2762
let :params do
2863
{
29-
ensure: 'absent'
64+
prompt: 'custom prompt',
3065
}
3166
end
3267

3368
it {
34-
expect(subject).to contain_file('/opt/env').with_ensure('absent').with_purge(true)
69+
is_expected.to contain_file('/opt/env').that_requires('Class[python::install]')
70+
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('python3.6 -m venv --clear --prompt custom\\ prompt /opt/env && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade pip && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade setuptools')
3571
}
3672
end
3773
end
38-
end
3974

40-
context "prompt on #{os} with python 3.6" do
41-
let :facts do
42-
# python 3.6 is required for venv and prompt
43-
facts.merge(
44-
python3_version: '3.6.1'
45-
)
46-
end
47-
let :title do
48-
'/opt/env'
49-
end
50-
51-
context 'with prompt' do
52-
let :params do
53-
{
54-
prompt: 'custom prompt',
55-
}
75+
context "prompt on #{os} with python 3.5" do
76+
let :facts do
77+
facts.merge(
78+
python3_version: '3.5.1'
79+
)
80+
end
81+
let :title do
82+
'/opt/env'
5683
end
5784

58-
it {
59-
is_expected.to contain_file('/opt/env').that_requires('Class[python::install]')
60-
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('python3.6 -m venv --clear --prompt custom\\ prompt /opt/env && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade pip && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade setuptools')
61-
}
62-
end
63-
end
64-
65-
context "prompt on #{os} with python 3.5" do
66-
let :facts do
67-
facts.merge(
68-
python3_version: '3.5.1'
69-
)
70-
end
71-
let :title do
72-
'/opt/env'
73-
end
85+
context 'with prompt' do
86+
let :params do
87+
{
88+
prompt: 'custom prompt',
89+
}
90+
end
7491

75-
context 'with prompt' do
76-
let :params do
77-
{
78-
prompt: 'custom prompt',
92+
it {
93+
is_expected.to contain_file('/opt/env').that_requires('Class[python::install]')
94+
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.5 --clear /opt/env && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade pip && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade setuptools')
7995
}
8096
end
81-
82-
it {
83-
is_expected.to contain_file('/opt/env').that_requires('Class[python::install]')
84-
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.5 --clear /opt/env && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade pip && /opt/env/bin/pip --log /opt/env/pip.log install --upgrade setuptools')
85-
}
8697
end
8798
end
8899
end

0 commit comments

Comments
 (0)