-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #50 - Clean all Qpid queues to zero
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |