From be6954edb5d3ff9841bd40d509f7744e302ced80 Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Thu, 2 Apr 2015 14:26:57 -0500 Subject: [PATCH] Add omapi_port parameter --- README.md | 1 + manifests/init.pp | 1 + spec/classes/dhcp_spec.rb | 37 +++++++++++++++++++++++++++++++++ spec/lib/module_spec_helper.rb | 14 +++++++++++++ spec/spec_helper.rb | 1 + templates/dhcpd.conf-header.erb | 3 +++ 6 files changed, 57 insertions(+) create mode 100644 spec/lib/module_spec_helper.rb diff --git a/README.md b/README.md index 10ef08e2..32375e3e 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Define the server and the zones it will be responsible for. require => Bind::Key['rndc-key'], pxeserver => '10.0.1.50', pxefilename => 'pxelinux.0', + omapi_port => 7911, } ### dhcp::pool diff --git a/manifests/init.pp b/manifests/init.pp index d0865cfe..cf2aca5f 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -21,6 +21,7 @@ $max_lease_time = 86400, $service_ensure = running, $globaloptions = '', + $omapi_port = undef, ) { if $dnsdomain == undef { diff --git a/spec/classes/dhcp_spec.rb b/spec/classes/dhcp_spec.rb index 8d296ce8..ae227e10 100644 --- a/spec/classes/dhcp_spec.rb +++ b/spec/classes/dhcp_spec.rb @@ -58,6 +58,43 @@ end end + context 'header' do + let :params do + default_params.merge({ + :interfaces => ['eth0'], + }) + end + + it 'defines dhcp header contents' do + verify_concat_fragment_exact_contents(subject, 'dhcp-conf-header', [ + 'authoritative;', + 'default-lease-time 3600;', + 'max-lease-time 86400;', + 'log-facility daemon;', + 'option domain-name "sampledomain.com";', + 'option domain-name-servers 1.1.1.1;', + 'option fqdn.no-client-update on; # set the "O" and "S" flag bits', + 'option fqdn.rcode2 255;', + 'option pxegrub code 150 = text;', + ]) + end + + context 'omapi_port => 7911' do + let :params do + default_params.merge({ + :interfaces => ['eth0'], + :omapi_port => 7911, + }) + end + + it 'defines dhcp header contents' do + verify_concat_fragment_contents(subject, 'dhcp-conf-header', [ + 'omapi-port 7911;', + ]) + end + end + end + context 'ntp' do let :params do default_params.merge({ diff --git a/spec/lib/module_spec_helper.rb b/spec/lib/module_spec_helper.rb new file mode 100644 index 00000000..ca7a5d60 --- /dev/null +++ b/spec/lib/module_spec_helper.rb @@ -0,0 +1,14 @@ +def verify_concat_fragment_contents(subject, title, expected_lines) + content = subject.resource('concat::fragment', title).send(:parameters)[:content] + (content.split("\n") & expected_lines).should == expected_lines +end + +def verify_concat_fragment_exact_contents(subject, title, expected_lines) + content = subject.resource('concat::fragment', title).send(:parameters)[:content] + content.split(/\n/).reject { |line| line =~ /(^#|^$|^\s+#)/ }.should == expected_lines +end + +def verify_exact_contents(subject, title, expected_lines) + content = subject.resource('file', title).send(:parameters)[:content] + content.split(/\n/).reject { |line| line =~ /(^#|^$|^\s+#)/ }.should == expected_lines +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2c6f5664..13a69da5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1 +1,2 @@ require 'puppetlabs_spec_helper/module_spec_helper' +require 'lib/module_spec_helper' diff --git a/templates/dhcpd.conf-header.erb b/templates/dhcpd.conf-header.erb index 48407fef..9f12b2af 100644 --- a/templates/dhcpd.conf-header.erb +++ b/templates/dhcpd.conf-header.erb @@ -3,6 +3,9 @@ # dhcpd.conf # ---------- authoritative; +<% if @omapi_port -%> +omapi-port <%= @omapi_port %>; +<% end -%> default-lease-time <%= @default_lease_time %>; max-lease-time <%= @max_lease_time %>; log-facility <%= @logfacility %>;