allows for 0 _ttl's without time signifier and enables tests

This commit is contained in:
Garrett Honeycutt 2013-04-08 23:49:18 +02:00
parent f464452b1d
commit fc3f8dc747
11 changed files with 156 additions and 9 deletions

View file

@ -1,5 +1,10 @@
fixtures:
repositories:
'inifile': "git://github.com/cprice-puppet/puppetlabs-inifile.git"
symlinks:
"puppetdb": "#{source_dir}"
repositories:
'inifile' : 'git://github.com/cprice-puppet/puppetlabs-inifile.git'
'stdlib' : 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
'postgresql': 'git://github.com/puppetlabs/puppet-postgresql.git'
'firewall' : 'git://github.com/puppetlabs/puppetlabs-firewall.git'
'apt' : 'git://github.com/puppetlabs/puppetlabs-apt.git'
'concat' : 'git://github.com/ripienaar/puppet-concat.git'
symlinks:
'puppetdb': '#{source_dir}'

6
.gemfile Normal file
View file

@ -0,0 +1,6 @@
source :rubygems
puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
gem 'puppet', puppetversion
gem 'puppetlabs_spec_helper', '>= 0.1.0'
gem 'puppet-lint', '>= 0.3.2'

4
.gitignore vendored
View file

@ -1,2 +1,6 @@
pkg/
metadata.json
*.swp
.DS_Store
coverage/
spec/fixtures/modules/*

17
.travis.yml Normal file
View file

@ -0,0 +1,17 @@
language: ruby
before_script: "gem install --no-ri --no-rdoc bundler"
after_script:
script: "rake spec"
notifications:
email: false
rvm:
- 1.9.3
- 1.8.7
env:
- PUPPET_VERSION=2.6.9
- PUPPET_VERSION=2.7.13
- PUPPET_VERSION=3.1.1
gemfile: .gemfile
matrix:
allow_failures:
- env: PUPPET_VERSION=2.6.9

View file

@ -10,3 +10,8 @@ project_page 'https://github.com/puppetlabs-puppet/puppetlabs-puppetdb'
dependency 'cprice404/inifile', '>= 0.9.0'
dependency 'puppetlabs/postgresql', '2.x'
dependency 'puppetlabs/firewall', '>= 0.0.4'
dependency 'puppetlabs/stdlib', '>= 3.2.x'
# needed by puppetlabs/postgresql and included here for spec tests
dependency 'puppetlabs/apt', '>=1.x'
dependency 'ripienaar/concat', '>= 0.2.x'

View file

@ -20,14 +20,14 @@
# '0.0.0.0' = all)
# ['listen_port'] - The port on which the puppetdb web server should
# accept HTTP requests (defaults to 8080).
# ['open_listen_port'] - If true, open the http listen port on the firewall.
# ['open_listen_port'] - If true, open the http listen port on the firewall.
# (defaults to false).
# ['ssl_listen_address'] - The address that the web server should bind to
# for HTTPS requests. (defaults to `$::clientcert`.)
# Set to '0.0.0.0' to listen on all addresses.
# ['ssl_listen_port'] - The port on which the puppetdb web server should
# accept HTTPS requests (defaults to 8081).
# ['open_ssl_listen_port'] - If true, open the ssl listen port on the firewall.
# ['open_ssl_listen_port'] - If true, open the ssl listen port on the firewall.
# (defaults to true).
# ['database'] - Which database backend to use; legal values are
# `postgres` (default) or `embedded`. (The `embedded`
@ -106,6 +106,36 @@ class puppetdb(
$confdir = $puppetdb::params::confdir
) inherits puppetdb::params {
# Apply necessary suffix if zero is specified.
if $node_ttl == '0' {
$node_ttl_real = '0s'
} else {
$node_ttl_real = downcase($node_ttl)
}
# Validate node_ttl
validate_re ($node_ttl_real, ['^(\d)+[s,m,d]$'], "node_ttl is <${node_ttl}> which does not match the regex validation")
# Apply necessary suffix if zero is specified.
if $node_purge_ttl == '0' {
$node_purge_ttl_real = '0s'
} else {
$node_purge_ttl_real = downcase($node_purge_ttl)
}
# Validate node_purge_ttl
validate_re ($node_purge_ttl_real, ['^(\d)+[s,m,d]$'], "node_purge_ttl is <${node_purge_ttl}> which does not match the regex validation")
# Apply necessary suffix if zero is specified.
if $report_ttl == '0' {
$report_ttl_real = '0s'
} else {
$report_ttl_real = downcase($report_ttl)
}
# Validate report_ttl
validate_re ($report_ttl_real, ['^(\d)+[s,m,d]$'], "report_ttl is <${report_ttl}> which does not match the regex validation")
if ($manage_redhat_firewall != undef) {
notify {'Deprecation notice: `$manage_redhat_firewall` has been deprecated in `puppetdb` class and will be removed in a future versions. Use $open_ssl_listen_port and $open_postgres_port instead.':}
}

View file

@ -27,14 +27,14 @@
# Set to '0.0.0.0' to listen on all addresses.
# ['listen_port'] - The port on which the puppetdb web server should
# accept HTTP requests (defaults to 8080).
# ['open_listen_port'] - If true, open the http listen port on the firewall.
# ['open_listen_port'] - If true, open the http listen port on the firewall.
# (defaults to false).
# ['ssl_listen_address'] - The address that the web server should bind to
# for HTTPS requests. (defaults to `$::clientcert`.)
# Set to '0.0.0.0' to listen on all addresses.
# ['ssl_listen_port'] - The port on which the puppetdb web server should
# accept HTTPS requests (defaults to 8081).
# ['open_ssl_listen_port'] - If true, open the ssl listen port on the firewall.
# ['open_ssl_listen_port'] - If true, open the ssl listen port on the firewall.
# (defaults to true).
# ['database'] - Which database backend to use; legal values are
# `postgres` (default) or `embedded`. (The `embedded`
@ -115,6 +115,36 @@ class puppetdb::server(
$confdir = $puppetdb::params::confdir,
) inherits puppetdb::params {
# Apply necessary suffix if zero is specified.
if $node_ttl == '0' {
$node_ttl_real = '0s'
} else {
$node_ttl_real = downcase($node_ttl)
}
# Validate node_ttl
validate_re ($node_ttl_real, ['^(\d)+[s,m,d]$'], "node_ttl is <${node_ttl}> which does not match the regex validation")
# Apply necessary suffix if zero is specified.
if $node_purge_ttl == '0' {
$node_purge_ttl_real = '0s'
} else {
$node_purge_ttl_real = downcase($node_purge_ttl)
}
# Validate node_purge_ttl
validate_re ($node_purge_ttl_real, ['^(\d)+[s,m,d]$'], "node_purge_ttl is <${node_purge_ttl}> which does not match the regex validation")
# Apply necessary suffix if zero is specified.
if $report_ttl == '0' {
$report_ttl_real = '0s'
} else {
$report_ttl_real = downcase($report_ttl)
}
# Validate report_ttl
validate_re ($report_ttl_real, ['^(\d)+[s,m,d]$'], "report_ttl is <${report_ttl}> which does not match the regex validation")
package { $puppetdb_package:
ensure => $puppetdb_version,
notify => Service[$puppetdb_service],

View file

@ -53,7 +53,7 @@ class puppetdb::server::validate_db(
# We don't need any validation for the embedded database, presumably.
if ($database == 'postgres') {
::postgresql::validate_db_connection { 'validate puppetdb postgres connection':
postgresql::validate_db_connection { 'validate puppetdb postgres connection':
database_host => $database_host,
database_port => $database_port,
database_username => $database_username,

48
spec/classes/init_spec.rb Normal file
View file

@ -0,0 +1,48 @@
require 'spec_helper'
describe 'puppetdb' do
ttl_args = ['node_ttl','node_purge_ttl','report_ttl']
context 'on a supported platform' do
let(:facts) { { :osfamily => 'RedHat',
:postgres_default_version => '9.1',
:concat_basedir => '/var/lib/puppet/concat',
} }
describe 'when using default values for puppetdb class' do
it {
should contain_class('puppetdb')
}
end
ttl_args.each do |ttl_arg|
describe "when using 0 for #{ttl_arg} puppetdb class" do
it {
should contain_class('puppetdb')
}
describe "when using a capitalized time signifier for #{ttl_arg} for puppetdb class" do
it {
should contain_class('puppetdb')
}
end
end
end
end
context 'with invalid arguments on a supported platform' do
let(:facts) { { :osfamily => 'RedHat',
:postgres_default_version => '9.1',
:concat_basedir => '/var/lib/puppet/concat',
} }
ttl_args.each do |ttl_arg|
let(:params) { { ttl_arg => 'invalid_value' } }
describe "when using a value that does not match the validation regex for #{ttl_arg} puppetdb class" do
it {
expect {
should contain_class('puppetdb')
}.to raise_error(Puppet::Error)
}
end
end
end
end

0
spec/fixtures/manifests/site.pp vendored Normal file
View file

2
spec/spec_helper.rb Normal file
View file

@ -0,0 +1,2 @@
require 'rubygems'
require 'puppetlabs_spec_helper/module_spec_helper'