From e271d85bac36ec65d2d663fbb75fe7da2d73333f Mon Sep 17 00:00:00 2001 From: BR Date: Tue, 20 Apr 2021 11:08:46 +0200 Subject: [PATCH 1/7] Use $real_pkgname for pip uninstall command Fix #606 --- manifests/pip.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/pip.pp b/manifests/pip.pp index 35d46900..3935df72 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -220,7 +220,7 @@ default: { # Anti-action, uninstall. - $command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${name}" + $command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${real_pkgname}" $unless_command = "! ${pip_env} list | grep -i -e '${grep_regex}'" } } From 2fd2a90b33f3dba527b2b0f76b29848ce20bcf5a Mon Sep 17 00:00:00 2001 From: BR Date: Mon, 26 Apr 2021 21:53:50 +0200 Subject: [PATCH 2/7] Added tests for pip uninstall --- spec/defines/pip_spec.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/defines/pip_spec.rb b/spec/defines/pip_spec.rb index 3ae5a61a..c2162e08 100644 --- a/spec/defines/pip_spec.rb +++ b/spec/defines/pip_spec.rb @@ -116,6 +116,14 @@ it { is_expected.to contain_exec('pip_uninstall_rpyc').with_command(%r{uninstall.*rpyc$}) } end + + context 'passes correct package name' do + let(:params) { { ensure: 'absent', 'pkgname': 'r-pyc' } } + + it { is_expected.not_to contain_exec('pip_install_rpyc') } + + it { is_expected.to contain_exec('pip_uninstall_rpyc').with_command(%r{uninstall.*r-pyc$}) } + end end end end From 7f5f52b465a09ea14e90dd4f3c25f1b136c75278 Mon Sep 17 00:00:00 2001 From: BR Date: Tue, 27 Apr 2021 22:56:46 +0200 Subject: [PATCH 3/7] Initial pip acceptance tests --- spec/acceptance/pip_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spec/acceptance/pip_spec.rb diff --git a/spec/acceptance/pip_spec.rb b/spec/acceptance/pip_spec.rb new file mode 100644 index 00000000..372d905f --- /dev/null +++ b/spec/acceptance/pip_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper_acceptance' + +describe 'python::pip defined resource' do + context 'install package with custom name' do + it 'works with no errors' do + pp = <<-PUPPET + class { 'python': + version => '3', + dev => 'present', + } + + python::pip { 'agent package': + pkgname => 'agent' + ensure => '0.1.2' + } + PUPPET + + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + end + describe command('/opt/agent/venv/bin/pip list') do + its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.to match %r{agent.* 0\.1\.2} } + end +end + From 1c177bd4ce7358756f04f694b3ce5751fbb8de79 Mon Sep 17 00:00:00 2001 From: BR Date: Tue, 27 Apr 2021 22:57:46 +0200 Subject: [PATCH 4/7] Fixed pip path --- spec/acceptance/pip_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/acceptance/pip_spec.rb b/spec/acceptance/pip_spec.rb index 372d905f..c88bd5d3 100644 --- a/spec/acceptance/pip_spec.rb +++ b/spec/acceptance/pip_spec.rb @@ -18,7 +18,7 @@ class { 'python': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end - describe command('/opt/agent/venv/bin/pip list') do + describe command('/usr/bin/pip list') do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to match %r{agent.* 0\.1\.2} } end From 9985ea0a36f5ae2d14e423f380ad65787230b150 Mon Sep 17 00:00:00 2001 From: BR Date: Tue, 27 Apr 2021 23:01:11 +0200 Subject: [PATCH 5/7] Added pip uninstall acceptance test --- spec/acceptance/pip_spec.rb | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/spec/acceptance/pip_spec.rb b/spec/acceptance/pip_spec.rb index c88bd5d3..f1ba7f26 100644 --- a/spec/acceptance/pip_spec.rb +++ b/spec/acceptance/pip_spec.rb @@ -10,17 +10,48 @@ class { 'python': } python::pip { 'agent package': - pkgname => 'agent' - ensure => '0.1.2' + pkgname => 'agent', + ensure => '0.1.2', } PUPPET apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) end + describe command('/usr/bin/pip list') do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to match %r{agent.* 0\.1\.2} } end + + context 'uninstall package with custom name' do + it 'works with no errors' do + pp = <<-PUPPET + class { 'python': + version => '3', + dev => 'present', + } + + python::pip { 'agent package install': + pkgname => 'agent', + ensure => '0.1.2', + } + + python::pip { 'agent package uninstall': + pkgname => 'agent', + ensure => 'absent', + require => Python::Pip['agent package install'], + } + + PUPPET + + apply_manifest(pp, catch_failures: true) + apply_manifest(pp, catch_changes: true) + end + + describe command('/usr/bin/pip list') do + its(:exit_status) { is_expected.to eq 0 } + its(:stdout) { is_expected.not_to match %r{agent.* 0\.1\.2} } + end end From 6599b7647a1e3c818daf63dc3cfff6c21df04281 Mon Sep 17 00:00:00 2001 From: BR Date: Wed, 28 Apr 2021 08:22:14 +0200 Subject: [PATCH 6/7] Fixed syntax in acceptance tests --- spec/acceptance/pip_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/acceptance/pip_spec.rb b/spec/acceptance/pip_spec.rb index f1ba7f26..b62c82a0 100644 --- a/spec/acceptance/pip_spec.rb +++ b/spec/acceptance/pip_spec.rb @@ -17,6 +17,7 @@ class { 'python': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) + end end describe command('/usr/bin/pip list') do @@ -47,6 +48,7 @@ class { 'python': apply_manifest(pp, catch_failures: true) apply_manifest(pp, catch_changes: true) + end end describe command('/usr/bin/pip list') do From f36ea4abe4499fd6ef7a99ecd8eaf603ab0a4bef Mon Sep 17 00:00:00 2001 From: BR Date: Wed, 28 Apr 2021 22:18:04 +0200 Subject: [PATCH 7/7] Use virtualenv for pip acceptance tests --- spec/acceptance/pip_spec.rb | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/spec/acceptance/pip_spec.rb b/spec/acceptance/pip_spec.rb index b62c82a0..b7d6d4e1 100644 --- a/spec/acceptance/pip_spec.rb +++ b/spec/acceptance/pip_spec.rb @@ -9,9 +9,17 @@ class { 'python': dev => 'present', } + python::pyvenv { '/opt/test-venv': + ensure => 'present', + systempkgs => false, + mode => '0755', + pip_version => '<= 20.3.4', + } + python::pip { 'agent package': - pkgname => 'agent', - ensure => '0.1.2', + virtualenv => '/opt/test-venv', + pkgname => 'agent', + ensure => '0.1.2', } PUPPET @@ -20,7 +28,7 @@ class { 'python': end end - describe command('/usr/bin/pip list') do + describe command('/opt/test-venv/bin/pip list') do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.to match %r{agent.* 0\.1\.2} } end @@ -33,25 +41,33 @@ class { 'python': dev => 'present', } + python::pyvenv { '/opt/test-venv': + ensure => 'present', + systempkgs => false, + mode => '0755', + pip_version => '<= 20.3.4', + } + python::pip { 'agent package install': - pkgname => 'agent', - ensure => '0.1.2', + ensure => '0.1.2', + pkgname => 'agent', + virtualenv => '/opt/test-venv', } - python::pip { 'agent package uninstall': - pkgname => 'agent', + python::pip { 'agent package uninstall custom pkgname': ensure => 'absent', + pkgname => 'agent', + virtualenv => '/opt/test-venv', require => Python::Pip['agent package install'], } PUPPET apply_manifest(pp, catch_failures: true) - apply_manifest(pp, catch_changes: true) end end - describe command('/usr/bin/pip list') do + describe command('/opt/test-venv/bin/pip list') do its(:exit_status) { is_expected.to eq 0 } its(:stdout) { is_expected.not_to match %r{agent.* 0\.1\.2} } end