foreman_maintain 1.12.4 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a99136516325dc9d13b83ddca246f197ecc63199d74cd950a582946a503fc2eb
4
- data.tar.gz: c59533ff3ae35ffdece203759eef0d16b3bc67fc9bd5146b32a0988c00821770
3
+ metadata.gz: e99fd5f893ec24f16eaea4c20b8260cd2878bf63149ddf830c29e15f0324cda0
4
+ data.tar.gz: 5f1e7e90783d76b45231d393e204f2588d5b4daf46723792186aaa14d9c525d9
5
5
  SHA512:
6
- metadata.gz: d2f883dfe1a9959d2790d856be260073a57a874d3d3e0fadd2c54b4eef1dbaf4979fe20070ffde6699dd2ff86dcb8733426f1eaa4a7213f1c1493a419678bc58
7
- data.tar.gz: 00a9ee5352ef84dd5b36451e862eedb070806e2b6233042cc35b72a1cd43c6c483b163246f301f833f4c2f3f6edf8bfbd1379463c9cf0060adef2e3ec6fb7258
6
+ metadata.gz: d5c950a2a4b110d1425f071a5532010f4b704267e3bde1d082ea1bed209ccf6f82bf5d2682ebbe444679edf85eb03e4b216ed7ba298dd3a6fd73904390ddce77
7
+ data.tar.gz: cccf743480372ef3b39e54ab995a9be077006dfe991a799021378371b3f58db1a04cac263f70e21bcd75b87e30892d55d390af17bb59cf0c57aee63030ae0543
@@ -0,0 +1,25 @@
1
+ module Checks
2
+ module Candlepin
3
+ class DBIndex < ForemanMaintain::Check
4
+ metadata do
5
+ description 'Make sure Candlepin DB indexes are OK'
6
+ label :candlepin_db_index
7
+ tags :db_index
8
+ for_feature :candlepin_database
9
+ confine do
10
+ feature(:candlepin_database)&.local?
11
+ end
12
+ end
13
+
14
+ def run
15
+ status, output = feature(:candlepin_database).amcheck
16
+
17
+ if !status.nil?
18
+ assert(status == 0, "Candlepin DB indexes have issues:\n#{output}")
19
+ else
20
+ skip 'amcheck is not available in this setup'
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Checks
2
+ module Foreman
3
+ class DBIndex < ForemanMaintain::Check
4
+ metadata do
5
+ description 'Make sure Foreman DB indexes are OK'
6
+ label :foreman_db_index
7
+ tags :db_index
8
+ for_feature :foreman_database
9
+ confine do
10
+ feature(:foreman_database)&.local?
11
+ end
12
+ end
13
+
14
+ def run
15
+ status, output = feature(:foreman_database).amcheck
16
+
17
+ if !status.nil?
18
+ assert(status == 0, "Foreman DB indexes have issues:\n#{output}")
19
+ else
20
+ skip 'amcheck is not available in this setup'
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Checks
2
+ module Pulpcore
3
+ class DBIndex < ForemanMaintain::Check
4
+ metadata do
5
+ description 'Make sure Pulpcore DB indexes are OK'
6
+ label :pulpcore_db_index
7
+ tags :db_index
8
+ for_feature :pulpcore_database
9
+ confine do
10
+ feature(:pulpcore_database)&.local?
11
+ end
12
+ end
13
+
14
+ def run
15
+ status, output = feature(:pulpcore_database).amcheck
16
+
17
+ if !status.nil?
18
+ assert(status == 0, "Pulpcore DB indexes have issues:\n#{output}")
19
+ else
20
+ skip 'amcheck is not available in this setup'
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -41,31 +41,26 @@ module Checks::Restore
41
41
 
42
42
  def required_katello_files(backup)
43
43
  backup_files_message(
44
- backup.katello_online_files.join(', '),
45
- backup.katello_offline_files.join(', ')
44
+ backup.katello_online_files.join(', ')
46
45
  )
47
46
  end
48
47
 
49
48
  def required_fpc_files(backup)
50
49
  backup_files_message(
51
- backup.fpc_online_files.join(', '),
52
- backup.fpc_offline_files.join(', ')
50
+ backup.fpc_online_files.join(', ')
53
51
  )
54
52
  end
55
53
 
56
54
  def required_foreman_files(backup)
57
55
  backup_files_message(
58
- backup.foreman_online_files.join(', '),
59
- backup.foreman_offline_files.join(', ')
56
+ backup.foreman_online_files.join(', ')
60
57
  )
61
58
  end
62
59
 
63
- def backup_files_message(online_files, offline_files)
60
+ def backup_files_message(online_files)
64
61
  message = ''
65
- message += 'An online or remote database backup directory contains: '
62
+ message += 'A backup directory contains: '
66
63
  message += "#{online_files}\n"
67
- message += 'An offline backup directory contains: '
68
- message += "#{offline_files}\n"
69
64
  message
70
65
  end
71
66
  end
@@ -10,9 +10,11 @@ class Checks::SystemRegistration < ForemanMaintain::Check
10
10
  end
11
11
 
12
12
  def run
13
- if rhsm_hostname_eql_hostname?
14
- warn! 'System is self registered'
15
- end
13
+ assert(!rhsm_hostname_eql_hostname?, 'System is self registered',
14
+ {
15
+ :warn => true,
16
+ :next_steps => [Procedures::KnowledgeBaseArticle.new(:doc => 'self_registered')],
17
+ })
16
18
  end
17
19
 
18
20
  def rhsm_hostname
@@ -26,6 +26,7 @@ class Procedures::KnowledgeBaseArticle < ForemanMaintain::Procedure
26
26
  'fix_cpdb_validate_failure' => 'https://access.redhat.com/solutions/3362821',
27
27
  'fix_db_migrate_failure_on_duplicate_roles' => 'https://access.redhat.com/solutions/3998941',
28
28
  'many_fact_values' => 'https://access.redhat.com/solutions/4163891',
29
+ 'self_registered' => 'https://access.redhat.com/solutions/3225941',
29
30
  }
30
31
  end
31
32
  end
@@ -15,10 +15,6 @@ module Procedures::Restore
15
15
  spinner.update('Extracting pulp data')
16
16
  extract_pulp_data(backup)
17
17
  end
18
- if backup.file_map[:pgsql_data][:present]
19
- spinner.update('Extracting pgsql data')
20
- extract_pgsql_data(backup)
21
- end
22
18
  end
23
19
  end
24
20
 
@@ -51,19 +47,5 @@ module Procedures::Restore
51
47
  def any_database
52
48
  feature(:foreman_database) || feature(:candlepin_database) || feature(:pulpcore_database)
53
49
  end
54
-
55
- def extract_pgsql_data(backup)
56
- pgsql_data_tar = base_tar.merge(
57
- :archive => backup.file_map[:pgsql_data][:path],
58
- :gzip => true
59
- )
60
- feature(:tar).run(pgsql_data_tar)
61
- del_data_dir_param if el?
62
- end
63
-
64
- def del_data_dir_param
65
- # workaround for https://tickets.puppetlabs.com/browse/MODULES-11160
66
- execute("sed -i '/data_directory/d' #{any_database.postgresql_conf}")
67
- end
68
50
  end
69
51
  end
@@ -18,8 +18,9 @@ module ForemanMaintain::Scenarios
18
18
 
19
19
  def compose
20
20
  check_valid_strategy
21
- add_step_with_context(Checks::Backup::IncrementalParentType,
22
- :online_backup => strategy == :online)
21
+ add_step(Checks::Foreman::DBIndex)
22
+ add_step(Checks::Candlepin::DBIndex)
23
+ add_step(Checks::Pulpcore::DBIndex)
23
24
  add_step(Checks::ForemanTasks::NotRunning.new(:wait_for_tasks => wait_for_tasks?))
24
25
  add_step(Checks::Pulpcore::NoRunningTasks.new(:wait_for_tasks => wait_for_tasks?))
25
26
  add_step_with_context(Procedures::Backup::AccessibilityConfirmation) if strategy == :offline
@@ -55,7 +56,6 @@ module ForemanMaintain::Scenarios
55
56
  context.map(:preserve_dir,
56
57
  Procedures::Backup::PrepareDirectory => :preserve_dir)
57
58
  context.map(:incremental_dir,
58
- Checks::Backup::IncrementalParentType => :incremental_dir,
59
59
  Procedures::Backup::PrepareDirectory => :incremental_dir,
60
60
  Procedures::Backup::Metadata => :incremental_dir)
61
61
  context.map(:proxy_features,
@@ -34,18 +34,13 @@ module ForemanMaintain::Scenarios
34
34
  add_steps_with_context(Procedures::Restore::InstallerReset)
35
35
  end
36
36
  add_step_with_context(Procedures::Service::Stop)
37
- add_steps_with_context(Procedures::Restore::ExtractFiles) if backup.tar_backups_exist?
38
37
 
39
38
  if backup.sql_needs_dump_restore?
40
39
  add_steps_with_context(Procedures::Restore::DropDatabases)
41
40
  restore_sql_dumps(backup)
42
41
  end
43
42
 
44
- if feature(:instance).postgresql_local? &&
45
- !backup.online_backup? &&
46
- backup.different_source_os?
47
- add_step_with_context(Procedures::Restore::ReindexDatabases)
48
- end
43
+ add_steps_with_context(Procedures::Restore::ExtractFiles) if backup.tar_backups_exist?
49
44
 
50
45
  add_step(Procedures::Installer::Run.new(:assumeyes => true))
51
46
  add_step_with_context(Procedures::Installer::UpgradeRakeTask)
@@ -140,6 +140,40 @@ module ForemanMaintain
140
140
  ' Make sure system has psql utility installed.'
141
141
  end
142
142
 
143
+ def amcheck
144
+ # executing the check requires superuser privileges
145
+ return unless local?
146
+
147
+ return unless amcheck_installed?
148
+
149
+ psqlcmd = "runuser - postgres -c 'psql --set=ON_ERROR_STOP=on #{configuration['database']}'"
150
+
151
+ amcheck_query = <<~SQL
152
+ SELECT bt_index_check(index => c.oid, heapallindexed => i.indisunique),
153
+ c.relname,
154
+ c.relpages
155
+ FROM pg_index i
156
+ JOIN pg_opclass op ON i.indclass[0] = op.oid
157
+ JOIN pg_am am ON op.opcmethod = am.oid
158
+ JOIN pg_class c ON i.indexrelid = c.oid
159
+ JOIN pg_namespace n ON c.relnamespace = n.oid
160
+ WHERE am.amname = 'btree' AND n.nspname = 'public'
161
+ -- Don't check temp tables, which may be from another session:
162
+ AND c.relpersistence != 't'
163
+ -- Function may throw an error when this is omitted:
164
+ AND c.relkind = 'i' AND i.indisready AND i.indisvalid
165
+ ORDER BY c.relpages DESC;
166
+ SQL
167
+
168
+ execute_with_status(psqlcmd, :stdin => amcheck_query)
169
+ end
170
+
171
+ def amcheck_installed?
172
+ sql = "select 'amcheck_installed' from pg_extension where extname='amcheck'"
173
+ result = query(sql)
174
+ !result.nil? && !result.empty?
175
+ end
176
+
143
177
  private
144
178
 
145
179
  def base_env
@@ -7,9 +7,8 @@ module ForemanMaintain
7
7
  class Backup
8
8
  include Concerns::SystemHelpers
9
9
 
10
- attr_accessor :standard_files, :katello_online_files, :katello_offline_files,
11
- :foreman_online_files, :foreman_offline_files, :fpc_offline_files,
12
- :fpc_online_files
10
+ attr_accessor :standard_files, :katello_online_files,
11
+ :foreman_online_files, :fpc_online_files
13
12
 
14
13
  ONLINE_BACKUP = 'online'.freeze
15
14
  OFFLINE_BACKUP = 'offline'.freeze
@@ -19,16 +18,12 @@ module ForemanMaintain
19
18
  @backup_dir = backup_dir
20
19
  @standard_files = ['config_files.tar.gz']
21
20
  @foreman_online_files = ['foreman.dump']
22
- @foreman_offline_files = ['pgsql_data.tar.gz']
23
21
  @katello_online_files = @foreman_online_files + ['candlepin.dump', 'pulpcore.dump']
24
- @katello_offline_files = ['pgsql_data.tar.gz']
25
22
  @fpc_online_files = ['pulpcore.dump']
26
- @fpc_offline_files = ['pgsql_data.tar.gz']
27
23
  end
28
24
 
29
25
  def file_map
30
26
  @file_map ||= {
31
- :pgsql_data => map_file(@backup_dir, 'pgsql_data.tar.gz'),
32
27
  :pulp_data => map_file(@backup_dir, 'pulp_data.tar'),
33
28
  :foreman_dump => map_file(@backup_dir, 'foreman.dump'),
34
29
  :iop_advisor_dump => map_file(@backup_dir, 'iop_advisor.dump'),
@@ -72,15 +67,15 @@ module ForemanMaintain
72
67
  end
73
68
 
74
69
  def valid_fpc_backup?
75
- fpc_online_backup? || fpc_standard_backup?
70
+ fpc_online_backup?
76
71
  end
77
72
 
78
73
  def valid_katello_backup?
79
- katello_online_backup? || katello_standard_backup?
74
+ katello_online_backup?
80
75
  end
81
76
 
82
77
  def valid_foreman_backup?
83
- foreman_standard_backup? || foreman_online_backup?
78
+ foreman_online_backup?
84
79
  end
85
80
 
86
81
  def check_file_existence(existence_map)
@@ -99,41 +94,22 @@ module ForemanMaintain
99
94
  true
100
95
  end
101
96
 
102
- def katello_standard_backup?
103
- present = [:pgsql_data]
104
- absent = [:candlepin_dump, :foreman_dump, :pulpcore_dump]
105
- check_file_existence(:present => present,
106
- :absent => absent)
107
- end
108
-
109
97
  def katello_online_backup?
110
98
  present = [:candlepin_dump, :foreman_dump, :pulpcore_dump]
111
- absent = [:pgsql_data]
112
- check_file_existence(:present => present,
113
- :absent => absent)
114
- end
115
-
116
- def fpc_standard_backup?
117
- present = [:pgsql_data]
118
- absent = [:candlepin_dump, :foreman_dump, :pulpcore_dump]
99
+ absent = []
119
100
  check_file_existence(:present => present,
120
101
  :absent => absent)
121
102
  end
122
103
 
123
104
  def fpc_online_backup?
124
105
  present = [:pulpcore_dump]
125
- absent = [:pgsql_data, :candlepin_dump, :foreman_dump]
106
+ absent = [:candlepin_dump, :foreman_dump]
126
107
  check_file_existence(:present => present, :absent => absent)
127
108
  end
128
109
 
129
- def foreman_standard_backup?
130
- check_file_existence(:present => [:pgsql_data],
131
- :absent => [:candlepin_dump, :foreman_dump, :pulpcore_dump])
132
- end
133
-
134
110
  def foreman_online_backup?
135
111
  check_file_existence(:present => [:foreman_dump],
136
- :absent => [:candlepin_dump, :pgsql_data, :pulpcore_dump])
112
+ :absent => [:candlepin_dump, :pulpcore_dump])
137
113
  end
138
114
 
139
115
  def validate_hostname?
@@ -174,12 +150,7 @@ module ForemanMaintain
174
150
  end
175
151
 
176
152
  def tar_backups_exist?
177
- file_map[:pulp_data][:present] ||
178
- file_map[:pgsql_data][:present]
179
- end
180
-
181
- def sql_tar_files_exist?
182
- file_map[:pgsql_data][:present]
153
+ file_map[:pulp_data][:present]
183
154
  end
184
155
 
185
156
  def sql_dump_files_exist?
@@ -189,7 +160,7 @@ module ForemanMaintain
189
160
  end
190
161
 
191
162
  def sql_needs_dump_restore?
192
- !sql_tar_files_exist? && sql_dump_files_exist?
163
+ sql_dump_files_exist?
193
164
  end
194
165
 
195
166
  def incremental?
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.12.4'.freeze
2
+ VERSION = '1.13.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_maintain
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.4
4
+ version: 1.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
@@ -156,7 +156,7 @@ files:
156
156
  - config/foreman_maintain.yml.packaging
157
157
  - config/hammer.yml.example
158
158
  - definitions/checks/backup/certs_tar_exist.rb
159
- - definitions/checks/backup/incremental_parent_type.rb
159
+ - definitions/checks/candlepin/db_index.rb
160
160
  - definitions/checks/candlepin/db_up.rb
161
161
  - definitions/checks/check_hotfix_installed.rb
162
162
  - definitions/checks/check_ipv6_disable.rb
@@ -174,6 +174,7 @@ files:
174
174
  - definitions/checks/foreman/check_external_db_evr_permissions.rb
175
175
  - definitions/checks/foreman/check_puppet_capsules.rb
176
176
  - definitions/checks/foreman/check_tuning_requirements.rb
177
+ - definitions/checks/foreman/db_index.rb
177
178
  - definitions/checks/foreman/db_up.rb
178
179
  - definitions/checks/foreman/facts_names.rb
179
180
  - definitions/checks/foreman/validate_external_db_version.rb
@@ -193,6 +194,7 @@ files:
193
194
  - definitions/checks/maintenance_mode/check_consistency.rb
194
195
  - definitions/checks/non_rh_packages.rb
195
196
  - definitions/checks/package_manager/dnf/validate_dnf_config.rb
197
+ - definitions/checks/pulpcore/db_index.rb
196
198
  - definitions/checks/pulpcore/db_up.rb
197
199
  - definitions/checks/pulpcore/no_running_tasks.rb
198
200
  - definitions/checks/puppet/verify_no_empty_cacert_requests.rb
@@ -319,7 +321,6 @@ files:
319
321
  - definitions/procedures/restore/iop_vmaas_dump.rb
320
322
  - definitions/procedures/restore/iop_vulnerability_dump.rb
321
323
  - definitions/procedures/restore/pulpcore_dump.rb
322
- - definitions/procedures/restore/reindex_databases.rb
323
324
  - definitions/procedures/restore/required_packages.rb
324
325
  - definitions/procedures/service/base.rb
325
326
  - definitions/procedures/service/daemon_reload.rb
@@ -1,33 +0,0 @@
1
- module Checks::Backup
2
- class IncrementalParentType < ForemanMaintain::Check
3
- metadata do
4
- description 'Check if the incremental backup has the right type'
5
- tags :backup
6
- param :incremental_dir, 'Path to existing backup directory'
7
- param :online_backup, 'Select for online backup', :flag => true, :default => false
8
- manual_detection
9
- end
10
-
11
- def run
12
- return unless @incremental_dir
13
-
14
- backup = ForemanMaintain::Utils::Backup.new(@incremental_dir)
15
-
16
- existing_type = backup.backup_type
17
- new_type = if @online_backup
18
- ForemanMaintain::Utils::Backup::ONLINE_BACKUP
19
- else
20
- ForemanMaintain::Utils::Backup::OFFLINE_BACKUP
21
- end
22
- msg = "The existing backup is an #{existing_type} backup, "\
23
- "but an #{new_type} backup was requested."
24
- assert(existing_type == new_type, msg)
25
-
26
- unless @online_backup
27
- msg = "The existing backup has PostgreSQL as a tarball, "\
28
- "but the new one will have a dump."
29
- assert(!backup.sql_tar_files_exist?, msg)
30
- end
31
- end
32
- end
33
- end
@@ -1,28 +0,0 @@
1
- module Procedures::Restore
2
- class ReindexDatabases < ForemanMaintain::Procedure
3
- include ForemanMaintain::Concerns::SystemService
4
- include ForemanMaintain::Concerns::SystemHelpers
5
-
6
- metadata do
7
- description 'REINDEX databases'
8
-
9
- confine do
10
- feature(:instance).postgresql_local?
11
- end
12
- end
13
-
14
- def run
15
- with_spinner('Reindexing the databases') do |spinner|
16
- feature(:service).handle_services(spinner, 'start', :only => ['postgresql'])
17
-
18
- spinner.update('Reindexing the databases')
19
- execute!('runuser - postgres -c "reindexdb -a"')
20
- if check_min_version('python3.11-pulp-ansible', '0.20.0')
21
- execute!('runuser -c '\
22
- '\'echo "ALTER COLLATION pulp_ansible_semver REFRESH VERSION;"'\
23
- '| psql pulpcore\' postgres')
24
- end
25
- end
26
- end
27
- end
28
- end