Skip to content

(CONT-950) - Fix mismatched data types #1430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/puppet/provider/postgresql_conf/parsed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
# simple string and numeric values don't need to be enclosed in quotes
val = if h[:value].is_a?(Numeric)
h[:value].to_s
elsif h[:value].is_a?(Array)
# multiple listen_addresses specified as a string containing a comma-speparated list
h[:value].join(', ')
else
h[:value]
end
Expand Down
2 changes: 1 addition & 1 deletion manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
Optional[String[1]] $service_status = $postgresql::params::service_status,
String[1] $default_database = $postgresql::params::default_database,
Hash $default_connect_settings = $postgresql::globals::default_connect_settings,
Optional[String[1]] $listen_addresses = $postgresql::params::listen_addresses,
Optional[Variant[String[1], Array[String[1]]]] $listen_addresses = $postgresql::params::listen_addresses,
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::params::port,
String[1] $ip_mask_deny_postgres_user = $postgresql::params::ip_mask_deny_postgres_user,
String[1] $ip_mask_allow_all_users = $postgresql::params::ip_mask_allow_all_users,
Expand Down
6 changes: 3 additions & 3 deletions manifests/server/config_entry.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# @param path Path for postgresql.conf
#
define postgresql::server::config_entry (
Enum['present', 'absent'] $ensure = 'present',
Optional[Variant[String[1], Integer]] $value = undef,
Variant[Boolean, String[1]] $path = false
Enum['present', 'absent'] $ensure = 'present',
Optional[Variant[String[1], Integer, Float]] $value = undef,
Variant[Boolean, String[1]] $path = false
) {
$postgresql_conf_path = $postgresql::server::postgresql_conf_path

Expand Down
54 changes: 27 additions & 27 deletions manifests/server/instance/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,33 @@
# @param extra_systemd_config Adds extra config to systemd config file, can for instance be used to add extra openfiles. This can be a multi line string
# lint:endignore:140chars
define postgresql::server::instance::config (
String[1] $ip_mask_deny_postgres_user = $postgresql::server::ip_mask_deny_postgres_user,
String[1] $ip_mask_allow_all_users = $postgresql::server::ip_mask_allow_all_users,
Optional[String[1]] $listen_addresses = $postgresql::server::listen_addresses,
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port,
Array[String[1]] $ipv4acls = $postgresql::server::ipv4acls,
Array[String[1]] $ipv6acls = $postgresql::server::ipv6acls,
Variant[String[1], Stdlib::Absolutepath] $pg_hba_conf_path = $postgresql::server::pg_hba_conf_path,
Variant[String[1], Stdlib::Absolutepath] $pg_ident_conf_path = $postgresql::server::pg_ident_conf_path,
Variant[String[1], Stdlib::Absolutepath] $postgresql_conf_path = $postgresql::server::postgresql_conf_path,
Optional[Stdlib::Filemode] $postgresql_conf_mode = $postgresql::server::postgresql_conf_mode,
Variant[String[1], Stdlib::Absolutepath] $recovery_conf_path = $postgresql::server::recovery_conf_path,
Boolean $pg_hba_conf_defaults = $postgresql::server::pg_hba_conf_defaults,
String[1] $user = $postgresql::server::user,
String[1] $group = $postgresql::server::group,
Optional[String[1]] $version = $postgresql::server::_version,
Boolean $manage_pg_hba_conf = $postgresql::server::manage_pg_hba_conf,
Boolean $manage_pg_ident_conf = $postgresql::server::manage_pg_ident_conf,
Boolean $manage_recovery_conf = $postgresql::server::manage_recovery_conf,
Boolean $manage_postgresql_conf_perms = $postgresql::server::manage_postgresql_conf_perms,
String[1] $datadir = $postgresql::server::datadir,
Optional[String[1]] $logdir = $postgresql::server::logdir,
String[1] $service_name = $postgresql::server::service_name,
Boolean $service_enable = $postgresql::server::service_enable,
Optional[String[1]] $log_line_prefix = $postgresql::server::log_line_prefix,
Optional[String[1]] $timezone = $postgresql::server::timezone,
Optional[String] $password_encryption = $postgresql::server::password_encryption,
Optional[String] $extra_systemd_config = $postgresql::server::extra_systemd_config,
String[1] $ip_mask_deny_postgres_user = $postgresql::server::ip_mask_deny_postgres_user,
String[1] $ip_mask_allow_all_users = $postgresql::server::ip_mask_allow_all_users,
Optional[Variant[String[1], Array[String[1]]]] $listen_addresses = $postgresql::server::listen_addresses,
Variant[String[1], Stdlib::Port, Integer] $port = $postgresql::server::port,
Array[String[1]] $ipv4acls = $postgresql::server::ipv4acls,
Array[String[1]] $ipv6acls = $postgresql::server::ipv6acls,
Variant[String[1], Stdlib::Absolutepath] $pg_hba_conf_path = $postgresql::server::pg_hba_conf_path,
Variant[String[1], Stdlib::Absolutepath] $pg_ident_conf_path = $postgresql::server::pg_ident_conf_path,
Variant[String[1], Stdlib::Absolutepath] $postgresql_conf_path = $postgresql::server::postgresql_conf_path,
Optional[Stdlib::Filemode] $postgresql_conf_mode = $postgresql::server::postgresql_conf_mode,
Variant[String[1], Stdlib::Absolutepath] $recovery_conf_path = $postgresql::server::recovery_conf_path,
Boolean $pg_hba_conf_defaults = $postgresql::server::pg_hba_conf_defaults,
String[1] $user = $postgresql::server::user,
String[1] $group = $postgresql::server::group,
Optional[String[1]] $version = $postgresql::server::_version,
Boolean $manage_pg_hba_conf = $postgresql::server::manage_pg_hba_conf,
Boolean $manage_pg_ident_conf = $postgresql::server::manage_pg_ident_conf,
Boolean $manage_recovery_conf = $postgresql::server::manage_recovery_conf,
Boolean $manage_postgresql_conf_perms = $postgresql::server::manage_postgresql_conf_perms,
String[1] $datadir = $postgresql::server::datadir,
Optional[String[1]] $logdir = $postgresql::server::logdir,
String[1] $service_name = $postgresql::server::service_name,
Boolean $service_enable = $postgresql::server::service_enable,
Optional[String[1]] $log_line_prefix = $postgresql::server::log_line_prefix,
Optional[String[1]] $timezone = $postgresql::server::timezone,
Optional[String] $password_encryption = $postgresql::server::password_encryption,
Optional[String] $extra_systemd_config = $postgresql::server::extra_systemd_config,
) {
if ($manage_pg_hba_conf == true) {
# Prepare the main pg_hba file
Expand Down
27 changes: 27 additions & 0 deletions spec/defines/server/config_entry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,33 @@
end
end

context 'passes values through appropriately' do
let(:params) { { ensure: 'present', name: 'string_value', value: 'entry_test' } }

it 'as a String' do
expect(subject).to contain_postgresql_conf('string_value').with(name: 'string_value',
value: 'entry_test')
end
end

context 'passes values through appropriately' do
let(:params) { { ensure: 'present', name: 'integer_value', value: 40 } }

it 'as an Integer' do
expect(subject).to contain_postgresql_conf('integer_value').with(name: 'integer_value',
value: 40)
end
end

context 'passes values through appropriately' do
let(:params) { { ensure: 'present', name: 'floating_point_value', value: 4.0 } }

it 'a Float' do
expect(subject).to contain_postgresql_conf('floating_point_value').with(name: 'floating_point_value',
value: 4.0)
end
end

context 'unix_socket_directories' do
let(:params) { { ensure: 'present', name: 'unix_socket_directories', value: '/var/pgsql, /opt/postgresql, /root/' } }

Expand Down
8 changes: 7 additions & 1 deletion spec/unit/provider/postgresql_conf/parsed_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,16 @@
)
end

it 'quotes addresses' do
it 'quotes single string address' do
expect(provider.to_line(name: 'listen_addresses', value: '0.0.0.0', comment: nil, record_type: :parsed)).to eq(
"listen_addresses = '0.0.0.0'",
)
end

it 'quotes an array of addresses' do
expect(provider.to_line(name: 'listen_addresses', value: ['0.0.0.0', '127.0.0.1'], comment: nil, record_type: :parsed)).to eq(
"listen_addresses = '0.0.0.0, 127.0.0.1'",
)
end
end
end