foreman_maintain 0.7.10 → 0.7.14

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: c02c6edfe990d37bd485aa0cb9831bab961b03e002314d1c860c676fb21916c2
4
- data.tar.gz: 8762d61ebb0ef9d842f4dc32ffaf7344c909bd4c686486f0ffe7a30e8a4ae7a4
3
+ metadata.gz: f85f48176164ae330cdc34b3358f7a28e9db102b0a4a1a3f56096545914a80d7
4
+ data.tar.gz: 218abc9daddc63f1ea18f4a652fe7c0ab29471d1ba57025b6fe4bfec1ef517ee
5
5
  SHA512:
6
- metadata.gz: 2dac90b49cb5e868c3cbcaef102a7b7a472ea141ab228fbbfdb7b1fbc1687509f8842b984b5b90992a42dc2afdc4d07c48aa2b699ed912c1fb7232b49d3d00a8
7
- data.tar.gz: 183cc48e2535b8f569954bdc96e5328c0ef8ed595458244091912cbecf757a86507759b3470c2a8fb3ea0fab442bed79e62fc4bdb94f909191d1824c454a82d1
6
+ metadata.gz: 6298d9c15def6a3e6f3fca79c1a917c583f4af0bc0281559abdc96e82f15820975ad109d9443bbb412da8396a5df7b3b94a6a7a00cd28fce2b3af6cb5d97eaa0
7
+ data.tar.gz: e572a81b1e74edc22985ef67e8e9d9e84af85161bb78105d32617962a90ddf016447e77a17cd7299254819e9987304709f991a65a2c4b4b59a95081c5c7c2490
@@ -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
@@ -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,
@@ -3,11 +3,13 @@ module Procedures::Content
3
3
  metadata do
4
4
  description 'Prepare content for Pulp 3'
5
5
  for_feature :pulpcore
6
+ param :quiet, 'Keep the output on a single line', :flag => true, :default => false
6
7
  end
7
8
 
8
9
  def run
9
10
  # use interactive to get realtime output
10
- puts execute!('foreman-rake katello:pulp3_migration', :interactive => true)
11
+ env_vars = @quiet ? '' : 'preserve_output=true '
12
+ puts execute!("#{env_vars}foreman-rake katello:pulp3_migration", :interactive => true)
11
13
  end
12
14
  end
13
15
  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
@@ -2,11 +2,10 @@ module ForemanMaintain::Scenarios
2
2
  module Content
3
3
  class ContentBase < ForemanMaintain::Scenario
4
4
  def enable_and_start_services
5
- add_step(Procedures::Service::Start)
6
5
  add_step(Procedures::Service::Enable.
7
6
  new(:only => Features::Pulpcore.pulpcore_migration_services))
8
7
  add_step(Procedures::Service::Start.
9
- new(:only => Features::Pulpcore.pulpcore_migration_services))
8
+ new(:include => Features::Pulpcore.pulpcore_migration_services))
10
9
  end
11
10
 
12
11
  def disable_and_stop_services
@@ -27,12 +26,18 @@ module ForemanMaintain::Scenarios
27
26
  def compose
28
27
  if feature(:satellite) && feature(:satellite).at_least_version?('6.9')
29
28
  enable_and_start_services
30
- add_step(Procedures::Content::Prepare)
29
+ add_step(Procedures::Content::Prepare.new(quiet: quiet?))
31
30
  disable_and_stop_services
32
31
  elsif !feature(:satellite)
33
- add_step(Procedures::Content::Prepare)
32
+ add_step(Procedures::Content::Prepare.new(quiet: quiet?))
34
33
  end
35
34
  end
35
+
36
+ private
37
+
38
+ def quiet?
39
+ !!context.get(:quiet)
40
+ end
36
41
  end
37
42
 
38
43
  class Switchover < ContentBase
@@ -60,6 +65,7 @@ module ForemanMaintain::Scenarios
60
65
 
61
66
  def compose
62
67
  if !feature(:satellite) || feature(:satellite).at_least_version?('6.9')
68
+ enable_and_start_services if feature(:satellite)
63
69
  add_step(Procedures::Content::PrepareAbort)
64
70
  end
65
71
  end
@@ -97,6 +103,24 @@ module ForemanMaintain::Scenarios
97
103
  end
98
104
  end
99
105
 
106
+ class CleanupRepositoryMetadata < ContentBase
107
+ metadata do
108
+ label :cleanup_repository_metadata
109
+ description 'Remove old leftover repository metadata'
110
+ param :remove_files, 'Actually remove the files? Otherwise a dryrun is performed.'
111
+
112
+ manual_detection
113
+ end
114
+
115
+ def compose
116
+ add_step_with_context(Procedures::Pulp::CleanupOldMetadataFiles)
117
+ end
118
+
119
+ def set_context_mapping
120
+ context.map(:remove_files, Procedures::Pulp::CleanupOldMetadataFiles => :remove_files)
121
+ end
122
+ end
123
+
100
124
  class RemovePulp2 < ContentBase
101
125
  metadata do
102
126
  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
@@ -2,8 +2,9 @@ module ForemanMaintain
2
2
  module Cli
3
3
  class ContentCommand < Base
4
4
  subcommand 'prepare', 'Prepare content for Pulp 3' do
5
+ option ['-q', '--quiet'], :flag, 'Keep the output on a single line'
5
6
  def execute
6
- run_scenarios_and_exit(Scenarios::Content::Prepare.new)
7
+ run_scenarios_and_exit(Scenarios::Content::Prepare.new(:quiet => quiet?))
7
8
  end
8
9
  end
9
10
 
@@ -34,6 +35,17 @@ module ForemanMaintain
34
35
  end
35
36
  end
36
37
 
38
+ subcommand 'cleanup-repository-metadata', 'Cleanup old repository metadata under Pulp 2' do
39
+ option ['-r', '--remove-files'], :flag, 'Remove the files instead of just listing them.',
40
+ :attribute_name => :remove_files
41
+
42
+ def execute
43
+ run_scenarios_and_exit(
44
+ Scenarios::Content::CleanupRepositoryMetadata.new(:remove_files => @remove_files)
45
+ )
46
+ end
47
+ end
48
+
37
49
  subcommand 'remove-pulp2', 'Remove pulp2 and mongodb packages and data' do
38
50
  def execute
39
51
  run_scenarios_and_exit(Scenarios::Content::RemovePulp2.new)
@@ -59,12 +59,15 @@ module ForemanMaintain
59
59
 
60
60
  private
61
61
 
62
+ # rubocop:disable Metrics/MethodLength
62
63
  def run_interactively
63
64
  # use tmp files to capture output and exit status of the command when
64
65
  # running interactively
65
66
  log_file = Tempfile.open('captured-output')
66
67
  exit_file = Tempfile.open('captured-exit-code')
67
- Kernel.system("script -qc '#{full_command}; echo $? > #{exit_file.path}' #{log_file.path}")
68
+ Kernel.system(
69
+ "bash -c '#{full_command}; echo $? > #{exit_file.path}' | tee -i #{log_file.path}"
70
+ )
68
71
  File.open(log_file.path) { |f| @output = f.read }
69
72
  File.open(exit_file.path) do |f|
70
73
  exit_status = f.read.strip
@@ -78,6 +81,7 @@ module ForemanMaintain
78
81
  log_file.close
79
82
  exit_file.close
80
83
  end
84
+ # rubocop:enable Metrics/MethodLength
81
85
 
82
86
  def run_non_interactively
83
87
  IO.popen(full_command, 'r+') do |f|
@@ -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.10'.freeze
2
+ VERSION = '0.7.14'.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.10
4
+ version: 0.7.14
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-06-07 00:00:00.000000000 Z
11
+ date: 2021-09-27 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