foreman_maintain 1.0.6 → 1.0.9

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: 41c40d80a596e78552a9e066e6d769db4fe57cd9e7c7368a7d64cf21f68edefa
4
- data.tar.gz: 4908652d3cc57dde9b08081b0d5fa20fac5cc9f8ab41f19778243a29b0963002
3
+ metadata.gz: d333d2c850308e6bf590acee0dfd55d4b257cdebebb7b148e4ef49fe48f001dd
4
+ data.tar.gz: eac9b73a13ff0f7829ddf0cea8380491884d6631e3d42ca42b9b88e76bbd4698
5
5
  SHA512:
6
- metadata.gz: aa7003129978adaa2e1798c3fa191a5be628403b1d86df618bd92110829de5b8f0cd81a2f6c97b1df2befeeda693ba950acdf985c843482d2d027d333e771957
7
- data.tar.gz: 1c16a69c401058063919df5c8b8a595a4b04d17c5662f93e12b9999bfa5e566f6276b1b4a1998ffb5a3d3f964af76a8275eae68554826a22b4aef8f3ca7b81fb
6
+ metadata.gz: 8f402842dfca9d32804e9825f9a7552c2eac13e81244b80436d46b51a79e8330ce208fcf91c9bf0d5d0bafd3b46ea868916bb54e6c3b8a486273cfed2cb672d2
7
+ data.tar.gz: 20f99acb920a6a6cd1496e3b9429f635dc24275ce9bd8a70bceb44202147cc8ce9f9930de631a3e0ffac3b80c80b2526ada9ce3e88fe4b690dff0d9fa6aa101c
@@ -41,9 +41,7 @@ module Checks::PackageManager
41
41
 
42
42
  def yum_config_options
43
43
  @yum_config_options ||= {
44
- 'exclude' => '^exclude\s*=\s*\S+.*$',
45
- 'clean_requirements_on_remove' =>
46
- '^clean_requirements_on_remove\s*=\S*(1|yes|true)$'
44
+ 'exclude' => '^exclude\s*=\s*\S+.*$'
47
45
  }
48
46
  end
49
47
  end
@@ -25,12 +25,14 @@ class Features::Nftables < ForemanMaintain::Feature
25
25
  execute!("nft add chain #{family} #{table} #{chain} #{chain_options}")
26
26
  end
27
27
 
28
- def add_rule(options = {})
28
+ def add_rules(options = {})
29
29
  family = options.fetch(:family, ip_family)
30
30
  table = options.fetch(:table, table_name)
31
31
  chain = options.fetch(:chain, chain_name)
32
- rule = options.fetch(:rule) # needs validation
33
- execute!("nft add rule #{family} #{table} #{chain} #{rule}")
32
+ rules = options.fetch(:rules) # needs validation
33
+ rules.each do |rule|
34
+ execute!("nft add rule #{family} #{table} #{chain} #{rule}")
35
+ end
34
36
  end
35
37
 
36
38
  def table_exist?(name = table_name)
@@ -4,6 +4,7 @@ module Procedures::Content
4
4
  description 'Prepare content for Pulp 3'
5
5
  for_feature :pulpcore
6
6
  param :quiet, 'Keep the output on a single line', :flag => true, :default => false
7
+ do_not_whitelist
7
8
  end
8
9
 
9
10
  def run
@@ -9,6 +9,7 @@ module Procedures::Content
9
9
  end
10
10
 
11
11
  param :skip_deb, 'Do not run debian options in installer.'
12
+ do_not_whitelist
12
13
  end
13
14
 
14
15
  def run
@@ -2,7 +2,9 @@ module Procedures::Packages
2
2
  class LockVersions < ForemanMaintain::Procedure
3
3
  metadata do
4
4
  description 'Lock packages'
5
- preparation_steps { [Checks::VersionLockingEnabled.new] }
5
+ confine do
6
+ package_manager.version_locking_supported?
7
+ end
6
8
  end
7
9
 
8
10
  def run
@@ -2,7 +2,9 @@ module Procedures::Packages
2
2
  class LockingStatus < ForemanMaintain::Procedure
3
3
  metadata do
4
4
  description 'Check status of version locking of packages'
5
- preparation_steps { [Checks::VersionLockingEnabled.new] }
5
+ confine do
6
+ package_manager.version_locking_supported?
7
+ end
6
8
  end
7
9
 
8
10
  def run
@@ -2,7 +2,9 @@ module Procedures::Packages
2
2
  class UnlockVersions < ForemanMaintain::Procedure
3
3
  metadata do
4
4
  description 'Unlock packages'
5
- preparation_steps { [Checks::VersionLockingEnabled.new] }
5
+ confine do
6
+ package_manager.version_locking_supported?
7
+ end
6
8
  end
7
9
 
8
10
  def run
@@ -0,0 +1,14 @@
1
+ module Procedures::Restore
2
+ class CandlepinResetMigrations < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'Ensure Candlepin runs all migrations after restoring the database'
5
+ confine do
6
+ feature(:candlepin_database)
7
+ end
8
+ end
9
+
10
+ def run
11
+ FileUtils.rm_f('/var/lib/candlepin/.puppet-candlepin-rpm-version')
12
+ end
13
+ end
14
+ end
@@ -46,7 +46,8 @@ module ForemanMaintain::Scenarios
46
46
  end
47
47
  restore_mongo_dump(backup)
48
48
  add_steps_with_context(Procedures::Pulp::Migrate,
49
- Procedures::Pulpcore::Migrate)
49
+ Procedures::Pulpcore::Migrate,
50
+ Procedures::Restore::CandlepinResetMigrations)
50
51
 
51
52
  add_steps_with_context(Procedures::Restore::RegenerateQueues) if backup.online_backup?
52
53
  add_steps_with_context(Procedures::Service::Start,
@@ -13,15 +13,22 @@ module ForemanMaintain::Scenarios
13
13
  end
14
14
 
15
15
  def target_version
16
- @target_version ||= context.get(:target_version)
16
+ current_full_version = feature(:instance).downstream.current_version
17
+ @target_version ||= current_full_version.bump
17
18
  end
18
19
 
19
20
  def current_version
20
21
  feature(:instance).downstream.current_minor_version
21
22
  end
22
23
 
24
+ def maintenance_repo_label
25
+ @maintenance_repo_label ||= context.get(:maintenance_repo_label)
26
+ end
27
+
23
28
  def maintenance_repo_id(version)
24
- if (repo = ENV['maintenance_repo'])
29
+ if maintenance_repo_label
30
+ return maintenance_repo_label
31
+ elsif (repo = ENV['MAINTENANCE_REPO_LABEL'])
25
32
  return repo unless repo.empty?
26
33
  end
27
34
 
@@ -64,7 +71,9 @@ module ForemanMaintain::Scenarios
64
71
  end
65
72
 
66
73
  def use_rhsm?
67
- if (repo = ENV['maintenance_repo'])
74
+ return false if maintenance_repo_label
75
+
76
+ if (repo = ENV['MAINTENANCE_REPO_LABEL'])
68
77
  return false unless repo.empty?
69
78
  end
70
79
 
@@ -0,0 +1,77 @@
1
+ import dnf
2
+ import dnf.exceptions
3
+ from dnfpluginscore import _, logger
4
+
5
+ import configparser
6
+
7
+ class ForemanProtector(dnf.Plugin):
8
+ name = 'foreman-protector'
9
+ config_name = 'foreman-protector'
10
+
11
+ def __init__(self,base,cli):
12
+ self.base = base
13
+ self.cli = cli
14
+
15
+ def _get_whitelist_file_url(self):
16
+ try:
17
+ parser = self.read_config(self.base.conf)
18
+ except Exception as e:
19
+ raise dnf.exceptions.Error(_("Parsing file failed: {}").format(str(e)))
20
+
21
+ if parser.has_section('main'):
22
+ fileurl = parser.get('main', 'whitelist')
23
+ else:
24
+ raise dnf.exceptions.Error(_('Incorrect plugin configuration!'))
25
+ return fileurl
26
+
27
+ def _load_whitelist(self):
28
+ fileurl = self._get_whitelist_file_url()
29
+ package_whitelist = set()
30
+ try:
31
+ if fileurl:
32
+ llfile = open(fileurl, 'r')
33
+ for line in llfile.readlines():
34
+ if line.startswith('#') or line.strip() == '':
35
+ continue
36
+
37
+ package_whitelist.add(line.rstrip())
38
+ llfile.close()
39
+ except IOError as e:
40
+ raise dnf.exceptions.Error('Unable to read Foreman protector"s configuration: %s' % e)
41
+ return package_whitelist
42
+
43
+ def _add_obsoletes(self):
44
+ package_whitelist = self._load_whitelist()
45
+ final_query = self.base.sack.query()
46
+ if package_whitelist:
47
+ # If anything obsoletes something that we have whitelisted ... then
48
+ # whitelist that too.
49
+ whitelist_query = self.base.sack.query().filterm(name=package_whitelist)
50
+ obsoletes_query = self.base.sack.query().filterm(obsoletes=list(whitelist_query))
51
+
52
+ final_query = whitelist_query.union(obsoletes_query)
53
+ return final_query
54
+
55
+ def sack(self):
56
+ whitelist_and_obsoletes = self._add_obsoletes()
57
+ all_available_packages = self.base.sack.query().available()
58
+ excluded_pkgs_query = all_available_packages.difference(whitelist_and_obsoletes)
59
+ total = len(excluded_pkgs_query)
60
+ logger.info(_('Reading Foreman protector configuration'))
61
+ self.base.sack.add_excludes(excluded_pkgs_query)
62
+
63
+ logger.info(_('*** Excluded total: %s' % total))
64
+ if total:
65
+ if total > 1:
66
+ suffix = 's'
67
+ else:
68
+ suffix = ''
69
+ logger.info(_('\n'
70
+ 'WARNING: Excluding %d package%s due to foreman-protector. \n'
71
+ 'Use foreman-maintain packages install/update <package> \n'
72
+ 'to safely install packages without restrictions.\n'
73
+ 'Use foreman-maintain upgrade run for full upgrade.\n'
74
+ % (total, suffix)))
75
+ else:
76
+ logger.info(_('\n'
77
+ 'Nothing excluded by foreman-protector!\n'))
@@ -17,5 +17,8 @@ boost-random
17
17
  boost-iostreams
18
18
  boost-thread
19
19
  yum-utils
20
+ # el8 yum-utils dependencies
21
+ dnf-plugins-core
22
+ python3-dnf-plugins-core
20
23
  # foreman-maintain
21
24
  rubygem-foreman_maintain
@@ -1,38 +1,23 @@
1
1
  module ForemanMaintain
2
2
  module Cli
3
3
  class SelfUpgradeCommand < Base
4
- option ['--target-version'], 'TARGET_VERSION',\
5
- 'Major version of the Satellite or Capsule'\
6
- ', e.g 6.11', :required => true
4
+ option ['--maintenance-repo-label'], 'REPOSITORY_LABEL',\
5
+ 'Repository label from which packages should be updated.'\
6
+ 'This can be used when standard CDN repositories are unavailable.'
7
7
  def execute
8
- allow_major_version_upgrade_only
9
8
  run_scenario(upgrade_scenario, upgrade_rescue_scenario)
10
9
  end
11
10
 
12
11
  def upgrade_scenario
13
- Scenarios::SelfUpgrade.new(target_version: target_version)
12
+ Scenarios::SelfUpgrade.new(
13
+ maintenance_repo_label: maintenance_repo_label
14
+ )
14
15
  end
15
16
 
16
17
  def upgrade_rescue_scenario
17
- Scenarios::SelfUpgradeRescue.new(target_version: target_version)
18
- end
19
-
20
- def current_downstream_version
21
- ForemanMaintain.detector.feature(:instance).downstream.current_version
22
- end
23
-
24
- def allow_major_version_upgrade_only
25
- begin
26
- next_version = Gem::Version.new(target_version)
27
- rescue ArgumentError => err
28
- raise Error::UsageError, "Invalid version! #{err}"
29
- end
30
- if current_downstream_version >= next_version
31
- message = "The target-version #{target_version} should be "\
32
- "greater than existing version #{current_downstream_version},"\
33
- "\nand self-upgrade should be used for major version upgrades only!"
34
- raise Error::UsageError, message
35
- end
18
+ Scenarios::SelfUpgradeRescue.new(
19
+ maintenance_repo_label: maintenance_repo_label
20
+ )
36
21
  end
37
22
  end
38
23
  end
@@ -10,7 +10,7 @@ module ForemanMaintain
10
10
  unless table_exist?
11
11
  add_table
12
12
  add_chain(:chain_options => nftables_chain_options)
13
- add_rule(rule: nftables_rule)
13
+ add_rules(rules: nftables_rules)
14
14
  end
15
15
  end
16
16
 
@@ -22,8 +22,8 @@ module ForemanMaintain
22
22
  '{type filter hook input priority 0\\;}'
23
23
  end
24
24
 
25
- def nftables_rule
26
- 'tcp dport https reject'
25
+ def nftables_rules
26
+ ['iifname "lo" accept', 'tcp dport 443 reject']
27
27
  end
28
28
 
29
29
  def status_for_maintenance_mode
@@ -100,6 +100,10 @@ module ForemanMaintain
100
100
  @data[:advanced_run] = advanced_run
101
101
  end
102
102
 
103
+ def do_not_whitelist
104
+ @data[:do_not_whitelist] = true
105
+ end
106
+
103
107
  def self.eval_dsl(metadata, &block)
104
108
  new(metadata).tap do |dsl|
105
109
  dsl.instance_eval(&block)
@@ -1,13 +1,8 @@
1
1
  module ForemanMaintain::PackageManager
2
2
  # rubocop:disable Lint/UnusedMethodArgument
3
3
  class Base
4
- # check tools are installed and enabled
5
- def version_locking_enabled?
6
- raise NotImplementedError
7
- end
8
-
9
- # make sure the version locking tools are configured
10
- def install_version_locking(assumeyes: false)
4
+ # confirms that Package Manager supports the locking mechanism
5
+ def version_locking_supported?
11
6
  raise NotImplementedError
12
7
  end
13
8
 
@@ -5,6 +5,10 @@ module ForemanMaintain::PackageManager
5
5
  super
6
6
  end
7
7
 
8
+ def version_locking_supported?
9
+ true
10
+ end
11
+
8
12
  private
9
13
 
10
14
  def dnf_action(action, packages, with_status: false, assumeyes: false)
@@ -2,7 +2,6 @@ module ForemanMaintain::PackageManager
2
2
  class Yum < Base
3
3
  PROTECTOR_CONFIG_FILE = '/etc/yum/pluginconf.d/foreman-protector.conf'.freeze
4
4
  PROTECTOR_WHITELIST_FILE = '/etc/yum/pluginconf.d/foreman-protector.whitelist'.freeze
5
- PROTECTOR_PLUGIN_FILE = '/usr/lib/yum-plugins/foreman-protector.py'.freeze
6
5
 
7
6
  def self.parse_envra(envra)
8
7
  # envra format: 0:foreman-1.20.1.10-1.el7sat.noarch
@@ -19,18 +18,17 @@ module ForemanMaintain::PackageManager
19
18
  end
20
19
 
21
20
  def versions_locked?
22
- !!(protector_config =~ /^\s*enabled\s*=\s*1/)
21
+ !!(protector_config =~ /^\s*enabled\s*=\s*1/) &&
22
+ protector_whitelist_file_nonzero?
23
23
  end
24
24
 
25
- def version_locking_enabled?
26
- File.exist?(PROTECTOR_PLUGIN_FILE) && File.exist?(PROTECTOR_CONFIG_FILE) &&
27
- File.exist?(PROTECTOR_WHITELIST_FILE)
25
+ def protector_whitelist_file_nonzero?
26
+ File.exist?(PROTECTOR_WHITELIST_FILE) &&
27
+ !File.zero?(PROTECTOR_WHITELIST_FILE)
28
28
  end
29
29
 
30
- def install_version_locking(*)
31
- install_extras('foreman_protector/foreman-protector.py', PROTECTOR_PLUGIN_FILE)
32
- install_extras('foreman_protector/foreman-protector.conf', PROTECTOR_CONFIG_FILE)
33
- install_extras('foreman_protector/foreman-protector.whitelist', PROTECTOR_WHITELIST_FILE)
30
+ def version_locking_supported?
31
+ true
34
32
  end
35
33
 
36
34
  def installed?(packages)
@@ -49,6 +47,10 @@ module ForemanMaintain::PackageManager
49
47
  yum_action('install', packages, :assumeyes => assumeyes)
50
48
  end
51
49
 
50
+ def reinstall(packages, assumeyes: false)
51
+ yum_action('reinstall', packages, :assumeyes => assumeyes)
52
+ end
53
+
52
54
  def remove(packages, assumeyes: false)
53
55
  yum_action('remove', packages, :assumeyes => assumeyes)
54
56
  end
@@ -129,14 +131,5 @@ module ForemanMaintain::PackageManager
129
131
  :interactive => !assumeyes, :valid_exit_statuses => valid_exit_statuses)
130
132
  end
131
133
  end
132
-
133
- def install_extras(src, dest, override: false)
134
- extras_src = File.expand_path('../../../../extras', __FILE__)
135
- if override ||
136
- (File.directory?(dest) && !File.exist?(File.join(dest, src))) ||
137
- !File.exist?(dest)
138
- FileUtils.cp(File.join(extras_src, src), dest)
139
- end
140
- end
141
134
  end
142
135
  end
@@ -317,7 +317,11 @@ module ForemanMaintain
317
317
 
318
318
  steps_with_error = scenario.steps_with_error(:whitelisted => false)
319
319
  steps_with_skipped = scenario.steps_with_skipped(:whitelisted => true)
320
- steps_to_whitelist = steps_with_error + steps_with_skipped
320
+ not_skippable_steps = scenario.steps_with_error.select do |step|
321
+ step.metadata[:do_not_whitelist] == true
322
+ end
323
+
324
+ steps_to_whitelist = steps_with_error + steps_with_skipped - not_skippable_steps
321
325
  unless steps_with_error.empty?
322
326
  message << format(<<-MESSAGE.strip_heredoc, format_steps(steps_with_error, "\n", 2))
323
327
  The following steps ended up in failing state:
@@ -325,11 +329,25 @@ module ForemanMaintain
325
329
  %s
326
330
  MESSAGE
327
331
  whitelist_labels = steps_to_whitelist.map(&:label_dashed).join(',')
328
- recommend << format(<<-MESSAGE.strip_heredoc, whitelist_labels)
329
- Resolve the failed steps and rerun
330
- the command. In case the failures are false positives,
331
- use --whitelist="%s"
332
- MESSAGE
332
+ unless whitelist_labels.empty?
333
+ recommend << if scenario.detector.feature(:instance).downstream
334
+ format(<<-MESSAGE.strip_heredoc, whitelist_labels)
335
+ Resolve the failed steps and rerun the command.
336
+
337
+ If the situation persists and, you are unclear what to do next,
338
+ contact Red Hat Technical Support.
339
+
340
+ In case the failures are false positives, use
341
+ --whitelist="%s"
342
+ MESSAGE
343
+ else
344
+ format(<<-MESSAGE.strip_heredoc, whitelist_labels)
345
+ Resolve the failed steps and rerun the command.
346
+ In case the failures are false positives, use
347
+ --whitelist="%s"
348
+ MESSAGE
349
+ end
350
+ end
333
351
  end
334
352
 
335
353
  steps_with_warning = scenario.steps_with_warning(:whitelisted => false)
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '1.0.6'.freeze
2
+ VERSION = '1.0.9'.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.6
4
+ version: 1.0.9
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-03-30 00:00:00.000000000 Z
11
+ date: 2022-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -184,7 +184,6 @@ files:
184
184
  - definitions/checks/server_ping.rb
185
185
  - definitions/checks/services_up.rb
186
186
  - definitions/checks/system_registration.rb
187
- - definitions/checks/version_locking_enabled.rb
188
187
  - definitions/features/apache.rb
189
188
  - definitions/features/candlepin.rb
190
189
  - definitions/features/candlepin_database.rb
@@ -274,7 +273,6 @@ files:
274
273
  - definitions/procedures/maintenance_mode/enable_maintenance_mode.rb
275
274
  - definitions/procedures/maintenance_mode/is_enabled.rb
276
275
  - definitions/procedures/packages/check_update.rb
277
- - definitions/procedures/packages/enable_version_locking.rb
278
276
  - definitions/procedures/packages/install.rb
279
277
  - definitions/procedures/packages/installer_confirmation.rb
280
278
  - definitions/procedures/packages/lock_versions.rb
@@ -299,6 +297,7 @@ files:
299
297
  - definitions/procedures/repositories/enable.rb
300
298
  - definitions/procedures/repositories/setup.rb
301
299
  - definitions/procedures/restore/candlepin_dump.rb
300
+ - definitions/procedures/restore/candlepin_reset_migrations.rb
302
301
  - definitions/procedures/restore/configs.rb
303
302
  - definitions/procedures/restore/confirmation.rb
304
303
  - definitions/procedures/restore/drop_databases.rb
@@ -361,9 +360,10 @@ files:
361
360
  - definitions/scenarios/upgrade_to_satellite_6_9.rb
362
361
  - definitions/scenarios/upgrade_to_satellite_6_9_z.rb
363
362
  - extras/foreman-maintain.sh
363
+ - extras/foreman_protector/dnf/foreman-protector.py
364
364
  - extras/foreman_protector/foreman-protector.conf
365
- - extras/foreman_protector/foreman-protector.py
366
365
  - extras/foreman_protector/foreman-protector.whitelist
366
+ - extras/foreman_protector/yum/foreman-protector.py
367
367
  - extras/passenger-recycler.cron
368
368
  - lib/foreman_maintain.rb
369
369
  - lib/foreman_maintain/check.rb
@@ -1,14 +0,0 @@
1
- module Checks
2
- class VersionLockingEnabled < ForemanMaintain::Check
3
- metadata do
4
- description 'Check if tooling for package locking is installed'
5
- end
6
-
7
- def run
8
- enabled = package_manager.version_locking_enabled?
9
- enable_locking = Procedures::Packages::EnableVersionLocking.new(:assumeyes => assumeyes?)
10
- assert(enabled, 'Tools for package version locking are not available on this system',
11
- :next_steps => enable_locking)
12
- end
13
- end
14
- end
@@ -1,12 +0,0 @@
1
- module Procedures::Packages
2
- class EnableVersionLocking < ForemanMaintain::Procedure
3
- metadata do
4
- description 'Install and configure tools for version locking'
5
- param :assumeyes, 'Do not ask for confirmation'
6
- end
7
-
8
- def run
9
- package_manager.install_version_locking(:assumeyes => @assumeyes)
10
- end
11
- end
12
- end