foreman_maintain 0.7.8 → 0.7.12

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: ae46ef9452f9bbb61d9f453a1d3aba399aa39aad83c8340ba2ba7129196eb6ec
4
- data.tar.gz: daae5660ce5a676c230b6ef4360e7341f3fdb5d82ce46cc53a0ac3596926ab94
3
+ metadata.gz: 58a7f9214ba787d4da524da11a36469573b52b25859ee6a1efa74502c98504a2
4
+ data.tar.gz: 8e5818b8ce279babe6a6cda10d8549ebe2c07eb5c5f651c2f8dab2b1ed6b4b93
5
5
  SHA512:
6
- metadata.gz: 62d82ea9a9d4ece0797e5872b8b0a551940864965416b23f3dfa7a7b054c68b8cd684d76f2cfd85532d6c744ab9f88942b03a8282a43aac96ae2282cb2a715ec
7
- data.tar.gz: 00f495d544d54df325d9e0541a0b206dab5fbd2a2f5930e5d17eb86173d450e92926cc41c74379fda20a878ed634c8e473abfaf440d0034ae6c0c44e50c88fe5
6
+ metadata.gz: 5b8356b678fb0335b5df23205cbc328afadc8ba33d27501d9b655301c025a4edbe4385a7ecc96d2e2ba70aecb313ce298086046a56e7053ff62b24cc8d9aaad8
7
+ data.tar.gz: 3cd2e0ca9b5a23b1e3de9f27faf2a86ee82399310786ee016e54d4f55cfbd87aab9ae250afdee9193df30254049e7edc893992362bbf5a0975128ee8345e11cc
@@ -0,0 +1,45 @@
1
+ module Checks
2
+ module Disk
3
+ class AvailableSpacePostgresql12 < ForemanMaintain::Check
4
+ metadata do
5
+ label :available_space_for_postgresql12
6
+ description 'Check to make sure PostgreSQL 12 work directory has enough space for upgrade'
7
+ confine do
8
+ (feature(:foreman_database) || feature(:candlepin_database)) && \
9
+ (file_exists?('/var/lib/pgsql') && \
10
+ file_exists?('/var/opt/rh/rh-postgresql12'))
11
+ end
12
+ end
13
+
14
+ def run
15
+ assert(psql_12_available_space >= psql_9_consumed_space, warning_message, :warn => true)
16
+ end
17
+
18
+ def pgsql_dir(version)
19
+ if version == 9
20
+ '/var/lib/pgsql/'
21
+ elsif version == 12
22
+ '/var/opt/rh/rh-postgresql12/'
23
+ end
24
+ end
25
+
26
+ def psql_9_consumed_space
27
+ io_obj = ForemanMaintain::Utils::Disk::IODevice.new(pgsql_dir(9))
28
+ io_obj.space_used
29
+ end
30
+
31
+ def psql_12_available_space
32
+ io_obj = ForemanMaintain::Utils::Disk::IODevice.new(pgsql_dir(12))
33
+ io_obj.available_space
34
+ end
35
+
36
+ def warning_message
37
+ sat_version = feature(:satellite).current_version.version[0..2]
38
+ "Satellite #{sat_version} uses PostgreSQL 12. \nThis changes PostgreSQL "\
39
+ "work directory to #{pgsql_dir(12)}\n"\
40
+ "The new work directory requires at least #{psql_9_consumed_space}"\
41
+ 'MiB free space for upgrade!'
42
+ end
43
+ end
44
+ end
45
+ end
@@ -37,6 +37,6 @@ class Features::DynflowSidekiq < ForemanMaintain::Feature
37
37
  end
38
38
 
39
39
  def configured_instances
40
- Dir['/etc/foreman/dynflow/*'].map { |config| File.basename(config, '.yml') }
40
+ Dir['/etc/foreman/dynflow/*.yml'].map { |config| File.basename(config, '.yml') }
41
41
  end
42
42
  end
@@ -34,4 +34,10 @@ class Features::Pulp < ForemanMaintain::Feature
34
34
  '/etc/default/pulp_workers'
35
35
  ]
36
36
  end
37
+
38
+ def exclude_from_backup
39
+ # Exclude /var/lib/pulp/katello-export and /var/lib/pulp/cache
40
+ # since the tar is run from /var/lib/pulp, list subdir paths only
41
+ ['katello-export', 'cache']
42
+ end
37
43
  end
@@ -25,9 +25,10 @@ class Features::Service < ForemanMaintain::Feature
25
25
  select(&:exist?)
26
26
  end
27
27
 
28
- def filtered_services(options)
28
+ def filtered_services(options, action = '')
29
29
  services = include_unregistered_services(existing_services, options[:include])
30
- services = filter_services(services, options)
30
+ services = filter_services(services, options, action)
31
+
31
32
  raise 'No services found matching your parameters' unless services.any?
32
33
  return services unless options[:reverse]
33
34
 
@@ -61,7 +62,7 @@ class Features::Service < ForemanMaintain::Feature
61
62
  def run_action_on_services(action, options, spinner)
62
63
  status = 0
63
64
  failed_services = []
64
- filtered_services(options).each_value do |group|
65
+ filtered_services(options, action).each_value do |group|
65
66
  fork_threads_for_services(action, group, spinner).each do |service, status_and_output|
66
67
  spinner.update("#{action_noun(action)} #{service}") if action == 'status'
67
68
  item_status, output = status_and_output
@@ -115,7 +116,8 @@ class Features::Service < ForemanMaintain::Feature
115
116
  service_list + socket_list
116
117
  end
117
118
 
118
- def filter_services(service_list, options)
119
+ # rubocop:disable Metrics/AbcSize
120
+ def filter_services(service_list, options, action)
119
121
  if options[:only] && options[:only].any?
120
122
  service_list = service_list.select do |service|
121
123
  options[:only].any? { |opt| service.matches?(opt) }
@@ -128,8 +130,17 @@ class Features::Service < ForemanMaintain::Feature
128
130
  end
129
131
 
130
132
  service_list = extend_service_list_with_sockets(service_list, options)
133
+ service_list = filter_disabled_services!(action, service_list)
131
134
  service_list.group_by(&:priority).to_h
132
135
  end
136
+ # rubocop:enable Metrics/AbcSize
137
+
138
+ def filter_disabled_services!(action, service_list)
139
+ if %w[start stop restart status].include?(action)
140
+ service_list.select! { |service| !service.respond_to?(:enabled?) || service.enabled? }
141
+ end
142
+ service_list
143
+ end
133
144
 
134
145
  def include_unregistered_services(service_list, services_filter)
135
146
  return service_list unless services_filter
@@ -30,7 +30,7 @@ module Procedures::Backup
30
30
  feature(:tar).run(
31
31
  :archive => File.join(@backup_dir, 'pulp_data.tar'),
32
32
  :command => 'create',
33
- :exclude => ['var/lib/pulp/katello-export'],
33
+ :exclude => feature(:pulp2).exclude_from_backup,
34
34
  :listed_incremental => File.join(@backup_dir, '.pulp.snar'),
35
35
  :transform => 's,^,var/lib/pulp/,S',
36
36
  :volume_size => @tar_volume_size,
@@ -19,8 +19,11 @@ module Procedures::Content
19
19
  puts execute!('foreman-rake katello:pulp3_content_switchover')
20
20
  puts 'Re-running the installer to switch specified content over to pulp3'
21
21
  args = ['--foreman-proxy-content-proxy-pulp-isos-to-pulpcore=true',
22
+ '--foreman-proxy-content-proxy-pulp-yum-to-pulpcore=true',
23
+ '--foreman-proxy-content-proxy-pulp-deb-to-pulpcore=true',
22
24
  '--katello-use-pulp-2-for-file=false',
23
25
  '--katello-use-pulp-2-for-docker=false',
26
+ '--katello-use-pulp-2-for-deb=false',
24
27
  '--katello-use-pulp-2-for-yum=false']
25
28
  feature(:installer).run(args.join(' '))
26
29
  end
@@ -0,0 +1,75 @@
1
+ require 'find'
2
+ require 'rexml/document'
3
+
4
+ module Procedures::Pulp
5
+ class CleanupOldMetadataFiles < ForemanMaintain::Procedure
6
+ metadata do
7
+ description 'Cleanup old and unneeded yum metadata files from /var/lib/pulp/'
8
+ confine do
9
+ check_max_version('katello-common', '4.0')
10
+ end
11
+ param :remove_files, 'If true, will actually delete files, otherwise will print them out.'
12
+ end
13
+
14
+ PULP_METADATA_DIR = '/var/lib/pulp/published/yum/master/yum_distributor/'.freeze
15
+ REPOMD_FILE = 'repomd.xml'.freeze
16
+
17
+ def run
18
+ return unless File.directory?(PULP_METADATA_DIR)
19
+ found = []
20
+
21
+ puts 'Warning: This command may cause reduced performance related to content operations.'
22
+ message = 'Locating repository metadata (this may take a while)'
23
+ with_spinner(message) do |spinner|
24
+ Find.find(PULP_METADATA_DIR) do |path|
25
+ next if File.basename(path) != REPOMD_FILE
26
+ found << path
27
+ spinner.update("#{message}: Found #{found.count} repos.")
28
+ end
29
+ end
30
+
31
+ found.each do |repo_md_path|
32
+ handle(repo_md_path, @remove_files)
33
+ end
34
+ end
35
+
36
+ def handle(repo_md_path, remove_files)
37
+ base_path = File.dirname(repo_md_path)
38
+ to_remove = list_existing_files(repo_md_path) - list_repomd_files(repo_md_path)
39
+
40
+ if to_remove.empty?
41
+ "Skipping #{base_path}, no files to remove."
42
+ elsif remove_files
43
+ puts '================================================================================'
44
+ puts "Removing #{to_remove.count} files from #{base_path}"
45
+ to_remove.each { |file| File.delete(File.join(base_path, file)) }
46
+ else
47
+ puts '================================================================================'
48
+ puts "For #{base_path} would remove, but --remove-files was not specified:"
49
+ to_remove.each { |file| puts " #{file}" }
50
+ end
51
+ end
52
+
53
+ def list_repomd_files(repo_md_path)
54
+ doc = REXML::Document.new(File.new(repo_md_path))
55
+ filenames = []
56
+ doc.root.elements.each do |data|
57
+ locations = data.elements['location']
58
+ next unless locations
59
+
60
+ if locations.attributes
61
+ filenames << locations.attributes['href']
62
+ end
63
+ end
64
+ base_names(filenames.flatten)
65
+ end
66
+
67
+ def list_existing_files(repo_md_path)
68
+ base_names(Dir[File.dirname(repo_md_path) + '/*']) - [REPOMD_FILE]
69
+ end
70
+
71
+ def base_names(file_list)
72
+ file_list.map { |file| File.basename(file) }
73
+ end
74
+ end
75
+ end
@@ -16,7 +16,7 @@ module Procedures
16
16
  def run_service_action(action, options)
17
17
  action_noun = feature(:service).action_noun(action).capitalize
18
18
  puts "\n#{action_noun} the following service(s):"
19
- services = feature(:service).filtered_services(options)
19
+ services = feature(:service).filtered_services(options, action)
20
20
  print_services(services)
21
21
  with_spinner('') do |spinner|
22
22
  feature(:service).handle_services(spinner, action, options)
@@ -97,6 +97,24 @@ module ForemanMaintain::Scenarios
97
97
  end
98
98
  end
99
99
 
100
+ class CleanupRepositoryMetadata < ContentBase
101
+ metadata do
102
+ label :cleanup_repository_metadata
103
+ description 'Remove old leftover repository metadata'
104
+ param :remove_files, 'Actually remove the files? Otherwise a dryrun is performed.'
105
+
106
+ manual_detection
107
+ end
108
+
109
+ def compose
110
+ add_step_with_context(Procedures::Pulp::CleanupOldMetadataFiles)
111
+ end
112
+
113
+ def set_context_mapping
114
+ context.map(:remove_files, Procedures::Pulp::CleanupOldMetadataFiles => :remove_files)
115
+ end
116
+ end
117
+
100
118
  class RemovePulp2 < ContentBase
101
119
  metadata do
102
120
  label :content_remove_pulp2
@@ -28,6 +28,7 @@ module Scenarios::Satellite_6_8
28
28
  add_steps(find_checks(:default))
29
29
  add_steps(find_checks(:pre_upgrade))
30
30
  add_step(Checks::Foreman::CheckpointSegments)
31
+ add_step(Checks::Disk::AvailableSpacePostgresql12)
31
32
  add_step(Checks::Repositories::Validate.new(:version => '6.8'))
32
33
  end
33
34
  end
@@ -28,6 +28,7 @@ module Scenarios::Satellite_6_9
28
28
  add_steps(find_checks(:default))
29
29
  add_steps(find_checks(:pre_upgrade))
30
30
  add_step(Checks::Foreman::CheckpointSegments)
31
+ add_step(Checks::Disk::AvailableSpacePostgresql12)
31
32
  add_step(Checks::Repositories::Validate.new(:version => '6.9'))
32
33
  end
33
34
  end
@@ -34,6 +34,17 @@ module ForemanMaintain
34
34
  end
35
35
  end
36
36
 
37
+ subcommand 'cleanup-repository-metadata', 'Cleanup old repository metadata under Pulp 2' do
38
+ option ['-r', '--remove-files'], :flag, 'Remove the files instead of just listing them.',
39
+ :attribute_name => :remove_files
40
+
41
+ def execute
42
+ run_scenarios_and_exit(
43
+ Scenarios::Content::CleanupRepositoryMetadata.new(:remove_files => @remove_files)
44
+ )
45
+ end
46
+ end
47
+
37
48
  subcommand 'remove-pulp2', 'Remove pulp2 and mongodb packages and data' do
38
49
  def execute
39
50
  run_scenarios_and_exit(Scenarios::Content::RemovePulp2.new)
@@ -15,6 +15,7 @@ module ForemanMaintain
15
15
  @reporter = reporter
16
16
  @scenarios = Array(scenarios)
17
17
  @quit = false
18
+ @rescue = false
18
19
  @last_scenario = nil
19
20
  @last_scenario_continuation_confirmed = false
20
21
  @exit_code = 0
@@ -29,12 +30,17 @@ module ForemanMaintain
29
30
  @assumeyes
30
31
  end
31
32
 
33
+ def rescue?
34
+ @rescue
35
+ end
36
+
32
37
  def run
33
38
  @scenarios.each do |scenario|
34
39
  run_scenario(scenario)
35
40
  next unless @quit
36
41
 
37
42
  if @rescue_scenario
43
+ @rescue = true
38
44
  logger.debug('=== Rescue scenario found. Executing ===')
39
45
  execute_scenario_steps(@rescue_scenario, true)
40
46
  end
@@ -44,10 +50,10 @@ module ForemanMaintain
44
50
 
45
51
  def run_scenario(scenario)
46
52
  return if scenario.steps.empty?
47
- raise 'The runner is already in quit state' if quit?
53
+ raise 'The runner is already in quit state' if quit? && !rescue?
48
54
 
49
55
  confirm_scenario(scenario)
50
- return if quit?
56
+ return if quit? && !rescue?
51
57
 
52
58
  execute_scenario_steps(scenario)
53
59
  ensure
@@ -26,6 +26,10 @@ module ForemanMaintain
26
26
  execute!("df #{dir}|awk {'print $5'}|tail -1").to_i
27
27
  end
28
28
 
29
+ def space_used
30
+ convert_kb_to_mb(execute!("du -ks #{dir} | awk {'print $1'}").to_i)
31
+ end
32
+
29
33
  private
30
34
 
31
35
  # In fio command, --direct option bypass the cache page
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.7.8'.freeze
2
+ VERSION = '0.7.12'.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: 0.7.8
4
+ version: 0.7.12
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: 2021-03-22 00:00:00.000000000 Z
11
+ date: 2021-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -126,6 +126,7 @@ files:
126
126
  - definitions/checks/check_tmout.rb
127
127
  - definitions/checks/disk/available_space.rb
128
128
  - definitions/checks/disk/available_space_candlepin.rb
129
+ - definitions/checks/disk/available_space_postgresql12.rb
129
130
  - definitions/checks/disk/performance.rb
130
131
  - definitions/checks/env_proxy.rb
131
132
  - definitions/checks/foreman/check_checkpoint_segments.rb
@@ -259,6 +260,7 @@ files:
259
260
  - definitions/procedures/packages/update_all_confirmation.rb
260
261
  - definitions/procedures/passenger_recycler.rb
261
262
  - definitions/procedures/prep_6_10_upgrade.rb
263
+ - definitions/procedures/pulp/cleanup_old_metadata_files.rb
262
264
  - definitions/procedures/pulp/migrate.rb
263
265
  - definitions/procedures/pulp/remove.rb
264
266
  - definitions/procedures/pulpcore/migrate.rb
@@ -403,7 +405,7 @@ homepage: https://github.com/theforeman/foreman_maintain
403
405
  licenses:
404
406
  - GPL-3.0
405
407
  metadata: {}
406
- post_install_message:
408
+ post_install_message:
407
409
  rdoc_options: []
408
410
  require_paths:
409
411
  - lib
@@ -418,8 +420,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
418
420
  - !ruby/object:Gem::Version
419
421
  version: '0'
420
422
  requirements: []
421
- rubygems_version: 3.2.3
422
- signing_key:
423
+ rubygems_version: 3.1.6
424
+ signing_key:
423
425
  specification_version: 4
424
426
  summary: Foreman maintenance tool belt
425
427
  test_files: []