From fa68f09e721282e05701ad6fcaff55d3276e26ac Mon Sep 17 00:00:00 2001 From: Edin Sarajlic Date: Thu, 19 Sep 2019 14:13:56 +1000 Subject: [PATCH] Add a function providing all units/nodes Rmq cluster_status in JSON --- .../charm_tests/rabbitmq_server/utils.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/zaza/openstack/charm_tests/rabbitmq_server/utils.py b/zaza/openstack/charm_tests/rabbitmq_server/utils.py index 3ef9836..66cb1c8 100644 --- a/zaza/openstack/charm_tests/rabbitmq_server/utils.py +++ b/zaza/openstack/charm_tests/rabbitmq_server/utils.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json import logging import zaza.model @@ -45,3 +46,22 @@ def get_cluster_status(unit): return str(output) +def get_cluster_running_nodes(unit): + """Parse rabbitmqctl cluster_status output string, return list of + running rabbitmq cluster nodes. + :param unit: unit pointer + :returns: List containing node names of running nodes + """ + # NOTE(beisner): rabbitmqctl cluster_status output is not + # json-parsable, do string chop foo, then json.loads that. + str_stat = get_cluster_status(unit) + if 'running_nodes' in str_stat: + pos_start = str_stat.find("{running_nodes,") + 15 + pos_end = str_stat.find("]},", pos_start) + 1 + str_run_nodes = str_stat[pos_start:pos_end].replace("'", '"') + run_nodes = json.loads(str_run_nodes) + return run_nodes + else: + return [] + +