File tree Expand file tree Collapse file tree 5 files changed +18
-20
lines changed Expand file tree Collapse file tree 5 files changed +18
-20
lines changed Original file line number Diff line number Diff line change 22
33Facter . add ( :ip6tables_version ) do
44 confine kernel : :Linux
5+ confine { Facter ::Core ::Execution . which ( 'ip6tables' ) }
56 setcode do
6- version = Facter ::Core ::Execution . execute ( 'ip6tables --version' )
7- if version
8- version . match ( %r{\d +\. \d +\. \d +} ) . to_s
9- else
10- nil
11- end
7+ version = Facter ::Core ::Execution . execute ( 'ip6tables --version' , { on_fail : nil } )
8+ version . match ( %r{\d +\. \d +\. \d +} ) . to_s if version
129 end
1310end
Original file line number Diff line number Diff line change 66 # Throw away STDERR because dpkg >= 1.16.7 will make some noise if the
77 # package isn't currently installed.
88 cmd = "dpkg-query -Wf '${Version}' netfilter-persistent 2>/dev/null"
9- version = Facter ::Core ::Execution . execute ( cmd )
9+ version = Facter ::Core ::Execution . execute ( cmd , { on_fail : nil } )
1010
1111 if version . nil? || !version . match ( %r{\d +\. \d +} )
1212 nil
Original file line number Diff line number Diff line change 22
33Facter . add ( :iptables_version ) do
44 confine kernel : :Linux
5+ confine { Facter ::Core ::Execution . which ( 'iptables' ) }
56 setcode do
6- version = Facter ::Core ::Execution . execute ( 'iptables --version' )
7- if version
8- version . match ( %r{\d +\. \d +\. \d +} ) . to_s
9- else
10- nil
11- end
7+ version = Facter ::Core ::Execution . execute ( 'iptables --version' , { on_fail : nil } )
8+ version . match ( %r{\d +\. \d +\. \d +} ) . to_s if version
129 end
1310end
Original file line number Diff line number Diff line change 1717 before ( :each ) do
1818 allow ( Facter . fact ( :operatingsystem ) ) . to receive ( :value ) . and_return ( os )
1919 allow ( Facter . fact ( :operatingsystemrelease ) ) . to receive ( :value ) . and_return ( os_release )
20- allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( dpkg_cmd )
20+ allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( dpkg_cmd , { on_fail : nil } )
2121 . and_return ( ver )
2222 end
2323 it { expect ( Facter . fact ( :iptables_persistent_version ) . value ) . to eql ver }
2828 before ( :each ) do
2929 allow ( Facter . fact ( :operatingsystem ) ) . to receive ( :value ) . and_return ( 'Ubuntu' )
3030 allow ( Facter . fact ( :operatingsystemrelease ) ) . to receive ( :value ) . and_return ( '20.04' )
31- allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( dpkg_cmd )
31+ allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( dpkg_cmd , { on_fail : nil } )
3232 . and_return ( nil )
3333 end
3434 it { expect ( Facter . fact ( :iptables_persistent_version ) . value ) . to be_nil }
6262 before ( :each ) do
6363 allow ( Facter . fact ( :operatingsystem ) ) . to receive ( :value ) . and_return ( os )
6464 allow ( Facter . fact ( :operatingsystemrelease ) ) . to receive ( :value ) . and_return ( os_release )
65- allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( dpkg_cmd )
65+ allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( dpkg_cmd , { on_fail : nil } )
6666 . and_return ( ver )
6767 end
6868 it { expect ( Facter . fact ( :iptables_persistent_version ) . value ) . to eql ver }
7474 before ( :each ) do
7575 allow ( Facter . fact ( :operatingsystem ) ) . to receive ( :value ) . and_return ( 'Ubuntu' )
7676 allow ( Facter . fact ( :operatingsystemrelease ) ) . to receive ( :value ) . and_return ( os_release )
77- allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( dpkg_cmd )
77+ allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( dpkg_cmd , { on_fail : nil } )
7878 . and_return ( nil )
7979 end
8080 it { expect ( Facter . fact ( :iptables_persistent_version ) . value ) . to be_nil }
Original file line number Diff line number Diff line change 1111
1212 describe 'iptables_version' do
1313 it {
14- allow ( Facter ::Core ::Execution ) . to receive ( :execute ) . with ( 'iptables --version' )
15- . and_return ( 'iptables v1.4.7' )
14+ allow ( Facter ::Core ::Execution ) . to receive ( :which )
15+ . with ( 'iptables' ) . and_return ( '/usr/sbin/iptables' )
16+ allow ( Facter ::Core ::Execution ) . to receive ( :execute )
17+ . with ( 'iptables --version' , { on_fail : nil } ) . and_return ( 'iptables v1.4.7' )
1618 expect ( Facter . fact ( :iptables_version ) . value ) . to eql '1.4.7'
1719 }
1820 end
1921
2022 describe 'ip6tables_version' do
2123 before ( :each ) do
24+ allow ( Facter ::Core ::Execution ) . to receive ( :which )
25+ . with ( 'ip6tables' ) . and_return ( '/usr/sbin/ip6tables' )
2226 allow ( Facter ::Core ::Execution ) . to receive ( :execute )
23- . with ( 'ip6tables --version' ) . and_return ( 'ip6tables v1.4.7' )
27+ . with ( 'ip6tables --version' , { on_fail : nil } ) . and_return ( 'ip6tables v1.4.7' )
2428 end
2529 it { expect ( Facter . fact ( :ip6tables_version ) . value ) . to eql '1.4.7' }
2630 end
You can’t perform that action at this time.
0 commit comments