From fc3f8dc74737f5120b5c37f9511d2aa2dff12e45 Mon Sep 17 00:00:00 2001 From: Garrett Honeycutt Date: Mon, 8 Apr 2013 23:49:18 +0200 Subject: [PATCH] allows for 0 _ttl's without time signifier and enables tests --- .fixtures.yml | 13 ++++++--- .gemfile | 6 +++++ .gitignore | 4 +++ .travis.yml | 17 ++++++++++++ Modulefile | 5 ++++ manifests/init.pp | 34 +++++++++++++++++++++-- manifests/server.pp | 34 +++++++++++++++++++++-- manifests/server/validate_db.pp | 2 +- spec/classes/init_spec.rb | 48 +++++++++++++++++++++++++++++++++ spec/fixtures/manifests/site.pp | 0 spec/spec_helper.rb | 2 ++ 11 files changed, 156 insertions(+), 9 deletions(-) create mode 100644 .gemfile create mode 100644 .travis.yml create mode 100644 spec/classes/init_spec.rb create mode 100644 spec/fixtures/manifests/site.pp create mode 100644 spec/spec_helper.rb diff --git a/.fixtures.yml b/.fixtures.yml index 1bb09823..67259157 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -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}' diff --git a/.gemfile b/.gemfile new file mode 100644 index 00000000..6e86a9f1 --- /dev/null +++ b/.gemfile @@ -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' diff --git a/.gitignore b/.gitignore index 42a59a40..7b07471a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ pkg/ metadata.json +*.swp +.DS_Store +coverage/ +spec/fixtures/modules/* diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..7a78bcb0 --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/Modulefile b/Modulefile index 2e2bafed..292064c9 100644 --- a/Modulefile +++ b/Modulefile @@ -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' diff --git a/manifests/init.pp b/manifests/init.pp index 8d06c770..da0b358a 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 @@ $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.':} } diff --git a/manifests/server.pp b/manifests/server.pp index cd4c2519..7428b93e 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -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 @@ $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], diff --git a/manifests/server/validate_db.pp b/manifests/server/validate_db.pp index 7ce6d3a8..48495d46 100644 --- a/manifests/server/validate_db.pp +++ b/manifests/server/validate_db.pp @@ -53,7 +53,7 @@ # 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, diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 00000000..b9bc968a --- /dev/null +++ b/spec/classes/init_spec.rb @@ -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 diff --git a/spec/fixtures/manifests/site.pp b/spec/fixtures/manifests/site.pp new file mode 100644 index 00000000..e69de29b diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..dc7e9f4a --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'rubygems' +require 'puppetlabs_spec_helper/module_spec_helper'