Skip to content

Commit

Permalink
Add shared-network configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Valantin committed Jul 18, 2024
1 parent 997a3b4 commit 141f220
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
14 changes: 14 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
Hash[String, Hash] $hosts = {},
Variant[Array[String], Optional[String]] $includes = undef,
String $config_comment = 'dhcpd.conf',
Optional[String] $shared_network = undef,
) inherits dhcp::params {
# In case people set interface instead of interfaces work around
# that. If they set both, use interfaces and the user is a unwise
Expand Down Expand Up @@ -157,6 +158,19 @@
order => '01',
}

if $shared_network {
concat::fragment { 'dhcp.conf+69_shared':
target => "${dhcp_dir}/dhcpd.conf",
content => "shared-network ${shared_network} {\n",
order => '69',
}
concat::fragment { 'dhcp.conf+71_shared':
target => "${dhcp_dir}/dhcpd.conf",
content => "}\n",
order => '71',
}
}

create_resources('dhcp::subnet', $subnets)
create_resources('dhcp::pool', $pools)
create_resources('dhcp::host', $hosts)
Expand Down
31 changes: 31 additions & 0 deletions spec/acceptance/shared_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'spec_helper_acceptance'

describe 'Simple installation' do
interface = 'eth0'
config_file = fact('os.family') == 'Archlinux' ? '/etc/dhcpd.conf' : '/etc/dhcp/dhcpd.conf'

it_behaves_like 'an idempotent resource' do
let(:manifest) do
<<-EOS
$interface = $facts['networking']['interfaces']['#{interface}']
class { 'dhcp':
interfaces => ['#{interface}'],
shared_network => 'shared',
}
dhcp::pool { "default subnet":
network => $interface['network'],
mask => $interface['netmask'],
}
EOS
end
end

it_behaves_like 'a DHCP server'

describe file(config_file) do
it { is_expected.to be_file }
its(:content) { should match %r{shared-network shared} }
end
end
14 changes: 14 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,20 @@
it { is_expected.to compile.and_raise_error(%r{dnsupdateserver or nameservers parameter is required to enable ddns}) }
end
end

describe "with shared_network" do
let(:params) { super().merge(shared_network: "shared") }

let(:expected_content) do
<<~CONTENT
shared-network shared {
CONTENT
end

it do
is_expected.to contain_concat__fragment('dhcp.conf+69_shared').with_content(expected_content)
end
end
end
end
end

0 comments on commit 141f220

Please sign in to comment.