diff --git a/manifests/globals.pp b/manifests/globals.pp index 866bae3..7e5e459 100644 --- a/manifests/globals.pp +++ b/manifests/globals.pp @@ -1,284 +1,280 @@ # @summary Class for setting cross-class global overrides. # # @note # Most server-specific defaults should be overridden in the postgresql::server class. # This class should be used only if you are using a non-standard OS, or if you are changing elements that can only be changed here, such as version or manage_package_repo. # # # @param client_package_name Overrides the default PostgreSQL client package name. # @param server_package_name Overrides the default PostgreSQL server package name. # @param contrib_package_name Overrides the default PostgreSQL contrib package name. # @param devel_package_name Overrides the default PostgreSQL devel package name. # @param java_package_name Overrides the default PostgreSQL java package name. # @param docs_package_name Overrides the default PostgreSQL docs package name. # @param perl_package_name Overrides the default PostgreSQL Perl package name. # @param plperl_package_name Overrides the default PostgreSQL PL/Perl package name. # @param plpython_package_name Overrides the default PostgreSQL PL/Python package name. # @param python_package_name Overrides the default PostgreSQL Python package name. # @param postgis_package_name Overrides the default PostgreSQL PostGIS package name. # # @param service_name Overrides the default PostgreSQL service name. # @param service_provider Overrides the default PostgreSQL service provider. # @param service_status Overrides the default status check command for your PostgreSQL service. # @param default_database Specifies the name of the default database to connect with. # # @param validcon_script_path Scipt path for the connection validation check. # # @param initdb_path Path to the initdb command. # @param createdb_path Deprecated. Path to the createdb command. # @param psql_path Sets the path to the psql command. # @param pg_hba_conf_path Specifies the path to your pg_hba.conf file. # @param pg_ident_conf_path Specifies the path to your pg_ident.conf file. # @param postgresql_conf_path Sets the path to your postgresql.conf file. # @param postgresql_conf_mode Sets the mode of your postgresql.conf file. Only relevant if manage_postgresql_conf_perms is true. # @param recovery_conf_path Path to your recovery.conf file. # @param default_connect_settings Default connection settings. # # @param pg_hba_conf_defaults Disables the defaults supplied with the module for pg_hba.conf if set to false. # # @param datadir # Overrides the default PostgreSQL data directory for the target platform. # Changing the datadir after installation causes the server to come to a full stop before making the change. # For Red Hat systems, the data directory must be labeled appropriately for SELinux. # On Ubuntu, you must explicitly set needs_initdb = true to allow Puppet to initialize the database in the new datadir (needs_initdb defaults to true on other systems). # Warning! If datadir is changed from the default, Puppet does not manage purging of the original data directory, which causes it to fail if the data directory is changed back to the original # # @param confdir Overrides the default PostgreSQL configuration directory for the target platform. # @param bindir Overrides the default PostgreSQL binaries directory for the target platform. # @param xlogdir Overrides the default PostgreSQL xlog directory. # @param logdir Overrides the default PostgreSQL log directory. # @param log_line_prefix Overrides the default PostgreSQL log prefix. # # @param user Overrides the default PostgreSQL super user and owner of PostgreSQL related files in the file system. # @param group Overrides the default postgres user group to be used for related files in the file system. # # @param version The version of PostgreSQL to install and manage. # @param postgis_version Defines the version of PostGIS to install, if you install PostGIS. # @param repo_proxy Sets the proxy option for the official PostgreSQL yum-repositories only. # # @param repo_baseurl Sets the baseurl for the PostgreSQL repository. Useful if you host your own mirror of the repository. # @param yum_repo_commonurl Sets the url for the PostgreSQL common Yum repository. Useful if you host your own mirror of the YUM repository. # # @param needs_initdb Explicitly calls the initdb operation after the server package is installed and before the PostgreSQL service is started. # # @param encoding # Sets the default encoding for all databases created with this module. # On certain operating systems, this is also used during the template1 initialization, so it becomes a default outside of the module as well. # @param locale # Sets the default database locale for all databases created with this module. # On certain operating systems, this is also used during the template1 initialization, so it becomes a default outside of the module as well. # On Debian, you'll need to ensure that the 'locales-all' package is installed for full functionality of PostgreSQL. # @param data_checksums # Use checksums on data pages to help detect corruption by the I/O system that would otherwise be silent. # Warning: This option is used during initialization by initdb, and cannot be changed later. # # @param timezone Sets the default timezone of the postgresql server. The postgresql built-in default is taking the systems timezone information. # # @param manage_pg_hba_conf Allow Puppet to manage the pg_hba.conf file. # @param manage_pg_ident_conf Allow Puppet to manage the pg_ident.conf file. # @param manage_recovery_conf Allow Puppet to manage the recovery.conf file. # @param manage_postgresql_conf_perms # Whether to manage the postgresql conf file permissions. This means owner, # group and mode. Contents are not managed but should be managed through # postgresql::server::config_entry. # # @param manage_datadir Set to false if you have file{ $datadir: } already defined # @param manage_logdir Set to false if you have file{ $logdir: } already defined # @param manage_xlogdir Set to false if you have file{ $xlogdir: } already defined # # @param manage_package_repo Sets up official PostgreSQL repositories on your host if set to true. # @param manage_dnf_module # Manage the DNF module. This only makes sense on distributions that use DNF # package manager, such as EL8 or Fedora. It also requires Puppet 5.5.20+ or # Puppet 6.15.0+ since they ship the dnfmodule provider. # @param module_workdir Specifies working directory under which the psql command should be executed. May need to specify if '/tmp' is on volume mounted with noexec option. # # class postgresql::globals ( $client_package_name = undef, $server_package_name = undef, $contrib_package_name = undef, $devel_package_name = undef, $java_package_name = undef, $docs_package_name = undef, $perl_package_name = undef, $plperl_package_name = undef, $plpython_package_name = undef, $python_package_name = undef, $postgis_package_name = undef, $service_name = undef, $service_provider = undef, $service_status = undef, $default_database = undef, $validcon_script_path = undef, $initdb_path = undef, $createdb_path = undef, $psql_path = undef, $pg_hba_conf_path = undef, $pg_ident_conf_path = undef, $postgresql_conf_path = undef, Optional[Stdlib::Filemode] $postgresql_conf_mode = undef, $recovery_conf_path = undef, $default_connect_settings = {}, $pg_hba_conf_defaults = undef, $datadir = undef, $confdir = undef, $bindir = undef, $xlogdir = undef, $logdir = undef, $log_line_prefix = undef, $manage_datadir = undef, $manage_logdir = undef, $manage_xlogdir = undef, $user = undef, $group = undef, $version = undef, $postgis_version = undef, $repo_proxy = undef, $repo_baseurl = undef, $yum_repo_commonurl = undef, $needs_initdb = undef, $encoding = undef, $locale = undef, $data_checksums = undef, $timezone = undef, $manage_pg_hba_conf = undef, $manage_pg_ident_conf = undef, $manage_recovery_conf = undef, $manage_postgresql_conf_perms = undef, $manage_selinux = undef, $manage_package_repo = undef, Boolean $manage_dnf_module = false, $module_workdir = undef, ) { # We are determining this here, because it is needed by the package repo # class. $default_version = $facts['os']['family'] ? { /^(RedHat|Linux)/ => $facts['os']['name'] ? { 'Fedora' => $facts['os']['release']['major'] ? { /^(34)$/ => '13', /^(32|33)$/ => '12', /^(31)$/ => '11.6', /^(30)$/ => '11.2', /^(29)$/ => '10.6', /^(28)$/ => '10.4', /^(26|27)$/ => '9.6', /^(24|25)$/ => '9.5', /^(22|23)$/ => '9.4', /^(21)$/ => '9.3', /^(18|19|20)$/ => '9.2', /^(17)$/ => '9.1', default => undef, }, 'Amazon' => '9.2', default => $facts['os']['release']['major'] ? { '8' => '10', '7' => '9.2', '6' => '8.4', '5' => '8.1', default => undef, }, }, 'Debian' => $facts['os']['name'] ? { 'Debian' => $facts['os']['release']['major'] ? { - '6' => '8.4', - '7' => '9.1', '8' => '9.4', '9' => '9.6', '10' => '11', '11' => '13', default => undef, }, 'Ubuntu' => $facts['os']['release']['major'] ? { - /^(10.04|10.10|11.04)$/ => '8.4', - /^(11.10|12.04|12.10|13.04|13.10)$/ => '9.1', /^(14.04)$/ => '9.3', /^(14.10|15.04|15.10)$/ => '9.4', /^(16.04|16.10)$/ => '9.5', /^(17.04|17.10)$/ => '9.6', /^(18.04)$/ => '10', /^(20.04)$/ => '12', default => undef, }, default => undef, }, 'Archlinux' => '9.2', 'Gentoo' => '9.5', 'FreeBSD' => '12', 'OpenBSD' => $facts['os']['release']['full'] ? { /5\.6/ => '9.3', /5\.[7-9]/ => '9.4', /6\.[0-9]/ => '9.5', }, 'Suse' => $facts['os']['name'] ? { 'SLES' => $facts['os']['release']['full'] ? { /11\.[0-3]/ => '91', /11\.4/ => '94', /12\.0/ => '93', /12\.[1-3]/ => '94', /12\.[4-5]/ => '10', /15\.[0-9]/ => '10', default => '96', }, 'OpenSuSE' => $facts['os']['release']['full'] ? { /42\.[1-2]/ => '94', default => '96', }, default => undef, }, default => undef, } $globals_version = pick($version, $default_version, 'unknown') if($globals_version == 'unknown') { fail('No preferred version defined or automatically detected.') } $default_postgis_version = $globals_version ? { '8.1' => '1.3.6', '8.4' => '2.0', '9.0' => '2.1', '9.1' => '2.1', '91' => '2.1', '9.2' => '2.3', '9.3' => '2.3', '93' => '2.3', '9.4' => '2.3', '9.5' => '2.3', '9.6' => '2.3', '10' => '2.4', '11' => '3.0', '12' => '3.0', default => undef, } $globals_postgis_version = $postgis_version ? { undef => $default_postgis_version, default => $postgis_version, } # Setup of the repo only makes sense globally, so we are doing this here. if($manage_package_repo) { class { 'postgresql::repo': version => $globals_version, proxy => $repo_proxy, baseurl => $repo_baseurl, commonurl => $yum_repo_commonurl, } } if $manage_dnf_module { class { 'postgresql::dnfmodule': ensure => $globals_version, } } } diff --git a/manifests/server/config_entry.pp b/manifests/server/config_entry.pp index 133a3b0..25f3528 100644 --- a/manifests/server/config_entry.pp +++ b/manifests/server/config_entry.pp @@ -1,170 +1,161 @@ # @summary Manage a postgresql.conf entry. # # @param ensure Removes an entry if set to 'absent'. # @param value Defines the value for the setting. # @param path Path for postgresql.conf # define postgresql::server::config_entry ( Enum['present', 'absent'] $ensure = 'present', $value = undef, $path = false ) { $postgresql_conf_path = $postgresql::server::postgresql_conf_path $target = $path ? { false => $postgresql_conf_path, default => $path, } # Those are the variables that are marked as "(change requires restart)" # on postgresql.conf. Items are ordered as on postgresql.conf. # # XXX: This resource supports setting other variables without knowing # their names. Do not add them here. $requires_restart_until = { 'data_directory' => undef, 'hba_file' => undef, 'ident_file' => undef, 'external_pid_file' => undef, 'listen_addresses' => undef, 'port' => undef, 'max_connections' => undef, 'superuser_reserved_connections' => undef, 'unix_socket_directory' => '9.3', # Turned into "unix_socket_directories" 'unix_socket_directories' => undef, 'unix_socket_group' => undef, 'unix_socket_permissions' => undef, 'bonjour' => undef, 'bonjour_name' => undef, 'ssl' => '10', 'ssl_ciphers' => '10', 'ssl_prefer_server_ciphers' => '10', # New on 9.4 'ssl_ecdh_curve' => '10', # New on 9.4 'ssl_cert_file' => '10', # New on 9.2 'ssl_key_file' => '10', # New on 9.2 'ssl_ca_file' => '10', # New on 9.2 'ssl_crl_file' => '10', # New on 9.2 'shared_buffers' => undef, 'huge_pages' => undef, # New on 9.4 'max_prepared_transactions' => undef, 'max_files_per_process' => undef, 'shared_preload_libraries' => undef, 'max_worker_processes' => undef, # New on 9.4 'old_snapshot_threshold' => undef, # New on 9.6 'wal_level' => undef, 'wal_log_hints' => undef, # New on 9.4 'wal_buffers' => undef, 'archive_mode' => undef, 'max_wal_senders' => undef, 'max_replication_slots' => undef, # New on 9.4 'track_commit_timestamp' => undef, # New on 9.5 'hot_standby' => undef, 'logging_collector' => undef, 'cluster_name' => undef, # New on 9.5 'silent_mode' => '9.2', # Removed 'track_activity_query_size' => undef, 'autovacuum_max_workers' => undef, 'autovacuum_freeze_max_age' => undef, 'autovacuum_multixact_freeze_max_age' => undef, # New on 9.5 'max_locks_per_transaction' => undef, 'max_pred_locks_per_transaction' => undef, } Exec { logoutput => 'on_failure', } if ! ($name in $requires_restart_until and ( ! $requires_restart_until[$name] or versioncmp($postgresql::server::_version, $requires_restart_until[$name]) < 0 )) { Postgresql_conf { notify => Class['postgresql::server::reload'], } } elsif $postgresql::server::service_restart_on_change { Postgresql_conf { notify => Class['postgresql::server::service'], } } else { Postgresql_conf { before => Class['postgresql::server::service'], } } # We have to handle ports and the data directory in a weird and # special way. On early Debian and Ubuntu and RHEL we have to ensure # we stop the service completely. On RHEL 7 we either have to create # a systemd override for the port or update the sysconfig file, but this # is managed for us in postgresql::server::config. if $facts['os']['name'] == 'Debian' or $facts['os']['name'] == 'Ubuntu' { - if $name == 'port' and $facts['os']['release']['major'] in ['6', '10.04'] { - exec { "postgresql_stop_${name}": - command => "service ${postgresql::server::service_name} stop", - onlyif => "service ${postgresql::server::service_name} status", - unless => "grep 'port = ${value}' ${postgresql::server::postgresql_conf_path}", - path => '/usr/sbin:/sbin:/bin:/usr/bin:/usr/local/bin', - before => Postgresql_conf[$name], - } - } - elsif $name == 'data_directory' { + if $name == 'data_directory' { exec { "postgresql_stop_${name}": command => "service ${postgresql::server::service_name} stop", onlyif => "service ${postgresql::server::service_name} status", unless => "grep \"data_directory = '${value}'\" ${postgresql::server::postgresql_conf_path}", path => '/usr/sbin:/sbin:/bin:/usr/bin:/usr/local/bin', before => Postgresql_conf[$name], } } } if $facts['os']['family'] == 'RedHat' { if ! ($facts['os']['release']['major'] in ['7', '8'] or $facts['os']['name'] == 'Fedora') { if $name == 'port' { # We need to force postgresql to stop before updating the port # because puppet becomes confused and is unable to manage the # service appropriately. exec { "postgresql_stop_${name}": command => "service ${postgresql::server::service_name} stop", onlyif => "service ${postgresql::server::service_name} status", unless => "grep 'PGPORT=${value}' /etc/sysconfig/pgsql/postgresql", path => '/sbin:/bin:/usr/bin:/usr/local/bin', require => File['/etc/sysconfig/pgsql/postgresql'], } -> augeas { 'override PGPORT in /etc/sysconfig/pgsql/postgresql': lens => 'Shellvars.lns', incl => '/etc/sysconfig/pgsql/postgresql', context => '/files/etc/sysconfig/pgsql/postgresql', changes => "set PGPORT ${value}", require => File['/etc/sysconfig/pgsql/postgresql'], notify => Class['postgresql::server::service'], before => Class['postgresql::server::reload'], } } elsif $name == 'data_directory' { # We need to force postgresql to stop before updating the data directory # otherwise init script breaks exec { "postgresql_${name}": command => "service ${postgresql::server::service_name} stop", onlyif => "service ${postgresql::server::service_name} status", unless => "grep 'PGDATA=${value}' /etc/sysconfig/pgsql/postgresql", path => '/sbin:/bin:/usr/bin:/usr/local/bin', require => File['/etc/sysconfig/pgsql/postgresql'], } -> augeas { 'override PGDATA in /etc/sysconfig/pgsql/postgresql': lens => 'Shellvars.lns', incl => '/etc/sysconfig/pgsql/postgresql', context => '/files/etc/sysconfig/pgsql/postgresql', changes => "set PGDATA ${value}", require => File['/etc/sysconfig/pgsql/postgresql'], notify => Class['postgresql::server::service'], before => Class['postgresql::server::reload'], } } } } postgresql_conf { $name: ensure => $ensure, target => $target, value => $value, require => Class['postgresql::server::initdb'], } } diff --git a/manifests/server/initdb.pp b/manifests/server/initdb.pp index 3385704..2454a43 100644 --- a/manifests/server/initdb.pp +++ b/manifests/server/initdb.pp @@ -1,190 +1,166 @@ # @api private class postgresql::server::initdb { $needs_initdb = $postgresql::server::needs_initdb $initdb_path = $postgresql::server::initdb_path $datadir = $postgresql::server::datadir $xlogdir = $postgresql::server::xlogdir $logdir = $postgresql::server::logdir $manage_datadir = $postgresql::server::manage_datadir $manage_logdir = $postgresql::server::manage_logdir $manage_xlogdir = $postgresql::server::manage_xlogdir $encoding = $postgresql::server::encoding $locale = $postgresql::server::locale $data_checksums = $postgresql::server::data_checksums $group = $postgresql::server::group $user = $postgresql::server::user $psql_path = $postgresql::server::psql_path $port = $postgresql::server::port $module_workdir = $postgresql::server::module_workdir # Set the defaults for the postgresql_psql resource Postgresql_psql { psql_user => $user, psql_group => $group, psql_path => $psql_path, port => $port, cwd => $module_workdir, } if $facts['os']['family'] == 'RedHat' and $facts['os']['selinux']['enabled'] == true { $seltype = 'postgresql_db_t' $logdir_type = 'postgresql_log_t' } else { $seltype = undef $logdir_type = undef } if($manage_datadir) { # Make sure the data directory exists, and has the correct permissions. file { $datadir: ensure => directory, owner => $user, group => $group, mode => '0700', seltype => $seltype, } } else { # changes an already defined datadir File <| title == $datadir |> { ensure => directory, owner => $user, group => $group, mode => '0700', seltype => $seltype, } } if($xlogdir) { if($manage_xlogdir) { # Make sure the xlog directory exists, and has the correct permissions. file { $xlogdir: ensure => directory, owner => $user, group => $group, mode => '0700', seltype => $seltype, } } else { # changes an already defined xlogdir File <| title == $xlogdir |> { ensure => directory, owner => $user, group => $group, mode => '0700', seltype => $seltype, } } } if($logdir) { if($manage_logdir) { # Make sure the log directory exists, and has the correct permissions. file { $logdir: ensure => directory, owner => $user, group => $group, seltype => $logdir_type, } } else { # changes an already defined logdir File <| title == $logdir |> { ensure => directory, owner => $user, group => $group, seltype => $logdir_type, } } } if($needs_initdb) { # Build up the initdb command. # # We optionally add the locale switch if specified. Older versions of the # initdb command don't accept this switch. So if the user didn't pass the # parameter, lets not pass the switch at all. $ic_base = "${initdb_path} --pgdata '${datadir}'" $ic_xlog = $xlogdir ? { undef => $ic_base, default => "${ic_base} -X '${xlogdir}'" } # The xlogdir need to be present before initdb runs. # If xlogdir is default it's created by package installer if($xlogdir) { $require_before_initdb = [$datadir, $xlogdir] } else { $require_before_initdb = [$datadir] } # PostgreSQL 11 no longer allows empty encoding $ic_encoding = $encoding ? { undef => $ic_xlog, default => "${ic_xlog} --encoding '${encoding}'" } $ic_locale = $locale ? { undef => $ic_encoding, default => "${ic_encoding} --locale '${locale}'" } $initdb_command = $data_checksums ? { undef => $ic_locale, false => $ic_locale, default => "${ic_locale} --data-checksums" } # This runs the initdb command, we use the existance of the PG_VERSION # file to ensure we don't keep running this command. exec { 'postgresql_initdb': command => $initdb_command, creates => "${datadir}/PG_VERSION", user => $user, group => $group, logoutput => on_failure, require => File[$require_before_initdb], cwd => $module_workdir, } - # The package will take care of this for us the first time, but if we - # ever need to init a new db we need to copy these files explicitly - if $facts['os']['name'] == 'Debian' or $facts['os']['name'] == 'Ubuntu' { - if $facts['os']['release']['major'] in ['6', '7', '10.04', '12.04'] { - file { 'server.crt': - ensure => file, - path => "${datadir}/server.crt", - source => 'file:///etc/ssl/certs/ssl-cert-snakeoil.pem', - owner => $postgresql::server::user, - group => $postgresql::server::group, - mode => '0644', - require => Exec['postgresql_initdb'], - } - file { 'server.key': - ensure => file, - path => "${datadir}/server.key", - source => 'file:///etc/ssl/private/ssl-cert-snakeoil.key', - owner => $postgresql::server::user, - group => $postgresql::server::group, - mode => '0600', - require => Exec['postgresql_initdb'], - } - } - } } elsif $encoding != undef { # [workaround] # by default pg_createcluster encoding derived from locale # but it do does not work by installing postgresql via puppet because puppet # always override LANG to 'C' postgresql_psql { "Set template1 encoding to ${encoding}": command => "UPDATE pg_database SET datistemplate = FALSE WHERE datname = 'template1' ; UPDATE pg_database SET encoding = pg_char_to_encoding('${encoding}'), datistemplate = TRUE WHERE datname = 'template1'", unless => "SELECT datname FROM pg_database WHERE datname = 'template1' AND encoding = pg_char_to_encoding('${encoding}')", } } } diff --git a/spec/unit/defines/server/extension_spec.rb b/spec/unit/defines/server/extension_spec.rb index 0489998..44454e8 100644 --- a/spec/unit/defines/server/extension_spec.rb +++ b/spec/unit/defines/server/extension_spec.rb @@ -1,275 +1,275 @@ # frozen_string_literal: true require 'spec_helper' describe 'postgresql::server::extension', type: :define do # rubocop:disable RSpec/MultipleDescribes let :pre_condition do "class { 'postgresql::server': } postgresql::server::database { 'template_postgis': template => 'template1', }" end let :facts do { os: { family: 'Debian', name: 'Debian', release: { 'full' => '8.0', 'major' => '8' }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let(:title) { 'postgis' } let(:params) do { database: 'template_postgis', } end context 'with mandatory arguments only' do it { is_expected.to contain_postgresql_psql('template_postgis: CREATE EXTENSION "postgis"') .with(db: 'template_postgis', command: 'CREATE EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]') } end context 'when schema is specified' do let(:params) do super().merge(schema: 'pg_catalog') end it { is_expected.to contain_postgresql_psql('template_postgis: ALTER EXTENSION "postgis" SET SCHEMA "pg_catalog"') } end context 'when setting package name' do let(:params) do super().merge(package_name: 'postgis') end it { is_expected.to contain_package('postgis') .with(ensure: 'installed', name: 'postgis').that_comes_before('Postgresql_psql[template_postgis: CREATE EXTENSION "postgis"]') } end context 'when ensuring absence' do let(:params) do super().merge(ensure: 'absent', package_name: 'postgis') end it { is_expected.to contain_postgresql_psql('template_postgis: DROP EXTENSION "postgis"') .with(db: 'template_postgis', command: 'DROP EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]') } it { is_expected.to contain_package('postgis').with(ensure: 'absent', name: 'postgis') } context 'when keeping package installed' do let(:params) do super().merge(package_ensure: 'present') end it { is_expected.to contain_postgresql_psql('template_postgis: DROP EXTENSION "postgis"') .with(db: 'template_postgis', command: 'DROP EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis]') } it { is_expected.to contain_package('postgis') .with(ensure: 'installed', name: 'postgis').that_requires('Postgresql_psql[template_postgis: DROP EXTENSION "postgis"]') } end end context 'when extension version is specified' do let(:params) do super().merge(ensure: 'absent', package_name: 'postgis', version: '99.99.99') end it { is_expected.to contain_postgresql_psql('template_postgis: ALTER EXTENSION "postgis" UPDATE TO \'99.99.99\'') .with(db: 'template_postgis', unless: "SELECT 1 FROM pg_extension WHERE extname='postgis' AND extversion='99.99.99'").that_requires('Postgresql::Server::Database[template_postgis]') } end context 'when extension version is latest' do let(:params) do super().merge(ensure: 'absent', package_name: 'postgis', version: 'latest') end it { is_expected.to contain_postgresql_psql('template_postgis: ALTER EXTENSION "postgis" UPDATE') .with(db: 'template_postgis', unless: "SELECT 1 FROM pg_available_extensions WHERE name = 'postgis' AND default_version = installed_version").that_requires('Postgresql::Server::Database[template_postgis]') } end end describe 'postgresql::server::extension', type: :define do let :pre_condition do "class { 'postgresql::server': } postgresql::server::database { 'template_postgis2': template => 'template1', }" end let :facts do { os: { family: 'Debian', name: 'Debian', - release: { 'full' => '6.0', 'major' => '6' }, + release: { 'full' => '10.0', 'major' => '10' }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let(:title) { 'postgis_db2' } let(:params) do { database: 'template_postgis2', extension: 'postgis', } end - it { is_expected.to contain_file('/var/lib/postgresql/8.4/main') } # FIXME: be more precise - it { is_expected.to contain_concat('/etc/postgresql/8.4/main/pg_hba.conf') } # FIXME: be more precise - it { is_expected.to contain_concat('/etc/postgresql/8.4/main/pg_ident.conf') } # FIXME: be more precise + it { is_expected.to contain_file('/var/lib/postgresql/11/main') } # FIXME: be more precise + it { is_expected.to contain_concat('/etc/postgresql/11/main/pg_hba.conf') } # FIXME: be more precise + it { is_expected.to contain_concat('/etc/postgresql/11/main/pg_ident.conf') } # FIXME: be more precise context 'with mandatory arguments only' do it { is_expected.to contain_postgresql_psql('template_postgis2: CREATE EXTENSION "postgis"') .with(db: 'template_postgis2', command: 'CREATE EXTENSION "postgis"').that_requires('Postgresql::Server::Database[template_postgis2]') } end end describe 'postgresql::server::extension', type: :define do let :facts do { os: { family: 'Debian', name: 'Debian', - release: { 'full' => '6.0', 'major' => '6' }, + release: { 'full' => '10.0', 'major' => '10' }, }, kernel: 'Linux', id: 'root', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', } end let(:title) { 'pg_repack' } let(:params) do { database: 'postgres', extension: 'pg_repack', } end context 'without including postgresql::server' do let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"') .with(db: 'postgres', command: 'CREATE EXTENSION "pg_repack"') } end context 'default port' do let :params do { database: 'postgres', extension: 'pg_repack', } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"').with_port('5432') } end context 'port overriden by explicit parameter' do let :params do { database: 'postgres', extension: 'pg_repack', port: 1234, } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"').with_port('1234') } end context 'with specific db connection settings' do let :params do { database: 'postgres', extension: 'pg_repack', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234' }, } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"') .with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234') .with_port(nil) } end context 'with specific db connection settings - port overriden by explicit parameter' do let :params do { database: 'postgres', extension: 'pg_repack', connect_settings: { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234' }, port: 5678, } end let :pre_condition do "class {'postgresql::server':}" end it { is_expected.to compile.with_all_deps } it { is_expected.to contain_postgresql_psql('postgres: CREATE EXTENSION "pg_repack"') .with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGPORT' => '1234') .with_port('5678') } end end