Skip to content

fixes to ipset_sync #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions files/ipset_init
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ scd=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))

cfg="${default_cfg}"

while getopts "c:dhi:" OPTION; do
while getopts "c:h:" OPTION; do
case ${OPTION} in
c)
cfg=${OPTARG}
Expand All @@ -46,7 +46,8 @@ fi
### autostart

# iterate over basenames in config directory
for item in $(find "${cfg}" -mindepth 1 -maxdepth 1 -type f -and \( -name '*.set' -or -name '*.hdr' \) -printf '%f\n' | sed -re 's/\.[^.]+$//' | sed -e '/^$/d' | sort -u); do
for path in `echo $cfg/*.set`; do
item=`basename $path .set`
# skip if the configuration is not complete
if ! ( [ -f "${cfg}/${item}.hdr" ] && [ -f "${cfg}/${item}.set" ] ); then
continue
Expand Down
2 changes: 1 addition & 1 deletion files/ipset_sync
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function construct_ipset_dump() {
# recreate the dump format from config files manually
(
cat "${f_header}";
cat "${f_content}" | grep -v '^[ ]*#' | sed -re "s/(.*)/add ${id} \\1/" | LC_ALL=C sort
cat "${f_content}" | sed -e '/^create/d' -e '/^[ ]*#/d' -e 's/#.*$//g' -e'/^$/d' -re "s/(.*)/add ${id} \\1/" | LC_ALL=C sort | LC_ALL=C uniq
)
}

Expand Down
2 changes: 0 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@
if $set =~ /^puppet:\/\// {
# passed as puppet file
file { "${::ipset::params::config_path}/${title}.set":
ensure => present,
source => $set,
}
} elsif $set =~ /^file:\/\// {
# passed as target node file
file { "${::ipset::params::config_path}/${title}.set":
ensure => present,
source => regsubst($set, '^.{7}', ''),
}
} else {
Expand Down
56 changes: 33 additions & 23 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# installs startup files and scripts
class ipset::install {
include ipset::params

$cfg = $::ipset::params::config_path

# main package
package { $::ipset::params::package:
alias => 'ipset',
ensure => installed,
alias => 'ipset',
}

# directory with config profiles (*.set & *.hdr files)
Expand All @@ -18,29 +19,38 @@
ipset::install::helper_script { ['ipset_sync', 'ipset_init']: }

# autostart
if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '6' {
# upstart starter
file { '/etc/init/ipset.conf':
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/init.upstart.erb"),
}
} else {
if $::osfamily == 'RedHat' and $::operatingsystemmajrelease == '7' {
# systemd
file { '/usr/lib/systemd/system/ipset.service':
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/systemd.service.erb"),
case $::osfamily {
'RedHat', 'redhat': {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly, case's in puppet against strings are case insensitive.

case $::operatingsystemrelease {
/^6.*/: { # upstart starter
file { '/etc/init/ipset.conf':
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/init.upstart.erb"),
}
}
/^7.*/: { # systemd
file { '/usr/lib/systemd/system/ipset.service':
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/systemd.service.erb"),
}
file { '/etc/systemd/system/basic.target.wants/ipset.service':
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't your addition, but wouldn't it be better to just run systemctl daemon-reload as a refreshonly exec if the systemd file changes? That way the backend will handle the linking incase someone decides to change the target at some point inside the template systemd service file...
exec's name would be(to avoid conflicts) 'ipset_systemctl_daemonreload'
I'd plug this stuff into a PR myself, but I just saw this module and was deciding whether to begin using it or not.

ensure => link,
target => '/usr/lib/systemd/system/ipset.service',
}
}
default: { fail("Unsupported RedHat family version is ${$::operatingsystemrelease} - autostart not enabled") }
}
file { '/etc/systemd/system/basic.target.wants/ipset.service':
ensure => link,
target => '/usr/lib/systemd/system/ipset.service',
}
} else {
warning('Autostart of ipset not implemented for this OS.')
}
'': { # handle bug in our Jenkins that returns empty strings for all of these when verifying
if "${$::osfamily}${$::operatingsystem}${$::operatingsystemmajrelease}" == '' {
warning("Got null for OS Family, assuming I'm running in Jenkins and this is a known bug!") }
else { fail( "Unsupported OSFamily \"${$::osfamily}\" OS is \"${$::operatingsystem}\" major version is \"${$::operatingsystemmajrelease}\" ") }
}
default: { fail( "Unsupported OSFamily \"${$::osfamily}\" OS is \"${$::operatingsystem}\" major version is \"${$::operatingsystemmajrelease}\" ") }
}

}
17 changes: 17 additions & 0 deletions spec/classes/ipset_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe 'ipset' do
it do
should contain_package('ipset')
end
it 'drops ipset_init' do
should contain_file('/usr/local/sbin/ipset_init')
end
it 'drops ipset_sync' do
should contain_file('/usr/local/sbin/ipset_sync')
end
it 'drops ipset.conf' do
should contain_file('/etc/init/ipset.conf')
end

end
15 changes: 15 additions & 0 deletions spec/defines/ipset_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require 'spec_helper'

describe 'ipset' do
let(:title){ 'ipset' }
let(:params){{ :set => "myipset" }}
it do
should contain_package('ipset')
should contain_file("/usr/local/sbin/ipset_init").
with_mode('0754').with_owner('root').with_group('root').
with_source("puppet:///modules/ipset/ipset_init")
should contain_file("/usr/local/sbin/ipset_sync").
with_mode('0754').with_owner('root').with_group('root').
with_source("puppet:///modules/ipset/ipset_sync")
end
end
Empty file added spec/fixtures/manifests/site.pp
Empty file.
1 change: 1 addition & 0 deletions spec/fixtures/modules/ipset/files
1 change: 1 addition & 0 deletions spec/fixtures/modules/ipset/manifests
1 change: 1 addition & 0 deletions spec/fixtures/modules/ipset/templates
1 change: 1 addition & 0 deletions spec/spec.opts
1 change: 1 addition & 0 deletions spec/spec_helper.rb