Use versioncmp for '::operatingsystemmajrelease' comparison

Use the builtin versioncmp() function for comparisons of the
'::operatingsystemmajrelease' fact. If that fact evaluates to a string,
regular arithmetric comparisons will fail under the Puppet 4.x
language.

Change-Id: Ib55dabd3c33f5773ac3ca67955e0f85418ec0698
Closes-bug: 1425300
Signed-off-by: Gael Chamoulaud <gchamoul@redhat.com>
This commit is contained in:
Gael Chamoulaud 2015-03-29 15:58:24 +02:00
parent 77e1c46656
commit 5a02533d7c
2 changed files with 8 additions and 4 deletions

View File

@ -43,7 +43,7 @@ class cinder::params {
case $::operatingsystem { case $::operatingsystem {
'RedHat', 'CentOS', 'Scientific': { 'RedHat', 'CentOS', 'Scientific': {
if $::operatingsystemmajrelease >= 7 { if (versioncmp($::operatingsystemmajrelease, '7') >= 0) {
$iscsi_helper = 'lioadm' $iscsi_helper = 'lioadm'
} else { } else {
$iscsi_helper = 'tgtadm' $iscsi_helper = 'tgtadm'

View File

@ -43,7 +43,7 @@ describe 'cinder::volume::iscsi' do
it_raises 'a Puppet::Error', /Unsupported iscsi helper: fooboozoo/ it_raises 'a Puppet::Error', /Unsupported iscsi helper: fooboozoo/
end end
describe 'with RedHat' do describe 'on RHEL Platforms' do
let :params do let :params do
req_params req_params
@ -52,6 +52,7 @@ describe 'cinder::volume::iscsi' do
let :facts do let :facts do
{:osfamily => 'RedHat', {:osfamily => 'RedHat',
:operatingsystem => 'RedHat', :operatingsystem => 'RedHat',
:operatingsystemrelease => 6.5,
:operatingsystemmajrelease => '6'} :operatingsystemmajrelease => '6'}
end end
@ -71,7 +72,10 @@ describe 'cinder::volume::iscsi' do
end end
let :facts do let :facts do
{:osfamily => 'RedHat'} {:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemrelease => 7.0,
:operatingsystemmajrelease => '7'}
end end
it { is_expected.to contain_package('targetcli').with_ensure('present')} it { is_expected.to contain_package('targetcli').with_ensure('present')}