foreman_maintain 0.7.9 → 0.7.13

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: 87bde0596489f26881bb8ee92b9cec10df4aead0e72fb3411a6dc80916949efe
4
- data.tar.gz: 0da057d0f9f7b6aaa0e5a2e0484a7adb66ed41eb09f0ef9f7fa32949640d7f92
3
+ metadata.gz: 4553337c4db35ead0b3f07871424c164b2df46bd1c8fc14937dc49768c428c29
4
+ data.tar.gz: 43aa2647efacc81fdb48b6c7aec36c791208c77cf637b1e187d8fda89b5c5053
5
5
  SHA512:
6
- metadata.gz: 76b77f3b03a65565e8cc4264ce27b9e172bfc1f84c2f9819718e359551f7906c42783e1cd2f50f3a5ad4601445274c92e8fa734c90141da993f7a6777c39d4a6
7
- data.tar.gz: 9b1dd4c293088f06b87584857123e74e17f2b7802408a0086d1889b159ef69a904af0b7eb16bc8f9f5a84bca7281d44fa30c4c9c4726853a854ea42f8f81365a
6
+ metadata.gz: 31c1e4710e552ce9fc04b66c497c86a3b1bc7cd27cf0feb025000026a5d5d148babe963f8c3090a2243c0f1f983b3bbbcd2113e3b391e84e3eb191eff5b75af2
7
+ data.tar.gz: 89158ea71347163b42ad198e978bec7990a581667049c5914c3c563216f233ae21a01d95dc52885699ed0777e449533a0657d45b045370abf5ddb07dae60bf52
@@ -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
@@ -11,13 +11,21 @@ class Features::Pulpcore < ForemanMaintain::Feature
11
11
  end
12
12
 
13
13
  def services
14
- self.class.pulpcore_common_services + [
14
+ self.class.pulpcore_common_services + configured_workers + [
15
15
  system_service('rh-redis5-redis', 5),
16
- system_service('pulpcore-worker@*', 20, :all => true, :skip_enablement => true),
17
16
  system_service('httpd', 30)
18
17
  ]
19
18
  end
20
19
 
20
+ def configured_workers
21
+ names = Dir['/etc/systemd/system/multi-user.target.wants/pulpcore-worker@*.service']
22
+ names = names.map { |f| File.basename(f) }
23
+ names.map do |name|
24
+ system_service(name, 20, :skip_enablement => true,
25
+ :instance_parent_unit => 'pulpcore-worker@')
26
+ end
27
+ end
28
+
21
29
  def self.pulpcore_migration_services
22
30
  pulpcore_common_services + [
23
31
  ForemanMaintain::Utils.system_service('pulpcore-worker@1', 20),
@@ -137,7 +137,7 @@ class Features::Service < ForemanMaintain::Feature
137
137
 
138
138
  def filter_disabled_services!(action, service_list)
139
139
  if %w[start stop restart status].include?(action)
140
- service_list.select!(&:enabled?)
140
+ service_list.select! { |service| !service.respond_to?(:enabled?) || service.enabled? }
141
141
  end
142
142
  service_list
143
143
  end
@@ -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,
@@ -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
@@ -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.9'.freeze
2
+ VERSION = '0.7.13'.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.9
4
+ version: 0.7.13
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: 2021-03-25 00:00:00.000000000 Z
11
+ date: 2021-08-30 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