foreman_maintain 0.6.9 → 0.6.10

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: 7050dd905c1396f95686caabf7afaea60f963b8c68c2b0849eb4d06b7e5330f7
4
- data.tar.gz: d683a46f74563cb3c22a4f0ab94ebf3354aa4685afd8b22a7ea68ec1fc6d70a7
3
+ metadata.gz: e382b3653ec4332ef6bc891b83e92263874dfc079fb84c1f3db951696804832e
4
+ data.tar.gz: 03b8467289528688c03ed6ad7b8361befee931c9eb0d51a897aa38a755b9ad8a
5
5
  SHA512:
6
- metadata.gz: 56ffb28e036596b3b7262ff27e5f7ab85ccd98ba3f261ef5049f0e4c404b743b96fe3086723a7a0d08005e27308b40888e209ca66125662d4dd72da8706a540c
7
- data.tar.gz: f056a9c36223352dededfd338e462070f71780b679e2d661360733a85ef07045ac1fd7f803421f945d9f1cc0176d7351d8f0f951da558635b33a5dcc7e99a67c
6
+ metadata.gz: 0f9b4071adbda3fb4f39c84a6c02891aa4e54c0138d8245dfb2da93844bbc6b51e8db88a0424a006fde8563b7b4806b833176caeacaaa9c4b3101ef23824c4f0
7
+ data.tar.gz: a00abc28ccc812b76de1ca75849f471bd16944fb3cd8bc7ead833f0c077c17e1860626ba6e9c52af834fa1f21c2a6c6b0c331551bc435d921926fdc694cda045
data/README.md CHANGED
@@ -488,6 +488,15 @@ Here, 0=ON & 1=OFF.
488
488
  If users would like to check whether maintenance-mode is ON/OFF on system in their external script then
489
489
  they can use subcommand `foreman-maintain maintenance-mode is-enabled`.
490
490
 
491
+ ## Exit codes with special meanings -
492
+
493
+ Every command returns an exit code. Any other exit status than 0 indicates a failure of some kind. Foreman Maintain uses following exit codes with special meaning.
494
+
495
+ | Exit Code | Description |
496
+ | -----------| -----------------------------------|
497
+ | 75 | Temporary failure and needs re-run |
498
+ | 78 | Command executed with warning(s) |
499
+
491
500
  ## How to contribute?
492
501
 
493
502
  Generally, follow the [Foreman guidelines](https://theforeman.org/contribute.html). For code-related contributions, fork this project and send a pull request with all changes. Some things to keep in mind:
@@ -0,0 +1,51 @@
1
+ module Checks
2
+ module Foreman
3
+ class CheckpointSegments < ForemanMaintain::Check
4
+ metadata do
5
+ label :check_postgresql_checkpoint_segments
6
+ description 'Check if checkpoint_segments configuration exists on the system'
7
+ confine do
8
+ feature(:foreman) && feature(:installer) &&
9
+ File.exist?(feature(:installer).custom_hiera_file)
10
+ end
11
+ end
12
+
13
+ def run
14
+ failure_message = check_custom_hiera
15
+ fail! failure_message if failure_message
16
+ end
17
+
18
+ # rubocop:disable Metrics/MethodLength
19
+ def check_custom_hiera
20
+ hiera_file = feature(:installer).custom_hiera_file
21
+ if (config = YAML.load_file(hiera_file)) &&
22
+ config.key?('postgresql::server::config_entries')
23
+ if config['postgresql::server::config_entries'].nil?
24
+ return <<-MESSAGE.strip_heredoc
25
+ ERROR: 'postgresql::server::config_entries' cannot be null.
26
+ Please remove it from following file and re-run the command.
27
+ - #{hiera_file}
28
+ MESSAGE
29
+ elsif config['postgresql::server::config_entries'].key?('checkpoint_segments')
30
+ message = <<-MESSAGE.strip_heredoc
31
+ ERROR: Tuning option 'checkpoint_segments' found.
32
+ This option is no longer valid for PostgreSQL 9.5 or newer.
33
+ Please remove it from following file and re-run the command.
34
+ - #{hiera_file}
35
+ MESSAGE
36
+ if feature(:katello)
37
+ message += <<-MESSAGE.strip_heredoc
38
+ The presence of checkpoint_segments in #{hiera_file} indicates manual tuning.
39
+ Manual tuning can override values provided by the --tuning parameter.
40
+ Review #{hiera_file} for values that are already provided by the built in tuning profiles.
41
+ Built in tuning profiles also provide a supported upgrade path.
42
+ MESSAGE
43
+ end
44
+ return message
45
+ end
46
+ end
47
+ end
48
+ # rubocop:enable Metrics/MethodLength
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ module Checks
2
+ module Foreman
3
+ class CheckDuplicatePermissions < ForemanMaintain::Check
4
+ metadata do
5
+ label :duplicate_permissions
6
+ for_feature :foreman_database
7
+ description 'Check for duplicate permissions from database'
8
+ tags :pre_upgrade
9
+ end
10
+
11
+ def run
12
+ duplicate_permissions = find_duplicate_permissions
13
+ assert(
14
+ duplicate_permissions.empty?,
15
+ 'Duplicate permissions in your database',
16
+ :next_steps => [
17
+ Procedures::Foreman::RemoveDuplicatePermissions.new
18
+ ]
19
+ )
20
+ end
21
+
22
+ def find_duplicate_permissions
23
+ feature(:foreman_database).query(self.class.query_to_get_duplicate_permission)
24
+ end
25
+
26
+ def self.query_to_get_duplicate_permission
27
+ <<-SQL
28
+ SELECT id,name FROM permissions p WHERE (SELECT count(name) FROM permissions pr WHERE p.name =pr.name) > 1
29
+ SQL
30
+ end
31
+ end
32
+ end
33
+ end
@@ -22,10 +22,9 @@ module Checks::ForemanProxy
22
22
  end
23
23
 
24
24
  def old_files_from_tftp_boot
25
- Dir.entries(tftp_boot_directory).map do |file|
25
+ Dir.glob("#{tftp_boot_directory}*-{vmlinuz,initrd.img}").map do |file|
26
26
  unless File.directory?(file)
27
- file_path = tftp_boot_directory + file
28
- file_path if File.mtime(file_path) + (token_duration * 60) < Time.now
27
+ file if File.mtime(file) + (token_duration * 60) < Time.now
29
28
  end
30
29
  end.compact
31
30
  end
@@ -53,6 +53,10 @@ class Features::Installer < ForemanMaintain::Feature
53
53
  end
54
54
  end
55
55
 
56
+ def custom_hiera_file
57
+ @custom_hiera_file ||= File.join(config_directory, 'custom-hiera.yaml')
58
+ end
59
+
56
60
  def can_upgrade?
57
61
  @installer_type == :scenarios || @installer_type == :legacy_katello
58
62
  end
@@ -0,0 +1,70 @@
1
+ module Procedures::Foreman
2
+ class RemoveDuplicatePermissions < ForemanMaintain::Procedure
3
+ metadata do
4
+ for_feature :foreman_database
5
+ description 'Remove duplicate permissions from database'
6
+ end
7
+
8
+ def run
9
+ duplicate_permissions = feature(:foreman_database).query(
10
+ Checks::Foreman::CheckDuplicatePermissions.query_to_get_duplicate_permission
11
+ ).group_by { |permission| permission['name'] }
12
+ unassigned_permissions = []
13
+ duplicate_permissions.each_value do |permissions|
14
+ permission_ids = permissions.map { |i| i['id'] }
15
+ filterings = check_permissions_assign_to_filter(permission_ids)
16
+ assigned_permissions = filterings.keys
17
+ unassigned_permissions << permission_ids - assigned_permissions
18
+ fix_permissions(assigned_permissions) if assigned_permissions.length > 1
19
+ end
20
+ delete_permission(unassigned_permissions.flatten) unless unassigned_permissions.empty?
21
+ end
22
+
23
+ private
24
+
25
+ def check_permissions_assign_to_filter(permission_ids)
26
+ sql = <<-SQL
27
+ SELECT id, filter_id, permission_id FROM filterings WHERE permission_id IN (#{permission_ids.join(',')})
28
+ SQL
29
+ feature(:foreman_database).query(sql).group_by { |filtering| filtering['permission_id'] }
30
+ end
31
+
32
+ def fix_permissions(assigned_permissions)
33
+ persist_permission = assigned_permissions.shift
34
+ filter_ids = filters_for_permission(persist_permission)
35
+ update_filtering(assigned_permissions, persist_permission, filter_ids)
36
+ delete_filtering(assigned_permissions)
37
+ delete_permission(assigned_permissions)
38
+ end
39
+
40
+ def filters_for_permission(permission)
41
+ feature(:foreman_database).query(
42
+ "SELECT filter_id FROM filterings WHERE permission_id = #{permission.to_i}"
43
+ ).map { |filter| filter['filter_id'] }
44
+ end
45
+
46
+ def update_filtering(old_ids, new_id, filter_ids)
47
+ sql = <<-SQL
48
+ WITH rows AS (
49
+ UPDATE filterings SET permission_id = '#{new_id}' WHERE permission_id IN (#{old_ids.join(',')}) AND filter_id NOT IN (#{filter_ids.join(',')})
50
+ RETURNING id
51
+ )
52
+ SELECT id
53
+ FROM rows
54
+ SQL
55
+ feature(:foreman_database).query(sql)
56
+ end
57
+
58
+ def delete_filtering(permission_ids)
59
+ feature(:foreman_database).psql(
60
+ "DELETE FROM filterings where permission_id IN (#{permission_ids.join(',')})"
61
+ )
62
+ end
63
+
64
+ def delete_permission(permission_ids)
65
+ feature(:foreman_database).psql(
66
+ "DELETE FROM permissions where id IN (#{permission_ids.join(',')})"
67
+ )
68
+ end
69
+ end
70
+ end
@@ -6,7 +6,7 @@ module Procedures::Installer
6
6
 
7
7
  def run
8
8
  assumeyes_val = @assumeyes.nil? ? assumeyes? : @assumeyes
9
- feature(:installer).run(@arguments, :interactive => !assumeyes_val)
9
+ feature(:installer).upgrade(:interactive => !assumeyes_val)
10
10
  end
11
11
  end
12
12
  end
@@ -27,6 +27,7 @@ module Scenarios::Satellite_6_8
27
27
  def compose
28
28
  add_steps(find_checks(:default))
29
29
  add_steps(find_checks(:pre_upgrade))
30
+ add_step(Checks::Foreman::CheckpointSegments)
30
31
  add_step(Checks::Repositories::Validate.new(:version => '6.8'))
31
32
  end
32
33
  end
@@ -38,7 +38,7 @@ module ForemanMaintain
38
38
 
39
39
  subcommand 'update', 'Update packages in an unlocked session' do
40
40
  interactive_option
41
- parameter '[PACKAGES ...]', 'packages to update', :attribute_name => :packages
41
+ parameter '[PACKAGES] ...', 'packages to update', :attribute_name => :packages
42
42
 
43
43
  def execute
44
44
  run_scenarios_and_exit(
@@ -53,7 +53,10 @@ module ForemanMaintain
53
53
  end
54
54
 
55
55
  subcommand 'list-versions', 'List versions this system is upgradable to' do
56
+ disable_self_upgrade_option
57
+
56
58
  def execute
59
+ ForemanMaintain.perform_self_upgrade unless disable_self_upgrade?
57
60
  print_versions(UpgradeRunner.available_targets)
58
61
  end
59
62
  end
@@ -72,7 +72,9 @@ module ForemanMaintain
72
72
  end
73
73
 
74
74
  def ansible_repo(server_version, rh_version_major)
75
- if server_version >= version('6.6')
75
+ if server_version >= version('6.8')
76
+ "rhel-#{rh_version_major}-server-ansible-2.9-rpms"
77
+ elsif server_version >= version('6.6')
76
78
  "rhel-#{rh_version_major}-server-ansible-2.8-rpms"
77
79
  elsif server_version >= version('6.4')
78
80
  "rhel-#{rh_version_major}-server-ansible-2.6-rpms"
@@ -105,7 +107,7 @@ module ForemanMaintain
105
107
  "rhel-#{rh_version_major}-server-satellite-tools-#{full_version}-rpms"]
106
108
  end
107
109
 
108
- return repos_arrary.first(1) if feature(:capsule)
110
+ return repos_arrary.first(1) if feature(:satellite)
109
111
 
110
112
  repos_arrary
111
113
  end
@@ -276,7 +276,7 @@ module ForemanMaintain
276
276
 
277
277
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
278
278
  def scenario_failure_message(scenario)
279
- return if scenario.passed?
279
+ return if scenario.passed? && !scenario.warning?
280
280
  message = []
281
281
  message << <<-MESSAGE.strip_heredoc
282
282
  Scenario [#{scenario.description}] failed.
@@ -54,6 +54,7 @@ module ForemanMaintain
54
54
  @last_scenario = scenario
55
55
  @last_scenario_continuation_confirmed = false
56
56
  end
57
+ @exit_code = 78 if scenario.warning?
57
58
  @exit_code = 1 if scenario.failed?
58
59
  end
59
60
 
@@ -129,8 +129,11 @@ module ForemanMaintain
129
129
 
130
130
  def passed?
131
131
  (steps_with_abort(:whitelisted => false) +
132
- steps_with_error(:whitelisted => false) +
133
- steps_with_warning(:whitelisted => false)).empty?
132
+ steps_with_error(:whitelisted => false)).empty?
133
+ end
134
+
135
+ def warning?
136
+ !steps_with_warning(:whitelisted => false).empty?
134
137
  end
135
138
 
136
139
  def failed?
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.6.9'.freeze
2
+ VERSION = '0.6.10'.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.6.9
4
+ version: 0.6.10
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: 2020-08-03 00:00:00.000000000 Z
11
+ date: 2020-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -127,7 +127,9 @@ files:
127
127
  - definitions/checks/disk/available_space.rb
128
128
  - definitions/checks/disk/performance.rb
129
129
  - definitions/checks/env_proxy.rb
130
+ - definitions/checks/foreman/check_checkpoint_segments.rb
130
131
  - definitions/checks/foreman/check_corrupted_roles.rb
132
+ - definitions/checks/foreman/check_duplicate_permission.rb
131
133
  - definitions/checks/foreman/check_duplicate_roles.rb
132
134
  - definitions/checks/foreman/db_up.rb
133
135
  - definitions/checks/foreman/facts_names.rb
@@ -226,6 +228,7 @@ files:
226
228
  - definitions/procedures/foreman/apipie_cache.rb
227
229
  - definitions/procedures/foreman/fix_corrupted_roles.rb
228
230
  - definitions/procedures/foreman/remove_duplicate_obsolete_roles.rb
231
+ - definitions/procedures/foreman/remove_duplicate_permissions.rb
229
232
  - definitions/procedures/foreman_docker/remove_foreman_docker.rb
230
233
  - definitions/procedures/foreman_openscap/invalid_report_associations.rb
231
234
  - definitions/procedures/foreman_proxy/features.rb