Skip to content

Commit

Permalink
Add option for not managing python,virtualenv, pip packages.
Browse files Browse the repository at this point in the history
Helps in cases where other modules are already managing those packages,
avoids duplicate resource definition issues.
  • Loading branch information
Tomislav Dukaric authored and bastelfreak committed Apr 26, 2020
1 parent fe96d62 commit 5e8bfe9
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 29 deletions.
16 changes: 16 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ The default umask for invoked exec calls.

Default value: `undef`

##### `manage_python_package`

Data type: `Boolean`

Whether to manage python package or not.

Default value: $python::params::manage_python_package

##### `manage_virtualenv_package`

Data type: `Boolean`

Whether to manage virtualenv package or not.

Default value: $python::params::manage_virtualenv_package

##### `gunicorn_package_name`

Data type: `Any`
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
41 changes: 41 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,13 +62,29 @@
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

describe 'with python::manage_python_package' do
context 'true/default/empty' do
it { is_expected.to compile.with_all_deps }

end
end

describe 'with python::manage_virtualenv_package' do
context 'true/default/empty' do
it { is_expected.to compile.with_all_deps }

end
end

describe 'with python::virtualenv, without python::dev' do
context 'true' do
let(:params) { { dev: 'absent', virtualenv: 'present' } }
Expand Down

0 comments on commit 5e8bfe9

Please sign in to comment.