foreman_maintain 0.8.21 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/definitions/checks/foreman/check_puppet_capsules.rb +43 -0
  3. data/definitions/checks/pulpcore/group_ownership_check.rb +18 -0
  4. data/definitions/checks/repositories/validate.rb +1 -2
  5. data/definitions/checks/restore/validate_interfaces.rb +24 -0
  6. data/definitions/features/candlepin.rb +1 -2
  7. data/definitions/features/pulpcore.rb +2 -1
  8. data/definitions/features/system_repos.rb +8 -0
  9. data/definitions/procedures/backup/metadata.rb +11 -0
  10. data/definitions/procedures/installer/upgrade_rake_task.rb +3 -1
  11. data/definitions/procedures/pulpcore/migrate.rb +1 -1
  12. data/definitions/procedures/puppet/remove_puppet.rb +50 -0
  13. data/definitions/procedures/puppet/remove_puppet_data.rb +21 -0
  14. data/definitions/procedures/repositories/backup_enabled_repos.rb +16 -0
  15. data/definitions/procedures/repositories/enable.rb +13 -0
  16. data/definitions/procedures/repositories/setup.rb +0 -4
  17. data/definitions/procedures/restore/configs.rb +5 -1
  18. data/definitions/scenarios/puppet.rb +21 -0
  19. data/definitions/scenarios/restore.rb +14 -1
  20. data/definitions/scenarios/self_upgrade.rb +102 -0
  21. data/definitions/scenarios/upgrade_to_capsule_7_0.rb +89 -0
  22. data/definitions/scenarios/upgrade_to_capsule_7_0_z.rb +89 -0
  23. data/definitions/scenarios/upgrade_to_satellite_6_10.rb +1 -8
  24. data/definitions/scenarios/upgrade_to_satellite_7_0.rb +93 -0
  25. data/definitions/scenarios/upgrade_to_satellite_7_0_z.rb +90 -0
  26. data/lib/foreman_maintain/cli/plugin_command.rb +14 -0
  27. data/lib/foreman_maintain/cli/restore_command.rb +5 -1
  28. data/lib/foreman_maintain/cli/self_upgrade_command.rb +38 -0
  29. data/lib/foreman_maintain/cli.rb +4 -0
  30. data/lib/foreman_maintain/concerns/downstream.rb +50 -22
  31. data/lib/foreman_maintain/concerns/os_facts.rb +70 -0
  32. data/lib/foreman_maintain/concerns/system_helpers.rb +12 -33
  33. data/lib/foreman_maintain/utils/backup.rb +36 -11
  34. data/lib/foreman_maintain/utils.rb +0 -1
  35. data/lib/foreman_maintain/version.rb +1 -1
  36. data/lib/foreman_maintain.rb +1 -0
  37. metadata +36 -11
  38. data/lib/foreman_maintain/concerns/el_repos_manager_common.rb +0 -20
  39. data/lib/foreman_maintain/repos_manager/dnf_config_manager.rb +0 -13
  40. data/lib/foreman_maintain/repos_manager/el_common.rb +0 -0
  41. data/lib/foreman_maintain/repos_manager/yum_config_manager.rb +0 -20
  42. data/lib/foreman_maintain/utils/facter.rb +0 -17
@@ -0,0 +1,89 @@
1
+ module Scenarios::Capsule_7_0_z
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_scenario
6
+ confine do
7
+ feature(:capsule) &&
8
+ (feature(:capsule).current_minor_version == '7.0' || \
9
+ ForemanMaintain.upgrade_in_progress == '7.0.z')
10
+ end
11
+ instance_eval(&block)
12
+ end
13
+ end
14
+
15
+ def target_version
16
+ '7.0.z'
17
+ end
18
+ end
19
+
20
+ class PreUpgradeCheck < Abstract
21
+ upgrade_metadata do
22
+ description 'Checks before upgrading to Capsule 7.0.z'
23
+ tags :pre_upgrade_checks
24
+ run_strategy :fail_slow
25
+ end
26
+
27
+ def compose
28
+ add_steps(find_checks(:default))
29
+ add_steps(find_checks(:pre_upgrade))
30
+ add_step(Checks::Repositories::Validate.new(:version => '7.0'))
31
+ end
32
+ end
33
+
34
+ class PreMigrations < Abstract
35
+ upgrade_metadata do
36
+ description 'Procedures before migrating to Capsule 7.0.z'
37
+ tags :pre_migrations
38
+ end
39
+
40
+ def compose
41
+ add_steps(find_procedures(:pre_migrations))
42
+ add_step(Procedures::Service::Stop.new)
43
+ end
44
+ end
45
+
46
+ class Migrations < Abstract
47
+ upgrade_metadata do
48
+ description 'Migration scripts to Capsule 7.0.z'
49
+ tags :migrations
50
+ end
51
+
52
+ def set_context_mapping
53
+ context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
54
+ end
55
+
56
+ def compose
57
+ add_step(Procedures::Repositories::Setup.new(:version => '7.0'))
58
+ add_step(Procedures::Packages::UnlockVersions.new)
59
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
60
+ add_step_with_context(Procedures::Installer::Upgrade)
61
+ end
62
+ end
63
+
64
+ class PostMigrations < Abstract
65
+ upgrade_metadata do
66
+ description 'Procedures after migrating to Capsule 7.0.z'
67
+ tags :post_migrations
68
+ end
69
+
70
+ def compose
71
+ add_step(Procedures::RefreshFeatures)
72
+ add_step(Procedures::Service::Start.new)
73
+ add_steps(find_procedures(:post_migrations))
74
+ end
75
+ end
76
+
77
+ class PostUpgradeChecks < Abstract
78
+ upgrade_metadata do
79
+ description 'Checks after upgrading to Capsule 7.0.z'
80
+ tags :post_upgrade_checks
81
+ run_strategy :fail_slow
82
+ end
83
+
84
+ def compose
85
+ add_steps(find_checks(:default))
86
+ add_steps(find_checks(:post_upgrade))
87
+ end
88
+ end
89
+ end
@@ -25,6 +25,7 @@ module Scenarios::Satellite_6_10
25
25
  end
26
26
 
27
27
  def compose
28
+ add_step(Checks::Pulpcore::GroupOwnershipCheck)
28
29
  add_step(Checks::Puppet::WarnAboutPuppetRemoval)
29
30
  add_step(Checks::CheckForNewerPackages.new(:packages => [foreman_plugin_name('katello'),
30
31
  'python3-pulp-2to3-migration'],
@@ -61,13 +62,6 @@ module Scenarios::Satellite_6_10
61
62
  context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
62
63
  end
63
64
 
64
- def check_var_lib_pulp
65
- group_id = File.stat('/var/lib/pulp/').gid
66
- if Etc.getgrgid(group_id).name != 'pulp'
67
- raise "Please run 'foreman-maintain prep-6.10-upgrade' prior to upgrading."
68
- end
69
- end
70
-
71
65
  def pulp3_switchover_steps
72
66
  add_step(Procedures::Service::Enable.
73
67
  new(:only => Features::Pulpcore.pulpcore_migration_services))
@@ -79,7 +73,6 @@ module Scenarios::Satellite_6_10
79
73
  end
80
74
 
81
75
  def compose
82
- check_var_lib_pulp
83
76
  unless check_min_version(foreman_plugin_name('katello'), '4.0')
84
77
  pulp3_switchover_steps
85
78
  end
@@ -0,0 +1,93 @@
1
+ module Scenarios::Satellite_7_0
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_scenario
6
+ confine do
7
+ feature(:satellite) &&
8
+ (feature(:satellite).current_minor_version == '6.10' || \
9
+ ForemanMaintain.upgrade_in_progress == '7.0')
10
+ end
11
+ instance_eval(&block)
12
+ end
13
+ end
14
+
15
+ def target_version
16
+ '7.0'
17
+ end
18
+ end
19
+
20
+ class PreUpgradeCheck < Abstract
21
+ upgrade_metadata do
22
+ description 'Checks before upgrading to Satellite 7.0'
23
+ tags :pre_upgrade_checks
24
+ run_strategy :fail_slow
25
+ end
26
+
27
+ def compose
28
+ add_steps(find_checks(:default))
29
+ add_steps(find_checks(:pre_upgrade))
30
+
31
+ add_step(Checks::Foreman::CheckpointSegments)
32
+ add_step(Checks::Repositories::Validate.new(:version => '7.0'))
33
+ end
34
+ end
35
+
36
+ class PreMigrations < Abstract
37
+ upgrade_metadata do
38
+ description 'Procedures before migrating to Satellite 7.0'
39
+ tags :pre_migrations
40
+ end
41
+
42
+ def compose
43
+ add_steps(find_procedures(:pre_migrations))
44
+ add_step(Procedures::Service::Stop.new)
45
+ end
46
+ end
47
+
48
+ class Migrations < Abstract
49
+ upgrade_metadata do
50
+ description 'Migration scripts to Satellite 7.0'
51
+ tags :migrations
52
+ run_strategy :fail_fast
53
+ end
54
+
55
+ def set_context_mapping
56
+ context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
57
+ end
58
+
59
+ def compose
60
+ add_step(Procedures::Repositories::Setup.new(:version => '7.0'))
61
+ add_step(Procedures::Packages::UnlockVersions.new)
62
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
63
+ add_step_with_context(Procedures::Installer::Upgrade)
64
+ add_step(Procedures::Installer::UpgradeRakeTask)
65
+ end
66
+ end
67
+
68
+ class PostMigrations < Abstract
69
+ upgrade_metadata do
70
+ description 'Procedures after migrating to Satellite 7.0'
71
+ tags :post_migrations
72
+ end
73
+
74
+ def compose
75
+ add_step(Procedures::RefreshFeatures)
76
+ add_step(Procedures::Service::Start.new)
77
+ add_steps(find_procedures(:post_migrations))
78
+ end
79
+ end
80
+
81
+ class PostUpgradeChecks < Abstract
82
+ upgrade_metadata do
83
+ description 'Checks after upgrading to Satellite 7.0'
84
+ tags :post_upgrade_checks
85
+ run_strategy :fail_slow
86
+ end
87
+
88
+ def compose
89
+ add_steps(find_checks(:default))
90
+ add_steps(find_checks(:post_upgrade))
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,90 @@
1
+ module Scenarios::Satellite_7_0_z
2
+ class Abstract < ForemanMaintain::Scenario
3
+ def self.upgrade_metadata(&block)
4
+ metadata do
5
+ tags :upgrade_scenario
6
+ confine do
7
+ feature(:satellite) &&
8
+ (feature(:satellite).current_minor_version == '7.0' || \
9
+ ForemanMaintain.upgrade_in_progress == '7.0.z')
10
+ end
11
+ instance_eval(&block)
12
+ end
13
+ end
14
+
15
+ def target_version
16
+ '7.0.z'
17
+ end
18
+ end
19
+
20
+ class PreUpgradeCheck < Abstract
21
+ upgrade_metadata do
22
+ description 'Checks before upgrading to Satellite 7.0.z'
23
+ tags :pre_upgrade_checks
24
+ run_strategy :fail_slow
25
+ end
26
+
27
+ def compose
28
+ add_steps(find_checks(:default))
29
+ add_steps(find_checks(:pre_upgrade))
30
+ add_step(Checks::Repositories::Validate.new(:version => '7.0'))
31
+ end
32
+ end
33
+
34
+ class PreMigrations < Abstract
35
+ upgrade_metadata do
36
+ description 'Procedures before migrating to Satellite 7.0.z'
37
+ tags :pre_migrations
38
+ end
39
+
40
+ def compose
41
+ add_steps(find_procedures(:pre_migrations))
42
+ add_step(Procedures::Service::Stop.new)
43
+ end
44
+ end
45
+
46
+ class Migrations < Abstract
47
+ upgrade_metadata do
48
+ description 'Migration scripts to Satellite 7.0.z'
49
+ tags :migrations
50
+ end
51
+
52
+ def set_context_mapping
53
+ context.map(:assumeyes, Procedures::Installer::Upgrade => :assumeyes)
54
+ end
55
+
56
+ def compose
57
+ add_step(Procedures::Repositories::Setup.new(:version => '7.0'))
58
+ add_step(Procedures::Packages::UnlockVersions.new)
59
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
60
+ add_step_with_context(Procedures::Installer::Upgrade)
61
+ add_step(Procedures::Installer::UpgradeRakeTask)
62
+ end
63
+ end
64
+
65
+ class PostMigrations < Abstract
66
+ upgrade_metadata do
67
+ description 'Procedures after migrating to Satellite 7.0.z'
68
+ tags :post_migrations
69
+ end
70
+
71
+ def compose
72
+ add_step(Procedures::RefreshFeatures)
73
+ add_step(Procedures::Service::Start.new)
74
+ add_steps(find_procedures(:post_migrations))
75
+ end
76
+ end
77
+
78
+ class PostUpgradeChecks < Abstract
79
+ upgrade_metadata do
80
+ description 'Checks after upgrading to Satellite 7.0.z'
81
+ tags :post_upgrade_checks
82
+ run_strategy :fail_slow
83
+ end
84
+
85
+ def compose
86
+ add_steps(find_checks(:default))
87
+ add_steps(find_checks(:post_upgrade))
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,14 @@
1
+ module ForemanMaintain
2
+ module Cli
3
+ class PluginCommand < Base
4
+ subcommand 'purge-puppet', 'Remove the Puppet feature' do
5
+ option ['-f', '--remove-all-data'], :flag, 'Purge all the Puppet data',
6
+ :attribute_name => :remove_data
7
+
8
+ def execute
9
+ run_scenarios_and_exit(Scenarios::Puppet::RemovePuppet.new(:remove_data => remove_data?))
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -7,11 +7,15 @@ module ForemanMaintain
7
7
 
8
8
  option ['-i', '--incremental'], :flag, 'Restore an incremental backup',
9
9
  :attribute_name => :incremental, :completion => { :type => :directory }
10
+ option ['-n', '--dry-run'], :flag,
11
+ 'Check if backup could be restored, without performing the restore',
12
+ :attribute_name => :dry_run
10
13
 
11
14
  def execute
12
15
  scenario = Scenarios::Restore.new(
13
16
  :backup_dir => @backup_dir,
14
- :incremental_backup => @incremental || incremental_backup?
17
+ :incremental_backup => @incremental || incremental_backup?,
18
+ :dry_run => @dry_run
15
19
  )
16
20
  rescue_scenario = Scenarios::RestoreRescue.new
17
21
  run_scenario(scenario, rescue_scenario)
@@ -0,0 +1,38 @@
1
+ module ForemanMaintain
2
+ module Cli
3
+ class SelfUpgradeCommand < Base
4
+ option ['--target-version'], 'TARGET_VERSION',\
5
+ 'Major version of the Satellite or Capsule'\
6
+ ', e.g 7.0', :required => true
7
+ def execute
8
+ allow_major_version_upgrade_only
9
+ run_scenario(upgrade_scenario, upgrade_rescue_scenario)
10
+ end
11
+
12
+ def upgrade_scenario
13
+ Scenarios::SelfUpgrade.new(target_version: target_version)
14
+ end
15
+
16
+ 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
+ raise Error::UsageError, message
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -11,6 +11,8 @@ require 'foreman_maintain/cli/restore_command'
11
11
  require 'foreman_maintain/cli/maintenance_mode_command'
12
12
  require 'foreman_maintain/cli/packages_command'
13
13
  require 'foreman_maintain/cli/content_command'
14
+ require 'foreman_maintain/cli/plugin_command'
15
+ require 'foreman_maintain/cli/self_upgrade_command'
14
16
 
15
17
  module ForemanMaintain
16
18
  module Cli
@@ -25,6 +27,8 @@ module ForemanMaintain
25
27
  subcommand 'packages', 'Lock/Unlock package protection, install, update', PackagesCommand
26
28
  subcommand 'advanced', 'Advanced tools for server maintenance', AdvancedCommand
27
29
  subcommand 'content', 'Content related commands', ContentCommand
30
+ subcommand 'plugin', 'Manage optional plugins on your server', PluginCommand
31
+ subcommand 'self-upgrade', 'Perform major version self upgrade', SelfUpgradeCommand
28
32
  subcommand 'maintenance-mode', 'Control maintenance-mode for application',
29
33
  MaintenanceModeCommand
30
34
  if ForemanMaintain.detector.feature(:satellite) &&
@@ -74,21 +74,36 @@ module ForemanMaintain
74
74
 
75
75
  def ansible_repo(server_version)
76
76
  if server_version >= version('6.8')
77
- "rhel-#{el_major_version}-server-ansible-2.9-rpms"
77
+ ansible_version = '2.9'
78
78
  elsif server_version >= version('6.6')
79
- "rhel-#{el_major_version}-server-ansible-2.8-rpms"
79
+ ansible_version = '2.8'
80
80
  elsif server_version >= version('6.4')
81
- "rhel-#{el_major_version}-server-ansible-2.6-rpms"
81
+ ansible_version = '2.6'
82
82
  end
83
+
84
+ if el7?
85
+ "rhel-#{el_major_version}-server-ansible-#{ansible_version}-rpms"
86
+ else
87
+ "ansible-#{ansible_version}-for-rhel-#{el_major_version}-x86_64-rpms"
88
+ end
89
+ end
90
+
91
+ def use_beta_repos?
92
+ ENV['FOREMAN_MAINTAIN_USE_BETA'] == '1'
83
93
  end
84
94
 
85
95
  def product_specific_repos(full_version)
86
- repos = []
87
- repos << if ENV['FOREMAN_MAINTAIN_USE_BETA'] == '1'
88
- "rhel-server-#{el_major_version}-#{package_name}-6-beta-rpms"
89
- else
90
- "rhel-#{el_major_version}-server-#{package_name}-#{full_version}-rpms"
91
- end
96
+ maj_version = full_version[0]
97
+ repos = if el7? && use_beta_repos?
98
+ ["rhel-server-#{el_major_version}-#{package_name}-#{maj_version}-beta-rpms"]
99
+ elsif el7?
100
+ ["rhel-#{el_major_version}-server-#{package_name}-#{full_version}-rpms"]
101
+ elsif use_beta_repos?
102
+ ["#{package_name}-#{maj_version}-beta-for-rhel-#{el_major_version}-x86_64-rpms"]
103
+ else
104
+ ["#{package_name}-#{full_version}-for-rhel-#{el_major_version}-x86_64-rpms"]
105
+ end
106
+
92
107
  repos << puppet4_repo(full_version) unless puppet4_repo(full_version).nil?
93
108
  repos.concat(common_repos(full_version))
94
109
  end
@@ -101,22 +116,35 @@ module ForemanMaintain
101
116
  end
102
117
 
103
118
  def common_repos(full_version)
104
- repos_arrary = if ENV['FOREMAN_MAINTAIN_USE_BETA'] == '1'
105
- ["rhel-#{el_major_version}-server-satellite-maintenance-6-beta-rpms",
106
- "rhel-#{el_major_version}-server-satellite-tools-6-beta-rpms"]
107
- else
108
- ["rhel-#{el_major_version}-server-satellite-maintenance-6-rpms",
109
- "rhel-#{el_major_version}-server-satellite-tools-#{full_version}-rpms"]
110
- end
111
-
112
- return repos_arrary.first(1) if feature(:satellite)
113
-
114
- repos_arrary
119
+ sat_maint_version = if version(full_version) >= version('7.0') && !use_beta_repos?
120
+ full_version
121
+ else
122
+ full_version[0]
123
+ end
124
+
125
+ # rubocop:disable Metrics/LineLength
126
+ repos = if el7? && use_beta_repos?
127
+ ["rhel-#{el_major_version}-server-satellite-maintenance-#{sat_maint_version}-beta-rpms"]
128
+ elsif el7?
129
+ ["rhel-#{el_major_version}-server-satellite-maintenance-#{sat_maint_version}-rpms"]
130
+ elsif use_beta_repos?
131
+ ["satellite-maintenance-#{sat_maint_version}-beta-for-rhel-#{el_major_version}-x86_64-rpms"]
132
+ else
133
+ ["satellite-maintenance-#{sat_maint_version}-for-rhel-#{el_major_version}-x86_64-rpms"]
134
+ end
135
+ # rubocop:enable Metrics/LineLength
136
+
137
+ repos
115
138
  end
116
139
 
117
140
  def main_rh_repos
118
- ["rhel-#{el_major_version}-server-rpms",
119
- "rhel-server-rhscl-#{el_major_version}-rpms"]
141
+ if el7?
142
+ ["rhel-#{el_major_version}-server-rpms",
143
+ "rhel-server-rhscl-#{el_major_version}-rpms"]
144
+ else
145
+ ["rhel-#{el_major_version}-for-x86_64-baseos-rpms",
146
+ "rhel-#{el_major_version}-for-x86_64-appstream-rpms"]
147
+ end
120
148
  end
121
149
 
122
150
  def version_from_source
@@ -0,0 +1,70 @@
1
+ module ForemanMaintain
2
+ module Concerns
3
+ module OsFacts
4
+ OS_RELEASE_FILE = '/etc/os-release'.freeze
5
+ FALLBACK_OS_RELEASE_FILE = '/usr/lib/os-release'.freeze
6
+
7
+ def os_release_file
8
+ if File.file?(OS_RELEASE_FILE)
9
+ return OS_RELEASE_FILE
10
+ elsif File.file?(FALLBACK_OS_RELEASE_FILE)
11
+ return FALLBACK_OS_RELEASE_FILE
12
+ else
13
+ puts "The #{OS_RELEASE_FILE} and #{FALLBACK_OS_RELEASE_FILE} files are missing! "\
14
+ "Can't continue the execution without Operating System's facts!"
15
+ exit 1
16
+ end
17
+ end
18
+
19
+ def facts
20
+ unless defined?(@facts)
21
+ @facts = {}
22
+ regex = /^(["'])(.*)(\1)$/
23
+ File.open(os_release_file) do |file|
24
+ file.readlines.each do |line|
25
+ line.strip! # drop any whitespace, including newlines from start and end of the line
26
+ next if line.start_with?('#') # ignore comments
27
+ # split at most into 2 items, if the value ever contains an =
28
+ key, value = line.split('=', 2)
29
+ next unless key && value
30
+ @facts[key] = value.gsub(regex, '\2').delete('\\')
31
+ end
32
+ end
33
+ end
34
+ @facts
35
+ end
36
+
37
+ def os_version_id
38
+ facts.fetch('VERSION_ID')
39
+ end
40
+
41
+ def os_id
42
+ facts.fetch('ID')
43
+ end
44
+
45
+ def os_id_like_list
46
+ facts.fetch('ID_LIKE', '').split
47
+ end
48
+
49
+ def el?
50
+ File.exist?('/etc/redhat-release')
51
+ end
52
+
53
+ def debian?
54
+ File.exist?('/etc/debian_version')
55
+ end
56
+
57
+ def el7?
58
+ el_major_version == 7
59
+ end
60
+
61
+ def el8?
62
+ el_major_version == 8
63
+ end
64
+
65
+ def el_major_version
66
+ return os_version_id.to_i if el?
67
+ end
68
+ end
69
+ end
70
+ end
@@ -8,6 +8,7 @@ module ForemanMaintain
8
8
  module SystemHelpers
9
9
  include Logger
10
10
  include Concerns::Finders
11
+ include ForemanMaintain::Concerns::OsFacts
11
12
 
12
13
  def self.included(klass)
13
14
  klass.extend(self)
@@ -184,51 +185,24 @@ module ForemanMaintain
184
185
  ForemanMaintain.package_manager
185
186
  end
186
187
 
187
- def os_facts
188
- facter = ForemanMaintain::Utils::Facter.path
189
- @os_facts ||= JSON.parse(execute("#{facter} -j os"))
190
- end
191
-
192
- def el?
193
- os_facts['os']['family'] == 'RedHat'
194
- end
195
-
196
- def debian?
197
- os_facts['os']['family'] == 'Debian'
198
- end
199
-
200
- def el7?
201
- os_facts['os']['release']['major'] == '7' && el?
202
- end
203
-
204
- def el8?
205
- os_facts['os']['release']['major'] == '8' && el?
206
- end
207
-
208
- def el_major_version
209
- return os_facts['os']['release']['major'] if el?
210
- end
211
-
212
188
  def ruby_prefix(scl = true)
213
- if el7? && scl
189
+ if debian?
190
+ 'ruby-'
191
+ elsif el7? && scl
214
192
  'tfm-rubygem-'
215
- elsif el7? || el8?
193
+ else
216
194
  'rubygem-'
217
- elsif debian?
218
- 'ruby-'
219
195
  end
220
196
  end
221
197
 
222
198
  def foreman_plugin_name(plugin)
223
- if debian?
224
- plugin.tr!('_', '-')
225
- end
199
+ plugin = plugin.tr('_', '-') if debian?
226
200
  ruby_prefix + plugin
227
201
  end
228
202
 
229
203
  def proxy_plugin_name(plugin)
230
204
  if debian?
231
- plugin.tr!('_', '-')
205
+ plugin = plugin.tr('_', '-')
232
206
  proxy_plugin_prefix = 'smart-proxy-'
233
207
  else
234
208
  proxy_plugin_prefix = 'smart_proxy_'
@@ -237,6 +211,11 @@ module ForemanMaintain
237
211
  ruby_prefix(scl) + proxy_plugin_prefix + plugin
238
212
  end
239
213
 
214
+ def hammer_plugin_name(plugin)
215
+ plugin = plugin.tr('_', '-') if debian?
216
+ [hammer_package, plugin].join(debian? ? '-' : '_')
217
+ end
218
+
240
219
  def hammer_package
241
220
  hammer_prefix = if debian?
242
221
  'hammer-cli'