foreman_maintain 1.8.0 → 1.8.2

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: 8e99ddc1408ae68f584bbfc6e8798367e623e38f981682666f40cac91bb8f5f4
4
- data.tar.gz: 173ee0cd4fbce206437d53937eaf0489111e4c6b57eac8b04943c9468eb5ab40
3
+ metadata.gz: a042b3f0cd480eab2e674abcbd5aecb247943b481bad114e31376610a3b785d0
4
+ data.tar.gz: 16e74a0e82caffb11d5d0363046bfa5120afab203ce1d88ad88a4311f664e1f4
5
5
  SHA512:
6
- metadata.gz: 60a28996480d8564f5900a56d3f1494f9eb756d0a54c1bf3fee4c37fb5096a848db3a4ed2a6700e65d2fd4193bda13bebb4a50368ca0dbfd2ca1dccf9ea76d8e
7
- data.tar.gz: c323322a2e40d116c34de3ed7430742caa127250024957aa4b2579b14bbc27fb271312a6d973d82533ef091ca77ead05de0cf61c005475da8e3766e910e35562
6
+ metadata.gz: 7bcc01a88e2f8bebb549a83af6d0b1f33a714a76925dc51ee48a2a979611e7d8fc47ed91b162ce97bd004360f9bb8cef7499c34160283e539e63e8b7f4b8315f
7
+ data.tar.gz: 4e056e25de905cb6bb98da55c10dc1c1a57b99de6ed39b13241c4d09d7e2ca8cbaacaf6a44153ccd0f9675f432cda32ed9cb617399c3258940b0569898b12448
data/README.md CHANGED
@@ -20,7 +20,6 @@ Subcommands:
20
20
  check --target-version TARGET_VERSION Run pre-upgrade checks for upgrading to specified version
21
21
  --disable-self-upgrade Disable automatic self upgrade (default: false)
22
22
  run --target-version TARGET_VERSION Run the full upgrade
23
- [--phase=phase TARGET_VERSION] Run just a specific phase of the upgrade
24
23
  --disable-self-upgrade Disable automatic self upgrade (default: false)
25
24
 
26
25
  advanced Advanced tools for server maintenance
@@ -42,35 +42,30 @@ module Checks::Restore
42
42
  def required_katello_files(backup)
43
43
  backup_files_message(
44
44
  backup.katello_online_files.join(', '),
45
- backup.katello_offline_files.join(', '),
46
- [backup.katello_online_files + backup.katello_offline_files].join(', ')
45
+ backup.katello_offline_files.join(', ')
47
46
  )
48
47
  end
49
48
 
50
49
  def required_fpc_files(backup)
51
50
  backup_files_message(
52
51
  backup.fpc_online_files.join(', '),
53
- backup.fpc_offline_files.join(', '),
54
- [backup.fpc_online_files + backup.fpc_offline_files].join(', ')
52
+ backup.fpc_offline_files.join(', ')
55
53
  )
56
54
  end
57
55
 
58
56
  def required_foreman_files(backup)
59
57
  backup_files_message(
60
58
  backup.foreman_online_files.join(', '),
61
- backup.foreman_offline_files.join(', '),
62
- [backup.foreman_online_files + backup.foreman_offline_files].join(', ')
59
+ backup.foreman_offline_files.join(', ')
63
60
  )
64
61
  end
65
62
 
66
- def backup_files_message(online_files, offline_files, logical_files)
63
+ def backup_files_message(online_files, offline_files)
67
64
  message = ''
68
65
  message += 'An online or remote database backup directory contains: '
69
66
  message += "#{online_files}\n"
70
67
  message += 'An offline backup directory contains: '
71
68
  message += "#{offline_files}\n"
72
- message += 'A logical backup directory contains: '
73
- message += "#{logical_files}\n"
74
69
  message
75
70
  end
76
71
  end
@@ -28,15 +28,6 @@ class Features::CandlepinDatabase < ForemanMaintain::Feature
28
28
  execute?(help_cmd)
29
29
  end
30
30
 
31
- def env_content_ids_with_null_content
32
- sql = <<-SQL
33
- SELECT ec.id
34
- FROM cp_env_content ec
35
- LEFT JOIN cp_content c ON ec.contentid = c.id WHERE c.id IS NULL
36
- SQL
37
- query(sql).map { |r| r['id'] }
38
- end
39
-
40
31
  private
41
32
 
42
33
  def load_configuration
@@ -70,6 +70,7 @@ class Features::ForemanProxy < ForemanMaintain::Feature
70
70
  configs += ['/var/lib/dhcpd', File.dirname(dhcpd_config_file)]
71
71
  end
72
72
  configs.push('/usr/share/xml/scap') if backup_features.include?('openscap')
73
+ configs.push('/etc/ansible') if backup_features.include?('ansible')
73
74
  configs
74
75
  end
75
76
 
@@ -26,18 +26,21 @@ class Features::PulpcoreDatabase < ForemanMaintain::Feature
26
26
 
27
27
  private
28
28
 
29
- # rubocop:disable Metrics/AbcSize
30
29
  def load_configuration
31
- full_config = File.read(PULPCORE_DB_CONFIG).split(/[\s,'":]/).reject(&:empty?)
30
+ python_command = <<~PYTHON.strip
31
+ from django.conf import settings; import json; print(json.dumps(settings.DATABASES["default"]))
32
+ PYTHON
33
+ manager_command = pulpcore_manager("shell --command '#{python_command}'")
34
+ manager_result = execute!(manager_command)
35
+ db_config = JSON.parse(manager_result)
32
36
 
33
37
  @configuration = {}
34
38
  @configuration['adapter'] = 'postgresql'
35
- @configuration['host'] = full_config[full_config.index('HOST') + 1]
36
- @configuration['port'] = full_config[full_config.index('PORT') + 1]
37
- @configuration['database'] = full_config[full_config.index('NAME') + 1]
38
- @configuration['username'] = full_config[full_config.index('USER') + 1]
39
- @configuration['password'] = full_config[full_config.index('PASSWORD') + 1]
39
+ @configuration['host'] = db_config['HOST']
40
+ @configuration['port'] = db_config['PORT']
41
+ @configuration['database'] = db_config['NAME']
42
+ @configuration['username'] = db_config['USER']
43
+ @configuration['password'] = db_config['PASSWORD']
40
44
  @configuration
41
45
  end
42
- # rubocop:enable Metrics/AbcSize
43
46
  end
@@ -26,10 +26,6 @@ class Features::PuppetServer < ForemanMaintain::Feature
26
26
  find_package('puppetserver') ? [system_service('puppetserver', 30)] : []
27
27
  end
28
28
 
29
- def puppet_version
30
- version(execute!("#{puppet_path} --version"))
31
- end
32
-
33
29
  def find_empty_cacert_request_files
34
30
  cmd_output = execute!("find #{cacert_requests_directory} -type f -size 0 | paste -d, -s")
35
31
  cmd_output.split(',')
@@ -14,8 +14,7 @@ module Procedures::Pulpcore
14
14
 
15
15
  feature(:service).handle_services(spinner, 'start', :only => necessary_services)
16
16
 
17
- spinner.update('Adding image metadata to pulp. You can continue using the ' \
18
- 'system normally while the task runs in the background.')
17
+ spinner.update('Adding image metadata to pulp.')
19
18
  execute!(pulpcore_manager('container-handle-image-data'))
20
19
  end
21
20
  end
@@ -8,8 +8,7 @@ module Procedures::Repositories
8
8
  end
9
9
 
10
10
  def run
11
- with_spinner(('Adding image metadata. You can continue using the ' \
12
- 'system normally while the task runs in the background.')) do
11
+ with_spinner('Adding image metadata to Katello.') do
13
12
  execute!('foreman-rake katello:import_container_manifest_labels')
14
13
  end
15
14
  end
@@ -16,11 +16,12 @@ module ForemanMaintain
16
16
  end
17
17
 
18
18
  def deb_postgresql_versions
19
- installed_pkgs = package_manager.list_installed_packages('${binary:Package}\n')
20
- @deb_postgresql_versions ||= installed_pkgs.grep(/^postgresql-\d+$/).map do |name|
21
- name.split('-').last
19
+ @deb_postgresql_versions ||= begin
20
+ installed_pkgs = package_manager.list_installed_packages('${binary:Package}\n')
21
+ installed_pkgs.grep(/^postgresql-\d+$/).map do |name|
22
+ name.split('-').last
23
+ end
22
24
  end
23
- @deb_postgresql_versions
24
25
  end
25
26
 
26
27
  def postgresql_conf
@@ -41,49 +42,47 @@ module ForemanMaintain
41
42
  raise NotImplementedError
42
43
  end
43
44
 
44
- def local?(config = configuration)
45
- ['localhost', '127.0.0.1', `hostname`.strip].include?(config['host'])
45
+ def local?
46
+ ['localhost', '127.0.0.1', `hostname`.strip].include?(configuration['host'])
46
47
  end
47
48
 
48
- def query(sql, config = configuration)
49
- parse_csv(query_csv(sql, config))
49
+ def query(sql)
50
+ parse_csv(query_csv(sql))
50
51
  end
51
52
 
52
- def query_csv(sql, config = configuration)
53
- psql(%{COPY (#{sql}) TO STDOUT WITH CSV HEADER}, config)
53
+ def query_csv(sql)
54
+ psql(%{COPY (#{sql}) TO STDOUT WITH CSV HEADER})
54
55
  end
55
56
 
56
- def psql(query, config = configuration)
57
- if ping(config)
58
- execute(psql_command(config),
59
- :stdin => query,
60
- :hidden_patterns => [config['password']])
61
- else
62
- raise_service_error
63
- end
57
+ def psql(query)
58
+ ping!
59
+
60
+ execute('psql',
61
+ :stdin => query,
62
+ :env => base_env)
64
63
  end
65
64
 
66
- def ping(config = configuration)
67
- execute?(psql_command(config),
65
+ def ping
66
+ execute?('psql',
68
67
  :stdin => 'SELECT 1 as ping',
69
- :hidden_patterns => [config['password']])
68
+ :env => base_env)
70
69
  end
71
70
 
72
- def dump_db(file, config = configuration)
73
- execute!(dump_command(config) + " > #{file}", :hidden_patterns => [config['password']])
71
+ def dump_db(file)
72
+ dump_command = "pg_dump -Fc -f #{file}"
73
+ execute!(dump_command, :env => base_env)
74
74
  end
75
75
 
76
- def restore_dump(file, localdb, config = configuration)
76
+ def restore_dump(file, localdb)
77
77
  if localdb
78
78
  dump_cmd = "runuser - postgres -c 'pg_restore -C -d postgres #{file}'"
79
79
  execute!(dump_cmd)
80
80
  else
81
81
  # TODO: figure out how to completely ignore errors. Currently this
82
82
  # sometimes exits with 1 even though errors are ignored by pg_restore
83
- dump_cmd = base_command(config, 'pg_restore') +
84
- ' --no-privileges --clean --disable-triggers -n public ' \
85
- "-d #{config['database']} #{file}"
86
- execute!(dump_cmd, :hidden_patterns => [config['password']],
83
+ dump_cmd = 'pg_restore --no-privileges --clean --disable-triggers -n public ' \
84
+ "-d #{configuration['database']} #{file}"
85
+ execute!(dump_cmd, :env => base_env,
87
86
  :valid_exit_statuses => [0, 1])
88
87
  end
89
88
  end
@@ -109,11 +108,11 @@ module ForemanMaintain
109
108
  @backup_dir ||= File.expand_path(ForemanMaintain.config.db_backup_dir)
110
109
  end
111
110
 
112
- def dropdb(config = configuration)
111
+ def dropdb
113
112
  if local?
114
- execute!("runuser - postgres -c 'dropdb #{config['database']}'")
113
+ execute!("runuser - postgres -c 'dropdb #{configuration['database']}'")
115
114
  else
116
- delete_statement = psql(<<-SQL)
115
+ delete_statement = psql(<<~SQL)
117
116
  select string_agg('drop table if exists \"' || tablename || '\" cascade;', '')
118
117
  from pg_tables
119
118
  where schemaname = 'public';
@@ -122,15 +121,13 @@ module ForemanMaintain
122
121
  end
123
122
  end
124
123
 
125
- def db_version(config = configuration)
126
- if ping(config)
127
- # Note - t removes headers, -A removes alignment whitespace
128
- server_version_cmd = psql_command(config) + ' -c "SHOW server_version" -t -A'
129
- version_string = execute!(server_version_cmd, :hidden_patterns => [config['password']])
130
- version(version_string)
131
- else
132
- raise_service_error
133
- end
124
+ def db_version
125
+ ping!
126
+
127
+ query = 'SHOW server_version'
128
+ server_version_cmd = 'psql --tuples-only --no-align'
129
+ version_string = execute!(server_version_cmd, :stdin => query, :env => base_env)
130
+ version(version_string)
134
131
  end
135
132
 
136
133
  def psql_cmd_available?
@@ -145,22 +142,20 @@ module ForemanMaintain
145
142
 
146
143
  private
147
144
 
148
- def base_command(config, command = 'psql')
149
- "PGPASSWORD='#{config[%(password)]}' "\
150
- "#{command} -h #{config['host'] || 'localhost'} "\
151
- " -p #{config['port'] || '5432'} -U #{config['username']}"
145
+ def base_env
146
+ {
147
+ 'PGHOST' => configuration.fetch('host', 'localhost'),
148
+ 'PGPORT' => configuration['port']&.to_s,
149
+ 'PGUSER' => configuration['username'],
150
+ 'PGPASSWORD' => configuration['password'],
151
+ 'PGDATABASE' => configuration['database'],
152
+ }
152
153
  end
153
154
 
154
- def psql_command(config)
155
- base_command(config, 'psql') + " -d #{config['database']}"
156
- end
157
-
158
- def dump_command(config)
159
- base_command(config, 'pg_dump') + " -Fc #{config['database']}"
160
- end
161
-
162
- def raise_service_error
163
- raise Error::Fail, 'Please check whether database service is up & running state.'
155
+ def ping!
156
+ unless ping
157
+ raise Error::Fail, 'Please check whether database service is up & running state.'
158
+ end
164
159
  end
165
160
  end
166
161
  end
@@ -137,7 +137,6 @@ module ForemanMaintain
137
137
  @reporter.before_scenario_starts(scenario)
138
138
  @reporter.puts <<~MESSAGE
139
139
  Skipping #{skipped_phase} phase as it was already run before.
140
- To enforce to run the phase, use `upgrade run --phase #{skipped_phase}`
141
140
  MESSAGE
142
141
  @reporter.after_scenario_finishes(scenario)
143
142
  end
@@ -67,18 +67,15 @@ module ForemanMaintain
67
67
  end
68
68
 
69
69
  def valid_fpc_backup?
70
- fpc_online_backup? || fpc_standard_backup? || fpc_logical_backup? || \
71
- fpc_hybrid_db_backup?
70
+ fpc_online_backup? || fpc_standard_backup?
72
71
  end
73
72
 
74
73
  def valid_katello_backup?
75
- katello_online_backup? || katello_standard_backup? || katello_logical_backup? || \
76
- # Katello can have setup where some of dbs are external but not all
77
- katello_hybrid_db_backup?
74
+ katello_online_backup? || katello_standard_backup?
78
75
  end
79
76
 
80
77
  def valid_foreman_backup?
81
- foreman_standard_backup? || foreman_online_backup? || foreman_logical_backup?
78
+ foreman_standard_backup? || foreman_online_backup?
82
79
  end
83
80
 
84
81
  def check_file_existence(existence_map)
@@ -111,19 +108,6 @@ module ForemanMaintain
111
108
  :absent => absent)
112
109
  end
113
110
 
114
- def katello_logical_backup?
115
- present = [:pgsql_data, :candlepin_dump, :foreman_dump, :pulpcore_dump]
116
- absent = []
117
- check_file_existence(:present => present,
118
- :absent => absent)
119
- end
120
-
121
- def katello_hybrid_db_backup?
122
- all_dbs = { :pgsql_data => %w[candlepin foreman pulpcore] }
123
- present, absent = dumps_for_hybrid_db_setup(all_dbs)
124
- check_file_existence(:present => present, :absent => absent)
125
- end
126
-
127
111
  def fpc_standard_backup?
128
112
  present = [:pgsql_data]
129
113
  absent = [:candlepin_dump, :foreman_dump, :pulpcore_dump]
@@ -137,19 +121,6 @@ module ForemanMaintain
137
121
  check_file_existence(:present => present, :absent => absent)
138
122
  end
139
123
 
140
- def fpc_logical_backup?
141
- present = [:pulpcore_dump, :pgsql_data]
142
- absent = [:candlepin_dump, :foreman_dump]
143
- check_file_existence(:present => present, :absent => absent)
144
- end
145
-
146
- def fpc_hybrid_db_backup?
147
- all_dbs = { :pgsql_data => ['pulpcore'] }
148
- present, absent = dumps_for_hybrid_db_setup(all_dbs)
149
- absent.concat [:candlepin_dump, :foreman_dump]
150
- check_file_existence(:present => present, :absent => absent)
151
- end
152
-
153
124
  def foreman_standard_backup?
154
125
  check_file_existence(:present => [:pgsql_data],
155
126
  :absent => [:candlepin_dump, :foreman_dump, :pulpcore_dump])
@@ -160,30 +131,6 @@ module ForemanMaintain
160
131
  :absent => [:candlepin_dump, :pgsql_data, :pulpcore_dump])
161
132
  end
162
133
 
163
- def foreman_logical_backup?
164
- check_file_existence(:present => [:pgsql_data, :foreman_dump],
165
- :absent => [:candlepin_dump, :pulpcore_dump])
166
- end
167
-
168
- def dumps_for_hybrid_db_setup(dbs_hash)
169
- present = []
170
- absent = []
171
- dbs_hash.each do |data_file, dbs|
172
- dbs.each do |db|
173
- feature_label = "#{db}_database"
174
- dump_file = "#{db}_dump"
175
- if feature(feature_label.to_sym).local?
176
- present |= [data_file]
177
- absent << dump_file.to_sym
178
- else
179
- present << dump_file.to_sym
180
- end
181
- end
182
- absent |= [data_file] unless present.include?(data_file)
183
- end
184
- [present, absent]
185
- end
186
-
187
134
  def validate_hostname?
188
135
  # make sure that the system hostname is the same as the backup
189
136
  metadata.fetch('hostname', nil) == hostname
@@ -8,26 +8,27 @@ module ForemanMaintain
8
8
  attr_reader :logger, :command
9
9
 
10
10
  def initialize(logger, command, options)
11
- options.validate_options!(:stdin, :hidden_patterns, :interactive, :valid_exit_statuses)
11
+ options.validate_options!(:stdin, :interactive, :valid_exit_statuses, :env)
12
12
  options[:valid_exit_statuses] ||= [0]
13
+ options[:env] ||= {}
13
14
  @logger = logger
14
15
  @command = command
15
16
  @stdin = options[:stdin]
16
- @hidden_patterns = Array(options[:hidden_patterns]).compact
17
17
  @interactive = options[:interactive]
18
18
  @options = options
19
19
  @valid_exit_statuses = options[:valid_exit_statuses]
20
+ @env = options[:env]
20
21
  raise ArgumentError, 'Can not pass stdin for interactive command' if @interactive && @stdin
21
22
  end
22
23
 
23
24
  def run
24
- logger&.debug(hide_strings("Running command #{@command} with stdin #{@stdin.inspect}"))
25
+ logger&.debug("Running command #{@command} with stdin #{@stdin.inspect}")
25
26
  if @interactive
26
27
  run_interactively
27
28
  else
28
29
  run_non_interactively
29
30
  end
30
- logger&.debug("output of the command:\n #{hide_strings(output)}")
31
+ logger&.debug("output of the command:\n #{output}")
31
32
  end
32
33
 
33
34
  def interactive?
@@ -49,10 +50,10 @@ module ForemanMaintain
49
50
  end
50
51
 
51
52
  def execution_error
52
- raise Error::ExecutionError.new(hide_strings(@command),
53
+ raise Error::ExecutionError.new(@command,
53
54
  exit_status,
54
- hide_strings(@stdin),
55
- @interactive ? nil : hide_strings(@output))
55
+ @stdin,
56
+ @interactive ? nil : @output)
56
57
  end
57
58
 
58
59
  private
@@ -81,7 +82,7 @@ module ForemanMaintain
81
82
  end
82
83
 
83
84
  def run_non_interactively
84
- IO.popen(full_command, 'r+') do |f|
85
+ IO.popen(@env, full_command, 'r+') do |f|
85
86
  if @stdin
86
87
  f.puts(@stdin)
87
88
  f.close_write
@@ -94,13 +95,6 @@ module ForemanMaintain
94
95
  def full_command
95
96
  "#{@command} 2>&1"
96
97
  end
97
-
98
- def hide_strings(string)
99
- return unless string
100
- @hidden_patterns.reduce(string) do |result, hidden_pattern|
101
- result.gsub(hidden_pattern, '[FILTERED]')
102
- end
103
- end
104
98
  end
105
99
  end
106
100
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.8.0'.freeze
2
+ VERSION = '1.8.2'.freeze
3
3
  end
@@ -181,20 +181,22 @@ module ForemanMaintain
181
181
 
182
182
  def perform_self_upgrade
183
183
  package_name, command = pkg_and_cmd_name
184
+ packages_to_update = [package_name, main_package_name].uniq
185
+ packages_to_update_str = packages_to_update.join(', ')
184
186
 
185
- puts "Checking for new version of #{package_name}..."
187
+ puts "Checking for new version of #{packages_to_update_str}..."
186
188
 
187
189
  enable_maintenance_module
188
190
  package_manager = ForemanMaintain.package_manager
189
191
 
190
- if package_manager.update_available?(main_package_name)
191
- puts "\nUpdating #{package_name} package."
192
- package_manager.update(main_package_name, :assumeyes => true)
193
- puts "\nThe #{package_name} package successfully updated."\
192
+ if package_manager.update_available?(packages_to_update)
193
+ puts "\nUpdating #{packages_to_update_str}."
194
+ package_manager.update(packages_to_update, :assumeyes => true)
195
+ puts "\nSuccessfully updated #{packages_to_update_str}."\
194
196
  "\nRe-run #{command} with required options!"
195
197
  exit 75
196
198
  end
197
- puts "Nothing to update, can't find new version of #{package_name}."
199
+ puts "Nothing to update, can't find new version of #{packages_to_update_str}."
198
200
  end
199
201
 
200
202
  def enable_maintenance_module
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.0
4
+ version: 1.8.2
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: 2024-10-10 00:00:00.000000000 Z
11
+ date: 2024-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -142,7 +142,6 @@ email: inecas@redhat.com
142
142
  executables:
143
143
  - foreman-maintain
144
144
  - foreman-maintain-complete
145
- - foreman-maintain-rotate-tar
146
145
  extensions: []
147
146
  extra_rdoc_files:
148
147
  - LICENSE
@@ -410,7 +409,7 @@ homepage: https://github.com/theforeman/foreman_maintain
410
409
  licenses:
411
410
  - GPL-3.0
412
411
  metadata: {}
413
- post_install_message:
412
+ post_install_message:
414
413
  rdoc_options: []
415
414
  require_paths:
416
415
  - lib
@@ -429,7 +428,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
429
428
  version: '0'
430
429
  requirements: []
431
430
  rubygems_version: 3.3.27
432
- signing_key:
431
+ signing_key:
433
432
  specification_version: 4
434
433
  summary: Foreman maintenance tool belt
435
434
  test_files: []