File tree Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Expand file tree Collapse file tree 2 files changed +41
-4
lines changed Original file line number Diff line number Diff line change 2
2
confine { Facter ::Util ::Resolution . which ( 'puppetdb' ) }
3
3
4
4
setcode do
5
- output = Facter ::Core ::Execution . execute ( 'puppetdb --version' )
6
- output . split ( ':' ) . last . strip
5
+ require 'open3'
6
+
7
+ # check if os is debian/ubuntu and the package is not from puppetlabs
8
+ if Facter . value ( :osfamily ) == 'Debian'
9
+ package_maintainer = Facter ::Core ::Execution . execute ( 'apt-cache show puppetdb | grep "Maintainer:" | head -1' )
10
+ unless package_maintainer . include? 'Puppet Labs'
11
+ output , status = Open3 . capture2 ( 'dpkg-query --showformat=\'${Version}\' --show puppetdb' )
12
+ if status . success?
13
+ output . strip . split ( '-' ) . first
14
+ else
15
+ nil
16
+ end
17
+ end
18
+ else
19
+ output , status = Open3 . capture2 ( 'puppetdb --version' )
20
+ if status . success?
21
+ output . split ( ':' ) . last . strip
22
+ else
23
+ nil
24
+ end
25
+ end
7
26
end
8
27
end
Original file line number Diff line number Diff line change 10
10
Facter . clear
11
11
end
12
12
13
- it 'returns the correct puppetdb version ' do
13
+ it 'returns a version on non-Debian family with puppetlabs package ' do
14
14
allow ( Facter ::Util ::Resolution ) . to receive ( :which ) . with ( 'puppetdb' ) . and_return ( '/usr/bin/puppetdb' )
15
- allow ( Facter :: Core :: Execution ) . to receive ( :execute ) . with ( 'puppetdb --version' ) . and_return ( "puppetdb version: 7.18.0\n " )
15
+ allow ( Open3 ) . to receive ( :capture2 ) . with ( 'puppetdb --version' ) . and_return ( "puppetdb version: 7.18.0\n " )
16
16
17
17
expect ( Facter . fact ( :puppetdb_version ) . value ) . to eq ( '7.18.0' )
18
18
end
19
19
20
+ it 'returns a version on Debian family with non-puppetlabs package' do
21
+ allow ( Facter ::Util ::Resolution ) . to receive ( :which ) . with ( 'puppetdb' ) . and_return ( '/usr/sbin/puppetdb' )
22
+ allow ( Facter ) . to receive ( :value ) . with ( :osfamily ) . and_return ( 'Debian' )
23
+ allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( 'apt-cache show puppetdb | grep "Maintainer:" | head -1' ) . and_return ( 'Maintainer: Ubuntu Developers' )
24
+ allow ( Open3 ) . to receive ( :capture2 ) . with ( 'dpkg-query --showformat=\'${Version}\' --show puppetdb' ) . and_return ( "6.2.0-5" )
25
+
26
+ expect ( Facter . fact ( :puppetdb_version ) . value ) . to eq ( '6.2.0' )
27
+ end
28
+
29
+ it 'returns a version on Debian family with puppetlabs package' do
30
+ allow ( Facter ::Util ::Resolution ) . to receive ( :which ) . with ( 'puppetdb' ) . and_return ( '/usr/sbin/puppetdb' )
31
+ allow ( Facter ) . to receive ( :value ) . with ( :osfamily ) . and_return ( 'Debian' )
32
+ allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( 'apt-cache show puppetdb | grep "Maintainer:" | head -1' ) . and_return ( 'Maintainer: Puppet Labs' )
33
+ allow ( Open3 ) . to receive ( :capture2 ) . with ( 'dpkg-query --showformat=\'${Version}\' --show puppetdb' ) . and_return ( "7.19.0-1jammy" )
34
+
35
+ expect ( Facter . fact ( :puppetdb_version ) . value ) . to eq ( '7.19.0' )
36
+ end
37
+
20
38
it 'returns nil if puppetdb command is not available' do
21
39
allow ( Facter ::Util ::Resolution ) . to receive ( :which ) . with ( 'puppetdb' ) . and_return ( nil )
22
40
You can’t perform that action at this time.
0 commit comments