Permalink
Browse files

Merge branch 'ticket/10957-iptables-facts'

* ticket/10957-iptables-facts:
  (#10957) add iptables_version and ip6tables_version facts
  • Loading branch information...
2 parents a5e7498 + 6d44e2f commit 46e9d1cc8b9d690f0ff75768113f92608bc49f06 @kbarber kbarber committed Dec 3, 2011
Showing with 44 additions and 0 deletions.
  1. +23 −0 lib/facter/iptables.rb
  2. +21 −0 spec/unit/facter/iptables_spec.rb
@@ -0,0 +1,23 @@
+Facter.add(:iptables_version) do
+ confine :kernel => :linux
+ setcode do
+ version = Facter::Util::Resolution.exec('iptables --version')
+ if version
+ version.match(/\d+\.\d+\.\d+/).to_s
+ else
+ nil
+ end
+ end
+end
+
+Facter.add(:ip6tables_version) do
+ confine :kernel => :linux
+ setcode do
+ version = Facter::Util::Resolution.exec('ip6tables --version')
+ if version
+ version.match(/\d+\.\d+\.\d+/).to_s
+ else
+ nil
+ end
+ end
+end
@@ -0,0 +1,21 @@
+require 'spec_helper'
+require 'facter/iptables'
+
+describe "Facter::Util::Fact" do
+ before {
+ Facter.fact(:kernel).stubs(:value).returns("Linux")
+ Facter.fact(:kernelrelease).stubs(:value).returns("2.6")
+ }
+
+ describe 'iptables_version' do
+ it {
+ Facter::Util::Resolution.stubs(:exec).with('iptables --version').returns('iptables v1.4.7')
+ Facter.fact(:iptables_version).value.should == '1.4.7'
+ }
+ end
+
+ describe 'ip6tables_version' do
+ before { Facter::Util::Resolution.stubs(:exec).with('ip6tables --version').returns('ip6tables v1.4.7') }
+ it { Facter.fact(:ip6tables_version).value.should == '1.4.7' }
+ end
+end

0 comments on commit 46e9d1c

Please sign in to comment.