diff --git a/kitchen.yml b/kitchen.yml index 9f356ff7..b3a3a2b0 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -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] diff --git a/resources/install.rb b/resources/install.rb index 0ea0ca33..942d6c81 100644 --- a/resources/install.rb +++ b/resources/install.rb @@ -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 }, @@ -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 @@ -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 @@ -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 @@ -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 @@ -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' diff --git a/test/cookbooks/test/recipes/all_repos_install.rb b/test/cookbooks/test/recipes/all_repos_install.rb new file mode 100644 index 00000000..27d42278 --- /dev/null +++ b/test/cookbooks/test/recipes/all_repos_install.rb @@ -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 diff --git a/test/cookbooks/test/recipes/no_repos_install.rb b/test/cookbooks/test/recipes/no_repos_install.rb new file mode 100644 index 00000000..49521747 --- /dev/null +++ b/test/cookbooks/test/recipes/no_repos_install.rb @@ -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 diff --git a/test/integration/all_repos_install/controls/all_repos_spec.rb b/test/integration/all_repos_install/controls/all_repos_spec.rb new file mode 100644 index 00000000..d64e354f --- /dev/null +++ b/test/integration/all_repos_install/controls/all_repos_spec.rb @@ -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 diff --git a/test/integration/all_repos_install/inspec.yml b/test/integration/all_repos_install/inspec.yml new file mode 100644 index 00000000..18ab0e74 --- /dev/null +++ b/test/integration/all_repos_install/inspec.yml @@ -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: help@sous-chefs.org +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 diff --git a/test/integration/no_repos_install/controls/no_repos_spec.rb b/test/integration/no_repos_install/controls/no_repos_spec.rb new file mode 100644 index 00000000..0327a0ec --- /dev/null +++ b/test/integration/no_repos_install/controls/no_repos_spec.rb @@ -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 diff --git a/test/integration/no_repos_install/inspec.yml b/test/integration/no_repos_install/inspec.yml new file mode 100644 index 00000000..0da1acb7 --- /dev/null +++ b/test/integration/no_repos_install/inspec.yml @@ -0,0 +1,13 @@ +--- +name: no_repos_install +title: PostgreSQL no_repos_install +maintainer: Sous Chefs +copyright_email: help@sous-chefs.org +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 diff --git a/test/integration/no_repos_install/no_repos_spec.rb b/test/integration/no_repos_install/no_repos_spec.rb new file mode 100644 index 00000000..d64e354f --- /dev/null +++ b/test/integration/no_repos_install/no_repos_spec.rb @@ -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 diff --git a/test/integration/server_install/controls/server_spec.rb b/test/integration/server_install/controls/server_spec.rb index 33f98f51..b3040a5e 100644 --- a/test/integration/server_install/controls/server_spec.rb +++ b/test/integration/server_install/controls/server_spec.rb @@ -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 }