Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'ticket/10957-iptables-facts'
* ticket/10957-iptables-facts:
  (#10957) add iptables_version and ip6tables_version facts
  • Loading branch information
kbarber committed Dec 3, 2011
2 parents a5e7498 + 6d44e2f commit 46e9d1c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/facter/iptables.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
21 changes: 21 additions & 0 deletions spec/unit/facter/iptables_spec.rb
@@ -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.