-
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
5 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_queues | ||
description 'check for qpid queues' | ||
tags :pre_upgrade | ||
end | ||
|
||
def run | ||
qpid_queues_count = feature(:qpid_queues).count | ||
assert(qpid_queues_count == 0, | ||
"There are #{qpid_queues_count} qpid queues 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,46 @@ | ||
class Features::QpidQueues < ForemanMaintain::Feature | ||
metadata do | ||
label :qpid_queues | ||
|
||
confine do | ||
qpid_tools_installed? && 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 | ||
rescue => e | ||
logger.error e.message | ||
ensure | ||
queues_cleared | ||
end | ||
|
||
def count | ||
available_qpid_queues.length | ||
end | ||
|
||
private | ||
|
||
def available_qpid_queues | ||
output = qpid_config('list queue --show-property=name | tail -n +4') | ||
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,14 @@ | ||
class Procedures::QpidQueuesClear < ForemanMaintain::Procedure | ||
metadata do | ||
for_feature :qpid_queues | ||
description 'clear qpid queues' | ||
end | ||
|
||
def run | ||
with_spinner('clear qpid queues') do |spinner| | ||
total_queues_cleared = feature(:qpid_queues).clear_all | ||
spinner.update "#{total_queues_cleared.length} qpid queues are cleared." | ||
spinner.update 'These queues will be recreated using installer' | ||
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
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_queues, :count => 0) | ||
result = run_check(subject) | ||
assert result.success? | ||
end | ||
|
||
it 'fails when qpid queues are present' do | ||
assume_feature_present(:qpid_queues, :count => 2) | ||
result = run_check(subject) | ||
assert result.fail? | ||
assert_match 'There are 2 qpid queues present in the system', result.output | ||
assert_equal [Procedures::QpidQueuesClear], subject.next_steps.map(&:class) | ||
end | ||
end |