Permalink
Browse files

Add dns::powerdns options

Closes GH-242
  • Loading branch information...
1 parent e5798b3 commit f0297694529c9d028058d715b5771133cb811172 @ekohl ekohl committed Aug 10, 2016
View
39 manifests/plugin/dns/powerdns.pp
@@ -4,31 +4,40 @@
#
# === Parameters:
#
-# $mysql_hostname:: MySQL server hostname
+# $backend:: The backend to select, either mysql or postgresql.
#
-# $mysql_username:: MySQL server username
+# $mysql_hostname:: MySQL server hostname. Only used when the backend is mysql.
#
-# $mysql_password:: MySQL server password
+# $mysql_username:: MySQL server username. Only used when the backend is mysql.
#
-# $mysql_database:: MySQL server database
+# $mysql_password:: MySQL server password. Only used when the backend is mysql.
#
-# $manage_database:: Whether to manage the mysql database. Also includes the mysql server.
-# type:boolean
+# $mysql_database:: MySQL server database. Only used when the backend is mysql.
#
-# $pdnssec:: pdnssec command to run rectify-zone with. Can be an empty string.
+# $postgresql_connection:: The postgresql connection string.
+#
+# $manage_database:: Whether to manage the database. Only works for
+# mysql. Includes the mysql server.
+# type:boolean
+#
+# $pdnssec:: pdnssec command to run rectify-zone with. Can be an
+# empty string.
#
class foreman_proxy::plugin::dns::powerdns (
- $mysql_hostname = $::foreman_proxy::plugin::dns::powerdns::params::mysql_hostname,
- $mysql_username = $::foreman_proxy::plugin::dns::powerdns::params::mysql_username,
- $mysql_password = $::foreman_proxy::plugin::dns::powerdns::params::mysql_password,
- $mysql_database = $::foreman_proxy::plugin::dns::powerdns::params::mysql_database,
- $manage_database = $::foreman_proxy::plugin::dns::powerdns::params::manage_database,
- $pdnssec = $::foreman_proxy::plugin::dns::powerdns::params::pdnssec,
+ $backend = $::foreman_proxy::plugin::dns::powerdns::params::backend,
+ $mysql_hostname = $::foreman_proxy::plugin::dns::powerdns::params::mysql_hostname,
+ $mysql_username = $::foreman_proxy::plugin::dns::powerdns::params::mysql_username,
+ $mysql_password = $::foreman_proxy::plugin::dns::powerdns::params::mysql_password,
+ $mysql_database = $::foreman_proxy::plugin::dns::powerdns::params::mysql_database,
+ $postgresql_connection = $::foreman_proxy::plugin::dns::powerdns::params::postgresql_connection,
+ $manage_database = $::foreman_proxy::plugin::dns::powerdns::params::manage_database,
+ $pdnssec = $::foreman_proxy::plugin::dns::powerdns::params::pdnssec,
) inherits foreman_proxy::plugin::dns::powerdns::params {
validate_bool($manage_database)
- validate_string($mysql_hostname, $mysql_username, $mysql_password, $mysql_database, $pdnssec)
+ validate_re($backend, '^mysql|postgresql$', 'Invalid backend: choose mysql or postgresql')
+ validate_string($mysql_hostname, $mysql_username, $mysql_password, $mysql_database, $postgresql_connection, $pdnssec)
- if $manage_database {
+ if $manage_database and $backend == 'mysql' {
include ::mysql::server
mysql::db { $mysql_database:
user => $mysql_username,
View
14 manifests/plugin/dns/powerdns/params.pp
@@ -1,8 +1,10 @@
class foreman_proxy::plugin::dns::powerdns::params {
- $mysql_hostname = 'localhost'
- $mysql_username = 'pdns'
- $mysql_password = cache_data('foreman_cache_data', 'smart_proxy_dns_powerdns_password', random_password(16))
- $mysql_database = 'pdns'
- $manage_database = false
- $pdnssec = 'pdnssec'
+ $backend = 'mysql'
+ $mysql_hostname = 'localhost'
+ $mysql_username = 'pdns'
+ $mysql_password = cache_data('foreman_cache_data', 'smart_proxy_dns_powerdns_password', random_password(16))
+ $mysql_database = 'pdns'
+ $postgresql_connection = '' # lint:ignore:empty_string_assignment
+ $manage_database = false
+ $pdnssec = 'pdnssec'
}
View
42 spec/classes/foreman_proxy__plugin__dns__powerdns_spec.rb
@@ -25,6 +25,7 @@
it 'should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/dns_powerdns.yml', [
'---',
+ ':powerdns_backend: "mysql"',
':powerdns_mysql_hostname: "localhost"',
':powerdns_mysql_username: "pdns"',
':powerdns_mysql_password: "password"',
@@ -51,6 +52,7 @@
it 'should contain the correct configuration' do
verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/dns_powerdns.yml', [
'---',
+ ':powerdns_backend: "mysql"',
':powerdns_mysql_hostname: "localhost"',
':powerdns_mysql_username: "pdns"',
':powerdns_mysql_password: "password"',
@@ -69,4 +71,44 @@
.with_grant(['ALL'])
end
end
+
+ context 'with backend postgresql' do
+ let :params do
+ {
+ :backend => 'postgresql',
+ :postgresql_connection => 'user=pdns',
+ :manage_database => true,
+ }
+ end
+
+ it { should compile.with_all_deps }
+
+ it 'should install the correct plugin' do
+ should contain_foreman_proxy__plugin('dns_powerdns')
+ end
+
+ it 'should contain the correct configuration' do
+ verify_exact_contents(catalogue, '/etc/foreman-proxy/settings.d/dns_powerdns.yml', [
+ '---',
+ ':powerdns_backend: "postgresql"',
+ ':powerdns_postgresql_connection: "user=pdns"',
+ ':powerdns_pdnssec: "pdnssec"',
+ ])
+ end
+
+ it 'should not manage the database' do
+ should_not contain_class('mysql::server')
+ should_not contain_mysql__db('pdns')
+ end
+ end
+
+ context 'with an invalid backend' do
+ let :params do
+ {
+ :backend => 'invalid',
+ }
+ end
+
+ it { expect { subject.call } .to raise_error(/Invalid backend: choose mysql or postgresql/) }
+ end
end
View
6 templates/plugin/dns_powerdns.yml.erb
@@ -1,6 +1,12 @@
---
+<% backend = scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::backend') -%>
+:powerdns_backend: "<%= backend %>"
+<% if backend == 'mysql' -%>
:powerdns_mysql_hostname: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_hostname') %>"
:powerdns_mysql_username: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_username') %>"
:powerdns_mysql_password: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_password') %>"
:powerdns_mysql_database: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::mysql_database') %>"
+<% elsif backend == 'postgresql' -%>
+:powerdns_postgresql_connection: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::postgresql_connection') %>"
+<% end -%>
:powerdns_pdnssec: "<%= scope.lookupvar('::foreman_proxy::plugin::dns::powerdns::pdnssec') %>"

0 comments on commit f029769

Please sign in to comment.