From 5838f490f65b39553e231ff00cc5eaa175f9e3e2 Mon Sep 17 00:00:00 2001 From: Justin Fernbaugh Date: Fri, 8 Dec 2023 11:33:49 -0800 Subject: [PATCH 1/5] Bug fix with multiple PG installations. Reverse hashmap of pg_version helpers Style correction modify variable name Remove commented code Signed-off-by: Justin Fernbaugh Revert minor bump Signed-off-by: Justin Fernbaugh Sort array with highest PG version first Add changelog note Signed-off-by: Justin Fernbaugh Cleanup sort_by Move package logic into function Removed changelog addition Modify sort logic to select based on version float --- libraries/helpers.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/helpers.rb b/libraries/helpers.rb index b00337ec..29ad9d71 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -23,12 +23,17 @@ module Cookbook module Helpers include Utils - def installed_postgresql_major_version + def installed_postgresql_package_logic pgsql_package = node['packages'].filter { |p| p.match?(/^postgresql-?(\d+)?$/) } + pgsql_package = [pgsql_package.max_by { |_key, value| value['version'].to_f }].to_h raise 'Unable to determine installed PostgreSQL version' if nil_or_empty?(pgsql_package) - pgsql_package = pgsql_package.values.first + pgsql_package.values.first + end + + def installed_postgresql_major_version + pgsql_package = installed_postgresql_package_logic pgsql_package_version = pgsql_package.fetch('version').to_i pgsql_package_source = if pgsql_package.key?('release') pgsql_package.fetch('release').match?('PGDG') ? :repo : :os @@ -42,11 +47,7 @@ def installed_postgresql_major_version end def installed_postgresql_package_source - pgsql_package = node['packages'].filter { |p| p.match?(/^postgresql-?(\d+)?$/) } - - raise 'Unable to determine installed PostgreSQL version' if nil_or_empty?(pgsql_package) - - pgsql_package = pgsql_package.values.first + pgsql_package = installed_postgresql_package_logic pgsql_package_version = pgsql_package.fetch('version').to_i pgsql_package_source = if pgsql_package.key?('release') pgsql_package.fetch('release').match?('PGDG') ? :repo : :os From 379cc6fba169d44ad2a6f0e65bf8d9b52624e0d0 Mon Sep 17 00:00:00 2001 From: Justin Fernbaugh Date: Mon, 22 Jan 2024 10:58:11 -0800 Subject: [PATCH 2/5] Remove PG11 from CI --- .github/workflows/ci.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bbcff657..ac3619c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,12 +34,10 @@ jobs: - "ubuntu-2004" - "ubuntu-2204" suite: - - "access-11" - "access-12" - "access-13" - "access-14" - "access-15" - - "client-install-11" - "client-install-12" - "client-install-13" - "client-install-14" @@ -53,7 +51,6 @@ jobs: - "ident-14" - "ident-15" - "initdb-locale-15" - - "server-install-11" - "server-install-12" - "server-install-13" - "server-install-14" From 787edbc928934ce9807288e916dfb7fc12181226 Mon Sep 17 00:00:00 2001 From: Justin Fernbaugh Date: Mon, 22 Jan 2024 11:00:51 -0800 Subject: [PATCH 3/5] Remove PG11 suites from kitchen Remove blank line from ci.yml Remove blank lines, add blank line at EOF Remove blank line from kitchen.yml Fix removed character Remove trailing space in ci.yml --- .github/workflows/ci.yml | 1 - kitchen.yml | 70 ---------------------------------------- 2 files changed, 71 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac3619c8..311f2c4a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,5 @@ --- name: ci - "on": pull_request: push: diff --git a/kitchen.yml b/kitchen.yml index 702d00c2..5959eb87 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -320,73 +320,3 @@ suites: pg_ver: "12" run_list: - recipe[test::server_install] - - - name: access_11 - attributes: - test: - pg_ver: "11" - verifier: - inspec_tests: - - path: test/integration/access/ - run_list: - - recipe[test::access] - - name: client_install_11 - attributes: - test: - pg_ver: "11" - verifier: - inspec_tests: - - path: test/integration/client_install/ - inputs: - pg_ver: "11" - run_list: - - recipe[test::client_install] - - name: extension_11 - attributes: - test: - pg_ver: "11" - verifier: - inspec_tests: - - path: test/integration/extension/ - run_list: - - recipe[test::extension] - - name: ident_11 - attributes: - test: - pg_ver: "11" - verifier: - inspec_tests: - - path: test/integration/ident/ - run_list: - - recipe[test::ident] - - name: initdb_locale_11 - attributes: - test: - pg_ver: "11" - verifier: - inspec_tests: - - path: test/integration/initdb_locale/ - run_list: - - recipe[test::initdb_locale] - - name: repo_11 - attributes: - test: - pg_ver: "11" - verifier: - inspec_tests: - - path: test/integration/repo/ - inputs: - pg_ver: "11" - run_list: - - recipe[test::repository] - - name: server_install_11 - attributes: - test: - pg_ver: "11" - verifier: - inspec_tests: - - path: test/integration/server_install/ - inputs: - pg_ver: "11" - run_list: - - recipe[test::server_install] From fac86c2d52a73438fcbff012c98192c9341f9765 Mon Sep 17 00:00:00 2001 From: Justin Fernbaugh Date: Mon, 22 Jan 2024 11:41:18 -0800 Subject: [PATCH 4/5] Add CHANGELOG documentation Combine two lines of documentation --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18de135b..801ed115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This file is used to list changes made in the last 3 major versions of the postg ## Unreleased +- Modify installed_postgresql_package_source to get highest PG version from packages +- Remove PG11 suites from kitchen & CI due to upstream removal + ## 11.9.0 - *2024-01-05* ## 11.8.5 - *2023-12-18* From 8678d3b5f3912cfedc661330b6d0f8f70ee93965 Mon Sep 17 00:00:00 2001 From: Justin Fernbaugh Date: Tue, 23 Jan 2024 12:17:45 -0800 Subject: [PATCH 5/5] Implement code refactor --- libraries/helpers.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libraries/helpers.rb b/libraries/helpers.rb index 29ad9d71..152f08f2 100644 --- a/libraries/helpers.rb +++ b/libraries/helpers.rb @@ -24,12 +24,17 @@ module Helpers include Utils def installed_postgresql_package_logic - pgsql_package = node['packages'].filter { |p| p.match?(/^postgresql-?(\d+)?$/) } - pgsql_package = [pgsql_package.max_by { |_key, value| value['version'].to_f }].to_h + pgsql_package = node['packages'].filter { |p| p.match?(/^postgresql-?(\d+)?$/) }.values + + unless pgsql_package.one? + versions = pgsql_package.map { |values| values['version'] }.join(', ') + Chef::Log.warn("Detected #{pgsql_package.count} installed PostgreSQL versions: #{versions}. Using latest version.") + pgsql_package = [pgsql_package.max_by { |values| values['version'].to_f }] + end raise 'Unable to determine installed PostgreSQL version' if nil_or_empty?(pgsql_package) - pgsql_package.values.first + pgsql_package.first end def installed_postgresql_major_version