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 all 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
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
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}(?:-python)?\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
2 changes: 1 addition & 1 deletion manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
82 changes: 64 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,75 @@
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 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
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 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
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