kolla-ansible/docker/rabbitmq/rabbitmq_get_gospel_node.py
Michal (inc0) Jastrzebski 22a07075d2 Robustify of rabbitmq upgrade
String parsing for gospel node detection was overly complex and not
robust. Hopefully this will make it better.

Closes-bug: #1573684
Change-Id: I12e869eff274d286d239c4f55cc4b4ddca389bbd
2016-04-22 16:49:00 +00:00

62 lines
1.7 KiB
Python

#!/usr/bin/python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import subprocess
import traceback
def extract_gospel_node(term):
return term.split("@")[1].translate(None, "\'\"{},")
def main():
try:
raw_status = subprocess.check_output(
"rabbitmqctl eval 'rabbit_clusterer:status().'",
shell=True, stderr=subprocess.STDOUT
)
if "Rabbit is running in cluster configuration" not in raw_status:
raise AttributeError
gospel_line = [
line for line in raw_status.split('\n') if 'gospel' in line
][0]
gospel_node = extract_gospel_node(gospel_line)
if not gospel_node:
raise AttributeError
except AttributeError:
result = {
'failed': True,
'error': raw_status,
'changed': True
}
except Exception:
result = {
'failed': True,
'error': traceback.format_exc(),
'changed': True
}
else:
result = {
'failed': False,
'hostname': gospel_node,
'changed': False
}
print(json.dumps(result))
if __name__ == '__main__':
main()