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 qpid foreman tfm hammer).freeze

Class Method Summary collapse

Class Method Details

.all_pulp_workers_present?(json) ⇒ Boolean

Returns:

  • (Boolean)


219
220
221
222
223
224
225
226
# File 'app/models/katello/ping.rb', line 219

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



134
135
136
137
138
# File 'app/models/katello/ping.rb', line 134

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

.event_daemon_status(status, result) ⇒ Object



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

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



141
142
143
144
145
146
147
148
149
150
151
152
# File 'app/models/katello/ping.rb', line 141

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



155
156
157
158
159
# File 'app/models/katello/ping.rb', line 155

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

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



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

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

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



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

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_events(result) ⇒ Object



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

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

.ping_candlepin_with_auth(service_result) ⇒ Object



110
111
112
113
114
115
# File 'app/models/katello/ping.rb', line 110

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



92
93
94
95
96
97
98
# File 'app/models/katello/ping.rb', line 92

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



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/models/katello/ping.rb', line 117

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_agent(result) ⇒ Object



67
68
69
70
71
72
# File 'app/models/katello/ping.rb', line 67

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

.ping_katello_events(result) ⇒ Object



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

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



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

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



74
75
76
77
78
# File 'app/models/katello/ping.rb', line 74

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



100
101
102
103
104
105
106
107
108
# File 'app/models/katello/ping.rb', line 100

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



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

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



209
210
211
212
213
214
215
216
217
# File 'app/models/katello/ping.rb', line 209

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



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'app/models/katello/ping.rb', line 191

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



161
162
163
164
165
# File 'app/models/katello/ping.rb', line 161

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



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'app/models/katello/ping.rb', line 171

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
18
# 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, :candlepin_events]
  services += [:pulp3, :pulp3_content] if proxy&.pulp3_enabled?
  services += [:katello_agent] if ::Katello.with_katello_agent?
  if proxy.nil? || proxy.has_feature?(SmartProxy::PULP_NODE_FEATURE) || proxy.has_feature?(SmartProxy::PULP_FEATURE)
    services += [:pulp, :pulp_auth]
  end

  services
end

.statusObject



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

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