Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor to use inifile add spec tests and fixture file

  • Loading branch information...
commit 56ccf0ad17c85e1239cb88346722928957c9793b 1 parent 7c4b54a
Stephen authored
View
5 .fixtures.yml
@@ -0,0 +1,5 @@
+fixtures:
+ repositories:
+ 'inifile': "git://github.com/cprice-puppet/puppetlabs-inifile.git"
+ symlinks:
+ "puppetdb": "#{source_dir}"
View
2  Rakefile
@@ -0,0 +1,2 @@
+require 'rubygems'
+require 'puppetlabs_spec_helper/rake_tasks'
View
7 manifests/params.pp
@@ -1,4 +1,11 @@
class puppetdb::params {
# TODO: need to condition this based on whether we are a PE install or not
+
+ $psqldatabase_host = 'localhost'
+ $psqldatabase_port = '5432'
+ $psqldatabase = 'puppetdb'
+ $psqldatabase_username = 'puppetdb'
+ $psqldatabase_password = 'puppetdb'
+ $gc_interval = 60
$confdir = '/etc/puppetdb/conf.d'
}
View
98 manifests/server.pp
@@ -1,26 +1,96 @@
class puppetdb::server(
- $database = 'embedded',
- $database_host = 'localhost',
- $puppetdb_conf_dir = $puppetdb::params::confdir
+ $database = 'embedded',
+ $psqldatabase_host = $puppetdb::params::psqldatabase_host,
+ $psqldatabase_port = $puppetdb::params::psqldatabase_port,
+ $psqldatabase_username = $puppetdb::params::psqldatabase_username,
+ $psqldatabase_password = $puppetdb::params::psqldatabase_password,
+ $psqldatabase = $puppetdb::params::psqldatabase,
+ $confdir = $puppetdb::params::confdir,
+ $gc_interval = $puppetdb::params::gc_interval,
+ $version = 'present',
) inherits puppetdb::params {
package { 'puppetdb':
- ensure => present,
+ ensure => present,
+ notify => Service['puppetdb'],
}
-
- file { 'puppetdb: database.ini':
+
+ file { "${confdir}/database.ini":
ensure => file,
- path => "${puppetdb_conf_dir}/database.ini",
- content => template('puppetdb/server/database.ini.erb'),
- notify => Service['puppetdb'],
+ require => Package['puppetdb'],
}
- service { "puppetdb":
+ service { 'puppetdb':
ensure => running,
- #ensure => stopped,
- }
+ enable => true,
+ require => File["${confdir}/database.ini"],
+ }
+
+ #Set the defaults
+ Ini_setting {
+ path => "${confdir}/database.ini",
+ require => File["${confdir}/database.ini"],
+ notify => Service['puppetdb'],
+ }
+
+ if $database == 'embedded'{
+ $classname = 'org.hsqldb.jdbcDriver'
+ $subprotocol = 'hsqldb'
+ $subname = 'file:/usr/share/puppetdb/db/db;hsqldb.tx=mvcc;sql.syntax_pgs=true'
+ } elsif $database == 'postgres' {
+ $classname = 'org.postgresql.Driver'
+ $subprotocol = 'postgresql'
+ $subname = "//${psqldatabase_host}:${psqldatabase_port}/${psqldatabase}"
+
+ ##Only setup for postgres
+ ini_setting {'puppetdb_psdatabase_username':
+ ensure => present,
+ section => 'database',
+ setting => 'username',
+ value => $psqldatabase_username,
+ }
+
+ ini_setting {'puppetdb_psdatabase_password':
+ ensure => present,
+ section => 'database',
+ setting => 'password',
+ value => $psqldatabase_password,
+ }
+ }
+
+ ini_setting {'puppetdb_classname':
+ ensure => present,
+ section => 'database',
+ setting => 'classname',
+ value => $classname,
+ }
+
+ ini_setting {'puppetdb_subprotocol':
+ ensure => present,
+ section => 'database',
+ setting => 'subprotocol',
+ value => $subprotocol,
+ }
- Package['puppetdb'] -> File['puppetdb: database.ini'] -> Service['puppetdb']
-# Package['puppetdb'] -> File['puppetdb: database.ini']
+ ini_setting {'puppetdb_pgs':
+ ensure => present,
+ section => 'database',
+ setting => 'syntax_pgs',
+ value => true,
+ }
+ ini_setting {'puppetdb_subname':
+ ensure => present,
+ section => 'database',
+ setting => 'subname',
+ value => $subname,
+ }
+
+ ini_setting {'puppetdb_gc_interval':
+ ensure => present,
+ section => 'database',
+ setting => 'gc-interval',
+ value => $gc_interval ,
+ }
+
}
View
60 manifests/storeconfigs.pp
@@ -0,0 +1,60 @@
+# Class: puppetdb::storeconfigs
+#
+# This class installs and configures the puppetdb terminus pacakge
+#
+# Parameters:
+# ['puppet_confdir'] - The config directory of puppet
+# ['dbport'] - The port of the puppetdb
+# ['dbserver'] - The dns name of the puppetdb server
+# ['puppet_conf'] - The puppet config file
+#
+# Actions:
+# - Configures the puppet to use stored configs
+#
+# Requires:
+# - Inifile
+# - Class['puppetdb::storeconfigs']
+#
+# Sample Usage:
+# class { 'puppetdb::storeconfigs':
+# dbserver => 'localhost'
+# dbport => 8081,
+# }
+#
+class puppetdb::storeconfigs(
+ $dbserver = 'localhost',
+ $dbport = '8081',
+ $puppet_confdir = '/etc/puppet/',
+ $puppet_conf = '/etc/puppet/puppet.conf',
+)
+{
+ class{ 'puppetdb::terminus':
+ puppet_confdir => $puppet_confdir,
+ dbport => $dbport,
+ dbserver => $dbserver,
+ }
+
+ Ini_setting{
+ section => 'master',
+ path => $puppet_conf,
+ require => Class[puppetdb::dbterminus],
+ }
+
+ ini_setting {'puppetmasterstoreconfigserver':
+ ensure => present,
+ setting => 'server',
+ value => $dbserver,
+ }
+
+ ini_setting {'puppetmasterstoreconfig':
+ ensure => present,
+ setting => 'storeconfigs',
+ value => true,
+ }
+
+ ini_setting {'puppetmasterstorebackend':
+ ensure => present,
+ setting => 'storeconfigs_backend',
+ value => 'puppetdb',
+ }
+}
View
101 manifests/terminus.pp
@@ -1,63 +1,60 @@
-class puppetdb::terminus(
- $puppetdb_host = $settings::certname
-) {
- package { "puppetdb-terminus":
- ensure => present,
- }
-
- package { "puppetmaster":
- ensure => present,
- }
-
- service { "puppetmaster":
- ensure => running,
+ # Class: puppetdb::terminus
+ #
+ # This class installs and configures the puppetdb terminus pacakge
+ #
+ # Parameters:
+ # ['puppet_confdir'] - The config directory of puppet
+ # ['dbport'] - The port of the puppetdb
+ # ['dbserver'] - The dns name of the puppetdb server
+ #
+ # Actions:
+ # - Configures the puppetdb terminus package
+ #
+ # Requires:
+ # - Inifile
+ #
+ # Sample Usage:
+ # class { 'puppet::terminus':
+ # puppet_confdir => '/etc/puppet/',
+ # dbport => 8081,
+ # dbserver => 'localhost'
+ # }
+ #
+ class puppetdb::terminus($puppet_confdir, $dbport, $dbserver)
+ {
+ package { 'puppetdb-terminus':
+ ensure => present,
}
# TODO: this will overwrite any existing routes.yaml;
# to handle this properly we should just be ensuring
# that the proper lines exist
- $routes_file = "${settings::confdir}/routes.yaml"
- file { "$routes_file":
- ensure => file,
- content => template('puppetdb/terminus/routes.yaml.erb'),
- notify => Service['puppetmaster'],
+ file { "${puppet_confdir}/routes.yaml":
+ ensure => file,
+ source => 'puppet:///modules/puppet/routes.yaml',
+ require => Package['puppetdb-terminus'],
}
- $notify_exec = "notify: puppet.conf changes required"
- $puppetdb_conf_file = "${settings::confdir}/puppetdb.conf"
- file { "$puppetdb_conf_file":
- ensure => file,
- content => template('puppetdb/terminus/puppetdb.conf.erb'),
- notify => [Service['puppetmaster'], Exec[$notify_exec]]
+ file { "${puppet_confdir}/puppetdb.conf":
+ ensure => file,
+ require => File["${puppet_confdir}/routes.yaml"],
}
- # TODO: we also need to make some small changes to puppet.conf, but
- # that requires the ability to manipulate an .ini file, which
- # we can't easily accomplish at this point. This exec is here
- # to notify the users of the situation. Can't use a real 'notify'
- # because we only want this to appear on refresh.
- $puppet_conf_changes_msg = "
- Almost there! To finish, you'll need to add the following lines to
- your puppet.conf file, in the [main] section:
-
- server=${settings::certname}
- storeconfigs=true
- storeconfigs_backend=puppetdb
-
- Then you should be able to run 'puppet agent --test' to exercise
- your puppetdb installation.
-
- "
- exec { $notify_exec:
- refreshonly => true,
- path => '/bin:/usr/bin',
- command => "echo \"$puppet_conf_changes_msg\"",
- logoutput => true,
+ ini_setting {'puppetterminusserver':
+ ensure => present,
+ section => 'main',
+ setting => 'server',
+ path => "${puppet_confdir}/puppetdb.conf",
+ value => $dbserver,
+ require => File["${puppet_confdir}/puppetdb.conf"],
}
- Package["puppetmaster"] ->
- Package["puppetdb-terminus"] ->
- File[$routes_file] ->
- File[$puppetdb_conf_file] ->
- Service["puppetmaster"]
-}
+ ini_setting {'puppetterminusport':
+ ensure => present,
+ section => 'main',
+ setting => 'port',
+ path => "${puppet_confdir}/puppetdb.conf",
+ value => $dbport,
+ require => File["${puppet_confdir}/puppetdb.conf"],
+ }
+ }
View
160 spec/classes/puppetdb_server_spec.rb
@@ -0,0 +1,160 @@
+require 'spec_helper'
+
+describe 'puppetdb::server', :type => :class do
+
+ context 'using hsqldb' do
+ let (:params) do
+ {
+ :database => 'embedded',
+ :version => 'present'
+ }
+ end
+ it {
+ should contain_package('puppetdb').with(
+ :ensure => params[:version],
+ :notify => 'Service[puppetdb]'
+ )
+ should contain_file('/etc/puppetdb/conf.d/database.ini').with(
+ :ensure => 'file',
+ :require => 'Package[puppetdb]'
+ )
+ should contain_service('puppetdb').with(
+ :ensure => 'running',
+ :enable => 'true',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]'
+ )
+ should contain_ini_setting('puppetdb_classname').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'classname',
+ :value => 'org.hsqldb.jdbcDriver',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_subprotocol').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'subprotocol',
+ :value => 'hsqldb',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_pgs').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'syntax_pgs',
+ :value => 'true',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_subname').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'subname',
+ :value => 'file:/usr/share/puppetdb/db/db;hsqldb.tx=mvcc;sql.syntax_pgs=true',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_gc_interval').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'gc-interval',
+ :value => '60',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ }
+ end
+
+ context 'using postgres' do
+ let (:params) do
+ {
+ :database => 'postgres',
+ :version => 'present'
+ }
+ end
+ it {
+ should contain_package('puppetdb').with(
+ :ensure => params[:version],
+ :notify => 'Service[puppetdb]'
+ )
+ should contain_file('/etc/puppetdb/conf.d/database.ini').with(
+ :ensure => 'file',
+ :require => 'Package[puppetdb]'
+ )
+ should contain_service('puppetdb').with(
+ :ensure => 'running',
+ :enable => 'true',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]'
+ )
+ should contain_ini_setting('puppetdb_psdatabase_username').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'username',
+ :value => 'puppetdb',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_psdatabase_password').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'password',
+ :value => 'puppetdb',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_classname').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'classname',
+ :value => 'org.postgresql.Driver',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_subprotocol').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'subprotocol',
+ :value => 'postgresql',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_pgs').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'syntax_pgs',
+ :value => 'true',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_subname').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'subname',
+ :value => '//localhost:5432/puppetdb',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ should contain_ini_setting('puppetdb_gc_interval').with(
+ :ensure => 'present',
+ :section => 'database',
+ :setting => 'gc-interval',
+ :value => '60',
+ :require => 'File[/etc/puppetdb/conf.d/database.ini]',
+ :notify => 'Service[puppetdb]',
+ :path => '/etc/puppetdb/conf.d/database.ini'
+ )
+ }
+ end
+end
View
40 spec/classes/puppetdb_storeconfigs_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+describe 'puppetdb::storeconfigs', :type => :class do
+
+ context 'on Debian' do
+ let (:params) do
+ {
+ :dbserver => 'test.example.com',
+ :dbport => '8081',
+ :puppet_confdir => '/etc/puppet/',
+ :puppet_conf => '/etc/puppet/puppet.conf',
+ }
+ end
+
+ it {
+ should contain_class('puppetdb::terminus')
+ should contain_ini_setting('puppetmasterstoreconfig').with(
+ :ensure => 'present',
+ :section => 'master',
+ :setting => 'storeconfigs',
+ :path => params[:puppet_conf],
+ :value =>'true'
+ )
+ should contain_ini_setting('puppetmasterstorebackend').with(
+ :ensure => 'present',
+ :section => 'master',
+ :setting => 'storeconfigs_backend',
+ :path => params[:puppet_conf],
+ :value =>'puppetdb'
+ )
+ should contain_ini_setting('puppetmasterstoreconfigserver').with(
+ :ensure => 'present',
+ :section => 'master',
+ :setting => 'server',
+ :path => params[:puppet_conf],
+ :value => params[:dbserver]
+ )
+ }
+ end
+end
View
45 spec/classes/puppetdb_terminus_spec.rb
@@ -0,0 +1,45 @@
+require 'spec_helper'
+
+describe 'puppetdb::terminus', :type => :class do
+
+ context 'on Debian' do
+ let (:params) do
+ {
+ :dbserver => 'test.example.com',
+ :dbport => '8081',
+ :puppet_confdir => '/etc/puppet/',
+ }
+ end
+
+ it {
+ should contain_package('puppetdb-terminus').with(
+ :ensure => 'present'
+ )
+ should contain_file("#{params[:puppet_confdir]}/routes.yaml").with(
+ :ensure => 'file',
+ :source => 'puppet:///modules/puppet/routes.yaml',
+ :notify => params[:puppet_service],
+ :require => 'Package[puppetdb-terminus]'
+ )
+ should contain_file("#{params[:puppet_confdir]}/puppetdb.conf").with(
+ :ensure => 'file',
+ :notify => params[:puppet_service],
+ :require => "File[#{params[:puppet_confdir]}/routes.yaml]"
+ )
+ should contain_ini_setting('puppetterminusserver').with(
+ :ensure => 'present',
+ :section => 'main',
+ :setting => 'server',
+ :path => "#{params[:puppet_confdir]}/puppetdb.conf",
+ :value => params[:dbserver]
+ )
+ should contain_ini_setting('puppetterminusport').with(
+ :ensure => 'present',
+ :section => 'main',
+ :setting => 'port',
+ :path => "#{params[:puppet_confdir]}/puppetdb.conf",
+ :value => params[:dbport]
+ )
+ }
+ end
+end
View
1  spec/spec_helper.rb
@@ -0,0 +1 @@
+require 'puppetlabs_spec_helper/module_spec_helper'
View
49 templates/server/database.ini.erb
@@ -1,49 +0,0 @@
-[database]
-
-# For the embedded DB: org.hsqldb.jdbcDriver
-# For PostgreSQL: org.postgresql.Driver
-classname = <%=
- if @database == 'postgres'
- 'org.postgresql.Driver'
- elsif @database == 'embedded'
- 'org.hsqldb.jdbcDriver'
- end
-%>
-
-# For the embedded DB: hsqldb
-# For PostgreSQL: postgresql
-subprotocol = <%=
- if @database == 'postgres'
- 'postgresql'
- elsif @database == 'embedded'
- 'hsqldb'
- end
-%>
-
-# For the embedded DB: file:/path/to/database;hsqldb.tx=mvcc;sql.syntax_pgs=true
-# For PostgreSQL: //host:port/databaseName
-subname = <%=
- if @database == 'postgres'
- # TODO: make port and dbname configurable
- "//#{@database_host}:5432/puppetdb"
- elsif @database == 'embedded'
- 'file:/usr/share/puppetdb/db/db;hsqldb.tx=mvcc;sql.syntax_pgs=true'
- end
-%>
-
-# Connect as a specific user
-# username = foobar
-<%= if @database == 'postgres'
- # TODO: make username configurable
- "username = puppetdb"
- end %>
-
-# Use a specific password
-# password = foobar
-<%= if @database == 'postgres'
- # TODO: make username configurable
- "password = puppetdb"
- end %>
-
-# How often (in minutes) to compact the database
-# gc-interval = 60
View
4 templates/terminus/puppetdb.conf.erb
@@ -1,4 +0,0 @@
-[main]
-server = <%= @puppetdb_host %>
-<%# TODO: make port configurable %>
-port = 8081
View
4 templates/terminus/routes.yaml.erb
@@ -1,4 +0,0 @@
- master:
- facts:
- terminus: puppetdb
- cache: yaml
View
7 tests/puppetdb-three-node.pp
@@ -1,7 +0,0 @@
-# This is intended to show how to install the various components that
-# comprise puppetdb (terminus, puppetdb server, and potentially postgres)
-# on separate nodes. Didn't quite get a chance to finish it.
-
-#node pe-debian6:
- #include puppetdb::
-
Please sign in to comment.
Something went wrong with that request. Please try again.