From cf3946fffb550c3644660c2671108478a088115c Mon Sep 17 00:00:00 2001 From: Matthias Baur Date: Tue, 26 Nov 2019 10:19:05 +0100 Subject: [PATCH] Fix duplicate declaration for python-venv package Fixes #517. --- manifests/pyvenv.pp | 12 +++++------- spec/classes/python_spec.rb | 22 ++++++++++++++++++++++ spec/defines/pyvenv_spec.rb | 12 ++++++++---- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/manifests/pyvenv.pp b/manifests/pyvenv.pp index 7807a6b3..5ae6eef3 100644 --- a/manifests/pyvenv.pp +++ b/manifests/pyvenv.pp @@ -32,13 +32,12 @@ $path = [ '/bin', '/usr/bin', '/usr/sbin', '/usr/local/bin' ], $environment = [], ) { - include python if $ensure == 'present' { $python_version = $version ? { - 'system' => $facts['python3_version'], - default => $version, + 'system' => $facts['python3_version'], + default => $version, } $python_version_parts = split($python_version, '[.]') @@ -50,11 +49,10 @@ case $facts['lsbdistcodename'] { 'xenial','bionic','cosmic','disco', 'jessie','stretch','buster': { - ensure_packages ($python3_venv_package, { - before => File[$venv_dir], - }) + ensure_packages ($python3_venv_package) + Package[$python3_venv_package] -> File[$venv_dir] } - default: {} + default: {} } } diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index afebca6b..41ea46d0 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -72,6 +72,28 @@ end end + describe 'with python::python_pyvenvs' do + context 'with two pyenvs' do + let(:params) do + { + python_pyvenvs: { + '/opt/env1' => { + version: '3.8' + }, + '/opt/env2' => { + version: '3.8' + } + } + } + end + + it { is_expected.to compile } + + it { is_expected.to contain_python__pyvenv('/opt/env1').with_ensure('present') } + it { is_expected.to contain_python__pyvenv('/opt/env2').with_ensure('present') } + end + end + describe 'with manage_gunicorn' do context 'true' do let(:params) { { manage_gunicorn: true } } diff --git a/spec/defines/pyvenv_spec.rb b/spec/defines/pyvenv_spec.rb index aa66aac5..81ec3fd1 100644 --- a/spec/defines/pyvenv_spec.rb +++ b/spec/defines/pyvenv_spec.rb @@ -13,10 +13,14 @@ '/opt/env' end - it { - is_expected.to contain_file('/opt/env') - is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.5 --clear /opt/env') - } + context 'with default parameters' do + it { is_expected.to contain_file('/opt/env') } + it { is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.5 --clear /opt/env') } + + if %w[xenial bionic cosmic disco jessie stretch buster].include?(facts[:lsbdistcodename]) + it { is_expected.to contain_package('python3.5-venv').that_comes_before('File[/opt/env]') } + end + end describe 'when ensure' do context 'is absent' do