foreman_maintain 1.8.2 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a042b3f0cd480eab2e674abcbd5aecb247943b481bad114e31376610a3b785d0
4
- data.tar.gz: 16e74a0e82caffb11d5d0363046bfa5120afab203ce1d88ad88a4311f664e1f4
3
+ metadata.gz: 9209b1f3f4a9910f6a635cd5876edbb3f9fa59e1381e532ae4961e18627fe638
4
+ data.tar.gz: 8a7f2e3ba17c629eea5535f86b94bb1be409620d520da3c0d96c61c1aea5009f
5
5
  SHA512:
6
- metadata.gz: 7bcc01a88e2f8bebb549a83af6d0b1f33a714a76925dc51ee48a2a979611e7d8fc47ed91b162ce97bd004360f9bb8cef7499c34160283e539e63e8b7f4b8315f
7
- data.tar.gz: 4e056e25de905cb6bb98da55c10dc1c1a57b99de6ed39b13241c4d09d7e2ca8cbaacaf6a44153ccd0f9675f432cda32ed9cb617399c3258940b0569898b12448
6
+ metadata.gz: 97e0f20269bc3b480bc429e91d7d119520ea4592162362f75efd42e9a4bc71200f4d13ff07b7103185200293826a3d887db265f99a2b7c94c385bd94a2eab352
7
+ data.tar.gz: de0dce8771c46602be6124a04a58b935529c051b2efb7d7f38fc8b5dd25e7b0d2203580335eb9038f2e6b21b79e0dab87a361e38ba173cb6f936bcfcd7378beb
@@ -0,0 +1,61 @@
1
+ module Checks
2
+ module Foreman
3
+ class CheckExternalDbEvrPermissions < ForemanMaintain::Check
4
+ metadata do
5
+ label :external_db_evr_permissions
6
+ for_feature :foreman_database
7
+ description 'Check that external databases have proper EVR extension permissions'
8
+ tags :pre_upgrade
9
+ confine do
10
+ feature(:foreman_database) && !feature(:foreman_database).local? && feature(:katello)
11
+ end
12
+ end
13
+
14
+ def run
15
+ return true unless evr_exists?
16
+
17
+ error_msg = 'The evr extension is not owned by the foreman database owner. ' \
18
+ 'Please run the following command on the external foreman database to fix it: ' \
19
+ 'UPDATE pg_extension SET extowner = (SELECT oid FROM pg_authid WHERE ' \
20
+ "rolname='#{foreman_db_user}') WHERE extname='evr';"
21
+ fail!(error_msg) unless foreman_owns_evr?
22
+ end
23
+
24
+ private
25
+
26
+ def foreman_db_user
27
+ feature(:foreman_database).configuration['username'] || 'foreman'
28
+ end
29
+
30
+ def evr_exists?
31
+ evr_exists = feature(:foreman_database).query(query_for_evr_existence)
32
+ return false if evr_exists.empty?
33
+ return evr_exists.first['evr_exists'] == '1'
34
+ end
35
+
36
+ def foreman_owns_evr?
37
+ evr_owned_by_postgres = feature(:foreman_database).query(query_if_postgres_owns_evr)
38
+ unless evr_owned_by_postgres.empty?
39
+ return evr_owned_by_postgres.first['evr_owned_by_postgres'] == '0'
40
+ end
41
+ failure_msg = 'Could not determine if the evr extension is owned by the ' \
42
+ 'foreman database owner. Check that the foreman database is accessible ' \
43
+ "and that the database connection configuration is up to date."
44
+ fail!(failure_msg)
45
+ end
46
+
47
+ def query_for_evr_existence
48
+ <<-SQL
49
+ SELECT 1 AS evr_exists FROM pg_extension WHERE extname = 'evr'
50
+ SQL
51
+ end
52
+
53
+ def query_if_postgres_owns_evr
54
+ <<-SQL
55
+ SELECT CASE WHEN r.rolname = '#{foreman_db_user}' THEN 0 ELSE 1 END AS evr_owned_by_postgres
56
+ FROM pg_extension e JOIN pg_roles r ON e.extowner = r.oid WHERE e.extname = 'evr'
57
+ SQL
58
+ end
59
+ end
60
+ end
61
+ end
@@ -40,6 +40,7 @@ module Scenarios::Foreman
40
40
  Checks::Disk::AvailableSpaceCandlepin, # if candlepin
41
41
  Checks::Disk::AvailableSpacePostgresql13,
42
42
  Checks::Foreman::ValidateExternalDbVersion, # if external database
43
+ Checks::Foreman::CheckExternalDbEvrPermissions, # if external database
43
44
  Checks::Foreman::CheckCorruptedRoles,
44
45
  Checks::Foreman::CheckDuplicatePermissions,
45
46
  Checks::Foreman::TuningRequirements, # if katello present
@@ -39,6 +39,7 @@ module Scenarios::Satellite
39
39
  Checks::Disk::AvailableSpace,
40
40
  Checks::Disk::AvailableSpaceCandlepin, # if candlepin
41
41
  Checks::Foreman::ValidateExternalDbVersion, # if external database
42
+ Checks::Foreman::CheckExternalDbEvrPermissions, # if external database
42
43
  Checks::Foreman::CheckCorruptedRoles,
43
44
  Checks::Foreman::CheckDuplicatePermissions,
44
45
  Checks::Foreman::TuningRequirements, # if katello present
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.8.2'.freeze
2
+ VERSION = '1.9.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_maintain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-13 00:00:00.000000000 Z
11
+ date: 2024-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -169,6 +169,7 @@ files:
169
169
  - definitions/checks/env_proxy.rb
170
170
  - definitions/checks/foreman/check_corrupted_roles.rb
171
171
  - definitions/checks/foreman/check_duplicate_permission.rb
172
+ - definitions/checks/foreman/check_external_db_evr_permissions.rb
172
173
  - definitions/checks/foreman/check_puppet_capsules.rb
173
174
  - definitions/checks/foreman/check_tuning_requirements.rb
174
175
  - definitions/checks/foreman/db_up.rb