From 8591aed9e8ba0a24a64914f8c302ffc4a8178f6d Mon Sep 17 00:00:00 2001 From: Alex Cullen Date: Thu, 19 Aug 2021 12:08:31 -0400 Subject: [PATCH 01/10] If user declares their own requirements, don't set subscribe to undef. --- manifests/requirements.pp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/manifests/requirements.pp b/manifests/requirements.pp index 9d245be3..e8c253fa 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -88,11 +88,8 @@ replace => false, content => '# Puppet will install and/or update pip packages listed here', } - - $local_subscribe = File[$requirements] - } else { - $local_subscribe = undef } + $local_subscribe = File[$requirements] exec { "python_requirements${name}": provider => shell, From f962dc943a6b4cc070f02fd167369c6a0bfec367 Mon Sep 17 00:00:00 2001 From: Alex Cullen <62033527+acullenhms@users.noreply.github.com> Date: Fri, 27 Aug 2021 11:50:29 -0400 Subject: [PATCH 02/10] Add declared requirements install test (#1) Add unit test for verifying requirements installation to declared venv --- .../declared_requirements_install_spec.rb | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 spec/acceptance/declared_requirements_install_spec.rb diff --git a/spec/acceptance/declared_requirements_install_spec.rb b/spec/acceptance/declared_requirements_install_spec.rb new file mode 100644 index 00000000..185e6db2 --- /dev/null +++ b/spec/acceptance/declared_requirements_install_spec.rb @@ -0,0 +1,24 @@ +require 'spec_helper_acceptance' + +describe 'requirements' do + it 'checks declared requirements file is installed to venv' do + pp = <<-EOS + file { '/tmp/requirements.txt': + ensure => 'present', + content => 'requests', + } + + python::pyvenv { '/tmp/pyvenv': + ensure => 'present', + } + + python::requirements { '/tmp/requirements.txt': + virtualenv => '/tmp/pyvenv' + } + EOS + + apply_manifest(pp, catch_failures: true) + + expect(shell('/tmp/pyvenv/bin/pip3 list --no-index | grep requests').stdout).to match(%r{requests +\d+.\d+.\d+}) + end +end From b8c374167ec7013f35e1473699812a9c4c4d751e Mon Sep 17 00:00:00 2001 From: Alex Cullen Date: Tue, 4 Jan 2022 15:55:04 -0500 Subject: [PATCH 03/10] use ensure_package instead of package for python install (test) --- manifests/install.pp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index 4645bdcb..dd827e36 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -36,10 +36,15 @@ } if $python::manage_python_package { - package { 'python': - ensure => $python::ensure, - name => $python, - } + ensure_package({ + 'python' => { + ensure => $python::ensure + } + }) + # package { 'python': + # ensure => $python::ensure, + # name => $python, + # } } case $python::provider { From 680bd8c83351e27aa574d11b2c3cb80d3f8338f5 Mon Sep 17 00:00:00 2001 From: Alex Cullen Date: Tue, 4 Jan 2022 16:12:38 -0500 Subject: [PATCH 04/10] revert use ensure_package instead of package for python install (test) --- manifests/install.pp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index dd827e36..4645bdcb 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -36,15 +36,10 @@ } if $python::manage_python_package { - ensure_package({ - 'python' => { - ensure => $python::ensure - } - }) - # package { 'python': - # ensure => $python::ensure, - # name => $python, - # } + package { 'python': + ensure => $python::ensure, + name => $python, + } } case $python::provider { From bba491a573506e4cb58e5a930f2c2dd34e8fd4f4 Mon Sep 17 00:00:00 2001 From: Alex Cullen Date: Tue, 22 Feb 2022 14:06:51 -0500 Subject: [PATCH 05/10] replace all package declarations with ensure_packages() --- manifests/install.pp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index 4645bdcb..a3daef14 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -36,26 +36,26 @@ } if $python::manage_python_package { - package { 'python': + ensure_packages (['python'], ensure => $python::ensure, name => $python, - } + ) } case $python::provider { 'pip': { if $python::manage_pip_package { - package { 'pip': + ensure_packages (['pip'], ensure => $pip_ensure, require => Package['python'], - } + ) } if $pythondev { - package { 'python-dev': + ensure_packages (['python-dev'], ensure => $dev_ensure, name => $pythondev, - } + ) } # Respect the $pip_ensure setting @@ -182,28 +182,28 @@ } if $pythondev { - package { 'python-dev': - ensure => $dev_ensure, - name => $pythondev, - alias => $pythondev, + ensure_packages (['python-dev'], + ensure => $dev_ensure, + name => $pythondev, + alias => $pythondev, provider => 'yum', - } + ) } } default: { if $python::manage_pip_package { - package { 'pip': + ensure_packages (['pip'], ensure => $pip_ensure, require => Package['python'], - } + ) } if $pythondev { - package { 'python-dev': + ensure_packages (['python-dev'], ensure => $dev_ensure, name => $pythondev, alias => $pythondev, - } + ) } } } From 6ca453bddf6dba5c9ea111d2c58295b619e60114 Mon Sep 17 00:00:00 2001 From: Stefan Goethals Date: Fri, 8 Sep 2023 10:23:00 +0200 Subject: [PATCH 06/10] Update declared_requirements_install_spec.rb Add # frozen_string_literal: true required by rubocop check --- spec/acceptance/declared_requirements_install_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/acceptance/declared_requirements_install_spec.rb b/spec/acceptance/declared_requirements_install_spec.rb index 185e6db2..bc9c07d4 100644 --- a/spec/acceptance/declared_requirements_install_spec.rb +++ b/spec/acceptance/declared_requirements_install_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'requirements' do From 8564e713b1944fad8768199d42793357d4ef3ce6 Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Mon, 11 Sep 2023 13:36:09 +0200 Subject: [PATCH 07/10] Use 'installed' because ensure_packages() forces it https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/lib/puppet/functions/stdlib/ensure_packages.rb#L36-L37 --- spec/classes/python_spec.rb | 24 ++++++++++++------------ types/package/ensure.pp | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index cca3ef65..3ef04fb1 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -50,15 +50,15 @@ { manage_pip_package: true, manage_venv_package: true, - pip: 'present', - venv: 'present' + pip: 'installed', + venv: 'installed' } end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_package('pip').with(ensure: 'present') } + it { is_expected.to contain_package('pip').with(ensure: 'installed') } - it { is_expected.to contain_package('python-venv').with(ensure: 'present') } unless facts[:os]['name'] == 'CentOS' + it { is_expected.to contain_package('python-venv').with(ensure: 'installed') } unless facts[:os]['name'] == 'CentOS' end case facts[:os]['family'] @@ -86,10 +86,10 @@ # rubocop:disable RSpec/RepeatedExampleGroupDescription describe 'with python::dev' do context 'true' do - let(:params) { { dev: 'present' } } + let(:params) { { dev: 'installed' } } it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_package('python-dev').with_ensure('present') } + it { is_expected.to contain_package('python-dev').with_ensure('installed') } end context 'empty/default' do @@ -233,9 +233,9 @@ describe 'with python::dev' do context 'true' do - let(:params) { { dev: 'present' } } + let(:params) { { dev: 'installed' } } - it { is_expected.to contain_package('python-dev').with_ensure('present') } + it { is_expected.to contain_package('python-dev').with_ensure('installed') } end context 'default/empty' do @@ -417,9 +417,9 @@ describe 'with python::dev' do context 'true' do - let(:params) { { dev: 'present' } } + let(:params) { { dev: 'installed' } } - it { is_expected.to contain_package('python-dev').with_ensure('present') } + it { is_expected.to contain_package('python-dev').with_ensure('installed') } end context 'empty/default' do @@ -467,9 +467,9 @@ describe 'with python::dev' do context 'true' do - let(:params) { { dev: 'present' } } + let(:params) { { dev: 'installed' } } - it { is_expected.to contain_package('python-dev').with_ensure('present') } + it { is_expected.to contain_package('python-dev').with_ensure('installed') } end context 'default/empty' do diff --git a/types/package/ensure.pp b/types/package/ensure.pp index 34189e4b..9fa54968 100644 --- a/types/package/ensure.pp +++ b/types/package/ensure.pp @@ -1,3 +1,3 @@ # @summary Match all valid package ensures for python # -type Python::Package::Ensure = Enum['absent', 'present', 'latest'] +type Python::Package::Ensure = Enum['absent', 'present', 'installed', 'latest'] From 5c0646b73111d97382731289260249e8a1c891b7 Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Mon, 11 Sep 2023 13:43:13 +0200 Subject: [PATCH 08/10] Add 'installed' to package ensure See https://github.com/puppetlabs/puppetlabs-stdlib/blob/main/lib/puppet/functions/stdlib/ensure_packages.rb#L36-L37 --- REFERENCE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/REFERENCE.md b/REFERENCE.md index 2aac08b3..7cc88c03 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -1163,7 +1163,7 @@ Alias of `Enum['debug', 'info', 'warning', 'error', 'critical']` Match all valid package ensures for python -Alias of `Enum['absent', 'present', 'latest']` +Alias of `Enum['absent', 'present', 'installed', 'latest']` ### `Python::Provider` From 8881c431aa9403eaaa68c4dfd456a3b03c7223f0 Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Tue, 12 Sep 2023 09:52:54 +0200 Subject: [PATCH 09/10] Only set subscribe to a requirements.txt file if manage_requirements is true --- manifests/requirements.pp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/manifests/requirements.pp b/manifests/requirements.pp index 2f000bde..f2743509 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -88,8 +88,13 @@ replace => false, content => '# Puppet will install and/or update pip packages listed here', } + + $local_subscribe = File[$requirements] + } elsif File[$requirements] and $manage_requirements == true { + $local_subscribe = File[$requirements] + } else { + $local_subscribe = undef } - $local_subscribe = File[$requirements] exec { "python_requirements${name}": provider => shell, From fa9cbc41ca0764c9c7d923b3340a24eadea110ea Mon Sep 17 00:00:00 2001 From: Stefan - Zipkid - Goethals Date: Wed, 13 Sep 2023 14:31:51 +0200 Subject: [PATCH 10/10] Remove ensure-packages --- manifests/install.pp | 30 +++++++++++++++--------------- spec/classes/python_spec.rb | 24 ++++++++++++------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/manifests/install.pp b/manifests/install.pp index 33067e8e..6a738435 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -25,10 +25,10 @@ } if $python::manage_python_package { - ensure_packages (['python'], + package { 'python': ensure => $python::ensure, name => $python, - ) + } } if $python::manage_venv_package { @@ -47,17 +47,17 @@ case $python::provider { 'pip': { if $python::manage_pip_package { - ensure_packages (['pip'], + package { 'pip': ensure => $python::pip, require => Package['python'], - ) + } } if $pythondev { - ensure_packages (['python-dev'], + package { 'python-dev': ensure => $python::dev, name => $pythondev, - ) + } } # Respect the $python::pip setting @@ -180,28 +180,28 @@ } if $pythondev { - ensure_packages (['python-dev'], - ensure => $python::dev, - name => $pythondev, - alias => $pythondev, + package { 'python-dev': + ensure => $python::dev, + name => $pythondev, + alias => $pythondev, provider => 'yum', - ) + } } } default: { if $python::manage_pip_package { - ensure_packages (['pip'], + package { 'pip': ensure => $python::pip, require => Package['python'], - ) + } } if $pythondev { - ensure_packages (['python-dev'], + package { 'python-dev': ensure => $python::dev, name => $pythondev, alias => $pythondev, - ) + } } } } diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index 3ef04fb1..cca3ef65 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -50,15 +50,15 @@ { manage_pip_package: true, manage_venv_package: true, - pip: 'installed', - venv: 'installed' + pip: 'present', + venv: 'present' } end it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_package('pip').with(ensure: 'installed') } + it { is_expected.to contain_package('pip').with(ensure: 'present') } - it { is_expected.to contain_package('python-venv').with(ensure: 'installed') } unless facts[:os]['name'] == 'CentOS' + it { is_expected.to contain_package('python-venv').with(ensure: 'present') } unless facts[:os]['name'] == 'CentOS' end case facts[:os]['family'] @@ -86,10 +86,10 @@ # rubocop:disable RSpec/RepeatedExampleGroupDescription describe 'with python::dev' do context 'true' do - let(:params) { { dev: 'installed' } } + let(:params) { { dev: 'present' } } it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_package('python-dev').with_ensure('installed') } + it { is_expected.to contain_package('python-dev').with_ensure('present') } end context 'empty/default' do @@ -233,9 +233,9 @@ describe 'with python::dev' do context 'true' do - let(:params) { { dev: 'installed' } } + let(:params) { { dev: 'present' } } - it { is_expected.to contain_package('python-dev').with_ensure('installed') } + it { is_expected.to contain_package('python-dev').with_ensure('present') } end context 'default/empty' do @@ -417,9 +417,9 @@ describe 'with python::dev' do context 'true' do - let(:params) { { dev: 'installed' } } + let(:params) { { dev: 'present' } } - it { is_expected.to contain_package('python-dev').with_ensure('installed') } + it { is_expected.to contain_package('python-dev').with_ensure('present') } end context 'empty/default' do @@ -467,9 +467,9 @@ describe 'with python::dev' do context 'true' do - let(:params) { { dev: 'installed' } } + let(:params) { { dev: 'present' } } - it { is_expected.to contain_package('python-dev').with_ensure('installed') } + it { is_expected.to contain_package('python-dev').with_ensure('present') } end context 'default/empty' do