From 7eae51bd3447c9db9317ea081ef31db2180dd610 Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Wed, 3 Apr 2019 14:01:30 +0100 Subject: [PATCH 1/5] Update version validation Fixes #471 --- manifests/init.pp | 4 ++-- manifests/install.pp | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index a62975b5..d3c276fc 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,7 +29,7 @@ # @example install python3 from scl repo # class { 'python' : # ensure => 'present', -# version => 'rh-python36-python', +# version => 'rh-python36', # dev => 'present', # virtualenv => 'present', # } @@ -64,7 +64,7 @@ } unless $version =~ Pattern[/\A(python)?[0-9](\.[0-9])+/, - /\Apypy\Z/, /\Asystem\Z/] { + /\Apypy\Z/, /\Asystem\Z/, /\Arh-python[0-9]{2}\Z/] { fail("version needs to be pypy, system or a version string like '3.5' or 'python3.5)") } diff --git a/manifests/install.pp b/manifests/install.pp index 22ae9e4a..63c88079 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -8,10 +8,11 @@ $python_version = getparam(Class['python'], 'version') $python = $python_version ? { - 'system' => 'python', - 'pypy' => 'pypy', + 'system' => 'python', + 'pypy' => 'pypy', /\A(python)?([0-9](\.?[0-9])+)/ => "python${2}", - default => "python${python::version}", + /\Arh-python[0-9]{2}/ => $python_version, + default => "python${python::version}", } $pythondev = $facts['os']['family'] ? { From 6045313a9cec4bba5683b52a56a5b8792016e2a0 Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Mon, 8 Apr 2019 10:42:47 +0100 Subject: [PATCH 2/5] Add tests for setting SCL package version Move SCL checks to the EL6/7 contexts as EL5 is neither tested against nor does it support SCL repositories. --- spec/classes/python_spec.rb | 72 +++++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index ab5b549d..f3ca5a34 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -129,7 +129,7 @@ end end end - when 'RedHat' + when 'RedHat', 'CentOS' case facts[:os]['release']['major'] when '5' # written for RHEL 5 @@ -204,23 +204,6 @@ } end - context 'scl' do - describe 'with manage_scl' do - context 'true' do - let(:params) { { provider: 'scl', manage_scl: true } } - - it { is_expected.to contain_package('centos-release-scl') } - it { is_expected.to contain_package('scl-utils') } - end - context 'false' do - let(:params) { { provider: 'scl', manage_scl: false } } - - it { is_expected.not_to contain_package('centos-release-scl') } - it { is_expected.not_to contain_package('scl-utils') } - end - end - end - # python::provider context 'default' do let(:params) { { provider: '' } } @@ -262,12 +245,65 @@ context 'on a Redhat 6 OS' do it { is_expected.to contain_class('python::install') } it { is_expected.to contain_package('pip').with_name('python-pip') } + + describe 'with python::provider' do + context 'scl' do + describe 'with version' do + context '3.6 SCL package' do + let(:params) { { version: 'rh-python36' } } + + it { is_expected.to compile } + end + end + describe 'with manage_scl' do + context 'true' do + let(:params) { { provider: 'scl', manage_scl: true } } + + it { is_expected.to contain_package('centos-release-scl') } + it { is_expected.to contain_package('scl-utils') } + end + context 'false' do + let(:params) { { provider: 'scl', manage_scl: false } } + + it { is_expected.not_to contain_package('centos-release-scl') } + it { is_expected.not_to contain_package('scl-utils') } + end + end + end + end end + when '7' context 'on a Redhat 7 OS' do it { is_expected.to contain_class('python::install') } it { is_expected.to contain_package('pip').with_name('python2-pip') } + + describe 'with python::provider' do + context 'scl' do + describe 'with version' do + context '3.6 SCL package' do + let(:params) { { version: 'rh-python36' } } + + it { is_expected.to compile } + end + end + describe 'with manage_scl' do + context 'true' do + let(:params) { { provider: 'scl', manage_scl: true } } + + it { is_expected.to contain_package('centos-release-scl') } + it { is_expected.to contain_package('scl-utils') } + end + context 'false' do + let(:params) { { provider: 'scl', manage_scl: false } } + + it { is_expected.not_to contain_package('centos-release-scl') } + it { is_expected.not_to contain_package('scl-utils') } + end + end + end + end end end end From b83aa36de75a333180df9504a6d5e5a3f380d4f9 Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Tue, 9 Apr 2019 09:58:16 +0100 Subject: [PATCH 3/5] Be more specific with compilation tests --- spec/classes/python_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index f3ca5a34..ac0e3ca9 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -252,7 +252,7 @@ context '3.6 SCL package' do let(:params) { { version: 'rh-python36' } } - it { is_expected.to compile } + it { is_expected.to compile.with_all_deps } end end describe 'with manage_scl' do @@ -285,7 +285,7 @@ context '3.6 SCL package' do let(:params) { { version: 'rh-python36' } } - it { is_expected.to compile } + it { is_expected.to compile.with_all_deps } end end describe 'with manage_scl' do From 5f6f76f14886f50434f5612012f0a12b810b5dc0 Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Tue, 9 Apr 2019 11:28:49 +0100 Subject: [PATCH 4/5] Allow rh-python36-python as a version --- manifests/init.pp | 4 ++-- spec/classes/python_spec.rb | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index d3c276fc..8b5ae4b6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -29,7 +29,7 @@ # @example install python3 from scl repo # class { 'python' : # ensure => 'present', -# version => 'rh-python36', +# version => 'rh-python36-python', # dev => 'present', # virtualenv => 'present', # } @@ -64,7 +64,7 @@ } unless $version =~ Pattern[/\A(python)?[0-9](\.[0-9])+/, - /\Apypy\Z/, /\Asystem\Z/, /\Arh-python[0-9]{2}\Z/] { + /\Apypy\Z/, /\Asystem\Z/, /\Arh-python[0-9]{2}(?:-python)?\Z/] { fail("version needs to be pypy, system or a version string like '3.5' or 'python3.5)") } diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index ac0e3ca9..208462ca 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -249,9 +249,14 @@ describe 'with python::provider' do context 'scl' do describe 'with version' do - context '3.6 SCL package' do + context '3.6 SCL meta package' do let(:params) { { version: 'rh-python36' } } + it { is_expected.to compile.with_all_deps } + end + context '3.6 SCL python package' do + let(:params) { { version: 'rh-python36-python' } } + it { is_expected.to compile.with_all_deps } end end @@ -282,9 +287,14 @@ describe 'with python::provider' do context 'scl' do describe 'with version' do - context '3.6 SCL package' do + context '3.6 SCL meta package' do let(:params) { { version: 'rh-python36' } } + it { is_expected.to compile.with_all_deps } + end + context '3.6 SCL python package' do + let(:params) { { version: 'rh-python36-python' } } + it { is_expected.to compile.with_all_deps } end end From 4d65c1c9a0ae0049ce05b29f98dfdbd366669b4f Mon Sep 17 00:00:00 2001 From: Matt Dainty Date: Wed, 10 Apr 2019 11:43:41 +0100 Subject: [PATCH 5/5] Use normalized version number with versioncmp() Allows the python3_version fact to be bypassed fully. --- manifests/pyvenv.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/pyvenv.pp b/manifests/pyvenv.pp index 579f7b11..59b582ed 100644 --- a/manifests/pyvenv.pp +++ b/manifests/pyvenv.pp @@ -59,7 +59,7 @@ } # pyvenv is deprecated since 3.6 and will be removed in 3.8 - if (versioncmp($facts['python3_version'], '3.6') >=0) { + if (versioncmp($normalized_python_version, '3.6') >=0) { $virtualenv_cmd = "${python::exec_prefix}python${normalized_python_version} -m venv" } else { $virtualenv_cmd = "${python::exec_prefix}pyvenv-${normalized_python_version}"