Skip to content
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

Fix library/helpers.rb pulling different package names with multiple PG installations #765

Merged
merged 5 commits into from
Jan 24, 2024
Merged
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
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
name: ci

"on":
pull_request:
push:
Expand Down Expand Up @@ -34,12 +33,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"
Expand All @@ -53,7 +50,6 @@ jobs:
- "ident-14"
- "ident-15"
- "initdb-locale-15"
- "server-install-11"
- "server-install-12"
- "server-install-13"
- "server-install-14"
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
70 changes: 0 additions & 70 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
22 changes: 14 additions & 8 deletions libraries/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,22 @@ module Cookbook
module Helpers
include Utils

def installed_postgresql_major_version
pgsql_package = node['packages'].filter { |p| p.match?(/^postgresql-?(\d+)?$/) }
def installed_postgresql_package_logic
bmhughes marked this conversation as resolved.
Show resolved Hide resolved
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 = pgsql_package.values.first
pgsql_package.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
Expand All @@ -42,11 +52,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
Expand Down
Loading