Skip to content

Allow more fine-grained control over yum repo config. Fixes #716. #784

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,25 @@ suites:
pg_ver: "15"
run_list:
- recipe[test::server_install]
- name: all_repos_install_15
attributes:
test:
pg_ver: "15"
verifier:
inspec_tests:
- path: test/integration/all_repos_install/
inputs:
pg_ver: "15"
run_list:
- recipe[test::all_repos_install]
- name: no_repos_install_15
attributes:
test:
pg_ver: "15"
verifier:
inspec_tests:
- path: test/integration/no_repos_install/
inputs:
pg_ver: "15"
run_list:
- recipe[test::no_repos_install]
35 changes: 30 additions & 5 deletions resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,43 @@

property :repo_pgdg, [true, false],
default: true,
description: 'Create pgdg repo'
description: 'Enable pgdg repo'

property :setup_repo_pgdg, [true, false],
default: lazy { |r| r.repo_pgdg },
description: 'Setup pgdg repo. Defaults to value of `:repo_pgdg`.'

property :repo_pgdg_common, [true, false],
default: true,
description: 'Create pgdg-common repo'
description: 'Enable pgdg-common repo'

property :setup_repo_pgdg_common, [true, false],
default: lazy { |r| r.repo_pgdg_common },
description: 'Setup pgdg-common repo. Defaults to value of `:repo_pgdg_common`.'

property :repo_pgdg_source, [true, false],
default: false,
description: 'Create pgdg-source repo'
description: 'Enable pgdg-source repo'

property :setup_repo_pgdg_source, [true, false],
default: lazy { |r| r.repo_pgdg_source },
description: 'Setup pgdg-source repo. Defaults to value of `:repo_pgdg_source`.'

property :repo_pgdg_updates_testing, [true, false],
default: false,
description: 'Create pgdg-updates-testing repo'
description: 'Enable pgdg-updates-testing repo'

property :setup_repo_pgdg_updates_testing, [true, false],
default: lazy { |r| r.repo_pgdg_updates_testing },
description: 'Setup pgdg-updates-testing repo. Defaults to value of `:repo_pgdg_updates_testing`.'

property :repo_pgdg_source_updates_testing, [true, false],
default: false,
description: 'Create pgdg-source-updates-testing repo'
description: 'Enable pgdg-source-updates-testing repo'

property :setup_repo_pgdg_source_updates_testing, [true, false],
default: lazy { |r| r.repo_pgdg_source_updates_testing },
description: 'Setup pgdg-source-updates-testing repo. Defaults to value of `:repo_pgdg_source_updates_testing`.'

property :yum_gpg_key_uri, String,
default: lazy { default_yum_gpg_key_uri },
Expand Down Expand Up @@ -116,6 +136,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg || new_resource.setup_repo_pgdg }
end

yum_repository 'PostgreSQL - common' do
Expand All @@ -126,6 +147,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg_common || new_resource.setup_repo_pgdg_common }
end

yum_repository "PostgreSQL #{new_resource.version} - source " do
Expand All @@ -137,6 +159,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg_source || new_resource.setup_repo_pgdg_source }
end

yum_repository "PostgreSQL #{new_resource.version} - updates testing" do
Expand All @@ -148,6 +171,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg_updates_testing || new_resource.setup_repo_pgdg_updates_testing }
end

yum_repository "PostgreSQL #{new_resource.version} - source - updates testing" do
Expand All @@ -159,6 +183,7 @@ def do_repository_action(repo_action)
gpgcheck true
gpgkey 'file:///etc/pki/rpm-gpg/PGDG-RPM-GPG-KEY'
action repo_action
only_if { new_resource.repo_pgdg_source_updates_testing || new_resource.setup_repo_pgdg_source_updates_testing }
end

when 'debian'
Expand Down
42 changes: 42 additions & 0 deletions test/cookbooks/test/recipes/all_repos_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
postgresql_install 'postgresql' do
version node['test']['pg_ver']
setup_repo_pgdg_source true
setup_repo_pgdg_updates_testing true
setup_repo_pgdg_source_updates_testing true
action %i(install init_server)
end

postgresql_config 'postgresql-server' do
version '15'

server_config({
'max_connections' => 110,
'shared_buffers' => '128MB',
'dynamic_shared_memory_type' => 'posix',
'max_wal_size' => '1GB',
'min_wal_size' => '80MB',
'log_destination' => 'stderr',
'logging_collector' => true,
'log_directory' => 'log',
'log_filename' => 'postgresql-%a.log',
'log_rotation_age' => '1d',
'log_rotation_size' => 0,
'log_truncate_on_rotation' => true,
'log_line_prefix' => '%m [%p]',
'log_timezone' => 'Etc/UTC',
'datestyle' => 'iso, mdy',
'timezone' => 'Etc/UTC',
'lc_messages' => 'C',
'lc_monetary' => 'C',
'lc_numeric' => 'C',
'lc_time' => 'C',
'default_text_search_config' => 'pg_catalog.english',
})

notifies :restart, 'postgresql_service[postgresql]', :delayed
action :create
end

postgresql_service 'postgresql' do
action %i(enable start)
end
52 changes: 52 additions & 0 deletions test/cookbooks/test/recipes/no_repos_install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# I can do it myself!
yum_repository 'postgresql-15' do
baseurl 'https://download.postgresql.org/pub/repos/yum/15/redhat/rhel-$releasever-$basearch'
gpgkey "https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL#{node['platform_version'].to_i.eql?(7) ? '7' : ''}"
end

yum_repository 'postgresql-common' do
baseurl 'https://download.postgresql.org/pub/repos/yum/common/redhat/rhel-$releasever-$basearch'
gpgkey "https://download.postgresql.org/pub/repos/yum/keys/PGDG-RPM-GPG-KEY-RHEL#{node['platform_version'].to_i.eql?(7) ? '7' : ''}"
end

postgresql_install 'postgresql' do
version node['test']['pg_ver']
repo_pgdg false
repo_pgdg_common false
action %i(install init_server)
end

postgresql_config 'postgresql-server' do
version '15'

server_config({
'max_connections' => 110,
'shared_buffers' => '128MB',
'dynamic_shared_memory_type' => 'posix',
'max_wal_size' => '1GB',
'min_wal_size' => '80MB',
'log_destination' => 'stderr',
'logging_collector' => true,
'log_directory' => 'log',
'log_filename' => 'postgresql-%a.log',
'log_rotation_age' => '1d',
'log_rotation_size' => 0,
'log_truncate_on_rotation' => true,
'log_line_prefix' => '%m [%p]',
'log_timezone' => 'Etc/UTC',
'datestyle' => 'iso, mdy',
'timezone' => 'Etc/UTC',
'lc_messages' => 'C',
'lc_monetary' => 'C',
'lc_numeric' => 'C',
'lc_time' => 'C',
'default_text_search_config' => 'pg_catalog.english',
})

notifies :restart, 'postgresql_service[postgresql]', :delayed
action :create
end

postgresql_service 'postgresql' do
action %i(enable start)
end
28 changes: 28 additions & 0 deletions test/integration/all_repos_install/controls/all_repos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true
pg_ver = input('pg_ver')

if os[:family] == 'redhat'
describe service("postgresql-#{pg_ver}") do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
%W(pgdg#{pg_ver} pgdg-common).each do |r|
describe yum.repo(r) do
it { should exist }
it { should be_enabled }
end
end
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
describe yum.repo(r) do
it { should exist }
it { should_not be_enabled }
end
end
else
describe service('postgresql') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
end
13 changes: 13 additions & 0 deletions test/integration/all_repos_install/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: all_repos_install
title: PostgreSQL server with all repos setup but only pgdg and pgdg-common enabled
maintainer: Sous Chefs
copyright_email: [email protected]
license: Apache
summary: Verify the correct installation of the postgresql server including correct repos setup and enabled
version: 0.0.1
supports:
- os-family: unix
depends:
- name: client
path: ./test/integration/client_install
28 changes: 28 additions & 0 deletions test/integration/no_repos_install/controls/no_repos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true
pg_ver = input('pg_ver')

if os[:family] == 'redhat'
describe service("postgresql-#{pg_ver}") do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
%W(pgdg#{pg_ver} pgdg-common).each do |r|
describe yum.repo(r) do
it { should_not exist }
it { should_not be_enabled }
end
end
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
describe yum.repo(r) do
it { should_not exist }
it { should_not be_enabled }
end
end
else
describe service('postgresql') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
end
13 changes: 13 additions & 0 deletions test/integration/no_repos_install/inspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: no_repos_install
title: PostgreSQL no_repos_install
maintainer: Sous Chefs
copyright_email: [email protected]
license: Apache
summary: Verify the correct installation of the postgresql server with cookbook provided yum repos instead of resource
version: 0.0.1
supports:
- os-family: unix
depends:
- name: client
path: ./test/integration/client_install
28 changes: 28 additions & 0 deletions test/integration/no_repos_install/no_repos_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true
pg_ver = input('pg_ver')

if os[:family] == 'redhat'
describe service("postgresql-#{pg_ver}") do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
%W(pgdg#{pg_ver} pgdg-common).each do |r|
describe yum.repo(r) do
it { should exist }
it { should be_enabled }
end
end
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
describe yum.repo(r) do
it { should exist }
it { should_not be_enabled }
end
end
else
describe service('postgresql') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
end
12 changes: 12 additions & 0 deletions test/integration/server_install/controls/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
it { should be_enabled }
it { should be_running }
end
%W(pgdg#{pg_ver} pgdg-common).each do |r|
describe yum.repo(r) do
it { should exist }
it { should be_enabled }
end
end
%W(pgdg#{pg_ver}-source pgdg#{pg_ver}-updates-testing pgdg#{pg_ver}-source-updates-testing).each do |r|
describe yum.repo(r) do
it { should_not exist }
it { should_not be_enabled }
end
end
else
describe service('postgresql') do
it { should be_installed }
Expand Down