From f8d838fa6f1db4439773e678f554e56201084882 Mon Sep 17 00:00:00 2001 From: Simon Hoenscheid Date: Mon, 4 Sep 2023 15:45:06 +0200 Subject: [PATCH] make resources unique to allow multiple instances --- manifests/server/instance/initdb.pp | 9 +++++++-- manifests/server/instance/passwd.pp | 2 +- manifests/server/instance/reload.pp | 2 +- spec/classes/server/initdb_spec.rb | 4 ++-- spec/classes/server_spec.rb | 22 +++++++++++----------- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/manifests/server/instance/initdb.pp b/manifests/server/instance/initdb.pp index 87ee475c63..97584c9d64 100644 --- a/manifests/server/instance/initdb.pp +++ b/manifests/server/instance/initdb.pp @@ -175,7 +175,7 @@ # 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': + exec { "postgresql_initdb_instance_${name}": command => $initdb_command, creates => "${datadir}/PG_VERSION", user => $user, @@ -185,6 +185,11 @@ cwd => $module_workdir, } } elsif $encoding != undef { - include postgresql::server::late_initdb + postgresql::server::instance::late_initdb { $name: + encoding => $encoding, + user => $user, + group => $group, + module_workdir => $module_workdir, + } } } diff --git a/manifests/server/instance/passwd.pp b/manifests/server/instance/passwd.pp index e539b7a69c..a4bc20f467 100644 --- a/manifests/server/instance/passwd.pp +++ b/manifests/server/instance/passwd.pp @@ -42,7 +42,7 @@ # the default for pg_hba.conf. $escaped = postgresql::postgresql_escape($real_postgres_password) $exec_command = "${stdlib::shell_escape($psql_path)}${_dboption} -c \"ALTER ROLE \\\"${stdlib::shell_escape($user)}\\\" PASSWORD \${NEWPASSWD_ESCAPED}\"" # lint:ignore:140chars - exec { 'set_postgres_postgrespw': + exec { "set_postgres_postgrespw_${name}": # This command works w/no password because we run it as postgres system # user command => $exec_command, diff --git a/manifests/server/instance/reload.pp b/manifests/server/instance/reload.pp index d663b840a9..53eb5fad99 100644 --- a/manifests/server/instance/reload.pp +++ b/manifests/server/instance/reload.pp @@ -6,7 +6,7 @@ String[1] $service_status = $postgresql::server::service_status, String[1] $service_reload = $postgresql::server::service_reload, ) { - exec { 'postgresql_reload': + exec { "postgresql_reload_${name}": path => '/usr/bin:/usr/sbin:/bin:/sbin', command => $service_reload, onlyif => $service_status, diff --git a/spec/classes/server/initdb_spec.rb b/spec/classes/server/initdb_spec.rb index a545a8e973..c18c7f92f8 100644 --- a/spec/classes/server/initdb_spec.rb +++ b/spec/classes/server/initdb_spec.rb @@ -65,7 +65,7 @@ class { 'postgresql::server': } end it 'contains exec with specified working directory' do - expect(subject).to contain_exec('postgresql_initdb').with( + expect(subject).to contain_exec('postgresql_initdb_instance_main').with( cwd: '/var/tmp', ) end @@ -82,7 +82,7 @@ class { 'postgresql::server': } end it 'contains exec with default working directory' do - expect(subject).to contain_exec('postgresql_initdb').with( + expect(subject).to contain_exec('postgresql_initdb_instance_main').with( cwd: '/tmp', ) end diff --git a/spec/classes/server_spec.rb b/spec/classes/server_spec.rb index f104112af9..caf592d611 100644 --- a/spec/classes/server_spec.rb +++ b/spec/classes/server_spec.rb @@ -11,7 +11,7 @@ it { is_expected.to contain_file('/var/lib/postgresql/13/main') } it { - expect(subject).to contain_exec('postgresql_reload').with('command' => 'systemctl reload postgresql') + expect(subject).to contain_exec('postgresql_reload_main').with('command' => 'systemctl reload postgresql') } it 'validates connection' do @@ -65,10 +65,10 @@ class { 'postgresql::globals': end it 'sets postgres password' do - expect(subject).to contain_exec('set_postgres_postgrespw').with('command' => '/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"', - 'user' => 'postgres', - 'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'], - 'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null") + expect(subject).to contain_exec('set_postgres_postgrespw_main').with('command' => '/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"', + 'user' => 'postgres', + 'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'], + 'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null") end end @@ -89,10 +89,10 @@ class { 'postgresql::globals': end it 'sets postgres password' do - expect(subject).to contain_exec('set_postgres_postgrespw').with('command' => ['/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"'], - 'user' => 'postgres', - 'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'], - 'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null") + expect(subject).to contain_exec('set_postgres_postgrespw_main').with('command' => ['/usr/bin/psql -c "ALTER ROLE \"postgres\" PASSWORD ${NEWPASSWD_ESCAPED}"'], + 'user' => 'postgres', + 'environment' => ['PGPASSWORD=new-p@s$word-to-set', 'PGPORT=5432', 'NEWPASSWD_ESCAPED=$$new-p@s$word-to-set$$'], + 'unless' => "/usr/bin/psql -h localhost -p 5432 -c 'select 1' > /dev/null") end end @@ -146,7 +146,7 @@ class { 'postgresql::globals': it { is_expected.to contain_class('postgresql::server') } it { - expect(subject).to contain_exec('postgresql_reload').with('command' => '/bin/true') + expect(subject).to contain_exec('postgresql_reload_main').with('command' => '/bin/true') } it 'validates connection' do @@ -194,7 +194,7 @@ class { 'postgresql::globals': end it 'contains proper initdb exec' do - expect(subject).to contain_exec('postgresql_initdb') + expect(subject).to contain_exec('postgresql_initdb_instance_main') end end