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
This commit is contained in:
Michal (inc0) Jastrzebski 2016-04-22 14:44:54 +00:00
parent 39aec94983
commit 22a07075d2

View File

@ -13,17 +13,12 @@
# limitations under the License. # limitations under the License.
import json import json
import re
import subprocess import subprocess
import traceback import traceback
def convert_erlang_to_json(term): def extract_gospel_node(term):
term = re.sub('[\s+]', '', term) return term.split("@")[1].translate(None, "\'\"{},")
term = re.sub('([<>].*?)}', r'"\1"}', term)
term = re.sub('{([a-z].*?),', r'{"\1":', term)
term = re.sub(':([a-z].*?)}', r':"\1"}', term)
return json.loads(term)
def main(): def main():
@ -34,15 +29,11 @@ def main():
) )
if "Rabbit is running in cluster configuration" not in raw_status: if "Rabbit is running in cluster configuration" not in raw_status:
raise AttributeError raise AttributeError
status = convert_erlang_to_json( gospel_line = [
'\n'.join(raw_status.split('\n')[1:-3]) line for line in raw_status.split('\n') if 'gospel' in line
) ][0]
gospel_node = extract_gospel_node(gospel_line)
gospel_node = None if not gospel_node:
for msg in status:
if 'gospel' in msg:
gospel_node = msg['gospel']['node'].split('@')[1]
if gospel_node is None:
raise AttributeError raise AttributeError
except AttributeError: except AttributeError:
result = { result = {