From 4d0a105c16cc8d4efd6b15c12d94e629bfc8c620 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Wed, 2 Mar 2022 08:57:24 +0900 Subject: [PATCH] Add support for PowerDNS 4 backend Change-Id: Ie9cc92622e1bf281fc07c97f480f5a3c16b7e6f3 --- manifests/backend/pdns4.pp | 74 +++++++++++++++++++ .../notes/pdns4-07768cbace039aee.yaml | 5 ++ spec/classes/designate_backend_pdns4_spec.rb | 58 +++++++++++++++ templates/pdns4-pools.yaml.erb | 25 +++++++ 4 files changed, 162 insertions(+) create mode 100644 manifests/backend/pdns4.pp create mode 100644 releasenotes/notes/pdns4-07768cbace039aee.yaml create mode 100644 spec/classes/designate_backend_pdns4_spec.rb create mode 100644 templates/pdns4-pools.yaml.erb diff --git a/manifests/backend/pdns4.pp b/manifests/backend/pdns4.pp new file mode 100644 index 00000000..c1f18172 --- /dev/null +++ b/manifests/backend/pdns4.pp @@ -0,0 +1,74 @@ +# == Class designate::backend::pdns4 +# +# Configure PowerDNS 4 as backend +# +# == Parameters +# +# [*api_token*] +# (Required) Token string to authenticate with the PowerDNS Authoritative +# Server. +# +# [*pdns4_hosts*] +# (Optional) Host running DNS service. +# Defaults to ['127.0.0,1']. +# +# [*pdns4_port*] +# (Optional) TCP port to connect to DNS service. +# Defaults to 53. +# +# [*mdns_hosts*] +# (Optional) Array of hosts where designate-mdns service is running. +# Defaults to ['127.0.0.1']. +# +# [*mdns_port*] +# (Optional) TCP Port to connect to designate-mdns service. +# Defaults to 5354. +# +# [*api_endpoint*] +# (Optional) URL to access the PowerDNS Authoritative Server. +# Defaults to 'http://127.0.0.1:8081'. +# +# [*tsigkey_name*] +# (Optional) Name of TSIGKey. +# Defaults to undef. +# +# [*manage_pool*] +# (Optional) Manage pools.yaml and update pools by designate-manage command +# Defaults to true +# +class designate::backend::pdns4 ( + $api_token, + $pdns4_hosts = ['127.0.0.1'], + $pdns4_port = 53, + $mdns_hosts = ['127.0.0.1'], + $mdns_port = 5354, + $api_endpoint = 'http://127.0.0.1:8081', + $tsigkey_name = undef, + $manage_pool = true, +) { + + include designate::deps + include designate::params + + if $manage_pool { + file { '/etc/designate/pools.yaml': + ensure => present, + path => '/etc/designate/pools.yaml', + owner => $designate::params::user, + group => $designate::params::group, + mode => '0640', + content => template('designate/pdns4-pools.yaml.erb'), + require => Anchor['designate::config::begin'], + before => Anchor['designate::config::end'], + } + + exec { 'designate-manage pool update': + command => 'designate-manage pool update', + path => '/usr/bin', + user => $designate::params::user, + refreshonly => true, + require => Anchor['designate::service::end'], + subscribe => File['/etc/designate/pools.yaml'], + } + } +} diff --git a/releasenotes/notes/pdns4-07768cbace039aee.yaml b/releasenotes/notes/pdns4-07768cbace039aee.yaml new file mode 100644 index 00000000..9a16092f --- /dev/null +++ b/releasenotes/notes/pdns4-07768cbace039aee.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + The new ``designate::backend::pdns4`` class has been added. This class + supports setting up PowerDNS 4 backend. diff --git a/spec/classes/designate_backend_pdns4_spec.rb b/spec/classes/designate_backend_pdns4_spec.rb new file mode 100644 index 00000000..ca86c672 --- /dev/null +++ b/spec/classes/designate_backend_pdns4_spec.rb @@ -0,0 +1,58 @@ +# +# Unit tests for designate::backend::pdns4 +# +require 'spec_helper' + +describe 'designate::backend::pdns4' do + + shared_examples 'designate-backend-pdns4' do + + let :params do + { :api_token => 'mytoken' } + end + + context 'with default params' do + it 'configures named and pool' do + is_expected.to contain_file('/etc/designate/pools.yaml').with( + :ensure => 'present', + :path => '/etc/designate/pools.yaml', + :owner => 'designate', + :group => 'designate', + :mode => '0640', + ) + is_expected.to contain_exec('designate-manage pool update').with( + :command => 'designate-manage pool update', + :path => '/usr/bin', + :user => 'designate', + :refreshonly => true, + ) + end + end + + context 'with pool management disabled' do + before do + params.merge!({ + :manage_pool => false + }) + end + it 'does not configure pool' do + is_expected.to_not contain_file('/etc/designate/pools.yaml') + is_expected.to_not contain_exec('designate-manage pool update') + end + end + + end + + on_supported_os({ + :supported_os => OSDefaults.get_supported_os + }).each do |os,facts| + context "on #{os}" do + let (:facts) do + facts.merge!(OSDefaults.get_facts()) + end + + it_behaves_like 'designate-backend-pdns4' + end + end + +end diff --git a/templates/pdns4-pools.yaml.erb b/templates/pdns4-pools.yaml.erb new file mode 100644 index 00000000..3cfa0bf5 --- /dev/null +++ b/templates/pdns4-pools.yaml.erb @@ -0,0 +1,25 @@ +--- +- name: default + description: Default pool + attributes: {} + + targets: +<% @pdns4_hosts.each do |pdns4_host| -%> + - type: pdns4 + description: PowerDNS4 DNS Server <%= pdns4_host %> + + masters: +<% @mdns_hosts.each do |mdns_host| -%> + - host: <%= mdns_host %> + port: <%= @mdns_port.to_s %> +<% end -%> + + options: + host: <%= pdns4_host %> + port: <%= @dns_port.to_s %> + api_endpoint: <%= @api_endpoint %> + api_token: <%= @api_token %> + <%- if @tsigkey_name -%> + tsigkey_name: <%= @tsigkey_name %> + <%- end -%> +<% end -%>