Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update version validation #472

Merged
merged 5 commits into from
Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# @example install python3 from scl repo
# class { 'python' :
# ensure => 'present',
# version => 'rh-python36-python',
# version => 'rh-python36',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mhm, is -python not valid anymore? That would be a backwards-incompatible change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either work to install the runtime as both packages basically require each other, but as I mentioned in #471 if you specify the version as rh-python36-python and elect to install the dev package, it will try and install rh-python36-python-scldevel which doesn't exist, yet rh-python36-scldevel does exist.

The original code has clearly been written with using rh-python36 as the version as there is a commented out block that would have installed ${version}-python-virtualenv which would also error if you tried to use rh-python36-python for the version, (too many -python-'s). It's been commented out as the rh-python36 package will pull this in as a dependency, but rh-python36-python will not.

I'll update the regex so it doesn't break existing users but personally I think it needs a bit of work in the future; arguably the version should actually be rh-python36-python and the dev option should install rh-python36-python-devel rather than rh-python36-scldevel, and rh-python36-python-virtualenv should be explicitly installed rather than be commented out like it is currently.

For reference, these are the "core" packages that are available for the 3.6 software collection:

rh-python36.x86_64 : Package that installs rh-python36
rh-python36-runtime.x86_64 : Package that handles rh-python36 Software Collection.
rh-python36-scldevel.x86_64 : Package shipping development files for rh-python36
rh-python36-python.x86_64 : Version 3 of the Python programming language aka Python 3000
rh-python36-python-debug.x86_64 : Debug version of the Python 3 runtime
rh-python36-python-devel.x86_64 : Libraries and header files needed for Python 3 development
rh-python36-python-setuptools.noarch : Easily build and distribute Python packages
rh-python36-python-virtualenv.noarch : Tool to create isolated Python environments
rh-python36-python-wheel.noarch : A built-package format for Python

# dev => 'present',
# virtualenv => 'present',
# }
Expand Down Expand Up @@ -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)")
}

Expand Down
7 changes: 4 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ? {
Expand Down
72 changes: 54 additions & 18 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
end
end
end
when 'RedHat'
when 'RedHat', 'CentOS'
case facts[:os]['release']['major']
when '5'
# written for RHEL 5
Expand Down Expand Up @@ -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: '' } }
Expand Down Expand Up @@ -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 }
bodgit marked this conversation as resolved.
Show resolved Hide resolved
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 }
bodgit marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down