Skip to content

Commit

Permalink
Merge pull request #500 from tdukaric/choose_to_manage_packages
Browse files Browse the repository at this point in the history
Add option for not managing python and virtualenv packages.
  • Loading branch information
bastelfreak authored Apr 26, 2020
2 parents fe96d62 + a6b8f4d commit b519893
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 29 deletions.
40 changes: 40 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,30 @@ The default umask for invoked exec calls.

Default value: `undef`

##### `manage_python_package`

Data type: `Boolean`



Default value: $python::params::manage_python_package

##### `manage_virtualenv_package`

Data type: `Boolean`



Default value: $python::params::manage_virtualenv_package

##### `manage_pip_package`

Data type: `Boolean`



Default value: $python::params::manage_pip_package

##### `gunicorn_package_name`

Data type: `Any`
Expand Down Expand Up @@ -277,6 +301,14 @@ Proxy server to use for outbound connections.

Default value: `undef`

##### `exec_provider`

Data type: `String[1]`



Default value: 'shell'

## Defined types

### python::dotfile
Expand Down Expand Up @@ -746,6 +778,14 @@ Data type: `Array[String]`

Default value: ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin']

##### `exec_provider`

Data type: `String[1]`



Default value: 'shell'

### python::pyvenv

Create a Python3 virtualenv using pyvenv.
Expand Down
3 changes: 3 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
Enum['absent', 'present', 'latest'] $virtualenv = $python::params::virtualenv,
Enum['absent', 'present', 'latest'] $gunicorn = $python::params::gunicorn,
Boolean $manage_gunicorn = $python::params::manage_gunicorn,
Boolean $manage_python_package = $python::params::manage_python_package,
Boolean $manage_virtualenv_package = $python::params::manage_virtualenv_package,
Boolean $manage_pip_package = $python::params::manage_pip_package,
$gunicorn_package_name = $python::params::gunicorn_package_name,
Optional[Enum['pip', 'scl', 'rhscl', 'anaconda', '']] $provider = $python::params::provider,
$valid_versions = $python::params::valid_versions,
Expand Down
48 changes: 29 additions & 19 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,29 @@
}
}

package { 'python':
ensure => $python::ensure,
name => $python,
if $python::manage_python_package {
package { 'python':
ensure => $python::ensure,
name => $python,
}
}

package { 'virtualenv':
ensure => $venv_ensure,
name => "${python}-virtualenv",
require => Package['python'],
if $python::manage_virtualenv_package {
package { 'virtualenv':
ensure => $venv_ensure,
name => "${python}-virtualenv",
require => Package['python'],
}
}

case $python::provider {
'pip': {

package { 'pip':
ensure => $pip_ensure,
require => Package['python'],
if $python::manage_pip_package {
package { 'pip':
ensure => $pip_ensure,
require => Package['python'],
}
}

if $pythondev {
Expand Down Expand Up @@ -205,10 +211,12 @@
version => 'pip3',
}
} else {
package { 'python-pip':
ensure => $pip_ensure,
require => Package['python'],
provider => 'yum',
if $python::manage_pip_package {
package { 'python-pip':
ensure => $pip_ensure,
require => Package['python'],
provider => 'yum',
}
}
}
if $pythondev {
Expand All @@ -222,9 +230,11 @@

}
default: {
package { 'pip':
ensure => $pip_ensure,
require => Package['python'],
if $python::manage_pip_package {
package { 'pip':
ensure => $pip_ensure,
require => Package['python'],
}
}
if $pythondev {
package { 'python-dev':
Expand All @@ -242,8 +252,8 @@
if $pip_ensure != 'absent' {
if $python::use_epel == true {
include 'epel'
Class['epel'] -> Package['pip']
Class['epel'] -> Package['python']
if $python::manage_pip_package { Class['epel'] -> Package['pip'] }
if $python::manage_python_package { Class['epel'] -> Package['python'] }
}
}
if ($venv_ensure != 'absent') and ($facts['os']['release']['full'] =~ /^6/) {
Expand Down
23 changes: 13 additions & 10 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
# The python Module default configuration settings.
#
class python::params {
$ensure = 'present'
$version = 'system'
$pip = 'present'
$dev = 'absent'
$virtualenv = 'absent'
$gunicorn = 'absent'
$manage_gunicorn = true
$provider = undef
$valid_versions = undef
$manage_scl = true
$ensure = 'present'
$version = 'system'
$pip = 'present'
$dev = 'absent'
$virtualenv = 'absent'
$gunicorn = 'absent'
$manage_gunicorn = true
$manage_python_package = true
$manage_virtualenv_package = true
$manage_pip_package = true
$provider = undef
$valid_versions = undef
$manage_scl = true

if $facts['os']['family'] == 'RedHat' {
if $facts['os']['name'] != 'Fedora' {
Expand Down
27 changes: 27 additions & 0 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,31 @@
facts
end

context 'with defaults' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_class('python::install') }
it { is_expected.to contain_class('python::params') }
it { is_expected.to contain_class('python::config') }
it { is_expected.to contain_package('python') }
it { is_expected.to contain_package('virtualenv') }
it { is_expected.to contain_package('pip') }
end

context 'without managing things' do
let :params do
{
manage_python_package: false,
manage_virtualenv_package: false,
manage_pip_package: false
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.not_to contain_package('python') }
it { is_expected.not_to contain_package('virtualenv') }
it { is_expected.not_to contain_package('pip') }
end

case facts[:os]['family']
when 'Debian'

Expand Down Expand Up @@ -37,9 +62,11 @@
context 'true' do
let(:params) { { dev: 'present' } }

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('python-dev').with_ensure('present') }
end
context 'empty/default' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_package('python-dev').with_ensure('absent') }
end
end
Expand Down

0 comments on commit b519893

Please sign in to comment.