Skip to content

Commit 61ea9e7

Browse files
committed
(CONT-256) Removing outdated code
Prior to this commit, the firewall modules had multiple instances of outdated code. This commit aims to clean-up some of that code to keep the module clean and readable.
1 parent 3739745 commit 61ea9e7

File tree

5 files changed

+16
-69
lines changed

5 files changed

+16
-69
lines changed

lib/facter/iptables_persistent_version.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@
55
setcode do
66
# Throw away STDERR because dpkg >= 1.16.7 will make some noise if the
77
# package isn't currently installed.
8-
os = Facter.value(:operatingsystem)
9-
os_release = Facter.value(:operatingsystemrelease)
10-
cmd = if (os == 'Debian' && (Puppet::Util::Package.versioncmp(os_release, '8.0') >= 0)) ||
11-
(os == 'Ubuntu' && (Puppet::Util::Package.versioncmp(os_release, '14.10') >= 0)) ||
12-
(os == 'Debian' && (Puppet::Util::Package.versioncmp(os_release, 'unstable') >= 0))
13-
"dpkg-query -Wf '${Version}' netfilter-persistent 2>/dev/null"
14-
else
15-
"dpkg-query -Wf '${Version}' iptables-persistent 2>/dev/null"
16-
end
8+
cmd = "dpkg-query -Wf '${Version}' netfilter-persistent 2>/dev/null"
179
version = Facter::Core::Execution.execute(cmd)
1810

1911
if version.nil? || !version.match(%r{\d+\.\d+})

lib/puppet/type/firewall.rb

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,12 +2342,9 @@ def should_to_s(value)
23422342
end
23432343
end
23442344

2345-
# autobefore is only provided since puppet 4.0
2346-
if Puppet::Util::Package.versioncmp(Puppet.version, '4.0') >= 0
2347-
# On RHEL 7 this needs to be threaded correctly to manage SE Linux permissions after persisting the rules
2348-
autobefore(:file) do
2349-
['/etc/sysconfig/iptables', '/etc/sysconfig/ip6tables']
2350-
end
2345+
# On RHEL 7 this needs to be threaded correctly to manage SE Linux permissions after persisting the rules
2346+
autobefore(:file) do
2347+
['/etc/sysconfig/iptables', '/etc/sysconfig/ip6tables']
23512348
end
23522349

23532350
validate do

manifests/linux/debian.pp

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,16 @@
2525
$package_name = $firewall::params::package_name,
2626
$package_ensure = $firewall::params::package_ensure,
2727
) inherits ::firewall::params {
28-
if $package_name {
29-
#Fixes hang while installing iptables-persistent on debian 8
30-
exec { 'iptables-persistent-debconf':
31-
command => "/bin/echo \"${package_name} ${package_name}/autosave_v4 boolean false\" |
32-
/usr/bin/debconf-set-selections && /bin/echo \"${package_name} ${package_name}/autosave_v6 boolean false\" |
33-
/usr/bin/debconf-set-selections",
28+
ensure_packages([$package_name], {
29+
ensure => $package_ensure
30+
})
3431

35-
refreshonly => true,
36-
}
37-
ensure_packages([$package_name], {
38-
ensure => $package_ensure,
39-
require => Exec['iptables-persistent-debconf']
40-
})
41-
}
42-
43-
if($::operatingsystemrelease =~ /^6\./ and $enable == true and $::iptables_persistent_version
44-
and versioncmp($::iptables_persistent_version, '0.5.0') < 0) {
45-
# This fixes a bug in the iptables-persistent LSB headers in 6.x, without it
46-
# we lose idempotency
47-
exec { 'iptables-persistent-enable':
48-
logoutput => on_failure,
49-
command => '/usr/sbin/update-rc.d iptables-persistent enable',
50-
unless => '/usr/bin/test -f /etc/rcS.d/S*iptables-persistent',
51-
require => Package[$package_name],
52-
}
53-
} else {
54-
# This isn't a real service/daemon. The start action loads rules, so just
55-
# needs to be called on system boot.
56-
service { $service_name:
57-
ensure => undef,
58-
enable => $enable,
59-
hasstatus => true,
60-
require => Package[$package_name],
61-
}
32+
# This isn't a real service/daemon. The start action loads rules, so just
33+
# needs to be called on system boot.
34+
service { $service_name:
35+
ensure => undef,
36+
enable => $enable,
37+
hasstatus => true,
38+
require => Package[$package_name],
6239
}
6340
}

manifests/linux/redhat.pp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@
4949
# RHEL 7 / CentOS 7 and later and Fedora 15 and later require the iptables-services
5050
# package, which provides the /usr/libexec/iptables/iptables.init used by
5151
# lib/puppet/util/firewall.rb.
52-
if ($::operatingsystem != 'Amazon')
53-
and (($::operatingsystem != 'Fedora' and versioncmp($::operatingsystemrelease, '7.0') >= 0)
54-
or ($::operatingsystem == 'Fedora' and versioncmp($::operatingsystemrelease, '15') >= 0)) {
52+
if ($::operatingsystem != 'Amazon') {
5553
if $firewalld_manage {
5654
service { 'firewalld':
5755
ensure => stopped,
@@ -74,9 +72,7 @@
7472
)
7573
}
7674

77-
if ($::operatingsystem != 'Amazon')
78-
and (($::operatingsystem != 'Fedora' and versioncmp($::operatingsystemrelease, '7.0') >= 0)
79-
or ($::operatingsystem == 'Fedora' and versioncmp($::operatingsystemrelease, '15') >= 0)) {
75+
if ($::operatingsystem != 'Amazon') {
8076
if $ensure == 'running' {
8177
exec { '/usr/bin/systemctl daemon-reload':
8278
require => Package[$package_name],
@@ -134,13 +130,6 @@
134130
}
135131
}
136132

137-
# Before puppet 4, the autobefore on the firewall type does not work - therefore
138-
# we need to keep this workaround here
139-
if versioncmp($::puppetversion, '4.0') <= 0 {
140-
File<| title == "/etc/sysconfig/${service_name}" |> -> Service<| title == $service_name |>
141-
File<| title == "/etc/sysconfig/${service_name_v6}" |> -> Service<| title == $service_name_v6 |>
142-
}
143-
144133
# Redhat 7 selinux user context for /etc/sysconfig/iptables is set to system_u
145134
# Redhat 7 selinux type context for /etc/sysconfig/iptables is set to system_conf_t
146135
case $::selinux {
@@ -149,11 +138,6 @@
149138
case $::operatingsystem {
150139
'CentOS': {
151140
case $::operatingsystemrelease {
152-
/^5\..*/: {
153-
$seluser = 'system_u'
154-
$seltype = 'etc_t'
155-
}
156-
157141
/^6\..*/: {
158142
$seluser = 'unconfined_u'
159143
$seltype = 'system_conf_t'

manifests/params.pp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
if versioncmp($::operatingsystemrelease, '34') >= 0 {
2222
$package_name = 'iptables-services'
2323
$iptables_name = 'iptables-compat'
24-
} elsif versioncmp($::operatingsystemrelease, '15') >= 0 {
25-
$package_name = 'iptables-services'
26-
$iptables_name = 'iptables'
2724
} else {
2825
$iptables_name = 'iptables'
2926
$package_name = undef

0 commit comments

Comments
 (0)