foreman_maintain 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/definitions/checks/disk_speed_minimal.rb +9 -5
  4. data/definitions/checks/foreman_tasks/not_running.rb +20 -2
  5. data/definitions/checks/hammer_ping.rb +16 -0
  6. data/definitions/checks/system_registration.rb +8 -8
  7. data/definitions/features/downstream.rb +9 -1
  8. data/definitions/features/foreman_proxy.rb +4 -1
  9. data/definitions/features/foreman_server.rb +12 -0
  10. data/definitions/features/foreman_tasks.rb +49 -4
  11. data/definitions/features/hammer.rb +55 -0
  12. data/definitions/features/katello.rb +17 -0
  13. data/definitions/features/katello_service.rb +54 -5
  14. data/definitions/procedures/foreman_tasks/fetch_tasks_status.rb +15 -0
  15. data/definitions/procedures/foreman_tasks/ui_investigate.rb +1 -1
  16. data/definitions/procedures/katello_service/restart.rb +24 -0
  17. data/definitions/procedures/katello_service/start.rb +19 -0
  18. data/definitions/procedures/katello_service/stop.rb +17 -0
  19. data/definitions/scenarios/upgrade_to_satellite_6_2.rb +3 -1
  20. data/definitions/scenarios/upgrade_to_satellite_6_2_z.rb +3 -1
  21. data/definitions/scenarios/upgrade_to_satellite_6_3.rb +3 -1
  22. data/definitions/scenarios/upgrade_to_satellite_6_3_z.rb +3 -1
  23. data/lib/foreman_maintain/cli/advanced/procedure/abstract_by_tag_command.rb +2 -2
  24. data/lib/foreman_maintain/cli/transform_clamp_options.rb +2 -2
  25. data/lib/foreman_maintain/cli/upgrade_command.rb +6 -1
  26. data/lib/foreman_maintain/concerns/system_helpers.rb +67 -45
  27. data/lib/foreman_maintain/config.rb +2 -2
  28. data/lib/foreman_maintain/detector.rb +1 -1
  29. data/lib/foreman_maintain/executable.rb +1 -3
  30. data/lib/foreman_maintain/runner/execution.rb +1 -1
  31. data/lib/foreman_maintain/utils/disk/io/block_device.rb +1 -1
  32. data/lib/foreman_maintain/utils/disk/io/file_system.rb +1 -1
  33. data/lib/foreman_maintain/version.rb +1 -1
  34. data/lib/foreman_maintain.rb +2 -1
  35. metadata +11 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b7df7b95f8a1a9903c19af1e5b49ccfa40008e73
4
- data.tar.gz: 70e9f58bfac04116906fb43b19b37c1cd93dc1df
3
+ metadata.gz: 6541f1ff74d6b4f49f684fdf4a90169407fff41c
4
+ data.tar.gz: 0de3f21c5ec4b3f20da234dd4ab6de64914e1da4
5
5
  SHA512:
6
- metadata.gz: a0aa83732512f0daa0d549d805c5ad354df123ac54731e7650912f928bde6ab7ef82a9c59e15da33df4dbf2f3e40ef5a68ebee3e5d028e3290a23c7f7d7a0a2a
7
- data.tar.gz: 6b311731eff01767e2aac5ed8cccd45e9e49f019b292e7bde6b59a28300816426f2dcd260549dfe5a716104d5076eda0873562d0ae7483686f015ad563305224
6
+ metadata.gz: c728131aed58b4939b2d8b2e1d4c0df2adfa192a28523643072ee16a1348f9136feb178987bd4a230ffc123adad54298be86697b6a657956c6c970c49313bb25
7
+ data.tar.gz: 643d48edb17bd4d7dafc84fd0a80b0404152c9ee77b834b88a4d10c960c107fe5b71bdb2da5a0801552d4cc31017bbe870f55c7b0b1f4154e79a62e2c7dd6ede
data/README.md CHANGED
@@ -85,7 +85,7 @@ state of the system.
85
85
 
86
86
  #### Satellite notes
87
87
 
88
- To use custom organzation/activation key for configuring repositories during
88
+ To use custom organization/activation key for configuring repositories during
89
89
  upgrade, set the following environment variables
90
90
 
91
91
  ```
@@ -116,7 +116,7 @@ The definitions for this components are present in `definitions` folder.
116
116
  ### Features
117
117
 
118
118
  Before `foreman_maintain` starts, it takes the set of `features` definition
119
- and determines their pesence by running their `confine` blocks against
119
+ and determines their presence by running their `confine` blocks against
120
120
  the system.
121
121
 
122
122
  The `confine` block can run an external command to check if the feature
@@ -154,7 +154,7 @@ scenarios) from version-specific nuances.
154
154
  Checks define assertions to determine status of the system.
155
155
 
156
156
  ```ruby
157
- class Checks::ForemanIsRuning < ForemanMaintain::Check
157
+ class Checks::ForemanIsRunning < ForemanMaintain::Check
158
158
  metadata do
159
159
  for_feature :foreman
160
160
  description 'check foreman service is running'
@@ -3,12 +3,16 @@ class Checks::DiskSpeedMinimal < ForemanMaintain::Check
3
3
  label :disk_io
4
4
  description 'Check for recommended disk speed of pulp, mongodb, pgsql dir.'
5
5
  tags :pre_upgrade
6
+
6
7
  preparation_steps { Procedures::Packages::Install.new(:packages => %w[hdparm fio]) }
8
+
9
+ confine do
10
+ feature(:katello)
11
+ end
7
12
  end
8
13
 
9
14
  EXPECTED_IO = 80
10
- DEFAULT_UNIT = 'MB/sec'.freeze
11
- DEFAULT_DIRS = ['/var/lib/pulp', '/var/lib/mongodb', '/var/lib/pgsql'].freeze
15
+ DEFAULT_UNIT = 'MB/sec'.freeze
12
16
 
13
17
  def run
14
18
  with_spinner(description) do |spinner|
@@ -20,14 +24,14 @@ class Checks::DiskSpeedMinimal < ForemanMaintain::Check
20
24
  end
21
25
 
22
26
  def check_only_single_device?
23
- DEFAULT_DIRS.map do |dir|
27
+ feature(:katello).data_dirs.map do |dir|
24
28
  ForemanMaintain::Utils::Disk::Device.new(dir).name
25
29
  end.uniq.length <= 1
26
30
  end
27
31
 
28
32
  def dirs_to_check
29
- return DEFAULT_DIRS.first(1) if check_only_single_device?
30
- DEFAULT_DIRS
33
+ return feature(:katello).data_dirs.first(1) if check_only_single_device?
34
+ feature(:katello).data_dirs
31
35
  end
32
36
 
33
37
  private
@@ -9,8 +9,26 @@ module Checks::ForemanTasks
9
9
  end
10
10
 
11
11
  def run
12
- assert(feature(:foreman_tasks).running_tasks_count == 0,
13
- 'There are actively running tasks in the system')
12
+ task_count = feature(:foreman_tasks).running_tasks_count
13
+ assert(task_count == 0,
14
+ failure_message(task_count),
15
+ :next_steps =>
16
+ [Procedures::ForemanTasks::FetchTasksStatus.new(:state => 'running'),
17
+ Procedures::ForemanTasks::UiInvestigate.new(
18
+ 'search_query' => search_query_for_running_tasks
19
+ )])
20
+ end
21
+
22
+ private
23
+
24
+ def search_query_for_running_tasks
25
+ 'state = running AND '\
26
+ "label !^(#{Features::ForemanTasks::EXCLUDE_ACTIONS_FOR_RUNNING_TASKS.join(' ')})"
27
+ end
28
+
29
+ def failure_message(task_count)
30
+ "There are #{task_count} active task(s) in the system." \
31
+ "\nPlease wait for these to complete or cancel them from the Monitor tab."
14
32
  end
15
33
  end
16
34
  end
@@ -0,0 +1,16 @@
1
+ class Checks::HammerPing < ForemanMaintain::Check
2
+ include ForemanMaintain::Concerns::Hammer
3
+ metadata do
4
+ label :hammer_ping
5
+ for_feature :hammer
6
+ description 'Check whether all services are running using hammer ping'
7
+ tags :default
8
+ end
9
+
10
+ def run
11
+ result = feature(:hammer).hammer_ping_cmd
12
+ assert(result[:success],
13
+ result[:message],
14
+ :next_steps => Procedures::KatelloService::Restart.new(:only => result[:data]))
15
+ end
16
+ end
@@ -5,22 +5,18 @@ class Checks::SystemRegistration < ForemanMaintain::Check
5
5
  tags :default
6
6
 
7
7
  confine do
8
- file_exists?('/etc/rhsm/rhsm.conf')
8
+ file_exists?('/etc/rhsm/rhsm.conf') &&
9
+ !feature(:foreman_server) &&
10
+ feature(:foreman_proxy)
9
11
  end
10
12
  end
11
13
 
12
14
  def run
13
- if system_is_self_registerd?
15
+ if rhsm_hostname_eql_hostname?
14
16
  warn! 'System is self registered'
15
- else
16
- puts 'System is not self registered'
17
17
  end
18
18
  end
19
19
 
20
- def system_is_self_registerd?
21
- rhsm_hostname.casecmp(hostname).zero?
22
- end
23
-
24
20
  def rhsm_hostname
25
21
  execute("grep '\\bhostname\\b' < #{rhsm_conf_file} | grep -v '^#'").sub(/.*?=/, '').strip
26
22
  end
@@ -28,4 +24,8 @@ class Checks::SystemRegistration < ForemanMaintain::Check
28
24
  def rhsm_conf_file
29
25
  '/etc/rhsm/rhsm.conf'
30
26
  end
27
+
28
+ def rhsm_hostname_eql_hostname?
29
+ @result ||= rhsm_hostname.casecmp(hostname).zero?
30
+ end
31
31
  end
@@ -34,9 +34,17 @@ class Features::Downstream < ForemanMaintain::Feature
34
34
  def rh_repos(sat_version)
35
35
  sat_version = version(sat_version)
36
36
  rh_version_major = execute!('facter operatingsystemmajrelease')
37
+
38
+ sat_repo_id = "rhel-#{rh_version_major}-server-satellite-#{sat_version.major}"\
39
+ ".#{sat_version.minor}-rpms"
40
+ # Override to use Beta repositories for 6.3 until GA
41
+ if sat_version.to_s == '6.3'
42
+ sat_repo_id = "rhel-server-#{rh_version_major}-satellite-6-beta-rpms"
43
+ end
44
+
37
45
  ["rhel-#{rh_version_major}-server-rpms",
38
46
  "rhel-server-rhscl-#{rh_version_major}-rpms",
39
- "rhel-#{rh_version_major}-server-satellite-#{sat_version.major}.#{sat_version.minor}-rpms"]
47
+ sat_repo_id]
40
48
  end
41
49
 
42
50
  def version_from_source
@@ -1,6 +1,9 @@
1
1
  class Features::ForemanProxy < ForemanMaintain::Feature
2
2
  metadata do
3
3
  label :foreman_proxy
4
+ confine do
5
+ find_package('foreman-proxy')
6
+ end
4
7
  end
5
8
 
6
9
  attr_reader :dhcpd_conf_file, :cert_path
@@ -36,7 +39,7 @@ class Features::ForemanProxy < ForemanMaintain::Feature
36
39
  array_output = curl_resp.split(/\r\n/)
37
40
  result_array = array_output.last.split(/\n/)
38
41
  curl_http_status = result_array.delete_at(result_array.length - 1).strip.to_i
39
- curl_http_resp = json_parse(result_array.join(''))
42
+ curl_http_resp = parse_json(result_array.join(''))
40
43
  ForemanMaintain::Utils::CurlResponse.new(
41
44
  curl_http_resp,
42
45
  curl_http_status,
@@ -0,0 +1,12 @@
1
+ module ForemanMaintain
2
+ module Features
3
+ class ForemanServer < ForemanMaintain::Feature
4
+ metadata do
5
+ label :foreman_server
6
+ confine do
7
+ server?
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,5 +1,7 @@
1
1
  class Features::ForemanTasks < ForemanMaintain::Feature
2
2
  MIN_AGE = 30
3
+ TIMEOUT_FOR_TASKS_STATUS = 300
4
+ RETRY_INTERVAL_FOR_TASKS_STATE = 10
3
5
 
4
6
  SAFE_TO_DELETE = %w[
5
7
  Actions::Katello::Host::GenerateApplicability
@@ -11,6 +13,11 @@ class Features::ForemanTasks < ForemanMaintain::Feature
11
13
  Actions::Katello::EventQueue::Monitor
12
14
  ].freeze
13
15
 
16
+ EXCLUDE_ACTIONS_FOR_RUNNING_TASKS = %w[
17
+ Actions::Candlepin::ListenOnCandlepinEvents
18
+ Actions::Katello::EventQueue::Monitor
19
+ ].freeze
20
+
14
21
  metadata do
15
22
  label :foreman_tasks
16
23
 
@@ -33,10 +40,14 @@ class Features::ForemanTasks < ForemanMaintain::Feature
33
40
  end
34
41
 
35
42
  def running_tasks_count
36
- # feature(:foreman_database).query(<<-SQL).first['count'].to_i
37
- # SELECT count(*) AS count FROM foreman_tasks_tasks WHERE state in ('running', 'paused')
38
- # SQL
39
- 0
43
+ actions_to_exclude = quotize(EXCLUDE_ACTIONS_FOR_RUNNING_TASKS)
44
+ sql = <<-SQL
45
+ SELECT count(*) AS count
46
+ FROM foreman_tasks_tasks
47
+ WHERE state IN ('running') AND
48
+ label NOT IN (#{actions_to_exclude})
49
+ SQL
50
+ feature(:foreman_database).query(sql).first['count'].to_i
40
51
  end
41
52
 
42
53
  def paused_tasks_count(ignored_tasks = [])
@@ -86,8 +97,42 @@ class Features::ForemanTasks < ForemanMaintain::Feature
86
97
  hammer('task resume')
87
98
  end
88
99
 
100
+ def fetch_tasks_status(state, spinner)
101
+ Timeout.timeout(TIMEOUT_FOR_TASKS_STATUS) do
102
+ check_task_count(state, spinner)
103
+ end
104
+ rescue Timeout::Error => e
105
+ logger.error e.message
106
+ puts "\nTimeout: #{e.message}. Try again."
107
+ end
108
+
89
109
  private
90
110
 
111
+ def check_task_count(state, spinner)
112
+ loop do
113
+ spinner.update "Try checking status of #{state} task(s)"
114
+ task_count = call_tasks_count_by_state(state)
115
+ break if task_count == 0
116
+ puts "\nThere are #{task_count} #{state} tasks."
117
+ spinner.update "Waiting #{RETRY_INTERVAL_FOR_TASKS_STATE} seconds before retry."
118
+ sleep RETRY_INTERVAL_FOR_TASKS_STATE
119
+ end
120
+ rescue StandardError => e
121
+ logger.error e.message
122
+ end
123
+
124
+ def call_tasks_count_by_state(state)
125
+ case state
126
+ when 'running'
127
+ running_tasks_count
128
+ when 'paused'
129
+ paused_tasks_count
130
+ else
131
+ logger.error "No count method defined for state #{state}."
132
+ raise "Unsupported for state #{state}."
133
+ end
134
+ end
135
+
91
136
  def parent_backup_dir
92
137
  File.expand_path(ForemanMaintain.config.backup_dir)
93
138
  end
@@ -0,0 +1,55 @@
1
+ class Features::Hammer < ForemanMaintain::Feature
2
+ metadata do
3
+ label :hammer
4
+ end
5
+
6
+ SERVICES_MAPPING = {
7
+ 'candlepin_auth' => %w[postgresql tomcat],
8
+ 'candlepin' => %w[postgresql tomcat],
9
+ 'pulp_auth' => %w[pulp_resource_manager pulp_workers pulp_celerybeat],
10
+ 'pulp' => %w[pulp_resource_manager pulp_workers pulp_celerybeat],
11
+ 'foreman_tasks' => %w[foreman-tasks]
12
+ }.freeze
13
+
14
+ def hammer_ping_cmd
15
+ cmd_output = exec_hammer_cmd('--output json ping', true)
16
+ return init_result_obj(false, cmd_output) if cmd_output.is_a?(String)
17
+ resources_failed = find_resources_which_failed(cmd_output.first)
18
+ return init_result_obj if resources_failed.empty?
19
+ services = map_resources_with_services(resources_failed)
20
+ msg_to_show = "#{resources_failed.join(', ')} resource(s) are failing."
21
+ init_result_obj(false, msg_to_show, services)
22
+ end
23
+
24
+ def find_resources_which_failed(hammer_ping_output)
25
+ resources_failed = []
26
+ hammer_ping_output.each do |resource, resp_obj|
27
+ resources_failed << resource if /FAIL/ =~ resp_obj['Status']
28
+ end
29
+ resources_failed
30
+ end
31
+
32
+ private
33
+
34
+ def map_resources_with_services(resources)
35
+ service_names = []
36
+ resources.each do |resource|
37
+ service_names.concat(SERVICES_MAPPING[resource])
38
+ end
39
+ service_names
40
+ end
41
+
42
+ def init_result_obj(success_val = true, message = '', data = [])
43
+ {
44
+ :success => success_val,
45
+ :message => message,
46
+ :data => data
47
+ }
48
+ end
49
+
50
+ def exec_hammer_cmd(cmd, required_json = false)
51
+ response = ForemanMaintain::Utils::Hammer.instance.run_command(cmd)
52
+ json_str = parse_json(response) if required_json
53
+ json_str ? json_str : response
54
+ end
55
+ end
@@ -0,0 +1,17 @@
1
+ class Features::Katello < ForemanMaintain::Feature
2
+ metadata do
3
+ label :katello
4
+
5
+ confine do
6
+ find_package('katello')
7
+ end
8
+ end
9
+
10
+ def data_dirs
11
+ @dirs ||= ['/var/lib/pulp', '/var/lib/mongodb', '/var/lib/pgsql']
12
+ end
13
+
14
+ def current_version
15
+ @current_version ||= rpm_version('katello')
16
+ end
17
+ end
@@ -3,20 +3,22 @@ class Features::KatelloService < ForemanMaintain::Feature
3
3
  label :katello_service
4
4
  end
5
5
 
6
+ RETRIES_FOR_SERVICES_RESTART = 5
7
+ PING_RETRY_INTERVAL = 30
8
+
6
9
  def make_stop(spinner, options = {})
7
10
  services = find_services_for_only_filter(running_services, options)
8
11
  if services.empty?
9
12
  spinner.update 'No katello service running'
10
- yield
13
+ yield if block_given?
11
14
  else
12
15
  begin
13
16
  filters = "--only #{services.join(',')}"
14
17
  spinner.update 'Stopping katello running services..'
15
18
  execute!("katello-service stop #{filters}")
16
- yield
19
+ yield if block_given?
17
20
  ensure
18
- spinner.update 'Starting the katello services..'
19
- execute("katello-service start #{filters}")
21
+ start_stopped_services_using_filters(spinner, filters) if block_given?
20
22
  end
21
23
  end
22
24
  end
@@ -27,13 +29,60 @@ class Features::KatelloService < ForemanMaintain::Feature
27
29
  spinner.update 'No katello service to start'
28
30
  else
29
31
  filters = "--only #{services.join(',')}"
30
- spinner.update 'Starting the katello services..'
32
+ spinner.update 'Starting katello services..'
31
33
  execute!("katello-service start #{filters}")
32
34
  end
33
35
  end
34
36
 
37
+ def restart(options = {})
38
+ if options[:only] || options[:exclude]
39
+ filters = construct_filters_for_restart(options)
40
+ execute!("katello-service restart #{filters}")
41
+ else
42
+ execute!('katello-service restart')
43
+ end
44
+ end
45
+
46
+ def hammer_ping_retry(spinner)
47
+ RETRIES_FOR_SERVICES_RESTART.times do |retry_count|
48
+ msg = "Try #{retry_count + 1}/#{RETRIES_FOR_SERVICES_RESTART}: checking status by hammer ping"
49
+ spinner.update msg
50
+ result = feature(:hammer).hammer_ping_cmd
51
+ if result[:success]
52
+ spinner.update 'All services are running.'
53
+ break
54
+ elsif retry_count < (RETRIES_FOR_SERVICES_RESTART - 1)
55
+ apply_sleep_before_retry(spinner, result)
56
+ end
57
+ end
58
+ rescue StandardError => e
59
+ logger.error e.message
60
+ end
61
+
35
62
  private
36
63
 
64
+ def apply_sleep_before_retry(spinner, result)
65
+ puts "\n#{result[:message]}"
66
+ spinner.update "Waiting #{PING_RETRY_INTERVAL} seconds before retry."
67
+ sleep PING_RETRY_INTERVAL
68
+ end
69
+
70
+ def construct_filters_for_restart(options)
71
+ filters = ''
72
+ if options[:only]
73
+ filters += "--only #{options[:only].join(',')}" unless options[:only].empty?
74
+ end
75
+ if options[:exclude]
76
+ filters += "--exclude #{options[:exclude].join(',')}" unless options[:exclude].empty?
77
+ end
78
+ filters
79
+ end
80
+
81
+ def start_stopped_services_using_filters(spinner, filters)
82
+ spinner.update 'Starting katello services..'
83
+ execute("katello-service start #{filters}")
84
+ end
85
+
37
86
  def find_services_for_only_filter(curr_services, options)
38
87
  defaults = { :only => [], :exclude => [] }
39
88
  options = defaults.merge(options)
@@ -0,0 +1,15 @@
1
+ module Procedures::ForemanTasks
2
+ class FetchTasksStatus < ForemanMaintain::Procedure
3
+ metadata do
4
+ for_feature :foreman_tasks
5
+ description 'Fetch tasks status and wait till they finish'
6
+ param :state, :required => true
7
+ end
8
+
9
+ def run
10
+ with_spinner("waiting for #{@state} tasks to finish") do |spinner|
11
+ feature(:foreman_tasks).fetch_tasks_status(@state, spinner)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -12,7 +12,7 @@ module Procedures::ForemanTasks
12
12
  def run
13
13
  ask(<<-MESSAGE.strip_heredoc)
14
14
  Go to https://#{hostname}/foreman_tasks/tasks?search=#{CGI.escape(@search_query.to_s)}
15
- press ENTER after the paused tasks are resolved.
15
+ press ENTER after the tasks are resolved.
16
16
  MESSAGE
17
17
  end
18
18
  end
@@ -0,0 +1,24 @@
1
+ module Procedures::KatelloService
2
+ class Restart < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'katello-service restart'
5
+ param :only, 'A comma-separated list of services to include', :array => true
6
+ param :exclude, 'A comma-separated list of services to skip', :array => true
7
+ end
8
+
9
+ def run
10
+ with_spinner('restarting katello service(s)') do |spinner|
11
+ spinner.update('Restarting services')
12
+ feature(:katello_service).restart(:only => @only, :exclude => @exclude)
13
+ feature(:katello_service).hammer_ping_retry(spinner)
14
+ end
15
+ end
16
+
17
+ def runtime_message
18
+ msg = 'katello-service restart'
19
+ msg += "--only #{@only.join(',')}" unless @only.empty?
20
+ msg += "--exclude #{@exclude.join(',')}" unless @exclude.empty?
21
+ msg
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,19 @@
1
+ module Procedures::KatelloService
2
+ class Start < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'katello-service start'
5
+ param :only, 'A comma-separated list of services to include', :array => true
6
+ param :exclude, 'A comma-separated list of services to skip', :array => true
7
+ for_feature :katello_service
8
+ tags :katello_service_start
9
+ end
10
+
11
+ def run
12
+ with_spinner('stopping katello service(s)') do |spinner|
13
+ feature(:katello_service).make_start(
14
+ spinner, :only => @only, :exclude => @exclude
15
+ )
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Procedures::KatelloService
2
+ class Stop < ForemanMaintain::Procedure
3
+ metadata do
4
+ description 'katello-service stop'
5
+ param :only, 'A comma-separated list of services to include', :array => true
6
+ param :exclude, 'A comma-separated list of services to skip', :array => true
7
+ for_feature :katello_service
8
+ tags :katello_service_stop
9
+ end
10
+
11
+ def run
12
+ with_spinner('stopping katello service(s)') do |spinner|
13
+ feature(:katello_service).make_stop(spinner, :only => @only, :exclude => @exclude)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -32,6 +32,7 @@ module Scenarios::Satellite_6_2
32
32
 
33
33
  def compose
34
34
  add_steps(find_procedures(:pre_migrations))
35
+ add_step(Procedures::KatelloService::Stop.new)
35
36
  end
36
37
  end
37
38
 
@@ -43,7 +44,7 @@ module Scenarios::Satellite_6_2
43
44
 
44
45
  def compose
45
46
  add_step(Procedures::Repositories::Setup.new(:version => '6.2'))
46
- add_step(Procedures::Packages::Update.new(:assumeyes => false))
47
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
47
48
  add_step(Procedures::Installer::Upgrade.new)
48
49
  end
49
50
  end
@@ -55,6 +56,7 @@ module Scenarios::Satellite_6_2
55
56
  end
56
57
 
57
58
  def compose
59
+ add_step(Procedures::KatelloService::Start.new)
58
60
  add_steps(find_procedures(:post_migrations))
59
61
  end
60
62
  end
@@ -32,6 +32,7 @@ module Scenarios::Satellite_6_2_z
32
32
 
33
33
  def compose
34
34
  add_steps(find_procedures(:pre_migrations))
35
+ add_step(Procedures::KatelloService::Stop.new)
35
36
  end
36
37
  end
37
38
 
@@ -42,7 +43,7 @@ module Scenarios::Satellite_6_2_z
42
43
  end
43
44
 
44
45
  def compose
45
- add_step(Procedures::Packages::Update.new(:assumeyes => false))
46
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
46
47
  add_step(Procedures::Installer::Upgrade.new)
47
48
  end
48
49
  end
@@ -54,6 +55,7 @@ module Scenarios::Satellite_6_2_z
54
55
  end
55
56
 
56
57
  def compose
58
+ add_step(Procedures::KatelloService::Start.new)
57
59
  add_steps(find_procedures(:post_migrations))
58
60
  end
59
61
  end
@@ -32,6 +32,7 @@ module Scenarios::Satellite_6_3
32
32
 
33
33
  def compose
34
34
  add_steps(find_procedures(:pre_migrations))
35
+ add_step(Procedures::KatelloService::Stop.new)
35
36
  end
36
37
  end
37
38
 
@@ -43,7 +44,7 @@ module Scenarios::Satellite_6_3
43
44
 
44
45
  def compose
45
46
  add_step(Procedures::Repositories::Setup.new(:version => '6.3'))
46
- add_step(Procedures::Packages::Update.new(:assumeyes => false))
47
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
47
48
  add_step(Procedures::Installer::Upgrade.new)
48
49
  end
49
50
  end
@@ -55,6 +56,7 @@ module Scenarios::Satellite_6_3
55
56
  end
56
57
 
57
58
  def compose
59
+ add_step(Procedures::KatelloService::Start.new)
58
60
  add_steps(find_procedures(:post_migrations))
59
61
  end
60
62
  end
@@ -32,6 +32,7 @@ module Scenarios::Satellite_6_3_z
32
32
 
33
33
  def compose
34
34
  add_steps(find_procedures(:pre_migrations))
35
+ add_step(Procedures::KatelloService::Stop.new)
35
36
  end
36
37
  end
37
38
 
@@ -42,7 +43,7 @@ module Scenarios::Satellite_6_3_z
42
43
  end
43
44
 
44
45
  def compose
45
- add_step(Procedures::Packages::Update.new(:assumeyes => false))
46
+ add_step(Procedures::Packages::Update.new(:assumeyes => true))
46
47
  add_step(Procedures::Installer::Upgrade.new)
47
48
  end
48
49
  end
@@ -54,6 +55,7 @@ module Scenarios::Satellite_6_3_z
54
55
  end
55
56
 
56
57
  def compose
58
+ add_step(Procedures::KatelloService::Start.new)
57
59
  add_steps(find_procedures(:post_migrations))
58
60
  end
59
61
  end
@@ -4,7 +4,7 @@ module ForemanMaintain
4
4
  class AbstractByTagCommand < AbstractProcedureCommand
5
5
  def self.tag_params_to_options(tag)
6
6
  params = params_for_tag(tag)
7
- params.values.each do |param|
7
+ params.each_value do |param|
8
8
  mapping = param[:procedures]
9
9
  instance = param[:instance]
10
10
  param_to_option(instance, :description => instance.description + " #{mapping}")
@@ -14,7 +14,7 @@ module ForemanMaintain
14
14
  def self.params_for_tag(tag)
15
15
  params = {}
16
16
  ForemanMaintain.available_procedures(:tags => tag).each do |procedure|
17
- procedure.params.values.each do |param|
17
+ procedure.params.each_value do |param|
18
18
  unless params.key?(param.name)
19
19
  params[param.name] = { :instance => param, :procedures => [] }
20
20
  end
@@ -17,7 +17,7 @@ module ForemanMaintain
17
17
  def get_params_for(definition)
18
18
  all_params = options_to_params
19
19
  params = {}
20
- definition.params.values.each do |param|
20
+ definition.params.each_value do |param|
21
21
  params[param.name] = all_params[param.name]
22
22
  end
23
23
  params
@@ -37,7 +37,7 @@ module ForemanMaintain
37
37
 
38
38
  module ParamsToOptions
39
39
  def params_to_options(params)
40
- params.values.each do |param|
40
+ params.each_value do |param|
41
41
  param_to_option(param)
42
42
  end
43
43
  end
@@ -66,7 +66,12 @@ module ForemanMaintain
66
66
  subcommand 'run', 'Run full upgrade to a specified version' do
67
67
  target_version_option
68
68
  interactive_option
69
- option '--phase', 'phase', 'run only a specific phase', :required => false
69
+ option '--phase', 'phase', 'run only a specific phase', :required => false do |phase|
70
+ unless UpgradeRunner::PHASES.include?(phase.to_sym)
71
+ raise Error::UsageError, "Unknown phase #{phase}"
72
+ end
73
+ phase
74
+ end
70
75
 
71
76
  def execute
72
77
  if phase
@@ -26,16 +26,69 @@ module ForemanMaintain
26
26
  end
27
27
  end
28
28
 
29
- def hostname
30
- execute('hostname -f')
29
+ def check_min_version(name, minimal_version)
30
+ current_version = package_version(name)
31
+ if current_version
32
+ return current_version >= version(minimal_version)
33
+ end
34
+ end
35
+
36
+ def downstream_installation?
37
+ execute?('rpm -q satellite') ||
38
+ (execute('rpm -q foreman') =~ /sat.noarch/)
39
+ end
40
+
41
+ def execute?(command, input = nil)
42
+ execute(command, :stdin => input)
43
+ $CHILD_STATUS.success?
44
+ end
45
+
46
+ def execute!(command, options = {})
47
+ command_runner = Utils::CommandRunner.new(logger, command, options)
48
+ execution.puts '' if command_runner.interactive? && respond_to?(:execution)
49
+ command_runner.run
50
+ if command_runner.success?
51
+ command_runner.output
52
+ else
53
+ raise command_runner.execution_error
54
+ end
55
+ end
56
+
57
+ def execute(command, options = {})
58
+ command_runner = Utils::CommandRunner.new(logger, command, options)
59
+ execution.puts '' if command_runner.interactive? && respond_to?(:execution)
60
+ command_runner.run
61
+ command_runner.output
31
62
  end
32
63
 
33
64
  def file_exists?(filename)
34
65
  File.exist?(filename)
35
66
  end
36
67
 
37
- def version(value)
38
- Version.new(value)
68
+ def find_package(name)
69
+ result = execute(%(rpm -q '#{name}'))
70
+ if $CHILD_STATUS.success?
71
+ result
72
+ end
73
+ end
74
+
75
+ def hostname
76
+ execute('hostname -f')
77
+ end
78
+
79
+ def install_packages(packages, options = {})
80
+ options.validate_options!(:assumeyes)
81
+ yum_options = []
82
+ yum_options << '-y' if options[:assumeyes]
83
+ execute!("yum #{yum_options.join(' ')} install #{packages.join(' ')}", :interactive => true)
84
+ end
85
+
86
+ def server?
87
+ find_package('foreman')
88
+ end
89
+
90
+ def smart_proxy?
91
+ !server? && find_package('foreman-proxy')
39
92
  end
40
93
 
41
94
  def packages_action(action, packages, options = {})
@@ -50,30 +103,11 @@ module ForemanMaintain
50
103
  :interactive => true)
51
104
  end
52
105
 
53
- def check_min_version(name, minimal_version)
54
- current_version = package_version(name)
55
- if current_version
56
- return current_version >= version(minimal_version)
57
- end
58
- end
59
-
60
- def downstream_installation?
61
- execute?('rpm -q satellite') ||
62
- (execute('rpm -q foreman') =~ /sat.noarch/)
63
- end
64
-
65
106
  def package_version(name)
66
107
  # space for extension to support non-rpm distributions
67
108
  rpm_version(name)
68
109
  end
69
110
 
70
- def rpm_version(name, queryformat = 'VERSION')
71
- rpm_version = execute(%(rpm -q '#{name}' --queryformat="%{#{queryformat}}"))
72
- if $CHILD_STATUS.success?
73
- version(rpm_version)
74
- end
75
- end
76
-
77
111
  def parse_csv(data)
78
112
  parsed_data = CSV.parse(data)
79
113
  header = parsed_data.first
@@ -82,37 +116,25 @@ module ForemanMaintain
82
116
  end
83
117
  end
84
118
 
85
- def execute?(command, input = nil)
86
- execute(command, :stdin => input)
87
- $CHILD_STATUS.success?
119
+ def parse_json(json_string)
120
+ JSON.parse(json_string)
121
+ rescue StandardError
122
+ nil
88
123
  end
89
124
 
90
- def execute!(command, options = {})
91
- command_runner = Utils::CommandRunner.new(logger, command, options)
92
- execution.puts '' if command_runner.interactive? && respond_to?(:execution)
93
- command_runner.run
94
- if command_runner.success?
95
- command_runner.output
96
- else
97
- raise command_runner.execution_error
125
+ def rpm_version(name)
126
+ rpm_version = execute(%(rpm -q '#{name}' --queryformat="%{VERSION}"))
127
+ if $CHILD_STATUS.success?
128
+ version(rpm_version)
98
129
  end
99
130
  end
100
131
 
101
- def execute(command, options = {})
102
- command_runner = Utils::CommandRunner.new(logger, command, options)
103
- execution.puts '' if command_runner.interactive? && respond_to?(:execution)
104
- command_runner.run
105
- command_runner.output
106
- end
107
-
108
132
  def shellescape(string)
109
133
  Shellwords.escape(string)
110
134
  end
111
135
 
112
- def json_parse(json_string)
113
- JSON.parse(json_string)
114
- rescue
115
- nil
136
+ def version(value)
137
+ Version.new(value)
116
138
  end
117
139
  end
118
140
  end
@@ -35,7 +35,7 @@ module ForemanMaintain
35
35
  "Config file #{config_file} not found, using default configuration"
36
36
  {}
37
37
  end
38
- rescue => e
38
+ rescue StandardError => e
39
39
  raise "Couldn't load configuration file. Error: #{e.message}"
40
40
  end
41
41
 
@@ -51,7 +51,7 @@ module ForemanMaintain
51
51
  dir_path = File.expand_path(dir_path_str)
52
52
  begin
53
53
  FileUtils.mkdir_p(dir_path, :mode => 0o750) unless File.exist?(dir_path)
54
- rescue => e
54
+ rescue StandardError => e
55
55
  $stderr.puts "No permissions to create dir #{dir_path_str}"
56
56
  $stderr.puts e.message.inspect
57
57
  end
@@ -67,7 +67,7 @@ module ForemanMaintain
67
67
  return if @all_features_scanned
68
68
  @available_features = []
69
69
  @features_by_label = {}
70
- autodetect_features.keys.each do |label|
70
+ autodetect_features.each_key do |label|
71
71
  detect_feature(label)
72
72
  end
73
73
  @all_features_scanned = true
@@ -8,8 +8,6 @@ module ForemanMaintain
8
8
  :assumeyes?, :whitelisted?,
9
9
  :execution, :puts, :print, :with_spinner, :ask, :storage
10
10
 
11
- attr_accessor :associated_feature
12
-
13
11
  def initialize(options = {})
14
12
  @options = options.inject({}) { |h, (k, v)| h.update(k.to_s => v) }
15
13
  @param_values = {}
@@ -33,7 +31,7 @@ module ForemanMaintain
33
31
  # processes the params from provided options
34
32
  def setup_params
35
33
  @options.validate_options!(params.values.map(&:name).map(&:to_s))
36
- params.values.each do |param|
34
+ params.each_value do |param|
37
35
  set_param_variable(param.name, param.process(@options[param.name.to_s]))
38
36
  end
39
37
  end
@@ -97,7 +97,7 @@ module ForemanMaintain
97
97
 
98
98
  def capture_errors
99
99
  yield
100
- rescue => e
100
+ rescue StandardError => e
101
101
  @status = :fail
102
102
  @output << e.message
103
103
  logger.error(e)
@@ -5,7 +5,7 @@ module ForemanMaintain
5
5
  class BlockDevice
6
6
  include ForemanMaintain::Concerns::SystemHelpers
7
7
 
8
- attr_accessor :dir, :unit, :read_speed, :name
8
+ attr_accessor :dir, :name
9
9
 
10
10
  def initialize(dir, name = Disk::Device.new('/var').name)
11
11
  @dir = dir
@@ -5,7 +5,7 @@ module ForemanMaintain
5
5
  class FileSystem
6
6
  include ForemanMaintain::Concerns::SystemHelpers
7
7
 
8
- attr_accessor :dir, :unit, :read_speed, :name
8
+ attr_accessor :dir, :name
9
9
 
10
10
  def initialize(dir, name = '')
11
11
  @dir = dir
@@ -1,3 +1,3 @@
1
1
  module ForemanMaintain
2
- VERSION = '0.0.9'.freeze
2
+ VERSION = '0.0.10'.freeze
3
3
  end
@@ -6,6 +6,7 @@ require 'forwardable'
6
6
  require 'json'
7
7
  require 'logger'
8
8
  require 'yaml'
9
+ require 'timeout'
9
10
 
10
11
  module ForemanMaintain
11
12
  require 'foreman_maintain/core_ext'
@@ -110,7 +111,7 @@ module ForemanMaintain
110
111
 
111
112
  def storage(label = :default)
112
113
  ForemanMaintain::YamlStorage.load(label)
113
- rescue => e
114
+ rescue StandardError => e
114
115
  logger.error "Invalid Storage label i.e #{label}. Error - #{e.message}"
115
116
  end
116
117
  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.0.9
4
+ version: 0.0.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: 2017-09-14 00:00:00.000000000 Z
11
+ date: 2017-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -116,21 +116,29 @@ files:
116
116
  - definitions/checks/foreman_tasks/invalid/check_planning_state.rb
117
117
  - definitions/checks/foreman_tasks/not_paused.rb
118
118
  - definitions/checks/foreman_tasks/not_running.rb
119
+ - definitions/checks/hammer_ping.rb
119
120
  - definitions/checks/system_registration.rb
120
121
  - definitions/features/downstream.rb
121
122
  - definitions/features/foreman_1_11_x.rb
122
123
  - definitions/features/foreman_1_7_x.rb
123
124
  - definitions/features/foreman_database.rb
124
125
  - definitions/features/foreman_proxy.rb
126
+ - definitions/features/foreman_server.rb
125
127
  - definitions/features/foreman_tasks.rb
128
+ - definitions/features/hammer.rb
129
+ - definitions/features/katello.rb
126
130
  - definitions/features/katello_service.rb
127
131
  - definitions/features/sync_plans.rb
128
132
  - definitions/features/upstream.rb
129
133
  - definitions/procedures/foreman_tasks/delete.rb
134
+ - definitions/procedures/foreman_tasks/fetch_tasks_status.rb
130
135
  - definitions/procedures/foreman_tasks/resume.rb
131
136
  - definitions/procedures/foreman_tasks/ui_investigate.rb
132
137
  - definitions/procedures/hammer_setup.rb
133
138
  - definitions/procedures/installer/upgrade.rb
139
+ - definitions/procedures/katello_service/restart.rb
140
+ - definitions/procedures/katello_service/start.rb
141
+ - definitions/procedures/katello_service/stop.rb
134
142
  - definitions/procedures/maintenance_mode/disable.rb
135
143
  - definitions/procedures/maintenance_mode/enable.rb
136
144
  - definitions/procedures/packages/install.rb
@@ -211,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
219
  version: '0'
212
220
  requirements: []
213
221
  rubyforge_project:
214
- rubygems_version: 2.5.2
222
+ rubygems_version: 2.6.12
215
223
  signing_key:
216
224
  specification_version: 4
217
225
  summary: Foreman maintenance tool belt