Skip to content

Commit e117ac1

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 e117ac1

File tree

1 file changed

+67
-57
lines changed

1 file changed

+67
-57
lines changed

spec/defines/pyvenv_spec.rb

Lines changed: 67 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,83 +6,93 @@
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+
context 'with default parameters' do
30+
it { is_expected.to contain_file('/opt/env').that_requires('Class[python::install]') }
31+
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') }
32+
end
33+
34+
describe 'when ensure' do
35+
context 'is absent' do
36+
let :params do
37+
{
38+
ensure: 'absent'
39+
}
40+
end
41+
42+
it {
43+
expect(subject).to contain_file('/opt/env').with_ensure('absent').with_purge(true)
44+
}
45+
end
46+
end
2347
end
2448

25-
describe 'when ensure' do
26-
context 'is absent' do
49+
context "prompt on #{os} with python 3.6" do
50+
let :facts do
51+
# python 3.6 is required for venv and prompt
52+
facts.merge(
53+
python3_version: '3.6.1'
54+
)
55+
end
56+
let :title do
57+
'/opt/env'
58+
end
59+
60+
context 'with prompt' do
2761
let :params do
2862
{
29-
ensure: 'absent'
63+
prompt: 'custom prompt',
3064
}
3165
end
3266

3367
it {
34-
expect(subject).to contain_file('/opt/env').with_ensure('absent').with_purge(true)
68+
is_expected.to contain_file('/opt/env').that_requires('Class[python::install]')
69+
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')
3570
}
3671
end
3772
end
38-
end
39-
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
5073

51-
context 'with prompt' do
52-
let :params do
53-
{
54-
prompt: 'custom prompt',
55-
}
74+
context "prompt on #{os} with python 3.5" do
75+
let :facts do
76+
facts.merge(
77+
python3_version: '3.5.1'
78+
)
79+
end
80+
let :title do
81+
'/opt/env'
5682
end
5783

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
84+
context 'with prompt' do
85+
let :params do
86+
{
87+
prompt: 'custom prompt',
88+
}
89+
end
7490

75-
context 'with prompt' do
76-
let :params do
77-
{
78-
prompt: 'custom prompt',
91+
it {
92+
is_expected.to contain_file('/opt/env').that_requires('Class[python::install]')
93+
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')
7994
}
8095
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-
}
8696
end
8797
end
8898
end

0 commit comments

Comments
 (0)