foreman_maintain 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/definitions/checks/disk/performance.rb +1 -1
- data/definitions/checks/foreman_openscap/invalid_report_associations.rb +27 -0
- data/definitions/checks/foreman_proxy/verify_dhcp_config_syntax.rb +11 -4
- data/definitions/checks/puppet/provide_upgrade_guide.rb +35 -0
- data/definitions/checks/repositories/validate.rb +3 -0
- data/definitions/features/downstream.rb +27 -10
- data/definitions/features/foreman_openscap.rb +57 -0
- data/definitions/features/foreman_proxy.rb +80 -14
- data/definitions/features/puppet_server.rb +6 -2
- data/definitions/procedures/foreman_openscap/invalid_report_associations.rb +15 -0
- data/definitions/procedures/knowledge_base_article.rb +2 -1
- data/definitions/procedures/remote_execution/remove_existing_settingsd.rb +6 -1
- data/definitions/procedures/repositories/setup.rb +4 -0
- data/definitions/scenarios/upgrade_to_satellite_6_4.rb +1 -0
- data/definitions/scenarios/upgrade_to_satellite_6_4_z.rb +1 -0
- data/lib/foreman_maintain/utils/disk/device.rb +2 -9
- data/lib/foreman_maintain/utils/disk/io_device.rb +38 -0
- data/lib/foreman_maintain/utils/disk.rb +1 -1
- data/lib/foreman_maintain/utils/facter.rb +21 -0
- data/lib/foreman_maintain/utils.rb +1 -0
- data/lib/foreman_maintain/version.rb +1 -1
- data/lib/foreman_maintain.rb +12 -0
- metadata +8 -5
- data/lib/foreman_maintain/utils/disk/io/block_device.rb +0 -40
- data/lib/foreman_maintain/utils/disk/io/file_system.rb +0 -41
- data/lib/foreman_maintain/utils/disk/io.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz: '
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0308a81ffbe17ee43deef021d8a3c43864fb886c'
|
4
|
+
data.tar.gz: 6c9b6d939187e1461b991760d507364500046da1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c75df5e43ecd4f33e2be2bc8b09a809c2931bf7d71657df4964f2d6ffe1ee6c5eb184800f9aa864f3effb524f3ca353dc974323f621c1c1112bd4b174e4697a
|
7
|
+
data.tar.gz: 99795da6683e38730a50c1ba4a286473bd2af075da7ee33a12f4ad045c68d5bc11cbac74fde3056604d3df373a73007e43f20593cfc3911c70f939cc8ea707b3
|
data/README.md
CHANGED
@@ -257,11 +257,11 @@ end
|
|
257
257
|
class Checks::DiskIO < ForemanMaintain::Check
|
258
258
|
metadata do
|
259
259
|
description 'check foreman service is running'
|
260
|
-
preparation_steps { Procedures::InstallPackage.new(:packages => %w[
|
260
|
+
preparation_steps { Procedures::InstallPackage.new(:packages => %w[fio]) }
|
261
261
|
end
|
262
262
|
|
263
263
|
def run
|
264
|
-
execute!('
|
264
|
+
execute!('fio ...')
|
265
265
|
end
|
266
266
|
end
|
267
267
|
```
|
@@ -5,7 +5,7 @@ module Checks
|
|
5
5
|
label :disk_performance
|
6
6
|
description 'Check for recommended disk speed of pulp, mongodb, pgsql dir.'
|
7
7
|
tags :pre_upgrade
|
8
|
-
preparation_steps { Procedures::Packages::Install.new(:packages => %w[
|
8
|
+
preparation_steps { Procedures::Packages::Install.new(:packages => %w[fio]) }
|
9
9
|
|
10
10
|
confine do
|
11
11
|
feature(:pulp)
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Checks
|
2
|
+
module ForemanOpenscap
|
3
|
+
class InvalidReportAssociations < ForemanMaintain::Check
|
4
|
+
metadata do
|
5
|
+
label :openscap_report_associations
|
6
|
+
for_feature :foreman_openscap
|
7
|
+
description 'Check whether reports have correct associations'
|
8
|
+
tags :pre_upgrade, :foreman_openscap, :openscap_report_associations
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
ids_to_remove = to_remove
|
13
|
+
assert(ids_to_remove.empty?,
|
14
|
+
"There are #{ids_to_remove.count} reports with issues that will be removed",
|
15
|
+
:next_steps => Procedures::ForemanOpenscap::InvalidReportAssociations.new(
|
16
|
+
:ids_to_remove => ids_to_remove
|
17
|
+
))
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_remove
|
21
|
+
(feature(:foreman_openscap).report_ids_without_policy +
|
22
|
+
feature(:foreman_openscap).report_ids_without_proxy +
|
23
|
+
feature(:foreman_openscap).report_ids_without_host).uniq
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,17 +1,24 @@
|
|
1
1
|
module Checks::ForemanProxy
|
2
2
|
class VerifyDhcpConfigSyntax < ForemanMaintain::Check
|
3
3
|
metadata do
|
4
|
-
for_feature :foreman_proxy
|
5
4
|
description 'Check for verifying syntax for ISP DHCP configurations'
|
6
5
|
tags :default
|
7
6
|
confine do
|
8
|
-
|
7
|
+
feature(:foreman_proxy)
|
9
8
|
end
|
10
9
|
end
|
11
10
|
|
12
11
|
def run
|
13
|
-
|
14
|
-
|
12
|
+
if feature(:foreman_proxy).features.include?('dhcp')
|
13
|
+
if feature(:foreman_proxy).dhcpd_conf_exist?
|
14
|
+
success = feature(:foreman_proxy).valid_dhcp_configs?
|
15
|
+
assert(success, 'Please check and verify DHCP configurations.')
|
16
|
+
else
|
17
|
+
fail! "Couldn't find configuration file at #{feature(:foreman_proxy).dhcpd_config_file}"
|
18
|
+
end
|
19
|
+
else
|
20
|
+
skip 'DHCP feature is not enabled'
|
21
|
+
end
|
15
22
|
end
|
16
23
|
end
|
17
24
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Checks::Puppet
|
2
|
+
class ProvideUpgradeGuide < ForemanMaintain::Check
|
3
|
+
metadata do
|
4
|
+
description 'Verify puppet and provide upgrade guide for it'
|
5
|
+
tags :puppet_upgrade_guide
|
6
|
+
confine do
|
7
|
+
feature(:downstream) &&
|
8
|
+
feature(:downstream).current_minor_version == '6.3' &&
|
9
|
+
find_package('puppet')
|
10
|
+
end
|
11
|
+
manual_detection
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
with_spinner('Verifying puppet version before upgrade') do |spinner|
|
16
|
+
puppet_package = find_package('puppet')
|
17
|
+
spinner.update "current puppet version: #{puppet_package}"
|
18
|
+
curr_sat_version = feature(:downstream).current_minor_version
|
19
|
+
assert(
|
20
|
+
(puppet_package !~ /puppet-3/),
|
21
|
+
'Before continuing with upgrade, please make sure you finish puppet upgrade.',
|
22
|
+
:next_steps => [
|
23
|
+
Procedures::KnowledgeBaseArticle.new(:doc => doc_ids_by_sat_versions[curr_sat_version])
|
24
|
+
]
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def doc_ids_by_sat_versions
|
32
|
+
{ '6.3' => 'upgrade_puppet_guide_for_sat63' }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -2,6 +2,9 @@ module Checks::Repositories
|
|
2
2
|
class Validate < ForemanMaintain::Check
|
3
3
|
metadata do
|
4
4
|
description 'Validate availability of repositories'
|
5
|
+
preparation_steps do
|
6
|
+
Procedures::Packages::Install.new(:packages => [ForemanMaintain::Utils::Facter.package])
|
7
|
+
end
|
5
8
|
|
6
9
|
confine do
|
7
10
|
feature(:downstream)
|
@@ -54,23 +54,40 @@ class Features::Downstream < ForemanMaintain::Feature
|
|
54
54
|
|
55
55
|
def rh_repos(sat_version)
|
56
56
|
sat_version = version(sat_version)
|
57
|
-
rh_version_major =
|
58
|
-
|
57
|
+
rh_version_major = ForemanMaintain::Utils::Facter.os_major_release
|
58
|
+
|
59
|
+
rh_repos = main_rh_repos(rh_version_major)
|
60
|
+
|
61
|
+
rh_repos.concat(sat_and_tools_repos(rh_version_major, sat_version))
|
62
|
+
|
63
|
+
rh_repos << 'rhel-7-server-ansible-2-rpms' if sat_version.to_s == '6.4'
|
64
|
+
|
65
|
+
if current_minor_version == '6.3' && sat_version.to_s != '6.4' && (
|
66
|
+
feature(:puppet_server) && feature(:puppet_server).puppet_version.major == 4)
|
67
|
+
rh_repos << "rhel-#{rh_version_major}-server-satellite-tools-6.3-puppet4-rpms"
|
68
|
+
end
|
69
|
+
|
70
|
+
rh_repos
|
71
|
+
end
|
59
72
|
|
73
|
+
def sat_and_tools_repos(rh_version_major, sat_version)
|
74
|
+
sat_version_full = "#{sat_version.major}.#{sat_version.minor}"
|
60
75
|
sat_repo_id = "rhel-#{rh_version_major}-server-satellite-#{sat_version_full}-rpms"
|
61
76
|
sat_tools_repo_id = "rhel-#{rh_version_major}-server-satellite-tools-#{sat_version_full}-rpms"
|
62
|
-
|
77
|
+
|
78
|
+
# Override to use Beta repositories for sat version until GA
|
63
79
|
if sat_version.to_s == '6.4'
|
64
80
|
sat_repo_id = "rhel-server-#{rh_version_major}-satellite-6-beta-rpms"
|
81
|
+
sat_tools_repo_id = "rhel-#{rh_version_major}-server-satellite-tools-6-beta-rpms"
|
65
82
|
end
|
66
83
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
84
|
+
[sat_repo_id, sat_tools_repo_id]
|
85
|
+
end
|
86
|
+
|
87
|
+
def main_rh_repos(rh_version_major)
|
88
|
+
["rhel-#{rh_version_major}-server-rpms",
|
89
|
+
"rhel-server-rhscl-#{rh_version_major}-rpms",
|
90
|
+
"rhel-#{rh_version_major}-server-satellite-maintenance-6-rpms"]
|
74
91
|
end
|
75
92
|
|
76
93
|
def version_from_source
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Features::ForemanOpenscap < ForemanMaintain::Feature
|
2
|
+
metadata do
|
3
|
+
label :foreman_openscap
|
4
|
+
|
5
|
+
confine do
|
6
|
+
check_min_version('tfm-rubygem-foreman_openscap', '0.5.3')
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def report_ids_without_host
|
11
|
+
reports_without_attribute('host_id')
|
12
|
+
end
|
13
|
+
|
14
|
+
def report_ids_without_proxy
|
15
|
+
reports_without_attribute('openscap_proxy_id')
|
16
|
+
end
|
17
|
+
|
18
|
+
def report_ids_without_policy
|
19
|
+
sql = <<-SQL
|
20
|
+
SELECT id
|
21
|
+
FROM reports
|
22
|
+
WHERE id
|
23
|
+
NOT IN (
|
24
|
+
SELECT reports.id
|
25
|
+
FROM reports INNER JOIN foreman_openscap_policy_arf_reports
|
26
|
+
ON reports.id = foreman_openscap_policy_arf_reports.arf_report_id
|
27
|
+
WHERE reports.type = 'ForemanOpenscap::ArfReport'
|
28
|
+
)
|
29
|
+
AND type = 'ForemanOpenscap::ArfReport'
|
30
|
+
SQL
|
31
|
+
execute_ids_query sql
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete_reports(ids)
|
35
|
+
feature(:foreman_database).psql(<<-SQL)
|
36
|
+
BEGIN;
|
37
|
+
DELETE FROM reports WHERE id IN (#{ids.join(', ')});
|
38
|
+
DELETE FROM foreman_openscap_policy_arf_reports WHERE arf_report_id IN (#{ids.join(', ')});
|
39
|
+
COMMIT;
|
40
|
+
SQL
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def reports_without_attribute(attr)
|
46
|
+
sql = <<-SQL
|
47
|
+
SELECT id
|
48
|
+
FROM reports
|
49
|
+
WHERE type = 'ForemanOpenscap::ArfReport' AND #{attr} IS NULL
|
50
|
+
SQL
|
51
|
+
execute_ids_query sql
|
52
|
+
end
|
53
|
+
|
54
|
+
def execute_ids_query(sql)
|
55
|
+
feature(:foreman_database).query(sql).map { |item| item['id'].to_i } || []
|
56
|
+
end
|
57
|
+
end
|
@@ -6,12 +6,11 @@ class Features::ForemanProxy < ForemanMaintain::Feature
|
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
FOREMAN_PROXY_SETTINGS_PATHS = ['/etc/foreman-proxy/settings.yml',
|
10
|
+
'/usr/local/etc/foreman-proxy/settings.yml'].freeze
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
@cert_path = ForemanMaintain.config.foreman_proxy_cert_path
|
14
|
-
end
|
12
|
+
FOREMAN_PROXY_DHCP_YML_PATHS = ['/etc/foreman-proxy/settings.d/dhcp.yml',
|
13
|
+
'/usr/local/etc/foreman-proxy/settings.d/dhcp.yml'].freeze
|
15
14
|
|
16
15
|
def valid_dhcp_configs?
|
17
16
|
dhcp_req_pass? && !syntax_error_exists?
|
@@ -21,6 +20,10 @@ class Features::ForemanProxy < ForemanMaintain::Feature
|
|
21
20
|
!!feature(:pulp)
|
22
21
|
end
|
23
22
|
|
23
|
+
def dhcpd_conf_exist?
|
24
|
+
file_exists?(dhcpd_config_file)
|
25
|
+
end
|
26
|
+
|
24
27
|
def services
|
25
28
|
{
|
26
29
|
'foreman-proxy' => 20,
|
@@ -37,21 +40,28 @@ class Features::ForemanProxy < ForemanMaintain::Feature
|
|
37
40
|
!!feature(:foreman_server)
|
38
41
|
end
|
39
42
|
|
40
|
-
def
|
41
|
-
|
43
|
+
def default_config_files
|
44
|
+
[
|
42
45
|
'/etc/foreman-proxy',
|
43
46
|
'/usr/share/foreman-proxy/.ssh',
|
44
47
|
'/var/lib/foreman-proxy/ssh',
|
45
48
|
'/etc/smart_proxy_dynflow_core/settings.yml',
|
46
|
-
'/etc/sudoers.d/foreman-proxy'
|
49
|
+
'/etc/sudoers.d/foreman-proxy',
|
50
|
+
settings_file
|
47
51
|
]
|
52
|
+
end
|
53
|
+
|
54
|
+
def config_files(for_features = ['all'])
|
55
|
+
configs = default_config_files
|
48
56
|
backup_features = backup_features(for_features)
|
49
57
|
|
50
58
|
configs.push(certs_tar) if certs_tar
|
51
59
|
|
52
60
|
configs.push('/var/lib/tftpboot') if backup_features.include?('tftp')
|
53
61
|
configs += ['/var/named/', '/etc/named*'] if backup_features.include?('dns')
|
54
|
-
|
62
|
+
if backup_features.include?('dhcp')
|
63
|
+
configs += ['/var/lib/dhcpd', File.dirname(dhcpd_config_file)]
|
64
|
+
end
|
55
65
|
configs.push('/usr/share/xml/scap') if backup_features.include?('openscap')
|
56
66
|
configs
|
57
67
|
end
|
@@ -71,6 +81,18 @@ class Features::ForemanProxy < ForemanMaintain::Feature
|
|
71
81
|
feature(:installer).answers[content_module]['certs_tar'] if content_module
|
72
82
|
end
|
73
83
|
|
84
|
+
def settings_file
|
85
|
+
@settings_file ||= lookup_into(FOREMAN_PROXY_SETTINGS_PATHS)
|
86
|
+
end
|
87
|
+
|
88
|
+
def proxy_settings
|
89
|
+
@proxy_settings ||= load_proxy_settings
|
90
|
+
end
|
91
|
+
|
92
|
+
def dhcpd_config_file
|
93
|
+
@dhcpd_config_file ||= lookup_dhcpd_config_file
|
94
|
+
end
|
95
|
+
|
74
96
|
private
|
75
97
|
|
76
98
|
def backup_features(for_features)
|
@@ -82,9 +104,14 @@ class Features::ForemanProxy < ForemanMaintain::Feature
|
|
82
104
|
end
|
83
105
|
|
84
106
|
def curl_cmd
|
85
|
-
|
86
|
-
|
87
|
-
|
107
|
+
ssl_cert = proxy_settings[:foreman_ssl_cert] || proxy_settings[:ssl_certificate]
|
108
|
+
ssl_key = proxy_settings[:foreman_ssl_key] || proxy_settings[:ssl_private_key]
|
109
|
+
ssl_ca = proxy_settings[:foreman_ssl_ca] || proxy_settings[:ssl_ca_file]
|
110
|
+
|
111
|
+
cmd = "curl -w '\n%{http_code}' -s "
|
112
|
+
cmd += format_shell_args('--cert' => ssl_cert, '--key' => ssl_key, '--cacert' => ssl_ca)
|
113
|
+
cmd += " https://$(hostname):#{proxy_settings[:https_port]}"
|
114
|
+
cmd
|
88
115
|
end
|
89
116
|
|
90
117
|
def dhcp_curl_cmd
|
@@ -136,13 +163,52 @@ class Features::ForemanProxy < ForemanMaintain::Feature
|
|
136
163
|
end
|
137
164
|
|
138
165
|
def syntax_error_exists?
|
139
|
-
cmd = "dhcpd -t -cf #{
|
166
|
+
cmd = "dhcpd -t -cf #{dhcpd_config_file}"
|
140
167
|
output = execute(cmd)
|
141
168
|
is_error = output.include?('Configuration file errors encountered')
|
142
169
|
if is_error
|
143
|
-
puts "\nFound syntax error in file #{
|
170
|
+
puts "\nFound syntax error in file #{dhcpd_config_file}:"
|
144
171
|
puts output
|
145
172
|
end
|
146
173
|
is_error
|
147
174
|
end
|
175
|
+
|
176
|
+
def load_proxy_settings
|
177
|
+
if settings_file
|
178
|
+
@proxy_settings = yaml_load(settings_file)
|
179
|
+
else
|
180
|
+
raise "Couldn't find settings file at #{FOREMAN_PROXY_SETTINGS_PATHS.join(', ')}"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def lookup_dhcpd_config_file
|
185
|
+
dhcpd_config_file = lookup_using_dhcp_yml
|
186
|
+
raise "Couldn't find DHCP Configuration file" if dhcpd_config_file.nil?
|
187
|
+
dhcpd_config_file
|
188
|
+
end
|
189
|
+
|
190
|
+
def lookup_using_dhcp_yml
|
191
|
+
dhcp_yml_path = lookup_into(FOREMAN_PROXY_DHCP_YML_PATHS)
|
192
|
+
raise "Couldn't find dhcp.yml file under foreman-proxy" unless dhcp_yml_path
|
193
|
+
|
194
|
+
configs_from_dhcp_yml = yaml_load(dhcp_yml_path)
|
195
|
+
if configs_from_dhcp_yml.key?(:dhcp_config)
|
196
|
+
return configs_from_dhcp_yml[:dhcp_config]
|
197
|
+
elsif configs_from_dhcp_yml.key?(:use_provider)
|
198
|
+
settings_d_dir = File.dirname(dhcp_yml_path)
|
199
|
+
dhcp_provider_fpath = File.join(settings_d_dir, "#{configs_from_dhcp_yml[:use_provider]}.yml")
|
200
|
+
dhcp_provider_configs = yaml_load(dhcp_provider_fpath)
|
201
|
+
return dhcp_provider_configs[:config] if dhcp_provider_configs.key?(:config)
|
202
|
+
else
|
203
|
+
raise "Couldn't find DHCP Configurations in #{dhcp_yml_path}"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def yaml_load(path)
|
208
|
+
YAML.load_file(path) || {}
|
209
|
+
end
|
210
|
+
|
211
|
+
def lookup_into(file_paths)
|
212
|
+
file_paths.find { |file_path| file_exists?(file_path) }
|
213
|
+
end
|
148
214
|
end
|
@@ -6,11 +6,15 @@ class Features::PuppetServer < ForemanMaintain::Feature
|
|
6
6
|
# is a part of httpd and relies on httpd service to restart, therefore
|
7
7
|
# not requiring a separate service to restart
|
8
8
|
confine do
|
9
|
-
find_package('puppetserver')
|
9
|
+
find_package('puppetserver') || find_package('puppet')
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
13
|
def services
|
14
|
-
{ 'puppetserver' => 30 }
|
14
|
+
find_package('puppetserver') ? { 'puppetserver' => 30 } : {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def puppet_version
|
18
|
+
version(execute!('puppet --version'))
|
15
19
|
end
|
16
20
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Procedures::ForemanOpenscap
|
2
|
+
class InvalidReportAssociations < ForemanMaintain::Procedure
|
3
|
+
metadata do
|
4
|
+
param :ids_to_remove, 'Ids of reports to remove', :required => true
|
5
|
+
for_feature :foreman_openscap
|
6
|
+
tags :pre_migration, :foreman_openscap, :openscap_report_associations
|
7
|
+
advanced_run false
|
8
|
+
description 'Delete reports with association issues'
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
feature(:foreman_openscap).delete_reports(@ids_to_remove)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -23,7 +23,8 @@ class Procedures::KnowledgeBaseArticle < ForemanMaintain::Procedure
|
|
23
23
|
|
24
24
|
def kcs_documents
|
25
25
|
{
|
26
|
-
'fix_cpdb_validate_failure' => 'https://access.redhat.com/solutions/3362821'
|
26
|
+
'fix_cpdb_validate_failure' => 'https://access.redhat.com/solutions/3362821',
|
27
|
+
'upgrade_puppet_guide_for_sat63' => 'https://access.redhat.com/documentation/en-us/red_hat_satellite/6.3/html/upgrading_and_updating_red_hat_satellite/upgrading_puppet-1'
|
27
28
|
}
|
28
29
|
end
|
29
30
|
end
|
@@ -11,7 +11,12 @@ module Procedures::RemoteExecution
|
|
11
11
|
|
12
12
|
def run
|
13
13
|
with_spinner("Removing existing #{@dirpath} directory") do |_spinner|
|
14
|
-
|
14
|
+
if Dir.pwd.strip.eql?(@dirpath)
|
15
|
+
fail! "Failed: You are trying to delete the current directory '#{@dirpath}' "\
|
16
|
+
'which is not possible'
|
17
|
+
else
|
18
|
+
execute!("rm -rf #{@dirpath}")
|
19
|
+
end
|
15
20
|
end
|
16
21
|
end
|
17
22
|
end
|
@@ -2,6 +2,10 @@ module Procedures::Repositories
|
|
2
2
|
class Setup < ForemanMaintain::Procedure
|
3
3
|
metadata do
|
4
4
|
description 'Setup repositories'
|
5
|
+
preparation_steps do
|
6
|
+
Procedures::Packages::Install.new(:packages => [ForemanMaintain::Utils::Facter.package])
|
7
|
+
end
|
8
|
+
|
5
9
|
confine do
|
6
10
|
feature(:downstream) || feature(:upstream)
|
7
11
|
end
|
@@ -17,7 +17,8 @@ module ForemanMaintain
|
|
17
17
|
def initialize(dir)
|
18
18
|
@dir = dir
|
19
19
|
@name = find_device
|
20
|
-
|
20
|
+
logger.info "#{dir} is externally mounted" if externally_mounted?
|
21
|
+
@io_device = IODevice.new(dir)
|
21
22
|
end
|
22
23
|
|
23
24
|
def slow_disk_error_msg
|
@@ -32,14 +33,6 @@ module ForemanMaintain
|
|
32
33
|
|
33
34
|
private
|
34
35
|
|
35
|
-
def init_io_device
|
36
|
-
if externally_mounted?
|
37
|
-
IO::FileSystem
|
38
|
-
else
|
39
|
-
IO::BlockDevice
|
40
|
-
end.new(dir, name)
|
41
|
-
end
|
42
|
-
|
43
36
|
def externally_mounted?
|
44
37
|
device_type = execute("stat -f -c %T #{dir}")
|
45
38
|
EXTERNAL_MOUNT_TYPE.include?(device_type)
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module ForemanMaintain
|
2
|
+
module Utils
|
3
|
+
module Disk
|
4
|
+
class IODevice
|
5
|
+
include ForemanMaintain::Concerns::SystemHelpers
|
6
|
+
|
7
|
+
attr_accessor :dir
|
8
|
+
|
9
|
+
def initialize(dir)
|
10
|
+
@dir = dir
|
11
|
+
end
|
12
|
+
|
13
|
+
def read_speed
|
14
|
+
@read_speed ||= convert_kb_to_mb(fio)
|
15
|
+
end
|
16
|
+
|
17
|
+
def unit
|
18
|
+
@unit ||= 'MB/sec'
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
# In fio command, --direct option bypass the cache page
|
24
|
+
def fio
|
25
|
+
cmd = "fio --name=job1 --rw=read --size=1g --output-format=json\
|
26
|
+
--directory=#{dir} --direct=1"
|
27
|
+
stdout = execute(cmd)
|
28
|
+
output = JSON.parse(stdout)
|
29
|
+
@fio ||= output['jobs'].first['read']['bw'].to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def convert_kb_to_mb(val)
|
33
|
+
val / 1024
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ForemanMaintain::Utils
|
2
|
+
module Facter
|
3
|
+
include ForemanMaintain::Concerns::SystemHelpers
|
4
|
+
|
5
|
+
FACTER_FILES = %w[/usr/bin/facter /opt/puppetlabs/bin/facter].freeze
|
6
|
+
|
7
|
+
def self.package
|
8
|
+
puppet_version = version(execute!('puppet --version'))
|
9
|
+
|
10
|
+
puppet_version.major >= 4 ? 'puppet-agent' : 'facter'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.path
|
14
|
+
FACTER_FILES.find { |path| File.exist?(path) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.os_major_release
|
18
|
+
execute!("#{path} operatingsystemmajrelease")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/foreman_maintain.rb
CHANGED
@@ -53,6 +53,18 @@ module ForemanMaintain
|
|
53
53
|
self.config = Config.new(options)
|
54
54
|
load_definitions
|
55
55
|
init_logger
|
56
|
+
update_path
|
57
|
+
end
|
58
|
+
|
59
|
+
# Appending PATH with expected paths needed for commands we run
|
60
|
+
def update_path
|
61
|
+
paths = ['/sbin']
|
62
|
+
existing_paths = ENV['PATH'].split(':')
|
63
|
+
paths -= existing_paths
|
64
|
+
if paths.any?
|
65
|
+
paths = paths.join(':').chomp(':')
|
66
|
+
ENV['PATH'] = "#{ENV['PATH']}:#{paths}"
|
67
|
+
end
|
56
68
|
end
|
57
69
|
|
58
70
|
def config_file
|
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.2.
|
4
|
+
version: 0.2.3
|
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: 2018-
|
11
|
+
date: 2018-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clamp
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- definitions/checks/check_epel_repository.rb
|
121
121
|
- definitions/checks/disk/performance.rb
|
122
122
|
- definitions/checks/foreman/db_up.rb
|
123
|
+
- definitions/checks/foreman_openscap/invalid_report_associations.rb
|
123
124
|
- definitions/checks/foreman_proxy/verify_dhcp_config_syntax.rb
|
124
125
|
- definitions/checks/foreman_tasks/invalid/check_old.rb
|
125
126
|
- definitions/checks/foreman_tasks/invalid/check_pending_state.rb
|
@@ -129,6 +130,7 @@ files:
|
|
129
130
|
- definitions/checks/hammer_ping.rb
|
130
131
|
- definitions/checks/mongo/db_up.rb
|
131
132
|
- definitions/checks/mongo/tools_installed.rb
|
133
|
+
- definitions/checks/puppet/provide_upgrade_guide.rb
|
132
134
|
- definitions/checks/remote_execution/verify_settings_file_already_exists.rb
|
133
135
|
- definitions/checks/repositories/validate.rb
|
134
136
|
- definitions/checks/restore/validate_backup.rb
|
@@ -141,6 +143,7 @@ files:
|
|
141
143
|
- definitions/features/foreman_1_11_x.rb
|
142
144
|
- definitions/features/foreman_1_7_x.rb
|
143
145
|
- definitions/features/foreman_database.rb
|
146
|
+
- definitions/features/foreman_openscap.rb
|
144
147
|
- definitions/features/foreman_proxy.rb
|
145
148
|
- definitions/features/foreman_server.rb
|
146
149
|
- definitions/features/foreman_tasks.rb
|
@@ -180,6 +183,7 @@ files:
|
|
180
183
|
- definitions/procedures/backup/snapshot/mount_pulp.rb
|
181
184
|
- definitions/procedures/backup/snapshot/prepare_mount.rb
|
182
185
|
- definitions/procedures/candlepin/delete_orphaned_records_from_env_content.rb
|
186
|
+
- definitions/procedures/foreman_openscap/invalid_report_associations.rb
|
183
187
|
- definitions/procedures/foreman_tasks/delete.rb
|
184
188
|
- definitions/procedures/foreman_tasks/fetch_tasks_status.rb
|
185
189
|
- definitions/procedures/foreman_tasks/resume.rb
|
@@ -275,11 +279,10 @@ files:
|
|
275
279
|
- lib/foreman_maintain/utils/curl_response.rb
|
276
280
|
- lib/foreman_maintain/utils/disk.rb
|
277
281
|
- lib/foreman_maintain/utils/disk/device.rb
|
278
|
-
- lib/foreman_maintain/utils/disk/
|
279
|
-
- lib/foreman_maintain/utils/disk/io/block_device.rb
|
280
|
-
- lib/foreman_maintain/utils/disk/io/file_system.rb
|
282
|
+
- lib/foreman_maintain/utils/disk/io_device.rb
|
281
283
|
- lib/foreman_maintain/utils/disk/nil_device.rb
|
282
284
|
- lib/foreman_maintain/utils/disk/stats.rb
|
285
|
+
- lib/foreman_maintain/utils/facter.rb
|
283
286
|
- lib/foreman_maintain/utils/hash_tools.rb
|
284
287
|
- lib/foreman_maintain/utils/mongo_core.rb
|
285
288
|
- lib/foreman_maintain/version.rb
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module ForemanMaintain
|
2
|
-
module Utils
|
3
|
-
module Disk
|
4
|
-
module IO
|
5
|
-
class BlockDevice
|
6
|
-
include ForemanMaintain::Concerns::SystemHelpers
|
7
|
-
|
8
|
-
attr_accessor :dir, :name
|
9
|
-
|
10
|
-
def initialize(dir, name = Disk::Device.new('/var').name)
|
11
|
-
@dir = dir
|
12
|
-
@name = name
|
13
|
-
end
|
14
|
-
|
15
|
-
def read_speed
|
16
|
-
@read_speed ||= extract_speed(hdparm)
|
17
|
-
end
|
18
|
-
|
19
|
-
def unit
|
20
|
-
@unit ||= extract_unit(hdparm)
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
def hdparm
|
26
|
-
@stdout ||= execute("hdparm -t #{name} | awk 'NF'")
|
27
|
-
end
|
28
|
-
|
29
|
-
def extract_unit(stdout)
|
30
|
-
stdout.split(' ').last
|
31
|
-
end
|
32
|
-
|
33
|
-
def extract_speed(stdout)
|
34
|
-
stdout.split(' ').reverse[1].to_i
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module ForemanMaintain
|
2
|
-
module Utils
|
3
|
-
module Disk
|
4
|
-
module IO
|
5
|
-
class FileSystem
|
6
|
-
include ForemanMaintain::Concerns::SystemHelpers
|
7
|
-
|
8
|
-
attr_accessor :dir, :name
|
9
|
-
|
10
|
-
def initialize(dir, name = '')
|
11
|
-
@dir = dir
|
12
|
-
@name = name
|
13
|
-
end
|
14
|
-
|
15
|
-
def read_speed
|
16
|
-
@read_speed ||= convert_kb_to_mb(fio)
|
17
|
-
end
|
18
|
-
|
19
|
-
def unit
|
20
|
-
@unit ||= 'MB/sec'
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# In fio command, --direct option bypass the cache page
|
26
|
-
def fio
|
27
|
-
cmd = "fio --name=job1 --rw=read --size=1g --output-format=json\
|
28
|
-
--directory=#{dir} --direct=1"
|
29
|
-
stdout = execute(cmd)
|
30
|
-
output = JSON.parse(stdout)
|
31
|
-
@fio ||= output['jobs'].first['read']['bw'].to_i
|
32
|
-
end
|
33
|
-
|
34
|
-
def convert_kb_to_mb(val)
|
35
|
-
val / 1024
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|