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

.check_candlepin_status(status) ⇒ Object



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

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

.event_daemon_status(status, result) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'app/models/katello/ping.rb', line 38

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



107
108
109
110
111
112
113
114
115
116
117
118
# File 'app/models/katello/ping.rb', line 107

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



121
122
123
124
125
# File 'app/models/katello/ping.rb', line 121

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

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



16
17
18
# File 'app/models/katello/ping.rb', line 16

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

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



20
21
22
23
24
25
26
27
28
29
# File 'app/models/katello/ping.rb', line 20

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



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

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



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

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



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/models/katello/ping.rb', line 83

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



49
50
51
52
53
54
# File 'app/models/katello/ping.rb', line 49

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



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

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



56
57
58
59
60
# File 'app/models/katello/ping.rb', line 56

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

.pulp3_content_without_auth(url) ⇒ Object



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

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



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/models/katello/ping.rb', line 127

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

.services(capsule_id = nil) ⇒ Object



8
9
10
11
12
13
14
# 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?

  services
end

.statusObject



31
32
33
34
35
36
# File 'app/models/katello/ping.rb', line 31

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