Commit 12dab8c2 authored by Nathan Ward's avatar Nathan Ward
Browse files

Add radsniff support for Debian-like OSes and specifying envfile and pidfile to support any OS

parent b2714c80
......@@ -172,4 +172,14 @@ class freeradius::params {
}
$radacctdir = "\${logdir}/radacct"
# Default radsniff environment file location
$fr_radsniff_envfile = $::osfamily ? {
'RedHat' => '/etc/sysconfig/radsniff',
'Debian' => '/etc/defaults/radsniff',
default => undef,
}
# Default radsniff pid file location
$fr_radsniff_pidfile = "/var/run/${fr_service}/radsniff.pid"
}
# @summary configure and run radsniff
#
# @param envfile path to the environment file, used by the systemd unit
# @param options commandline options passed to radsniff when it runs
# @param
class freeradius::radsniff (
Optional[String] $envfile = undef,
String $options = '',
) {
Optional[String] $pidfile = undef,
) inherits freeradius::params {
unless $::freeradius::utils_support {
fail('freeradius::radsniff requires freeradius have utils_support enabled')
}
unless $facts['os']['family'] == 'RedHat' {
fail('freeradius::radsniff only supports RedHat like OSes at the moment')
# Calculate the envfile to use - specified, then calculated, then error if none
if $envfile {
$final_envfile = $envfile
} else {
if $freeradius::fr_radsniff_envfile {
$final_envfile = $freeradius::fr_radsniff_envfile
} else {
fail('freeradius::radsniff requires envfile to be explicitly set on this OS')
}
}
# Calculate the pidfile to use - specified, then calculated, then error if none
if $pidfile {
$final_pidfile = $pidfile
} else {
if $freeradius::fr_radsniff_pidfile {
$final_pidfile = $freeradius::fr_radsniff_pidfile
} else {
fail('freeradius::radsniff requires pidfile to be explicitly set on this OS')
}
}
$escaped_cmd = $options.regsubst('"','\\\\"','G')
file {'/etc/sysconfig/radsniff':
file { $envfile:
content => @("SYSCONFIG"),
RADSNIFF_OPTIONS="${escaped_cmd}"
| SYSCONFIG
......
......@@ -13,6 +13,14 @@ describe 'freeradius::radsniff' do
}
end
if os_facts[:osfamily] =~ %r{^RedHat|Debian$}
it do
is_expected.to contain_service('radsniff')
.with_ensure('running')
.with_enable(true)
end
end
case os_facts[:osfamily]
when 'RedHat'
it do
......@@ -23,19 +31,63 @@ describe 'freeradius::radsniff' do
end
it do
is_expected.to contain_service('radsniff')
.with_ensure('running')
.with_enable(true)
is_expected.to contain_systemd__unit_file('radsniff.service')
.with_content(%r{^Pidfile=/var/run/radiusd/radsniff.pid$})
.with_content(%r{^EnvironmentFile=/etc/sysconfig/radsniff$})
.with_content(%r{^ExecStart=/usr/bin/radsniff -P /var/run/radiusd/radsniff.pid -d /etc/raddb $RADSNIFF_OPTIONS$})
.that_notifies('Service[radsniff]')
end
when 'Debian'
it do
is_expected.to contain_file('/etc/defaults/radsniff')
.with_content(%r{RADSNIFF_OPTIONS="radsniff cmd \\"line\\" options"})
.that_notifies('Service[radsniff]')
.that_requires('Package[freeradius-utils]')
end
it do
is_expected.to contain_systemd__unit_file('radsniff.service')
.with_source('puppet:///modules/freeradius/radsniff.service')
.with_content(%r{^Pidfile=/var/run/freeradius/radsniff.pid$})
.with_content(%r{^EnvironmentFile=/etc/defaults/radsniff$})
.with_content(%r{^ExecStart=/usr/bin/radsniff -P /var/run/freeradius/radsniff.pid -d /etc/freeradius $RADSNIFF_OPTIONS$})
.that_notifies('Service[radsniff]')
end
else
it do
is_expected.to compile.and_raise_error(%r{radsniff only supports RedHat})
is_expected.to compile.and_raise_error(%r{freeradius::radsniff requires envfile to be explicitly set on this OS})
is_expected.to compile.and_raise_error(%r{freeradius::radsniff requires pidfile to be explicitly set on this OS})
end
end
context 'with envfile and pidfile set' do
let(:params) do
super().merge(
envfile: '/test/env/file',
pidfile: '/a/pid/file',
)
end
if os_facts[:osfamily] !~ %r{^RedHat|Debian$}
it do
is_expected.to contain_service('radsniff')
.with_ensure('running')
.with_enable(true)
end
end
it do
is_expected.to contain_file('/test/env/file')
.with_content(%r{RADSNIFF_OPTIONS="radsniff cmd \\"line\\" options"})
.that_notifies('Service[radsniff]')
.that_requires('Package[freeradius-utils]')
end
it do
is_expected.to contain_systemd__unit_file('radsniff.service')
.with_content(%r{^Pidfile=/a/pid/file$})
.with_content(%r{^EnvironmentFile=/test/env/file$})
.with_content(%r{^ExecStart=/usr/bin/radsniff -P /a/pid/file -d /etc/freeradius $RADSNIFF_OPTIONS$})
.that_notifies('Service[radsniff]')
end
end
end
......
......@@ -5,9 +5,9 @@ After=radiusd.target
[Service]
Type=forking
PIDFile=/var/run/radiusd/radsniff.pid
EnvironmentFile=/etc/sysconfig/radsniff
ExecStart=/usr/bin/radsniff -P /var/run/radiusd/radsniff.pid -d /etc/raddb $RADSNIFF_OPTIONS
Pidfile=<%=scope['::freeradius::radsniff::final_pidfile']%>
EnvironmentFile=<%=scope['::freeradius::radsniff::final_envpath']%>
ExecStart=/usr/bin/radsniff -P <%=scope['::freeradius::radsniff::pidpath']%> -d <%=scope['::freeradius::radsniff::fr_basepath']%> $RADSNIFF_OPTIONS
[Install]
WantedBy=multi-user.target
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment