From d3df6fdfd9ac8f1f04b18564e7e934a0dffd1a62 Mon Sep 17 00:00:00 2001 From: Arnoud de Jonge Date: Fri, 29 Jan 2016 10:15:58 +0000 Subject: [PATCH] Added Designate Pool Manager Added classes and defines to manage the Designate Pool Manager. Change-Id: I52c3789394bc8719c4251abd13e489b47111f0f4 --- manifests/params.pp | 52 +++--- manifests/pool.pp | 32 ++++ manifests/pool_manager.pp | 149 ++++++++++++++++++ manifests/pool_manager_cache/memcache.pp | 26 +++ manifests/pool_manager_cache/sqlalchemy.pp | 53 +++++++ manifests/pool_nameserver.pp | 22 +++ manifests/pool_target.pp | 53 +++++++ ...ignate_pool_manager_cache_memcache_spec.rb | 61 +++++++ ...nate_pool_manager_cache_sqlalchemy_spec.rb | 68 ++++++++ spec/classes/designate_pool_manager_spec.rb | 139 ++++++++++++++++ .../defines/designate_pool_nameserver_spec.rb | 53 +++++++ spec/defines/designate_pool_spec.rb | 57 +++++++ spec/defines/designate_pool_target_spec.rb | 58 +++++++ 13 files changed, 799 insertions(+), 24 deletions(-) create mode 100644 manifests/pool.pp create mode 100644 manifests/pool_manager.pp create mode 100644 manifests/pool_manager_cache/memcache.pp create mode 100644 manifests/pool_manager_cache/sqlalchemy.pp create mode 100644 manifests/pool_nameserver.pp create mode 100644 manifests/pool_target.pp create mode 100644 spec/classes/designate_pool_manager_cache_memcache_spec.rb create mode 100644 spec/classes/designate_pool_manager_cache_sqlalchemy_spec.rb create mode 100644 spec/classes/designate_pool_manager_spec.rb create mode 100644 spec/defines/designate_pool_nameserver_spec.rb create mode 100644 spec/defines/designate_pool_spec.rb create mode 100644 spec/defines/designate_pool_target_spec.rb diff --git a/manifests/params.pp b/manifests/params.pp index fa740f94..07da4a40 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -12,35 +12,39 @@ class designate::params { case $::osfamily { 'RedHat': { # package name - $common_package_name = 'openstack-designate' - $api_package_name = 'openstack-designate-api' - $central_package_name = 'openstack-designate-central' - $agent_package_name = 'openstack-designate-agent' - $sink_package_name = 'openstack-designate-sink' - $mdns_package_name = 'openstack-designate-mdns' + $common_package_name = 'openstack-designate' + $api_package_name = 'openstack-designate-api' + $central_package_name = 'openstack-designate-central' + $agent_package_name = 'openstack-designate-agent' + $sink_package_name = 'openstack-designate-sink' + $pymysql_package_name = undef + $mdns_package_name = 'openstack-designate-mdns' + $pool_manager_package_name = 'openstack-designate-pool-manager' # service names - $agent_service_name = 'openstack-designate-agent' - $api_service_name = 'openstack-designate-api' - $central_service_name = 'openstack-designate-central' - $sink_service_name = 'openstack-designate-sink' - $pymysql_package_name = undef - $mdns_service_name = 'openstack-designate-mdns' + $agent_service_name = 'openstack-designate-agent' + $api_service_name = 'openstack-designate-api' + $central_service_name = 'openstack-designate-central' + $sink_service_name = 'openstack-designate-sink' + $mdns_service_name = 'openstack-designate-mdns' + $pool_manager_service_name = 'openstack-designate-pool-manager' } 'Debian': { # package name - $common_package_name = 'designate-common' - $api_package_name = 'designate-api' - $central_package_name = 'designate-central' - $agent_package_name = 'designate-agent' - $sink_package_name = 'designate-sink' - $mdns_package_name = 'designate-mdns' + $common_package_name = 'designate-common' + $api_package_name = 'designate-api' + $central_package_name = 'designate-central' + $agent_package_name = 'designate-agent' + $sink_package_name = 'designate-sink' + $pymysql_package_name = 'python-pymysql' + $pool_manager_package_name = 'openstack-designate-pool-manager' + $mdns_package_name = 'designate-mdns' # service names - $agent_service_name = 'designate-agent' - $api_service_name = 'designate-api' - $central_service_name = 'designate-central' - $sink_service_name = 'designate-sink' - $pymysql_package_name = 'python-pymysql' - $mdns_service_name = 'designate-mdns' + $agent_service_name = 'designate-agent' + $api_service_name = 'designate-api' + $central_service_name = 'designate-central' + $sink_service_name = 'designate-sink' + $mdns_service_name = 'designate-mdns' + $pool_manager_service_name = 'designate-pool-manager' } default: { fail("Unsupported osfamily: ${::osfamily} operatingsystem") diff --git a/manifests/pool.pp b/manifests/pool.pp new file mode 100644 index 00000000..53d0974a --- /dev/null +++ b/manifests/pool.pp @@ -0,0 +1,32 @@ +# == Define: designate::pool +# +# Define a pool. +# +# === Parameters +# +# [*nameservers*] +# An array of UUID's of the nameservers in this pool +# +# [*targets*] +# An array of UUID's of the targets in this pool +# +# [*also_notifies*] +# (optional) List of hostnames and port numbers to also notify on zone changes. +# +define designate::pool( + $nameservers, + $targets, + $also_notifies = [], +){ + validate_re($name, '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}', + 'Pool name should be a UUID.') + validate_array($nameservers) + validate_array($targets) + validate_array($also_notifies) + + designate_config { + "pool:${name}/nameservers": value => join($nameservers,','); + "pool:${name}/targets": value => join($targets,','); + "pool:${name}/also-notifies": value => join($also_notifies,','); + } +} diff --git a/manifests/pool_manager.pp b/manifests/pool_manager.pp new file mode 100644 index 00000000..beccc79b --- /dev/null +++ b/manifests/pool_manager.pp @@ -0,0 +1,149 @@ +# == Class: designate::pool_manager +# +# Configure designate pool manager service +# +# == Parameters +# +# [*pool_id*] +# UUID of the pool to use. +# +# [*package_ensure*] +# (optional) The state of the package +# Defaults to 'present' +# +# [*manage_package*] +# Whether Puppet should manage the package. Default is true. +# +# [*pool_manager_package_name*] +# (optional) Name of the package containing pool manager +# resources. Defaults to pool_manager_package_name from +# designate::params +# +# [*enabled*] +# (optional) Whether to enable services. +# Defaults to true +# +# [*service_ensure*] +# (optional) Whether the designate pool manager service will +# be running. +# Defaults to 'running' +# +# [*workers*] +# (optional) Number of worker processes. +# Defaults to $::os_service_default +# +# [*threads*] +# (optional) Number of Pool Manager greenthreads to spawn +# Defaults to $::os_service_default +# +# [*threshold_percentage*] +# (optional) Threshold percentage. +# Defaults to $::os_service_default +# +# [*poll_timeout*] +# (optional) Poll timeout. +# Defaults to $::os_service_default +# +# [*poll_retry_interval*] +# (optional) Poll retry interval. +# Defaults to $::os_service_default +# +# [*poll_max_retries*] +# (optional) Poll max retries. +# Defaults to $::os_service_default +# +# [*poll_delay*] +# (optional) Poll delay. +# Defaults to $::os_service_default +# +# [*enable_recovery_timer*] +# (optional) Enable the recovery thread +# Defaults to $::os_service_default +# +# [*periodic_recovery_interval*] +# (optional) Periodic recovery interval. +# Defaults to $::os_service_default +# +# [*enable_sync_timer*] +# (optional) Enable the sync thread +# Defaults to $::os_service_default +# +# [*periodic_sync_interval*] +# (optional) Periodic sync interval. +# Defaults to $::os_service_default +# +# [*periodic_sync_seconds*] +# (optional) Periodic sync seconds. +# Defaults to $::os_service_default +# +# [*periodic_sync_max_attempts*] +# (optional) Zones Updated within last N seconds will be syncd. Use None to sync all zones +# Defaults to $::os_service_default +# +# [*periodic_sync_retry_interval*] +# (optional) Perform multiple update attempts during periodic_sync +# Defaults to $::os_service_default +# +class designate::pool_manager( + $pool_id, + $manage_package = true, + $package_ensure = present, + $pool_manager_package_name = undef, + $enabled = true, + $service_ensure = 'running', + $workers = $::os_service_default, + $threads = $::os_service_default, + $threshold_percentage = $::os_service_default, + $poll_timeout = $::os_service_default, + $poll_retry_interval = $::os_service_default, + $poll_max_retries = $::os_service_default, + $poll_delay = $::os_service_default, + $enable_recovery_timer = $::os_service_default, + $periodic_recovery_interval = $::os_service_default, + $enable_sync_timer = $::os_service_default, + $periodic_sync_interval = $::os_service_default, + $periodic_sync_seconds = $::os_service_default, + $periodic_sync_max_attempts = $::os_service_default, + $periodic_sync_retry_interval = $::os_service_default, +) { + include ::designate::params + + if $pool_id !~ /^[[:xdigit:]]{8}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{4}-[[:xdigit:]]{12}$/ { + fail('pool_id should be a valid UUID') + } + + if $manage_package { + package { 'designate-pool-manager': + ensure => $package_ensure, + name => pick($pool_manager_package_name, $::designate::params::pool_manager_service_name), + tag => ['openstack', 'designate-package'], + } + } + + service { 'designate-pool-manager': + ensure => $service_ensure, + name => $::designate::params::pool_manager_service_name, + enable => $enabled, + hasstatus => true, + hasrestart => true, + tag => ['openstack', 'designate-service'], + } + + designate_config { + 'service:pool_manager/pool_id': value => $pool_id; + 'service:pool_manager/workers': value => $workers; + 'service:pool_manager/threads': value => $threads; + 'service:pool_manager/threshold_percentage': value => $threshold_percentage; + 'service:pool_manager/poll_timeout': value => $poll_timeout; + 'service:pool_manager/poll_retry_interval': value => $poll_retry_interval; + 'service:pool_manager/poll_max_retries': value => $poll_max_retries; + 'service:pool_manager/poll_delay': value => $poll_delay; + 'service:pool_manager/periodic_recovery_interval': value => $periodic_recovery_interval; + 'service:pool_manager/periodic_sync_interval': value => $periodic_sync_interval; + 'service:pool_manager/periodic_sync_seconds': value => $periodic_sync_seconds; + 'service:pool_manager/enable_recovery_timer': value => $enable_recovery_timer; + 'service:pool_manager/enable_sync_timer': value => $enable_sync_timer; + 'service:pool_manager/periodic_sync_max_attempts': value => $periodic_sync_max_attempts; + 'service:pool_manager/periodic_sync_retry_interval': value => $periodic_sync_retry_interval; + } +} diff --git a/manifests/pool_manager_cache/memcache.pp b/manifests/pool_manager_cache/memcache.pp new file mode 100644 index 00000000..876a573a --- /dev/null +++ b/manifests/pool_manager_cache/memcache.pp @@ -0,0 +1,26 @@ +# == Class: designate::pool_manager_cache::memcache +# +# Configure Memcache as caching service for the pool manager. +# +# == Parameters +# +# [*memcached_servers*] +# (optional) Memcache servers. +# Defaults to ['127.0.0.1'] +# +# [*expiration*] +# Cache expiration time. +# Defaults to $::os_service_default +# +class designate::pool_manager_cache::memcache( + $memcached_servers = ['127.0.0.1'], + $expiration = $::os_service_default, +){ + validate_array($memcached_servers) + + designate_config { + 'service:pool_manager/cache_driver': value => 'memcache'; + 'pool_manager_cache:memcache/memcached_servers': value => join($memcached_servers,','); + 'pool_manager_cache:memcache/expiration': value => $expiration; + } +} diff --git a/manifests/pool_manager_cache/sqlalchemy.pp b/manifests/pool_manager_cache/sqlalchemy.pp new file mode 100644 index 00000000..1ba4c520 --- /dev/null +++ b/manifests/pool_manager_cache/sqlalchemy.pp @@ -0,0 +1,53 @@ +# Class: designate::pool_manager_cache::sqlalchemy +# +# === Parameters +# +# [*connection*] +# Connection string for SQLAlchemy. For instance: +# sqlite:///$state_path/designate_pool_manager.sqlite +# Defaults to $::os_service_default +# +# [*connection_debug*] +# Wether to show debug information for SQLAlchemy. +# Defaults to $::os_service_default +# +# [*connection_trace*] +# Wether to show traces in SQLAlchemy. +# Defaults to $::os_service_default +# +# [*sqlite_synchronous*] +# Wether or not to enable synchronous queries in SQLite. +# Defaults to $::os_service_default +# +# [*idle_timeout*] +# (optional) Set idle timeout. +# Defaults to $::os_service_default +# +# [*max_retries*] +# (optional) Set max retries. +# Defaults to $::os_service_default +# +# [*retry_interval*] +# (optional) Set retry interval. +# Defaults to $::os_service_default +# +class designate::pool_manager_cache::sqlalchemy( + $connection = $::os_service_default, + $connection_debug = $::os_service_default, + $connection_trace = $::os_service_default, + $sqlite_synchronous = $::os_service_default, + $idle_timeout = $::os_service_default, + $max_retries = $::os_service_default, + $retry_interval = $::os_service_default, +){ + designate_config { + 'service:pool_manager/cache_driver': value => 'sqlalchemy'; + 'pool_manager_cache:sqlalchemy/connection': value => $connection; + 'pool_manager_cache:sqlalchemy/connection_debug': value => $connection_debug; + 'pool_manager_cache:sqlalchemy/connection_trace': value => $connection_trace; + 'pool_manager_cache:sqlalchemy/sqlite_synchronous': value => $sqlite_synchronous; + 'pool_manager_cache:sqlalchemy/idle_timeout': value => $idle_timeout; + 'pool_manager_cache:sqlalchemy/max_retries': value => $max_retries; + 'pool_manager_cache:sqlalchemy/retry_interval': value => $retry_interval; + } +} diff --git a/manifests/pool_nameserver.pp b/manifests/pool_nameserver.pp new file mode 100644 index 00000000..3d8629be --- /dev/null +++ b/manifests/pool_nameserver.pp @@ -0,0 +1,22 @@ +# Define: designate::pool_nameserver +# +# === Parameters +# +# [*port*] +# Port number of the DNS server. +# +# [*host*] +# IP address or hostname of the DNS server. +# +define designate::pool_nameserver( + $port = 53, + $host = '127.0.0.1', +){ + validate_re($name, '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}', + 'Name should be a UUID.') + + designate_config { + "pool_nameserver:${name}/port": value => $port; + "pool_nameserver:${name}/host": value => $host; + } +} diff --git a/manifests/pool_target.pp b/manifests/pool_target.pp new file mode 100644 index 00000000..020ddb4c --- /dev/null +++ b/manifests/pool_target.pp @@ -0,0 +1,53 @@ +# == Define: designate::pool_target +# +# Configure a target for the Designate Pool Manager. +# +# == Parameters +# +# [*options*] +# Options to be passed to the backend DNS server. This should include host and +# port. For instance for a bind9 +# target this could be: +# rndc_host: 192.168.27.100, rndc_port: 953, rndc_config_file: /etc/bind/rndc.conf, rndc_key_file: /etc/bind/rndc.key, port: 53, host: 192.168.27.100 +# +# [*type*] +# Port number of the target DNS server. +# +# [*masters*] +# (optional) IP addresses and ports of the master DNS server. This should point +# to the Designate mDNS servers and ports. +# Defaults to ['127.0.0.1:5354'] +# +define designate::pool_target ( + $options, + $type, + $masters = ['127.0.0.1:5354'], +) { + if target == 'powerdns' { + include ::powerdns + include ::powerdns::mysql + } + + validate_re($name, '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}') + validate_array($masters) + + designate_config { + "pool_target:${name}/options": value => $options; + "pool_target:${name}/type": value => $type; + "pool_target:${name}/masters": value => join($masters,','); + } + + if $type == 'powerdns' { + exec { "designate-powerdns-dbsync ${name}": + command => "${::designate::params::designate_manage} powerdns sync ${name}", + path => '/usr/bin', + user => 'root', + refreshonly => true, + logoutput => on_failure, + } + + # Have to have a valid configuration file before running migrations + Designate_config<||> -> Exec["designate-powerdns-dbsync ${name}"] + Exec["designate-powerdns-dbsync ${name}"] ~> Service<| title == 'designate-pool-manager' |> + } +} diff --git a/spec/classes/designate_pool_manager_cache_memcache_spec.rb b/spec/classes/designate_pool_manager_cache_memcache_spec.rb new file mode 100644 index 00000000..968e155e --- /dev/null +++ b/spec/classes/designate_pool_manager_cache_memcache_spec.rb @@ -0,0 +1,61 @@ +# +# Unit tests for designate::pool_manager +# +require 'spec_helper' + +describe 'designate::pool_manager_cache::memcache' do + let :params do + { + } + end + + shared_examples 'designate-pool-manager-cache-memcache' do + context 'with default parameters' do + it { is_expected.to contain_class('designate::pool_manager_cache::memcache') } + it 'configures designate-pool-manager with required parameters' do + is_expected.to contain_designate_config('service:pool_manager/cache_driver').with_value('memcache') + is_expected.to contain_designate_config('pool_manager_cache:memcache/memcached_servers').with_value(['127.0.0.1']) + is_expected.to contain_designate_config('pool_manager_cache:memcache/expiration').with_value('') + end + end + + context 'with all parameters' do + before do + params.merge!( { :memcached_servers => ['192.168.0.1'], :expiration => 123 } ) + end + + it { is_expected.to contain_class('designate::pool_manager_cache::memcache') } + it 'configures designate-pool-manager with required parameters' do + is_expected.to contain_designate_config('service:pool_manager/cache_driver').with_value('memcache') + is_expected.to contain_designate_config('pool_manager_cache:memcache/memcached_servers').with_value( params[:memcached_servers] ) + is_expected.to contain_designate_config('pool_manager_cache:memcache/expiration').with_value( params[:expiration] ) + 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 + + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { + :pool_manager_package_name => 'designate-pool-manager', + :pool_manager_service_name => 'designate-pool-manager' + } + when 'RedHat' + { + :pool_manager_package_name => 'openstack-designate-pool-manager', + :pool_manager_service_name => 'openstack-designate-pool-manager' + } + end + end + it_behaves_like 'designate-pool-manager-cache-memcache' + end + end +end diff --git a/spec/classes/designate_pool_manager_cache_sqlalchemy_spec.rb b/spec/classes/designate_pool_manager_cache_sqlalchemy_spec.rb new file mode 100644 index 00000000..29cb4fee --- /dev/null +++ b/spec/classes/designate_pool_manager_cache_sqlalchemy_spec.rb @@ -0,0 +1,68 @@ +# +# Unit tests for designate::pool_manager_cache::sqlalchemy +# +require 'spec_helper' + +describe 'designate::pool_manager_cache::sqlalchemy' do + let :params do + { + } + end + + let :params_all do + { + :connection => 'connection = sqlite:///$state_path/designate_pool_manager.sqlite', + :connection_debug => 100, + :connection_trace => true, + :sqlite_synchronous => true, + :idle_timeout => 3600, + :max_retries => 10, + :retry_interval => 10, + } + end + + shared_examples 'designate-pool-manager-cache-sqlalchemy' do + context 'with default parameters' do + it { is_expected.to contain_class('designate::pool_manager_cache::sqlalchemy') } + + it 'configures designate-pool-manager with required parameters' do + is_expected.to contain_designate_config('service:pool_manager/cache_driver').with_value('sqlalchemy') + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/connection').with_value('') + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/connection_debug').with_value('') + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/connection_trace').with_value('') + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/sqlite_synchronous').with_value('') + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/idle_timeout').with_value('') + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/max_retries').with_value('') + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/retry_interval').with_value('') + end + end + + context 'with all parameters' do + before do + params.merge!( params_all ) + end + + it 'configures designate-pool-manager with required parameters' do + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/connection').with_value( params[:connection] ) + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/connection_debug').with_value( params[:connection_debug] ) + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/connection_trace').with_value( params[:connection_trace] ) + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/sqlite_synchronous').with_value( params[:sqlite_synchronous] ) + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/idle_timeout').with_value( params[:idle_timeout] ) + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/max_retries').with_value( params[:max_retries] ) + is_expected.to contain_designate_config('pool_manager_cache:sqlalchemy/retry_interval').with_value( params[:retry_interval] ) + 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-pool-manager-cache-sqlalchemy' + end + end +end diff --git a/spec/classes/designate_pool_manager_spec.rb b/spec/classes/designate_pool_manager_spec.rb new file mode 100644 index 00000000..629171c2 --- /dev/null +++ b/spec/classes/designate_pool_manager_spec.rb @@ -0,0 +1,139 @@ +# +# Unit tests for designate::pool_manager +# +require 'spec_helper' + +describe 'designate::pool_manager' do + let :params do + { + :pool_id => '794ccc2c-d751-44fe-b57f-8894c9f5c842', + } + end + + let :params_all do + { + :manage_package => true, + :package_ensure => 'present', + :pool_manager_package_name => nil, + :enabled => true, + :service_ensure => 'running', + :workers => 10, + :threads => 900, + :threshold_percentage => 90, + :poll_timeout => 15, + :poll_retry_interval => 10, + :poll_max_retries => 5, + :poll_delay => 1, + :enable_recovery_timer => false, + :periodic_recovery_interval => 60, + :enable_sync_timer => false, + :periodic_sync_interval => 900, + :periodic_sync_seconds => 5, + :periodic_sync_max_attempts => 1, + :periodic_sync_retry_interval => 15, + } + end + + shared_examples 'designate-pool-manager' do + context 'with default parameters' do + it { is_expected.to contain_class('designate::pool_manager') } + + it 'installs designate-pool-manager package and service' do + is_expected.to contain_service('designate-pool-manager').with( + :name => platform_params[:pool_manager_service_name], + :ensure => 'running', + :enable => 'true', + :tag => ['openstack', 'designate-service'], + ) + is_expected.to contain_package('designate-pool-manager').with( + :name => platform_params[:pool_manager_package_name], + :ensure => 'present', + :tag => ['openstack', 'designate-package'], + ) + end + + it 'configures designate-pool-manager with default parameters' do + is_expected.to contain_designate_config('service:pool_manager/pool_id').with_value( params[:pool_id] ) + is_expected.to contain_designate_config('service:pool_manager/workers').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/threads').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/threshold_percentage').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/poll_timeout').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/poll_retry_interval').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/poll_max_retries').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/poll_delay').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/enable_recovery_timer').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/periodic_recovery_interval').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/enable_sync_timer').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/periodic_sync_interval').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/periodic_sync_seconds').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/periodic_sync_max_attempts').with_value( '' ) + is_expected.to contain_designate_config('service:pool_manager/periodic_sync_retry_interval').with_value( '' ) + end + end + + context 'with custom package name' do + before do + params.merge!({ :pool_manager_package_name => 'designate-pool-manager-custom-name' }) + end + + it 'configures using custom name' do + is_expected.to contain_package('designate-pool-manager').with( + :name => 'designate-pool-manager-custom-name', + :ensure => 'present', + :tag => ['openstack', 'designate-package'], + ) + end + end + + context 'with all params' do + before do + params.merge!( params_all ) + end + + it 'configures designate-pool-manager with all parameters' do + is_expected.to contain_designate_config('service:pool_manager/pool_id').with_value( params[:pool_id] ) + is_expected.to contain_designate_config('service:pool_manager/workers').with_value( params[:workers] ) + is_expected.to contain_designate_config('service:pool_manager/threads').with_value( params[:threads] ) + is_expected.to contain_designate_config('service:pool_manager/threshold_percentage').with_value( params[:threshold_percentage] ) + is_expected.to contain_designate_config('service:pool_manager/poll_timeout').with_value( params[:poll_timeout] ) + is_expected.to contain_designate_config('service:pool_manager/poll_retry_interval').with_value( params[:poll_retry_interval] ) + is_expected.to contain_designate_config('service:pool_manager/poll_max_retries').with_value( params[:poll_max_retries] ) + is_expected.to contain_designate_config('service:pool_manager/poll_delay').with_value( params[:poll_delay] ) + is_expected.to contain_designate_config('service:pool_manager/enable_recovery_timer').with_value( params[:enable_recovery_timer] ) + is_expected.to contain_designate_config('service:pool_manager/periodic_recovery_interval').with_value( params[:periodic_recovery_interval] ) + is_expected.to contain_designate_config('service:pool_manager/enable_sync_timer').with_value( params[:enable_sync_timer] ) + is_expected.to contain_designate_config('service:pool_manager/periodic_sync_interval').with_value( params[:periodic_sync_interval] ) + is_expected.to contain_designate_config('service:pool_manager/periodic_sync_seconds').with_value( params[:periodic_sync_seconds] ) + is_expected.to contain_designate_config('service:pool_manager/periodic_sync_max_attempts').with_value( params[:periodic_sync_max_attempts] ) + is_expected.to contain_designate_config('service:pool_manager/periodic_sync_retry_interval').with_value( params[:periodic_sync_retry_interval] ) + 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 + + let(:platform_params) do + case facts[:osfamily] + when 'Debian' + { + :pool_manager_package_name => 'designate-pool-manager', + :pool_manager_service_name => 'designate-pool-manager' + } + when 'RedHat' + { + :pool_manager_package_name => 'openstack-designate-pool-manager', + :pool_manager_service_name => 'openstack-designate-pool-manager' + } + end + end + it_behaves_like 'designate-pool-manager' + end + end +end diff --git a/spec/defines/designate_pool_nameserver_spec.rb b/spec/defines/designate_pool_nameserver_spec.rb new file mode 100644 index 00000000..03b313d7 --- /dev/null +++ b/spec/defines/designate_pool_nameserver_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe 'designate::pool_nameserver' do + let :facts do + @default_facts.merge({:osfamily => 'Debian'}) + end + + let :params do + { + } + end + + let :pre_condition do + 'include designate' + end + + let :title do + '0f66b842-96c2-4189-93fc-1dc95a08b012' + end + + shared_examples_for 'without parameters' do + it { is_expected.to contain_designate__pool_nameserver('0f66b842-96c2-4189-93fc-1dc95a08b012') } + + it 'configures designate pool-nameserver with default parameters' do + is_expected.to contain_designate_config("pool_nameserver:0f66b842-96c2-4189-93fc-1dc95a08b012/host").with_value('127.0.0.1') + is_expected.to contain_designate_config("pool_nameserver:0f66b842-96c2-4189-93fc-1dc95a08b012/port").with_value(53) + end + end + + shared_examples_for 'with all parameters' do + before { params.merge!( { :host => '192.168.0.1', :port => 5353 } ) } + + it { is_expected.to contain_designate__pool_nameserver('0f66b842-96c2-4189-93fc-1dc95a08b012') } + + it 'configures designate pool-nameserver with default parameters' do + is_expected.to contain_designate_config("pool_nameserver:0f66b842-96c2-4189-93fc-1dc95a08b012/host").with_value('192.168.0.1') + is_expected.to contain_designate_config("pool_nameserver:0f66b842-96c2-4189-93fc-1dc95a08b012/port").with_value(5353) + 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 'without parameters' + it_behaves_like 'with all parameters' + end + end +end diff --git a/spec/defines/designate_pool_spec.rb b/spec/defines/designate_pool_spec.rb new file mode 100644 index 00000000..447496dc --- /dev/null +++ b/spec/defines/designate_pool_spec.rb @@ -0,0 +1,57 @@ +require 'spec_helper' + +describe 'designate::pool' do + let :facts do + @default_facts.merge({:osfamily => 'Debian'}) + end + + let :params do + { + :nameservers => ['0f66b842-96c2-4189-93fc-1dc95a08b012'], + :targets => ['f26e0b32-736f-4f0a-831b-039a415c481e'], + } + end + + let :pre_condition do + 'include designate' + end + + let :title do + '794ccc2c-d751-44fe-b57f-8894c9f5c842' + end + + shared_examples_for 'with only required parameters' do + it { is_expected.to contain_designate__pool('794ccc2c-d751-44fe-b57f-8894c9f5c842') } + + it 'configures designate pool with default parameters' do + is_expected.to contain_designate_config("pool:794ccc2c-d751-44fe-b57f-8894c9f5c842/nameservers").with_value( params[:nameservers]) + is_expected.to contain_designate_config("pool:794ccc2c-d751-44fe-b57f-8894c9f5c842/targets").with_value( params[:targets] ) + is_expected.to contain_designate_config("pool:794ccc2c-d751-44fe-b57f-8894c9f5c842/also-notifies").with_value( "" ) + end + end + + shared_examples_for 'with all parameters' do + before { params.merge!( { :also_notifies => ["192.168.0.1"] } ) } + + it { is_expected.to contain_designate__pool('794ccc2c-d751-44fe-b57f-8894c9f5c842') } + + it 'configures designate pool with default parameters' do + is_expected.to contain_designate_config("pool:794ccc2c-d751-44fe-b57f-8894c9f5c842/nameservers").with_value( params[:nameservers]) + is_expected.to contain_designate_config("pool:794ccc2c-d751-44fe-b57f-8894c9f5c842/targets").with_value( params[:targets] ) + is_expected.to contain_designate_config("pool:794ccc2c-d751-44fe-b57f-8894c9f5c842/also-notifies").with_value( ["192.168.0.1"] ) + 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 'with only required parameters' + it_behaves_like 'with all parameters' + end + end +end diff --git a/spec/defines/designate_pool_target_spec.rb b/spec/defines/designate_pool_target_spec.rb new file mode 100644 index 00000000..cd23e2d8 --- /dev/null +++ b/spec/defines/designate_pool_target_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe 'designate::pool_target' do + let :facts do + @default_facts.merge({:osfamily => 'Debian'}) + end + + let :params do + { + :options => 'rndc_host: 192.168.27.100, rndc_port: 953, rndc_config_file: /etc/bind/rndc.conf, rndc_key_file: /etc/bind/rndc.key, port: 53, host: 192.168.27.100', + :type => 'bind9', + :masters => ['127.0.0.1:5354'], + } + end + + let :pre_condition do + 'include designate' + end + + let :title do + 'f26e0b32-736f-4f0a-831b-039a415c481e' + end + + shared_examples_for 'with only required parameters' do + it { is_expected.to contain_designate__pool_target('f26e0b32-736f-4f0a-831b-039a415c481e') } + + it 'configures designate pool-manager pool with default parameters' do + is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/options').with_value(params[:options]) + is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/type').with_value(params[:type]) + is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/masters').with_value(params[:masters]) + end + end + + shared_examples_for 'with all parameters' do + before { params.merge!( { :masters => ['192.168.0.1'] } ) } + + it { is_expected.to contain_designate__pool_target('f26e0b32-736f-4f0a-831b-039a415c481e') } + + it 'configures designate pool-manager pool with default parameters' do + is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/options').with_value(params[:options]) + is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/type').with_value(params[:type]) + is_expected.to contain_designate_config('pool_target:f26e0b32-736f-4f0a-831b-039a415c481e/masters').with_value(params[:masters]) + 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 'with only required parameters' + it_behaves_like 'with all parameters' + end + end +end