From a3aaeb9923db3319ce8df17c82a5bad78ed46e8f Mon Sep 17 00:00:00 2001 From: pcheliniy Date: Thu, 25 Dec 2014 10:32:50 +0300 Subject: [PATCH 1/2] fixed package name on Ubuntu 14.10 --- manifests/params.pp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/manifests/params.pp b/manifests/params.pp index a5f1f6190..c9814bf6e 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -37,6 +37,15 @@ $package_name = 'iptables-persistent' } } + 'Ubuntu' : { + if $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '14.10') >= 0 { + $service_name = 'netfilter-persistent' + $package_name = 'netfilter-persistent' + } else { + $service_name = 'iptables-persistent' + $package_name = 'iptables-persistent' + } + } default: { $package_name = undef $service_name = 'iptables' From 94f8ec85e7fe3462f2062d0658407a3486ff4831 Mon Sep 17 00:00:00 2001 From: Jonathan Tripathy Date: Thu, 22 Jan 2015 15:39:40 -0800 Subject: [PATCH 2/2] MODULES-1029 Fixed issues with Ubuntu 14.10 --- lib/facter/iptables_persistent_version.rb | 9 +- lib/puppet/type/firewall.rb | 2 +- lib/puppet/util/firewall.rb | 2 +- manifests/params.pp | 40 ++++--- .../iptables_persistent_version_spec.rb | 111 ++++++++++++++---- 5 files changed, 123 insertions(+), 41 deletions(-) diff --git a/lib/facter/iptables_persistent_version.rb b/lib/facter/iptables_persistent_version.rb index 80bf9dea1..4dbf6bcf6 100644 --- a/lib/facter/iptables_persistent_version.rb +++ b/lib/facter/iptables_persistent_version.rb @@ -3,7 +3,14 @@ setcode do # Throw away STDERR because dpkg >= 1.16.7 will make some noise if the # package isn't currently installed. - cmd = "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null" + os = Facter.value(:operatingsystem) + os_release = Facter.value(:operatingsystemrelease) + if (os == 'Debian' and (Puppet::Util::Package.versioncmp(os_release, '8.0') >= 0)) or + (os == 'Ubuntu' and (Puppet::Util::Package.versioncmp(os_release, '14.10') >= 0)) + cmd = "dpkg-query -Wf '${Version}' netfilter-persistent 2>/dev/null" + else + cmd = "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null" + end version = Facter::Util::Resolution.exec(cmd) if version.nil? or !version.match(/\d+\.\d+/) diff --git a/lib/puppet/type/firewall.rb b/lib/puppet/type/firewall.rb index 0895b6c62..6209c8840 100644 --- a/lib/puppet/type/firewall.rb +++ b/lib/puppet/type/firewall.rb @@ -1113,7 +1113,7 @@ def insync?(is) autorequire(:package) do case value(:provider) when :iptables, :ip6tables - %w{iptables iptables-persistent iptables-services} + %w{iptables iptables-persistent netfilter-persistent iptables-services} else [] end diff --git a/lib/puppet/util/firewall.rb b/lib/puppet/util/firewall.rb index 34bcd4044..fa81e75ed 100644 --- a/lib/puppet/util/firewall.rb +++ b/lib/puppet/util/firewall.rb @@ -191,7 +191,7 @@ def persist_iptables(proto) when :Debian case proto.to_sym when :IPv4, :IPv6 - if Puppet::Util::Package.versioncmp(persist_ver, '1.0') > 0 + if (persist_ver and Puppet::Util::Package.versioncmp(persist_ver, '1.0') > 0) %w{/usr/sbin/service netfilter-persistent save} else %w{/usr/sbin/service iptables-persistent save} diff --git a/manifests/params.pp b/manifests/params.pp index c9814bf6e..4d66159bd 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -29,21 +29,31 @@ } } 'Debian': { - if $::operatingsystem == 'Debian' and versioncmp($::operatingsystemrelease, '8.0') >= 0 { - $service_name = 'netfilter-persistent' - $package_name = 'netfilter-persistent' - } else { - $service_name = 'iptables-persistent' - $package_name = 'iptables-persistent' - } - } - 'Ubuntu' : { - if $::operatingsystem == 'Ubuntu' and versioncmp($::operatingsystemrelease, '14.10') >= 0 { - $service_name = 'netfilter-persistent' - $package_name = 'netfilter-persistent' - } else { - $service_name = 'iptables-persistent' - $package_name = 'iptables-persistent' + case $::operatingsystem { + 'Debian': { + if versioncmp($::operatingsystemrelease, '8.0') >= 0 { + $service_name = 'netfilter-persistent' + $package_name = 'netfilter-persistent' + } else { + $service_name = 'iptables-persistent' + $package_name = 'iptables-persistent' + } + + } + 'Ubuntu': { + if versioncmp($::operatingsystemrelease, '14.10') >= 0 { + $service_name = 'netfilter-persistent' + $package_name = 'netfilter-persistent' + } else { + $service_name = 'iptables-persistent' + $package_name = 'iptables-persistent' + } + + } + default: { + $service_name = 'iptables-persistent' + $package_name = 'iptables-persistent' + } } } default: { diff --git a/spec/unit/facter/iptables_persistent_version_spec.rb b/spec/unit/facter/iptables_persistent_version_spec.rb index 13a23a5c2..2c97c3d00 100644 --- a/spec/unit/facter/iptables_persistent_version_spec.rb +++ b/spec/unit/facter/iptables_persistent_version_spec.rb @@ -1,35 +1,100 @@ require 'spec_helper' describe "Facter::Util::Fact iptables_persistent_version" do - before { Facter.clear } - let(:dpkg_cmd) { "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null" } - - { - "Debian" => "0.0.20090701", - "Ubuntu" => "0.5.3ubuntu2", - }.each do |os, ver| - describe "#{os} package installed" do + + + context "iptables-persistent applicable" do + before { Facter.clear } + + let(:dpkg_cmd) { "dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null" } + + { + "Debian" => "0.0.20090701", + "Ubuntu" => "0.5.3ubuntu2", + }.each do |os, ver| + + if os == "Debian" + os_release = "7.0" + elsif os == "Ubuntu" + os_release = "14.04" + end + + describe "#{os} package installed" do + before { + allow(Facter.fact(:operatingsystem)).to receive(:value).and_return(os) + allow(Facter.fact(:operatingsystemrelease)).to receive(:value).and_return(os_release) + allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd). + and_return(ver) + } + it { Facter.fact(:iptables_persistent_version).value.should == ver } + end + end + + describe 'Ubuntu package not installed' do before { - allow(Facter.fact(:operatingsystem)).to receive(:value).and_return(os) + allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Ubuntu') + allow(Facter.fact(:operatingsystemrelease)).to receive(:value).and_return('14.04') allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd). - and_return(ver) + and_return(nil) } - it { Facter.fact(:iptables_persistent_version).value.should == ver } + it { Facter.fact(:iptables_persistent_version).value.should be_nil } + end + + describe 'CentOS not supported' do + before { allow(Facter.fact(:operatingsystem)).to receive(:value). + and_return("CentOS") } + it { Facter.fact(:iptables_persistent_version).value.should be_nil } end - end - describe 'Ubuntu package not installed' do - before { - allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Ubuntu') - allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd). - and_return(nil) - } - it { Facter.fact(:iptables_persistent_version).value.should be_nil } end - describe 'CentOS not supported' do - before { allow(Facter.fact(:operatingsystem)).to receive(:value). - and_return("CentOS") } - it { Facter.fact(:iptables_persistent_version).value.should be_nil } + context "netfilter-persistent applicable" do + before { Facter.clear } + + let(:dpkg_cmd) { "dpkg-query -Wf '${Version}' netfilter-persistent 2>/dev/null" } + + { + "Debian" => "0.0.20090701", + "Ubuntu" => "0.5.3ubuntu2", + }.each do |os, ver| + + if os == "Debian" + os_release = "8.0" + elsif os == "Ubuntu" + os_release = "14.10" + end + + describe "#{os} package installed" do + before { + allow(Facter.fact(:operatingsystem)).to receive(:value).and_return(os) + allow(Facter.fact(:operatingsystemrelease)).to receive(:value).and_return(os_release) + allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd). + and_return(ver) + } + it { Facter.fact(:iptables_persistent_version).value.should == ver } + end + end + + describe 'Ubuntu package not installed' do + os_release = "14.10" + before { + allow(Facter.fact(:operatingsystem)).to receive(:value).and_return('Ubuntu') + allow(Facter.fact(:operatingsystemrelease)).to receive(:value).and_return(os_release) + allow(Facter::Util::Resolution).to receive(:exec).with(dpkg_cmd). + and_return(nil) + } + it { Facter.fact(:iptables_persistent_version).value.should be_nil } + end + + describe 'CentOS not supported' do + before { allow(Facter.fact(:operatingsystem)).to receive(:value). + and_return("CentOS") } + it { Facter.fact(:iptables_persistent_version).value.should be_nil } + end + end + + + + end