File tree Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Expand file tree Collapse file tree 2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Checks if the OS version is at least a certain version. Note that only the
2
+ # major version is taken into account.
3
+ #
4
+ # Example usage:
5
+ #
6
+ # if os_version_gte('Debian', '9') { }
7
+ # if os_version_gte('Ubuntu', '18.04') { }
8
+ Puppet ::Functions . create_function ( :os_version_gte ) do
9
+ dispatch :os_version_gte do
10
+ param 'String[1]' , :os
11
+ param 'String[1]' , :version
12
+ return_type 'Boolean'
13
+ end
14
+
15
+ def os_version_gte ( os , version )
16
+ facts = closure_scope [ 'facts' ]
17
+ ( facts [ 'operatingsystem' ] == os &&
18
+ Puppet ::Util ::Package . versioncmp ( version , facts [ 'operatingsystemmajrelease' ] ) >= 0 )
19
+ end
20
+ end
Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ describe 'os_version_gte' do
4
+ context 'on Debian 9' do
5
+ let ( :facts ) do
6
+ {
7
+ :operatingsystem => 'Debian' ,
8
+ :operatingsystemmajrelease => '9' ,
9
+ }
10
+ end
11
+
12
+ it { is_expected . to run . with_params ( 'Debian' , '9' ) . and_return ( true ) }
13
+ it { is_expected . to run . with_params ( 'Debian' , '8' ) . and_return ( false ) }
14
+ it { is_expected . to run . with_params ( 'Debian' , '8.0' ) . and_return ( false ) }
15
+ it { is_expected . to run . with_params ( 'Ubuntu' , '16.04' ) . and_return ( false ) }
16
+ it { is_expected . to run . with_params ( 'Fedora' , '29' ) . and_return ( false ) }
17
+ end
18
+
19
+ context 'on Ubuntu 16.04' do
20
+ let ( :facts ) do
21
+ {
22
+ :operatingsystem => 'Ubuntu' ,
23
+ :operatingsystemmajrelease => '16.04' ,
24
+ }
25
+ end
26
+
27
+ it { is_expected . to run . with_params ( 'Debian' , '9' ) . and_return ( false ) }
28
+ it { is_expected . to run . with_params ( 'Ubuntu' , '16' ) . and_return ( false ) }
29
+ it { is_expected . to run . with_params ( 'Ubuntu' , '16.04' ) . and_return ( true ) }
30
+ it { is_expected . to run . with_params ( 'Ubuntu' , '18.04' ) . and_return ( true ) }
31
+ it { is_expected . to run . with_params ( 'Fedora' , '29' ) . and_return ( false ) }
32
+ end
33
+ end
You can’t perform that action at this time.
0 commit comments