Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #50 - Clean all Qpid queues to zero #52

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions definitions/checks/qpid_queues_not_clear.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Checks::QpidQueuesNotClear < ForemanMaintain::Check
metadata do
for_feature :qpid
description 'check for qpid queues'
tags :pre_upgrade
end

def run
qpid_queues_count = feature(:qpid).count
assert(qpid_queues_count == 0,
"There are #{qpid_queues_count} persistent qpid queue(s) present in the system",
:next_steps => Procedures::QpidQueuesClear.new)
end
end
47 changes: 47 additions & 0 deletions definitions/features/qpid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
class Features::Qpid < ForemanMaintain::Feature
metadata do
label :qpid

confine do
execute?('rpm -qa |grep qpid-tools') & File.exist?('/etc/pki/katello/qpid_client_striped.crt')
end
end

def clear_all
queues_cleared = []
available_qpid_queues.each do |qname|
clear(qname)
queues_cleared << qname
end
queues_cleared
rescue => e
logger.error e.message
return queues_cleared
end

def count
available_qpid_queues.length
end

private

def available_qpid_queues
output = qpid_config("list queue --show-property=name \
--show-property=autoDelete | awk '$2 ~ /False/{ print $1 }'")
output ? output.split(' ') : []
rescue => e
logger.error e.message
logger.error e.backtrace.join('\n')
end

def clear(queue_name)
qpid_config("del queue #{queue_name} --force")
end

def qpid_config(sub_cmd)
cmd = 'qpid-config --ssl-certificate=/etc/pki/katello/qpid_client_striped.crt\
-b amqps://localhost:5671 '
cmd += sub_cmd
execute(cmd)
end
end
17 changes: 17 additions & 0 deletions definitions/procedures/qpid_queues_clear.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Procedures::QpidQueuesClear < ForemanMaintain::Procedure
metadata do
for_feature :qpid
description 'clear qpid queues'
end

def run
with_spinner('clear qpid queues') do |spinner|
feature(:katello_service).make_stop(spinner, :exclude => ['qpidd']) do
spinner.update 'Clearing qpid queues..'
total_queues_cleared = feature(:qpid).clear_all
spinner.update "#{total_queues_cleared.length} queues cleared.\
These queues are recreated by restarting katello-services."
end
end
end
end
23 changes: 23 additions & 0 deletions test/definitions/checks/qpid_queues_not_clear_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'test_helper'

describe Checks::QpidQueuesNotClear do
include DefinitionsTestHelper

subject do
Checks::QpidQueuesNotClear.new
end

it 'runs on empty qpid queue' do
assume_feature_present(:qpid, :count => 0)
result = run_check(subject)
assert result.success?
end

it 'fails when qpid queues are present' do
assume_feature_present(:qpid, :count => 2)
result = run_check(subject)
assert result.fail?
assert_match 'There are 2 persistent qpid queue(s) present in the system', result.output
assert_equal [Procedures::QpidQueuesClear], subject.next_steps.map(&:class)
end
end