From a6b8f4dd6b6faea0b2439d42b2f2686be8037fb9 Mon Sep 17 00:00:00 2001 From: Tomislav Dukaric Date: Wed, 3 Jul 2019 17:42:39 +0900 Subject: [PATCH] Add option for not managing python,virtualenv, pip packages. Helps in cases where other modules are already managing those packages, avoids duplicate resource definition issues. --- REFERENCE.md | 40 +++++++++++++++++++++++++++++++ manifests/init.pp | 3 +++ manifests/install.pp | 48 ++++++++++++++++++++++--------------- manifests/params.pp | 23 ++++++++++-------- spec/classes/python_spec.rb | 27 +++++++++++++++++++++ 5 files changed, 112 insertions(+), 29 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 69e58da4..069496bd 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -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` @@ -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 @@ -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. diff --git a/manifests/init.pp b/manifests/init.pp index 8b622683..e2071925 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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, diff --git a/manifests/install.pp b/manifests/install.pp index a00fc94c..6861c5e9 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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 { @@ -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 { @@ -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': @@ -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/) { diff --git a/manifests/params.pp b/manifests/params.pp index 0444d756..af9bfd4d 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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' { diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index ec1120cf..ef6c10db 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -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' @@ -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