Skip to content

Commit

Permalink
Fix an ERB validation error, by moving logic for calculating the ippo…
Browse files Browse the repository at this point in the history
…ol cache size in to puppet, rather than in ERB
  • Loading branch information
nward committed May 6, 2021
1 parent 155e385 commit e79c9bf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
7 changes: 7 additions & 0 deletions manifests/module/ippool.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
Integer $maximum_timeout = 0,
Optional[String] $key = undef,
) {
if ($cache_size !~ Undef) {
$real_cache_size = $cache_size
} else {
$real_cache_size = inline_template(@("IPADDRRANGE"/L))
<%- require 'ipaddr' -%><%=(IPAddr.new @range_stop).to_i - (IPAddr.new @range_start).to_i + 1 %>
|-IPADDRRANGE
}

freeradius::module { "ippool_${name}":
ensure => $ensure,
Expand Down
23 changes: 23 additions & 0 deletions spec/defines/module/ippool_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper'

describe 'freeradius::module::ippool' do
include_context 'redhat_common_dependencies'

let(:title) { 'test' }

let(:params) do
{
range_start: '192.168.0.1',
range_stop: '192.168.0.10',
netmask: '255.255.255.0',
}
end

it do
is_expected.to contain_freeradius__module('ippool_test')
.with_content(%r{^\s+range_start = 192.168.0.1$})
.with_content(%r{^\s+range_stop = 192.168.0.10$})
.with_content(%r{^\s+netmask = 255.255.255.0$})
.with_content(%r{^\s+cache_size = 10$})
end
end
8 changes: 1 addition & 7 deletions templates/ippool.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<%- require 'ipaddr' -%>

# Do server side ip pool management. Should be added in
# post-auth and accounting sections.
#
Expand Down Expand Up @@ -37,11 +35,7 @@ ippool <%= @name %> {
# The gdbm cache size for the db files. Should
# be equal to the number of ip's available in
# the ip pool
<%- if @cache_size -%>
cache_size = <%= @cache_size %>
<%- else -%>
cache_size = <%= (IPAddr.new @range_stop).to_i() - (IPAddr.new @range_start).to_i() + 1 %>
<%- end -%>
cache_size = <%= @real_cache_size %>

# Helper db index file used in multilink
<%- if @ip_index -%>
Expand Down

0 comments on commit e79c9bf

Please sign in to comment.