Skip to content

Commit

Permalink
Allow additional options to be specified for dhcp::host
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Mar 31, 2015
1 parent 692d65f commit 7c53837
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions manifests/host.pp
Expand Up @@ -3,9 +3,12 @@
define dhcp::host (
$ip,
$mac,
$options = {},
$comment=''
) {

validate_hash($options)

$host = $name

include dhcp::params
Expand Down
40 changes: 39 additions & 1 deletion spec/defines/host_spec.rb
Expand Up @@ -10,13 +10,51 @@
:osfamily => 'RedHat',
}
end
let :params do
let :default_params do
{
'ip' => '1.2.3.4',
'mac' => '90:FB:A6:E4:08:9F',
'comment' => 'test_comment'
}
end
let(:params) { default_params }

it { should contain_concat__fragment("dhcp_host_#{title}") }

it 'creates a host declaration' do
content = subject.resource('concat::fragment', "dhcp_host_#{title}").send(:parameters)[:content]
expected_lines = [
"host #{title} {",
" hardware ethernet #{params['mac']};",
" fixed-address #{params['ip']};",
" option host-name \"#{title}\";",
'}',
]
expect(content.split("\n")).to eq(expected_lines)
end

context 'when options defined' do
let(:params) do
default_params.merge({
:options => {
'vendor-encapsulated-options' => '01:04:31:41:50:43',
'domain-name-servers' => '10.0.0.1',
}
})
end

it 'creates a host declaration with options' do
content = subject.resource('concat::fragment', "dhcp_host_#{title}").send(:parameters)[:content]
expected_lines = [
"host #{title} {",
" hardware ethernet #{params['mac']};",
" fixed-address #{params['ip']};",
" option host-name \"#{title}\";",
" option domain-name-servers 10.0.0.1;",
" option vendor-encapsulated-options 01:04:31:41:50:43;",
'}',
]
expect(content.split("\n")).to eq(expected_lines)
end
end
end
5 changes: 5 additions & 0 deletions templates/dhcpd.host.erb
Expand Up @@ -2,4 +2,9 @@ host <%= @host %> {
hardware ethernet <%= @mac %>;
fixed-address <%= @ip %>;
option host-name "<%= @name %>";
<% if not @options.empty? -%>
<% @options.keys.sort.each do |option| -%>
option <%= option %> <%= @options[option] %>;
<% end -%>
<% end -%>
}

0 comments on commit 7c53837

Please sign in to comment.