Class: Katello::Ping

Inherits:
Object
  • Object
show all
Defined in:
app/models/katello/ping.rb

Constant Summary collapse

OK_RETURN_CODE =
'ok'.freeze
FAIL_RETURN_CODE =
'FAIL'.freeze
PACKAGES =
%w(katello candlepin pulp foreman hammer dynflow).freeze

Class Method Summary collapse

Class Method Details

.all_pulp_workers_present?(json) ⇒ Boolean

Returns:

  • (Boolean)


204
205
206
207
208
209
210
211
# File 'app/models/katello/ping.rb', line 204

def all_pulp_workers_present?(json)
  worker_ids = json["known_workers"].collect { |worker| worker["_id"] }
  return false unless worker_ids.any?
  scheduler = worker_ids.any? { |worker| worker.include?("scheduler@") }
  resource_manager = worker_ids.any? { |worker| worker.include?("resource_manager@") }
  reservered_resource_worker = worker_ids.any? { |worker| worker =~ /reserved_resource_worker-./ }
  scheduler && resource_manager && reservered_resource_worker
end

.check_candlepin_status(status) ⇒ Object



119
120
121
122
123
# File 'app/models/katello/ping.rb', line 119

def check_candlepin_status(status)
  if status[:mode] != 'NORMAL'
    fail _("Candlepin is not running properly")
  end
end

.event_daemon_status(status, result) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'app/models/katello/ping.rb', line 41

def event_daemon_status(status, result)
  running = status&.dig(:running)

  if running
    result[:message] = "#{status[:processed_count].to_i} Processed, #{status[:failed_count].to_i} Failed"
  else
    result[:status] = FAIL_RETURN_CODE
    result[:message] = _("Not running")
  end
end

.exception_watch(result) ⇒ Object

check for exception - set the result code properly



126
127
128
129
130
131
132
133
134
135
136
137
# File 'app/models/katello/ping.rb', line 126

def exception_watch(result)
  start = Time.new
  result[:status] = OK_RETURN_CODE
  yield
  result[:duration_ms] = ((Time.new - start) * 1000).round.to_s
  result
rescue => e
  Rails.logger.warn(e.backtrace ? [e.message, e.backtrace].join("\n") : e.message)
  result[:status] = FAIL_RETURN_CODE
  result[:message] = e.message
  result
end

.packagesObject

get package information for katello and its components



140
141
142
143
144
# File 'app/models/katello/ping.rb', line 140

def packages
  names = PACKAGES.join("|")
  packages = `rpm -qa | egrep "#{names}"`
  packages.split("\n").sort
end

.ping(services: nil, capsule_id: nil) ⇒ Object



19
20
21
# File 'app/models/katello/ping.rb', line 19

def ping(services: nil, capsule_id: nil)
  ping_services_for_capsule(services, capsule_id)
end

.ping!(services: nil, capsule_id: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'app/models/katello/ping.rb', line 23

def ping!(services: nil, capsule_id: nil)
  result = ping_services_for_capsule(services, capsule_id)

  if result[:status] != OK_RETURN_CODE
    failed_names = failed_services(result).keys
    fail Katello::Errors::PingError, "The following services have not been started or are reporting errors: #{failed_names.join(', ')}"
  end

  result
end

.ping_candlepin_with_auth(service_result) ⇒ Object



95
96
97
98
99
100
# File 'app/models/katello/ping.rb', line 95

def ping_candlepin_with_auth(service_result)
  exception_watch(service_result) do
    status = Katello::Resources::Candlepin::CandlepinPing.ping
    check_candlepin_status(status)
  end
end

.ping_candlepin_without_auth(service_result) ⇒ Object



77
78
79
80
81
82
83
# File 'app/models/katello/ping.rb', line 77

def ping_candlepin_without_auth(service_result)
  url = SETTINGS[:katello][:candlepin][:url]
  exception_watch(service_result) do
    status = backend_status(url, :candlepin)
    check_candlepin_status(status)
  end
end

.ping_foreman_tasks(service_result) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/models/katello/ping.rb', line 102

def ping_foreman_tasks(service_result)
  exception_watch(service_result) do
    timeout   = 2
    world     = ForemanTasks.dynflow.world
    executors = world.coordinator.find_worlds(true)
    if executors.empty?
      fail _("foreman-tasks service not running or is not ready yet")
    end

    checks = executors.map { |executor| world.ping(executor.id, timeout) }
    checks.each(&:wait)
    if checks.any?(&:rejected?)
      fail _("some executors are not responding, check %{status_url}") % { :status_url => '/foreman_tasks/dynflow/status' }
    end
  end
end

.ping_katello_events(result) ⇒ Object



52
53
54
55
56
57
# File 'app/models/katello/ping.rb', line 52

def ping_katello_events(result)
  exception_watch(result) do
    status = Katello::EventDaemon::Runner.service_status(:katello_events)
    event_daemon_status(status, result)
  end
end

.ping_pulp3_content_without_auth(service_result, capsule_id) ⇒ Object



65
66
67
68
69
# File 'app/models/katello/ping.rb', line 65

def ping_pulp3_content_without_auth(service_result, capsule_id)
  exception_watch(service_result) do
    Katello::Ping.pulp3_content_without_auth(fetch_proxy(capsule_id).pulp3_url)
  end
end

.ping_pulp3_without_auth(service_result, capsule_id) ⇒ Object



59
60
61
62
63
# File 'app/models/katello/ping.rb', line 59

def ping_pulp3_without_auth(service_result, capsule_id)
  exception_watch(service_result) do
    Katello::Ping.pulp3_without_auth(fetch_proxy(capsule_id).pulp3_url)
  end
end

.ping_pulp_with_auth(service_result, pulp_without_auth_status, capsule_id) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'app/models/katello/ping.rb', line 85

def ping_pulp_with_auth(service_result, pulp_without_auth_status, capsule_id)
  exception_watch(service_result) do
    if pulp_without_auth_status == OK_RETURN_CODE
      Katello::Pulp::Server.config(pulp_url(capsule_id), User.remote_user).resources.user.retrieve_all
    else
      fail _("Skipped pulp_auth check after failed pulp check")
    end
  end
end

.ping_pulp_without_auth(service_result, capsule_id) ⇒ Object



71
72
73
74
75
# File 'app/models/katello/ping.rb', line 71

def ping_pulp_without_auth(service_result, capsule_id)
  exception_watch(service_result) do
    Katello::Ping.pulp_without_auth(pulp_url(capsule_id))
  end
end

.pulp3_content_without_auth(url) ⇒ Object



194
195
196
197
198
199
200
201
202
# File 'app/models/katello/ping.rb', line 194

def pulp3_content_without_auth(url)
  json = backend_status(url, :pulp)
  fail _("Pulp does not appear to be running at %s.") % url if json.empty?

  content_apps = json["online_content_apps"] || []
  fail _("No pulpcore content apps are running at %s.") % url if content_apps.empty?

  json
end

.pulp3_without_auth(url) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'app/models/katello/ping.rb', line 176

def pulp3_without_auth(url)
  json = backend_status(url, :pulp)
  fail _("Pulp does not appear to be running at %s.") % url if json.empty?

  if json['database_connection'] && json['database_connection']['connected'] != true
    fail _("Pulp database connection issue at %s.") % url
  end

  if json['redis_connection'] && json['redis_connection']['connected'] != true
    fail _("Pulp redis connection issue at %s.") % url
  end

  workers = json["online_workers"] || []
  fail _("No pulpcore workers are running at %s.") % url if workers.empty?

  json
end

.pulp_url(capsule_id) ⇒ Object



146
147
148
149
150
# File 'app/models/katello/ping.rb', line 146

def pulp_url(capsule_id)
  proxy = fetch_proxy(capsule_id)
  uri = URI.parse(proxy.pulp_url)
  "#{uri.scheme}://#{uri.host.downcase}/pulp/api/v2/"
end

.pulp_without_auth(url) ⇒ Object

this checks Pulp is running and responding without need for authentication. We don’t use RestClient.options here because it returns empty string, which is not enough to say pulp is the one that responded



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'app/models/katello/ping.rb', line 156

def pulp_without_auth(url)
  json = backend_status(url, :pulp)

  fail _("Pulp does not appear to be running at %s.") % url if json.empty?

  if json['database_connection'] && json['database_connection']['connected'] != true
    fail _("Pulp database connection issue at %s.") % url
  end

  if json['messaging_connection'] && json['messaging_connection']['connected'] != true
    fail _("Pulp message bus connection issue at %s.") % url
  end

  unless all_pulp_workers_present?(json)
    fail _("Not all necessary pulp workers running at %s.") % url
  end

  json
end

.services(capsule_id = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'app/models/katello/ping.rb', line 8

def services(capsule_id = nil)
  proxy = fetch_proxy(capsule_id)
  services = [:candlepin, :candlepin_auth, :foreman_tasks, :katello_events]
  services += [:pulp3, :pulp3_content] if proxy&.pulp3_enabled?
  if proxy.nil? || proxy.has_feature?(SmartProxy::PULP_NODE_FEATURE) || proxy.has_feature?(SmartProxy::PULP_FEATURE)
    services += [:pulp, :pulp_auth]
  end

  services
end

.statusObject



34
35
36
37
38
39
# File 'app/models/katello/ping.rb', line 34

def status
  {
    version: Katello::VERSION,
    timeUTC: Time.now.getutc,
  }
end