foreman_maintain 1.0.12 → 1.0.15

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: 40bec791581fb8e2670586e331afd5e89ba1ca436b38d95e848837fc8ce1fdd3
4
- data.tar.gz: 54f35bb8139e221173ca57786c93e36559957116577907fa936d0ff3f4256858
3
+ metadata.gz: 67560267151a5d6834a062b2bf14d776149cc6137cab2e260d96057ee61b6ef5
4
+ data.tar.gz: 7246d6a07958e7426f21f1094be8f2d84b7da1fcbc7422183770060c599c46a2
5
5
  SHA512:
6
- metadata.gz: 2e00f5941e44f62e5fa09d47924fa231af050cf32ae555a775bdb247753c0b38d1a2b3c554e86d3699287f1a4367a461f780be6fca5c897031feffbf07de9f53
7
- data.tar.gz: 80447d1b43a06edcdd7d9846637c4f484f8bd454e9bdda303355223f64671fa276e37e1c0c8bf50aff1c6213ed30d23028c850b31e1e9f3463b1660994109902
6
+ metadata.gz: 32034709e2b49b1ab049be1e934540dccb77440bfc01206149fc47da13bf3ab6d1a422105ea92c2cce74bc05e378774b480c80190f300abf5508b28573020c7b
7
+ data.tar.gz: 10c21481d5fcc501acd7b3e12b75195c1b52591c6b39bf4d66dda2503e723170201e72b7fa87851d4f6eb8cb14e2a455ec043ab0e425707e225482dd6d4f5316
@@ -6,12 +6,14 @@ module Procedures::Packages
6
6
  param :force, 'Do not skip if package is installed', :flag => true, :default => false
7
7
  param :warn_on_errors, 'Do not interrupt scenario on failure',
8
8
  :flag => true, :default => false
9
+ param :yum_options, 'Extra yum options if any', :array => true, :default => []
9
10
  end
10
11
 
11
12
  def run
12
13
  assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
13
14
  package_manager.clean_cache(:assumeyes => assumeyes_val)
14
- packages_action(:update, @packages, :assumeyes => assumeyes_val)
15
+ opts = { :assumeyes => assumeyes_val, :yum_options => @yum_options }
16
+ packages_action(:update, @packages, opts)
15
17
  rescue ForemanMaintain::Error::ExecutionError => e
16
18
  if @warn_on_errors
17
19
  set_status(:warning, e.message)
@@ -24,7 +24,15 @@ module Procedures::Pulp
24
24
  '/var/lib/pulp/uploads',
25
25
  '/var/lib/mongodb/',
26
26
  '/var/cache/pulp'
27
- ]
27
+ ].select { |dir| File.directory?(dir) }
28
+ end
29
+
30
+ def pulp_data_dirs_mountpoints
31
+ pulp_data_dirs.select { |d| Pathname(d).mountpoint? }
32
+ end
33
+
34
+ def deletable_pulp_dirs
35
+ @deletable_pulp_dirs ||= pulp_data_dirs - pulp_data_dirs_mountpoints
28
36
  end
29
37
 
30
38
  # rubocop:disable Metrics/MethodLength
@@ -53,11 +61,12 @@ module Procedures::Pulp
53
61
  @installed_pulp_packages
54
62
  end
55
63
 
56
- def data_dir_removal_cmds
57
- pulp_data_dirs.select { |dir| File.directory?(dir) }.map { |dir| "rm -rf #{dir}" }
64
+ def data_dir_removal_cmds(pulp_dirs)
65
+ pulp_dirs.map { |dir| "rm -rf #{dir}" }
58
66
  end
59
67
 
60
- def ask_to_proceed(rm_cmds)
68
+ def ask_to_proceed
69
+ rm_cmds = data_dir_removal_cmds(pulp_data_dirs)
61
70
  question = "\nWARNING: All pulp2 packages will be removed with the following commands:\n"
62
71
  question += "\n# rpm -e #{pulp_packages.join(' ')}" if pulp_packages.any?
63
72
  question += "\n# yum remove rh-mongodb34-*"
@@ -70,11 +79,9 @@ module Procedures::Pulp
70
79
  end
71
80
 
72
81
  def run
73
- rm_cmds = data_dir_removal_cmds
74
-
75
82
  assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
76
83
 
77
- ask_to_proceed(rm_cmds) unless assumeyes_val
84
+ ask_to_proceed unless assumeyes_val
78
85
 
79
86
  remove_pulp if pulp_packages.any?
80
87
 
@@ -86,7 +93,7 @@ module Procedures::Pulp
86
93
 
87
94
  drop_migrations
88
95
 
89
- delete_pulp_data(rm_cmds) if rm_cmds.any?
96
+ delete_pulp_data
90
97
 
91
98
  restart_pulpcore_services
92
99
  end
@@ -163,12 +170,41 @@ module Procedures::Pulp
163
170
  end
164
171
  # rubocop:enable Metrics/BlockLength
165
172
 
166
- def delete_pulp_data(rm_cmds)
167
- with_spinner('Deleting pulp2 data directories') do |spinner|
168
- rm_cmds.each do |cmd|
169
- execute!(cmd)
173
+ def delete_pulp_data
174
+ non_mountpoints = data_dir_removal_cmds(deletable_pulp_dirs)
175
+ mountpoints = pulp_data_dirs_mountpoints
176
+ with_spinner('') do |spinner|
177
+ if non_mountpoints.any?
178
+ spinner.update('Deleting pulp2 data directories.')
179
+ non_mountpoints.each do |cmd|
180
+ execute!(cmd)
181
+ end
182
+ msg_for_del_non_mountpoints(mountpoints, spinner)
183
+ end
184
+ if mountpoints.any?
185
+ msg_for_del_mountpoints(mountpoints, spinner)
170
186
  end
171
- spinner.update('Done deleting pulp2 data directories')
187
+ end
188
+ end
189
+
190
+ def msg_for_del_non_mountpoints(mountpoints, spinner)
191
+ if mountpoints.empty?
192
+ spinner.update('Done deleting all pulp2 data directories.')
193
+ else
194
+ spinner.update("Deleted: #{deletable_pulp_dirs.join("\n")}")
195
+ end
196
+ end
197
+
198
+ def msg_for_del_mountpoints(mountpoints, spinner)
199
+ _, cmd_name = ForemanMaintain.pkg_and_cmd_name
200
+ if mountpoints.count > 1
201
+ spinner.update("The directories #{mountpoints.join(',')} are individual mountpoints.")
202
+ puts "\nThe #{cmd_name} won't delete these directories.\n"\
203
+ 'You need to remove content and these directories on your own.'
204
+ else
205
+ spinner.update("The directory #{mountpoints.join(',')} is individual mountpoint.")
206
+ puts "\nThe #{cmd_name} won't delete the directory.\n"\
207
+ 'You need to remove content and the directory on your own.'
172
208
  end
173
209
  end
174
210
 
@@ -1,18 +1,6 @@
1
1
  module ForemanMaintain::Scenarios
2
2
  class SelfUpgradeBase < ForemanMaintain::Scenario
3
3
  include ForemanMaintain::Concerns::Downstream
4
- def enabled_system_repos_id
5
- repository_manager.enabled_repos.keys
6
- end
7
-
8
- def enable_repos(repo_ids = stored_enabled_repos_ids)
9
- add_step(Procedures::Repositories::Enable.new(repos: repo_ids))
10
- end
11
-
12
- def disable_repos(repo_ids = stored_enabled_repos_ids)
13
- add_step(Procedures::Repositories::Disable.new(repos: repo_ids))
14
- end
15
-
16
4
  def target_version
17
5
  current_full_version = feature(:instance).downstream.current_version
18
6
  @target_version ||= current_full_version.bump
@@ -44,36 +32,6 @@ module ForemanMaintain::Scenarios
44
32
  end
45
33
  end
46
34
 
47
- def maintenance_repo_version
48
- return '6' if current_version == '6.10'
49
-
50
- current_version
51
- end
52
-
53
- def stored_enabled_repos_ids
54
- @stored_enabled_repos_ids ||= begin
55
- path = File.expand_path('enabled_repos.yml', ForemanMaintain.config.backup_dir)
56
- @stored_enabled_repos_ids = File.file?(path) ? YAML.load(File.read(path)) : []
57
- end
58
- end
59
-
60
- def all_maintenance_repos
61
- repo_regex = if el7?
62
- /rhel-\d-server-satellite-maintenance-\d.\d-rpms/
63
- else
64
- /satellite-maintenance-\d.\d-for-rhel-\d-x86_64-rpms/
65
- end
66
- stored_enabled_repos_ids.select { |id| !id.match(repo_regex).nil? }
67
- end
68
-
69
- def repos_ids_to_reenable
70
- repos_ids_to_reenable = stored_enabled_repos_ids - all_maintenance_repos
71
- if use_rhsm?
72
- repos_ids_to_reenable << maintenance_repo(maintenance_repo_version)
73
- end
74
- repos_ids_to_reenable
75
- end
76
-
77
35
  def use_rhsm?
78
36
  return false if maintenance_repo_label
79
37
 
@@ -100,30 +58,11 @@ module ForemanMaintain::Scenarios
100
58
  def compose
101
59
  if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
102
60
  pkgs_to_update = %w[satellite-maintain rubygem-foreman_maintain]
103
- add_step(Procedures::Repositories::BackupEnabledRepos.new)
104
- disable_repos
105
- add_step(Procedures::Repositories::Enable.new(repos: req_repos_to_update_pkgs,
106
- use_rhsm: use_rhsm?))
107
- add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true))
108
- disable_repos('*')
109
- enable_repos(repos_ids_to_reenable)
110
- end
111
- end
112
- end
113
-
114
- class SelfUpgradeRescue < SelfUpgradeBase
115
- metadata do
116
- label :rescue_self_upgrade
117
- description 'Disables all version specific maintenance repositories and,'\
118
- "\nenables the repositories which were configured prior to self upgrade"
119
- manual_detection
120
- run_strategy :fail_slow
121
- end
122
-
123
- def compose
124
- if check_min_version('foreman', '2.5') || check_min_version('foreman-proxy', '2.5')
125
- disable_repos('*')
126
- enable_repos(repos_ids_to_reenable)
61
+ yum_options = req_repos_to_update_pkgs.map do |id|
62
+ "--enablerepo=#{id}"
63
+ end
64
+ add_step(Procedures::Packages::Update.new(packages: pkgs_to_update, assumeyes: true,
65
+ yum_options: yum_options))
127
66
  end
128
67
  end
129
68
  end
@@ -40,6 +40,7 @@ module Scenarios::Capsule_6_11
40
40
  def compose
41
41
  add_steps(find_procedures(:pre_migrations))
42
42
  add_step(Procedures::Pulp::Remove.new(:assumeyes => true))
43
+ add_step(Procedures::Content::FixPulpcoreArtifactOwnership.new(:assumeyes => true))
43
44
  add_step(Procedures::Service::Stop.new)
44
45
  end
45
46
  end
@@ -39,6 +39,7 @@ module Scenarios::Capsule_6_11_z
39
39
 
40
40
  def compose
41
41
  add_steps(find_procedures(:pre_migrations))
42
+ add_step(Procedures::Content::FixPulpcoreArtifactOwnership.new(:assumeyes => true))
42
43
  add_step(Procedures::Service::Stop.new)
43
44
  end
44
45
  end
@@ -42,6 +42,7 @@ module Scenarios::Satellite_6_11
42
42
  def compose
43
43
  add_steps(find_procedures(:pre_migrations))
44
44
  add_step(Procedures::Pulp::Remove.new(:assumeyes => true))
45
+ add_step(Procedures::Content::FixPulpcoreArtifactOwnership.new(:assumeyes => true))
45
46
  add_step(Procedures::Service::Stop.new)
46
47
  end
47
48
  end
@@ -39,6 +39,7 @@ module Scenarios::Satellite_6_11_z
39
39
 
40
40
  def compose
41
41
  add_steps(find_procedures(:pre_migrations))
42
+ add_step(Procedures::Content::FixPulpcoreArtifactOwnership.new(:assumeyes => true))
42
43
  add_step(Procedures::Service::Stop.new)
43
44
  end
44
45
  end
@@ -5,7 +5,7 @@ module ForemanMaintain
5
5
  'Repository label from which packages should be updated.'\
6
6
  'This can be used when standard CDN repositories are unavailable.'
7
7
  def execute
8
- run_scenario(upgrade_scenario, upgrade_rescue_scenario)
8
+ run_scenario(upgrade_scenario)
9
9
  end
10
10
 
11
11
  def upgrade_scenario
@@ -13,12 +13,6 @@ module ForemanMaintain
13
13
  maintenance_repo_label: maintenance_repo_label
14
14
  )
15
15
  end
16
-
17
- def upgrade_rescue_scenario
18
- Scenarios::SelfUpgradeRescue.new(
19
- maintenance_repo_label: maintenance_repo_label
20
- )
21
- end
22
16
  end
23
17
  end
24
18
  end
@@ -100,12 +100,13 @@ module ForemanMaintain
100
100
  end
101
101
 
102
102
  def packages_action(action, packages, options = {})
103
- options.validate_options!(:assumeyes)
103
+ options.validate_options!(:assumeyes, :yum_options)
104
104
  case action
105
105
  when :install
106
106
  package_manager.install(packages, :assumeyes => options[:assumeyes])
107
107
  when :update
108
- package_manager.update(packages, :assumeyes => options[:assumeyes])
108
+ package_manager.update(packages, :assumeyes => options[:assumeyes],
109
+ :yum_options => options[:yum_options])
109
110
  when :remove
110
111
  package_manager.remove(packages, :assumeyes => options[:assumeyes])
111
112
  else
@@ -55,8 +55,8 @@ module ForemanMaintain::PackageManager
55
55
  yum_action('remove', packages, :assumeyes => assumeyes)
56
56
  end
57
57
 
58
- def update(packages = [], assumeyes: false)
59
- yum_action('update', packages, :assumeyes => assumeyes)
58
+ def update(packages = [], assumeyes: false, yum_options: [])
59
+ yum_action('update', packages, :assumeyes => assumeyes, :yum_options => yum_options)
60
60
  end
61
61
 
62
62
  def clean_cache(assumeyes: false)
@@ -116,8 +116,12 @@ module ForemanMaintain::PackageManager
116
116
  File.open(protector_config_file, 'w') { |file| file.puts config }
117
117
  end
118
118
 
119
- def yum_action(action, packages, with_status: false, assumeyes: false, valid_exit_statuses: [0])
120
- yum_options = []
119
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
120
+ def yum_action(action, packages, options)
121
+ with_status = options.fetch(:with_status, false)
122
+ assumeyes = options.fetch(:assumeyes, false)
123
+ valid_exit_statuses = options.fetch(:valid_exit_statuses, [0])
124
+ yum_options = options.fetch(:yum_options, [])
121
125
  packages = [packages].flatten(1)
122
126
  yum_options << '-y' if assumeyes
123
127
  yum_options << '--disableplugin=foreman-protector'
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.0.12'.freeze
2
+ VERSION = '1.0.15'.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: 1.0.12
4
+ version: 1.0.15
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: 2022-06-08 00:00:00.000000000 Z
11
+ date: 2022-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp