foreman_maintain 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. checksums.yaml +5 -5
  2. data/definitions/checks/pulpcore/db_up.rb +29 -0
  3. data/definitions/features/foreman_database.rb +5 -3
  4. data/definitions/features/foreman_tasks.rb +7 -2
  5. data/definitions/features/instance.rb +5 -2
  6. data/definitions/features/{pulp3.rb → pulpcore.rb} +9 -3
  7. data/definitions/features/pulpcore_database.rb +39 -0
  8. data/definitions/features/tar.rb +5 -0
  9. data/definitions/procedures/backup/offline/pulpcore_db.rb +57 -0
  10. data/definitions/procedures/backup/online/pulpcore_db.rb +20 -0
  11. data/definitions/procedures/backup/snapshot/logical_volume_confirmation.rb +1 -0
  12. data/definitions/procedures/backup/snapshot/mount_pulpcore_db.rb +48 -0
  13. data/definitions/procedures/content/prepare.rb +1 -1
  14. data/definitions/procedures/content/switchover.rb +18 -0
  15. data/definitions/procedures/packages/installer_confirmation.rb +1 -1
  16. data/definitions/procedures/packages/update_all_confirmation.rb +24 -0
  17. data/definitions/procedures/pulpcore/migrate.rb +25 -0
  18. data/definitions/procedures/restore/drop_databases.rb +11 -1
  19. data/definitions/procedures/restore/extract_files.rb +1 -0
  20. data/definitions/procedures/restore/pulpcore_dump.rb +30 -0
  21. data/definitions/scenarios/backup.rb +18 -3
  22. data/definitions/scenarios/packages.rb +7 -3
  23. data/definitions/scenarios/restore.rb +7 -1
  24. data/extras/foreman_protector/foreman-protector.py +1 -1
  25. data/lib/foreman_maintain/cli/packages_command.rb +1 -1
  26. data/lib/foreman_maintain/concerns/base_database.rb +5 -1
  27. data/lib/foreman_maintain/reporter/cli_reporter.rb +3 -3
  28. data/lib/foreman_maintain/utils/backup.rb +58 -62
  29. data/lib/foreman_maintain/utils/disk/io_device.rb +1 -1
  30. data/lib/foreman_maintain/version.rb +1 -1
  31. metadata +173 -165
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9cf2de71b1fd3ab00b7305e517b1529428af64ef
4
- data.tar.gz: 5fe408d0a49b4e196c27d81cf9e732fd994358a2
2
+ SHA256:
3
+ metadata.gz: a4e65df7ebef0968a8e42c0d8bcc643b46dfb2855dd2d7c89124004370b63e15
4
+ data.tar.gz: 6f18c7e5ed3415ecf1bfe1e75bc13bb437aab40a95d06493e531a5d500d99d95
5
5
  SHA512:
6
- metadata.gz: 2588c117972fcc18c28fd503b945a9f00313906df3ac225af45ccb0a973e406d31bddd191d84937e3778718fae7e9a45cb7c2b57c812815a65f8922d29b0519b
7
- data.tar.gz: 8973ea5b1105d668c3e493cb49e68c95e01bccb298f6fa7c2fa702dd629b781d460aca39a72a8a20d5e6e68e8c92adb6dd3e2678e960f1d976d9d23fcfd6708c
6
+ metadata.gz: c51b1f7d04a9df33f4c5b0e82c3df17f51162942eee4a4df61a2fe8930f8118d03b35c0f21de56a208662dee0b259e980a9552785d3f83bb6fd60f7422f5e943
7
+ data.tar.gz: 81e2b0db0d04283cc4ec49b778dc7fdb783ef0b462f826230713fa77a2c6425f54f93283706f4c24886d9d0c4e195dc39f403b0707e83ff5a7df673788b89c54
@@ -0,0 +1,29 @@
1
+ module Checks
2
+ module Pulpcore
3
+ class DBUp < ForemanMaintain::Check
4
+ metadata do
5
+ description 'Make sure Pulpcore DB is up'
6
+ label :pulpcore_db_up
7
+ for_feature :pulpcore_database
8
+ end
9
+
10
+ def run
11
+ status = false
12
+ with_spinner('Checking connection to the Pulpcore DB') do
13
+ status = feature(:pulpcore_database).ping
14
+ end
15
+ assert(status, 'Pulpcore DB is not responding. ' \
16
+ 'It needs to be up and running to perform the following steps',
17
+ :next_steps => next_steps)
18
+ end
19
+
20
+ def next_steps
21
+ if feature(:pulpcore_database).local?
22
+ [Procedures::Service::Start.new(:only => 'postgresql')]
23
+ else
24
+ [] # there is nothing we can do for remote db
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -16,9 +16,11 @@ class Features::ForemanDatabase < ForemanMaintain::Feature
16
16
  end
17
17
 
18
18
  def config_files
19
- [
20
- '/var/lib/pgsql/data/postgresql.conf'
21
- ]
19
+ if check_min_version('foreman', '2.0')
20
+ ['/var/opt/rh/rh-postgresql12/lib/pgsql/data/postgresql.conf']
21
+ else
22
+ ['/var/lib/pgsql/data/postgresql.conf']
23
+ end
22
24
  end
23
25
 
24
26
  def services
@@ -162,8 +162,13 @@ class Features::ForemanTasks < ForemanMaintain::Feature
162
162
  def export_csv(sql, file_name, state)
163
163
  dir = prepare_for_backup(state)
164
164
  filepath = "#{dir}/#{file_name}"
165
- execute("echo \"COPY (#{sql}) TO STDOUT WITH CSV;\" \
166
- | su - postgres -c '/usr/bin/psql -d foreman' | bzip2 -9 > #{filepath}.bz2")
165
+ csv_output = feature(:foreman_database).query_csv(sql)
166
+ File.open(filepath, 'w') do |f|
167
+ f.write(csv_output)
168
+ f.close
169
+ end
170
+ execute("bzip2 #{filepath} -c -9 > #{filepath}.bz2")
171
+ FileUtils.rm_rf(filepath)
167
172
  end
168
173
 
169
174
  def old_tasks_condition(state = "'stopped', 'paused'")
@@ -37,7 +37,9 @@ class Features::Instance < ForemanMaintain::Feature
37
37
  end
38
38
 
39
39
  def postgresql_local?
40
- database_local?(:candlepin_database) || database_local?(:foreman_database)
40
+ database_local?(:candlepin_database) ||
41
+ database_local?(:foreman_database) ||
42
+ database_local?(:pulpcore_database)
41
43
  end
42
44
 
43
45
  def foreman_proxy_with_content?
@@ -65,7 +67,7 @@ class Features::Instance < ForemanMaintain::Feature
65
67
  end
66
68
 
67
69
  def pulp
68
- feature(:pulp2) || feature(:pulp3)
70
+ feature(:pulp2) || feature(:pulpcore)
69
71
  end
70
72
 
71
73
  private
@@ -143,6 +145,7 @@ class Features::Instance < ForemanMaintain::Feature
143
145
  'candlepin' => %w[candlepin candlepin_database],
144
146
  'pulp_auth' => %w[pulp2 mongo],
145
147
  'pulp' => %w[pulp2 mongo],
148
+ 'pulpcore' => %w[pulpcore pulpcore_database],
146
149
  'foreman_tasks' => %w[foreman_tasks]
147
150
  }
148
151
  end
@@ -1,8 +1,8 @@
1
1
  require 'foreman_maintain/utils/service/systemd'
2
2
 
3
- class Features::Pulp3 < ForemanMaintain::Feature
3
+ class Features::Pulpcore < ForemanMaintain::Feature
4
4
  metadata do
5
- label :pulp3
5
+ label :pulpcore
6
6
 
7
7
  confine do
8
8
  ForemanMaintain::Utils::Service::Systemd.new('pulpcore-api', 0).exist?
@@ -11,12 +11,18 @@ class Features::Pulp3 < ForemanMaintain::Feature
11
11
 
12
12
  def services
13
13
  [
14
+ system_service('rh-redis5-redis', 5),
14
15
  system_service('pulpcore-api', 10),
15
16
  system_service('pulpcore-content', 10),
16
17
  system_service('pulpcore-resource-manager', 10),
17
18
  system_service('pulpcore-worker@*', 20, :all => true, :skip_enablement => true),
18
- system_service('rh-redis5-redis', 30),
19
19
  system_service('httpd', 30)
20
20
  ]
21
21
  end
22
+
23
+ def config_files
24
+ [
25
+ '/etc/pulp/settings.py'
26
+ ]
27
+ end
22
28
  end
@@ -0,0 +1,39 @@
1
+ class Features::PulpcoreDatabase < ForemanMaintain::Feature
2
+ PULPCORE_DB_CONFIG = '/etc/pulp/settings.py'.freeze
3
+
4
+ include ForemanMaintain::Concerns::BaseDatabase
5
+
6
+ metadata do
7
+ label :pulpcore_database
8
+
9
+ confine do
10
+ file_nonzero?(PULPCORE_DB_CONFIG)
11
+ end
12
+ end
13
+
14
+ def configuration
15
+ @configuration || load_configuration
16
+ end
17
+
18
+ def services
19
+ [
20
+ system_service('postgresql', 10, :component => 'pulpcore',
21
+ :db_feature => feature(:pulpcore_database))
22
+ ]
23
+ end
24
+
25
+ private
26
+
27
+ def load_configuration
28
+ full_config = File.read(PULPCORE_DB_CONFIG).split(/[\s,'":]/).reject(&:empty?)
29
+
30
+ @configuration = {}
31
+ @configuration['adapter'] = 'postgresql'
32
+ @configuration['host'] = full_config[full_config.index('HOST') + 1]
33
+ @configuration['port'] = full_config[full_config.index('PORT') + 1]
34
+ @configuration['database'] = full_config[full_config.index('NAME') + 1]
35
+ @configuration['username'] = full_config[full_config.index('USER') + 1]
36
+ @configuration['password'] = full_config[full_config.index('PASSWORD') + 1]
37
+ @configuration
38
+ end
39
+ end
@@ -38,6 +38,7 @@ class Features::Tar < ForemanMaintain::Feature
38
38
  # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
39
39
  def tar_command(options)
40
40
  volume_size = options.fetch(:volume_size, nil)
41
+ absolute_names = options.fetch(:absolute_names, nil)
41
42
  validate_volume_size(volume_size) unless volume_size.nil?
42
43
 
43
44
  tar_command = ['tar']
@@ -45,6 +46,10 @@ class Features::Tar < ForemanMaintain::Feature
45
46
  tar_command << "--#{options.fetch(:command, 'create')}"
46
47
  tar_command << "--file=#{options.fetch(:archive)}"
47
48
 
49
+ if absolute_names
50
+ tar_command << '--absolute-names'
51
+ end
52
+
48
53
  if volume_size
49
54
  split_tar_script = default_split_tar_script
50
55
  tar_command << "--tape-length=#{volume_size}"
@@ -0,0 +1,57 @@
1
+ module Procedures::Backup
2
+ module Offline
3
+ class PulpcoreDB < ForemanMaintain::Procedure
4
+ metadata do
5
+ description 'Backup Pulpcore DB offline'
6
+ tags :backup
7
+ label :backup_offline_pulpcore_db
8
+ for_feature :pulpcore_database
9
+ preparation_steps { Checks::Pulpcore::DBUp.new unless feature(:pulpcore_database).local? }
10
+ param :backup_dir, 'Directory where to backup to', :required => true
11
+ param :tar_volume_size, 'Size of tar volume (indicates splitting)'
12
+ param :mount_dir, 'Snapshot mount directory'
13
+ end
14
+
15
+ def run
16
+ if feature(:pulpcore_database).local?
17
+ if File.exist?(pg_backup_file)
18
+ puts 'Already done'
19
+ else
20
+ local_backup
21
+ end
22
+ else
23
+ puts "Backup of #{pg_data_dir} is not supported for remote databases." \
24
+ ' Doing postgres dump instead...'
25
+ with_spinner('Getting Pulpcore DB dump') do
26
+ feature(:pulpcore_database).dump_db(File.join(@backup_dir, 'pulpcore.dump'))
27
+ end
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ def local_backup
34
+ with_spinner("Collecting data from #{pg_data_dir}") do
35
+ feature(:pulpcore_database).backup_local(
36
+ pg_backup_file,
37
+ :listed_incremental => File.join(@backup_dir, '.postgres.snar'),
38
+ :volume_size => @tar_volume_size,
39
+ :data_dir => pg_data_dir
40
+ )
41
+ end
42
+ end
43
+
44
+ def pg_backup_file
45
+ File.join(@backup_dir, 'pgsql_data.tar')
46
+ end
47
+
48
+ def pg_data_dir
49
+ return feature(:pulpcore_database).data_dir if @mount_dir.nil?
50
+ mount_point = File.join(@mount_dir, 'pgsql')
51
+ dir = feature(:pulpcore_database).find_base_directory(mount_point)
52
+ fail!("Snapshot of Pulpcore DB was not found mounted in #{mount_point}") if dir.nil?
53
+ dir
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,20 @@
1
+ module Procedures::Backup
2
+ module Online
3
+ class PulpcoreDB < ForemanMaintain::Procedure
4
+ metadata do
5
+ description 'Backup Pulpcore database online'
6
+ tags :backup
7
+ label :backup_online_pulpcore_db
8
+ for_feature :pulpcore_database
9
+ preparation_steps { Checks::Pulpcore::DBUp.new }
10
+ param :backup_dir, 'Directory where to backup to', :required => true
11
+ end
12
+
13
+ def run
14
+ with_spinner('Getting Pulpcore DB dump') do
15
+ feature(:pulpcore_database).dump_db(File.join(@backup_dir, 'pulpcore.dump'))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -16,6 +16,7 @@ module Procedures::Backup
16
16
  dbs[:mongo] = 'Mongo' if db_local?(:mongo)
17
17
  dbs[:candlepin_database] = 'Candlepin' if db_local?(:candlepin_database)
18
18
  dbs[:foreman_database] = 'Foreman' if db_local?(:foreman_database)
19
+ dbs[:pulpcore_database] = 'Pulpcore' if db_local?(:pulpcore_database)
19
20
 
20
21
  shared_lv = dbs.inject([]) do |list, (db_label, db_name)|
21
22
  db_lv = get_lv_info(feature(db_label).data_dir)
@@ -0,0 +1,48 @@
1
+ require 'procedures/backup/snapshot/mount_base'
2
+ module Procedures::Backup
3
+ module Snapshot
4
+ class MountPulpcoreDB < MountBase
5
+ metadata do
6
+ description 'Create and mount snapshot of Pulpcore DB'
7
+ tags :backup
8
+ label :backup_snapshot_mount_pulpcore_db
9
+ for_feature :pulpcore_database
10
+ preparation_steps { Checks::Pulpcore::DBUp.new unless feature(:pulpcore_database).local? }
11
+ MountBase.common_params(self)
12
+ param :backup_dir, 'Directory where to backup to'
13
+ end
14
+
15
+ def run
16
+ if feature(:pulpcore_database).local?
17
+ snapshot
18
+ else
19
+ dump_pulpcore
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def dump_pulpcore
26
+ puts 'LV snapshots are not supported for remote databases. Doing postgres dump instead... '
27
+ with_spinner('Getting Pulpcore DB dump') do
28
+ feature(:pulpcore_database).dump_db(File.join(@backup_dir, 'pulpcore.dump'))
29
+ end
30
+ end
31
+
32
+ def snapshot
33
+ mount_point = mount_location('pgsql')
34
+ FileUtils.mkdir_p(mount_point) unless File.directory?(mount_point)
35
+ if directory_empty?(mount_point)
36
+ with_spinner('Creating snapshot of Postgres') do |spinner|
37
+ lv_info = get_lv_info(feature(:pulpcore_database).data_dir)
38
+ create_lv_snapshot('pgsql-snap', @block_size, lv_info[0])
39
+ spinner.update("Mounting snapshot of Postgres on #{mount_point}")
40
+ mount_snapshot('pgsql', lv_info[1])
41
+ end
42
+ else
43
+ puts 'Snapshot of Postgres is already mounted'
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -2,7 +2,7 @@ module Procedures::Content
2
2
  class Prepare < ForemanMaintain::Procedure
3
3
  metadata do
4
4
  description 'Prepare content for Pulp 3'
5
- for_feature :pulp3
5
+ for_feature :pulpcore
6
6
  end
7
7
 
8
8
  def run
@@ -0,0 +1,18 @@
1
+ module Procedures::Content
2
+ class Switchover < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'Switch support for certain content from Pulp 2 to Pulp 3'
5
+ for_feature :pulpcore
6
+ end
7
+
8
+ def run
9
+ execute!('foreman-rake katello:pulp3_migration')
10
+ execute!('foreman-rake katello:pulp3_post_migration_check')
11
+ execute!('foreman-rake katello:pulp3_content_switchover')
12
+ args = ['--foreman-proxy-content-proxy-pulp-isos-to-pulpcore=true',
13
+ '--katello-use-pulp-2-for-file=false',
14
+ '--katello-use-pulp-2-for-docker=false']
15
+ feature(:installer).run(args.join(' '))
16
+ end
17
+ end
18
+ end
@@ -5,7 +5,7 @@ module Procedures::Packages
5
5
  end
6
6
 
7
7
  def run
8
- question = "WARNING: This script runs #{feature(:installer).installer_command} " \
8
+ question = "\nWARNING: This script runs #{feature(:installer).installer_command} " \
9
9
  "after the yum execution \n" \
10
10
  "to ensure the #{feature(:instance).product_name} " \
11
11
  "is in a consistent state.\n" \
@@ -0,0 +1,24 @@
1
+ module Procedures::Packages
2
+ class UpdateAllConfirmation < ForemanMaintain::Procedure
3
+ metadata do
4
+ param :packages, 'List of packages to update', :array => true
5
+
6
+ description 'Confirm update all is intentional'
7
+ end
8
+
9
+ def run
10
+ if @packages.nil? || @packages.empty?
11
+ question = "\nWARNING: No specific packages to update were provided\n" \
12
+ "so we are going to update all available packages.\n" \
13
+ "It is recommended to update everything only as part of upgrade\n" \
14
+ "of the #{feature(:instance).product_name} to the next version. \n" \
15
+ "To Upgrade to next version use 'foreman-maintain upgrade'.\n\n" \
16
+ "NOTE: --assumeyes is not applicable for this check\n\n" \
17
+ "Do you want to proceed with update of everything regardless\n" \
18
+ 'of the recommendations?'
19
+ answer = ask_decision(question, 'y(yes), q(quit)', ignore_assumeyes: true)
20
+ abort! unless answer == :yes
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ module Procedures::Pulpcore
2
+ class Migrate < ForemanMaintain::Procedure
3
+ include ForemanMaintain::Concerns::SystemService
4
+
5
+ metadata do
6
+ description 'Migrate pulpcore db'
7
+ for_feature :pulpcore
8
+ end
9
+
10
+ def run
11
+ with_spinner('Migrating pulpcore') do |spinner|
12
+ necessary_services = feature(:pulpcore_database).services
13
+ pulp_services = feature(:pulpcore).services
14
+
15
+ feature(:service).handle_services(spinner, 'start', :only => necessary_services)
16
+ feature(:service).handle_services(spinner, 'stop', :only => pulp_services)
17
+
18
+ spinner.update('Migrating pulpcore database')
19
+ execute!('sudo PULP_SETTINGS=/etc/pulp/settings.py '\
20
+ 'DJANGO_SETTINGS_MODULE=pulpcore.app.settings '\
21
+ 'python3-django-admin migrate --noinput')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -8,7 +8,7 @@ module Procedures::Restore
8
8
  :required => true
9
9
 
10
10
  confine do
11
- feature(:foreman_database) || feature(:candlepin_database)
11
+ feature(:foreman_database) || feature(:candlepin_database) || feature(:pulpcore_database)
12
12
  end
13
13
  end
14
14
 
@@ -19,6 +19,9 @@ module Procedures::Restore
19
19
  feature(:service).handle_services(spinner, 'start', :only => ['postgresql'])
20
20
  drop_foreman(backup, spinner)
21
21
  drop_candlepin(backup, spinner)
22
+ if feature(:pulpcore)
23
+ drop_pulpcore(backup, spinner)
24
+ end
22
25
  end
23
26
  end
24
27
 
@@ -35,5 +38,12 @@ module Procedures::Restore
35
38
  feature(:candlepin_database).dropdb
36
39
  end
37
40
  end
41
+
42
+ def drop_pulpcore(backup, spinner)
43
+ if backup.file_map[:pulpcore_dump][:present]
44
+ spinner.update('Dropping pulpcore database')
45
+ feature(:pulpcore_database).dropdb
46
+ end
47
+ end
38
48
  end
39
49
  end