foreman_maintain 1.3.5 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/definitions/checks/check_hotfix_installed.rb +2 -3
  4. data/definitions/checks/disk/performance.rb +1 -2
  5. data/definitions/checks/package_manager/{yum/validate_yum_config.rb → dnf/validate_dnf_config.rb} +13 -11
  6. data/definitions/checks/repositories/check_upstream_repository.rb +1 -2
  7. data/definitions/features/installer.rb +8 -66
  8. data/definitions/features/instance.rb +0 -6
  9. data/definitions/procedures/backup/metadata.rb +5 -3
  10. data/definitions/procedures/packages/installer_confirmation.rb +1 -1
  11. data/definitions/procedures/packages/update.rb +3 -3
  12. data/definitions/scenarios/backup.rb +1 -6
  13. data/definitions/scenarios/self_upgrade.rb +4 -6
  14. data/definitions/scenarios/{upgrade_to_capsule_6_14_z.rb → upgrade_to_capsule_6_15.rb} +11 -12
  15. data/definitions/scenarios/{upgrade_to_capsule_6_14.rb → upgrade_to_capsule_6_15_z.rb} +12 -13
  16. data/definitions/scenarios/upgrade_to_katello_nightly.rb +1 -1
  17. data/definitions/scenarios/{upgrade_to_satellite_6_14_z.rb → upgrade_to_satellite_6_15.rb} +12 -12
  18. data/definitions/scenarios/{upgrade_to_satellite_6_14.rb → upgrade_to_satellite_6_15_z.rb} +12 -14
  19. data/extras/foreman_protector/foreman-protector.conf +1 -1
  20. data/lib/foreman_maintain/concerns/base_database.rb +0 -41
  21. data/lib/foreman_maintain/concerns/system_helpers.rb +2 -2
  22. data/lib/foreman_maintain/config.rb +5 -1
  23. data/lib/foreman_maintain/package_manager/dnf.rb +138 -11
  24. data/lib/foreman_maintain/package_manager.rb +0 -1
  25. data/lib/foreman_maintain/repository_manager/el.rb +2 -2
  26. data/lib/foreman_maintain/version.rb +1 -1
  27. metadata +11 -20
  28. data/definitions/checks/backup/directory_ready.rb +0 -23
  29. data/definitions/checks/foreman/check_checkpoint_segments.rb +0 -59
  30. data/definitions/checks/foreman/check_duplicate_roles.rb +0 -42
  31. data/definitions/checks/foreman/puppet_class_duplicates.rb +0 -48
  32. data/definitions/checks/original_assets.rb +0 -23
  33. data/definitions/procedures/foreman/apipie_cache.rb +0 -12
  34. data/definitions/procedures/foreman_docker/remove_foreman_docker.rb +0 -16
  35. data/extras/foreman_protector/yum/foreman-protector.py +0 -86
  36. data/lib/foreman_maintain/package_manager/yum.rb +0 -142
@@ -1,25 +1,25 @@
1
- module Scenarios::Satellite_6_14
1
+ module Scenarios::Satellite_6_15_z
2
2
  class Abstract < ForemanMaintain::Scenario
3
3
  def self.upgrade_metadata(&block)
4
4
  metadata do
5
5
  tags :upgrade_scenario
6
6
  confine do
7
7
  feature(:satellite) &&
8
- (feature(:satellite).current_minor_version == '6.13' || \
9
- ForemanMaintain.upgrade_in_progress == '6.14')
8
+ (feature(:satellite).current_minor_version == '6.15' || \
9
+ ForemanMaintain.upgrade_in_progress == '6.15.z')
10
10
  end
11
11
  instance_eval(&block)
12
12
  end
13
13
  end
14
14
 
15
15
  def target_version
16
- '6.14'
16
+ '6.15.z'
17
17
  end
18
18
  end
19
19
 
20
20
  class PreUpgradeCheck < Abstract
21
21
  upgrade_metadata do
22
- description 'Checks before upgrading to Satellite 6.14'
22
+ description 'Checks before upgrading to Satellite 6.15.z'
23
23
  tags :pre_upgrade_checks
24
24
  run_strategy :fail_slow
25
25
  end
@@ -27,14 +27,13 @@ module Scenarios::Satellite_6_14
27
27
  def compose
28
28
  add_steps(find_checks(:default))
29
29
  add_steps(find_checks(:pre_upgrade))
30
- add_step(Checks::Foreman::CheckpointSegments)
31
- add_step(Checks::Repositories::Validate.new(:version => '6.14'))
30
+ add_step(Checks::Repositories::Validate.new(:version => '6.15'))
32
31
  end
33
32
  end
34
33
 
35
34
  class PreMigrations < Abstract
36
35
  upgrade_metadata do
37
- description 'Procedures before migrating to Satellite 6.14'
36
+ description 'Procedures before migrating to Satellite 6.15.z'
38
37
  tags :pre_migrations
39
38
  end
40
39
 
@@ -45,9 +44,8 @@ module Scenarios::Satellite_6_14
45
44
 
46
45
  class Migrations < Abstract
47
46
  upgrade_metadata do
48
- description 'Migration scripts to Satellite 6.14'
47
+ description 'Migration scripts to Satellite 6.15.z'
49
48
  tags :migrations
50
- run_strategy :fail_fast
51
49
  end
52
50
 
53
51
  def set_context_mapping
@@ -55,11 +53,11 @@ module Scenarios::Satellite_6_14
55
53
  end
56
54
 
57
55
  def compose
58
- add_step(Procedures::Repositories::Setup.new(:version => '6.14'))
56
+ add_step(Procedures::Repositories::Setup.new(:version => '6.15'))
59
57
  modules_to_enable = ["satellite:#{el_short_name}"]
60
58
  add_step(Procedures::Packages::EnableModules.new(:module_names => modules_to_enable))
61
59
  add_step(Procedures::Packages::Update.new(:assumeyes => true,
62
- :yum_options => ['--downloadonly']))
60
+ :dnf_options => ['--downloadonly']))
63
61
  add_step(Procedures::Service::Stop.new)
64
62
  add_step(Procedures::Packages::Update.new(:assumeyes => true))
65
63
  add_step_with_context(Procedures::Installer::Upgrade)
@@ -69,7 +67,7 @@ module Scenarios::Satellite_6_14
69
67
 
70
68
  class PostMigrations < Abstract
71
69
  upgrade_metadata do
72
- description 'Procedures after migrating to Satellite 6.14'
70
+ description 'Procedures after migrating to Satellite 6.15.z'
73
71
  tags :post_migrations
74
72
  end
75
73
 
@@ -82,7 +80,7 @@ module Scenarios::Satellite_6_14
82
80
 
83
81
  class PostUpgradeChecks < Abstract
84
82
  upgrade_metadata do
85
- description 'Checks after upgrading to Satellite 6.14'
83
+ description 'Checks after upgrading to Satellite 6.15.z'
86
84
  tags :post_upgrade_checks
87
85
  run_strategy :fail_slow
88
86
  end
@@ -1,3 +1,3 @@
1
1
  [main]
2
2
  enabled = 0
3
- whitelist = /etc/yum/pluginconf.d/foreman-protector.whitelist
3
+ whitelist = /etc/dnf/plugins/foreman-protector.whitelist
@@ -75,11 +75,6 @@ module ForemanMaintain
75
75
  :hidden_patterns => [config['password']])
76
76
  end
77
77
 
78
- def backup_file_path(config = configuration)
79
- dump_file_name = "#{config['database']}_#{Time.now.strftime('%Y-%m-%d_%H-%M-%S')}.dump"
80
- "#{backup_dir}/#{dump_file_name}.bz2"
81
- end
82
-
83
78
  def dump_db(file, config = configuration)
84
79
  execute!(dump_command(config) + " > #{file}", :hidden_patterns => [config['password']])
85
80
  end
@@ -115,47 +110,11 @@ module ForemanMaintain
115
110
  end
116
111
  end
117
112
 
118
- # TODO: refactor to use dump_db
119
- def backup_db_command(file_path, config = configuration)
120
- pg_dump_cmd = "pg_dump -Fc #{config['database']}"
121
- "runuser - postgres -c '#{pg_dump_cmd}' | bzip2 -9 > #{file_path}"
122
- end
123
-
124
113
  # TODO: remove the backup file path tools from here. Lib Utils::Backup?
125
114
  def backup_dir
126
115
  @backup_dir ||= File.expand_path(ForemanMaintain.config.db_backup_dir)
127
116
  end
128
117
 
129
- def perform_backup(config = configuration)
130
- file_path = backup_file_path(config)
131
- backup_cmd = backup_db_command(file_path, config)
132
- execute!(backup_cmd, :hidden_patterns => [config['password']])
133
- puts "\n Note: Database backup file path - #{file_path}"
134
- puts "\n In case of any exception, use above dump file to restore DB."
135
- end
136
-
137
- def table_exist?(table_name)
138
- sql = <<-SQL
139
- SELECT EXISTS ( SELECT *
140
- FROM information_schema.tables WHERE table_name = '#{table_name}' )
141
- SQL
142
- result = query(sql)
143
- return false if result.nil? || (result && result.empty?)
144
-
145
- result.first['exists'].eql?('t')
146
- end
147
-
148
- def delete_records_by_ids(tbl_name, rec_ids)
149
- quotize_rec_ids = rec_ids.map { |el| "'#{el}'" }.join(',')
150
- unless quotize_rec_ids.empty?
151
- psql(<<-SQL)
152
- BEGIN;
153
- DELETE FROM #{tbl_name} WHERE id IN (#{quotize_rec_ids});
154
- COMMIT;
155
- SQL
156
- end
157
- end
158
-
159
118
  def find_base_directory(directory)
160
119
  find_dir_containing_file(directory, 'postgresql.conf')
161
120
  end
@@ -100,13 +100,13 @@ module ForemanMaintain
100
100
  end
101
101
 
102
102
  def packages_action(action, packages, options = {})
103
- options.validate_options!(:assumeyes, :yum_options)
103
+ options.validate_options!(:assumeyes, :dnf_options)
104
104
  case action
105
105
  when :install
106
106
  package_manager.install(packages, :assumeyes => options[:assumeyes])
107
107
  when :update
108
108
  package_manager.update(packages, :assumeyes => options[:assumeyes],
109
- :yum_options => options[:yum_options])
109
+ :dnf_options => options[:dnf_options])
110
110
  when :remove
111
111
  package_manager.remove(packages, :assumeyes => options[:assumeyes])
112
112
  else
@@ -64,7 +64,11 @@ module ForemanMaintain
64
64
  end
65
65
 
66
66
  def config_file_path
67
- File.exist?(CONFIG_FILE) ? CONFIG_FILE : File.join(source_path, 'config/foreman_maintain.yml')
67
+ if defined?(CONFIG_FILE) && File.exist?(CONFIG_FILE)
68
+ CONFIG_FILE
69
+ else
70
+ File.join(source_path, 'config/foreman_maintain.yml')
71
+ end
68
72
  end
69
73
 
70
74
  def source_path
@@ -1,14 +1,100 @@
1
1
  module ForemanMaintain::PackageManager
2
- class Dnf < Yum
3
- def clean_cache(assumeyes: false)
4
- dnf_action('clean', 'all', :assumeyes => assumeyes)
5
- super
2
+ class Dnf < Base
3
+ PROTECTOR_CONFIG_FILE = '/etc/dnf/plugins/foreman-protector.conf'.freeze
4
+ PROTECTOR_WHITELIST_FILE = '/etc/dnf/plugins/foreman-protector.whitelist'.freeze
5
+
6
+ def self.parse_envra(envra)
7
+ # envra format: 0:foreman-1.20.1.10-1.el7sat.noarch
8
+ parsed = envra.match(/\d*:?(?<name>.*)-[^-]+-[^-]+\.[^.]+/)
9
+ parsed ? Hash[parsed.names.map(&:to_sym).zip(parsed.captures)].merge(:envra => envra) : nil
10
+ end
11
+
12
+ def lock_versions
13
+ enable_protector
14
+ end
15
+
16
+ def unlock_versions
17
+ disable_protector
18
+ end
19
+
20
+ def versions_locked?
21
+ !!(protector_config =~ /^\s*enabled\s*=\s*1/) &&
22
+ protector_whitelist_file_nonzero?
23
+ end
24
+
25
+ def protector_whitelist_file_nonzero?
26
+ File.exist?(PROTECTOR_WHITELIST_FILE) &&
27
+ !File.zero?(PROTECTOR_WHITELIST_FILE)
6
28
  end
7
29
 
8
30
  def version_locking_supported?
9
31
  true
10
32
  end
11
33
 
34
+ def installed?(packages)
35
+ packages_list = [packages].flatten(1).map { |pkg| "'#{pkg}'" }.join(' ')
36
+ sys.execute?(%(rpm -q #{packages_list}))
37
+ end
38
+
39
+ def find_installed_package(name, queryformat = '')
40
+ rpm_cmd = "rpm -q '#{name}'"
41
+ unless queryformat.empty?
42
+ rpm_cmd += " --qf '#{queryformat}'"
43
+ end
44
+ status, result = sys.execute_with_status(rpm_cmd, interactive: false)
45
+ if status == 0
46
+ result
47
+ end
48
+ end
49
+
50
+ def install(packages, assumeyes: false)
51
+ dnf_action('install', packages, assumeyes: assumeyes)
52
+ end
53
+
54
+ def reinstall(packages, assumeyes: false)
55
+ dnf_action('reinstall', packages, assumeyes: assumeyes)
56
+ end
57
+
58
+ def remove(packages, assumeyes: false)
59
+ dnf_action('remove', packages, assumeyes: assumeyes)
60
+ end
61
+
62
+ def update(packages = [], assumeyes: false, dnf_options: [])
63
+ dnf_action('update', packages, assumeyes: assumeyes, dnf_options: dnf_options)
64
+ end
65
+
66
+ def check_update(packages: nil, with_status: false)
67
+ dnf_action(
68
+ 'check-update',
69
+ packages,
70
+ assumeyes: true,
71
+ valid_exit_statuses: [0, 100],
72
+ with_status: with_status
73
+ )
74
+ end
75
+
76
+ def update_available?(package)
77
+ cmd_output = dnf_action('check-update -q', package, with_status: true, assumeyes: false)
78
+ cmd_output[0] == 100
79
+ end
80
+
81
+ def files_not_owned_by_package(directory)
82
+ find_cmd = "find #{directory} -exec /bin/sh -c 'rpm -qf {} &> /dev/null || echo {}' \\;"
83
+ sys.execute(find_cmd).split("\n")
84
+ end
85
+
86
+ def list_installed_packages(queryformat = '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n')
87
+ # The queryformat should only include valid tag(s) as per `rpm --querytags` list.
88
+ # If any special formatting is required with querytag then it should be provided with tag i.e,
89
+ # "--%{VENDOR}"
90
+ # The queryformat string must end with '\n'
91
+ sys.execute!("rpm -qa --qf '#{queryformat}'").split("\n")
92
+ end
93
+
94
+ def clean_cache(assumeyes: false)
95
+ dnf_action('clean', 'all', :assumeyes => assumeyes)
96
+ end
97
+
12
98
  def module_enabled?(name)
13
99
  _status, result = info(name)
14
100
  result.match?(/Stream.+\[e\].+/)
@@ -29,18 +115,59 @@ module ForemanMaintain::PackageManager
29
115
 
30
116
  private
31
117
 
32
- def dnf_action(action, packages, with_status: false, assumeyes: false)
118
+ # rubocop:disable Metrics/LineLength, Metrics/ParameterLists
119
+ def dnf_action(action, packages, with_status: false, assumeyes: false, dnf_options: [], valid_exit_statuses: [0])
33
120
  packages = [packages].flatten(1)
34
- yum_options = []
35
- yum_options << '-y' if assumeyes
121
+
122
+ dnf_options << '-y' if assumeyes
123
+ dnf_options << '--disableplugin=foreman-protector'
124
+
125
+ command = ['dnf', dnf_options.join(' '), action]
126
+
127
+ command.push(packages.join(' ')) unless packages.empty?
128
+ command = command.join(' ')
129
+
36
130
  if with_status
37
- sys.execute_with_status("dnf #{yum_options.join(' ')} #{action} #{packages.join(' ')}",
38
- :interactive => !assumeyes)
131
+ sys.execute_with_status(
132
+ command,
133
+ :interactive => !assumeyes
134
+ )
39
135
  else
40
- sys.execute!("dnf #{yum_options.join(' ')} #{action} #{packages.join(' ')}",
41
- :interactive => !assumeyes)
136
+ sys.execute!(
137
+ command,
138
+ :interactive => !assumeyes,
139
+ :valid_exit_statuses => valid_exit_statuses
140
+ )
141
+ end
142
+ end
143
+ # rubocop:enable Metrics/LineLength, Metrics/ParameterLists
42
144
 
145
+ def protector_config
146
+ File.exist?(protector_config_file) ? File.read(protector_config_file) : ''
147
+ end
148
+
149
+ def protector_config_file
150
+ PROTECTOR_CONFIG_FILE
151
+ end
152
+
153
+ def enable_protector
154
+ setup_protector(true)
155
+ end
156
+
157
+ def disable_protector
158
+ setup_protector(false)
159
+ end
160
+
161
+ def setup_protector(enabled)
162
+ config = protector_config
163
+ config += "\n" unless config[-1] == "\n"
164
+ enabled_re = /^\s*enabled\s*=.*$/
165
+ if enabled_re.match(config)
166
+ config = config.gsub(enabled_re, "enabled = #{enabled ? '1' : '0'}")
167
+ else
168
+ config += "enabled = #{enabled ? '1' : '0'}\n"
43
169
  end
170
+ File.open(protector_config_file, 'w') { |file| file.puts config }
44
171
  end
45
172
  end
46
173
  end
@@ -1,5 +1,4 @@
1
1
  require 'foreman_maintain/package_manager/base'
2
- require 'foreman_maintain/package_manager/yum'
3
2
  require 'foreman_maintain/package_manager/dnf'
4
3
  require 'foreman_maintain/package_manager/apt'
5
4
 
@@ -72,8 +72,8 @@ module ForemanMaintain::RepositoryManager
72
72
  entry.split(':', 2).last.strip
73
73
  end]
74
74
 
75
- # The EL7 yum repolist output includes extra info in the output,
76
- # as example
75
+ # repolist output includes extra info in the output
76
+ #
77
77
  # rhel-7-server-rpms/7Server/x86_64
78
78
  # rhel-server-rhscl-7-rpms/7Server/x86_64
79
79
  # This trims anything after first '/' to get correct repo label
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.3.5'.freeze
2
+ VERSION = '1.4.1'.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.3.5
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-16 00:00:00.000000000 Z
11
+ date: 2023-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -158,7 +158,6 @@ files:
158
158
  - config/foreman_maintain.yml.packaging
159
159
  - config/hammer.yml.example
160
160
  - definitions/checks/backup/certs_tar_exist.rb
161
- - definitions/checks/backup/directory_ready.rb
162
161
  - definitions/checks/candlepin/db_up.rb
163
162
  - definitions/checks/check_for_newer_packages.rb
164
163
  - definitions/checks/check_hotfix_installed.rb
@@ -168,15 +167,12 @@ files:
168
167
  - definitions/checks/disk/available_space_postgresql12.rb
169
168
  - definitions/checks/disk/performance.rb
170
169
  - definitions/checks/env_proxy.rb
171
- - definitions/checks/foreman/check_checkpoint_segments.rb
172
170
  - definitions/checks/foreman/check_corrupted_roles.rb
173
171
  - definitions/checks/foreman/check_duplicate_permission.rb
174
- - definitions/checks/foreman/check_duplicate_roles.rb
175
172
  - definitions/checks/foreman/check_puppet_capsules.rb
176
173
  - definitions/checks/foreman/check_tuning_requirements.rb
177
174
  - definitions/checks/foreman/db_up.rb
178
175
  - definitions/checks/foreman/facts_names.rb
179
- - definitions/checks/foreman/puppet_class_duplicates.rb
180
176
  - definitions/checks/foreman/validate_external_db_version.rb
181
177
  - definitions/checks/foreman_openscap/invalid_report_associations.rb
182
178
  - definitions/checks/foreman_proxy/check_tftp_storage.rb
@@ -188,8 +184,7 @@ files:
188
184
  - definitions/checks/foreman_tasks/not_running.rb
189
185
  - definitions/checks/maintenance_mode/check_consistency.rb
190
186
  - definitions/checks/non_rh_packages.rb
191
- - definitions/checks/original_assets.rb
192
- - definitions/checks/package_manager/yum/validate_yum_config.rb
187
+ - definitions/checks/package_manager/dnf/validate_dnf_config.rb
193
188
  - definitions/checks/pulpcore/db_up.rb
194
189
  - definitions/checks/puppet/verify_no_empty_cacert_requests.rb
195
190
  - definitions/checks/repositories/check_non_rh_repository.rb
@@ -259,11 +254,9 @@ files:
259
254
  - definitions/procedures/crond/start.rb
260
255
  - definitions/procedures/crond/stop.rb
261
256
  - definitions/procedures/files/remove.rb
262
- - definitions/procedures/foreman/apipie_cache.rb
263
257
  - definitions/procedures/foreman/fix_corrupted_roles.rb
264
258
  - definitions/procedures/foreman/remove_duplicate_obsolete_roles.rb
265
259
  - definitions/procedures/foreman/remove_duplicate_permissions.rb
266
- - definitions/procedures/foreman_docker/remove_foreman_docker.rb
267
260
  - definitions/procedures/foreman_maintain_features.rb
268
261
  - definitions/procedures/foreman_openscap/invalid_report_associations.rb
269
262
  - definitions/procedures/foreman_proxy/features.rb
@@ -332,17 +325,16 @@ files:
332
325
  - definitions/scenarios/restore.rb
333
326
  - definitions/scenarios/self_upgrade.rb
334
327
  - definitions/scenarios/services.rb
335
- - definitions/scenarios/upgrade_to_capsule_6_14.rb
336
- - definitions/scenarios/upgrade_to_capsule_6_14_z.rb
328
+ - definitions/scenarios/upgrade_to_capsule_6_15.rb
329
+ - definitions/scenarios/upgrade_to_capsule_6_15_z.rb
337
330
  - definitions/scenarios/upgrade_to_foreman_nightly.rb
338
331
  - definitions/scenarios/upgrade_to_katello_nightly.rb
339
- - definitions/scenarios/upgrade_to_satellite_6_14.rb
340
- - definitions/scenarios/upgrade_to_satellite_6_14_z.rb
332
+ - definitions/scenarios/upgrade_to_satellite_6_15.rb
333
+ - definitions/scenarios/upgrade_to_satellite_6_15_z.rb
341
334
  - extras/foreman-maintain.sh
342
335
  - extras/foreman_protector/dnf/foreman-protector.py
343
336
  - extras/foreman_protector/foreman-protector.conf
344
337
  - extras/foreman_protector/foreman-protector.whitelist
345
- - extras/foreman_protector/yum/foreman-protector.py
346
338
  - lib/foreman_maintain.rb
347
339
  - lib/foreman_maintain/check.rb
348
340
  - lib/foreman_maintain/cli.rb
@@ -397,7 +389,6 @@ files:
397
389
  - lib/foreman_maintain/package_manager/apt.rb
398
390
  - lib/foreman_maintain/package_manager/base.rb
399
391
  - lib/foreman_maintain/package_manager/dnf.rb
400
- - lib/foreman_maintain/package_manager/yum.rb
401
392
  - lib/foreman_maintain/param.rb
402
393
  - lib/foreman_maintain/procedure.rb
403
394
  - lib/foreman_maintain/reporter.rb
@@ -433,7 +424,7 @@ homepage: https://github.com/theforeman/foreman_maintain
433
424
  licenses:
434
425
  - GPL-3.0
435
426
  metadata: {}
436
- post_install_message:
427
+ post_install_message:
437
428
  rdoc_options: []
438
429
  require_paths:
439
430
  - lib
@@ -451,8 +442,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
451
442
  - !ruby/object:Gem::Version
452
443
  version: '0'
453
444
  requirements: []
454
- rubygems_version: 3.3.26
455
- signing_key:
445
+ rubygems_version: 3.4.10
446
+ signing_key:
456
447
  specification_version: 4
457
448
  summary: Foreman maintenance tool belt
458
449
  test_files: []
@@ -1,23 +0,0 @@
1
- module Checks::Backup
2
- class DirectoryReady < ForemanMaintain::Check
3
- metadata do
4
- description 'Check if the directory exists and is writable'
5
- tags :backup
6
- manual_detection
7
- param :backup_dir, 'Directory where to backup to', :required => true
8
- param :preserve_dir, 'Directory where to backup to', :flag => true, :default => false
9
- param :postgres_access, 'Whether the postgres user needs access', :flag => true,
10
- :default => false
11
- end
12
-
13
- def run
14
- assert(File.directory?(@backup_dir), "Backup directory (#{@backup_dir}) does not exist.")
15
- if feature(:instance).postgresql_local? && @postgres_access
16
- result = system("runuser - postgres -c 'test -w #{@backup_dir}'")
17
- assert(result, "Postgres user needs write access to the backup directory \n" \
18
- "Please allow the postgres user write access to #{@backup_dir}" \
19
- ' or choose another directory.')
20
- end
21
- end
22
- end
23
- end
@@ -1,59 +0,0 @@
1
- module Checks
2
- module Foreman
3
- class CheckpointSegments < ForemanMaintain::Check
4
- metadata do
5
- label :check_postgresql_checkpoint_segments
6
- description 'Check if checkpoint_segments configuration exists on the system'
7
- confine do
8
- feature(:foreman) && feature(:installer) &&
9
- File.exist?(feature(:installer).custom_hiera_file)
10
- end
11
- end
12
-
13
- def run
14
- failure_message = check_custom_hiera
15
- fail! failure_message if failure_message
16
- end
17
-
18
- # rubocop:disable Metrics/MethodLength
19
- def check_custom_hiera
20
- hiera_file = feature(:installer).custom_hiera_file
21
- begin
22
- config = YAML.load_file(hiera_file)
23
- if config.is_a?(Hash) && config.key?('postgresql::server::config_entries')
24
- if config['postgresql::server::config_entries'].nil?
25
- return <<-MESSAGE.strip_heredoc
26
- ERROR: 'postgresql::server::config_entries' cannot be null.
27
- Please remove it from following file and re-run the command.
28
- - #{hiera_file}
29
- MESSAGE
30
- elsif config['postgresql::server::config_entries'].key?('checkpoint_segments')
31
- message = <<-MESSAGE.strip_heredoc
32
- ERROR: Tuning option 'checkpoint_segments' found.
33
- This option is no longer valid for PostgreSQL 9.5 or newer.
34
- Please remove it from following file and re-run the command.
35
- - #{hiera_file}
36
- MESSAGE
37
- if feature(:katello)
38
- message += <<-MESSAGE.strip_heredoc
39
- The presence of checkpoint_segments in #{hiera_file} indicates manual tuning.
40
- Manual tuning can override values provided by the --tuning parameter.
41
- Review #{hiera_file} for values that are already provided by the built in tuning profiles.
42
- Built in tuning profiles also provide a supported upgrade path.
43
- MESSAGE
44
- end
45
- return message
46
- end
47
- elsif config.is_a?(String)
48
- fail! "Error: File #{hiera_file} is not a yaml file."
49
- exit 1
50
- end
51
- rescue Psych::SyntaxError
52
- fail! "Found syntax error in file: #{hiera_file}"
53
- exit 1
54
- end
55
- end
56
- # rubocop:enable Metrics/MethodLength
57
- end
58
- end
59
- end
@@ -1,42 +0,0 @@
1
- module Checks
2
- module Foreman
3
- class CheckDuplicateRoles < ForemanMaintain::Check
4
- metadata do
5
- label :duplicate_roles
6
- for_feature :foreman_database
7
- description 'Check for duplicate roles from DB'
8
- tags :pre_upgrade
9
- confine do
10
- check_max_version('foreman', '1.20')
11
- end
12
- end
13
-
14
- def run
15
- duplicate_roles = find_duplicate_roles
16
- roles_names = duplicate_roles.map { |r| r['name'] }.uniq
17
- assert(
18
- duplicate_roles.empty?,
19
- "Duplicate entries found for role(s) - #{roles_names.join(', ')} in your DB",
20
- :next_steps => [
21
- Procedures::Foreman::RemoveDuplicateObsoleteRoles.new,
22
- Procedures::KnowledgeBaseArticle.new(
23
- :doc => 'fix_db_migrate_failure_on_duplicate_roles'
24
- ),
25
- ]
26
- )
27
- end
28
-
29
- def find_duplicate_roles
30
- feature(:foreman_database).query(self.class.query_to_get_duplicate_roles)
31
- end
32
-
33
- def self.query_to_get_duplicate_roles
34
- <<-SQL
35
- SELECT r.id, r.name FROM roles r JOIN (
36
- SELECT name, COUNT(*) FROM roles GROUP BY name HAVING count(*) > 1
37
- ) dr ON r.name = dr.name ORDER BY r.name
38
- SQL
39
- end
40
- end
41
- end
42
- end
@@ -1,48 +0,0 @@
1
- module Checks
2
- module Foreman
3
- class PuppetClassDuplicates < ForemanMaintain::Check
4
- metadata do
5
- label :puppet_class_duplicates
6
- for_feature :foreman_database
7
- description 'Check for duplicate Puppet class records'
8
- tags :pre_upgrade
9
- confine do
10
- check_max_version('foreman', '1.20')
11
- end
12
- end
13
-
14
- def run
15
- duplicate_names = find_duplicate_names
16
- assert(duplicate_names.empty?, duplicate_msg(duplicate_names))
17
- end
18
-
19
- private
20
-
21
- def duplicate_msg(duplicate_names)
22
- msg = "There are #{duplicate_names.count} Puppet classes with duplicities:\n"
23
- classes_list = duplicate_names.reduce('') do |memo, hash|
24
- memo.tap { |acc| acc << "#{hash['name']} - #{hash['name_count']}\n" }
25
- end
26
- help_msg = 'Please head over to Configure -> Classes'
27
- help_msg << " and make sure there is only 1 Puppet class record for each name.\n"
28
- [msg, classes_list, help_msg].join('')
29
- end
30
-
31
- def find_duplicate_names
32
- feature(:foreman_database).query(duplicate_names_query)
33
- end
34
-
35
- def duplicate_names_query
36
- <<-SQL
37
- SELECT name, name_count
38
- FROM (
39
- SELECT name, count(name) AS name_count
40
- FROM puppetclasses
41
- GROUP BY name
42
- ) AS puppetclass_counts
43
- WHERE name_count > 1
44
- SQL
45
- end
46
- end
47
- end
48
- end