foreman_maintain 1.2.6 → 1.2.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 193b1e7cefdc871725692b84d03636fab11dcf6a0de8928c7c8ff05179b8ddd8
4
- data.tar.gz: afdf239a676685fa3b793e78389d989029f6dd29ec806bb1cef4ee72a91c37fe
3
+ metadata.gz: e83e212f9fbf31738c939454ad7978b9d29beb66b66cbfb5d905e2a15aebe1af
4
+ data.tar.gz: b09528f68095f1139ab66e1dbdb7587e79b1c7d5e135626f94e60f7abb17e393
5
5
  SHA512:
6
- metadata.gz: d2305610529e5ff51dc325daaaeee9da689259a0c1aeec88d155c8315d83da7551d0c00b8c5098439986602b039ae85bae3346dc679db184dc08bd856610b3d4
7
- data.tar.gz: f0fdf10df80d8a26552c1f74aed56d944b1324ef06fe8960c92aa9d8411cae211f24ff596d60c8a1fff2bae450901c40e9b478889fe118432323fb748ee07d6c
6
+ metadata.gz: 69809841cb9ede602ae08a7c3c57b777be895aa80795ecc6293961f5411ae3fd5872b7f1eb5f0ad8c06e33a0ee594897e1d08413866ecfbf34daf941db07a742
7
+ data.tar.gz: 00cd8080285c9e9a2809de32bb500585c641fdd740dd23895ee02f8767540be97cf36d1c34790a25bbfbc20071b782124a30ea185dd16dd62d8f83b8d6e3208b
@@ -3,33 +3,11 @@ class Features::SyncPlans < ForemanMaintain::Feature
3
3
  label :sync_plans
4
4
  end
5
5
 
6
- def required_new_implementation
7
- @required_new_implementation ||=
8
- feature(:foreman_database).query(
9
- <<-SQL
10
- SELECT COUNT(1) FROM information_schema.table_constraints
11
- WHERE constraint_name='katello_sync_plan_foreman_tasks_recurring_logic_fk' AND table_name='katello_sync_plans'
12
- SQL
13
- ).first['count'].to_i > 0
14
- end
15
-
16
- def sync_plan_ids_by_status(enabled = true, filter_ids = nil)
17
- if filter_ids
18
- return [] if filter_ids.empty?
19
-
20
- ids_condition = filter_ids.map { |id| "'#{id}'" }.join(',')
21
- end
22
-
23
- if required_new_implementation
24
- query = <<-SQL
25
- select sp.id as id from katello_sync_plans sp inner join foreman_tasks_recurring_logics rl on sp.foreman_tasks_recurring_logic_id = rl.id
26
- where rl.state='#{enabled ? 'active' : 'disabled'}' #{ids_condition ? " AND sp.id IN (#{ids_condition})" : ''}
27
- SQL
28
- else
29
- query = <<-SQL
30
- SELECT id FROM katello_sync_plans WHERE enabled ='#{enabled ? 't' : 'f'}' #{ids_condition ? " AND id IN (#{ids_condition})" : ''}
31
- SQL
32
- end
6
+ def sync_plan_ids_by_status(enabled = true)
7
+ query = <<-SQL
8
+ select sp.id as id from katello_sync_plans sp inner join foreman_tasks_recurring_logics rl on sp.foreman_tasks_recurring_logic_id = rl.id
9
+ where rl.state='#{enabled ? 'active' : 'disabled'}'
10
+ SQL
33
11
  feature(:foreman_database).query(query).map { |r| r['id'].to_i }
34
12
  end
35
13
 
@@ -41,14 +19,17 @@ class Features::SyncPlans < ForemanMaintain::Feature
41
19
  feature(:foreman_database).query(query).map { |r| r['id'].to_i }
42
20
  end
43
21
 
44
- def make_disable(ids)
45
- update_records(ids, false)
22
+ def make_disable
23
+ cleanup_enabled_in_storage
24
+ update_records(sync_plan_ids_by_status(true), false)
25
+ @data[:disabled]
46
26
  end
47
27
 
48
28
  def make_enable
49
29
  # remove ids of sync plans which no longer exist in DB
50
30
  @data[:disabled] = validate_sync_plan_ids(@data[:disabled])
51
31
  update_records(@data[:disabled], true)
32
+ @data[:enabled]
52
33
  end
53
34
 
54
35
  def load_from_storage(storage)
@@ -80,11 +61,8 @@ class Features::SyncPlans < ForemanMaintain::Feature
80
61
  private
81
62
 
82
63
  def update_records(ids, enabled)
83
- ids_not_required_update = sync_plan_ids_by_status(enabled, ids)
84
- ids_required_update = ids - ids_not_required_update
85
- make_data_key_empty(enabled) if !ids_not_required_update.empty? && ids_required_update.empty?
86
64
  updated_record_ids = []
87
- ids_required_update.each do |sp_id|
65
+ ids.each do |sp_id|
88
66
  result = feature(:hammer).run("sync-plan update --id #{sp_id} --enabled #{enabled}")
89
67
  if result.include?('Sync plan updated')
90
68
  updated_record_ids << sp_id
@@ -92,29 +70,29 @@ class Features::SyncPlans < ForemanMaintain::Feature
92
70
  raise result
93
71
  end
94
72
  end
95
- updated_record_ids
96
73
  ensure
97
74
  update_data(enabled, updated_record_ids)
98
75
  end
99
76
 
100
77
  def data
101
78
  raise 'Use load_from_storage before accessing the data' unless defined? @data
102
-
103
79
  @data
104
80
  end
105
81
 
106
- def make_data_key_empty(enabled)
107
- key_name = enabled ? 'disabled' : 'enabled'
108
- @data[:"#{key_name}"] = []
82
+ def cleanup_enabled_in_storage
83
+ @data[:enabled] = []
109
84
  end
110
85
 
111
86
  def update_data(enabled, new_ids)
87
+ # init data
88
+ @data[:disabled] = [] unless @data[:disabled]
89
+ @data[:enabled] = [] unless @data[:enabled]
90
+
112
91
  if enabled
113
92
  @data[:disabled] -= new_ids
114
- @data[:enabled] = new_ids
93
+ @data[:enabled].concat(new_ids).uniq!
115
94
  else
116
- @data[:disabled] = [] unless @data[:disabled]
117
- @data[:enabled] = [] if @data[:disabled].empty?
95
+ @data[:enabled] -= new_ids
118
96
  @data[:disabled].concat(new_ids).uniq!
119
97
  end
120
98
  end
@@ -0,0 +1,10 @@
1
+ class Procedures::ForemanMaintainFeatures < ForemanMaintain::Procedure
2
+ metadata do
3
+ description 'List detected Foreman Maintain features'
4
+ end
5
+
6
+ def run
7
+ features = ForemanMaintain.available_features
8
+ output << features.map(&:inspect).join("\n")
9
+ end
10
+ end
@@ -21,9 +21,8 @@ module Procedures::SyncPlans
21
21
  default_storage = ForemanMaintain.storage(:default)
22
22
  feature(:sync_plans).load_from_storage(default_storage)
23
23
  with_spinner('disabling sync plans') do |spinner|
24
- ids = feature(:sync_plans).sync_plan_ids_by_status(true)
25
- feature(:sync_plans).make_disable(ids)
26
- spinner.update "Total #{ids.length} sync plans are now disabled."
24
+ record_ids = feature(:sync_plans).make_disable
25
+ spinner.update "Total #{record_ids.length} sync plans are now disabled."
27
26
  end
28
27
  ensure
29
28
  feature(:sync_plans).save_to_storage(default_storage)
@@ -58,7 +58,6 @@ module ForemanMaintain::Scenarios
58
58
  Procedures::Backup::CompressData => :backup_dir,
59
59
  Procedures::Backup::Pulp => :backup_dir,
60
60
  Procedures::Backup::Online::Mongo => :backup_dir,
61
- Procedures::Backup::Online::PgGlobalObjects => :backup_dir,
62
61
  Procedures::Backup::Online::CandlepinDB => :backup_dir,
63
62
  Procedures::Backup::Online::ForemanDB => :backup_dir,
64
63
  Procedures::Backup::Online::PulpcoreDB => :backup_dir,
@@ -160,9 +159,6 @@ module ForemanMaintain::Scenarios
160
159
  end
161
160
 
162
161
  def include_dumps
163
- if feature(:instance).postgresql_local?
164
- add_step_with_context(Procedures::Backup::Online::PgGlobalObjects)
165
- end
166
162
  if feature(:instance).database_local?(:candlepin_database)
167
163
  add_step_with_context(Procedures::Backup::Online::CandlepinDB)
168
164
  end
@@ -217,7 +213,6 @@ module ForemanMaintain::Scenarios
217
213
  add_step_with_context(Procedures::Backup::Pulp, :ensure_unchanged => true)
218
214
  add_steps_with_context(
219
215
  Procedures::Backup::Online::Mongo,
220
- Procedures::Backup::Online::PgGlobalObjects,
221
216
  Procedures::Backup::Online::CandlepinDB,
222
217
  Procedures::Backup::Online::ForemanDB,
223
218
  Procedures::Backup::Online::PulpcoreDB
@@ -73,9 +73,6 @@ module ForemanMaintain::Scenarios
73
73
  end
74
74
 
75
75
  def restore_sql_dumps(backup)
76
- if backup.file_map[:pg_globals][:present]
77
- add_steps_with_context(Procedures::Restore::PgGlobalObjects)
78
- end
79
76
  if backup.file_map[:candlepin_dump][:present]
80
77
  add_steps_with_context(Procedures::Restore::CandlepinDump)
81
78
  end
@@ -108,7 +105,6 @@ module ForemanMaintain::Scenarios
108
105
  Checks::Restore::ValidateInterfaces => :backup_dir,
109
106
  Procedures::Restore::Configs => :backup_dir,
110
107
  Procedures::Restore::DropDatabases => :backup_dir,
111
- Procedures::Restore::PgGlobalObjects => :backup_dir,
112
108
  Procedures::Restore::CandlepinDump => :backup_dir,
113
109
  Procedures::Restore::ForemanDump => :backup_dir,
114
110
  Procedures::Restore::PulpcoreDump => :backup_dir,
@@ -69,6 +69,8 @@ module ForemanMaintain::Scenarios
69
69
  end
70
70
 
71
71
  def downstream_self_upgrade(pkgs_to_update)
72
+ ForemanMaintain.enable_maintenance_module
73
+
72
74
  if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
73
75
  yum_options = req_repos_to_update_pkgs.map do |id|
74
76
  "--enablerepo=#{id}"
@@ -106,7 +108,7 @@ module ForemanMaintain::Scenarios
106
108
  end
107
109
 
108
110
  def compose
109
- pkgs_to_update = %w[rubygem-foreman_maintain]
111
+ pkgs_to_update = [ForemanMaintain.main_package_name]
110
112
  if feature(:instance).downstream
111
113
  pkgs_to_update << 'satellite-maintain'
112
114
  downstream_self_upgrade(pkgs_to_update)
@@ -108,11 +108,6 @@ module ForemanMaintain
108
108
  end
109
109
  end
110
110
 
111
- def restore_pg_globals(pg_globals, config = configuration)
112
- execute!(base_command(config, 'psql') + " -f #{pg_globals} postgres 2>/dev/null",
113
- :hidden_patterns => [config['password']])
114
- end
115
-
116
111
  def backup_local(backup_file, extra_tar_options = {})
117
112
  dir = extra_tar_options.fetch(:data_dir, data_dir)
118
113
  command = extra_tar_options.fetch(:command, 'create')
@@ -139,10 +134,6 @@ module ForemanMaintain
139
134
  @backup_dir ||= File.expand_path(ForemanMaintain.config.db_backup_dir)
140
135
  end
141
136
 
142
- def backup_global_objects(file)
143
- execute!("runuser - postgres -c 'pg_dumpall -g > #{file}'")
144
- end
145
-
146
137
  def perform_backup(config = configuration)
147
138
  file_path = backup_file_path(config)
148
139
  backup_cmd = backup_db_command(file_path, config)
@@ -30,7 +30,7 @@ module ForemanMaintain
30
30
  end
31
31
 
32
32
  def systemd_installed?
33
- File.exist?('/usr/bin/systemctl')
33
+ File.exist?('/run/systemd/system/')
34
34
  end
35
35
 
36
36
  def check_min_version(name, minimal_version)
@@ -9,6 +9,24 @@ module ForemanMaintain::PackageManager
9
9
  true
10
10
  end
11
11
 
12
+ def module_enabled?(name)
13
+ _status, result = info(name)
14
+ result.match?(/Stream.+\[e\].+/)
15
+ end
16
+
17
+ def enable_module(name)
18
+ dnf_action('module enable', name, assumeyes: true)
19
+ end
20
+
21
+ def module_exists?(name)
22
+ status, _result = info(name)
23
+ status == 0
24
+ end
25
+
26
+ def info(name)
27
+ dnf_action('module info', name, with_status: true, assumeyes: true)
28
+ end
29
+
12
30
  private
13
31
 
14
32
  def dnf_action(action, packages, with_status: false, assumeyes: false)
@@ -42,7 +42,6 @@ module ForemanMaintain
42
42
  :candlepin_dump => map_file(@backup_dir, 'candlepin.dump'),
43
43
  :mongo_dump => map_file(@backup_dir, 'mongo_dump'),
44
44
  :config_files => map_file(@backup_dir, 'config_files.tar.gz'),
45
- :pg_globals => map_file(@backup_dir, 'pg_globals.dump'),
46
45
  :metadata => map_file(@backup_dir, 'metadata.yml'),
47
46
  :pulpcore_dump => map_file(@backup_dir, 'pulpcore.dump')
48
47
  }
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.2.6'.freeze
2
+ VERSION = '1.2.8'.freeze
3
3
  end
@@ -178,6 +178,9 @@ module ForemanMaintain
178
178
  package_name, command = pkg_and_cmd_name
179
179
 
180
180
  puts "Checking for new version of #{package_name}..."
181
+
182
+ enable_maintenance_module
183
+
181
184
  if ForemanMaintain.package_manager.update_available?(main_package_name)
182
185
  puts "\nUpdating #{package_name} package."
183
186
  ForemanMaintain.package_manager.update(main_package_name, :assumeyes => true)
@@ -188,8 +191,21 @@ module ForemanMaintain
188
191
  puts "Nothing to update, can't find new version of #{package_name}."
189
192
  end
190
193
 
194
+ def enable_maintenance_module
195
+ return unless el? && !el7?
196
+
197
+ maintenance_module = 'satellite-maintenance:el8'
198
+ package_manager = ForemanMaintain.package_manager
199
+
200
+ if package_manager.module_exists?(maintenance_module) &&
201
+ !package_manager.module_enabled?(maintenance_module)
202
+ puts "\nEnabling #{maintenance_module} module"
203
+ package_manager.enable_module(maintenance_module)
204
+ end
205
+ end
206
+
191
207
  def main_package_name
192
- 'rubygem-foreman_maintain'
208
+ el? ? 'rubygem-foreman_maintain' : 'ruby-foreman-maintain'
193
209
  end
194
210
  end
195
211
  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: 1.2.6
4
+ version: 1.2.8
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: 2023-02-23 00:00:00.000000000 Z
11
+ date: 2023-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -241,7 +241,6 @@ files:
241
241
  - definitions/procedures/backup/online/candlepin_db.rb
242
242
  - definitions/procedures/backup/online/foreman_db.rb
243
243
  - definitions/procedures/backup/online/mongo.rb
244
- - definitions/procedures/backup/online/pg_global_objects.rb
245
244
  - definitions/procedures/backup/online/pulpcore_db.rb
246
245
  - definitions/procedures/backup/online/safety_confirmation.rb
247
246
  - definitions/procedures/backup/prepare_directory.rb
@@ -270,6 +269,7 @@ files:
270
269
  - definitions/procedures/foreman/remove_duplicate_obsolete_roles.rb
271
270
  - definitions/procedures/foreman/remove_duplicate_permissions.rb
272
271
  - definitions/procedures/foreman_docker/remove_foreman_docker.rb
272
+ - definitions/procedures/foreman_maintain_features.rb
273
273
  - definitions/procedures/foreman_openscap/invalid_report_associations.rb
274
274
  - definitions/procedures/foreman_proxy/features.rb
275
275
  - definitions/procedures/foreman_tasks/delete.rb
@@ -321,7 +321,6 @@ files:
321
321
  - definitions/procedures/restore/foreman_dump.rb
322
322
  - definitions/procedures/restore/installer_reset.rb
323
323
  - definitions/procedures/restore/mongo_dump.rb
324
- - definitions/procedures/restore/pg_global_objects.rb
325
324
  - definitions/procedures/restore/postgres_owner.rb
326
325
  - definitions/procedures/restore/pulpcore_dump.rb
327
326
  - definitions/procedures/restore/regenerate_queues.rb
@@ -1,29 +0,0 @@
1
- module Procedures::Backup
2
- module Online
3
- class PgGlobalObjects < ForemanMaintain::Procedure
4
- include ForemanMaintain::Concerns::SystemHelpers
5
-
6
- metadata do
7
- description 'Backup Postgres global objects online'
8
- tags :backup
9
- param :backup_dir, 'Directory where to backup to', :required => true
10
- confine do
11
- feature(:foreman_database) || feature(:candlepin_database)
12
- end
13
- end
14
-
15
- def run
16
- if feature(:instance).postgresql_local?
17
- local_db = if feature(:instance).database_local?(:foreman_database)
18
- :foreman_database
19
- else
20
- :candlepin_database
21
- end
22
- feature(local_db).backup_global_objects(File.join(@backup_dir, 'pg_globals.dump'))
23
- else
24
- skip 'Backup of global objects is not supported for remote databases.'
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,36 +0,0 @@
1
- module Procedures::Restore
2
- class PgGlobalObjects < ForemanMaintain::Procedure
3
- include ForemanMaintain::Concerns::SystemHelpers
4
-
5
- metadata do
6
- description 'Restore any existing postgresql global objects from backup'
7
-
8
- param :backup_dir,
9
- 'Path to backup directory',
10
- :required => true
11
-
12
- confine do
13
- feature(:foreman_database) || feature(:candlepin_database)
14
- end
15
- end
16
-
17
- def run
18
- backup = ForemanMaintain::Utils::Backup.new(@backup_dir)
19
- restore_global_objects(backup.file_map[:pg_globals][:path])
20
- end
21
-
22
- def restore_global_objects(pg_global_file)
23
- if feature(:instance).postgresql_local?
24
- with_spinner('') do |spinner|
25
- feature(:service).handle_services(spinner, 'start', :only => ['postgresql'])
26
-
27
- spinner.update('Restoring postgresql global objects')
28
- local_db = feature(:foreman_database).local? ? :foreman_database : :candlepin_database
29
- feature(local_db).restore_pg_globals(pg_global_file)
30
- end
31
- else
32
- skip 'Restore of global objects is not supported for remote databases.'
33
- end
34
- end
35
- end
36
- end