Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 5263759

Browse files
committed
Merge pull request voxpupuli#117 from poikilotherm/master
Added validations to init.pp, fixed some tests.
2 parents 520c6b4 + a71ee7c commit 5263759

4 files changed

Lines changed: 51 additions & 10 deletions

File tree

manifests/init.pp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@
55
# === Parameters
66
#
77
# [*version*]
8-
# Python version to install. Default: system default
8+
# Python version to install. Beware that valid values for this differ a) by
9+
# the provider you choose and b) by the osfamily/operatingsystem you are using.
10+
# Default: system default
11+
# Allowed values:
12+
# - provider == pip: everything pip allows as a version after the 'python=='
13+
# - else: 'system', 'pypy', 3/3.3/...
14+
# - Be aware that 'system' usually means python 2.X.
15+
# - 'pypy' actually lets us use pypy as python.
16+
# - 3/3.3/... means you are going to install the python3/python3.3/...
17+
# package, if available on your osfamily.
918
#
1019
# [*pip*]
1120
# Install python-pip. Default: true
@@ -23,6 +32,11 @@
2332
# [*manage_gunicorn*]
2433
# Allow Installation / Removal of Gunicorn. Default: true
2534
#
35+
# [*provider*]
36+
# What provider to use for installation of the packages, except gunicorn.
37+
# Default: system default provider
38+
# Allowed values: 'pip'
39+
#
2640
# === Examples
2741
#
2842
# class { 'python':
@@ -47,6 +61,24 @@
4761
$provider = undef
4862
) {
4963

64+
# validate inputs
65+
if $provider != undef {
66+
validate_re($provider, ['^pip$'], 'Only "pip" is a valid provider besides the system default.')
67+
}
68+
69+
if $provider == 'pip' {
70+
validate_re($version, ['^(2\.[4-7]\.\d|3\.\d\.\d)$','^system$'])
71+
# this will only be checked if not pip, every other string would be rejected by provider check
72+
} else {
73+
validate_re($version, concat(['system', 'pypy'], $::python::install::valid_versions))
74+
}
75+
76+
validate_bool($pip)
77+
validate_bool($dev)
78+
validate_bool($virtualenv)
79+
validate_bool($gunicorn)
80+
validate_bool($manage_gunicorn)
81+
5082
# Module compatibility check
5183
$compatible = [ 'Debian', 'RedHat']
5284
if ! ($::osfamily in $compatible) {

manifests/install.pp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515

1616
class python::install {
1717

18-
$python = $python::version ? {
18+
$valid_version = $::osfamily ? {
19+
'RedHat' => ['3'],
20+
'Debian' => ['3', '3.3']
21+
}
22+
23+
$python = $::python::version ? {
1924
'system' => 'python',
2025
'pypy' => 'pypy',
2126
default => "python${python::version}",
@@ -26,6 +31,13 @@
2631
'Debian' => "${python}-dev"
2732
}
2833

34+
# pip version: use only for installation via os package manager!
35+
if $::python::version =~ /^3/ {
36+
$pip = 'python3-pip'
37+
} else {
38+
$pip = 'python-pip'
39+
}
40+
2941
$dev_ensure = $python::dev ? {
3042
true => present,
3143
default => absent,
@@ -46,12 +58,11 @@
4658
pip: {
4759
package { 'virtualenv': ensure => latest, provider => pip }
4860
package { 'pip': ensure => latest, provider => pip }
49-
package { $pythondev: ensure => latest }
5061
package { "python==${python::version}": ensure => latest, provider => pip }
5162
}
5263
default: {
5364
package { 'python-virtualenv': ensure => $venv_ensure }
54-
package { 'python-pip': ensure => $pip_ensure }
65+
package { $pip: ensure => $pip_ensure }
5566
package { $pythondev: ensure => $dev_ensure }
5667
package { $python: ensure => present }
5768
}

manifests/virtualenv.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167

168168
python::requirements { "${requirements}_${venv_dir}":
169169
requirements => $requirements,
170-
virtualenv => $venv_dir,
170+
virtualenv => $venv_dir,
171171
proxy => $proxy,
172172
owner => $owner,
173173
group => $group,

spec/classes/python_spec.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
end
7373
end
7474

75-
describe "with python::virtualenv" do
75+
describe "without python::virtualenv" do
7676
context "default/empty" do
77-
let (:params) {{ :provider => '', :virtualenv => '' }}
77+
let (:params) {{ :provider => '' }}
7878
it { is_expected.to contain_package("python-virtualenv").with_ensure('absent') }
7979
end
8080
end
@@ -87,7 +87,6 @@
8787
it { is_expected.to contain_package("python-dev").with_ensure('present') }
8888
end
8989
context "default/empty" do
90-
let (:params) {{ :dev => '' }}
9190
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
9291
end
9392
end
@@ -165,7 +164,7 @@
165164

166165
describe "with python::virtualenv" do
167166
context "default/empty" do
168-
let (:params) {{ :provider => '', :virtualenv => '' }}
167+
let (:params) {{ :provider => '' }}
169168
it { is_expected.to contain_package("python-virtualenv").with_ensure('absent') }
170169
end
171170
end
@@ -178,7 +177,6 @@
178177
it { is_expected.to contain_package("python-devel").with_ensure('present') }
179178
end
180179
context "default/empty" do
181-
let (:params) {{ :dev => '' }}
182180
it { is_expected.to contain_package("python-devel").with_ensure('absent') }
183181
end
184182
end

0 commit comments

Comments
 (0)